From 3766ebbd70a1931aa471945b0e5b07ce07eeed95 Mon Sep 17 00:00:00 2001 From: Guillaume Souchere Date: Wed, 17 Apr 2024 10:17:52 +0200 Subject: [PATCH] fix(console): bug where backspace erases the prompt in dumb mode --- components/console/linenoise/linenoise.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/components/console/linenoise/linenoise.c b/components/console/linenoise/linenoise.c index 3a94e81b00..ed031fb401 100644 --- a/components/console/linenoise/linenoise.c +++ b/components/console/linenoise/linenoise.c @@ -1120,9 +1120,15 @@ static int linenoiseDumb(char* buf, size_t buflen, const char* prompt) { } else if (c == BACKSPACE || c == 0x8) { if (count > 0) { buf[count - 1] = 0; - count --; + count--; + + /* Only erase symbol echoed from stdin. */ + fputs("\x08 ", stdout); /* Windows CMD: erase symbol under cursor */ + flushWrite(); + } else { + /* Consume backspace if the command line is empty to avoid erasing the prompt */ + continue; } - fputs("\x08 ", stdout); /* Windows CMD: erase symbol under cursor */ } else { buf[count] = c; ++count;