shared/shell: Fix colors not using proper escape sequence
Luiz Augusto von Dentz
maintainerPATCH 1/2 shared/shell: Fix colors not using proper escape sequence
From: Luiz Augusto von Dentz <[email protected]>
According to readline documentation \001 and \002 has to be used to delimit characters which takes no space:
'Applications may indicate that the prompt contains characters that take up no physical screen space when displayed by bracketing a sequence of such characters with the special markers RL_PROMPT_START_IGNORE' and RL_PROMPT_END_IGNORE'.'
--- src/shared/shell.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
src/shared/shell.h +8 -8
@@ -22,14 +22,14 @@*/ #include <getopt.h> -#define COLOR_OFF "\x1B[0m" -#define COLOR_RED "\x1B[0;91m" -#define COLOR_GREEN "\x1B[0;92m" -#define COLOR_YELLOW "\x1B[0;93m" -#define COLOR_BLUE "\x1B[0;94m" -#define COLOR_BOLDGRAY "\x1B[1;30m" -#define COLOR_BOLDWHITE "\x1B[1;37m" -#define COLOR_HIGHLIGHT "\x1B[1;39m" +#define COLOR_OFF "\001\x1B[0m\002" +#define COLOR_RED "\001\x1B[0;91m\002" +#define COLOR_GREEN "\001\x1B[0;92m\002" +#define COLOR_YELLOW "\001\x1B[0;93m\002" +#define COLOR_BLUE "\001\x1B[0;94m\002" +#define COLOR_BOLDGRAY "\001\x1B[1;30m\002" +#define COLOR_BOLDWHITE "\001\x1B[1;37m\002" +#define COLOR_HIGHLIGHT "\001\x1B[1;39m\002"struct bt_shell_menu ;
Signature · 1 line
2.20.1
Luiz Augusto von Dentz
maintainerPATCH 2/2 shared/shell: Highlight user prompt input
From: Luiz Augusto von Dentz <[email protected]>
This makes them more evident compared to regular output which is now possible since coloring prompts should not produce artifacs anymore.
--- src/shared/shell.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
src/shared/shell.c +4 -2
@@ -592,7 +592,8 @@ void bt_shell_prompt_input(const char *label, const char *msg, prompt = new0(struct bt_shell_prompt_input, 1); -if (asprintf (&prompt->str,"[%s] %s " , label, msg) <0 ) { +if (asprintf (&str,COLOR_HIGHLIGHT "[%s] %s " COLOR_OFF , label, + msg) <0 ) {free (prompt);return ; }
@@ -605,7 +606,8 @@ void bt_shell_prompt_input(const char *label, const char *msg,return ; } -if (asprintf (&str,"[%s] %s " , label, msg) <0 ) +if (asprintf (&str,COLOR_HIGHLIGHT "[%s] %s " COLOR_OFF , label, + msg) <0 )return ;prompt_input (str, func, user_data);
Signature · 1 line
2.20.1