mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
Parse OSC codes in escape_code_length(). They begin with <esc> ] and are terminated with ST (<esc> backslash) or BEL (ASCII 7).
This commit is contained in:
parent
6c80a3461c
commit
9f59cf1468
2 changed files with 39 additions and 1 deletions
|
@ -1209,13 +1209,16 @@ static void test_escape_sequences(void)
|
|||
if (escape_code_length(L"\x1b[2J") != 4) err(L"test_escape_sequences failed on line %d\n", __LINE__);
|
||||
if (escape_code_length(L"\x1b[38;5;123mABC") != strlen("\x1b[38;5;123m")) err(L"test_escape_sequences failed on line %d\n", __LINE__);
|
||||
if (escape_code_length(L"\x1b@") != 2) err(L"test_escape_sequences failed on line %d\n", __LINE__);
|
||||
if (escape_code_length(L"\x1b@") != 2) err(L"test_escape_sequences failed on line %d\n", __LINE__);
|
||||
|
||||
// iTerm2 escape sequences
|
||||
if (escape_code_length(L"\x1b]50;CurrentDir=/tmp/foo\x07NOT_PART_OF_SEQUENCE") != 24) err(L"test_escape_sequences failed on line %d\n", __LINE__);
|
||||
if (escape_code_length(L"\x1b]50;SetMark\x07NOT_PART_OF_SEQUENCE") != 12) err(L"test_escape_sequences failed on line %d\n", __LINE__);
|
||||
if (escape_code_length(L"\x1b" L"]6;1;bg;red;brightness;255\x07NOT_PART_OF_SEQUENCE") != 27) err(L"test_escape_sequences failed on line %d\n", __LINE__);
|
||||
if (escape_code_length(L"\x1b]Pg4040ff\x1b\\NOT_PART_OF_SEQUENCE") != 10) err(L"test_escape_sequences failed on line %d\n", __LINE__);
|
||||
|
||||
// OSC codes
|
||||
if (escape_code_length(L"\x1b]blahblahblah\x1b\\") != 16) err(L"test_escape_sequences failed on line %d\n", __LINE__);
|
||||
if (escape_code_length(L"\x1b]blahblahblah\x07") != 15) err(L"test_escape_sequences failed on line %d\n", __LINE__);
|
||||
}
|
||||
|
||||
class lru_node_test_t : public lru_node_t
|
||||
|
|
35
screen.cpp
35
screen.cpp
|
@ -317,7 +317,42 @@ size_t escape_code_length(const wchar_t *code)
|
|||
resulting_length = cursor;
|
||||
}
|
||||
}
|
||||
if (! found)
|
||||
{
|
||||
/* OSC code, terminated by <esc>\ or <bel> */
|
||||
if (code[1] == L']')
|
||||
{
|
||||
// Start at 2 to skip over <esc>]
|
||||
size_t cursor = 2;
|
||||
bool backslash_ends = false;
|
||||
for (; code[cursor] != L'\0'; cursor++)
|
||||
{
|
||||
/* Consume a sequence of characters up to <esc>\ or <bel> */
|
||||
wchar_t c = code[cursor];
|
||||
if (c == L'\x1b') {
|
||||
backslash_ends = true;
|
||||
}
|
||||
else if (c == L'\\' && backslash_ends)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
backslash_ends = false;
|
||||
}
|
||||
|
||||
if (c == L'\x07') {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found)
|
||||
{
|
||||
resulting_length = cursor + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (! found)
|
||||
{
|
||||
/* Generic VT100 two byte sequence: <esc> followed by something in the range @ through _ */
|
||||
|
|
Loading…
Reference in a new issue