Skip to content

Add visible cursor block and enhanced keyboard navigation#12

Merged
forketyfork merged 1 commit into
mainfrom
cursor-enhancements
Dec 31, 2025
Merged

Add visible cursor block and enhanced keyboard navigation#12
forketyfork merged 1 commit into
mainfrom
cursor-enhancements

Conversation

@forketyfork
Copy link
Copy Markdown
Owner

Summary

This PR adds a visible cursor block to terminals and implements comprehensive keyboard shortcuts for efficient text editing, matching standard macOS/readline behavior.

Changes

1. Visible Cursor Block

  • Renders a light gray block cursor at the current cursor position
  • Only displayed when terminal is focused and viewing live content (not scrolled)
  • Properly scaled for both grid view (1/3 scale) and full-screen view
  • Uses ghostty-vt's screen.cursor for accurate positioning

2. Enhanced Keyboard Navigation

Implemented the following shortcuts using standard readline control sequences:

Cursor Movement:

  • Alt+Left / Alt+Right: Move word-by-word (ESC+b/f)
  • Cmd+Left / Cmd+Right: Jump to beginning/end of line (Ctrl+A/E)

Deletion:

  • Alt+Backspace: Delete previous word (Ctrl+W)
  • Cmd+Backspace: Delete from cursor to line start (Ctrl+U)

3. Technical Implementation

  • Modified encodeKeyWithMod() to handle GUI and Alt modifiers
  • Added SDL_KMOD_ALT binding to c.zig
  • All shortcuts work with bash, zsh, and other readline-compatible shells
  • Comprehensive test coverage for all new keyboard shortcuts

Testing

  • ✅ All existing tests pass
  • ✅ New tests added for all keyboard shortcuts
  • ✅ Build successful with no warnings
  • ✅ Cursor renders correctly in both grid and full-screen modes

Original Request

I can't see the cursor block in the terminal. Please add it. Then add the ability to move cursor word-by-word with Alt+Left/Right and to the beginning/end of the line with Cmd+Left/Right. Finally, add Cmd+Backspace to delete the line and Alt+Backspace to delete the word.

Prompt: I can't see the cursor block in the terminal. Please add it.
Then add the ability to move cursor word-by-word with Alt+Left/Right
and to the beginning/end of the line with Cmd+Left/Right. Finally,
add Cmd+Backspace to delete the line and Alt+Backspace to delete the
word.

Solution: Implemented comprehensive cursor enhancements:

1. Visible cursor block (src/main.zig:858-880):
   - Renders a light gray filled rectangle at cursor position
   - Only visible when terminal is focused and viewing live content
   - Uses ghostty-vt's screen.cursor.x/y for positioning
   - Properly scaled and bounds-checked for grid and full-screen views

2. Enhanced keyboard navigation (src/main.zig:1108-1183):
   - Alt+Left/Right: Word-by-word movement using ESC+b/f sequences
   - Cmd+Left/Right: Line navigation using Ctrl+A/E (beginning/end)
   - Cmd+Backspace: Delete line using Ctrl+U
   - Alt+Backspace: Delete word using Ctrl+W
   - All shortcuts use standard readline control sequences

3. SDL3 bindings update (src/c.zig:69):
   - Added SDL_KMOD_ALT export for Alt key detection

4. Comprehensive test coverage (src/main.zig:1328-1376):
   - Tests for all cursor movement shortcuts
   - Tests for deletion shortcuts
   - Verifies correct control sequence generation

All shortcuts work seamlessly with bash, zsh, and other readline-
compatible shells.
@forketyfork forketyfork merged commit 1758c00 into main Dec 31, 2025
4 checks passed
@forketyfork forketyfork deleted the cursor-enhancements branch December 31, 2025 15:32
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