Files
pipelines/app/test/third_party_xterm/osc_test.dart
T
alan 8f758bc721 xterm: answer OSC 10/11/12 queries; OSC 8 links, OSC 52 and OSC 7
OSC 10/11/12 ; ? is answered with rgb:rrrr/gggg/bbbb from the view's theme
(RenderTerminal reports it through Terminal.setReportedColors), terminated
like the query (BEL or ST). OSC 8 hyperlinks are stored on the cells (a
16-bit id in the attributes; Terminal.hyperlinkAt), survive SGR resets and
end with an empty URI. OSC 52 sets reach Terminal.onClipboardSet decoded;
clipboard reads are not supported. OSC 7 reaches onWorkingDirectoryChange.

OSC bodies keep their semicolons (titles, URIs), and an OSC cut short by
another escape no longer swallows that escape's first byte.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 23:32:21 +00:00

106 lines
3.5 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'xterm_fixture.dart';
void main() {
group('OSC 10/11/12 colour queries', () {
FixtureTerminal themed() {
final t = FixtureTerminal();
t.terminal.setReportedColors(
foreground: 0xFFC0C0C0,
background: 0xFF102030,
cursor: 0xFFFF8000,
);
return t;
}
test('answer with the theme colours and the query terminator', () {
final t = themed()..feed('\x1b]11;?\x1b\\');
expect(t.takeReplies(), '\x1b]11;rgb:1010/2020/3030\x1b\\');
t.feed('\x1b]10;?\x07');
expect(t.takeReplies(), '\x1b]10;rgb:c0c0/c0c0/c0c0\x07');
t.feed('\x1b]12;?\x07');
expect(t.takeReplies(), '\x1b]12;rgb:ffff/8080/0000\x07');
});
test('a multi-colour query answers each colour in turn', () {
final t = themed()..feed('\x1b]10;?;?\x07');
expect(
t.takeReplies(),
'\x1b]10;rgb:c0c0/c0c0/c0c0\x07\x1b]11;rgb:1010/2020/3030\x07',
);
});
test('setting a colour sends nothing and prints nothing', () {
final t = themed()..feed('\x1b]11;#000000\x07x');
expect(t.takeReplies(), '');
expect(t.row(0), 'x');
});
});
group('OSC 8 hyperlinks', () {
test('link cells without printing the sequence', () {
final t = FixtureTerminal()
..feed('a\x1b]8;id=1;https://example.com/a;b\x1b\\link\x1b]8;;\x1b\\z');
expect(t.row(0), 'alinkz');
final line = t.buffer.lines[0];
expect(t.terminal.hyperlinkAt(line, 0), isNull);
for (var x = 1; x <= 4; x++) {
expect(t.terminal.hyperlinkAt(line, x), 'https://example.com/a;b');
}
expect(t.terminal.hyperlinkAt(line, 5), isNull);
});
test('a link survives SGR changes and ends with an empty URI', () {
final t = FixtureTerminal()
..feed('\x1b]8;;https://x.test\x07\x1b[1ma\x1b[0mb\x1b]8;;\x07c');
final line = t.buffer.lines[0];
expect(t.terminal.hyperlinkAt(line, 0), 'https://x.test');
expect(t.terminal.hyperlinkAt(line, 1), 'https://x.test');
expect(t.terminal.hyperlinkAt(line, 2), isNull);
expect(t.cell(1, 0).flags & 0xFFFF, 0, reason: 'no SGR attributes');
});
});
group('OSC 52 clipboard', () {
test('a set reaches the callback decoded', () {
final t = FixtureTerminal();
final sets = <(String, String)>[];
t.terminal.onClipboardSet = (text, selection) =>
sets.add((text, selection));
t.feed('\x1b]52;c;aGVsbG8gd8O2cmxk\x07x');
expect(sets, [('hello wörld', 'c')]);
expect(t.row(0), 'x');
});
test('a read request and invalid data are ignored', () {
final t = FixtureTerminal();
var calls = 0;
t.terminal.onClipboardSet = (_, _) => calls++;
t.feed('\x1b]52;c;?\x07\x1b]52;c;not base64!\x07');
expect(calls, 0);
expect(t.takeReplies(), '');
});
});
test('OSC 7 reports the working directory', () {
final t = FixtureTerminal();
final dirs = <String>[];
t.terminal.onWorkingDirectoryChange = dirs.add;
t.feed('\x1b]7;file://host/home/me/a;b\x1b\\');
expect(dirs, ['file://host/home/me/a;b']);
expect(t.row(0), '');
});
test('titles keep their semicolons; an aborted OSC prints nothing', () {
final t = FixtureTerminal();
final titles = <String>[];
t.terminal.onTitleChange = titles.add;
t.feed('\x1b]2;vim; a.txt\x07');
t.feed('\x1b]2;cut\x1b[1mB');
expect(titles, ['vim; a.txt']);
expect(t.row(0), 'B');
expect(t.cell(0, 0).flags, isNot(0));
});
}