diff options
author | Damien George <damien.p.george@gmail.com> | 2015-02-13 15:04:53 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-02-13 15:04:53 +0000 |
commit | 0b32e50365b6e36474e183a7240ccfc8fa56830a (patch) | |
tree | 101cf35f6844c50672af4f15b5866e226bcb47d9 /lib/mp-readline/readline.c | |
parent | c385a639e6316cba4ff0e7a859325807857d8f00 (diff) | |
download | micropython-0b32e50365b6e36474e183a7240ccfc8fa56830a.tar.gz micropython-0b32e50365b6e36474e183a7240ccfc8fa56830a.zip |
stmhal: Make pybstdio usable by other ports, and use it.
Now all ports can use pybstdio.c to provide sys.stdin/stdout/stderr, so
long as they implement mp_hal_stdin_* and mp_hal_stdout_* functions.
Diffstat (limited to 'lib/mp-readline/readline.c')
-rw-r--r-- | lib/mp-readline/readline.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/lib/mp-readline/readline.c b/lib/mp-readline/readline.c index 2bbbc5385d..53376708f8 100644 --- a/lib/mp-readline/readline.c +++ b/lib/mp-readline/readline.c @@ -30,7 +30,7 @@ #include "py/mpstate.h" #include "readline.h" -#include "pybstdio.h" +#include MICROPY_HAL_H #if 0 // print debugging info #define DEBUG_PRINT (1) @@ -60,20 +60,20 @@ STATIC char *str_dup_maybe(const char *str) { STATIC void move_cursor_back(uint pos) { if (pos <= 4) { // fast path for most common case of 1 step back - stdout_tx_strn("\b\b\b\b", pos); + mp_hal_stdout_tx_strn("\b\b\b\b", pos); } else { char vt100_command[6]; // snprintf needs space for the terminating null character int n = snprintf(&vt100_command[0], sizeof(vt100_command), "\x1b[%u", pos); if (n > 0) { vt100_command[n] = 'D'; // replace null char - stdout_tx_strn(vt100_command, n + 1); + mp_hal_stdout_tx_strn(vt100_command, n + 1); } } } STATIC void erase_line_from_cursor(void) { - stdout_tx_strn("\x1b[K", 3); + mp_hal_stdout_tx_strn("\x1b[K", 3); } typedef struct _readline_t { @@ -107,7 +107,7 @@ int readline_process_char(int c) { goto end_key; } else if (c == '\r') { // newline - stdout_tx_str("\r\n"); + mp_hal_stdout_tx_str("\r\n"); if (rl.line->len > rl.orig_line_len && (MP_STATE_PORT(readline_hist)[0] == NULL || strcmp(MP_STATE_PORT(readline_hist)[0], rl.line->buf + rl.orig_line_len) != 0)) { // a line which is not empty and different from the last one // so update the history @@ -245,13 +245,13 @@ end_key: erase_line_from_cursor(); } // draw new chars - stdout_tx_strn(rl.line->buf + rl.cursor_pos, rl.line->len - rl.cursor_pos); + mp_hal_stdout_tx_strn(rl.line->buf + rl.cursor_pos, rl.line->len - rl.cursor_pos); // move cursor forward if needed (already moved forward by length of line, so move it back) move_cursor_back(rl.line->len - (rl.cursor_pos + redraw_step_forward)); rl.cursor_pos += redraw_step_forward; } else if (redraw_step_forward > 0) { // draw over old chars to move cursor forwards - stdout_tx_strn(rl.line->buf + rl.cursor_pos, redraw_step_forward); + mp_hal_stdout_tx_strn(rl.line->buf + rl.cursor_pos, redraw_step_forward); rl.cursor_pos += redraw_step_forward; } @@ -273,10 +273,10 @@ void readline_init(vstr_t *line) { } int readline(vstr_t *line, const char *prompt) { - stdout_tx_str(prompt); + mp_hal_stdout_tx_str(prompt); readline_init(line); for (;;) { - int c = stdin_rx_chr(); + int c = mp_hal_stdin_rx_chr(); int r = readline_process_char(c); if (r >= 0) { return r; |