Skip to content

Commit 5430400

Browse files
heghehenrikbrixandersen
authored andcommitted
shell: add option to toggle logs output
When logging through shell is enabled, it is inconvenient to use the shell when there are logs coming in. Having a mechanism for easy disabling/re-enabling the shell logs is a nice quality of life feature. To toggle the logs, `CTRL+T` combination can be used. This is available only when meta key feature is enabled. Signed-off-by: Heghedus Razvan <[email protected]>
1 parent 78197c6 commit 5430400

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

doc/services/shell/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,8 @@ The shell module supports the following meta keys:
664664
- Moves in history to next entry.
665665
* - :kbd:`Ctrl+p`
666666
- Moves in history to previous entry.
667+
* - :kbd:`Ctrl+t`
668+
- Toggles logs output on the shell when :kconfig:option:`CONFIG_SHELL_LOG_BACKEND` is set.
667669
* - :kbd:`Ctrl+u`
668670
- Clears the currently typed command.
669671
* - :kbd:`Ctrl+w`

subsys/shell/shell.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,21 @@ static int execute(const struct shell *sh)
812812
&argv[cmd_with_handler_lvl], &help_entry);
813813
}
814814

815+
static void toggle_logs_output(const struct shell *sh)
816+
{
817+
const struct shell_log_backend *backend = sh->log_backend;
818+
819+
if (!IS_ENABLED(CONFIG_SHELL_LOG_BACKEND)) {
820+
return;
821+
}
822+
823+
if (backend->control_block->state == SHELL_LOG_BACKEND_ENABLED) {
824+
z_shell_log_backend_disable(backend);
825+
} else if (backend->control_block->state == SHELL_LOG_BACKEND_DISABLED) {
826+
z_shell_log_backend_enable(backend, (void *)sh, sh->ctx->log_level);
827+
}
828+
}
829+
815830
static void tab_handle(const struct shell *sh)
816831
{
817832
const char *__argv[CONFIG_SHELL_ARGC_MAX + 1];
@@ -926,6 +941,10 @@ static void ctrl_metakeys_handle(const struct shell *sh, char data)
926941
history_handle(sh, true);
927942
break;
928943

944+
case SHELL_VT100_ASCII_CTRL_T: /* CTRL + T */
945+
toggle_logs_output(sh);
946+
break;
947+
929948
case SHELL_VT100_ASCII_CTRL_U: /* CTRL + U */
930949
z_shell_op_cursor_home_move(sh);
931950
cmd_buffer_clear(sh);
@@ -1840,7 +1859,7 @@ static int cmd_help(const struct shell *sh, size_t argc, char **argv)
18401859
#if defined(CONFIG_SHELL_METAKEYS)
18411860
shell_print(sh,
18421861
"\nShell supports following meta-keys:\n"
1843-
" Ctrl + (a key from: abcdefklnpuw)\n"
1862+
" Ctrl + (a key from: abcdefklnptuw)\n"
18441863
" Alt + (a key from: bf)\n"
18451864
"Please refer to shell documentation for more details.");
18461865
#endif

subsys/shell/shell_vt100.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define SHELL_VT100_ASCII_CTRL_L (0x0C)
2121
#define SHELL_VT100_ASCII_CTRL_N (0x0E)
2222
#define SHELL_VT100_ASCII_CTRL_P (0x10)
23+
#define SHELL_VT100_ASCII_CTRL_T (0x14)
2324
#define SHELL_VT100_ASCII_CTRL_U (0x15)
2425
#define SHELL_VT100_ASCII_CTRL_W (0x17)
2526
#define SHELL_VT100_ASCII_ALT_B (0x62)

0 commit comments

Comments
 (0)