This change is in preparation to [PR 10788]. PR 10788 will make the
shell exitable which may lead to unexpected behavior in comparison to
previous usage of the shell.
To prevent this, this PR introduces two "new" functions to the shell's
API: `shell_run_once()` and `shell_run_forever()`.
`shell_run_once()` basically has the same behavior as `shell_run()` in
current master: Start a shell and continue reading lines until EOF is
reached.
`shell_run_forever()` wraps around `shell_run_once()` and restarts the
shell if it exits.
`shell_run()` is re-introduced as a back-porting alias for
`shell_run_forever()`.
As a consequence all current calls to `shell_run()` won't exit even
with [PR 10788] merged (which would add EOT as additional exit
condition for `shell_run_once()`).
[PR 10788]: https://github.com/RIOT-OS/RIOT/pull/10788
CTRL-C cancels the current line, similar to how getty works.
This is useful if one is using a dumb terminal to communicate with
a node, as it saves having to repeatedly type backspace to discard the
current line. It also helps when connecting to an already running node,
as one does not know what is on the line buffer, the safest thing to do
is to begin by sending a ctrl-C.
This is a suggestion of @benemorius.
When using a serial terminal without local echo, the current line
would not get updated as the user typed because the shell module's
readline() was not flushing each character.
This commit fixes that behavior. For additional clarity, fflush is
turned into a macro (flush_if_needed) which expands to either a call
to fflush() or empty, according to the standard library used.
This also fixes the erase/line editing behavior (the delete characters
were not being flushed either.)
In RIOT native, sending CTRL+D to a shell started using shell_run would resulted in and
endless prompt loop. I've been unable to trigger such a behaviour
on actual hardware using a UART connection, but calling `pm_off` seemed
like a better alternative than having an `#ifdef BOARD_NATIVE`.
Fixes#9946
When SHELL_NO_ECHO was defined and not SHELL_NO_PROMPT build was broken
because _putchar was not defined.
This define _putchar when one of SHELL_NO_PROMPT or SHELL_NO_ECHO is not
defined.
changed from void(*put_char)(int) to int(*putchar)(int).
This is beneficial, as now the std-libs putchar can be given as
an argument to shell_init() directly.
Per #708.
This patch allows escaped characters in the shell, and makes the
apostrophe a quotation mark. The escape character is backslash.
The term "escape character" is used liberally in here: if a backslash is
encountered in the command line, the next character will be taken
verbatim. No escape sequences are understood, i.e. `"\n"` is just the
letter `n`, not a new line.
Compare #708.
Now the tokenization of an input line is done by the shell itself. You
may quote arguments with `"..."`. Empty arguments, supplied by `""` are
preserved. Spaces in between arguments are squasheds; spaces inside
quotes are preserved.
You cannot partially quote an argument. You must not use
- `cmd "abc`,
- `cmd abc"def"`, or
- `cmd "abc"def`.
before, we actually duplicated code for handling of shell commands
supplied to shell_init and those hardcoded by MODULE_SHELL_COMMANDS.
This patch refactors shell.c find_handler and print_help so there's
no duplicated code.