Merge branch 'worktree-agent-ad4dacaa0da379451'
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:pipelines_app/features/chat/shell/chat_shell_terminal_search.dar
|
||||
import 'package:xterm/xterm.dart';
|
||||
|
||||
import 'terminal_view_harness.dart';
|
||||
import 'terminal_typing.dart';
|
||||
|
||||
const _field = ValueKey('terminal-find-field');
|
||||
|
||||
@@ -108,7 +109,7 @@ void main() {
|
||||
expect(find.byKey(_field), findsNothing);
|
||||
expect(harness.controller(tester).highlights, isEmpty);
|
||||
expect(harness.view(tester).focusNode!.hasFocus, isTrue);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyX);
|
||||
await typeKey(tester, LogicalKeyboardKey.keyX);
|
||||
await tester.pump();
|
||||
expect(harness.typed, 'x');
|
||||
}, variant: desktops);
|
||||
|
||||
@@ -0,0 +1,203 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/shell/chat_shell_terminal_keys.dart';
|
||||
import 'package:pipelines_app/features/chat/shell/chat_shell_terminal_sticky.dart';
|
||||
import 'package:pipelines_app/features/chat/shell/chat_shell_terminal_view.dart';
|
||||
|
||||
import 'terminal_typing.dart';
|
||||
import 'terminal_view_harness.dart';
|
||||
|
||||
final _touch = TargetPlatformVariant({
|
||||
TargetPlatform.android,
|
||||
TargetPlatform.iOS,
|
||||
});
|
||||
|
||||
/// A phone-sized live terminal with the touch key row under it.
|
||||
Future<TerminalViewHarness> _pumpRow(WidgetTester tester) async {
|
||||
final harness = TerminalViewHarness();
|
||||
tester.view.physicalSize = const Size(400, 700);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
addTearDown(harness.session.dispose);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ChatShellTerminalView(
|
||||
session: harness.session,
|
||||
fill: true,
|
||||
autofocus: true,
|
||||
),
|
||||
),
|
||||
ChatShellTerminalKeys(session: harness.session, touch: true),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
return harness;
|
||||
}
|
||||
|
||||
Widget _key(WidgetTester tester, String id) =>
|
||||
tester.widget(find.byKey(Key('chat-shell-key-$id')));
|
||||
|
||||
void main() {
|
||||
group('sticky modifiers', () {
|
||||
var now = DateTime(2026);
|
||||
ChatShellStickyModifiers sticky() =>
|
||||
ChatShellStickyModifiers(clock: () => now);
|
||||
|
||||
test('a tap holds one for one key; a quick second tap locks it', () {
|
||||
final mods = sticky();
|
||||
mods.tapCtrl();
|
||||
expect(mods.ctrl, ChatShellStickyState.once);
|
||||
expect(mods.take(), (ctrl: true, alt: false));
|
||||
expect(mods.ctrl, ChatShellStickyState.off);
|
||||
expect(mods.take(), (ctrl: false, alt: false));
|
||||
|
||||
mods.tapAlt();
|
||||
now = now.add(const Duration(milliseconds: 200));
|
||||
mods.tapAlt();
|
||||
expect(mods.alt, ChatShellStickyState.locked);
|
||||
expect(mods.take(), (ctrl: false, alt: true));
|
||||
expect(mods.take(), (ctrl: false, alt: true));
|
||||
mods.tapAlt();
|
||||
expect(mods.alt, ChatShellStickyState.off);
|
||||
});
|
||||
|
||||
test('a slow second tap releases a held one instead of locking it', () {
|
||||
final mods = sticky();
|
||||
mods.tapCtrl();
|
||||
now = now.add(const Duration(seconds: 2));
|
||||
mods.tapCtrl();
|
||||
expect(mods.ctrl, ChatShellStickyState.off);
|
||||
});
|
||||
|
||||
test('held text: Ctrl maps the first character, Alt prefixes ESC', () {
|
||||
expect(chatShellStickyText('c', ctrl: true, alt: false), '\x03');
|
||||
expect(chatShellStickyText('b', ctrl: false, alt: true), '\x1bb');
|
||||
expect(chatShellStickyText('cd', ctrl: true, alt: true), '\x1b\x03d');
|
||||
expect(chatShellStickyText('é', ctrl: true, alt: false), 'é');
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('the row sends the keys a phone lacks, as hardware keys do', (
|
||||
tester,
|
||||
) async {
|
||||
final harness = await _pumpRow(tester);
|
||||
for (final id in [
|
||||
'esc',
|
||||
'tab',
|
||||
'left',
|
||||
'up',
|
||||
'home',
|
||||
'end',
|
||||
'pgup',
|
||||
'pgdn',
|
||||
'sym-124',
|
||||
'sym-126',
|
||||
'sym-45',
|
||||
'sym-47',
|
||||
'sym-92',
|
||||
'enter',
|
||||
]) {
|
||||
await tapKey(tester, id);
|
||||
}
|
||||
expect(
|
||||
harness.typed,
|
||||
'\x1b\t\x1b[D\x1b[A\x1b[H\x1b[F\x1b[5~\x1b[6~|~-/\\\r',
|
||||
);
|
||||
// Application cursor keys (DECCKM) from the program's own mode.
|
||||
harness.sent.clear();
|
||||
await harness.write(tester, '\x1b[?1h');
|
||||
await tapKey(tester, 'up');
|
||||
await tapKey(tester, 'home');
|
||||
expect(harness.typed, '\x1bOA\x1bOH');
|
||||
}, variant: _touch);
|
||||
|
||||
testWidgets('a tapped Ctrl or Alt applies to the next key or typed '
|
||||
'character once; a double tap locks it until tapped again', (
|
||||
tester,
|
||||
) async {
|
||||
final harness = await _pumpRow(tester);
|
||||
final sticky = harness.session.modifiers;
|
||||
expect(_key(tester, 'ctrl'), isA<OutlinedButton>());
|
||||
await tapKey(tester, 'ctrl');
|
||||
expect(sticky.ctrl, ChatShellStickyState.once);
|
||||
expect(_key(tester, 'ctrl'), isA<FilledButton>());
|
||||
// The soft keyboard's next character takes it.
|
||||
await commitText(tester, 'c');
|
||||
expect(harness.typed, '\x03');
|
||||
expect(sticky.ctrl, ChatShellStickyState.off);
|
||||
await commitText(tester, 'c');
|
||||
expect(harness.typed, '\x03c');
|
||||
|
||||
// A row key takes it too, with xterm's modifier parameter.
|
||||
harness.sent.clear();
|
||||
await tapKey(tester, 'ctrl');
|
||||
await tapKey(tester, 'right');
|
||||
expect(harness.typed, '\x1b[1;5C');
|
||||
await tapKey(tester, 'ctrl');
|
||||
await tapKey(tester, 'sym-47');
|
||||
expect(harness.typed, '\x1b[1;5C\x1f');
|
||||
|
||||
// Double tap: locked for every key until released.
|
||||
harness.sent.clear();
|
||||
await tester.ensureVisible(find.byKey(const Key('chat-shell-key-alt')));
|
||||
await tester.pump();
|
||||
await tester.tap(find.byKey(const Key('chat-shell-key-alt')));
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
await tester.tap(find.byKey(const Key('chat-shell-key-alt')));
|
||||
await tester.pump();
|
||||
expect(sticky.alt, ChatShellStickyState.locked);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('chat-shell-key-alt')),
|
||||
matching: find.byIcon(Icons.lock),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
await commitText(tester, 'b');
|
||||
await commitText(tester, 'f');
|
||||
await tapKey(tester, 'left');
|
||||
expect(harness.typed, '\x1bb\x1bf\x1b[1;3D');
|
||||
expect(sticky.alt, ChatShellStickyState.locked);
|
||||
await tapKey(tester, 'alt');
|
||||
expect(sticky.alt, ChatShellStickyState.off);
|
||||
await commitText(tester, 'b');
|
||||
expect(harness.typed, '\x1bb\x1bf\x1b[1;3Db');
|
||||
}, variant: _touch);
|
||||
|
||||
testWidgets('a held modifier applies to a soft keyboard key event', (
|
||||
tester,
|
||||
) async {
|
||||
final harness = await _pumpRow(tester);
|
||||
await tapKey(tester, 'ctrl');
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.backspace);
|
||||
expect(harness.typed, '\b');
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.backspace);
|
||||
expect(harness.typed, '\b\x7f');
|
||||
}, variant: _touch);
|
||||
|
||||
testWidgets(
|
||||
'Line opens a field for a whole line, sent with Enter',
|
||||
(tester) async {
|
||||
final harness = await _pumpRow(tester);
|
||||
final field = find.byKey(const Key('chat-shell-terminal-field'));
|
||||
expect(field, findsNothing);
|
||||
await tapKey(tester, 'line');
|
||||
expect(field, findsOneWidget);
|
||||
await tester.enterText(field, 'echo hi');
|
||||
await tester.testTextInput.receiveAction(TextInputAction.send);
|
||||
await tester.pump();
|
||||
expect(harness.typed, 'echo hi\r');
|
||||
await tapKey(tester, 'line');
|
||||
expect(field, findsNothing);
|
||||
},
|
||||
variant: TargetPlatformVariant.only(TargetPlatform.android),
|
||||
);
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import 'package:pipelines_app/features/chat/shell/chat_shell_runs_controller.dar
|
||||
import 'package:xterm/xterm.dart';
|
||||
|
||||
import 'chat_shell_fixtures.dart';
|
||||
import 'terminal_typing.dart';
|
||||
|
||||
void main() {
|
||||
late ShellGateway gateway;
|
||||
@@ -43,8 +44,8 @@ void main() {
|
||||
expect(find.byKey(const Key('chat-shell-terminal-field')), findsNothing);
|
||||
await tester.tap(find.byType(TerminalView));
|
||||
await tester.pump();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyG);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.digit7);
|
||||
await typeKey(tester, LogicalKeyboardKey.keyG);
|
||||
await typeKey(tester, LogicalKeyboardKey.digit7);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyC);
|
||||
@@ -156,7 +157,7 @@ void main() {
|
||||
await press(tester, LogicalKeyboardKey.arrowLeft, modifiers: alt);
|
||||
await press(tester, LogicalKeyboardKey.arrowRight, modifiers: ctrl);
|
||||
await press(tester, LogicalKeyboardKey.keyT, modifiers: ctrl);
|
||||
await press(tester, LogicalKeyboardKey.keyX);
|
||||
await typeKey(tester, LogicalKeyboardKey.keyX);
|
||||
expect(
|
||||
typed(),
|
||||
'\x1bb\x1bf\x1b.\x1bB\x1b\x7f\x1f\x1d'
|
||||
@@ -289,10 +290,8 @@ void main() {
|
||||
),
|
||||
);
|
||||
await openRunning(tester);
|
||||
await tester.tap(find.byKey(const Key('chat-shell-key-paste')));
|
||||
await tester.pump();
|
||||
await tester.tap(find.byKey(const Key('chat-shell-key-enter')));
|
||||
await tester.pump();
|
||||
await tapKey(tester, 'paste');
|
||||
await tapKey(tester, 'enter');
|
||||
expect(typed(), 'gho_pasted-token\r');
|
||||
});
|
||||
|
||||
@@ -301,13 +300,16 @@ void main() {
|
||||
) async {
|
||||
await openRunning(tester, output: 'Password: ');
|
||||
for (final key in ['ctrl-c', 'tab', 'esc', 'left', 'down', 'right']) {
|
||||
await tester.tap(find.byKey(Key('chat-shell-key-$key')));
|
||||
await tester.pump();
|
||||
await tapKey(tester, key);
|
||||
}
|
||||
expect(typed(), '\x03\t\x1b\x1b[D\x1b[B\x1b[C');
|
||||
gateway.calls.clear();
|
||||
|
||||
// Typing goes to the terminal key by key; Line opens a field for a
|
||||
// whole line.
|
||||
final field = find.byKey(const Key('chat-shell-terminal-field'));
|
||||
expect(field, findsNothing);
|
||||
await tapKey(tester, 'line');
|
||||
expect(field, findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('chat-shell-terminal-hide')));
|
||||
await tester.pump();
|
||||
@@ -331,8 +333,7 @@ void main() {
|
||||
expect(tester.testTextInput.isVisible, isTrue);
|
||||
expect(tester.testTextInput.hasAnyClients, isTrue);
|
||||
gateway.calls.clear();
|
||||
tester.testTextInput.enterText('tok');
|
||||
await tester.pump();
|
||||
await commitText(tester, 'tok');
|
||||
await tester.testTextInput.receiveAction(TextInputAction.newline);
|
||||
await tester.pump();
|
||||
expect(typed(), startsWith('tok'));
|
||||
@@ -390,7 +391,7 @@ void main() {
|
||||
expect(claim['activate'], isTrue);
|
||||
expect((claim['cols'], claim['rows']), (laidOut['cols'], laidOut['rows']));
|
||||
// Typing carries this client's size.
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyG);
|
||||
await typeKey(tester, LogicalKeyboardKey.keyG);
|
||||
await tester.pump();
|
||||
var inputs = gateway.bodies('chat_shell_input');
|
||||
expect(inputs.single['data'], 'g');
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:xterm/xterm.dart';
|
||||
|
||||
import 'terminal_typing.dart';
|
||||
import 'terminal_view_harness.dart';
|
||||
|
||||
/// Desktops whose IMEs, dead keys, emoji pickers and dictation commit text
|
||||
/// through the text input (the web runs on these too).
|
||||
final _desktops = TargetPlatformVariant({
|
||||
TargetPlatform.macOS,
|
||||
TargetPlatform.linux,
|
||||
TargetPlatform.windows,
|
||||
});
|
||||
|
||||
void main() {
|
||||
testWidgets('a desktop terminal takes committed text from the text input: '
|
||||
'IME, dead keys, emoji and dictation', (tester) async {
|
||||
final harness = TerminalViewHarness();
|
||||
await harness.pump(tester);
|
||||
expect(tester.testTextInput.hasAnyClients, isTrue);
|
||||
// A dead key's composed character, a CJK commit, an emoji, a phrase.
|
||||
await commitText(tester, 'é');
|
||||
await commitText(tester, '日本');
|
||||
await commitText(tester, '\u{1F44D}');
|
||||
await commitText(tester, ':q!');
|
||||
expect(harness.typed, 'é日本\u{1F44D}:q!');
|
||||
}, variant: _desktops);
|
||||
|
||||
testWidgets('composing text is drawn at the cursor and sent only when '
|
||||
'committed; the IME keeps its keys meanwhile', (tester) async {
|
||||
final harness = TerminalViewHarness();
|
||||
await harness.pump(tester);
|
||||
final render = harness.viewState(tester).renderTerminal;
|
||||
await composeText(tester, 'にほ');
|
||||
expect(render.composingText, 'にほ');
|
||||
// Enter picks the IME's candidate, not the shell's line.
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.backspace);
|
||||
expect(harness.typed, isEmpty);
|
||||
await commitText(tester, '日本');
|
||||
expect(render.composingText, isNull);
|
||||
expect(harness.typed, '日本');
|
||||
// A dead key: ´ is shown, é is sent.
|
||||
await composeText(tester, '´');
|
||||
expect(harness.typed, '日本');
|
||||
await commitText(tester, 'é');
|
||||
expect(harness.typed, '日本é');
|
||||
// A cancelled composition sends nothing.
|
||||
await composeText(tester, 'x');
|
||||
await commitText(tester, '');
|
||||
expect(harness.typed, '日本é');
|
||||
}, variant: _desktops);
|
||||
|
||||
testWidgets('a key the terminal encodes is taken, so the platform never '
|
||||
'types it again; a printing key is left to the text input', (
|
||||
tester,
|
||||
) async {
|
||||
final harness = TerminalViewHarness();
|
||||
await harness.pump(tester);
|
||||
// Handled: the browser's default (inserting text) is prevented.
|
||||
expect(await tester.sendKeyEvent(LogicalKeyboardKey.enter), isTrue);
|
||||
expect(await tester.sendKeyEvent(LogicalKeyboardKey.backspace), isTrue);
|
||||
expect(await tester.sendKeyEvent(LogicalKeyboardKey.arrowLeft), isTrue);
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
|
||||
expect(await tester.sendKeyEvent(LogicalKeyboardKey.keyC), isTrue);
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
|
||||
expect(harness.typed, '\r\x7f\x1b[D\x03');
|
||||
// Not handled: the platform types it through the text input, once.
|
||||
expect(await tester.sendKeyEvent(LogicalKeyboardKey.keyA), isFalse);
|
||||
expect(harness.typed, '\r\x7f\x1b[D\x03');
|
||||
await typeKey(tester, LogicalKeyboardKey.keyA);
|
||||
expect(harness.typed, '\r\x7f\x1b[D\x03a');
|
||||
}, variant: _desktops);
|
||||
|
||||
testWidgets('after the platform closes the text input (a browser window '
|
||||
'losing focus), a printing key is typed and the input reopened', (
|
||||
tester,
|
||||
) async {
|
||||
final harness = TerminalViewHarness();
|
||||
await harness.pump(tester);
|
||||
tester.testTextInput.closeConnection();
|
||||
await tester.pump();
|
||||
tester.testTextInput.log.clear();
|
||||
expect(await tester.sendKeyEvent(LogicalKeyboardKey.keyQ), isTrue);
|
||||
expect(harness.typed, 'q');
|
||||
expect(
|
||||
tester.testTextInput.log.map((call) => call.method),
|
||||
contains('TextInput.setClient'),
|
||||
);
|
||||
await commitText(tester, 'w');
|
||||
expect(harness.typed, 'qw');
|
||||
}, variant: _desktops);
|
||||
|
||||
testWidgets('the text input sits at the cursor, so an IME opens its '
|
||||
'candidates there', (tester) async {
|
||||
final harness = TerminalViewHarness();
|
||||
await harness.pump(tester);
|
||||
await harness.write(tester, r'$ echo ');
|
||||
tester.testTextInput.log.clear();
|
||||
await tester.pump();
|
||||
// The editable follows the cursor once painted.
|
||||
harness.terminal.write('x');
|
||||
await tester.pump();
|
||||
final calls = tester.testTextInput.log.where(
|
||||
(call) => call.method == 'TextInput.setEditableSizeAndTransform',
|
||||
);
|
||||
expect(calls, isNotEmpty);
|
||||
final transform = List<num>.from(
|
||||
(calls.last.arguments as Map)['transform'] as List,
|
||||
);
|
||||
final cursor = harness.viewState(tester).globalCursorRect;
|
||||
expect(transform[12], moreOrLessEquals(cursor.left));
|
||||
expect(transform[13], moreOrLessEquals(cursor.top));
|
||||
}, variant: TargetPlatformVariant.only(TargetPlatform.macOS));
|
||||
|
||||
testWidgets('a live terminal is a focused text field to assistive '
|
||||
'technology (the web text input under semantics)', (tester) async {
|
||||
final semantics = tester.ensureSemantics();
|
||||
final harness = TerminalViewHarness();
|
||||
await harness.pump(tester);
|
||||
expect(
|
||||
tester.getSemantics(find.byType(TerminalView)),
|
||||
isSemantics(isTextField: true, isFocused: true, isEnabled: true),
|
||||
);
|
||||
semantics.dispose();
|
||||
}, variant: TargetPlatformVariant.only(TargetPlatform.linux));
|
||||
|
||||
testWidgets('a finished run attaches no text input', (tester) async {
|
||||
final harness = TerminalViewHarness(live: false);
|
||||
await harness.pump(tester);
|
||||
await tester.tap(find.byType(TerminalView));
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
expect(tester.testTextInput.hasAnyClients, isFalse);
|
||||
}, variant: _desktops);
|
||||
|
||||
testWidgets('a soft keyboard types key by key: characters, Backspace and '
|
||||
'Return reach the process without submitting a line', (tester) async {
|
||||
final harness = TerminalViewHarness();
|
||||
await harness.pump(tester);
|
||||
expect(defaultTargetPlatform, TargetPlatform.android);
|
||||
await commitText(tester, 'l');
|
||||
expect(harness.typed, 'l');
|
||||
await commitText(tester, 's');
|
||||
expect(harness.typed, 'ls');
|
||||
// Backspace on the (otherwise empty) field deletes one of its two
|
||||
// placeholder spaces, which is read as Backspace.
|
||||
final before = '${tester.testTextInput.editingState!['text']}';
|
||||
expect(before, ' ');
|
||||
tester.testTextInput.updateEditingValue(
|
||||
const TextEditingValue(
|
||||
text: ' ',
|
||||
selection: TextSelection.collapsed(offset: 1),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(harness.typed, 'ls\x7f');
|
||||
// Return types a line break, which is Enter.
|
||||
await commitText(tester, '\n');
|
||||
expect(harness.typed, 'ls\x7f\r');
|
||||
// Close the keyboard connection before the tree goes away.
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
}, variant: TargetPlatformVariant.only(TargetPlatform.android));
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
/// Commits [text] through the platform text input, as an IME, dead key,
|
||||
/// the emoji picker, dictation or a soft keyboard does: appended to what
|
||||
/// the focused client last told the platform, the caret at its end.
|
||||
Future<void> commitText(WidgetTester tester, String text) async {
|
||||
final before = '${tester.testTextInput.editingState?['text'] ?? ''}';
|
||||
final value = '$before$text';
|
||||
tester.testTextInput.updateEditingValue(
|
||||
TextEditingValue(
|
||||
text: value,
|
||||
selection: TextSelection.collapsed(offset: value.length),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
/// Sends [text] as composing (marked) text: drawn, not yet committed.
|
||||
Future<void> composeText(WidgetTester tester, String text) async {
|
||||
final before = '${tester.testTextInput.editingState?['text'] ?? ''}';
|
||||
final value = '$before$text';
|
||||
tester.testTextInput.updateEditingValue(
|
||||
TextEditingValue(
|
||||
text: value,
|
||||
selection: TextSelection.collapsed(offset: value.length),
|
||||
composing: TextRange(start: before.length, end: value.length),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
/// Presses [key] as a desktop platform does: the key event first, and only
|
||||
/// if no handler took it, its [character] (default: the key's label in
|
||||
/// lower case) through the text input. A key the terminal encoded is never
|
||||
/// typed a second time.
|
||||
Future<void> typeKey(
|
||||
WidgetTester tester,
|
||||
LogicalKeyboardKey key, {
|
||||
String? character,
|
||||
}) async {
|
||||
final handled = await tester.sendKeyEvent(key, character: character);
|
||||
if (!handled) {
|
||||
final text = character ?? key.keyLabel.toLowerCase();
|
||||
if (text.isNotEmpty) await commitText(tester, text);
|
||||
}
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
/// Taps the key toolbar's key [id] (`chat-shell-key-<id>`), scrolling the
|
||||
/// touch key row to it first.
|
||||
Future<void> tapKey(WidgetTester tester, String id) async {
|
||||
final key = find.byKey(Key('chat-shell-key-$id'));
|
||||
await tester.ensureVisible(key);
|
||||
await tester.pump();
|
||||
await tester.tap(key);
|
||||
await tester.pump();
|
||||
}
|
||||
@@ -131,6 +131,26 @@ void main() {
|
||||
expect(actions, isNot(contains('Move between terminal tabs')));
|
||||
});
|
||||
|
||||
test('a browser outside macOS documents capturing its keys', () {
|
||||
List<String> actions(TargetPlatform platform, {required bool web}) => [
|
||||
for (final entry in KeyboardShortcutRegistry(
|
||||
platform: platform,
|
||||
web: web,
|
||||
).entries)
|
||||
entry.action,
|
||||
];
|
||||
const action = 'Send browser keys to the terminal';
|
||||
final entry = _entry(
|
||||
const KeyboardShortcutRegistry(platform: TargetPlatform.linux, web: true),
|
||||
action,
|
||||
);
|
||||
expect(entry.group, KeyboardShortcutGroup.terminal);
|
||||
expect(entry.caveat, contains('Alt+Backspace'));
|
||||
expect(entry.caveat, contains('hold Esc'));
|
||||
expect(actions(TargetPlatform.macOS, web: true), isNot(contains(action)));
|
||||
expect(actions(TargetPlatform.linux, web: false), isNot(contains(action)));
|
||||
});
|
||||
|
||||
test('Search documents field-scoped Control navigation', () {
|
||||
final registry = KeyboardShortcutRegistry(
|
||||
platform: TargetPlatform.macOS,
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/terminal/terminal_browser_keys.dart';
|
||||
import 'package:pipelines_app/features/terminal/terminal_hub.dart';
|
||||
import 'package:pipelines_app/features/terminal/terminal_layout.dart';
|
||||
import 'package:pipelines_app/features/terminal/terminal_tab_strip.dart';
|
||||
|
||||
import '../chat/shell/terminal_view_harness.dart';
|
||||
import 'terminal_fixtures.dart';
|
||||
|
||||
/// A browser's Keyboard Lock, recorded.
|
||||
class FakeBrowserKeys implements TerminalBrowserKeysBackend {
|
||||
FakeBrowserKeys({this.supported = true, this.grant = true});
|
||||
|
||||
@override
|
||||
final bool supported;
|
||||
final bool grant;
|
||||
int locks = 0;
|
||||
int unlocks = 0;
|
||||
void Function()? released;
|
||||
|
||||
@override
|
||||
Future<bool> lock() async {
|
||||
locks++;
|
||||
return grant;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> unlock() async => unlocks++;
|
||||
|
||||
@override
|
||||
set onReleased(void Function() callback) => released = callback;
|
||||
}
|
||||
|
||||
void main() {
|
||||
final original = TerminalBrowserKeys.instance;
|
||||
tearDown(() => TerminalBrowserKeys.instance = original);
|
||||
|
||||
test('capture locks the keys until released by the app or the browser '
|
||||
'(Esc held)', () async {
|
||||
final backend = FakeBrowserKeys();
|
||||
final keys = TerminalBrowserKeys(backend: backend);
|
||||
expect(keys.supported, isTrue);
|
||||
expect(await keys.capture(), isTrue);
|
||||
expect(keys.active, isTrue);
|
||||
expect(terminalBrowserKeysLabel(keys), 'Release browser keys');
|
||||
await keys.release();
|
||||
expect((keys.active, backend.unlocks), (false, 1));
|
||||
await keys.capture();
|
||||
backend.released!();
|
||||
expect(keys.active, isFalse);
|
||||
expect(terminalBrowserKeysLabel(keys), 'Capture browser keys');
|
||||
});
|
||||
|
||||
test('a refused lock or an unsupported browser leaves it off', () async {
|
||||
final refused = TerminalBrowserKeys(backend: FakeBrowserKeys(grant: false));
|
||||
expect(await refused.capture(), isFalse);
|
||||
expect(refused.active, isFalse);
|
||||
final none = FakeBrowserKeys(supported: false);
|
||||
final unsupported = TerminalBrowserKeys(backend: none);
|
||||
expect(await unsupported.capture(), isFalse);
|
||||
expect(none.locks, 0);
|
||||
});
|
||||
|
||||
test('native builds (and tests) have nothing to capture', () {
|
||||
expect(TerminalBrowserKeys().supported, isFalse);
|
||||
});
|
||||
|
||||
Future<void> pumpStrip(WidgetTester tester) async {
|
||||
final hub = TerminalHub(TestMachines([]));
|
||||
addTearDown(hub.dispose);
|
||||
final layout = TerminalLayout(store: MemoryLayoutStore());
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: TerminalTabStrip(hub: hub, layout: layout),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
const item = ValueKey('terminal-browser-keys');
|
||||
|
||||
testWidgets('the terminal menu offers Capture browser keys where the '
|
||||
'browser can, checked while on', (tester) async {
|
||||
final backend = FakeBrowserKeys();
|
||||
TerminalBrowserKeys.instance = TerminalBrowserKeys(backend: backend);
|
||||
await pumpStrip(tester);
|
||||
await tester.tap(find.byTooltip('Terminal options'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(item), findsOneWidget);
|
||||
expect(
|
||||
tester.widget<CheckedPopupMenuItem<Object?>>(find.byKey(item)).checked,
|
||||
isFalse,
|
||||
);
|
||||
await tester.tap(find.byKey(item));
|
||||
await tester.pumpAndSettle();
|
||||
expect(backend.locks, 1);
|
||||
expect(find.textContaining('Hold Esc'), findsOneWidget);
|
||||
await tester.tap(find.byTooltip('Terminal options'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.widget<CheckedPopupMenuItem<Object?>>(find.byKey(item)).checked,
|
||||
isTrue,
|
||||
);
|
||||
await tester.tap(find.byKey(item));
|
||||
await tester.pumpAndSettle();
|
||||
expect(backend.unlocks, 1);
|
||||
expect(TerminalBrowserKeys.instance.active, isFalse);
|
||||
});
|
||||
|
||||
testWidgets('no such item where the browser cannot capture its keys', (
|
||||
tester,
|
||||
) async {
|
||||
TerminalBrowserKeys.instance = TerminalBrowserKeys(
|
||||
backend: FakeBrowserKeys(supported: false),
|
||||
);
|
||||
await pumpStrip(tester);
|
||||
await tester.tap(find.byTooltip('Terminal options'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(item), findsNothing);
|
||||
expect(find.byKey(const ValueKey('terminal-hide')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a refused capture says so', (tester) async {
|
||||
TerminalBrowserKeys.instance = TerminalBrowserKeys(
|
||||
backend: FakeBrowserKeys(grant: false),
|
||||
);
|
||||
await pumpStrip(tester);
|
||||
await tester.tap(find.byTooltip('Terminal options'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(item));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.textContaining('did not let the page'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets("the chat terminal's right-click menu has it too", (
|
||||
tester,
|
||||
) async {
|
||||
final backend = FakeBrowserKeys();
|
||||
TerminalBrowserKeys.instance = TerminalBrowserKeys(backend: backend);
|
||||
final harness = TerminalViewHarness();
|
||||
await harness.pump(tester);
|
||||
await harness.rightClick(tester, 1, 0);
|
||||
final menuItem = find.byKey(const ValueKey('terminal-menu-browserKeys'));
|
||||
expect(menuItem, findsOneWidget);
|
||||
expect(find.text('Capture browser keys'), findsOneWidget);
|
||||
await tester.tap(menuItem);
|
||||
await tester.pumpAndSettle();
|
||||
expect(backend.locks, 1);
|
||||
await harness.rightClick(tester, 1, 0);
|
||||
expect(find.text('Release browser keys'), findsOneWidget);
|
||||
}, variant: desktops);
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import 'package:xterm/xterm.dart';
|
||||
|
||||
import 'terminal_app.dart';
|
||||
import 'terminal_fixtures.dart';
|
||||
import '../chat/shell/terminal_typing.dart';
|
||||
|
||||
void main() {
|
||||
late TerminalGateway mac;
|
||||
@@ -160,6 +161,24 @@ void main() {
|
||||
expect(linuxWeb.summary, contains(linuxWeb.inTerminalNote));
|
||||
});
|
||||
|
||||
test('a browser outside macOS keeps Ctrl+W: the menu says how to send '
|
||||
'it anyway and what to press instead', () {
|
||||
const linuxWeb = TerminalShortcutLabels(
|
||||
web: true,
|
||||
platform: TargetPlatform.linux,
|
||||
);
|
||||
expect(linuxWeb.browserKeysNote, contains('Capture browser keys'));
|
||||
expect(linuxWeb.browserKeysNote, contains('Alt+Backspace'));
|
||||
expect(linuxWeb.summary, contains(linuxWeb.browserKeysNote));
|
||||
for (final labels in const [
|
||||
TerminalShortcutLabels(web: true, platform: TargetPlatform.macOS),
|
||||
TerminalShortcutLabels(web: false, platform: TargetPlatform.linux),
|
||||
]) {
|
||||
expect(labels.browserKeysNote, isNull);
|
||||
expect(labels.summary, isNot(contains('Ctrl+W')));
|
||||
}
|
||||
});
|
||||
|
||||
desktopTestWidgets('holding the chord toggles once and types nothing', (
|
||||
tester,
|
||||
) async {
|
||||
@@ -203,8 +222,7 @@ void main() {
|
||||
expect(terminalFocused(key('term_a')), isTrue);
|
||||
expect(appFieldFocused(tester), isFalse);
|
||||
// Typing goes straight to the shell.
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyX);
|
||||
await tester.pump();
|
||||
await typeKey(tester, LogicalKeyboardKey.keyX);
|
||||
expect(mac.bodies('terminal_input').last['data'], 'x');
|
||||
await toggleTerminal(tester);
|
||||
expect(appFieldFocused(tester), isTrue);
|
||||
@@ -348,8 +366,7 @@ void main() {
|
||||
// App-wide shortcuts see a typing surface and leave the key alone.
|
||||
expect(primaryFocusIsTypingSurface(), isTrue);
|
||||
expect(primaryFocusTakesTyping(), isTrue);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.slash, character: '/');
|
||||
await tester.pump();
|
||||
await typeKey(tester, LogicalKeyboardKey.slash, character: '/');
|
||||
expect(terminalFocused(key('term_a')), isTrue);
|
||||
expect(
|
||||
mac.bodies('terminal_input').map((b) => b['data']).join(),
|
||||
|
||||
@@ -13,6 +13,7 @@ import 'package:xterm/xterm.dart';
|
||||
|
||||
import 'terminal_app.dart';
|
||||
import 'terminal_fixtures.dart';
|
||||
import '../chat/shell/terminal_typing.dart';
|
||||
|
||||
void main() {
|
||||
late TerminalGateway mac;
|
||||
@@ -73,8 +74,7 @@ void main() {
|
||||
// The terminal has the keyboard, yet the shortcut still hides it.
|
||||
await tester.tap(find.byType(TerminalView));
|
||||
await tester.pump();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyX);
|
||||
await tester.pump();
|
||||
await typeKey(tester, LogicalKeyboardKey.keyX);
|
||||
expect(mac.bodies('terminal_input').last['data'], 'x');
|
||||
await ctrlBacktick(tester);
|
||||
expect(find.byKey(const ValueKey('terminal-panel')), findsNothing);
|
||||
|
||||
Reference in New Issue
Block a user