Skip to content

feat: host file marks in the Files sidebar - #12

Merged
backnotprop merged 1 commit into
mainfrom
feat/file-badges
Nov 20, 2026
Merged

backnotprop merged 1 commit into
mainfrom
feat/file-badges

Conversation

@backnotprop

Copy link
Copy Markdown
Contributor

Adds a small host API so an embedding app can mark files in the Files sidebar. plannotator-tui needs it to show its "viewed" marks in the file list. Today that list is drawn by diffs-rs and a host cannot decorate a row.

API

pub struct FileMark<'a> {
    pub path: &'a str,             // FileMetadata::path: new path, or old path of a deleted file
    pub badge: Option<Badge<'a>>,
    pub dimmed: bool,              // name, status and counts drawn muted
}
pub struct Badge<'a> { pub text: &'a str, pub color: BadgeColor } // 1 or 2 cells
pub enum BadgeColor { Text, Muted, Accent, Added, Deleted, Modified, Renamed }

impl Engine {
    pub fn set_file_marks(&mut self, marks: &[FileMark<'_>]) -> Result<()>;
}
  • Each call replaces the whole set, like set_markers. The engine stores the paths in a hash map, keeps one copy of each distinct badge, and recomputes the folder results in one pass over the tree. Only the sidebar is redrawn and the diff does not reflow, so it is cheap to call on every toggle.
  • Badges have a fixed column: after the first call, every row has 3 cells (a gap and two badge cells) between the counts and the divider. Rows with and without a badge stay aligned. Long names are shortened; the badge is never cut. The column stays until replace() or close(), even for an empty set, so a host can call set_file_marks(&[]) at open and the first badge does not shift the rows.
  • Folders: a folder row shows a badge when every file under it has the same badge (same text and color), and is dimmed when every file under it is dimmed. Collapsed folders are included. The library computes this because only it knows the tree's folders, path splitting and escaping, and duplicate paths. The host would otherwise need folder paths in the API. The result is kept on the tree nodes. It is recomputed when a new set arrives and updated for each ancestor as files arrive, so a loading patch costs O(depth) per file.
  • Paths: a mark names a file by path, not by index, so marks can be set before files arrive and apply to every occurrence of a path (git log -p). Marks for paths that are not in the review draw nothing.
  • Validation: a badge that is empty, wider than two cells or contains control characters rejects the whole set, and the previous set stays. The call fails after close().
  • Hosts that never call it, and the diffs viewer, render exactly as before. The existing sidebar layout tests are unchanged.

BadgeColor names theme colors rather than taking a Style, so badges follow the dark/light theme.

Example host

embedded_viewer gets a v key: it marks the cursor's file viewed (a green ✓ and a dimmed row), or unmarks it. A new opt-in check, embedded_host_marks_viewed_files_in_the_sidebar, runs it in a PTY. It checks the ticks, the folder aggregate, the dimmed color, unmarking, and that reopening drops the column.

  ▾ docs/            1 +2 −1 ✓  │
    readme.md        M +2 −1 ✓  │
  ▾ src/             3 +6 −3 ✓  │
    ▾ lib/           2 +4 −2 ✓  │
      b.rs           M +2 −1 ✓  │
 *    c.rs           M +2 −1 ✓  │
    a.rs             M +2 −1 ✓  │
  top.txt            M +2 −1    │

Version

This change only adds API. It adds no field to an existing public struct and no variant to an existing enum. Under the crate's pre-1.0 rule (breaking changes take a minor bump, as in 0.2.0), the next release can be 0.2.1. The CHANGELOG entry is under "0.2.1 - Unreleased". Cargo.toml is not bumped; that happens in the release steps.

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 with NATIVE_DIFF_HOST_BINARY (7 passed)
  • cargo +1.88.0 check --locked --all-targets
  • RUSTDOCFLAGS="-D warnings" cargo doc --no-deps

I also wired the API into a local plannotator-tui branch and ran the real binary to confirm the API fits that host. That branch is not pushed; it will wait for a release.

@backnotprop
backnotprop merged commit f6ddecc into main Nov 20, 2026
3 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