From: Jonatan Schlag Date: Thu, 15 Jun 2017 16:18:51 +0000 (+0200) Subject: cli: print the color of a zone/port X-Git-Tag: 009~212 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2e3317f41c94a33e250973ca99e694b9981b7971;p=network.git cli: print the color of a zone/port Signed-off-by: Jonatan Schlag Signed-off-by: Michael Tremer --- diff --git a/src/functions/functions.cli b/src/functions/functions.cli index a4690b23..5efd923d 100644 --- a/src/functions/functions.cli +++ b/src/functions/functions.cli @@ -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}" +}