mayContainTerminalGraphics function
Whether value can contain one of the graphics protocols handled here.
This is intentionally a cheap prefilter for hot renderer paths. It may return true for malformed payloads, but it must not return false for any sequence recognized by the parsing helpers in this library.
Implementation
bool mayContainTerminalGraphics(String value) {
var escIndex = value.indexOf('\x1b');
while (escIndex != -1) {
if (escIndex + 2 < value.length) {
final next = value.codeUnitAt(escIndex + 1);
final third = value.codeUnitAt(escIndex + 2);
if ((next == 0x5F && third == 0x47) || (next == 0x50 && third == 0x71)) {
return true;
}
}
escIndex = value.indexOf('\x1b', escIndex + 1);
}
return value.contains('\x9fG') || value.contains('\x90q');
}