From 410757f4f4d0ba6a6e2a80d3ef7f86317339c54c Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 20 Feb 2020 00:45:58 +1100 Subject: [PATCH] unix/mphalport.h: Fix build when MICROPY_USE_READLINE=0. If the built-in input() is enabled (which it is by default) then it needs some form of readline, so supply it with one when MICROPY_USE_READLINE=0. Fixes issue #5658. --- ports/unix/mphalport.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ports/unix/mphalport.h b/ports/unix/mphalport.h index e3e045aed..cb86e7048 100644 --- a/ports/unix/mphalport.h +++ b/ports/unix/mphalport.h @@ -35,7 +35,21 @@ void mp_hal_set_interrupt_char(char c); void mp_hal_stdio_mode_raw(void); void mp_hal_stdio_mode_orig(void); -#if MICROPY_USE_READLINE == 1 && MICROPY_PY_BUILTINS_INPUT +#if MICROPY_PY_BUILTINS_INPUT && MICROPY_USE_READLINE == 0 + +#include +#include "py/misc.h" +#include "input.h" +#define mp_hal_readline mp_hal_readline +static inline int mp_hal_readline(vstr_t *vstr, const char *p) { + char *line = prompt((char*)p); + vstr_add_str(vstr, line); + free(line); + return 0; +} + +#elif MICROPY_PY_BUILTINS_INPUT && MICROPY_USE_READLINE == 1 + #include "py/misc.h" #include "lib/mp-readline/readline.h" // For built-in input() we need to wrap the standard readline() to enable raw mode @@ -46,6 +60,7 @@ static inline int mp_hal_readline(vstr_t *vstr, const char *p) { mp_hal_stdio_mode_orig(); return ret; } + #endif // TODO: POSIX et al. define usleep() as guaranteedly capable only of 1s sleep: