Add visible cursor block and enhanced keyboard navigation#12
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
screen.cursorfor accurate positioning2. 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
encodeKeyWithMod()to handle GUI and Alt modifiersSDL_KMOD_ALTbinding toc.zigTesting
Original Request