Merge main into the terminal flow-control branch
Conflicts resolved keeping both sides: main's active-client rules, input lane, reply marking and key input, and this branch's flow control, acknowledgements, subscriptions and sliced emulator feed. terminal_ack joins the terminal lane; the feed marks each live slice it writes as drawing, so the emulator's answers still go to onReply. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,309 @@
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/shell/chat_shell_run.dart';
|
||||
import 'package:pipelines_app/features/chat/shell/chat_shell_terminal_key_input.dart';
|
||||
import 'package:pipelines_app/features/chat/shell/chat_shell_terminal_session.dart';
|
||||
import 'package:xterm/core.dart';
|
||||
|
||||
/// Modifiers held, as [chatShellKeyEventBytes] reads them.
|
||||
class _Held extends HardwareKeyboard {
|
||||
_Held(String mods)
|
||||
: shift = mods.contains('S'),
|
||||
alt = mods.contains('A'),
|
||||
ctrl = mods.contains('C'),
|
||||
meta = mods.contains('M');
|
||||
final bool shift, alt, ctrl, meta;
|
||||
@override
|
||||
bool get isShiftPressed => shift;
|
||||
@override
|
||||
bool get isAltPressed => alt;
|
||||
@override
|
||||
bool get isControlPressed => ctrl;
|
||||
@override
|
||||
bool get isMetaPressed => meta;
|
||||
}
|
||||
|
||||
KeyDownEvent _down(
|
||||
LogicalKeyboardKey logical, {
|
||||
PhysicalKeyboardKey? physical,
|
||||
String? character,
|
||||
}) => KeyDownEvent(
|
||||
physicalKey: physical ?? PhysicalKeyboardKey.keyA,
|
||||
logicalKey: logical,
|
||||
character: character,
|
||||
timeStamp: Duration.zero,
|
||||
);
|
||||
|
||||
/// The bytes a key sends with [mods] (S Shift, A Alt, C Ctrl, M Meta).
|
||||
String? _bytes(
|
||||
LogicalKeyboardKey logical, {
|
||||
String mods = '',
|
||||
String? character,
|
||||
PhysicalKeyboardKey? physical,
|
||||
Terminal? terminal,
|
||||
bool optionAsMeta = true,
|
||||
}) => chatShellKeyEventBytes(
|
||||
_down(logical, physical: physical, character: character),
|
||||
_Held(mods),
|
||||
terminal ?? Terminal(),
|
||||
optionAsMeta: optionAsMeta,
|
||||
);
|
||||
|
||||
const _l = LogicalKeyboardKey.new;
|
||||
|
||||
void main() {
|
||||
final linux = TargetPlatformVariant.only(TargetPlatform.linux);
|
||||
final mac = TargetPlatformVariant.only(TargetPlatform.macOS);
|
||||
|
||||
testWidgets('Alt is Meta: ESC and the character typed, Shift and layout '
|
||||
'included', (tester) async {
|
||||
expect(_bytes(LogicalKeyboardKey.keyB, mods: 'A', character: 'b'), '\x1bb');
|
||||
expect(_bytes(LogicalKeyboardKey.keyF, mods: 'A', character: 'f'), '\x1bf');
|
||||
expect(_bytes(LogicalKeyboardKey.keyD, mods: 'A', character: 'd'), '\x1bd');
|
||||
expect(
|
||||
_bytes(LogicalKeyboardKey.keyB, mods: 'AS', character: 'B'),
|
||||
'\x1bB',
|
||||
);
|
||||
expect(
|
||||
_bytes(LogicalKeyboardKey.period, mods: 'A', character: '.'),
|
||||
'\x1b.',
|
||||
);
|
||||
expect(
|
||||
_bytes(LogicalKeyboardKey.digit1, mods: 'A', character: '1'),
|
||||
'\x1b1',
|
||||
);
|
||||
// Without a character (some platforms send none with Alt): the key's.
|
||||
expect(_bytes(LogicalKeyboardKey.keyT, mods: 'A'), '\x1bt');
|
||||
expect(_bytes(LogicalKeyboardKey.period, mods: 'AS'), '\x1b>');
|
||||
// A non-US layout's own character (AZERTY's A key types "q").
|
||||
expect(_bytes(LogicalKeyboardKey.keyQ, mods: 'A', character: 'q'), '\x1bq');
|
||||
expect(_bytes(LogicalKeyboardKey.backspace, mods: 'A'), '\x1b\x7f');
|
||||
expect(_bytes(LogicalKeyboardKey.enter, mods: 'A'), '\x1b\r');
|
||||
expect(
|
||||
_bytes(LogicalKeyboardKey.space, mods: 'A', character: ' '),
|
||||
'\x1b ',
|
||||
);
|
||||
}, variant: linux);
|
||||
|
||||
testWidgets('Ctrl sends the control code of letters and symbols', (
|
||||
tester,
|
||||
) async {
|
||||
final table = <(LogicalKeyboardKey, String, String), String>{
|
||||
(LogicalKeyboardKey.keyA, '', 'a'): '\x01',
|
||||
(LogicalKeyboardKey.keyT, '', 't'): '\x14',
|
||||
(LogicalKeyboardKey.keyT, 'S', 'T'): '\x14',
|
||||
(LogicalKeyboardKey.slash, '', '/'): '\x1f',
|
||||
(LogicalKeyboardKey.bracketRight, '', ']'): '\x1d',
|
||||
(LogicalKeyboardKey.backslash, '', '\\'): '\x1c',
|
||||
(LogicalKeyboardKey.bracketLeft, '', '['): '\x1b',
|
||||
(LogicalKeyboardKey.minus, 'S', '_'): '\x1f',
|
||||
(LogicalKeyboardKey.digit2, '', '2'): '\x00',
|
||||
(LogicalKeyboardKey.digit2, 'S', '@'): '\x00',
|
||||
(LogicalKeyboardKey.digit6, 'S', '^'): '\x1e',
|
||||
(LogicalKeyboardKey.digit8, '', '8'): '\x7f',
|
||||
(LogicalKeyboardKey.space, '', ' '): '\x00',
|
||||
(LogicalKeyboardKey.keyB, 'A', 'b'): '\x1b\x02',
|
||||
};
|
||||
for (final MapEntry(key: (key, mods, character), value: bytes)
|
||||
in table.entries) {
|
||||
expect(
|
||||
_bytes(key, mods: 'C$mods', character: character),
|
||||
bytes,
|
||||
reason: 'Ctrl+$mods $character',
|
||||
);
|
||||
}
|
||||
// A control character as the event's character still maps by key.
|
||||
expect(
|
||||
_bytes(LogicalKeyboardKey.slash, mods: 'C', character: '\x1f'),
|
||||
'\x1f',
|
||||
);
|
||||
expect(_bytes(LogicalKeyboardKey.backspace, mods: 'C'), '\b');
|
||||
// Ctrl+1 has no control code: the emulator types it.
|
||||
expect(
|
||||
_bytes(LogicalKeyboardKey.digit1, mods: 'C', character: '1'),
|
||||
isNull,
|
||||
);
|
||||
}, variant: linux);
|
||||
|
||||
testWidgets('modified special keys use the xterm modifier parameter', (
|
||||
tester,
|
||||
) async {
|
||||
const up = LogicalKeyboardKey.arrowUp;
|
||||
expect(_bytes(up), '\x1b[A');
|
||||
expect(_bytes(up, mods: 'S'), '\x1b[1;2A');
|
||||
expect(_bytes(LogicalKeyboardKey.arrowLeft, mods: 'A'), '\x1b[1;3D');
|
||||
expect(_bytes(LogicalKeyboardKey.arrowDown, mods: 'AS'), '\x1b[1;4B');
|
||||
expect(_bytes(LogicalKeyboardKey.arrowRight, mods: 'C'), '\x1b[1;5C');
|
||||
expect(_bytes(up, mods: 'CS'), '\x1b[1;6A');
|
||||
expect(_bytes(up, mods: 'CA'), '\x1b[1;7A');
|
||||
expect(_bytes(up, mods: 'CAS'), '\x1b[1;8A');
|
||||
expect(_bytes(LogicalKeyboardKey.home), '\x1b[H');
|
||||
expect(_bytes(LogicalKeyboardKey.end, mods: 'S'), '\x1b[1;2F');
|
||||
expect(_bytes(LogicalKeyboardKey.home, mods: 'C'), '\x1b[1;5H');
|
||||
expect(_bytes(LogicalKeyboardKey.pageUp), '\x1b[5~');
|
||||
expect(_bytes(LogicalKeyboardKey.pageUp, mods: 'S'), '\x1b[5;2~');
|
||||
expect(_bytes(LogicalKeyboardKey.pageDown, mods: 'C'), '\x1b[6;5~');
|
||||
expect(_bytes(LogicalKeyboardKey.insert), '\x1b[2~');
|
||||
expect(_bytes(LogicalKeyboardKey.delete), '\x1b[3~');
|
||||
expect(_bytes(LogicalKeyboardKey.delete, mods: 'A'), '\x1b[3;3~');
|
||||
expect(_bytes(LogicalKeyboardKey.f1), '\x1bOP');
|
||||
expect(_bytes(LogicalKeyboardKey.f1, mods: 'S'), '\x1b[1;2P');
|
||||
expect(_bytes(LogicalKeyboardKey.f4, mods: 'C'), '\x1b[1;5S');
|
||||
expect(_bytes(LogicalKeyboardKey.f5), '\x1b[15~');
|
||||
expect(_bytes(LogicalKeyboardKey.f12, mods: 'C'), '\x1b[24;5~');
|
||||
expect(_bytes(LogicalKeyboardKey.tab, mods: 'S'), '\x1b[Z');
|
||||
expect(_bytes(LogicalKeyboardKey.tab), '\t');
|
||||
expect(_bytes(LogicalKeyboardKey.enter), '\r');
|
||||
expect(_bytes(LogicalKeyboardKey.escape), '\x1b');
|
||||
expect(_bytes(LogicalKeyboardKey.backspace), '\x7f');
|
||||
}, variant: linux);
|
||||
|
||||
testWidgets('application cursor keys and keypad mode', (tester) async {
|
||||
final terminal = Terminal()..write('\x1b[?1h');
|
||||
String? bytes(LogicalKeyboardKey key, [String mods = '']) =>
|
||||
_bytes(key, mods: mods, terminal: terminal);
|
||||
expect(bytes(LogicalKeyboardKey.arrowUp), '\x1bOA');
|
||||
expect(bytes(LogicalKeyboardKey.arrowLeft), '\x1bOD');
|
||||
expect(bytes(LogicalKeyboardKey.home), '\x1bOH');
|
||||
expect(bytes(LogicalKeyboardKey.end), '\x1bOF');
|
||||
// Modified keys are the same in either mode.
|
||||
expect(bytes(LogicalKeyboardKey.arrowUp, 'C'), '\x1b[1;5A');
|
||||
// The keypad's operators and Enter follow DECKPAM; digits keep typing.
|
||||
expect(bytes(LogicalKeyboardKey.numpadAdd), isNull);
|
||||
expect(bytes(LogicalKeyboardKey.numpadEnter), '\r');
|
||||
terminal.write('\x1b=');
|
||||
expect(bytes(LogicalKeyboardKey.numpadAdd), '\x1bOk');
|
||||
expect(bytes(LogicalKeyboardKey.numpadEnter), '\x1bOM');
|
||||
expect(bytes(LogicalKeyboardKey.numpadDivide), '\x1bOo');
|
||||
expect(bytes(LogicalKeyboardKey.numpad1), isNull);
|
||||
terminal.write('\x1b>\x1b[?1l');
|
||||
expect(bytes(LogicalKeyboardKey.arrowUp), '\x1b[A');
|
||||
expect(bytes(LogicalKeyboardKey.numpadAdd), isNull);
|
||||
// Enter in line feed mode (LNM).
|
||||
terminal.write('\x1b[20h');
|
||||
expect(bytes(LogicalKeyboardKey.enter), '\r\n');
|
||||
}, variant: linux);
|
||||
|
||||
testWidgets('plain typing, Cmd chords and AltGr are left to the emulator', (
|
||||
tester,
|
||||
) async {
|
||||
expect(_bytes(LogicalKeyboardKey.keyA, character: 'a'), isNull);
|
||||
expect(_bytes(LogicalKeyboardKey.keyA, mods: 'S', character: 'A'), isNull);
|
||||
expect(_bytes(LogicalKeyboardKey.space, character: ' '), isNull);
|
||||
expect(_bytes(LogicalKeyboardKey.keyK, mods: 'M', character: 'k'), isNull);
|
||||
// German AltGr+Q types @.
|
||||
expect(
|
||||
_bytes(
|
||||
LogicalKeyboardKey.keyQ,
|
||||
mods: 'CA',
|
||||
character: '@',
|
||||
physical: PhysicalKeyboardKey.keyQ,
|
||||
),
|
||||
isNull,
|
||||
);
|
||||
}, variant: linux);
|
||||
|
||||
testWidgets('a Mac\'s Option is Meta while the setting is on', (
|
||||
tester,
|
||||
) async {
|
||||
// Option+B types ∫; its logical key is B (natively) or ∫ (browsers).
|
||||
expect(_bytes(LogicalKeyboardKey.keyB, mods: 'A', character: '∫'), '\x1bb');
|
||||
expect(
|
||||
_bytes(
|
||||
_l(0x222b),
|
||||
mods: 'A',
|
||||
character: '∫',
|
||||
physical: PhysicalKeyboardKey.keyB,
|
||||
),
|
||||
'\x1bb',
|
||||
);
|
||||
expect(
|
||||
_bytes(
|
||||
_l(0x0131),
|
||||
mods: 'AS',
|
||||
character: 'ı',
|
||||
physical: PhysicalKeyboardKey.keyB,
|
||||
),
|
||||
'\x1bB',
|
||||
);
|
||||
expect(
|
||||
_bytes(
|
||||
_l(0x2265),
|
||||
mods: 'A',
|
||||
character: '≥',
|
||||
physical: PhysicalKeyboardKey.period,
|
||||
),
|
||||
'\x1b.',
|
||||
);
|
||||
expect(_bytes(LogicalKeyboardKey.backspace, mods: 'A'), '\x1b\x7f');
|
||||
expect(_bytes(LogicalKeyboardKey.slash, mods: 'C', character: '/'), '\x1f');
|
||||
// Off, Option types its symbol; special keys keep the Alt parameter.
|
||||
expect(
|
||||
_bytes(
|
||||
LogicalKeyboardKey.keyB,
|
||||
mods: 'A',
|
||||
character: '∫',
|
||||
optionAsMeta: false,
|
||||
),
|
||||
isNull,
|
||||
);
|
||||
expect(
|
||||
_bytes(LogicalKeyboardKey.backspace, mods: 'A', optionAsMeta: false),
|
||||
'\x7f',
|
||||
);
|
||||
expect(
|
||||
_bytes(LogicalKeyboardKey.arrowLeft, mods: 'A', optionAsMeta: false),
|
||||
'\x1b[1;3D',
|
||||
);
|
||||
expect(
|
||||
_bytes(LogicalKeyboardKey.arrowLeft, mods: 'A', optionAsMeta: true),
|
||||
'\x1b[1;3D',
|
||||
);
|
||||
}, variant: mac);
|
||||
|
||||
ChatShellTerminalSession session(List<String> sent, bool Function() meta) =>
|
||||
ChatShellTerminalSession(
|
||||
ChatShellRun.fromJson({
|
||||
'id': 'run_1',
|
||||
'command': 'sh',
|
||||
'directory': '/w',
|
||||
'status': 'running',
|
||||
'started_at': 1,
|
||||
'output': '',
|
||||
'output_bytes': 0,
|
||||
'terminal': true,
|
||||
'cols': 40,
|
||||
'rows': 10,
|
||||
})!,
|
||||
onInput: sent.add,
|
||||
onResize: (_, _) {},
|
||||
optionAsMeta: meta,
|
||||
);
|
||||
|
||||
testWidgets('the toolbar and soft keyboard keys go through the same '
|
||||
'encoding', (tester) async {
|
||||
final sent = <String>[];
|
||||
final terminal = session(sent, () => true).terminal;
|
||||
terminal.keyInput(TerminalKey.arrowUp);
|
||||
terminal.write('\x1b[?1h');
|
||||
terminal.keyInput(TerminalKey.arrowUp);
|
||||
terminal.keyInput(TerminalKey.keyB, alt: true);
|
||||
terminal.keyInput(TerminalKey.keyB, alt: true, shift: true);
|
||||
terminal.keyInput(TerminalKey.slash, ctrl: true);
|
||||
terminal.keyInput(TerminalKey.arrowLeft, alt: true);
|
||||
// A plain letter is typed as its text instead.
|
||||
expect(terminal.keyInput(TerminalKey.keyB), isFalse);
|
||||
expect(sent, ['\x1b[A', '\x1bOA', '\x1bb', '\x1bB', '\x1f', '\x1b[1;3D']);
|
||||
}, variant: linux);
|
||||
|
||||
testWidgets('on a Mac with Option as Meta off, the package does not '
|
||||
'send its own Alt sequence', (tester) async {
|
||||
final sent = <String>[];
|
||||
var meta = false;
|
||||
final terminal = session(sent, () => meta).terminal;
|
||||
expect(terminal.keyInput(TerminalKey.keyB, alt: true), isFalse);
|
||||
meta = true;
|
||||
expect(terminal.keyInput(TerminalKey.keyB, alt: true), isTrue);
|
||||
expect(sent, ['\x1bb']);
|
||||
}, variant: mac);
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/shell/chat_shell_run.dart';
|
||||
import 'package:pipelines_app/features/chat/shell/chat_shell_terminal_session.dart';
|
||||
import 'package:pipelines_app/features/chat/shell/chat_shell_terminal_view.dart';
|
||||
import 'package:xterm/core.dart';
|
||||
|
||||
ChatShellTerminalSession _session({int cols = 40, int rows = 10}) =>
|
||||
ChatShellTerminalSession(
|
||||
ChatShellRun.fromJson({
|
||||
'id': 'run_1',
|
||||
'command': 'sh',
|
||||
'directory': '/w',
|
||||
'status': 'running',
|
||||
'started_at': 1,
|
||||
'output': '',
|
||||
'output_bytes': 0,
|
||||
'terminal': true,
|
||||
'cols': cols,
|
||||
'rows': rows,
|
||||
})!,
|
||||
onInput: (_) {},
|
||||
onResize: (_, _) {},
|
||||
);
|
||||
|
||||
/// The rows on screen, trimmed.
|
||||
List<String> _screen(Terminal terminal) {
|
||||
final buffer = terminal.buffer;
|
||||
final top = buffer.height - terminal.viewHeight;
|
||||
return [
|
||||
for (var y = 0; y < terminal.viewHeight; y++)
|
||||
buffer.lines[top + y].getText().trimRight(),
|
||||
];
|
||||
}
|
||||
|
||||
String _cursorRow(Terminal terminal) => terminal
|
||||
.buffer
|
||||
.lines[terminal.buffer.absoluteCursorY]
|
||||
.getText()
|
||||
.trimRight();
|
||||
|
||||
/// Twelve output lines of 58 characters (two rows each at 40 columns), then
|
||||
/// a prompt.
|
||||
String _longLines() => [
|
||||
for (var i = 0; i < 12; i++)
|
||||
'line ${i.toString().padLeft(2, '0')} ${'x' * 50}',
|
||||
r'$ ',
|
||||
].join('\r\n');
|
||||
|
||||
void main() {
|
||||
test('shrinking keeps the prompt on the cursor row at the bottom, and '
|
||||
'growing brings the rows above back in order', () {
|
||||
final terminal = _session().terminal..write(_longLines());
|
||||
expect(terminal.buffer.cursorY, 9);
|
||||
expect(_cursorRow(terminal), r'$');
|
||||
|
||||
terminal.resize(20, 5);
|
||||
expect(terminal.buffer.cursorY, 4);
|
||||
expect(_cursorRow(terminal), r'$');
|
||||
// Line 11's second row (cut at 20 columns), then the prompt.
|
||||
expect(_screen(terminal), [
|
||||
'line 10 ${'x' * 12}',
|
||||
'x' * 18,
|
||||
'line 11 ${'x' * 12}',
|
||||
'x' * 18,
|
||||
r'$',
|
||||
]);
|
||||
|
||||
// The shell redraws its prompt and runs a command: nothing lands on
|
||||
// old rows and no rows merge.
|
||||
terminal.write('\r\x1b[K\$ ls\r\nout\r\n\$ ');
|
||||
expect(_screen(terminal).sublist(2), [r'$ ls', 'out', r'$']);
|
||||
|
||||
terminal.resize(40, 10);
|
||||
expect(terminal.buffer.cursorY, 9);
|
||||
expect(_cursorRow(terminal), r'$');
|
||||
final screen = _screen(terminal);
|
||||
expect(screen.sublist(7), [r'$ ls', 'out', r'$']);
|
||||
// Rows cut while narrow stay cut: no stale text past column 20.
|
||||
for (final row in screen) {
|
||||
expect(row.length, lessThanOrEqualTo(20), reason: row);
|
||||
}
|
||||
});
|
||||
|
||||
test('a prompt redrawn while narrow does not grow stale text when the '
|
||||
'terminal widens again', () {
|
||||
final terminal = _session().terminal..write('\$ ${'abcdefghij' * 3}');
|
||||
terminal.resize(10, 10);
|
||||
terminal.write('\r\x1b[K\$ ');
|
||||
terminal.resize(40, 10);
|
||||
expect(_cursorRow(terminal), r'$');
|
||||
expect(terminal.buffer.cursorX, 2);
|
||||
});
|
||||
|
||||
test('a cleared screen and scrollback stay cleared across resizes', () {
|
||||
final terminal = _session().terminal..write(_longLines());
|
||||
terminal.write('\x1b[H\x1b[2J\x1b[3J\$ ');
|
||||
terminal.resize(20, 5);
|
||||
terminal.resize(40, 12);
|
||||
expect(_screen(terminal), [r'$', for (var i = 0; i < 11; i++) '']);
|
||||
expect(terminal.buffer.height, 12);
|
||||
expect(terminal.buffer.absoluteCursorY, 0);
|
||||
});
|
||||
|
||||
test('fewer rows than the output drop blank rows below the cursor first', () {
|
||||
final terminal = _session().terminal..write('a\r\nb\r\n\$ ');
|
||||
terminal.resize(40, 4);
|
||||
expect(_screen(terminal), ['a', 'b', r'$', '']);
|
||||
expect(terminal.buffer.absoluteCursorY, 2);
|
||||
terminal.resize(40, 10);
|
||||
expect(_screen(terminal).take(3), ['a', 'b', r'$']);
|
||||
expect(terminal.buffer.absoluteCursorY, 2);
|
||||
});
|
||||
|
||||
testWidgets('the view resizes the live terminal as its box changes, '
|
||||
'keeping the prompt on the cursor row', (tester) async {
|
||||
final session = _session(cols: 80, rows: 24);
|
||||
final sizes = <(int, int)>[];
|
||||
session.terminal.onResize = (cols, rows, _, _) => sizes.add((cols, rows));
|
||||
session.terminal.write(_longLines());
|
||||
var size = const Size(600, 300);
|
||||
late StateSetter setSize;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
setSize = setState;
|
||||
return SizedBox.fromSize(
|
||||
size: size,
|
||||
child: ChatShellTerminalView(session: session, fill: true),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
final wide = session.terminal.viewWidth;
|
||||
// The prompt is the 13th line; the screen has room below it.
|
||||
final row = session.terminal.buffer.cursorY;
|
||||
expect(row, 12);
|
||||
expect(_cursorRow(session.terminal), r'$');
|
||||
|
||||
setSize(() => size = const Size(250, 120));
|
||||
await tester.pump();
|
||||
final terminal = session.terminal;
|
||||
expect(terminal.viewWidth, lessThan(wide));
|
||||
expect(terminal.buffer.cursorY, terminal.viewHeight - 1);
|
||||
expect(_cursorRow(terminal), r'$');
|
||||
|
||||
setSize(() => size = const Size(600, 300));
|
||||
await tester.pump();
|
||||
expect(terminal.viewWidth, wide);
|
||||
// The rows that scrolled off come back above the prompt.
|
||||
expect(terminal.buffer.cursorY, row);
|
||||
expect(_cursorRow(terminal), r'$');
|
||||
expect(_screen(terminal)[row - 1], startsWith('line 11'));
|
||||
expect(_screen(terminal)[0], startsWith('line 00'));
|
||||
expect(sizes.length, greaterThanOrEqualTo(3));
|
||||
});
|
||||
}
|
||||
@@ -67,6 +67,35 @@ void main() {
|
||||
expect(sent, hasLength(2));
|
||||
});
|
||||
|
||||
test('query answers go to onReply; focus reports the laid out size', () {
|
||||
final typed = <String>[];
|
||||
final replies = <String>[];
|
||||
final activations = <(int, int)>[];
|
||||
final session = ChatShellTerminalSession(
|
||||
_run('prompt'),
|
||||
onInput: typed.add,
|
||||
onReply: replies.add,
|
||||
onResize: (_, _) {},
|
||||
onActivate: (cols, rows) => activations.add((cols, rows)),
|
||||
);
|
||||
session.append(_run('prompt\x1b[6n'), '\x1b[6n', 6, 10);
|
||||
session.terminal.textInput('y');
|
||||
expect(replies, ['\x1b[1;7R']);
|
||||
expect(typed, ['y']);
|
||||
// Drawn at the run's own size until a view lays it out.
|
||||
expect(session.viewSize, isNull);
|
||||
session.activate();
|
||||
expect(activations, isEmpty);
|
||||
session.terminal.resize(90, 20);
|
||||
expect(session.viewSize, (90, 20));
|
||||
session.activate();
|
||||
expect(activations, [(90, 20)]);
|
||||
// A finished run claims nothing.
|
||||
session.finish(_run('prompt', status: 'exited'));
|
||||
session.activate();
|
||||
expect(activations, hasLength(1));
|
||||
});
|
||||
|
||||
test('a chunk after a hole redraws the held copy', () {
|
||||
final session = ChatShellTerminalSession(
|
||||
_run('a\r\n'),
|
||||
@@ -85,7 +114,8 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
test('narrowing rewraps without pushing the first line out of view', () {
|
||||
test('narrowing a live terminal cuts rows instead of rewrapping, keeping '
|
||||
'the first line and the cursor on its own', () {
|
||||
final session = ChatShellTerminalSession(
|
||||
_run('first\r\n${'u' * 30}\r\nprompt: '),
|
||||
onInput: (_) {},
|
||||
@@ -95,11 +125,26 @@ void main() {
|
||||
final buffer = session.terminal.buffer;
|
||||
expect(buffer.height, 6);
|
||||
expect(buffer.lines[0].getText().trim(), 'first');
|
||||
expect(buffer.lines[3].getText().trim(), 'prompt:');
|
||||
expect(buffer.absoluteCursorY, 3);
|
||||
expect(buffer.lines[1].getText().trim(), 'u' * 20);
|
||||
expect(buffer.lines[2].getText().trim(), 'prompt:');
|
||||
expect(buffer.absoluteCursorY, 2);
|
||||
expect(buffer.cursorX, 8);
|
||||
});
|
||||
|
||||
test('finished output still rewraps to the width it is shown at', () {
|
||||
final session = ChatShellTerminalSession(
|
||||
_run('first\r\n${'u' * 30}\r\nend', status: 'exited'),
|
||||
onInput: (_) {},
|
||||
onResize: (_, _) {},
|
||||
);
|
||||
session.terminal.resize(20, 6);
|
||||
final buffer = session.terminal.buffer;
|
||||
expect(buffer.lines[0].getText().trim(), 'first');
|
||||
expect(buffer.lines[1].getText().trim(), 'u' * 20);
|
||||
expect(buffer.lines[2].getText().trim(), 'u' * 10);
|
||||
expect(buffer.lines[3].getText().trim(), 'end');
|
||||
});
|
||||
|
||||
test('a finished run counts the rows its output takes at a width', () {
|
||||
final session = ChatShellTerminalSession(
|
||||
_run('a\r\n${'x' * 50}\r\nend\r\n', status: 'exited'),
|
||||
|
||||
@@ -110,6 +110,109 @@ void main() {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> press(
|
||||
WidgetTester tester,
|
||||
LogicalKeyboardKey key, {
|
||||
List<LogicalKeyboardKey> modifiers = const [],
|
||||
String? character,
|
||||
PhysicalKeyboardKey? physical,
|
||||
}) async {
|
||||
for (final modifier in modifiers) {
|
||||
await tester.sendKeyDownEvent(modifier);
|
||||
}
|
||||
await tester.sendKeyDownEvent(
|
||||
key,
|
||||
character: character,
|
||||
physicalKey: physical,
|
||||
);
|
||||
await tester.sendKeyUpEvent(key, physicalKey: physical);
|
||||
for (final modifier in modifiers.reversed) {
|
||||
await tester.sendKeyUpEvent(modifier);
|
||||
}
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
testWidgets('the focused terminal sends xterm bytes for Alt, Ctrl and '
|
||||
'modified keys, and the copy and paste keys still work', (tester) async {
|
||||
await openRunning(tester, output: r'$ ');
|
||||
await tester.tap(find.byType(TerminalView));
|
||||
await tester.pump();
|
||||
const alt = [LogicalKeyboardKey.altLeft];
|
||||
const ctrl = [LogicalKeyboardKey.controlLeft];
|
||||
const shift = [LogicalKeyboardKey.shiftLeft];
|
||||
await press(tester, LogicalKeyboardKey.keyB, modifiers: alt);
|
||||
await press(tester, LogicalKeyboardKey.keyF, modifiers: alt);
|
||||
await press(tester, LogicalKeyboardKey.period, modifiers: alt);
|
||||
await press(
|
||||
tester,
|
||||
LogicalKeyboardKey.keyB,
|
||||
modifiers: [...alt, ...shift],
|
||||
character: 'B',
|
||||
);
|
||||
await press(tester, LogicalKeyboardKey.backspace, modifiers: alt);
|
||||
await press(tester, LogicalKeyboardKey.slash, modifiers: ctrl);
|
||||
await press(tester, LogicalKeyboardKey.bracketRight, modifiers: ctrl);
|
||||
await press(tester, LogicalKeyboardKey.arrowUp, modifiers: shift);
|
||||
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);
|
||||
expect(
|
||||
typed(),
|
||||
'\x1bb\x1bf\x1b.\x1bB\x1b\x7f\x1f\x1d'
|
||||
'\x1b[1;2A\x1b[1;3D\x1b[1;5C\x14x',
|
||||
);
|
||||
// Application cursor keys from the process's own mode switch.
|
||||
gateway.emitOutput('run_t', '\x1b[?1h', 2);
|
||||
await tester.pump();
|
||||
gateway.calls.clear();
|
||||
await press(tester, LogicalKeyboardKey.arrowUp);
|
||||
expect(typed(), '\x1bOA');
|
||||
// Ctrl-V is still paste, not ^V.
|
||||
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
SystemChannels.platform,
|
||||
(call) async =>
|
||||
call.method == 'Clipboard.getData' ? {'text': 'tok'} : null,
|
||||
);
|
||||
addTearDown(
|
||||
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
SystemChannels.platform,
|
||||
null,
|
||||
),
|
||||
);
|
||||
await press(tester, LogicalKeyboardKey.keyV, modifiers: ctrl);
|
||||
for (var i = 0; i < 5; i++) {
|
||||
await tester.pump(const Duration(milliseconds: 20));
|
||||
}
|
||||
expect(typed(), '\x1bOAtok');
|
||||
await tester.pump(const Duration(milliseconds: 400));
|
||||
}, variant: TargetPlatformVariant.only(TargetPlatform.linux));
|
||||
|
||||
testWidgets(
|
||||
'on a Mac, Option is Meta in the terminal',
|
||||
(tester) async {
|
||||
await openRunning(tester, output: r'$ ');
|
||||
await tester.tap(find.byType(TerminalView));
|
||||
await tester.pump();
|
||||
await press(
|
||||
tester,
|
||||
LogicalKeyboardKey.keyB,
|
||||
modifiers: [LogicalKeyboardKey.altLeft],
|
||||
character: '∫',
|
||||
);
|
||||
await press(
|
||||
tester,
|
||||
const LogicalKeyboardKey(0x2202),
|
||||
modifiers: [LogicalKeyboardKey.altLeft],
|
||||
character: '∂',
|
||||
physical: PhysicalKeyboardKey.keyD,
|
||||
);
|
||||
expect(typed(), '\x1bb\x1bd');
|
||||
await tester.pump(const Duration(milliseconds: 400));
|
||||
},
|
||||
variant: TargetPlatformVariant.only(TargetPlatform.macOS),
|
||||
);
|
||||
|
||||
testWidgets('on Linux, Ctrl-C copies a selection and interrupts without one; '
|
||||
'Ctrl-Insert copies too', (tester) async {
|
||||
await openRunning(tester, output: 'Paste your token: ');
|
||||
@@ -274,6 +377,47 @@ void main() {
|
||||
expect(gateway.bodies('chat_shell_input'), isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('focusing the terminal claims it at its size; typing carries '
|
||||
'the size and query answers are marked', (tester) async {
|
||||
await openRunning(tester, output: 'size? \x1b[6n');
|
||||
await tester.pump(const Duration(milliseconds: 200));
|
||||
final laidOut = gateway.bodies('chat_shell_resize').single;
|
||||
// The replayed query is not answered; nothing was claimed yet.
|
||||
expect(gateway.bodies('chat_shell_input'), isEmpty);
|
||||
await tester.tap(find.byType(TerminalView));
|
||||
await tester.pump();
|
||||
final claim = gateway.bodies('chat_shell_resize').last;
|
||||
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 tester.pump();
|
||||
var inputs = gateway.bodies('chat_shell_input');
|
||||
expect(inputs.single['data'], 'g');
|
||||
expect(inputs.single['reply'], isNull);
|
||||
expect(
|
||||
(inputs.single['cols'], inputs.single['rows']),
|
||||
(laidOut['cols'], laidOut['rows']),
|
||||
);
|
||||
// A live query is answered with the answer marked, without a size.
|
||||
gateway.emitOutput('run_t', '\x1b[6n', 'size? \x1b[6n'.length);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
inputs = gateway.bodies('chat_shell_input');
|
||||
expect(inputs.last['data'], '\x1b[1;7R');
|
||||
expect(inputs.last['reply'], isTrue);
|
||||
expect(inputs.last['cols'], isNull);
|
||||
// Focusing again after the focus left claims again.
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
await tester.pump();
|
||||
await tester.tap(find.byType(TerminalView));
|
||||
await tester.pump();
|
||||
expect(
|
||||
gateway.bodies('chat_shell_resize').where((b) => b['activate'] == true),
|
||||
hasLength(2),
|
||||
);
|
||||
}, variant: TargetPlatformVariant.only(TargetPlatform.linux));
|
||||
|
||||
testWidgets('coloured output is drawn without its escape codes', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/shell/chat_shell_terminals.dart';
|
||||
import 'package:pipelines_app/features/terminal/terminal_info.dart';
|
||||
import 'package:pipelines_app/features/terminal/terminal_tab.dart';
|
||||
|
||||
import 'terminal_fixtures.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('answers are marked, typing carries the size, focus activates', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = TerminalGateway();
|
||||
final tab = TerminalTab(
|
||||
machineId: 'm',
|
||||
machineName: 'm',
|
||||
gateway: gateway,
|
||||
info: TerminalInfo.fromJson(gateway.add('t1')),
|
||||
);
|
||||
// Before a view lays it out, focus has no size to claim.
|
||||
tab.session.activate();
|
||||
await tester.pump();
|
||||
expect(gateway.bodies('terminal_resize'), isEmpty);
|
||||
|
||||
tab.session.terminal.resize(100, 30);
|
||||
await tester.pump(chatShellResizeDelay);
|
||||
expect(gateway.bodies('terminal_resize'), [
|
||||
{'terminal_id': 't1', 'cols': 100, 'rows': 30},
|
||||
]);
|
||||
|
||||
// A cursor position query in the output: the answer is marked.
|
||||
tab.frame({'output': '\x1b[6n', 'offset': 0, 'end': 4});
|
||||
await tester.pump();
|
||||
// Typing carries the size this client draws at.
|
||||
tab.session.terminal.textInput('ls');
|
||||
await tester.pump();
|
||||
expect(gateway.bodies('terminal_input'), [
|
||||
{'terminal_id': 't1', 'data': '\x1b[1;1R', 'reply': true},
|
||||
{'terminal_id': 't1', 'data': 'ls', 'cols': 100, 'rows': 30},
|
||||
]);
|
||||
|
||||
// A view gaining focus claims the terminal at once, at its size.
|
||||
tab.session.activate();
|
||||
await tester.pump();
|
||||
expect(gateway.bodies('terminal_resize').last, {
|
||||
'terminal_id': 't1',
|
||||
'cols': 100,
|
||||
'rows': 30,
|
||||
'activate': true,
|
||||
});
|
||||
|
||||
// A new connection reports its size again.
|
||||
tab.attach(gateway, TerminalInfo.fromJson(gateway.terminals['t1']!));
|
||||
await tester.pump(chatShellResizeDelay);
|
||||
expect(gateway.bodies('terminal_resize'), hasLength(3));
|
||||
expect(gateway.bodies('terminal_resize').last, {
|
||||
'terminal_id': 't1',
|
||||
'cols': 100,
|
||||
'rows': 30,
|
||||
});
|
||||
tab.dispose();
|
||||
});
|
||||
|
||||
test('the input pipe keeps answers and typing apart, in order', () async {
|
||||
final sent = <(String, bool)>[];
|
||||
final pipe = ChatShellInputPipe((data, reply) async {
|
||||
sent.add((data, reply));
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
}, (_) {});
|
||||
pipe.add('a');
|
||||
// While the first is in flight, typing, an answer and typing wait.
|
||||
pipe.add('b');
|
||||
pipe.add('c');
|
||||
pipe.add('\x1b[1;1R', reply: true);
|
||||
pipe.add('d');
|
||||
pipe.add('${'x' * chatShellInputChunk}y');
|
||||
await pumpEventQueue();
|
||||
expect(sent, [
|
||||
('a', false),
|
||||
('bc', false),
|
||||
('\x1b[1;1R', true),
|
||||
('d${'x' * (chatShellInputChunk - 1)}', false),
|
||||
('xy', false),
|
||||
]);
|
||||
});
|
||||
|
||||
test('a refusal drops what was waiting and reports once', () async {
|
||||
final failures = <Object>[];
|
||||
final sent = <String>[];
|
||||
final pipe = ChatShellInputPipe((data, reply) async {
|
||||
sent.add(data);
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
throw StateError('not running');
|
||||
}, failures.add);
|
||||
pipe.add('a');
|
||||
pipe.add('b');
|
||||
pipe.add('?', reply: true);
|
||||
await pumpEventQueue();
|
||||
expect(sent, ['a']);
|
||||
expect(failures, hasLength(1));
|
||||
});
|
||||
}
|
||||
@@ -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