Linux-Bluetooth Archive on lore.kernel.org
 help / Atom feed
* [PATCH BlueZ] shell: Fix artifacts when asking for user input
@ 2018-11-22 16:02 Luiz Augusto von Dentz
  2018-11-26 11:28 ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 2+ messages in thread
From: Luiz Augusto von Dentz @ 2018-11-22 16:02 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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(-)

diff --git a/src/shared/shell.c b/src/shared/shell.c
index 89a2e82bc..aabbc5d0e 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -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)
-- 
2.17.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH BlueZ] shell: Fix artifacts when asking for user input
  2018-11-22 16:02 [PATCH BlueZ] shell: Fix artifacts when asking for user input Luiz Augusto von Dentz
@ 2018-11-26 11:28 ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 2+ messages in thread
From: Luiz Augusto von Dentz @ 2018-11-26 11:28 UTC (permalink / raw)
  To: linux-bluetooth

Hi,
On Thu, Nov 22, 2018 at 6:02 PM Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
>
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> 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(-)
>
> diff --git a/src/shared/shell.c b/src/shared/shell.c
> index 89a2e82bc..aabbc5d0e 100644
> --- a/src/shared/shell.c
> +++ b/src/shared/shell.c
> @@ -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)
> --
> 2.17.2

Applied.

-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-22 16:02 [PATCH BlueZ] shell: Fix artifacts when asking for user input Luiz Augusto von Dentz
2018-11-26 11:28 ` Luiz Augusto von Dentz

Linux-Bluetooth Archive on lore.kernel.org

Archives are clonable: git clone --mirror https://lore.kernel.org/linux-bluetooth/0 linux-bluetooth/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-bluetooth linux-bluetooth/ https://lore.kernel.org/linux-bluetooth \
		linux-bluetooth@vger.kernel.org linux-bluetooth@archiver.kernel.org
	public-inbox-index linux-bluetooth


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-bluetooth


AGPL code for this site: git clone https://public-inbox.org/ public-inbox