Skip to content

feat: draw on the terminal's own background - #13

Merged
backnotprop merged 1 commit into
mainfrom
feat/terminal-background
Nov 20, 2026
Merged

backnotprop merged 1 commit into
mainfrom
feat/terminal-background

Conversation

@backnotprop

Copy link
Copy Markdown
Contributor

This adds a host option to draw the diff on the terminal's own background and text color, so plannotator-tui's code review matches its Markdown screen. Today diffs-rs paints its whole rectangle with the theme's #0a0a0a (or #ffffff in the light theme).

API

impl Engine {
    pub fn set_terminal_background(&mut self, on: bool) -> Result<()>;
}

It is off by default, so hosts that do not call it and the diffs viewer do not change. It can be set before files arrive, stays set across replace(), and follows the t theme toggle. I made it a method rather than an Options field: a new field breaks hosts that build Options without ..Options::default(), as the 0.2.0 changelog notes. As a method it is additive and fits 0.2.1. The CHANGELOG entry is under "0.2.1 - Unreleased", and docs/embedding.md has a new "Terminal background" section.

What changes when it is on

  • These draw with Color::Reset as background: empty rows, plain context lines, gaps, metadata and "no newline" rows, file headers, the Files sidebar, and with chrome the label row, footer and help.
  • Plain text uses the terminal's default foreground. This includes syntax tokens that carry the theme's text color (#fafafa dark, #0a0a0a light). Other syntax colors stay.
  • These keep explicit colors from the palette of Options::appearance: added and deleted lines, changed words, hunk headers, the empty half of a split row, and the Files keyboard cursor row. The host picks the appearance that matches its terminal.
  • Gutter markers, the cursor and selection indicators, and search underlines are unchanged.

The terminal's real background is unknown, so the explicit colors are derived differently in this mode:

theme background (unchanged) terminal background
dark hunk header #2a2a2a #363636
dark added / deleted line #182d22 / #381917 #22392d / #472420
dark changed word #154b35 / #601d1f #1d553e / #6c2626
dark empty half #303030 #2e2e2e
light hunk header #f4f4f4 #e6e6e6
light tints, empty half unchanged unchanged

On a dark terminal the tints now start from a slightly lighter base (#0a0a0a mixed 6% toward the text color). They read on black, #1e1e1e and a blue-grey #1e2230 alike, instead of looking like dark holes on lighter backgrounds. The light hunk header was almost invisible on an off-white terminal, so it is mixed more strongly.

The Files cursor row normally uses the context color. In this mode that color is the terminal's own background, so the cursor row uses the hunk header color instead. theme::Colors gains no field.

Tests

  • Frame tests, dark and light, split and unified: with the option on, no cell in a plain context row, an empty row, the sidebar, the file headers, the label row or the footer has an explicit background. Plain text has no explicit foreground. Added, deleted, hunk and empty-half tints are still present, and turning the option off restores the exact theme frame.
  • A Files cursor test checks the cursor row keeps a visible highlight and that the option survives a theme toggle.
  • An engine test with real syntax colors checks that the theme's text color is gone from a context row, that other syntax colors stay, and that the option survives replace().

Checks run locally

  • cargo fmt --check
  • cargo clippy --locked --all-targets -- -D warnings, and the same with --all-features
  • cargo test --release --locked --no-fail-fast -- --test-threads=1
  • the embedded host checks (7 passed)
  • cargo +1.88.0 check --locked --all-targets
  • RUSTDOCFLAGS="-D warnings" cargo doc --no-deps

I also ran plannotator-tui with the option on, on a dark (#1e2230) and a light (#fafafa) page, and compared it with the screen before the change. That host branch is local only.

@backnotprop
backnotprop merged commit 00b2095 into main Nov 20, 2026
3 checks passed
github-merge-queue Bot pushed a commit to plannotator/plannotator-tui that referenced this pull request Nov 23, 2026
…the terminal background (#186)

* feat(review): tick viewed files in the file list

The diff viewer's file list now shows a tick after a viewed file's counts and dims its
row; a folder gets the tick once every file in it is viewed, also when collapsed. It uses
diffs-rs `Engine::set_file_marks`, synced on open, on every toggle, when files arrive and
on reload.

Not mergeable yet: `set_file_marks` is not in a diffs-rs release. The root Cargo.toml
patches diffs-rs to a commit of plannotator/diffs-rs feat/file-badges. Once diffs-rs
0.2.1 is published: delete the [patch.crates-io] section, require
diffs-rs = "0.2.1" in crates/plannotator-tui/Cargo.toml, and run
`cargo update -p diffs-rs`.

* feat(review): draw the code review on the terminal's own background

The diff viewer now leaves empty rows, plain context lines and its file list to the
terminal's background and plain text to its foreground, as the document screen does.
Changed lines and hunk headings keep tints from the light or dark palette that the theme
setting picks. Uses diffs-rs `Engine::set_terminal_background`.

Not mergeable yet: needs plannotator/diffs-rs#13 and a diffs-rs release. The root
Cargo.toml patches diffs-rs to that PR's commit; once 0.2.1 is published, delete the
[patch.crates-io] section, require diffs-rs = "0.2.1", and run `cargo update -p diffs-rs`.
If the whole-file view (#172) lands first, its second engine needs the same call.

* build: diffs-rs 0.2.1 from crates.io; the whole-file view on the terminal background too

The [patch.crates-io] pointer to a diffs-rs commit is gone: 0.2.1 has
Engine::set_file_marks and Engine::set_terminal_background.

The whole-file view (o, O) opens a second engine; it now draws on the
terminal's background as the diff does. Tests cover that, the light
palette, and the file list's ticks through x in the whole-file view,
ctrl+n, the rail hidden and shown, a change on disk, a reload that
drops a changed file's mark, and a PR review's own marks.
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