Skip to content

New rendering engine - #76

Merged
Araxeus merged 6 commits into
masterfrom
flicker/a-crossterm-differ
Oct 31, 2026
Merged

Araxeus merged 6 commits into
masterfrom
flicker/a-crossterm-differ

Conversation

@Araxeus

@Araxeus Araxeus commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

Summary

Replaces the prompt renderer with a small retained-frame renderer that only redraws rows that changed. This removes the flicker on every keypress and folder change, and fixes the slow, line-by-line ("typewriter") drawing over SSH.

Also adds mouse support: click to select, double click to open.

Why

The old renderer erased the whole prompt and drew it again on every keypress, and left a blank frame between folders. Each erase, move and line went out as a separate write, so over SSH a frame arrived in many small packets.

What changed

Rendering (screen.rs)

  • Diffs each frame against what is on screen and rewrites only the rows that changed
  • Overwrites a row in place, then erases the rest of it, so a row is never blank on screen
  • Sends each frame as one write wrapped in a synchronized update (DEC 2026)
    • Supporting terminals paint the frame in one go
    • Over SSH the frame travels as one packet
  • Moves the cursor only relative to the prompt, so it never asks the terminal where the cursor is
  • Cuts lines to the terminal width, so nothing wraps
  • Repaints in place on resize and never clears the scrollback

Prompt (prompt/mod.rs,prompt/selector.rs)

  • One Ui lives for the whole session, so each new folder is drawn over the previous one
  • Raw mode stays on for the whole session instead of toggling every frame
  • Keys that arrive together are handled before the next draw, so a burst of keys costs one frame
  • Key handling moved into Selector, which has no drawing code and is unit tested
  • Fuzzy matches are recomputed only when the search term changes

Mouse

  • Click selects a row
  • Double click acts like Enter: opens the folder, opens the file, or prints its path with -x
  • Mouse wheel moves the selection
  • Only button presses and releases are reported (modes 1000 and 1006), so movinr SSH

Fixes

  • resolve_lnk no longer drops the panic hook after reading a shortcut
  • A panic restores the terminal: raw mode off, cursor shown, mouse reporting off

Numbers

Measured in a 100x30 pty with 60 files, counting writes to stderr:

master this PR
Bytes per arrow key ~2200 ~175
10x Down, total bytes 24193 4039
Writes per frame several 1
Time to first frame ~15 ms ~11 ms

Dependencies

  • unicode-width (was already in the tree through other crates)
  • libc on Unix only (was already in the tree), for the cursor position query
  • vt100 as a dev dependency: a terminal emulator the tests draw into

Testing

  • 127 unit tests
    • Random frame sequences drawn into a terminal emulator must match a clean redraw
    • Key handling, mouse clicks and double clicks
    • Cleanup on quit, on errors and when the Ui is dropped
  • cargo fmt --check and clippy with the CI lint set, on Windows and Linux
  • Manually: Windows Terminal, SSH to a slow VM, tmux, and a terminal without synchronized update support

resolve_lnk silenced panics with an empty hook and then reset it to the
default, which dropped the human-panic hook for the rest of the session.
It now saves the previous hook and puts it back.
Every keypress and every folder change used to erase the whole prompt and
draw it again, and switching folders left a blank frame in between. Over
SSH that showed up as flicker and as frames that arrived line by line.

The prompt now keeps a retained frame (Screen) and diffs each new frame
against it:
- only changed rows are rewritten, each overwritten in place before the
  rest of the row is erased, so no row is ever blank on screen
- each frame is one write wrapped in a synchronized update (DEC 2026), so
  supporting terminals paint it atomically and SSH sends one packet
- cursor movement is relative, so there is no cursor position round trip
- lines are cut to the terminal width, so nothing wraps
- one Ui lives for the whole session, so a new folder is drawn over the
  old one, and raw mode stays on instead of toggling every frame
- a resize repaints the region in place and never clears the scrollback

Key handling moved into a Selector with no drawing code. It caches the
fuzzy matches and recomputes them only when the search term changes.

At 30 rows an arrow key now writes about 175 bytes instead of 2.2 KB.
The prompt now turns on mouse reporting while it is open. A click
selects the row under the pointer, a second click on the same row within
half a second chooses it like Enter: a folder opens, a file runs, or its
path is printed with -x. The wheel moves the selection like the arrows.

This also fixes clicks that jumped to the drive view. Without mouse
reporting some terminals (VS Code, Windows Terminal) turn a click on the
main screen into arrow keys that move the shell's cursor there, and each
Left went up one folder.

Only presses and releases are reported (modes 1000 and 1006), so moving
the mouse sends nothing over SSH.

The inline region only knows where it is relative to the cursor, so the
first click asks the terminal for the cursor position (one round trip
over SSH) and the screen tracks its rows from there. Starting the prompt
still waits for nothing.
Most of the code lived in src/structs, whatever its job, plus a catch-all
utils.rs. The modules now follow what the code does:
- entry: the listed files and folders, their types and icons, and .lnk
  shortcut resolution
- prompt: the interactive chooser (Ui, Selector, Theme) and the terminal
  it talks to, now in its own terminal.rs
- render: escape sequence handling and the screen differ
- system: OS helpers (pretty paths, computer name, Windows drives)

Errors are printed by main only: resolving a shortcut returns None when
it cannot be read, and the prompt's choose is called from main. No
behaviour changes.
@Araxeus
Araxeus merged commit 7ec62b7 into master Oct 31, 2026
2 checks passed
@Araxeus
Araxeus deleted the flicker/a-crossterm-differ branch October 31, 2026 03:33
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