Skip to content

claw: shell readline — history, cursor editing, Ctrl-C#103

Merged
zevorn merged 2 commits intomainfrom
claw/shell-readline
Mar 20, 2026
Merged

claw: shell readline — history, cursor editing, Ctrl-C#103
zevorn merged 2 commits intomainfrom
claw/shell-readline

Conversation

@zevorn
Copy link
Copy Markdown
Owner

@zevorn zevorn commented Mar 20, 2026

Summary

Add interactive shell improvements across all three platforms (ESP, Zynq, Linux).

Command history (Up/Down arrows)

  • Shared ring buffer (shell_history.c) stores up to 16 recent inputs
  • Duplicate suppression (consecutive identical inputs not repeated)
  • Current unsaved input preserved as scratch when navigating, restored on down-past-newest
  • Covers both AI messages and /commands

Cursor editing (Linux — new; ESP/Zynq — already had)

  • Left/Right arrow keys for cursor movement with insert mode
  • Home/End keys to jump to line start/end
  • Delete key to remove character at cursor
  • Proper redraw on mid-line insert and backspace

Ctrl-C support (all platforms)

  • Line editing: ^C discards current input and returns to fresh prompt
  • AI chat: animation thread polls console for Ctrl-C during thinking, sets cancel flag, discards AI response
  • Linux: double Ctrl-C within 1 second exits program; Ctrl-D still exits immediately

Changes (2 commits)

Commit Description
claw: add shell history and cursor editing across all platforms History ring buffer, Up/Down in ESP/Zynq/Linux, cursor editing in Linux
claw: add Ctrl-C to cancel input and interrupt AI chat Ctrl-C line cancel + AI interrupt + Linux double-press exit

New files

  • include/claw/shell/shell_history.h — history API
  • claw/shell/shell_history.c — ring buffer implementation

Test plan

  • make build-linux — zero warnings
  • make build-zynq-a9-qemu — zero warnings
  • make test-unit-zynq — all suites pass
  • Linux functional boot tests — pass
  • make build-esp32c3-qemu + smoke tests (CI)
  • Manual: verify Up/Down history recall on serial console
  • Manual: verify Ctrl-C cancels AI thinking animation

zevorn added 2 commits March 20, 2026 21:18
Add a shared ring-buffer history module (shell_history.c) that
stores up to 16 recent inputs with duplicate suppression.

All three shell implementations now support:
  - Up/Down arrows to cycle through command history
  - History covers both AI messages and /commands
  - Current unsaved input is preserved as scratch when
    navigating, restored on down-past-newest

Linux shell additionally gains:
  - Left/Right arrow cursor movement with insert mode
  - Home/End keys
  - Delete key
  - Proper redraw on mid-line insert and backspace

(ESP and Zynq shells already had cursor editing; this commit
adds only history navigation to them.)

Signed-off-by: Chao Liu <chao.liu.zevorn@gmail.com>
Line editing (all platforms):
  - Ctrl-C prints ^C and discards current input, returns to
    a fresh prompt without exiting.

AI chat interruption (all platforms):
  - Animation thread polls console for Ctrl-C during thinking.
  - On detection, sets cancel flag, stops animation, and
    discards the AI response when ai_chat() completes.

Linux-specific:
  - Double Ctrl-C within 1 second exits the program (replaces
    the old single Ctrl-C exit behavior).
  - Ctrl-D still exits immediately.
  - Keep raw mode during AI chat so animation thread can poll
    stdin for Ctrl-C.

Signed-off-by: Chao Liu <chao.liu.zevorn@gmail.com>
@zevorn zevorn merged commit 9d31538 into main Mar 20, 2026
11 checks passed
@zevorn zevorn deleted the claw/shell-readline branch March 23, 2026 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant