e94f4856e3
CSI parameters now record colon subparameters (ITU T.416), so SGR 4:3 is a curly underline instead of 4 and 3 = 43 (yellow background), and 38:2::r:g:b, 38:2:r:g:b and 38:5:n set colours. Underline styles 4:0-4:5 and 21 (double) are stored on the cell; 58/59 underline colours are consumed and ignored; 53/55 toggle overline; 22 clears bold and faint; truncated 38;5 no longer throws. Intermediate bytes and private prefixes are kept, so CSI > 4;2 m (modifyOtherKeys) is no longer applied as SGR. An empty parameter reads as 0 (default), so CSI ;5H and CSI 3H position the cursor. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
99 lines
3.4 KiB
Dart
99 lines
3.4 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:xterm/xterm.dart';
|
|
|
|
import 'xterm_fixture.dart';
|
|
|
|
void main() {
|
|
CellData styled(String sgr) {
|
|
final t = FixtureTerminal()..feed('\x1b[${sgr}mX');
|
|
return t.cell(0, 0);
|
|
}
|
|
|
|
int underlineStyle(CellData cell) => cell.flags & CellAttr.underline == 0
|
|
? 0
|
|
: (cell.flags & CellAttr.underlineStyleMask) >>
|
|
CellAttr.underlineStyleShift;
|
|
|
|
test('4:3 is a curly underline, not a yellow background', () {
|
|
final cell = styled('4:3');
|
|
expect(underlineStyle(cell), 3);
|
|
expect(cell.background, 0);
|
|
expect(cell.flags & CellAttr.italic, 0);
|
|
});
|
|
|
|
test('underline styles 4:0 to 4:5 and plain 4 / 24 / 21', () {
|
|
expect(underlineStyle(styled('4')), 1);
|
|
expect(underlineStyle(styled('4:0')), 0);
|
|
expect(underlineStyle(styled('4:1')), 1);
|
|
expect(underlineStyle(styled('4:2')), 2);
|
|
expect(underlineStyle(styled('4:4')), 4);
|
|
expect(underlineStyle(styled('4:5')), 5);
|
|
expect(underlineStyle(styled('4:3;24')), 0);
|
|
expect(underlineStyle(styled('4:3;4:0')), 0);
|
|
expect(underlineStyle(styled('21')), 2);
|
|
expect(styled('21').flags & CellAttr.bold, 0);
|
|
});
|
|
|
|
test('colon direct colours with and without a colour space id', () {
|
|
expect(styled('38:2::10:20:30').foreground, rgb(10, 20, 30));
|
|
expect(styled('38:2:1:10:20:30').foreground, rgb(10, 20, 30));
|
|
expect(styled('38:2:10:20:30').foreground, rgb(10, 20, 30));
|
|
expect(styled('48:2::1:2:3').background, rgb(1, 2, 3));
|
|
});
|
|
|
|
test('colon and semicolon indexed colours', () {
|
|
expect(styled('38:5:196').foreground, palette(196));
|
|
expect(styled('48:5:21').background, palette(21));
|
|
expect(styled('38;5;196').foreground, palette(196));
|
|
expect(styled('38;2;1;2;3;1').foreground, rgb(1, 2, 3));
|
|
expect(styled('38;2;1;2;3;1').flags & CellAttr.bold, isNot(0));
|
|
});
|
|
|
|
test('colon groups end at the next semicolon', () {
|
|
final cell = styled('38:5:2;41;1');
|
|
expect(cell.foreground, palette(2));
|
|
expect(cell.background, named(NamedColor.red));
|
|
expect(cell.flags & CellAttr.bold, isNot(0));
|
|
});
|
|
|
|
test('underline colour 58 / 59 is consumed, not applied elsewhere', () {
|
|
var cell = styled('58:2::255:0:0;4:3');
|
|
expect(cell.foreground, 0);
|
|
expect(cell.background, 0);
|
|
expect(underlineStyle(cell), 3);
|
|
cell = styled('58;5;9;1');
|
|
expect(cell.foreground, 0);
|
|
expect(cell.flags & CellAttr.bold, isNot(0));
|
|
cell = styled('58;2;1;2;3;59;7');
|
|
expect(cell.flags & CellAttr.inverse, isNot(0));
|
|
expect(cell.background, 0);
|
|
});
|
|
|
|
test('truncated extended colours do not throw or misapply', () {
|
|
expect(styled('38;5').foreground, 0);
|
|
expect(styled('38;2;1;2').foreground, 0);
|
|
expect(styled('48').background, 0);
|
|
});
|
|
|
|
test('22 clears bold and faint; 53/55 toggle overline', () {
|
|
expect(styled('1;2;22').flags & (CellAttr.bold | CellAttr.faint), 0);
|
|
expect(styled('53').flags & CellAttr.overline, isNot(0));
|
|
expect(styled('53;55').flags & CellAttr.overline, 0);
|
|
});
|
|
|
|
test('a private-prefixed m (modifyOtherKeys) is not SGR', () {
|
|
final t = FixtureTerminal()..feed('\x1b[>4;2mX');
|
|
expect(t.cell(0, 0).flags, 0);
|
|
expect(t.row(0), 'X');
|
|
});
|
|
|
|
test('empty parameters default: CSI ; 5 H and CSI 3 H', () {
|
|
final t = FixtureTerminal()..feed('\x1b[;5H');
|
|
expect(t.buffer.cursorX, 4);
|
|
expect(t.buffer.cursorY, 0);
|
|
t.feed('\x1b[3H');
|
|
expect(t.buffer.cursorX, 0);
|
|
expect(t.buffer.cursorY, 2);
|
|
});
|
|
}
|