From beadb6d72c018c447d28652ab00b24c542eeadca Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Thu, 12 Feb 2015 13:14:13 +0200 Subject: [PATCH] tools/btmgmt: Add index-dependent prompt --- tools/btmgmt.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tools/btmgmt.c b/tools/btmgmt.c index 6d5fcb932..15152b1d4 100644 --- a/tools/btmgmt.c +++ b/tools/btmgmt.c @@ -83,6 +83,26 @@ static int pending_index = 0; #define PROMPT_ON COLOR_BLUE "[mgmt]" COLOR_OFF "# " +static void update_prompt(uint16_t index) +{ + char str[32]; + + if (index == MGMT_INDEX_NONE) + snprintf(str, sizeof(str), "%s# ", + COLOR_BLUE "[mgmt]" COLOR_OFF); + else + snprintf(str, sizeof(str), + COLOR_BLUE "[hci%u]" COLOR_OFF "# ", index); + + if (saved_prompt) { + free(saved_prompt); + saved_prompt = strdup(str); + return; + } + + rl_set_prompt(str); +} + static void noninteractive_quit(int status) { if (interactive) @@ -3340,6 +3360,8 @@ static void cmd_select(struct mgmt *mgmt, uint16_t index, register_mgmt_callbacks(mgmt, mgmt_index); print("Selected index %u", mgmt_index); + + update_prompt(mgmt_index); } static struct cmd_info interactive_cmd[] = { @@ -3604,7 +3626,7 @@ int main(int argc, char *argv[]) rl_erase_empty_line = 1; rl_callback_handler_install(NULL, rl_handler); - rl_set_prompt(PROMPT_ON); + update_prompt(index); rl_redisplay(); } -- 2.47.3