Implement a plan for how to show the current cursor position as a beam |
Plan implementation for showing cursor beam
Thorsten
Ball • @mrnugget
1y agoSorry, *come up* with that plan: analyze the code, think hard, come up with a plan
Based on the analysis, here's the plan for implementing a cursor beam:
Cursor Beam Implementation Plan
1. Data Model Changes
- Add
Cursorstruct with position, color, style (beam width), and visibility flag - Add
CursorStyle::Beam { width_px }enum for future extensibility - Extend
Sceneto includecursor: Option<Cursor>
2. Shader Pipeline
- Add new
solid_fragmentshader that renders solid color without texture sampling - Reuse existing
text_vertexshader andTextVertexInstructure - Create separate
solid_pipeline_statein Renderer
3. Rendering Logic
- Use
GridConfig::grid_to_ndc()to calculate cursor position in NDC - Generate 4-vertex triangle strip for thin vertical beam at cursor column
- Beam dimensions: 2-3px width × full cell height
- Render cursor after text so it appears on top
4. Blinking Mechanism
- Add
Instant-based timer fields to Renderer:cursor_blink_interval,cursor_blink_last_toggle,cursor_blink_on - Toggle visibility every ~500ms
- Reset blink to "on" state on keyboard input
5. Integration
- Pull cursor position from
Terminal::cursor_position()when building Scene - Re-enable
Terminal::update_max_cols()to sync withGridConfig.colson resize - Pass cursor data through Scene → Renderer → draw call
6. Implementation Order
- Add shader function (solid_fragment)
- Update Scene structs (Cursor, CursorStyle)
- Add Renderer blink timer fields & pipeline setup
- Implement cursor quad generation in draw()
- Wire Terminal cursor to Scene in app/window code
- Test & tune beam width and blink timing
This approach keeps text rendering untouched while adding minimal, clean cursor rendering with ~100 lines of new code.
great!