Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

feat(mobile): tab, clear and / on the terminal's key bar

bubu-dudu5603259378d7
diff --git a/mobile/lib/phone/terminal_input_dock.dart b/mobile/lib/phone/terminal_input_dock.dart
index 16a9526cd..9cf3b4d89 100644
--- a/mobile/lib/phone/terminal_input_dock.dart
+++ b/mobile/lib/phone/terminal_input_dock.dart
@@ -109,6 +109,8 @@ class _TerminalInputDockState extends State<TerminalInputDock>
builder: (context, _) => TerminalKeyBar(
terminal: widget.session.terminal,
enabled: widget.session.acceptsInput,
+ onClearPrompt: widget.session.clearPrompt,
+ onPromptEdited: widget.session.resetInputBuffer,
onDismissKeyboard: widget.onDismiss,
onPickImage: widget.onPickImage,
onTakePhoto: widget.onTakePhoto,
diff --git a/mobile/lib/phone/terminal_key_bar.dart b/mobile/lib/phone/terminal_key_bar.dart
index fc4cc7fcc..245ebc69b 100644
--- a/mobile/lib/phone/terminal_key_bar.dart
+++ b/mobile/lib/phone/terminal_key_bar.dart
@@ -18,25 +18,41 @@ import 'phone_sheet.dart';
/// enough on a phone that chrome is worth its height only while someone is
/// actually typing.
///
-/// ⚠️ **ONE row, fixed, and nothing scrolls.** It used to be two — `tab`, `↵`,
-/// `⇧tab`, `ctrl` and a row of digits beside what is here now — and the second
-/// row cost the terminal a line of output for keys the system keyboard below
-/// already types (the digits) or that were rarely reached for. What is left is
-/// what a phone keyboard genuinely cannot produce and a pane is driven by: `esc`
-/// and the arrows. Every key stays in the same place every time; this strip is
-/// used while looking at the TERMINAL, not at the strip.
+/// ⚠️ **ONE row, fixed, and nothing scrolls.** It used to be two — `↵`, `⇧tab`,
+/// `ctrl` and a row of digits beside what is here now — and the second row cost
+/// the terminal a line of output for keys the system keyboard below already
+/// types (the digits) or that were rarely reached for. What is left is what a
+/// phone keyboard cannot produce, or buries, and a pane is driven by:
+///
+/// ```
+/// esc tab clear ← ↑ ↓ → / │ 🖼 ⌄
+/// ```
+///
+/// Every key stays in the same place every time; this strip is used while
+/// looking at the TERMINAL, not at the strip.
class TerminalKeyBar extends StatelessWidget {
const TerminalKeyBar({
super.key,
required this.terminal,
required this.enabled,
required this.onDismissKeyboard,
+ this.onClearPrompt,
+ this.onPromptEdited,
this.onPickImage,
this.onTakePhoto,
});
final Terminal terminal;
+ /// The `clear` key: empties the prompt being typed into. Null leaves the key
+ /// out.
+ final VoidCallback? onClearPrompt;
+
+ /// Called after `tab` or `/` changed the prompt without the software
+ /// keyboard knowing — so its buffer can be emptied before it edits words the
+ /// prompt no longer holds.
+ final VoidCallback? onPromptEdited;
+
/// False while the stream is not accepting input — the strip stays visible
/// (it moves with the keyboard, and a row that vanished would take the
/// keyboard's place with it) but dims and stops answering.
@@ -98,8 +114,18 @@ class TerminalKeyBar extends StatelessWidget {
AppTheme.watch(context);
// What drives an engine and a phone keyboard lacks: leave a mode, walk
// history, move through a menu.
+ final onClearPrompt = this.onClearPrompt;
final keys = <Widget>[
_key(label: 'esc', onTap: () => terminal.keyInput(TerminalKey.escape)),
+ // Completes a path or a command, and moves through Claude Code's menus.
+ _key(
+ label: 'tab',
+ onTap: () {
+ terminal.keyInput(TerminalKey.tab);
+ onPromptEdited?.call();
+ },
+ ),
+ if (onClearPrompt != null) _key(label: 'clear', onTap: onClearPrompt),
_key(
icon: LucideIcons.arrowLeft300,
semanticLabel: 'Left',
@@ -120,6 +146,15 @@ class TerminalKeyBar extends StatelessWidget {
semanticLabel: 'Right',
onTap: () => terminal.keyInput(TerminalKey.arrowRight),
),
+ // Last before the rule, beside the image key: how a slash command
+ // starts, and a phone keyboard buries `/` a layer down.
+ _key(
+ label: '/',
+ onTap: () {
+ terminal.textInput('/');
+ onPromptEdited?.call();
+ },
+ ),
];
// ⚠️ **Neither of these sends a byte anywhere**, and that is why they sit
// apart from the grid rather than in it. Every key to the left of the rule
@@ -223,14 +258,22 @@ class TerminalKeyBar extends StatelessWidget {
),
child: icon != null
? Icon(icon, size: 16, color: foreground)
- : Text(
- label!,
- maxLines: 1,
- style: TextStyle(
- fontSize: 13,
- height: 1,
- color: foreground,
- fontWeight: FontWeight.w500,
+ // Shrinks rather than clips: ten keys share a phone's width, and
+ // `clear` is the widest word among them.
+ : Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 3),
+ child: FittedBox(
+ fit: BoxFit.scaleDown,
+ child: Text(
+ label!,
+ maxLines: 1,
+ style: TextStyle(
+ fontSize: 13,
+ height: 1,
+ color: foreground,
+ fontWeight: FontWeight.w500,
+ ),
+ ),
),
),
),
diff --git a/mobile/lib/terminal/terminal_session.dart b/mobile/lib/terminal/terminal_session.dart
index a4174863a..20fa65fb5 100644
--- a/mobile/lib/terminal/terminal_session.dart
+++ b/mobile/lib/terminal/terminal_session.dart
@@ -717,6 +717,25 @@ class TerminalSession extends ChangeNotifier {
if (identical(_viewport, viewport)) _viewport = null;
}
+ /// Empties the prompt being typed into: Ctrl+E to its end, then Ctrl+U to
+ /// delete back to its start — what a shell and Claude Code's prompt both
+ /// read as "clear the line" — and the keyboard's own buffer with it (see
+ /// [TerminalViewport.clearInputBuffer]).
+ ///
+ /// ⚠️ Not Ctrl+C: to Claude Code an empty prompt's Ctrl+C is the first half
+ /// of quitting.
+ void clearPrompt() {
+ if (!acceptsInput) return;
+ terminal.keyInput(TerminalKey.keyE, ctrl: true);
+ terminal.keyInput(TerminalKey.keyU, ctrl: true);
+ resetInputBuffer();
+ }
+
+ /// Empties the keyboard's own buffer after a key sent from outside it — Tab
+ /// completing a word, a `/` typed from the key strip — changed the prompt
+ /// behind its back. See [TerminalViewport.clearInputBuffer].
+ void resetInputBuffer() => _viewport?.clearInputBuffer();
+
/// Changes only the local paint phase of the cursor. Incoming terminal data
/// is always parsed against [_remoteCursorVisible], so blinking cannot turn
/// a remote DECTCEM hide/show command into terminal input or corrupt its
diff --git a/mobile/lib/terminal/terminal_viewport.dart b/mobile/lib/terminal/terminal_viewport.dart
index 639a7f912..7b7b83c5c 100644
--- a/mobile/lib/terminal/terminal_viewport.dart
+++ b/mobile/lib/terminal/terminal_viewport.dart
@@ -15,4 +15,10 @@ abstract interface class TerminalViewport {
/// Claims an already mounted editor before navigation's next rendered frame.
/// False means the destination has no ready input view yet.
bool focusInput();
+
+ /// Empties the software keyboard's own copy of what was typed, after the
+ /// prompt has been cleared on the far side. Left holding the old words, the
+ /// keyboard would edit them again — Vietnamese Telex re-marks the word it
+ /// thinks is being typed, and would rub out characters already gone.
+ void clearInputBuffer();
}
diff --git a/mobile/lib/widgets/terminal_panel.dart b/mobile/lib/widgets/terminal_panel.dart
index 2673eda11..c799a7fc1 100644
--- a/mobile/lib/widgets/terminal_panel.dart
+++ b/mobile/lib/widgets/terminal_panel.dart
@@ -638,6 +638,9 @@ class _TerminalPanelState extends State<TerminalPanel>
return _claimFocus(view, navigating: true);
}
+ @override
+ void clearInputBuffer() => _terminalViewKey.currentState?.clearInputBuffer();
+
void _claimFocusAfterFrame() {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) return;
diff --git a/mobile/test/terminal_key_bar_test.dart b/mobile/test/terminal_key_bar_test.dart
index 1bc181f07..c133d009c 100644
--- a/mobile/test/terminal_key_bar_test.dart
+++ b/mobile/test/terminal_key_bar_test.dart
@@ -7,11 +7,15 @@ void main() {
late Terminal terminal;
late List<String> outbound;
late int dismissals;
+ late int clears;
+ late int edits;
setUp(() {
terminal = Terminal(maxLines: 200, reflowEnabled: false)..resize(80, 12);
outbound = [];
dismissals = 0;
+ clears = 0;
+ edits = 0;
terminal.onOutput = outbound.add;
});
@@ -25,6 +29,8 @@ void main() {
terminal: terminal,
enabled: enabled,
onDismissKeyboard: () => dismissals++,
+ onClearPrompt: () => clears++,
+ onPromptEdited: () => edits++,
),
),
),
@@ -51,12 +57,30 @@ void main() {
expect(outbound, ['\x1b', '\x1b[D', '\x1b[A', '\x1b[B', '\x1b[C']);
});
- testWidgets('the row holds esc, the arrows and hide — nothing else', (
+ testWidgets('tab and / reach the pty and empty the keyboard buffer', (
tester,
) async {
await pumpBar(tester);
- for (final gone in ['tab', 'Enter', 'ctrl', '1', '0']) {
+ await tapKey(tester, 'tab');
+ await tapKey(tester, '/');
+
+ expect(outbound, ['\t', '/']);
+ expect(edits, 2);
+ });
+
+ testWidgets('clear hands the prompt to its owner to empty', (tester) async {
+ await pumpBar(tester);
+
+ await tapKey(tester, 'clear');
+
+ expect(clears, 1);
+ });
+
+ testWidgets('the row holds no Enter, ctrl or digits', (tester) async {
+ await pumpBar(tester);
+
+ for (final gone in ['Enter', 'ctrl', '1', '0']) {
expect(
find.byKey(ValueKey('terminal-key-$gone')),
findsNothing,
diff --git a/mobile/third_party/xterm/README.autonomous.md b/mobile/third_party/xterm/README.autonomous.md
index 05f6d8281..0c3ed58b7 100644
--- a/mobile/third_party/xterm/README.autonomous.md
+++ b/mobile/third_party/xterm/README.autonomous.md
@@ -221,3 +221,11 @@ it if one is dropped.
full-screen program as wheel events or arrow keys, until the view was
rebuilt. The setter now moves `_onScroll` with it. Regression:
`mobile/test/terminal_alt_scroll_test.dart`.
+
+16. **An embedder can empty the keyboard's buffer**
+ (`lib/src/terminal_view.dart`). `TerminalViewState.clearInputBuffer()`
+ resets the native editing state the way a submitted line does. The phone's
+ key strip clears the prompt with Ctrl+E Ctrl+U and types `/` and Tab
+ without the keyboard seeing them; left holding the old words, the keyboard
+ would edit them again — Telex re-marks the word it believes is being typed
+ and would rub out characters the prompt no longer holds.
diff --git a/mobile/third_party/xterm/lib/src/terminal_view.dart b/mobile/third_party/xterm/lib/src/terminal_view.dart
index 3f1a3709f..20b7125c0 100644
--- a/mobile/third_party/xterm/lib/src/terminal_view.dart
+++ b/mobile/third_party/xterm/lib/src/terminal_view.dart
@@ -396,6 +396,13 @@ class TerminalViewState extends State<TerminalView> {
_customTextEditKey.currentState?.closeKeyboard();
}
+ /// AUTONOMOUS PATCH: empties the native input buffer, the way a submitted
+ /// line does, for an embedder that has cleared the prompt by other means
+ /// (a Ctrl+U sent from its own key strip).
+ void clearInputBuffer() {
+ _customTextEditKey.currentState?.resetEditingState();
+ }
+
Rect get cursorRect {
return renderTerminal.cursorOffset & renderTerminal.cellSize;
}