Skip to content

Commit

Permalink
shared/shell: Add bt_shell_echo
Browse files Browse the repository at this point in the history
This adds bt_shell_echo which can be used to print messages on the echo
area.
  • Loading branch information
Vudentz committed Dec 14, 2022
1 parent 89b2072 commit 7b8c87c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/shared/shell.c
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/shared/shell.h
Expand Up @@ -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);

Expand Down

0 comments on commit 7b8c87c

Please sign in to comment.