diff mbox series

[BlueZ,v2,2/5] shared/shell: Add bt_shell_echo

Message ID 20221215211037.2686489-2-luiz.dentz@gmail.com
State New
Headers show
Series [BlueZ,v2,1/5] client/player: Make transport.send non-blocking | expand

Commit Message

Luiz Augusto von Dentz Dec. 15, 2022, 9:10 p.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds bt_shell_echo which can be used to print messages on the echo
area.
---
 src/shared/shell.c | 20 ++++++++++++++++++++
 src/shared/shell.h |  2 ++
 2 files changed, 22 insertions(+)
diff mbox series

Patch

diff --git a/src/shared/shell.c b/src/shared/shell.c
index 0639c786d983..3c0e61dbc414 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -576,6 +576,26 @@  void bt_shell_printf(const char *fmt, ...)
 	}
 }
 
+void bt_shell_echo(const char *fmt, ...)
+{
+	va_list args;
+	char *str;
+	int err;
+
+	va_start(args, fmt);
+	err = vasprintf(&str, fmt, args);
+	if (!err)
+		err = asprintf(&str, COLOR_HIGHLIGHT "%s#" COLOR_OFF, str);
+	va_end(args);
+
+	if (err)
+		return;
+
+	rl_save_prompt();
+	bt_shell_set_prompt(str);
+	rl_restore_prompt();
+}
+
 static void print_string(const char *str, void *user_data)
 {
 	bt_shell_printf("%s\n", str);
diff --git a/src/shared/shell.h b/src/shared/shell.h
index 8baa2854a250..87fb5c415f20 100644
--- a/src/shared/shell.h
+++ b/src/shared/shell.h
@@ -70,6 +70,8 @@  void bt_shell_set_prompt(const char *string);
 
 void bt_shell_printf(const char *fmt,
 				...) __attribute__((format(printf, 1, 2)));
+void bt_shell_echo(const char *fmt,
+				...) __attribute__((format(printf, 1, 2)));
 void bt_shell_hexdump(const unsigned char *buf, size_t len);
 void bt_shell_usage(void);