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>
111 lines
2.6 KiB
Dart
111 lines
2.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:xterm/core.dart';
|
|
|
|
import 'chat_shell_terminal_key_button.dart';
|
|
import 'chat_shell_terminal_key_row.dart';
|
|
import 'chat_shell_terminal_session.dart';
|
|
|
|
/// One key of the desktop terminal toolbar: its label, icon and what it
|
|
/// sends.
|
|
typedef _Key = ({
|
|
String id,
|
|
String label,
|
|
IconData? material,
|
|
void Function(Terminal terminal) send,
|
|
});
|
|
|
|
final List<_Key> _keys = [
|
|
(
|
|
id: 'enter',
|
|
label: 'Enter',
|
|
material: Icons.keyboard_return,
|
|
send: (t) => t.keyInput(TerminalKey.enter),
|
|
),
|
|
(
|
|
id: 'ctrl-c',
|
|
label: 'Ctrl-C',
|
|
material: null,
|
|
send: (t) => t.textInput('\x03'),
|
|
),
|
|
(
|
|
id: 'tab',
|
|
label: 'Tab',
|
|
material: Icons.keyboard_tab,
|
|
send: (t) => t.keyInput(TerminalKey.tab),
|
|
),
|
|
(
|
|
id: 'esc',
|
|
label: 'Esc',
|
|
material: null,
|
|
send: (t) => t.keyInput(TerminalKey.escape),
|
|
),
|
|
(
|
|
id: 'left',
|
|
label: 'Left',
|
|
material: Icons.keyboard_arrow_left,
|
|
send: (t) => t.keyInput(TerminalKey.arrowLeft),
|
|
),
|
|
(
|
|
id: 'up',
|
|
label: 'Up',
|
|
material: Icons.keyboard_arrow_up,
|
|
send: (t) => t.keyInput(TerminalKey.arrowUp),
|
|
),
|
|
(
|
|
id: 'down',
|
|
label: 'Down',
|
|
material: Icons.keyboard_arrow_down,
|
|
send: (t) => t.keyInput(TerminalKey.arrowDown),
|
|
),
|
|
(
|
|
id: 'right',
|
|
label: 'Right',
|
|
material: Icons.keyboard_arrow_right,
|
|
send: (t) => t.keyInput(TerminalKey.arrowRight),
|
|
),
|
|
];
|
|
|
|
/// The keys a running terminal's toolbar offers. With [touch] it is the
|
|
/// touch key row ([ChatShellTerminalKeyRow]: sticky Ctrl and Alt and the
|
|
/// keys a phone keyboard lacks); otherwise Paste and a few keys for a mouse.
|
|
class ChatShellTerminalKeys extends StatelessWidget {
|
|
const ChatShellTerminalKeys({
|
|
super.key,
|
|
required this.session,
|
|
required this.touch,
|
|
});
|
|
|
|
final ChatShellTerminalSession session;
|
|
final bool touch;
|
|
|
|
Terminal get _terminal => session.terminal;
|
|
|
|
Future<void> _paste() async {
|
|
final data = await Clipboard.getData(Clipboard.kTextPlain);
|
|
final text = data?.text;
|
|
if (text != null && text.isNotEmpty && session.live) {
|
|
_terminal.paste(text);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (touch) return ChatShellTerminalKeyRow(session: session);
|
|
return Wrap(
|
|
spacing: 4,
|
|
runSpacing: 4,
|
|
children: [
|
|
chatShellKeyButton('paste', 'Paste', Icons.content_paste, _paste),
|
|
for (final key in _keys)
|
|
chatShellKeyButton(
|
|
key.id,
|
|
key.label,
|
|
key.material,
|
|
() => key.send(_terminal),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|