Skip to content

In-place line redraw — carriage return + erase controls #22

Description

@bedro96

What to build

The terminal buffer is append-only, so interactive CLIs (e.g. GitHub Copilot CLI) that redraw a line in place appear to "stack" a new line on every refresh instead of overwriting. Introduce a minimal cursor/line model so in-place redraws work end-to-end (parser → buffer → on-screen render):

  • Interpret carriage return \r as "move cursor to column 0 of the current line" (subsequent characters overwrite existing content on that line).
  • Interpret erase-in-line ESC [ K (and ESC [ 0/1/2 K) to clear from the cursor to end of line / start of line / whole line.
  • Interpret erase-in-display ESC [ 2 J and cursor-home ESC [ H to clear/reset the screen.
  • Interpret basic cursor-column positioning (ESC [ <n> G) and cursor left/right (ESC [ <n> C/D) enough to keep redraws aligned.

This introduces the cursor-position state that issue for the blinking cursor depends on. Keep the existing backspace/DEL and SGR behavior intact.

Acceptance criteria

  • abc\rX renders as Xbc (CR overwrites from column 0), not abc on one line and X on the next
  • foobar\rfoo ESC[K erases the tail, leaving foo
  • A repeated single-line redraw (CR + text + ESC[K) updates in place and does not add new lines
  • ESC[2J / ESC[H clear/reset the visible buffer
  • Existing backspace/DEL, UTF-8, and SGR color tests still pass
  • New unit tests cover CR overwrite, ESC[K variants, and in-place redraw
  • ./run-tests.sh passes

Blocked by

None - can start immediately

Metadata

Metadata

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions