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>
This commit is contained in:
2026-11-25 23:26:47 +00:00
parent 326e7710d4
commit 30b32921fe
3 changed files with 48 additions and 1 deletions
@@ -0,0 +1,45 @@
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');
});
}
+2
View File
@@ -908,7 +908,9 @@ class EscapeParser {
handler.clearAltBuffer();
handler.useAltBuffer();
} else {
// The cursor was saved on the main screen when 1049 was set.
handler.useMainBuffer();
handler.restoreCursor();
}
return;
case 2004:
+1 -1
View File
@@ -116,7 +116,7 @@ class KeytabInputHandler implements TerminalInputHandler {
alt: event.alt,
shift: event.shift,
newLineMode: event.state.lineFeedMode,
appCursorKeys: event.state.appKeypadMode,
appCursorKeys: event.state.cursorKeysMode,
appKeyPad: event.state.appKeypadMode,
appScreen: event.altBuffer,
macos: event.platform == TerminalTargetPlatform.macos,