diff mbox series

[BlueZ,2/3] shared/shell: Add bt_shell_echo

Message ID 20221214002129.2105777-2-luiz.dentz@gmail.com (mailing list archive)
State Superseded
Headers show
Series [BlueZ,1/3] client/player: Make transport.send non-blocking | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/CheckPatch warning WARNING:PREFER_DEFINED_ATTRIBUTE_MACRO: Prefer __printf(1, 2) over __attribute__((format(printf, 1, 2))) #126: FILE: src/shared/shell.h:74: + ...) __attribute__((format(printf, 1, 2))); /github/workspace/src/src/13072605.patch total: 0 errors, 1 warnings, 29 lines checked NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace. /github/workspace/src/src/13072605.patch has style problems, please review. NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO NOTE: If any of the errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS.
tedd_an/GitLint success Gitlint PASS
tedd_an/IncrementalBuild fail [BlueZ,2/3] shared/shell: Add bt_shell_echo src/shared/shell.c: In function ‘bt_shell_echo’: src/shared/shell.c:585:2: error: ignoring return value of ‘vasprintf’, declared with attribute warn_unused_result [-Werror=unused-result] 585 | vasprintf(&str, fmt, args); | ^~~~~~~~~~~~~~~~~~~~~~~~~~ src/shared/shell.c:586:2: error: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Werror=unused-result] 586 | asprintf(&str, COLOR_HIGHLIGHT "%s" COLOR_OFF, str); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors make[1]: *** [Makefile:8276: src/shared/libshared_mainloop_la-shell.lo] Error 1 make[1]: *** Waiting for unfinished jobs.... make: *** [Makefile:4482: all] Error 2

Commit Message

Luiz Augusto von Dentz Dec. 14, 2022, 12:21 a.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 | 15 +++++++++++++++
 src/shared/shell.h |  2 ++
 2 files changed, 17 insertions(+)
diff mbox series

Patch

diff --git a/src/shared/shell.c b/src/shared/shell.c
index 0639c786d983..0045ac80ca6b 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -576,6 +576,21 @@  void bt_shell_printf(const char *fmt, ...)
 	}
 }
 
+void bt_shell_echo(const char *fmt, ...)
+{
+	va_list args;
+	char *str;
+
+	va_start(args, fmt);
+	vasprintf(&str, fmt, args);
+	asprintf(&str, COLOR_HIGHLIGHT "%s" COLOR_OFF, str);
+	va_end(args);
+
+	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);