Terminal: xterm key encoding, no live reflow on resize, Alt+T/Ctrl+T reach the shell
- Live terminals no longer reflow (xterm.dart 4.0.0 left the cursor on the wrong row); narrowing cuts and erases cells past the width, rows scroll into scrollback keeping the cursor row; finished output still reflows. - App-side key encoding before xterm.dart's defaults: Alt as Meta (ESC + the typed character), Ctrl symbol table, xterm modifier parameter for arrows/Home/End/PgUp/PgDn/Ins/Del/F-keys, DECCKM and DECKPAM, Alt+BS. - Settings > Appearance > Terminal: Use Option as Meta key (Macs, on). - Inside a focused terminal only Cmd+T and Ctrl+` toggle it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -90,9 +90,7 @@ class TerminalTestAppState extends State<TerminalTestApp> {
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('App'),
|
||||
actions: [
|
||||
TerminalToggleButton(layout: widget.layout),
|
||||
],
|
||||
actions: [TerminalToggleButton(layout: widget.layout)],
|
||||
),
|
||||
body: const TextField(key: appField),
|
||||
),
|
||||
@@ -125,6 +123,8 @@ Future<void> chord(
|
||||
}
|
||||
}
|
||||
|
||||
/// Alt+T: shows or hides the terminal from outside it (inside, it is the
|
||||
/// shell's ESC t).
|
||||
Future<void> altT(WidgetTester tester, {bool settle = true}) => chord(
|
||||
tester,
|
||||
LogicalKeyboardKey.keyT,
|
||||
@@ -132,6 +132,14 @@ Future<void> altT(WidgetTester tester, {bool settle = true}) => chord(
|
||||
settle: settle,
|
||||
);
|
||||
|
||||
/// Ctrl+`: shows or hides the terminal wherever the keyboard is.
|
||||
Future<void> toggleTerminal(WidgetTester tester, {bool settle = true}) => chord(
|
||||
tester,
|
||||
LogicalKeyboardKey.backquote,
|
||||
[LogicalKeyboardKey.controlLeft],
|
||||
settle: settle,
|
||||
);
|
||||
|
||||
Future<void> ctrlTab(WidgetTester tester, {bool reverse = false}) => chord(
|
||||
tester,
|
||||
LogicalKeyboardKey.tab,
|
||||
|
||||
@@ -57,9 +57,7 @@ Future<Widget?> _pumpBar(
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: theme,
|
||||
home: actions == null
|
||||
? bar
|
||||
: TerminalScope(actions: actions, child: bar),
|
||||
home: actions == null ? bar : TerminalScope(actions: actions, child: bar),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
@@ -106,7 +106,7 @@ void main() {
|
||||
|
||||
// Hidden again: the composer that had the keyboard gets it back, and
|
||||
// Ctrl+Tab is the chat's once more.
|
||||
await altT(tester);
|
||||
await toggleTerminal(tester);
|
||||
expect(_composer(tester, 'a').focusNode.hasPrimaryFocus, isTrue);
|
||||
await ctrlTab(tester);
|
||||
expect(workspace.activePane?.sessionId, 'b');
|
||||
|
||||
@@ -48,7 +48,7 @@ void main() {
|
||||
await pumpTerminalApp(tester, hub: hub, layout: layout);
|
||||
await tester.tap(find.byKey(appField));
|
||||
await tester.pump();
|
||||
await altT(tester, settle: false);
|
||||
await toggleTerminal(tester, settle: false);
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
expect(panelFinder, findsOneWidget);
|
||||
// Midway: the app has given up part of the panel's height, and the
|
||||
@@ -61,7 +61,7 @@ void main() {
|
||||
expect(appBottom(tester), shown);
|
||||
expect(panelOpacity(tester), 1);
|
||||
|
||||
await altT(tester, settle: false);
|
||||
await toggleTerminal(tester, settle: false);
|
||||
// The keyboard is back in the field at once; the panel leaves after.
|
||||
expect(appFieldFocused(tester), isTrue);
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
@@ -77,7 +77,7 @@ void main() {
|
||||
'shrinks away', (tester) async {
|
||||
layout.setMode(TerminalMode.float);
|
||||
await pumpTerminalApp(tester, hub: hub, layout: layout);
|
||||
await altT(tester, settle: false);
|
||||
await toggleTerminal(tester, settle: false);
|
||||
// The window is built, then its motion starts.
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
@@ -87,7 +87,7 @@ void main() {
|
||||
expect(appBottom(tester), 800);
|
||||
await tester.pumpAndSettle();
|
||||
expect(floatScale(tester).scale.value, 1);
|
||||
await altT(tester, settle: false);
|
||||
await toggleTerminal(tester, settle: false);
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
// Hiding: no longer shown, still painted while it shrinks away.
|
||||
expect(floatFinder, findsNothing);
|
||||
@@ -100,7 +100,7 @@ void main() {
|
||||
// AnimationSpeedController plays animations at half speed this way.
|
||||
timeDilation = 2;
|
||||
await pumpTerminalApp(tester, hub: hub, layout: layout);
|
||||
await altT(tester, settle: false);
|
||||
await toggleTerminal(tester, settle: false);
|
||||
await tester.pump(const Duration(milliseconds: 300));
|
||||
expect(appBottom(tester), inExclusiveRange(shown, 800));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -112,16 +112,16 @@ void main() {
|
||||
tester,
|
||||
) async {
|
||||
await pumpTerminalApp(tester, hub: hub, layout: layout, reduceMotion: true);
|
||||
await altT(tester, settle: false);
|
||||
await toggleTerminal(tester, settle: false);
|
||||
await tester.pump();
|
||||
expect(appBottom(tester), shown);
|
||||
expect(panelOpacity(tester), 1);
|
||||
await altT(tester, settle: false);
|
||||
await toggleTerminal(tester, settle: false);
|
||||
await tester.pump();
|
||||
expect(panelFinder, findsNothing);
|
||||
expect(appBottom(tester), 800);
|
||||
layout.setMode(TerminalMode.float);
|
||||
await altT(tester, settle: false);
|
||||
await toggleTerminal(tester, settle: false);
|
||||
await tester.pump();
|
||||
expect(floatScale(tester).scale.value, 1);
|
||||
// The emulator's size reaches the server after its debounce.
|
||||
|
||||
@@ -31,16 +31,48 @@ void main() {
|
||||
|
||||
String key(String id) => terminalKey('mac', id);
|
||||
|
||||
/// Each toggle chord, and what it sends to the shell from inside the
|
||||
/// terminal (null: it hides the terminal there too).
|
||||
const toggles = {
|
||||
'Alt+T': (LogicalKeyboardKey.keyT, LogicalKeyboardKey.altLeft),
|
||||
'Ctrl+T': (LogicalKeyboardKey.keyT, LogicalKeyboardKey.controlLeft),
|
||||
'Cmd+T': (LogicalKeyboardKey.keyT, LogicalKeyboardKey.metaLeft),
|
||||
'Ctrl+`': (LogicalKeyboardKey.backquote, LogicalKeyboardKey.controlLeft),
|
||||
'Alt+T': (LogicalKeyboardKey.keyT, LogicalKeyboardKey.altLeft, '\x1bt'),
|
||||
'Ctrl+T': (LogicalKeyboardKey.keyT, LogicalKeyboardKey.controlLeft, '\x14'),
|
||||
'Cmd+T': (LogicalKeyboardKey.keyT, LogicalKeyboardKey.metaLeft, null),
|
||||
'Ctrl+`': (
|
||||
LogicalKeyboardKey.backquote,
|
||||
LogicalKeyboardKey.controlLeft,
|
||||
null,
|
||||
),
|
||||
};
|
||||
|
||||
for (final mode in TerminalMode.values) {
|
||||
for (final MapEntry(key: name, value: (letter, modifier))
|
||||
for (final MapEntry(key: name, value: (letter, modifier, sent))
|
||||
in toggles.entries) {
|
||||
if (sent != null) {
|
||||
desktopTestWidgets(
|
||||
'$name shows the ${mode.label.toLowerCase()} from a text field; '
|
||||
'inside the terminal it reaches the shell',
|
||||
(tester) async {
|
||||
layout.setMode(mode);
|
||||
await pumpTerminalApp(tester, hub: hub, layout: layout);
|
||||
await tester.tap(find.byKey(appField));
|
||||
await tester.pump();
|
||||
await chord(tester, letter, [modifier]);
|
||||
expect(layout.visible, isTrue);
|
||||
expect(find.text('t'), findsNothing);
|
||||
expect(terminalFocused(key('term_a')), isTrue);
|
||||
await chord(tester, letter, [modifier]);
|
||||
expect(layout.visible, isTrue);
|
||||
expect(mac.bodies('terminal_input').last['data'], sent);
|
||||
// Cmd+T and Ctrl+` still hide it from inside.
|
||||
await chord(tester, LogicalKeyboardKey.backquote, [
|
||||
LogicalKeyboardKey.controlLeft,
|
||||
]);
|
||||
expect(layout.visible, isFalse);
|
||||
await tester.pump(const Duration(milliseconds: 300));
|
||||
},
|
||||
);
|
||||
continue;
|
||||
}
|
||||
desktopTestWidgets(
|
||||
'$name toggles the ${mode.label.toLowerCase()} from a text '
|
||||
'field and from inside the terminal',
|
||||
@@ -58,8 +90,7 @@ void main() {
|
||||
// The shortcut never types into the field it was pressed in.
|
||||
expect(find.text('t'), findsNothing);
|
||||
expect(terminalFocused(key('term_a')), isTrue);
|
||||
// Inside the terminal the same keys hide it instead of reaching the
|
||||
// shell (Ctrl+T would be transpose-chars there).
|
||||
// Inside the terminal the same keys hide it.
|
||||
final typed = mac.bodies('terminal_input').length;
|
||||
await chord(tester, letter, [modifier]);
|
||||
expect(surface, findsNothing);
|
||||
@@ -79,6 +110,54 @@ void main() {
|
||||
timeStamp: Duration.zero,
|
||||
);
|
||||
expect(terminalToggleShortcut(event, _AltHeld()), isTrue);
|
||||
// Inside the terminal Option+T is the shell's (ESC t, or † when Option
|
||||
// is not Meta).
|
||||
expect(
|
||||
terminalToggleShortcut(event, _AltHeld(), inTerminal: true),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
|
||||
test('inside the terminal only Cmd+T and Ctrl+` toggle', () {
|
||||
KeyDownEvent down(LogicalKeyboardKey key, PhysicalKeyboardKey physical) =>
|
||||
KeyDownEvent(
|
||||
physicalKey: physical,
|
||||
logicalKey: key,
|
||||
timeStamp: Duration.zero,
|
||||
);
|
||||
final t = down(LogicalKeyboardKey.keyT, PhysicalKeyboardKey.keyT);
|
||||
final tick = down(
|
||||
LogicalKeyboardKey.backquote,
|
||||
PhysicalKeyboardKey.backquote,
|
||||
);
|
||||
bool inside(KeyDownEvent event, HardwareKeyboard keyboard) =>
|
||||
terminalToggleShortcut(event, keyboard, inTerminal: true);
|
||||
expect(inside(t, _AltHeld()), isFalse);
|
||||
expect(inside(t, _Held(control: true)), isFalse);
|
||||
expect(inside(t, _Held(meta: true)), isTrue);
|
||||
expect(inside(tick, _Held(control: true)), isTrue);
|
||||
expect(terminalToggleShortcut(t, _Held(control: true)), isTrue);
|
||||
});
|
||||
|
||||
test('the menu and cheatsheet say which keys reach the shell', () {
|
||||
expect(
|
||||
const TerminalShortcutLabels(
|
||||
web: false,
|
||||
platform: TargetPlatform.macOS,
|
||||
).inTerminalNote,
|
||||
'Inside the terminal, Option+T and Ctrl+T reach the shell; Cmd+T or '
|
||||
'Ctrl+` hides it.',
|
||||
);
|
||||
const linuxWeb = TerminalShortcutLabels(
|
||||
web: true,
|
||||
platform: TargetPlatform.linux,
|
||||
);
|
||||
expect(
|
||||
linuxWeb.inTerminalNote,
|
||||
'Inside the terminal, Alt+T and Ctrl+T reach the shell; Ctrl+` hides '
|
||||
'it.',
|
||||
);
|
||||
expect(linuxWeb.summary, contains(linuxWeb.inTerminalNote));
|
||||
});
|
||||
|
||||
desktopTestWidgets('holding the chord toggles once and types nothing', (
|
||||
@@ -127,7 +206,7 @@ void main() {
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyX);
|
||||
await tester.pump();
|
||||
expect(mac.bodies('terminal_input').last['data'], 'x');
|
||||
await altT(tester);
|
||||
await toggleTerminal(tester);
|
||||
expect(appFieldFocused(tester), isTrue);
|
||||
// The bar button focuses it as well.
|
||||
await tester.tap(find.byIcon(Icons.terminal));
|
||||
@@ -170,7 +249,7 @@ void main() {
|
||||
await ctrlTab(tester);
|
||||
expect(hub.selected!.info.id, 'term_a');
|
||||
expect(terminalFocused(key('term_a')), isTrue);
|
||||
await altT(tester);
|
||||
await toggleTerminal(tester);
|
||||
await ctrlTab(tester);
|
||||
expect(hub.selected!.info.id, 'term_a');
|
||||
});
|
||||
@@ -195,8 +274,8 @@ void main() {
|
||||
expect(empty.bodies('terminal_open'), hasLength(1));
|
||||
expect(bare.tabs, hasLength(1));
|
||||
expect(terminalFocused(bare.tabs.single.key), isTrue);
|
||||
await altT(tester);
|
||||
await altT(tester);
|
||||
await toggleTerminal(tester);
|
||||
await toggleTerminal(tester);
|
||||
expect(empty.bodies('terminal_open'), hasLength(1));
|
||||
});
|
||||
|
||||
@@ -220,7 +299,7 @@ void main() {
|
||||
await ctrlTab(tester, reverse: true);
|
||||
expect(hub.selected!.info.id, 'term_c');
|
||||
expect(terminalFocused(key('term_c')), isTrue);
|
||||
await chord(tester, LogicalKeyboardKey.keyT, [
|
||||
await chord(tester, LogicalKeyboardKey.backquote, [
|
||||
LogicalKeyboardKey.controlLeft,
|
||||
]);
|
||||
expect(find.widgetWithText(AppBar, 'Terminal'), findsNothing);
|
||||
@@ -284,6 +363,21 @@ void main() {
|
||||
});
|
||||
}
|
||||
|
||||
/// A keyboard with the given modifiers held.
|
||||
class _Held extends HardwareKeyboard {
|
||||
_Held({this.control = false, this.meta = false});
|
||||
final bool control;
|
||||
final bool meta;
|
||||
@override
|
||||
bool get isAltPressed => false;
|
||||
@override
|
||||
bool get isControlPressed => control;
|
||||
@override
|
||||
bool get isMetaPressed => meta;
|
||||
@override
|
||||
bool get isShiftPressed => false;
|
||||
}
|
||||
|
||||
/// A keyboard on which only Alt (Option) is held.
|
||||
class _AltHeld extends HardwareKeyboard {
|
||||
@override
|
||||
|
||||
@@ -265,6 +265,39 @@ void main() {
|
||||
expect(layout.mode, TerminalMode.panel);
|
||||
});
|
||||
|
||||
Future<void> pumpSettings(WidgetTester tester) => tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: SingleChildScrollView(
|
||||
child: SettingsTerminalSection(layout: layout),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
const optionAsMeta = ValueKey('settings-terminal-option-as-meta');
|
||||
|
||||
desktopTestWidgets('on a Mac, Settings chooses whether Option is Meta, '
|
||||
'saved with the layout', (tester) async {
|
||||
await pumpSettings(tester);
|
||||
expect(layout.optionAsMeta, isTrue);
|
||||
await tester.tap(find.byKey(optionAsMeta));
|
||||
await tester.pumpAndSettle();
|
||||
expect(layout.optionAsMeta, isFalse);
|
||||
expect(saved()['option_as_meta'], isFalse);
|
||||
final restored = TerminalLayout(store: store);
|
||||
await restored.restore();
|
||||
expect(restored.optionAsMeta, isFalse);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'elsewhere Alt is always Meta and there is no Option switch',
|
||||
(tester) async {
|
||||
await pumpSettings(tester);
|
||||
expect(find.byKey(optionAsMeta), findsNothing);
|
||||
},
|
||||
variant: TargetPlatformVariant.only(TargetPlatform.linux),
|
||||
);
|
||||
|
||||
desktopTestWidgets(
|
||||
'a narrow window opens the terminal full screen with the key '
|
||||
'toolbar',
|
||||
|
||||
Reference in New Issue
Block a user