From faaac450436aa84b82272594005504f523a87e2c Mon Sep 17 00:00:00 2001 From: Jade Mattsson Date: Fri, 1 Mar 2024 12:27:32 +1100 Subject: [PATCH] Switch to single-byte console reads. --- components/base_nodemcu/user_main.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/components/base_nodemcu/user_main.c b/components/base_nodemcu/user_main.c index e208c706f..42fba0d20 100644 --- a/components/base_nodemcu/user_main.c +++ b/components/base_nodemcu/user_main.c @@ -148,14 +148,18 @@ static void nodemcu_init(void) static void console_task(void *) { - char linebuf[64]; for (;;) { - ssize_t n = read(fileno(stdin), linebuf, sizeof(linebuf)); + /* We can't use a large read buffer here as some console choices + * (e.g. usb-serial-jtag) don't support read timeouts/partial reads, + * which breaks the echo support and makes for a bad user experience. + */ + char c; + ssize_t n = read(fileno(stdin), &c, 1); if (n > 0) { // If we want to honor run_input, we'd need to check the return val - feed_lua_input(linebuf, n); + feed_lua_input(&c, 1); // The IDF doesn't seem to honor setvbuf(stdout, NULL, _IONBF, 0) :( fsync(fileno(stdout)); }