Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys/shell: document configs and add them to Kconfig #15918

Merged
merged 1 commit into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion sys/include/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,63 @@
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
* 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.
*/
# 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)
*/
Expand Down
23 changes: 23 additions & 0 deletions sys/shell/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 5 additions & 16 deletions sys/shell/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <assert.h>
#include <errno.h>

#include "kernel_defines.h"
#include "shell.h"
#include "shell_commands.h"

Expand All @@ -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
Expand Down Expand Up @@ -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('>');
leandrolanzieri marked this conversation as resolved.
Show resolved Hide resolved
putchar(' ');
}
Expand All @@ -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');
Expand All @@ -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');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/gnrc_tcp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion tests/test_tools/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
#include <string.h>
#include <ctype.h>

#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

Expand Down