]> git.ipfire.org Git - people/ms/network.git/commitdiff
cli: print the color of a zone/port
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Thu, 15 Jun 2017 16:18:51 +0000 (18:18 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 19 Jun 2017 16:06:15 +0000 (18:06 +0200)
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.cli

index a4690b23c22afa997c159258cee4073fedaadb27..5efd923d04c11b8561255ff1a76c79bb7c78a39f 100644 (file)
@@ -112,6 +112,18 @@ cli_device_headline() {
                        ;;
        esac
        cli_print_fmt1 1 "Status" "${status}"
+
+       # Print the color of the device.
+       case "${type}" in
+               port)
+                       cli_print_fmt1 1 "Color" "$(cli_color_bar $(port_get_color ${device}))"
+                       ;;
+
+               zone)
+                       cli_print_fmt1 1 "Color" "$(cli_color_bar $(zone_get_color ${device}))"
+                       ;;
+       esac
+
        if enabled long; then
                cli_print_fmt1 1 "Address" "$(device_get_address ${device})"
        fi
@@ -423,3 +435,33 @@ cli_show_man() {
 
        man ${manpage}
 }
+
+cli_set_color() {
+       #Function to set the back and foreground color at once.
+       local fg=${1}
+       local bg=${2}
+
+       local i
+       for i in fg bg; do
+               # Skip if color is empty
+               [ -n "${!i}" ] || continue
+
+               # Skip for dash
+               [ "${!i}" = "-" ] && continue
+
+               color_set_shell ${i} ${!i}
+       done
+}
+
+cli_reset_color() {
+       #Reset the shell color.
+       printf "\e[0m"
+}
+
+cli_color_bar() {
+       # This function return some colored space
+       assert [ $# -eq 1 ]
+
+       local color=${1}
+       echo "$(cli_set_color - ${color})            ${CLR_RESET}"
+}