e65354496a
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
99 lines
3.0 KiB
Dart
99 lines
3.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:xterm/xterm.dart';
|
|
|
|
import 'paint_fixture.dart';
|
|
|
|
void main() {
|
|
group('maxLines', () {
|
|
Terminal filled(int lines) {
|
|
final terminal = Terminal(maxLines: 100)..resize(10, 4);
|
|
terminal.write(List.generate(lines, (i) => 'l$i').join('\r\n'));
|
|
return terminal;
|
|
}
|
|
|
|
test('shrinking drops the oldest lines and keeps anchors right', () {
|
|
final terminal = filled(80);
|
|
final buffer = terminal.buffer;
|
|
expect(buffer.height, 80);
|
|
final anchor = buffer.createAnchor(0, 79);
|
|
final old = buffer.createAnchor(0, 5);
|
|
terminal.maxLines = 30;
|
|
expect(terminal.maxLines, 30);
|
|
expect(buffer.height, 30);
|
|
expect(buffer.lines[0].getText().trim(), 'l50');
|
|
expect(buffer.lines[29].getText().trim(), 'l79');
|
|
expect(anchor.attached, isTrue);
|
|
expect(anchor.y, 29);
|
|
expect(old.attached, isFalse);
|
|
// Further output keeps to the new length.
|
|
terminal.write('\r\nnext');
|
|
expect(buffer.height, 30);
|
|
expect(buffer.lines[29].getText().trim(), 'next');
|
|
});
|
|
|
|
test('growing keeps every line and makes room for more', () {
|
|
final terminal = filled(100);
|
|
terminal.maxLines = 300;
|
|
expect(terminal.buffer.height, 100);
|
|
terminal.write(List.generate(150, (i) => '\r\nm$i').join());
|
|
expect(terminal.buffer.height, 250);
|
|
expect(terminal.buffer.lines[0].getText().trim(), 'l0');
|
|
});
|
|
|
|
test('never fewer than the screen rows', () {
|
|
final terminal = filled(20);
|
|
terminal.maxLines = 2;
|
|
expect(terminal.buffer.height, 4);
|
|
});
|
|
|
|
test('clearing the scrollback detaches its lines', () {
|
|
final terminal = filled(20);
|
|
final buffer = terminal.buffer;
|
|
final old = buffer.createAnchor(0, 2);
|
|
final screen = buffer.createAnchor(0, 18);
|
|
buffer.clearScrollback();
|
|
expect(buffer.height, 4);
|
|
expect(old.attached, isFalse);
|
|
expect(screen.y, 2);
|
|
});
|
|
});
|
|
|
|
testWidgets('cursorBlinkVisible hides the cursor in its off phase', (
|
|
tester,
|
|
) async {
|
|
final terminal = Terminal()..write('ab');
|
|
final phase = ValueNotifier(true);
|
|
addTearDown(phase.dispose);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Center(
|
|
child: SizedBox(
|
|
width: 200,
|
|
height: 100,
|
|
child: TerminalView(
|
|
terminal,
|
|
theme: fixtureTheme,
|
|
alwaysShowCursor: false,
|
|
cursorBlinkVisible: phase,
|
|
hardwareKeyboardOnly: true,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
// The background, then (after the text) the unfocused cursor's outline.
|
|
PaintPattern cursor() => paints
|
|
..rect(color: backgroundColor)
|
|
..rect(color: cursorColor);
|
|
final view = find.byType(TerminalView);
|
|
expect(view, cursor());
|
|
phase.value = false;
|
|
await tester.pump();
|
|
expect(view, isNot(cursor()));
|
|
phase.value = true;
|
|
await tester.pump();
|
|
expect(view, cursor());
|
|
});
|
|
}
|