Skip to content

fix(review): show diff colors on non-truecolor terminals, fix tab indentation, add commit picker - #29

Merged
reckerp merged 1 commit into
mainfrom
feat-review-diff-rework
Jul 3, 2026
Merged

fix(review): show diff colors on non-truecolor terminals, fix tab indentation, add commit picker#29
reckerp merged 1 commit into
mainfrom
feat-review-diff-rework

Conversation

@reckerp

@reckerp reckerp commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Why

gx review had two rendering bugs that made the diff hard to read, and the scope switcher was incomplete:

  1. No syntax highlighting on many terminals. The widget emitted 24-bit truecolor (38;2;R;G;B) for every syntax color and every add/remove background. Terminals that drop truecolor escapes — tmux and macOS Terminal.app unless specially configured for RGB/Tc — silently ignored them, so the diff rendered as plain, uncolored text. (Highlighting was working; the terminal just never saw the colors.)
  2. Broken indentation. Tabs were passed through as a single cell, so any tab-indented file lost its indentation.
  3. Missing scope options. There was an s switcher (branch / +worktree / uncommitted) but no way to pick a specific commit or range, and it was under-discovered.

What changed

  • Color-depth adaptation (new src/ui/review/color.rs): detect whether the terminal reliably supports truecolor, and downsample every RGB color (syntax foregrounds + diff palette) to the nearest xterm-256 index otherwise. Conservative auto-detection treats tmux/screen as 256-color unless truecolor = "always".
  • Tab expansion: tabs render as tab_width-aligned spaces in the diff (byte offsets stay aligned so word-level emphasis is unaffected).
  • Scope switcher rework: clearer s menu (uncommitted · all branch changes · branch + working tree) plus a commit picker reviews one commit, space marks a range endpoint to review older^..newer. Each scope keeps its own comments. Discoverable via the empty-state hint, help bar, and help overlay.
  • Config: new [review] truecolor (auto / always / never) and tab_width (default 4). Documented in docs/review.md.

Testing

  • cargo test --bin gx — 266 pass (incl. new color-downsampling and tab-expansion tests); cargo clippy clean.
  • Captured the real binary's TTY output under tmux before/after: before emitted 38;2;… truecolor (dropped by tmux); after emits 38;5;N/48;5;N 256-color that tmux renders. Verified tab-indented lines now align with space-indented ones via a rendered-buffer dump. Smoke-tested the commit picker end-to-end (no panic).

…indentation

The diff view emitted 24-bit truecolor for every syntax color and diff
background. Terminals that drop truecolor escapes — tmux and macOS
Terminal.app unless specially configured — rendered the diff as plain,
uncolored text, which reads as "missing syntax highlighting". Detect the
terminal color depth and downsample RGB to the 256-color palette when
truecolor isn't reliably supported (new src/ui/review/color.rs).

Tabs collapsed to a single cell, breaking indentation. Expand them to
tab-stop-aligned spaces in the diff view.

Rework the in-TUI scope switcher into a clearer menu (uncommitted /
branch / branch+worktree) and add a commit picker: review a single
commit, or mark two commits to review the range between them.

New [review] config: truecolor ("auto" | "always" | "never") and
tab_width. Docs updated in docs/review.md.
@reckerp
reckerp merged commit 68b67a3 into main Jul 3, 2026
6 checks passed
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