Skip to contentSkip to conversation

shell: Fix artifacts when asking for user input

PATCH Applied Luiz Augusto von Dentz 1 participant 2 messages Nov 22, 2018 – Nov 26, 2018 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/1 shell: Fix artifacts when asking for user input

From: Luiz Augusto von Dentz <[email protected]>

Instead of printing a message use set the new prompt so it is carried over when new lines are printed. Unfortunately this has some drawbacks as apparently readline is not really able to redisplay properly if the prompt contain colors.

---
 src/shared/shell.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
src/shared/shell.c +6 -2
index 89a2e82bc..aabbc5d0e 100644
@@ -562,6 +562,8 @@ void bt_shell_usage()
 void bt_shell_prompt_input(const char *label, const char *msg,
 			bt_shell_prompt_input_func func, void *user_data)
 {
+	char *str;
+
 	if (!data.init || data.mode)
 		return;
 
@@ -573,9 +575,11 @@ void bt_shell_prompt_input(const char *label, const char *msg,
 	data.saved_prompt = true;
 	data.saved_func = func;
 	data.saved_user_data = user_data;
+	asprintf(&str, "[%s] %s ", label, msg);
 
 	rl_save_prompt();
-	bt_shell_printf(COLOR_RED "[%s]" COLOR_OFF " %s ", label, msg);
+	bt_shell_set_prompt(str);
+	free(str);
 }
 
 int bt_shell_release_prompt(const char *input)
@@ -1209,7 +1213,7 @@ void bt_shell_set_prompt(const char *string)
 		return;
 
 	rl_set_prompt(string);
-	bt_shell_printf("\r");
+	rl_redisplay();
 }
 
 static bool input_read(struct io *io, void *user_data)
Signature · 1 line
2.17.2
author maintainer Applied
#1 lore raw

Hi,

Quoted 47 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Instead of printing a message use set the new prompt so it is carried over when new lines are printed. Unfortunately this has some drawbacks as apparently readline is not really able to redisplay properly if the prompt contain colors.

---
 src/shared/shell.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
src/shared/shell.c +6 -3
index 89a2e82bc..aabbc5d0e 100644
@@ -562,6 +562,8 @@ void bt_shell_usage()
 void bt_shell_prompt_input(const char *label, const char *msg,
                        bt_shell_prompt_input_func func, void *user_data)
 {
+       char *str;
+
        if (!data.init || data.mode)
                return;
 
@@ -573,9 +575,11 @@ void bt_shell_prompt_input(const char *label, const char *msg,
        data.saved_prompt = true;
        data.saved_func = func;
        data.saved_user_data = user_data;
+       asprintf(&str, "[%s] %s ", label, msg);
 
        rl_save_prompt();
-       bt_shell_printf(COLOR_RED "[%s]" COLOR_OFF " %s ", label, msg);
+       bt_shell_set_prompt(str);
+       free(str);
 }
 
 int bt_shell_release_prompt(const char *input)
@@ -1209,7 +1213,7 @@ void bt_shell_set_prompt(const char *string)
                return;
 
        rl_set_prompt(string);
-       bt_shell_printf("\r");
+       rl_redisplay();
 }
 
 static bool input_read(struct io *io, void *user_data)
--
Quoted 1 line

2.17.2

Applied.

Signature · 1 line
Luiz Augusto von Dentz