diff --git a/sys/include/shell.h b/sys/include/shell.h index e44c6ebb00ed..644ab6fb806f 100644 --- a/sys/include/shell.h +++ b/sys/include/shell.h @@ -29,8 +29,15 @@ extern "C" { #endif +/** + * @defgroup sys_shell_config Shell compile time configurations + * @ingroup config + * @{ + */ /** * @brief Shutdown RIOT on shell exit + * + * @note On native platform this option defaults to 1. */ #ifndef CONFIG_SHELL_SHUTDOWN_ON_EXIT /* Some systems (e.g Ubuntu 20.04) close stdin on CTRL-D / EOF @@ -38,11 +45,47 @@ extern "C" { * Instead terminate RIOT, which is also the behavior a user would * expect from a CLI application. */ -# ifdef CPU_NATIVE +# if defined(CPU_NATIVE) && !IS_ACTIVE(KCONFIG_MODULE_SHELL) # define CONFIG_SHELL_SHUTDOWN_ON_EXIT 1 +# else +# define CONFIG_SHELL_SHUTDOWN_ON_EXIT 0 # endif #endif +/** + * @brief Set to 1 to disable shell's echo + */ +#ifndef CONFIG_SHELL_NO_ECHO +#define CONFIG_SHELL_NO_ECHO 0 +#endif + +/** + * @brief Set to 1 to disable shell's prompt + */ +#ifndef CONFIG_SHELL_NO_PROMPT +#define CONFIG_SHELL_NO_PROMPT 0 +#endif + +/** + * @brief Set to 1 to disable shell's echo + * @deprecated This has been replaced by @ref CONFIG_SHELL_NO_ECHO and will be + * removed after release 2021.07. + */ +#ifndef SHELL_NO_ECHO +#define SHELL_NO_ECHO CONFIG_SHELL_NO_ECHO +#endif + +/** + * @brief Set to 1 to disable shell's prompt + * @deprecated This has been replaced by @ref CONFIG_SHELL_NO_PROMPT and will be + * removed after release 2021.07. + */ +#ifndef SHELL_NO_PROMPT +#define SHELL_NO_PROMPT CONFIG_SHELL_NO_PROMPT +#endif + +/** @} */ + /** * @brief Default shell buffer size (maximum line length shell can handle) */ diff --git a/sys/shell/Kconfig b/sys/shell/Kconfig index 454093dfd6e2..1a024ec4fb16 100644 --- a/sys/shell/Kconfig +++ b/sys/shell/Kconfig @@ -11,3 +11,26 @@ menuconfig MODULE_SHELL depends on TEST_KCONFIG rsource "commands/Kconfig" + +menuconfig KCONFIG_MODULE_SHELL + bool "Configure the Shell interpreter" + depends on USEMODULE_SHELL + +if KCONFIG_MODULE_SHELL + +config SHELL_SHUTDOWN_ON_EXIT + bool "Shutdown RIOT on shell exit" + default y if CPU_NATIVE + help + Some systems (e.g Ubuntu 20.04) close stdin on CTRL-D / EOF + That means we can't just re-start the shell. + Instead terminate RIOT, which is also the behavior a user would expect + from a CLI application. + +config SHELL_NO_ECHO + bool "Disable echo" + +config SHELL_NO_PROMPT + bool "Disable prompt" + +endif # KCONFIG_MODULE_SHELL diff --git a/sys/shell/shell.c b/sys/shell/shell.c index d03faac2e35e..bae4cda24fbf 100644 --- a/sys/shell/shell.c +++ b/sys/shell/shell.c @@ -35,6 +35,7 @@ #include #include +#include "kernel_defines.h" #include "shell.h" #include "shell_commands.h" @@ -49,18 +50,6 @@ #define flush_if_needed() #endif /* MODULE_NEWLIB || MODULE_PICOLIBC */ -#ifndef SHELL_NO_ECHO - #define ECHO_ON 1 -#else - #define ECHO_ON 0 -#endif /* SHELL_NO_ECHO */ - -#ifndef SHELL_NO_PROMPT - #define PROMPT_ON 1 -#else - #define PROMPT_ON 0 -#endif /* SHELL_NO_PROMPT */ - #ifdef MODULE_SHELL_COMMANDS #define _builtin_cmds _shell_command_list #else @@ -343,7 +332,7 @@ __attribute__((weak)) void shell_post_command_hook(int ret, int argc, static inline void print_prompt(void) { - if (PROMPT_ON) { + if (!IS_ACTIVE(CONFIG_SHELL_NO_PROMPT) && !IS_ACTIVE(SHELL_NO_PROMPT)) { putchar('>'); putchar(' '); } @@ -353,14 +342,14 @@ static inline void print_prompt(void) static inline void echo_char(char c) { - if (ECHO_ON) { + if (!IS_ACTIVE(CONFIG_SHELL_NO_ECHO) && !IS_ACTIVE(SHELL_NO_ECHO)) { putchar(c); } } static inline void white_tape(void) { - if (ECHO_ON) { + if (!IS_ACTIVE(CONFIG_SHELL_NO_ECHO) && !IS_ACTIVE(SHELL_NO_ECHO)) { putchar('\b'); putchar(' '); putchar('\b'); @@ -369,7 +358,7 @@ static inline void white_tape(void) static inline void new_line(void) { - if (ECHO_ON) { + if (!IS_ACTIVE(CONFIG_SHELL_NO_ECHO) && !IS_ACTIVE(SHELL_NO_ECHO)) { putchar('\r'); putchar('\n'); } diff --git a/tests/gnrc_tcp/Makefile b/tests/gnrc_tcp/Makefile index c946fcdac0c7..bd1b2cd3b698 100644 --- a/tests/gnrc_tcp/Makefile +++ b/tests/gnrc_tcp/Makefile @@ -12,7 +12,7 @@ TIMEOUT_MS ?= 3000 # Suppress test execution to avoid CI errors TEST_ON_CI_BLACKLIST += all -CFLAGS += -DSHELL_NO_ECHO +CFLAGS += -DCONFIG_SHELL_NO_ECHO ifeq (native,$(BOARD)) TERMFLAGS ?= $(TAP) diff --git a/tests/test_tools/Makefile b/tests/test_tools/Makefile index eff1f887a108..bdbda5c3fe6a 100644 --- a/tests/test_tools/Makefile +++ b/tests/test_tools/Makefile @@ -4,7 +4,7 @@ include ../Makefile.tests_common USEMODULE += shell # Disable shell echo and prompt to not have them in the way for testing -CFLAGS += -DSHELL_NO_ECHO=1 -DSHELL_NO_PROMPT=1 +CFLAGS += -DCONFIG_SHELL_NO_ECHO=1 -DCONFIG_SHELL_NO_PROMPT=1 # No need for test_utils_interactive_sync in this test since the test # synchronizes by itself through `shellping` command. diff --git a/tests/test_tools/main.c b/tests/test_tools/main.c index 1051930c1bc6..b9bb1078b7d3 100644 --- a/tests/test_tools/main.c +++ b/tests/test_tools/main.c @@ -18,10 +18,11 @@ #include #include +#include "kernel_defines.h" #include "shell_commands.h" #include "shell.h" -#if !defined(SHELL_NO_ECHO) || !defined(SHELL_NO_PROMPT) +#if !IS_ACTIVE(CONFIG_SHELL_NO_ECHO) || !IS_ACTIVE(CONFIG_SHELL_NO_PROMPT) #error This test assumes no shell echo or shell prompt #endif