Skip to content

Commit

Permalink
sys/shell: ensure character is flushed when echoing.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jcarrano committed Dec 18, 2018
1 parent d4fd607 commit 64900f8
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions sys/shell/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ static void _putchar(int c) {
#endif
#endif

#ifdef MODULE_NEWLIB
#define flush_if_needed() (fflush(stdout))
#else
#define flush_if_needed()
#endif

static shell_command_handler_t find_handler(const shell_command_t *command_list, char *command)
{
const shell_command_t *command_lists[] = {
Expand Down Expand Up @@ -263,6 +269,7 @@ static int readline(char *buf, size_t size)
*line_buf_ptr++ = c;
#ifndef SHELL_NO_ECHO
_putchar(c);
flush_if_needed();
#endif
}
}
Expand All @@ -275,9 +282,7 @@ static inline void print_prompt(void)
_putchar(' ');
#endif

#ifdef MODULE_NEWLIB
fflush(stdout);
#endif
flush_if_needed();
}

void shell_run(const shell_command_t *shell_commands, char *line_buf, int len)
Expand Down

0 comments on commit 64900f8

Please sign in to comment.