Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

feat(switch): restyle the pr preview pane — flush description, cyan field labels (#3195)

Maximilian Roosd81ed36bc15c
diff --git a/src/commands/picker/items.rs b/src/commands/picker/items.rs
index 13d395258..727a1dbfe 100644
--- a/src/commands/picker/items.rs
+++ b/src/commands/picker/items.rs
@@ -1366,13 +1366,14 @@ mod tests {
pane.contains("https://github.com/o/r/pull/42"),
"url: {pane:?}"
);
+ // No body → no description block (it prefixes a blank line + reset).
assert!(
- !pane.contains("\x1b[107m"),
- "no description gutter without a body: {pane:?}"
+ !pane.contains("\n\n\x1b[0m"),
+ "no description block without a body: {pane:?}"
);
// A PR carrying title + body → the title rides the header and the body
- // renders as markdown in the house gutter, matching the `--prs` pane.
+ // renders flush as markdown, matching the `--prs` pane.
let full = row(Some(Some(status(
Some(PrRef::pr(7)),
Some("https://github.com/o/r/pull/7"),
@@ -1382,7 +1383,19 @@ mod tests {
let pane = full.render_pr_pane(full.pr_preview(), 80);
assert!(pane.contains("#7"), "reference: {pane:?}");
assert!(pane.contains("Fix the flaky retry"), "title: {pane:?}");
- assert!(pane.contains("\x1b[107m"), "description gutter: {pane:?}");
+ assert!(pane.contains("\n\n\x1b[0m"), "description block: {pane:?}");
+ assert!(
+ pane.contains("DESCRIPTION"),
+ "cyan `DESCRIPTION` label heads the block: {pane:?}"
+ );
+ assert!(
+ !pane.contains("\x1b[107m"),
+ "renders flush, no gutter: {pane:?}"
+ );
+ assert!(
+ pane.contains("bounded"),
+ "description body rendered: {pane:?}"
+ );
assert!(pane.contains("\x1b[1m"), "markdown bold rendered: {pane:?}");
assert!(!pane.contains("**"), "markdown markers consumed: {pane:?}");
@@ -1408,13 +1421,14 @@ mod tests {
comment_count,
};
- // A PR with comments adds a `comments` metadata line carrying the count.
+ // A PR with comments adds a cyan all-caps `COMMENTS` metadata line
+ // carrying the count (same `field_label` styling as BRANCH/URL).
let with = render_worktree_pr("feature", PrRef::pr(7), &status(Some(3)), 80)
.ansi_strip()
.to_string();
assert!(
with.lines()
- .any(|l| l.contains("comments") && l.contains('3')),
+ .any(|l| l.contains("COMMENTS") && l.contains('3')),
"comments line with count: {with:?}"
);
@@ -1424,7 +1438,7 @@ mod tests {
.ansi_strip()
.to_string();
assert!(
- !without.contains("comments"),
+ !without.contains("COMMENTS"),
"no comments line when absent: {without:?}"
);
}
@@ -1472,8 +1486,12 @@ mod tests {
"title: {pr_pane:?}"
);
assert!(
- pr_pane.contains("\x1b[107m"),
- "description gutter: {pr_pane:?}"
+ !pr_pane.contains("\x1b[107m"),
+ "description renders flush, no gutter: {pr_pane:?}"
+ );
+ assert!(
+ pr_pane.contains("bounded"),
+ "description body rendered: {pr_pane:?}"
);
// `SkimItem::preview` reads the default in-memory mode (WorkingTree, since
diff --git a/src/commands/picker/pr_pane.rs b/src/commands/picker/pr_pane.rs
index d69eeae0a..24b234f4e 100644
--- a/src/commands/picker/pr_pane.rs
+++ b/src/commands/picker/pr_pane.rs
@@ -3,17 +3,21 @@
//! Two rows show a PR/MR: a worktree row whose branch has one
//! (`render_worktree_pr` in [`super::items`]) and a `--prs` row
//! ([`super::prs::PrSkimItem`]). Both render the same shape — a bold reference +
-//! title header, dim-labeled metadata lines whose values share one column, and
-//! the description as markdown inside the house gutter — so they read alike.
+//! title header, cyan all-caps labeled metadata lines whose values share one
+//! column, and a matching `DESCRIPTION` heading above the full body rendered
+//! flush as markdown — so they read alike.
//! They build from these shared pieces rather than each formatting their own.
+//! Every label (`BRANCH`, `URL`, `DESCRIPTION`, …) goes through [`field_label`],
+//! which renders the app's cyan all-caps title style, so they all match the
+//! headings elsewhere in the CLI (`wt config show`, `wt step`, …).
use anstyle::Reset;
use color_print::cformat;
-use worktrunk::styling::format_with_gutter;
+use worktrunk::styling::{format_heading, format_with_gutter};
use super::super::list::ci_status::PrRef;
-/// Column (in cells) where a metadata line's value begins, after its dim label.
+/// Column (in cells) where a metadata line's value begins, after its cyan label.
/// The widest labels (`branch`/`author`, 6) plus a 3-space gap; shorter labels
/// (`url`, `state`) pad out to the same column so every value lines up — across
/// lines and across the two panes.
@@ -30,47 +34,59 @@ pub(super) fn header(pr_ref: PrRef, title: Option<&str>) -> String {
}
}
-/// One dim-labeled metadata line (`branch`, `author`, `url`, …). The label pads
-/// so the value starts at [`VALUE_COLUMN`], aligning values down the pane and
-/// between the two panes. `value` may carry its own styling (e.g. a yellow
-/// `draft`) and must close its own spans. A full `{reset}` after the label keeps
-/// the dim from bleeding into the value (skim's ANSI parser drops color_print's
-/// `</>`); see [`super::items::render_preview_tabs`].
-pub(super) fn metadata_line(label: &str, value: &str) -> String {
+/// A field label (`BRANCH`, `URL`, `DESCRIPTION`, …) in the app's cyan all-caps
+/// title style, rendered through [`format_heading`] so it matches the section
+/// headings across the CLI (`wt config show`, `wt step`, …). A trailing full
+/// `{reset}` closes the span: skim's ANSI parser drops color_print's `</>` (the
+/// SGR 39 `format_heading` itself emits), so the cyan would otherwise bleed into
+/// the value or body (see [`super::items::render_preview_tabs`]). Every label in
+/// the pane goes through this one helper, so they all render identically.
+fn field_label(text: &str) -> String {
let reset = Reset;
+ format!("{}{reset}", format_heading(&text.to_uppercase(), None))
+}
+
+/// One cyan all-caps labeled metadata line (`BRANCH`, `AUTHOR`, `URL`, …). The
+/// label pads so the value starts at [`VALUE_COLUMN`], aligning values down the
+/// pane and between the two panes. `value` may carry its own styling (e.g. a
+/// yellow `draft`) and must close its own spans.
+pub(super) fn metadata_line(label: &str, value: &str) -> String {
let pad = " ".repeat(VALUE_COLUMN.saturating_sub(label.len()));
- let label = cformat!("<dim>{label}</>{reset}");
- format!("{label}{pad}{value}\n")
+ format!("{}{pad}{value}\n", field_label(label))
}
-/// The description block: `body` rendered as markdown (bold headers, styled
-/// lists and inline code — the same renderer the `summary` tab uses) and quoted
-/// in the house gutter ([`format_with_gutter`], a bg-color bar that closes each
-/// line with a full `\x1b[0m`, skim-safe). The whole body renders; the preview
-/// pane scrolls (`ctrl-u`/`ctrl-d`) through a long one. Empty body → empty
-/// string, so the block is skipped. The leading `\x1b[0m` is a defensive
-/// boundary so the first gutter line renders clean regardless of what precedes
-/// it (the metadata lines already reset their own spans).
+/// The description block: a cyan all-caps `DESCRIPTION` label (via
+/// [`field_label`], so it matches the metadata labels above it) over the full
+/// `body` rendered flush as markdown (bold headers, styled lists, inline code;
+/// fenced code blocks dim and flush) via
+/// [`render_markdown_flush`](crate::md_help::render_markdown_flush) —
+/// nothing is quoted in the house gutter, so the whole body sits flush-left.
+/// Blank lines set the label off from the inline metadata above and from its
+/// body below. The whole body renders; the preview pane scrolls
+/// (`ctrl-u`/`ctrl-d`) through a long one. Empty body → empty string, so the
+/// block (label included) is skipped. The leading `\x1b[0m` is a defensive
+/// boundary so the label renders clean regardless of what precedes it (the
+/// metadata lines already reset their own spans).
///
-/// `width` is the preview-pane width. The `--prs` pane is built before skim
-/// renders, so it passes the list width as a close proxy (Right splits ~50/50;
-/// Down gives list and preview the full width); the worktree pane reads the live
-/// preview width. The markdown wraps to the gutter's inner width (the bar plus
-/// its pad take two columns) so the gutter's own wrap is a no-op rather than
-/// re-breaking the already-styled lines.
+/// `width` is the preview-pane width, which the markdown wraps prose to. The
+/// `--prs` pane is built before skim renders, so it passes the list width as a
+/// close proxy (Right splits ~50/50; Down gives list and preview the full
+/// width); the worktree pane reads the live preview width.
pub(super) fn description(body: &str, width: usize) -> String {
let body = body.trim();
if body.is_empty() {
return String::new();
}
let reset = Reset;
- format!("\n{reset}{}\n", markdown_in_gutter(body, width))
+ let label = field_label("description");
+ let rendered = crate::md_help::render_markdown_flush(body, Some(width));
+ format!("\n{reset}{label}\n\n{rendered}\n")
}
/// Render `body` as markdown and quote it in the house gutter, returning no
-/// leading/trailing newline — the shared inner form behind [`description`] and
-/// the `--prs` comments pane (`prs::render_comment_blocks`), so the PR/MR body
-/// and each comment read alike. The markdown wraps to the gutter's inner width
+/// leading/trailing newline — the inner form behind the `--prs` comments pane
+/// (`prs::render_comment_blocks`), where the gutter sets each comment's body
+/// off from its author header. The markdown wraps to the gutter's inner width
/// (the bar plus its pad take two columns) so the gutter's own wrap is a no-op
/// rather than re-breaking the already-styled lines.
pub(super) fn markdown_in_gutter(body: &str, width: usize) -> String {
@@ -133,36 +149,60 @@ mod tests {
#[test]
fn description_empty_or_blank_renders_nothing() {
// No body, or whitespace-only — the block is skipped entirely so the
- // pane doesn't show an empty gutter.
+ // pane shows nothing.
assert_eq!(description("", 80), "");
assert_eq!(description(" \n\t \n", 80), "");
}
#[test]
- fn description_wraps_into_the_house_gutter() {
+ fn description_renders_flush_without_a_gutter() {
let out = description("Fixes the flaky retry logic.", 80);
- // Leading full reset clears inherited style; the house gutter sets a
- // bg color and closes each line with a skim-safe `\x1b[0m`.
+ // Leading full reset clears inherited style; the body renders flush, so
+ // no house-gutter bg bar (`\x1b[107m`) wraps it.
assert!(out.starts_with("\n\x1b[0m"), "leading reset: {out:?}");
- assert!(out.contains("\x1b[107m"), "house gutter bg: {out:?}");
+ assert!(!out.contains("\x1b[107m"), "no gutter bar: {out:?}");
assert!(
out.contains("Fixes the flaky retry logic."),
"body: {out:?}"
);
}
+ #[test]
+ fn description_labels_the_block_like_the_metadata() {
+ use ansi_str::AnsiStr;
+ let out = description("Fixes the flaky retry logic.", 80);
+ // A cyan all-caps `DESCRIPTION` label (SGR 36) heads the block, the same
+ // styling the `branch`/`url` metadata labels use via `field_label`.
+ assert!(out.contains("\x1b[36m"), "cyan label present: {out:?}");
+ let stripped = out.ansi_strip();
+ let lines: Vec<&str> = stripped.lines().collect();
+ let label_idx = lines
+ .iter()
+ .position(|l| l.trim() == "DESCRIPTION")
+ .expect("standalone `DESCRIPTION` label line");
+ // A blank line separates the label from its body.
+ assert!(
+ lines[label_idx + 1].is_empty(),
+ "blank line after the label: {stripped:?}"
+ );
+ assert!(
+ lines[label_idx + 2].contains("Fixes the flaky retry logic."),
+ "body follows the blank line: {stripped:?}"
+ );
+ }
+
#[test]
fn description_renders_the_whole_body() {
- // One item per line so each survives as its own gutter line; the pane
- // scrolls, so the full body renders with no truncation hint.
+ // One item per line; the whole body renders with no truncation, so both
+ // the first and last item survive and there's no `…` marker.
let body = (0..50)
.map(|i| format!("- word{i}"))
.collect::<Vec<_>>()
.join("\n");
let out = description(&body, 80);
- assert!(!out.contains("more line"), "no truncation hint: {out:?}");
assert!(out.contains("word0"), "head kept: {out:?}");
assert!(out.contains("word49"), "tail kept: {out:?}");
+ assert!(!out.contains('…'), "no truncation marker: {out:?}");
}
#[test]
@@ -173,4 +213,19 @@ mod tests {
assert!(out.contains("\x1b[1m"), "bold rendered: {out:?}");
assert!(!out.contains("**"), "markers consumed: {out:?}");
}
+
+ #[test]
+ fn description_renders_code_blocks_flush() {
+ use ansi_str::AnsiStr;
+ // A fenced code block renders flush and dim — no house gutter bar, and
+ // the code line sits at column 0, not indented into a gutter.
+ let out = description("Run it:\n\n```\nwt switch\n```", 80);
+ assert!(!out.contains("\x1b[107m"), "no gutter bar: {out:?}");
+ let code = out
+ .lines()
+ .map(|l| l.ansi_strip().into_owned())
+ .find(|l| l.contains("wt switch"))
+ .expect("code line present");
+ assert_eq!(code, "wt switch", "code flush at column 0: {code:?}");
+ }
}
diff --git a/src/commands/picker/prs.rs b/src/commands/picker/prs.rs
index ec3e8827a..686d297ae 100644
--- a/src/commands/picker/prs.rs
+++ b/src/commands/picker/prs.rs
@@ -1670,13 +1670,35 @@ mod tests {
with_body.body = "A short summary of the change.".to_string();
let pr = pr_item(with_body, 120, Some(&grid()));
assert!(pr.pr_pane.contains("A short summary of the change."));
- assert!(pr.pr_pane.contains("\x1b[107m"), "gutter present");
+ // The body renders flush, not quoted in a gutter bar; `description`
+ // prefixes its block with a blank line + full reset.
+ assert!(
+ !pr.pr_pane.contains("\x1b[107m"),
+ "no gutter bar: {:?}",
+ pr.pr_pane
+ );
+ assert!(
+ pr.pr_pane.contains("\n\n\x1b[0m"),
+ "description block present"
+ );
+ // The block is headed by a cyan `DESCRIPTION` label, matching branch/url.
+ assert!(
+ pr.pr_pane.contains("DESCRIPTION"),
+ "DESCRIPTION label present: {:?}",
+ pr.pr_pane
+ );
- // The base fixture has an empty body — no gutter, no description.
+ // The base fixture has an empty body — the description block is skipped,
+ // label and all.
let plain_pr = pr_item(entry(RefKind::Pr, 2, "t"), 120, Some(&grid()));
assert!(
- !plain_pr.pr_pane.contains("\x1b[107m"),
- "no gutter when empty"
+ !plain_pr.pr_pane.contains("\n\n\x1b[0m"),
+ "no description block when empty"
+ );
+ assert!(
+ !plain_pr.pr_pane.contains("DESCRIPTION"),
+ "no DESCRIPTION label when empty: {:?}",
+ plain_pr.pr_pane
);
}
diff --git a/src/md_help.rs b/src/md_help.rs
index b3ac418d4..26eedf856 100644
--- a/src/md_help.rs
+++ b/src/md_help.rs
@@ -38,11 +38,31 @@ fn help_table_skin() -> MadSkin {
skin
}
+/// How fenced code blocks render: quoted in the house gutter (the default, for
+/// help pages and the summary tab) or flush and dim with no gutter. The picker's
+/// `pr` description pane renders the whole body gutter-free, so it picks `Flush`.
+#[derive(Clone, Copy, PartialEq)]
+enum CodeBlocks {
+ Gutter,
+ Flush,
+}
+
/// Render markdown in help text to ANSI with minimal styling (green headers only)
///
/// If `width` is provided, prose text is wrapped to that width. Tables, code blocks,
/// and headers are never wrapped (tables need full-width rows for alignment).
pub(crate) fn render_markdown_in_help_with_width(help: &str, width: Option<usize>) -> String {
+ render_markdown(help, width, CodeBlocks::Gutter)
+}
+
+/// Like [`render_markdown_in_help_with_width`], but renders fenced code blocks
+/// flush and dim rather than quoted in the house gutter — for the picker's `pr`
+/// description pane, which renders the whole body gutter-free and flush-left.
+pub(crate) fn render_markdown_flush(help: &str, width: Option<usize>) -> String {
+ render_markdown(help, width, CodeBlocks::Flush)
+}
+
+fn render_markdown(help: &str, width: Option<usize>, code_blocks: CodeBlocks) -> String {
let green = Style::new().fg_color(Some(Color::Ansi(AnsiColor::Green)));
let mut result = String::new();
@@ -85,37 +105,49 @@ pub(crate) fn render_markdown_in_help_with_width(help: &str, width: Option<usize
code_block_lines.clear();
in_code_block = true;
} else {
- // Closing fence — render collected code block with gutter
+ // Closing fence — render the collected code block. Flush mode
+ // dims each line with no gutter and no language-specific
+ // highlighting, so the description pane stays gutter-free and
+ // flush-left; the gutter mode quotes it in the house bar.
let content = code_block_lines.join("\n");
- let formatted = match code_block_lang.as_str() {
- "toml" => format_toml(&content),
- "console" => {
- // Strip `$ ` prompt from console blocks for copy-paste.
- // The prefix is preserved in source for web docs.
- let stripped = content
- .lines()
- .map(|l| l.strip_prefix("$ ").unwrap_or(l))
- .collect::<Vec<_>>()
- .join("\n");
- // Captured `wt list` tables (chop_next_block) are chopped to
- // width; hand-authored command sessions still word-wrap.
- if chop_next_block {
- format_bash_with_gutter_chopped(&stripped)
- } else {
- format_bash_with_gutter(&stripped)
+ let formatted = if code_blocks == CodeBlocks::Flush {
+ let dim = Style::new().dimmed();
+ code_block_lines
+ .iter()
+ .map(|l| format!("{dim}{l}{dim:#}"))
+ .collect::<Vec<_>>()
+ .join("\n")
+ } else {
+ match code_block_lang.as_str() {
+ "toml" => format_toml(&content),
+ "console" => {
+ // Strip `$ ` prompt from console blocks for copy-paste.
+ // The prefix is preserved in source for web docs.
+ let stripped = content
+ .lines()
+ .map(|l| l.strip_prefix("$ ").unwrap_or(l))
+ .collect::<Vec<_>>()
+ .join("\n");
+ // Captured `wt list` tables (chop_next_block) are chopped to
+ // width; hand-authored command sessions still word-wrap.
+ if chop_next_block {
+ format_bash_with_gutter_chopped(&stripped)
+ } else {
+ format_bash_with_gutter(&stripped)
+ }
+ }
+ "bash" | "sh" => format_bash_with_gutter(&content),
+ _ => {
+ // Dim the content before adding gutter (format_with_gutter
+ // doesn't style text; bash/toml formatters handle their own)
+ let dim = Style::new().dimmed();
+ let dimmed = code_block_lines
+ .iter()
+ .map(|l| format!("{dim}{l}{dim:#}"))
+ .collect::<Vec<_>>()
+ .join("\n");
+ format_with_gutter(&dimmed, None)
}
- }
- "bash" | "sh" => format_bash_with_gutter(&content),
- _ => {
- // Dim the content before adding gutter (format_with_gutter
- // doesn't style text; bash/toml formatters handle their own)
- let dim = Style::new().dimmed();
- let dimmed = code_block_lines
- .iter()
- .map(|l| format!("{dim}{l}{dim:#}"))
- .collect::<Vec<_>>()
- .join("\n");
- format_with_gutter(&dimmed, None)
}
};
result.push_str(&formatted);