[prev in list] [next in list] [prev in thread] [next in thread]
List: ipfire-development
Subject: [PATCH v2 3/5] cli: print the color of a zone/port
From: Jonatan Schlag <jonatan.schlag () ipfire ! org>
Date: 2017-06-15 16:18:51
Message-ID: 1497543533-5925-3-git-send-email-jonatan.schlag () ipfire ! org
[Download RAW message or body]
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
---
src/functions/functions.cli | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/src/functions/functions.cli b/src/functions/functions.cli
index a4690b2..5efd923 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}"
+}
--
2.6.3
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic