basic/terminal-util: accept ST or BEL to end escape sequence queries

Currently scan_background_color_response only accepts BEL (\x07) to end
a response, however some terminals (namely kitty in my case) will reply
with the string terminator (ST - https://en.wikipedia.org/wiki/ANSI_escape_code).

This commit changes the behaviour to now accept either ending.
This commit is contained in:
Sam Leonard
2024-02-28 11:50:18 +00:00
parent 9924d3c595
commit 73a72e3a7b
+13 -2
View File
@@ -1581,6 +1581,7 @@ typedef enum BackgroundColorState {
BACKGROUND_RED,
BACKGROUND_GREEN,
BACKGROUND_BLUE,
BACKGROUND_STRING_TERMINATOR,
} BackgroundColorState;
typedef struct BackgroundColorContext {
@@ -1672,7 +1673,9 @@ static int scan_background_color_response(
return 1; /* success! */
context->state = BACKGROUND_TEXT;
} else {
} else if (c == '\x1b')
context->state = context->blue_bits > 0 ? BACKGROUND_STRING_TERMINATOR : BACKGROUND_TEXT;
else {
int d = unhexchar(c);
if (d < 0 || context->blue_bits >= sizeof(context->blue)*8)
context->state = BACKGROUND_TEXT;
@@ -1682,10 +1685,18 @@ static int scan_background_color_response(
}
}
break;
case BACKGROUND_STRING_TERMINATOR:
if (c == '\\')
return 1; /* success! */
context->state = c == ']' ? BACKGROUND_ESCAPE : BACKGROUND_TEXT;
break;
}
/* Reset any colors we might have picked up */
if (context->state == BACKGROUND_TEXT) {
if (IN_SET(context->state, BACKGROUND_TEXT, BACKGROUND_ESCAPE)) {
/* reset color */
context->red = context->green = context->blue = 0;
context->red_bits = context->green_bits = context->blue_bits = 0;