Fit chat terminals to their output, keep pastes and keys in the terminal

Finished terminals are sized synchronously from their rows at the view's
width (the post-frame fit made the transcript re-anchor forever); blank rows
xterm.dart keeps when rewrapping are dropped; desktop typing uses key events;
the composer leaves Cmd/Ctrl-V to a focused terminal; Ctrl-A reaches the
process. The probe fixture gains coloured terminal runs and an interactive
login. Notes record behaviour, protocol, security and verification.
This commit is contained in:
2026-11-09 20:51:59 +00:00
parent 89882d90f3
commit 2332143e5b
10 changed files with 429 additions and 52 deletions
@@ -84,4 +84,31 @@ void main() {
contains('earlier output was dropped'),
);
});
test('narrowing rewraps without pushing the first line out of view', () {
final session = ChatShellTerminalSession(
_run('first\r\n${'u' * 30}\r\nprompt: '),
onInput: (_) {},
onResize: (_, _) {},
);
session.terminal.resize(20, 6);
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.cursorX, 8);
});
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'),
onInput: (_) {},
onResize: (_, _) {},
);
// The 50-character line wraps at the terminal's 40 columns.
expect(session.rowsAt(40), 4);
expect(session.rowsAt(20), 5);
expect(session.rowsAt(100), 3);
});
}
@@ -39,12 +39,36 @@ 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 tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.keyC);
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
await tester.pump();
expect(typed(), '\x1b[A\x03');
expect(typed(), 'g7\x1b[A\x03');
// Cmd-V pastes the clipboard into the process.
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
SystemChannels.platform,
(call) async =>
call.method == 'Clipboard.getData' ? {'text': 'tok'} : null,
);
addTearDown(
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
SystemChannels.platform,
null,
),
);
await tester.sendKeyDownEvent(LogicalKeyboardKey.metaLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.keyV);
await tester.sendKeyUpEvent(LogicalKeyboardKey.metaLeft);
for (var i = 0; i < 5; i++) {
await tester.pump(const Duration(milliseconds: 20));
}
expect(typed(), 'g7\x1b[A\x03tok');
// The chat composer leaves a paste into the terminal alone.
expect(find.text('tok'), findsNothing);
expect(find.byType(EditableText), findsWidgets);
await tester.pump(const Duration(milliseconds: 400));
expect(gateway.bodies('chat_shell_input').first['run_id'], 'run_t');
},