Skip to content

Commit bfabdf1

Browse files
aescolarAnas Nashif
authored andcommitted
shell: Added noprompt command
Added noprompt command to shell. It will disable printing the prompt. For the native port, when feeding commands from a file or pipe the prompt reprinting after each command (without echoing) just confuses the user. Signed-off-by: Alberto Escolar Piedras <[email protected]>
1 parent 6ef85ed commit bfabdf1

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

doc/subsystems/shell.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ Select module commands
5353
``select``
5454
Clears selected module. Restores prompt as well.
5555

56+
Other commands
57+
==============
58+
59+
``noprompt``
60+
This command will disable the shell prompt. The shell will still be fully
61+
functional, but the prompt will not be printed each time the shell expects a
62+
new command.
63+
5664
Shell configuration
5765
*******************
5866
There are two levels of configuration: Infrastructure level and Module level.

subsys/shell/shell.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ extern struct shell_cmd __shell_cmd_end[];
5151
static const char *prompt;
5252
static char default_module_prompt[PROMPT_MAX_LEN];
5353
static struct shell_module *default_module;
54+
static bool no_promt;
5455

5556
#define STACKSIZE CONFIG_CONSOLE_SHELL_STACKSIZE
5657
static K_THREAD_STACK_DEFINE(stack, STACKSIZE);
@@ -338,6 +339,16 @@ static int cmd_exit(int argc, char *argv[])
338339
return 0;
339340
}
340341

342+
static int cmd_noprompt(int argc, char *argv[])
343+
{
344+
no_promt = true;
345+
return 0;
346+
}
347+
348+
#define SHELL_CMD_NOPROMPT "noprompt"
349+
SHELL_REGISTER_COMMAND(SHELL_CMD_NOPROMPT, cmd_noprompt,
350+
"Disable shell prompt");
351+
341352
static const struct shell_cmd *get_internal(const char *command)
342353
{
343354
static const struct shell_cmd internal_commands[] = {
@@ -350,7 +361,6 @@ static const struct shell_cmd *get_internal(const char *command)
350361
return get_cmd(internal_commands, command);
351362
}
352363

353-
354364
int shell_exec(char *line)
355365
{
356366
char *argv[ARGC_MAX + 1], **argv_start = argv;
@@ -424,11 +434,13 @@ static void shell(void *p1, void *p2, void *p3)
424434
while (1) {
425435
struct console_input *cmd;
426436

427-
printk("%s", get_prompt());
437+
if (!no_promt) {
438+
printk("%s", get_prompt());
428439
#if defined(CONFIG_NATIVE_POSIX_CONSOLE)
429-
/* The native printk driver is line buffered */
430-
posix_flush_stdout();
440+
/* The native printk driver is line buffered */
441+
posix_flush_stdout();
431442
#endif
443+
}
432444

433445
cmd = k_fifo_get(&cmds_queue, K_FOREVER);
434446

0 commit comments

Comments
 (0)