mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-01 13:01:21 -03:00
Remove is_color_escape_seq
This is supposed to detect color escape sequences, to figure out how long an escape sequence is, for use in width calculations. However, the typical color sequences are already taken care of by is_csi_style_escape_seq because they look like a csi sequence starting with `\e[` and ending in `m`. In the entire terminfo database shipped with ncurses 6.3, these are the terminals that have non-csi color sequences: at-color atari-color atari_st-color d220-dg d230-dg d230c-dg d430-dg d430-unix d430-unix-25 d430-unix-s d430-unix-sr d430-unix-w d430c-dg d430c-unix d430c-unix-25 d430c-unix-s d430c-unix-sr d430c-unix-w d470-dg d470c-dg dg+fixed dgmode+color dgmode+color8 dgunix+fixed emu fbterm i3164 ibm3164 linux-m1b linux-m2 minitel1 minitel1b putty-m1b putty-m2 st52-color tt52 tw52 tw52-color xterm-8bit Most of these were discontinued in the 90s and their manufacturers no longer exist (like Data General, which went defunct in 1999). The last one is a special mode for xterm that is fundamentally UTF-8 incompatible because it encodes a CSI as \X9b. The linux/putty m1b and m2 entries (also for minitel) don't support color to begin with and the sequences they have in their terminfo entries are control characters anyway, so the calculation would still add up. In turn, what we gain from this is much faster width calculations with unrecognized escapes - e.g. `string length -V \efoo` is sped up by a factor of 20. An alternative would be to skip this if max_colors is > 16 as that is the most any of these entries can do. The runtime scales linearly with the number of colors so on those systems it would be reasonably quick anyway. But given just *how* outdated these are I believe it is okay to just remove support outright. I do not believe anyone has ever run fish on any of these.
This commit is contained in:
@@ -189,6 +189,7 @@ static bool is_two_byte_escape_seq(const wchar_t *code, size_t *resulting_length
|
||||
|
||||
/// Generic VT100 CSI-style sequence. <esc>, followed by zero or more ASCII characters NOT in
|
||||
/// the range [@,_], followed by one character in that range.
|
||||
/// This will also catch color sequences.
|
||||
static bool is_csi_style_escape_seq(const wchar_t *code, size_t *resulting_length) {
|
||||
if (code[1] != L'[') {
|
||||
return false;
|
||||
@@ -214,37 +215,6 @@ static bool is_csi_style_escape_seq(const wchar_t *code, size_t *resulting_lengt
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Detect whether the escape sequence sets foreground/background color. Note that 24-bit color
|
||||
/// sequences are detected by `is_csi_style_escape_seq()` if they use the ANSI X3.64 pattern for
|
||||
/// such sequences. This function only handles those escape sequences for setting color that rely on
|
||||
/// the terminfo definition and which might use a different pattern.
|
||||
static bool is_color_escape_seq(const wchar_t *code, size_t *resulting_length) {
|
||||
if (!cur_term) return false;
|
||||
|
||||
// Detect these terminfo color escapes with parameter value up to max_colors, all of which
|
||||
// don't move the cursor.
|
||||
const char *const esc[] = {
|
||||
set_a_foreground,
|
||||
set_a_background,
|
||||
set_foreground,
|
||||
set_background,
|
||||
};
|
||||
|
||||
for (auto p : esc) {
|
||||
if (!p) continue;
|
||||
|
||||
for (int k = 0; k < max_colors; k++) {
|
||||
size_t esc_seq_len = try_sequence(tparm(const_cast<char *>(p), k), code);
|
||||
if (esc_seq_len) {
|
||||
*resulting_length = esc_seq_len;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Detect whether the escape sequence sets one of the terminal attributes that affects how text is
|
||||
/// displayed other than the color.
|
||||
static bool is_visual_escape_seq(const wchar_t *code, size_t *resulting_length) {
|
||||
@@ -285,9 +255,6 @@ maybe_t<size_t> escape_code_length(const wchar_t *code) {
|
||||
if (!found) found = is_three_byte_escape_seq(code, &esc_seq_len);
|
||||
if (!found) found = is_csi_style_escape_seq(code, &esc_seq_len);
|
||||
if (!found) found = is_two_byte_escape_seq(code, &esc_seq_len);
|
||||
// Colors are the hardest to match, so we try last.
|
||||
// (also tparm is *slow*, we should try to find a better replacement)
|
||||
if (!found) found = is_color_escape_seq(code, &esc_seq_len);
|
||||
|
||||
return found ? maybe_t<size_t>{esc_seq_len} : none();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user