Teach fish to compute the length of more escape sequences.

Fixes #1243
This commit is contained in:
ridiculousfish 2014-07-26 14:07:17 -07:00
parent 2bb08a4ca0
commit d07ea3b66a
2 changed files with 33 additions and 0 deletions

View file

@ -1209,6 +1209,13 @@ 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__);
}
class lru_node_test_t : public lru_node_t

View file

@ -252,6 +252,32 @@ size_t escape_code_length(const wchar_t *code)
}
}
}
if (! found)
{
/* iTerm2 escape codes: CSI followed by ], terminated by either BEL or - see https://code.google.com/p/iterm2/wiki/ProprietaryEscapeCodes */
if (code[1] == ']')
{
/* A sequence of characters terminated by either 'ESC backslash' or BEL */
const wchar_t * const end1_sentinel = L"\x1b\\";
const wchar_t * const end2_sentinel = L"\a";
const wchar_t *end1 = wcsstr(&code[2], end1_sentinel);
const wchar_t *end2 = wcsstr(&code[2], end2_sentinel);
// Use the non-null end, or if both are null, use the earlier end
const wchar_t *end = end1;
if (end == NULL || (end2 != NULL && end2 < end))
{
end = end2;
}
if (end != NULL)
{
assert(end > code);
resulting_length = (end - code);
found = true;
}
}
}
if (! found)
{