Ticket #4597: fix CSI parser

fish shell 4.0 wants to send sequences like "\x1b[=5u",
so strip them from the output as well.

See https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_(Control_Sequence_Introducer)_sequences

In future we should probably pass through some sequences like bracketed paste.

Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
This commit is contained in:
Johannes Altmanninger 2024-10-09 07:25:18 +02:00 committed by Yury V. Zaytsev
parent 9e4e7e8a7f
commit 0ea77d2ec7

View File

@ -736,7 +736,10 @@ skip_numbers (const char *s)
* "control sequence", in a sort of pidgin BNF, as follows:
*
* control-seq = Esc non-'['
* | Esc '[' (0 or more digits or ';' or ':' or '?') (any other char)
* | Esc '[' (parameter-byte)* (intermediate-byte)* final-byte
* parameter-byte = [\x30-\x3F] # one of "0-9;:<=>?"
* intermediate-byte = [\x20\x2F] # one of " !\"#$%&'()*+,-./"
* final-byte = [\x40-\x7e] # one of "@AZ[\]^_`az{|}~"
*
* The 256-color and true-color escape sequences should allow either ';' or ':' inside as separator,
* actually, ':' is the more correct according to ECMA-48.
@ -763,8 +766,10 @@ strip_ctrl_codes (char *s)
if (*(++r) == '[' || *r == '(')
{
/* strchr() matches trailing binary 0 */
while (*(++r) != '\0' && strchr ("0123456789;:?", *r) != NULL)
while (*(++r) != '\0' && strchr ("0123456789;:<=>?", *r) != NULL)
;
while (*r != '\0' && (*r < 0x40 || *r > 0x7E))
++r;
}
else if (*r == ']')
{