c5af000453
- Desktop and web terminals use the text-input path too, so IMEs, dead keys, the emoji picker and dictation work; the key handler still encodes special keys and chords first (handled keys are never typed again), composing text is drawn at the cursor and sent on commit, the platform editable sits at the cursor, and a closed input reopens on the next key. The editable terminal is a semantics text field so web typing also works with semantics on. - Web: "Capture browser keys" (terminal menu and right-click menu) goes full screen and calls navigator.keyboard.lock(); hold Esc to leave. No-op where unsupported; cheatsheet and menu note give alternatives. - Touch: scrollable key row with sticky Ctrl/Alt (tap once, double-tap lock), Esc, Tab, arrows, Home/End, PgUp/PgDn and symbols through the hardware encoder; soft keyboard types per key (delete detection, Return as Enter); the line field moves behind the row's Line button. - Capture kit: compose=, --semantics false, --user-agent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
118 lines
3.5 KiB
Dart
118 lines
3.5 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../chat/shell/chat_shell_terminal_keys.dart';
|
|
import '../chat/shell/chat_shell_terminal_view.dart';
|
|
import 'terminal_hub.dart';
|
|
import 'terminal_tab.dart';
|
|
|
|
/// The selected terminal: its emulator (focused when shown), what the
|
|
/// operator should know about it (ended, machine offline, ends with the
|
|
/// server) and, with [keys], the touch key toolbar. With [focus] it is that
|
|
/// focus scope, which the surface focuses whenever the terminal shows.
|
|
class TerminalBody extends StatelessWidget {
|
|
const TerminalBody({
|
|
super.key,
|
|
required this.hub,
|
|
this.keys = false,
|
|
this.focus,
|
|
});
|
|
|
|
final TerminalHub hub;
|
|
final bool keys;
|
|
final FocusScopeNode? focus;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final focus = this.focus;
|
|
final body = _body(context);
|
|
return focus == null ? body : FocusScope(node: focus, child: body);
|
|
}
|
|
|
|
Widget _body(BuildContext context) {
|
|
final tab = hub.selected;
|
|
if (tab == null) return _empty(context);
|
|
final notes = <String>[
|
|
if (!tab.connected)
|
|
'${tab.machineName} is not connected; the terminal resumes when it is.'
|
|
else if (!tab.info.running)
|
|
tab.info.endedText,
|
|
?tab.error,
|
|
?hub.error,
|
|
];
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.fromLTRB(8, 0, 8, 8),
|
|
child: ChatShellTerminalView(
|
|
key: ValueKey('terminal-view-${tab.key}'),
|
|
session: tab.session,
|
|
fill: true,
|
|
autofocus: true,
|
|
),
|
|
),
|
|
),
|
|
for (final note in notes)
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(12, 0, 12, 8),
|
|
child: Text(note, style: _noteStyle(context)),
|
|
),
|
|
if (keys && tab.session.live && tab.connected)
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(8, 0, 8, 8),
|
|
child: ChatShellTerminalKeys(
|
|
session: tab.session,
|
|
touch: chatShellTouchFirst(),
|
|
),
|
|
),
|
|
if (!tab.info.running && tab.connected) _closeEnded(tab),
|
|
],
|
|
);
|
|
}
|
|
|
|
TextStyle? _noteStyle(BuildContext context) => Theme.of(context)
|
|
.textTheme
|
|
.bodySmall
|
|
?.copyWith(color: Theme.of(context).colorScheme.onSurfaceVariant);
|
|
|
|
Widget _closeEnded(TerminalTab tab) {
|
|
void close() => unawaited(hub.close(tab));
|
|
return Padding(
|
|
padding: const EdgeInsets.fromLTRB(8, 0, 8, 8),
|
|
child: Align(
|
|
alignment: AlignmentDirectional.centerStart,
|
|
child: TextButton(onPressed: close, child: const Text('Close tab')),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _empty(BuildContext context) {
|
|
final machines = hub.connected;
|
|
final text = machines.isEmpty
|
|
? 'No machine is connected.'
|
|
: 'No terminals are open.';
|
|
void open() => unawaited(hub.open());
|
|
return Center(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Text(text, style: _noteStyle(context)),
|
|
if (hub.error case final error?)
|
|
Padding(
|
|
padding: const EdgeInsets.all(8),
|
|
child: Text(error, style: _noteStyle(context)),
|
|
),
|
|
if (machines.isNotEmpty)
|
|
FilledButton.tonal(
|
|
onPressed: open,
|
|
child: const Text('New terminal'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|