diff options
| author | Oliver Kiddle <opk@zsh.org> | 2026-04-30 20:36:35 +0200 |
|---|---|---|
| committer | Oliver Kiddle <opk@zsh.org> | 2026-04-30 20:48:12 +0200 |
| commit | 5e1716fd00a0ab6c0046f6fd20611cdeee6c3607 (patch) | |
| tree | cf99b2f0432be568154e6001e6049c31367f6112 | |
| parent | unposted: _opkg: guard zparseopts long-option specs (diff) | |
| download | zsh-5e1716fd00a0ab6c0046f6fd20611cdeee6c3607.tar zsh-5e1716fd00a0ab6c0046f6fd20611cdeee6c3607.tar.gz zsh-5e1716fd00a0ab6c0046f6fd20611cdeee6c3607.tar.bz2 zsh-5e1716fd00a0ab6c0046f6fd20611cdeee6c3607.tar.lz zsh-5e1716fd00a0ab6c0046f6fd20611cdeee6c3607.tar.xz zsh-5e1716fd00a0ab6c0046f6fd20611cdeee6c3607.tar.zst zsh-5e1716fd00a0ab6c0046f6fd20611cdeee6c3607.zip | |
54404: skip the RGB terminal query on older versions of the Apple terminal
The sequence isn't consumed so gets printed and then quickly erased.
macOS conveniently sets TERM_PROGRAM in the environment so this can be
detected.
| -rw-r--r-- | ChangeLog | 6 | ||||
| -rw-r--r-- | Src/Zle/termquery.c | 19 | ||||
| -rw-r--r-- | Test/X06termquery.ztst | 1 |
3 files changed, 25 insertions, 1 deletions
@@ -1,3 +1,9 @@ +2026-04-30 Oliver Kiddle <opk@zsh.org> + + * 54404: Src/Zle/termquery.c, Test/X06termquery.ztst: skip + the RGB terminal query on older versions of the Apple terminal + which fail to consume the sequence + 2026-04-29 dana <dana@dana.is> * unposted: Completion/Linux/Command/_opkg: guard zparseopts diff --git a/Src/Zle/termquery.c b/Src/Zle/termquery.c index d8be6e49a..bd601735f 100644 --- a/Src/Zle/termquery.c +++ b/Src/Zle/termquery.c @@ -507,8 +507,25 @@ query_terminal(void) { char *tqend = tquery; static seqstate_t states[] = QUERY_STATES; char **f, **flist = getaparam(EXTVAR); + char *envid = getsparam("TERM_PROGRAM"); + int badapple = 0; size_t i; + /* If TERM_PROGRAM is set in the environment, use that and + * skip the XTVERSION query */ + if (envid) { + char *envver; + handle_query(4, NULL, 0, envid, strlen(envid), NULL); + if ((envver = getsparam("TERM_PROGRAM_VERSION"))) { + handle_query(5, NULL, 0, envver, strlen(envver), NULL); + /* Older macOS terminal doesn't consume RGB queries, + * nor does it support truecolor. Given that it's widely + * used, we handle it explicitly. */ + badapple = !strcmp(envid, "Apple_Terminal") && + zstrtol(envver, NULL, 10) < 470; + } + } + for (f = flist; f && *f; f++) if (!strcmp(*f, "-query")) return; /* disable all queries */ @@ -536,7 +553,7 @@ query_terminal(void) { (!strcmp(cterm, "truecolor") || !strcmp(cterm, "24bit"))))) handle_query(3, NULL, 0, NULL, 0, NULL); - else + else if ((i != 4 || !badapple) && (i != 5 || !envid)) struncpy(&tqend, (char *) queries[i], /* collate escape sequences */ sizeof(tquery) - (tqend - tquery)); } diff --git a/Test/X06termquery.ztst b/Test/X06termquery.ztst index 5f3a81aae..701cd625b 100644 --- a/Test/X06termquery.ztst +++ b/Test/X06termquery.ztst @@ -5,6 +5,7 @@ termresp() { setopt localoptions extendedglob export PS1= PS2= COLORTERM= TERM= + typeset +x TERM_PROGRAM typeset +x -m .term.\* zpty -d zpty zsh "${(q)ZTST_testdir}/../Src/zsh -fiV +Z" |
