Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix(picker): keep text after an ANSI reset dark on the selected picker row (#4408)
Worktrunk Bot7bde63a01fe1
diff --git a/src/commands/picker/items.rs b/src/commands/picker/items.rsindex e5c0a9de9..d6bcf86b9 100644--- a/src/commands/picker/items.rs+++ b/src/commands/picker/items.rs@@ -37,11 +37,16 @@ use super::preview_orchestrator::{PreviewDemand, SpawnGeneration};/// codes — converts them itself. Rows are single lines; spans from any parsed/// lines are flattened into one. A parse failure falls back to the raw text.///-/// Each span's background is cleared to `None`. The rows are foreground-only,-/// but an `\x1b[0m` reset in the source ANSI parses to an explicit-/// `bg = Reset`, which would override skim's `highlight_line` fill and leave the-/// selected row's gray highlight (`current_bg`) full of holes. Leaving `bg`-/// unset lets the line-level current-row background show through uniformly.+/// An `\x1b[0m` reset in the source ANSI parses to explicit `Reset` colors,+/// which would override skim's line-level row style, so both are cleared to+/// `None`:+///+/// - `bg`: the rows are foreground-only, and an explicit `Reset` would leave+/// the selected row's gray highlight (`current_bg`) full of holes.+/// - `fg`: an explicit `Reset` draws the terminal's default foreground instead+/// of the selected row's `current:237`. A branch-only row's dim `/ ` gutter+/// ends in `\x1b[0m`, so its branch name rendered light-on-light under the+/// selection on dark themes. Off-cursor, `None` and `Reset` look the same.pub(super) fn ansi_to_line(s: &str) -> Line<'static> {match s.into_text() {Ok(text) => Line::from(@@ -50,6 +55,9 @@ pub(super) fn ansi_to_line(s: &str) -> Line<'static> {.flat_map(|line| line.spans).map(|mut span| {span.style.bg = None;+ if span.style.fg == Some(Color::Reset) {+ span.style.fg = None;+ }span}).collect::<Vec<Span<'static>>>(),@@ -1923,6 +1931,26 @@ mod tests {ListItem::new_worktree(subject, data)}+ /// Text after an `\x1b[0m` reset inherits the row's line-level foreground.+ /// A branch-only row opens with a dim `/ ` gutter closed by `\x1b[0m`, so+ /// its (non-removable) branch name used to parse to an explicit+ /// `fg = Reset` — the terminal's default foreground, which overrides skim's+ /// selected-row `current:237` and is light-on-light on a dark theme.+ #[test]+ fn ansi_to_line_leaves_reset_foreground_to_the_row_style() {+ let line = ansi_to_line("\x1b[2m/ \x1b[0mfeature \x1b[33m✗\x1b[39m");+ let fgs: Vec<_> = line+ .spans+ .iter()+ .map(|span| (span.content.as_ref(), span.style.fg))+ .collect();+ assert_eq!(+ fgs,+ vec![("/ ", None), ("feature ", None), ("✗", Some(Color::Yellow))]+ );+ assert!(line.spans.iter().all(|span| span.style.bg.is_none()));+ }+/// `anchor_faint_under_selection` recolors faint text to an explicit gray/// only on the selected row (and only foreground-less faint spans), so the/// "safe to delete" gray survives skim's selection highlight while