From 6e883b89720a359e01f8a45a9ee84c2560c1618c Mon Sep 17 00:00:00 2001 From: Tw Date: Wed, 3 Dec 2025 19:11:10 +0800 Subject: [PATCH] shell: Prevent buggy moving zero column behavior According to https://unix.stackexchange.com/a/559331, moving zero column is implemented inconsistently between different terminal emulators. In order to fix this inconsistency, we avoid using this escape sequence entirely. Signed-off-by: Tw Change-Id: I73d4252f8472c769f0cf98b6bbdf2b3d6a6a6964 --- src/mainclient/shell.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/mainclient/shell.c b/src/mainclient/shell.c index 3d95ee2d..2b36375b 100644 --- a/src/mainclient/shell.c +++ b/src/mainclient/shell.c @@ -379,10 +379,12 @@ static void refresh(void) { janet_buffer_push_cstring(&b, gbl_prompt); janet_buffer_push_bytes(&b, (uint8_t *) _buf, _len); /* Erase to right */ - janet_buffer_push_cstring(&b, "\x1b[0K"); + janet_buffer_push_cstring(&b, "\x1b[0K\r"); /* Move cursor to original position. */ - snprintf(seq, 64, "\r\x1b[%dC", (int)(_pos + gbl_plen)); - janet_buffer_push_cstring(&b, seq); + if (_pos + gbl_plen) { + snprintf(seq, 64, "\x1b[%dC", (int)(_pos + gbl_plen)); + janet_buffer_push_cstring(&b, seq); + } if (write_console((char *) b.data, b.count) == -1) { exit(1); }