From 98610fcd37f655d44586323dc86c1d013c2798ce Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sun, 26 Jan 2025 13:40:57 +0100 Subject: 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]) { -- cgit v1.2.3 From f114bcedd113017d907aad32031db92c050f4bf3 Mon Sep 17 00:00:00 2001 From: sasha Date: Sun, 27 Jul 2025 05:43:47 +0000 Subject: Eat up "CSI 58" sequences This is used in the wild by systemd systemctl for example and st misinterpreted it as "blink", because it didn't know "58", then saw "5" as "blink", and then didn't know "245". This should print "foo" as normal text: printf '\e[58:5:245mfoo\n' printf '\e[58:2:50:100:200mfoo\n' --- st.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/st.c b/st.c index 03b9bc8..37f38c5 100644 --- a/st.c +++ b/st.c @@ -1430,6 +1430,12 @@ tsetattr(const int *attr, int l) case 49: term.c.attr.bg = defaultbg; break; + case 58: + /* This starts a sequence to change the color of + * "underline" pixels. We don't support that and + * instead eat up a following "5;n" or "2;r;g;b". */ + tdefcolor(attr, &i, l); + break; default: if (BETWEEN(attr[i], 30, 37)) { term.c.attr.fg = attr[i] - 30; -- cgit v1.2.3 From d6c431859c6c0201e0668ed24a9f17cebf0a68f5 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Fri, 8 Aug 2025 17:11:59 -0400 Subject: Support OSC 110, 111, and 112 for resetting colors This adds support for OSC 110, 111, and 112 escape sequences to reset the foreground, background, and cursor colors in the terminal. The changes include handling these sequences in the `strhandle` function of `st.c`, allowing applications to reset colors to their default values. The OSC sequences originated from Xterm control sequences and are now widely used in terminal applications and supported by many terminal emulators. For applications, this allows them to reset colors to default values without needing to know the colors beforehand. Signed-off-by: Ayman Bagabas --- st.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/st.c b/st.c index 37f38c5..e9fea17 100644 --- a/st.c +++ b/st.c @@ -1967,6 +1967,19 @@ strhandle(void) tfulldirt(); } return; + case 110: + case 111: + case 112: + if (narg != 1) + break; + if ((j = par - 110) < 0 || j >= LEN(osc_table)) + break; /* shouldn't be possible */ + if (xsetcolorname(osc_table[j].idx, NULL)) { + fprintf(stderr, "erresc: %s color not found\n", osc_table[j].str); + } else { + tfulldirt(); + } + return; } break; case 'k': /* old title set compatibility */ -- cgit v1.2.3 From 5a4666c19e3956069147aee43a06b326d998366e Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sat, 9 Aug 2025 12:57:30 +0200 Subject: add a few comments --- st.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/st.c b/st.c index e9fea17..8e57991 100644 --- a/st.c +++ b/st.c @@ -1420,14 +1420,14 @@ tsetattr(const int *attr, int l) if ((idx = tdefcolor(attr, &i, l)) >= 0) term.c.attr.fg = idx; break; - case 39: + case 39: /* set foreground color to default */ term.c.attr.fg = defaultfg; break; case 48: if ((idx = tdefcolor(attr, &i, l)) >= 0) term.c.attr.bg = idx; break; - case 49: + case 49: /* set background color to default */ term.c.attr.bg = defaultbg; break; case 58: @@ -1532,7 +1532,7 @@ tsetmode(int priv, int set, const int *args, int narg) case 1006: /* 1006: extended reporting mode */ xsetmode(set, MODE_MOUSESGR); break; - case 1034: + case 1034: /* 1034: enable 8-bit mode for keyboard input */ xsetmode(set, MODE_8BIT); break; case 1049: /* swap screen & set/restore cursor as xterm */ @@ -1540,8 +1540,8 @@ tsetmode(int priv, int set, const int *args, int narg) break; tcursor((set) ? CURSOR_SAVE : CURSOR_LOAD); /* FALLTHROUGH */ - case 47: /* swap screen */ - case 1047: + case 47: /* swap screen buffer */ + case 1047: /* swap screen buffer */ if (!allowaltscreen) break; alt = IS_SET(MODE_ALTSCREEN); @@ -1554,7 +1554,7 @@ tsetmode(int priv, int set, const int *args, int narg) if (*args != 1049) break; /* FALLTHROUGH */ - case 1048: + case 1048: /* save/restore cursor (like DECSC/DECRC) */ tcursor((set) ? CURSOR_SAVE : CURSOR_LOAD); break; case 2004: /* 2004: bracketed paste mode */ @@ -1913,7 +1913,7 @@ strhandle(void) if (narg > 1) xsettitle(strescseq.args[1]); return; - case 52: + case 52: /* manipulate selection data */ if (narg > 2 && allowwindowops) { dec = base64dec(strescseq.args[2]); if (dec) { @@ -1924,9 +1924,9 @@ strhandle(void) } } return; - case 10: - case 11: - case 12: + case 10: /* set dynamic VT100 text foreground color */ + case 11: /* set dynamic VT100 text background color */ + case 12: /* set dynamic text cursor color */ if (narg < 2) break; p = strescseq.args[1]; @@ -1967,9 +1967,9 @@ strhandle(void) tfulldirt(); } return; - case 110: - case 111: - case 112: + case 110: /* reset dynamic VT100 text foreground color */ + case 111: /* reset dynamic VT100 text background color */ + case 112: /* reset dynamic text cursor color */ if (narg != 1) break; if ((j = par - 110) < 0 || j >= LEN(osc_table)) -- cgit v1.2.3 From 6e970474743d57a5d8b054c41fd3bff2bc895742 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sat, 9 Aug 2025 14:35:14 +0200 Subject: bump version to 0.9.3 --- config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.mk b/config.mk index fdc29a7..2fc854e 100644 --- a/config.mk +++ b/config.mk @@ -1,5 +1,5 @@ # st version -VERSION = 0.9.2 +VERSION = 0.9.3 # Customize below to fit your system -- cgit v1.2.3