Files
pipelines/app/test/third_party_xterm/modes_test.dart
T
alan 30b32921fe xterm: restore the cursor leaving 1049; arrow keys follow DECCKM
Resetting mode 1049 switched back to the main screen without restoring the
cursor saved when it was set. The keytab input handler read application
cursor keys from the keypad mode (DECKPAM) instead of DECCKM (CSI ?1 h/l);
Terminal.cursorKeysMode is the mode to read.

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

46 lines
1.4 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:xterm/xterm.dart';
import 'xterm_fixture.dart';
void main() {
test('leaving the 1049 alternate screen restores the saved cursor', () {
final t = FixtureTerminal()..feed('main\x1b[3;5H\x1b[31m');
t.feed('\x1b[?1049h');
expect(t.terminal.isUsingAltBuffer, isTrue);
t.feed('\x1b[1;1H\x1b[0malt screen');
t.feed('\x1b[?1049l');
expect(t.terminal.isUsingAltBuffer, isFalse);
expect(t.buffer.cursorX, 4);
expect(t.buffer.cursorY, 2);
expect(t.row(0), 'main');
t.feed('z');
expect(t.cell(4, 2).foreground, named(NamedColor.red));
});
test('DECCKM (CSI ? 1 h/l) is its own mode, not the keypad mode', () {
final t = FixtureTerminal();
expect(t.terminal.cursorKeysMode, isFalse);
t.feed('\x1b[?1h');
expect(t.terminal.cursorKeysMode, isTrue);
expect(t.terminal.appKeypadMode, isFalse);
t.feed('\x1b[?1l\x1b=');
expect(t.terminal.cursorKeysMode, isFalse);
expect(t.terminal.appKeypadMode, isTrue);
});
test('arrow keys follow DECCKM, not DECKPAM', () {
final t = FixtureTerminal();
t.terminal.keyInput(TerminalKey.arrowUp);
expect(t.takeReplies(), '\x1b[A');
t.feed('\x1b=');
t.terminal.keyInput(TerminalKey.arrowUp);
expect(t.takeReplies(), '\x1b[A');
t.feed('\x1b>\x1b[?1h');
t.terminal.keyInput(TerminalKey.arrowUp);
expect(t.takeReplies(), '\x1bOA');
});
}