From 113d0e761c0987190b039f5297f4c6b494dd6f71 Mon Sep 17 00:00:00 2001
From: Johannes Altmanninger <aclopte@gmail.com>
Date: Wed, 9 Oct 2024 07:25:18 +0200
Subject: [PATCH 1/3] 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.
---
lib/util.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/lib/util.c b/lib/util.c
index 3fb8c54e5..c25cb05a0 100644
a
|
b
|
skip_numbers (const char *s) |
736 | 736 | * "control sequence", in a sort of pidgin BNF, as follows: |
737 | 737 | * |
738 | 738 | * control-seq = Esc non-'[' |
739 | | * | Esc '[' (0 or more digits or ';' or ':' or '?') (any other char) |
| 739 | * | Esc '[' (parameter-byte)* (intermediate-byte)* final-byte |
| 740 | * parameter-byte = [\x30-\x3F] # one of "0-9;:<=>?" |
| 741 | * intermediate-byte = [\x20–\x2F] # one of " !\"#$%&'()*+,-./" |
| 742 | * final-byte = [\x40-\x7e] # one of "@A–Z[\]^_`a–z{|}~" |
740 | 743 | * |
741 | 744 | * The 256-color and true-color escape sequences should allow either ';' or ':' inside as separator, |
742 | 745 | * actually, ':' is the more correct according to ECMA-48. |
… |
… |
strip_ctrl_codes (char *s) |
763 | 766 | if (*(++r) == '[' || *r == '(') |
764 | 767 | { |
765 | 768 | /* strchr() matches trailing binary 0 */ |
766 | | while (*(++r) != '\0' && strchr ("0123456789;:?", *r) != NULL) |
| 769 | while (*(++r) != '\0' && strchr ("0123456789;:<=>?", *r) != NULL) |
767 | 770 | ; |
| 771 | while (*r != 0 && (*r < 0x40 || *r > 0x7E)) |
| 772 | ++r; |
768 | 773 | } |
769 | 774 | else if (*r == ']') |
770 | 775 | { |