From 1813074eae6d278bf0bb355a1a6eebf43a466362 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Fri, 29 Aug 2025 14:38:31 +0100 Subject: [PATCH] Ctrl shell: Add colours for printing topics and +ve and -ve responses Apply to the getRole command --- apps/mosquitto_ctrl/ctrl_shell.c | 18 ++++++++++++++++++ apps/mosquitto_ctrl/ctrl_shell.h | 3 +++ apps/mosquitto_ctrl/ctrl_shell_dynsec.c | 3 ++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/apps/mosquitto_ctrl/ctrl_shell.c b/apps/mosquitto_ctrl/ctrl_shell.c index f391c8e9..6cfd6f3b 100644 --- a/apps/mosquitto_ctrl/ctrl_shell.c +++ b/apps/mosquitto_ctrl/ctrl_shell.c @@ -51,6 +51,9 @@ const char *ANSI_INPUT = NULL; const char *ANSI_ERROR = NULL; const char **ANSI_LABEL = NULL; const char *ANSI_RESET = "\001\e[0m\002"; +const char *ANSI_TOPIC = NULL; +const char *ANSI_POSITIVE = NULL; +const char *ANSI_NEGATIVE = NULL; const char *ANSI_LABEL_none[] = {"", ""}; @@ -62,6 +65,9 @@ const char *ANSI_LABEL_dark[] = { "\001\e[38;5;207m\002", "\001\e[38;5;219m\002", }; +const char ANSI_TOPIC_dark[] = "\001\e[93m\002"; +const char ANSI_POSITIVE_dark[] = "\001\e[92m\002"; +const char ANSI_NEGATIVE_dark[] = "\001\e[95m\002"; const char ANSI_URL_light[] = "\001\e[38;5;23m\002"; const char ANSI_MODULE_light[] = "\001\e[38;5;130m\002"; @@ -71,6 +77,9 @@ const char *ANSI_LABEL_light[] = { "\001\e[38;5;165m\002", "\001\e[38;5;171m\002", }; +const char ANSI_TOPIC_light[] = "\001\e[33m\002"; +const char ANSI_POSITIVE_light[] = "\001\e[32m\002"; +const char ANSI_NEGATIVE_light[] = "\001\e[35m\002"; char prompt[200]; @@ -589,6 +598,9 @@ void set_no_colour(void) ANSI_ERROR = ""; ANSI_LABEL = ANSI_LABEL_none; ANSI_RESET = ""; + ANSI_TOPIC = ""; + ANSI_POSITIVE = ""; + ANSI_NEGATIVE = ""; } static void set_bg_light(void) @@ -598,6 +610,9 @@ static void set_bg_light(void) ANSI_INPUT = ANSI_INPUT_light; ANSI_ERROR = ANSI_ERROR_light; ANSI_LABEL = ANSI_LABEL_light; + ANSI_TOPIC = ANSI_TOPIC_light; + ANSI_POSITIVE = ANSI_POSITIVE_light; + ANSI_NEGATIVE = ANSI_NEGATIVE_light; } static void set_bg_dark(void) @@ -607,6 +622,9 @@ static void set_bg_dark(void) ANSI_INPUT = ANSI_INPUT_dark; ANSI_ERROR = ANSI_ERROR_dark; ANSI_LABEL = ANSI_LABEL_dark; + ANSI_TOPIC = ANSI_TOPIC_dark; + ANSI_POSITIVE = ANSI_POSITIVE_dark; + ANSI_NEGATIVE = ANSI_NEGATIVE_dark; } diff --git a/apps/mosquitto_ctrl/ctrl_shell.h b/apps/mosquitto_ctrl/ctrl_shell.h index 0295c6d5..0acb5ff1 100644 --- a/apps/mosquitto_ctrl/ctrl_shell.h +++ b/apps/mosquitto_ctrl/ctrl_shell.h @@ -31,6 +31,9 @@ extern const char *ANSI_INPUT; extern const char *ANSI_ERROR; extern const char **ANSI_LABEL; extern const char *ANSI_RESET; +extern const char *ANSI_TOPIC; +extern const char *ANSI_POSITIVE; +extern const char *ANSI_NEGATIVE; /* This relatively complex structure is used to store the command tree. It * allows for commands to be shared between different parts of the tree, and diff --git a/apps/mosquitto_ctrl/ctrl_shell_dynsec.c b/apps/mosquitto_ctrl/ctrl_shell_dynsec.c index 67b3b463..70a49dc0 100644 --- a/apps/mosquitto_ctrl/ctrl_shell_dynsec.c +++ b/apps/mosquitto_ctrl/ctrl_shell_dynsec.c @@ -915,7 +915,8 @@ static void print_role(cJSON *j_data) && json_get_bool(j_acl, "allow", &allow, false, false) == MOSQ_ERR_SUCCESS ){ - ctrl_shell_print_value(1, "%-*s %s %s (priority %d)\n", (int)strlen("publishClientReceive"), acltype, allow?"allow":"deny ", topic, priority); + const char *ANSI_ALLOW = allow?ANSI_POSITIVE:ANSI_NEGATIVE; + ctrl_shell_print_value(1, "%-*s %s%s%s %s%s%s (priority %d)\n", (int)strlen("publishClientReceive"), acltype, ANSI_ALLOW, allow?"allow":"deny", ANSI_RESET, ANSI_TOPIC, topic, ANSI_RESET, priority); } } }