import 'package:flutter/painting.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:xterm/xterm.dart'; import 'paint_fixture.dart'; import 'xterm_fixture.dart'; void main() { TestWidgetsFlutterBinding.ensureInitialized(); group('DECSCUSR', () { test('stores the requested shape and blinking', () { final t = FixtureTerminal(); expect(t.terminal.cursorShape, isNull); const expected = { 1: (TerminalCursorType.block, true), 2: (TerminalCursorType.block, false), 3: (TerminalCursorType.underline, true), 4: (TerminalCursorType.underline, false), 5: (TerminalCursorType.verticalBar, true), 6: (TerminalCursorType.verticalBar, false), }; for (final MapEntry(key: ps, value: (shape, blinks)) in expected.entries) { t.feed('\x1b[$ps q'); expect(t.terminal.cursorShape, shape, reason: 'Ps $ps'); expect(t.terminal.cursorShapeBlinks, blinks, reason: 'Ps $ps'); } t.feed('\x1b[0 q'); expect(t.terminal.cursorShape, isNull); t.feed('\x1b[6 q\x1bc'); expect(t.terminal.cursorShape, isNull); }); test('does not print and is reported by DECRQSS', () { final t = FixtureTerminal()..feed('\x1b[5 qa'); expect(t.row(0), 'a'); t.feed('\x1bP\$q q\x1b\\'); expect(t.takeReplies(), '\x1bP1\$r5 q\x1b\\'); }); }); group('cursor painting', () { final cell = fixturePainter().cellSize; final w = cell.width.ceil(); final h = cell.height.ceil(); final area = Rect.fromLTWH(0, 0, cell.width, cell.height); Future cursor(TerminalCursorType type, {CellData? under}) => Pixels.paint( w * 2, h, (canvas) => fixturePainter().paintCursor( canvas, Offset.zero, cursorType: type, cell: under, ), ); test('a block cursor draws the character under it inverted', () async { final empty = await cursor(TerminalCursorType.block); expect(empty.count(backgroundColor, area), 0); expect(empty.count(cursorColor, area), greaterThan(0)); final withChar = await cursor( TerminalCursorType.block, under: cellOf('M'), ); // The test font's glyphs fill the whole cell; before the fix the // block hid them and every pixel was the cursor colour. expect( withChar.count(backgroundColor, area), greaterThan(0), reason: 'the glyph is drawn in the background colour', ); }); test('a block cursor over a wide character spans two cells', () async { final pixels = await cursor( TerminalCursorType.block, under: cellOf('δΈ­', width: 2), ); expect(pixels.at(w + w ~/ 2, 0), cursorColor); }); test('underline and bar cursors sit in the cell, not at the top', () async { final underline = await cursor(TerminalCursorType.underline); expect(underline.at(w ~/ 2, h - 1), cursorColor); expect(underline.at(w ~/ 2, 0), isNot(cursorColor)); final bar = await cursor(TerminalCursorType.verticalBar); expect(bar.at(0, h ~/ 2), cursorColor); expect(bar.at(w - 1, h ~/ 2), isNot(cursorColor)); }); }); }