From 6009e6e25bdff9548f085e9ae562b1ca305d3a0b Mon Sep 17 00:00:00 2001 From: Markus Rinne Date: Mon, 25 Nov 2024 13:31:56 +0200 Subject: [PATCH 1/2] Clear screen: Fix edge case With sequence \e[1J, if cursor is on second line, clear the first line. --- st.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/st.c b/st.c index 57c6e96..2e3800e 100644 --- a/st.c +++ b/st.c @@ -1705,7 +1705,7 @@ csihandle(void) } break; case 1: /* above */ - if (term.c.y > 1) + if (term.c.y > 0) tclearregion(0, 0, term.col-1, term.c.y-1); tclearregion(0, term.c.y, term.c.x, term.c.y); break; From 98610fcd37f655d44586323dc86c1d013c2798ce Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sun, 26 Jan 2025 13:40:57 +0100 Subject: [PATCH 2/2] Do not interpret CSI ? u as DECRC The kitty keyboard protocol docs recommend CSI ? u to query support for that protocol, see https://sw.kovidgoyal.net/kitty/keyboard-protocol/ For better or worse, fish shell uses this query to work around bugs in other terminals triggered by requesting that protocol via CSI = 5 u. Unfortunately, st interprets CSI ? u as DECRC (restore cursor position). reproduce with 'printf "\x1b[?u"; cat'. fish could work around this by switching to the alternate screen before running this query; but that might cause tearing on terminals that don't support Synchronized Output. I'm not sure. In the meantime, let's correct our parser. This adds a redundant else-after-return, for consistency with the surrounding code. --- st.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/st.c b/st.c index 2e3800e..03b9bc8 100644 --- a/st.c +++ b/st.c @@ -1801,7 +1801,11 @@ csihandle(void) tcursor(CURSOR_SAVE); break; case 'u': /* DECRC -- Restore cursor position (ANSI.SYS) */ - tcursor(CURSOR_LOAD); + if (csiescseq.priv) { + goto unknown; + } else { + tcursor(CURSOR_LOAD); + } break; case ' ': switch (csiescseq.mode[1]) {