sys/shell: ensure character is flushed when echoing.

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.)
This commit is contained in:
Juan Carrano 2018-12-18 14:49:28 +01:00
parent d4fd6076c4
commit b34dc3a565

View File

@ -44,6 +44,13 @@ static void _putchar(int c) {
#endif #endif
#endif #endif
static void flush_if_needed(void)
{
#ifdef MODULE_NEWLIB
fflush(stdout);
#endif
}
static shell_command_handler_t find_handler(const shell_command_t *command_list, char *command) static shell_command_handler_t find_handler(const shell_command_t *command_list, char *command)
{ {
const shell_command_t *command_lists[] = { const shell_command_t *command_lists[] = {
@ -265,6 +272,7 @@ static int readline(char *buf, size_t size)
_putchar(c); _putchar(c);
#endif #endif
} }
flush_if_needed();
} }
} }
@ -275,9 +283,7 @@ static inline void print_prompt(void)
_putchar(' '); _putchar(' ');
#endif #endif
#ifdef MODULE_NEWLIB flush_if_needed();
fflush(stdout);
#endif
} }
void shell_run(const shell_command_t *shell_commands, char *line_buf, int len) void shell_run(const shell_command_t *shell_commands, char *line_buf, int len)