Skip to content

Commit

Permalink
shared/shell: Remove readline color escapes
Browse files Browse the repository at this point in the history
This removes readline color escapes from color defines and instead only
used them with prompt since they are only really useful when readline
is rendering the text, so it can calculate the prompt length properly.

Fixes: #10
  • Loading branch information
Vudentz committed Nov 17, 2023
1 parent 8b035b7 commit d8fc0dd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
10 changes: 9 additions & 1 deletion src/shared/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -1419,10 +1419,18 @@ bool bt_shell_add_submenu(const struct bt_shell_menu *menu)

void bt_shell_set_prompt(const char *string)
{
char *prompt;

if (!data.init || data.mode)
return;

rl_set_prompt(string);
if (asprintf(&prompt, "\001%s\002", string) < 0)
rl_set_prompt(string);
else {
rl_set_prompt(prompt);
free(prompt);
}

rl_redisplay();
}

Expand Down
16 changes: 8 additions & 8 deletions src/shared/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
#include <getopt.h>
#include <stdbool.h>

#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"
#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"

struct bt_shell_menu;

Expand Down

0 comments on commit d8fc0dd

Please sign in to comment.