Skip to content

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

feat(statusline): make the CI and URL segments clickable in Claude Code (#3550)

Maximilian Roos14d4d92532d3
diff --git a/docs/content/claude-code.md b/docs/content/claude-code.md
index 17b07a10e..06605956d 100644
--- a/docs/content/claude-code.md
+++ b/docs/content/claude-code.md
@@ -109,6 +109,8 @@ Claude Code agents can run in isolated worktrees (`isolation: "worktree"`). By d
<code>~/w/myproject.feature-auth !πŸ€– @<span style='color:#0a0'>+42</span> <span style='color:#a00'>-8</span> <span style='color:#0a0'>↑3</span> <span style='color:#0a0'>⇑1</span> <span style='color:#0a0'>#3035</span> Opus πŸŒ” 65% <span style='color:#a70'>1.4Γ—(10am–3pm)</span></code>
+The CI reference (`#3035`) links to its pull request, and a configured [dev server URL](@/list.md) collapses to a clickable `:3000` instead of rendering in full. Both are OSC 8 hyperlinks: underlined and clickable in terminals that support them, plain text everywhere else.
+
When Claude Code provides context window usage via stdin JSON, a moon phase gauge appears (πŸŒ•β†’πŸŒ‘ as context fills). A `<n>Γ—(<window>)` segment appears when Claude's 5-hour or weekly rate limit is on track to be hit before reset β€” `1.4Γ—(10am–3pm)` reads as 1.4Γ— the pace that would exactly fill that window. Its colour deepens with severity β€” dim, then dim-yellow, then yellow β€” as more of the window would be spent locked out at the cap, so a fast pace that would only tip over near the reset stays dim. Above 90% used it shows usage instead of pace β€” `93%(10am–3pm)` β€” near the cap, how much is left matters more than how fast it's going.
<figure class="demo">
diff --git a/docs/content/list.md b/docs/content/list.md
index 57cc12581..04f36a21d 100644
--- a/docs/content/list.md
+++ b/docs/content/list.md
@@ -283,7 +283,7 @@ Item fields:
| `dev_server` | `{url, listening}` from the project's `list.url` template |
| `summary` | LLM branch summary (requires `[list] summary = true`) |
| `vars` | Per-branch variables from [`wt config state vars`](@/config.md#wt-config-state-vars) |
-| `display` | Rendered strings: `state` (schema 1's `main_state` vocabulary), `symbols`, `statusline` (with ANSI colors), `columns` (custom-column cells keyed by header) |
+| `display` | Rendered strings: `state` (schema 1's `main_state` vocabulary), `symbols`, `statusline` (with ANSI colors and OSC 8 hyperlinks), `columns` (custom-column cells keyed by header) |
Schema 1 names map directly: `commit` β†’ `head`, `working_tree` β†’
`worktree.changes`, `main` + `main_state` β†’ `default_branch` +
@@ -323,7 +323,7 @@ The original bare-array format, and the default while unset:
| `url` | string | Dev server URL from project config; absent when not configured |
| `url_active` | boolean | Whether the URL's port is listening; absent when not configured |
| `summary` | string | LLM-generated branch summary; `--full` only, then absent when not configured or no summary |
-| `statusline` | string | Pre-formatted status with ANSI colors |
+| `statusline` | string | Pre-formatted status with colors and links |
| `symbols` | string | Raw status symbols without colors (e.g., `"!?↓"`) |
| `vars` | object | Per-branch variables from [`wt config state vars`](@/config.md#wt-config-state-vars) (absent when empty) |
| `columns` | object | Rendered [custom column](#custom-columns) values keyed by header; empty cells omitted (absent when none configured) |
diff --git a/plugins/worktrunk/skills/worktrunk/reference/claude-code.md b/plugins/worktrunk/skills/worktrunk/reference/claude-code.md
index 955ad72a9..53905c1dc 100644
--- a/plugins/worktrunk/skills/worktrunk/reference/claude-code.md
+++ b/plugins/worktrunk/skills/worktrunk/reference/claude-code.md
@@ -111,6 +111,8 @@ Claude Code agents can run in isolated worktrees (`isolation: "worktree"`). By d
<code>~/w/myproject.feature-auth !πŸ€– @<span style='color:#0a0'>+42</span> <span style='color:#a00'>-8</span> <span style='color:#0a0'>↑3</span> <span style='color:#0a0'>⇑1</span> <span style='color:#0a0'>#3035</span> Opus πŸŒ” 65% <span style='color:#a70'>1.4Γ—(10am–3pm)</span></code>
+The CI reference (`#3035`) links to its pull request, and a configured [dev server URL](https://worktrunk.dev/list/) collapses to a clickable `:3000` instead of rendering in full. Both are OSC 8 hyperlinks: underlined and clickable in terminals that support them, plain text everywhere else.
+
When Claude Code provides context window usage via stdin JSON, a moon phase gauge appears (πŸŒ•β†’πŸŒ‘ as context fills). A `<n>Γ—(<window>)` segment appears when Claude's 5-hour or weekly rate limit is on track to be hit before reset β€” `1.4Γ—(10am–3pm)` reads as 1.4Γ— the pace that would exactly fill that window. Its colour deepens with severity β€” dim, then dim-yellow, then yellow β€” as more of the window would be spent locked out at the cap, so a fast pace that would only tip over near the reset stays dim. Above 90% used it shows usage instead of pace β€” `93%(10am–3pm)` β€” near the cap, how much is left matters more than how fast it's going.
Add to `~/.claude/settings.json`:
diff --git a/plugins/worktrunk/skills/worktrunk/reference/list.md b/plugins/worktrunk/skills/worktrunk/reference/list.md
index 8b98ea209..5145e9797 100644
--- a/plugins/worktrunk/skills/worktrunk/reference/list.md
+++ b/plugins/worktrunk/skills/worktrunk/reference/list.md
@@ -268,7 +268,7 @@ Item fields:
| `dev_server` | `{url, listening}` from the project's `list.url` template |
| `summary` | LLM branch summary (requires `[list] summary = true`) |
| `vars` | Per-branch variables from [`wt config state vars`](https://worktrunk.dev/config/#wt-config-state-vars) |
-| `display` | Rendered strings: `state` (schema 1's `main_state` vocabulary), `symbols`, `statusline` (with ANSI colors), `columns` (custom-column cells keyed by header) |
+| `display` | Rendered strings: `state` (schema 1's `main_state` vocabulary), `symbols`, `statusline` (with ANSI colors and OSC 8 hyperlinks), `columns` (custom-column cells keyed by header) |
Schema 1 names map directly: `commit` β†’ `head`, `working_tree` β†’
`worktree.changes`, `main` + `main_state` β†’ `default_branch` +
@@ -344,7 +344,7 @@ $ wt list --format=json --full | jq '.[] | select(.ci.stale) | .branch'
| `url` | string | Dev server URL from project config; absent when not configured |
| `url_active` | boolean | Whether the URL's port is listening; absent when not configured |
| `summary` | string | LLM-generated branch summary; `--full` only, then absent when not configured or no summary |
-| `statusline` | string | Pre-formatted status with ANSI colors |
+| `statusline` | string | Pre-formatted status with colors and links |
| `symbols` | string | Raw status symbols without colors (e.g., `"!?↓"`) |
| `vars` | object | Per-branch variables from [`wt config state vars`](https://worktrunk.dev/config/#wt-config-state-vars) (absent when empty) |
| `columns` | object | Rendered [custom column](#custom-columns) values keyed by header; empty cells omitted (absent when none configured) |
diff --git a/skills/worktrunk/reference/claude-code.md b/skills/worktrunk/reference/claude-code.md
index 955ad72a9..53905c1dc 100644
--- a/skills/worktrunk/reference/claude-code.md
+++ b/skills/worktrunk/reference/claude-code.md
@@ -111,6 +111,8 @@ Claude Code agents can run in isolated worktrees (`isolation: "worktree"`). By d
<code>~/w/myproject.feature-auth !πŸ€– @<span style='color:#0a0'>+42</span> <span style='color:#a00'>-8</span> <span style='color:#0a0'>↑3</span> <span style='color:#0a0'>⇑1</span> <span style='color:#0a0'>#3035</span> Opus πŸŒ” 65% <span style='color:#a70'>1.4Γ—(10am–3pm)</span></code>
+The CI reference (`#3035`) links to its pull request, and a configured [dev server URL](https://worktrunk.dev/list/) collapses to a clickable `:3000` instead of rendering in full. Both are OSC 8 hyperlinks: underlined and clickable in terminals that support them, plain text everywhere else.
+
When Claude Code provides context window usage via stdin JSON, a moon phase gauge appears (πŸŒ•β†’πŸŒ‘ as context fills). A `<n>Γ—(<window>)` segment appears when Claude's 5-hour or weekly rate limit is on track to be hit before reset β€” `1.4Γ—(10am–3pm)` reads as 1.4Γ— the pace that would exactly fill that window. Its colour deepens with severity β€” dim, then dim-yellow, then yellow β€” as more of the window would be spent locked out at the cap, so a fast pace that would only tip over near the reset stays dim. Above 90% used it shows usage instead of pace β€” `93%(10am–3pm)` β€” near the cap, how much is left matters more than how fast it's going.
Add to `~/.claude/settings.json`:
diff --git a/skills/worktrunk/reference/list.md b/skills/worktrunk/reference/list.md
index 8b98ea209..5145e9797 100644
--- a/skills/worktrunk/reference/list.md
+++ b/skills/worktrunk/reference/list.md
@@ -268,7 +268,7 @@ Item fields:
| `dev_server` | `{url, listening}` from the project's `list.url` template |
| `summary` | LLM branch summary (requires `[list] summary = true`) |
| `vars` | Per-branch variables from [`wt config state vars`](https://worktrunk.dev/config/#wt-config-state-vars) |
-| `display` | Rendered strings: `state` (schema 1's `main_state` vocabulary), `symbols`, `statusline` (with ANSI colors), `columns` (custom-column cells keyed by header) |
+| `display` | Rendered strings: `state` (schema 1's `main_state` vocabulary), `symbols`, `statusline` (with ANSI colors and OSC 8 hyperlinks), `columns` (custom-column cells keyed by header) |
Schema 1 names map directly: `commit` β†’ `head`, `working_tree` β†’
`worktree.changes`, `main` + `main_state` β†’ `default_branch` +
@@ -344,7 +344,7 @@ $ wt list --format=json --full | jq '.[] | select(.ci.stale) | .branch'
| `url` | string | Dev server URL from project config; absent when not configured |
| `url_active` | boolean | Whether the URL's port is listening; absent when not configured |
| `summary` | string | LLM-generated branch summary; `--full` only, then absent when not configured or no summary |
-| `statusline` | string | Pre-formatted status with ANSI colors |
+| `statusline` | string | Pre-formatted status with colors and links |
| `symbols` | string | Raw status symbols without colors (e.g., `"!?↓"`) |
| `vars` | object | Per-branch variables from [`wt config state vars`](https://worktrunk.dev/config/#wt-config-state-vars) (absent when empty) |
| `columns` | object | Rendered [custom column](#custom-columns) values keyed by header; empty cells omitted (absent when none configured) |
diff --git a/src/cli/mod.rs b/src/cli/mod.rs
index 2d10d7073..2323ee272 100644
--- a/src/cli/mod.rs
+++ b/src/cli/mod.rs
@@ -1024,7 +1024,7 @@ Item fields:
| `dev_server` | `{url, listening}` from the project's `list.url` template |
| `summary` | LLM branch summary (requires `[list] summary = true`) |
| `vars` | Per-branch variables from [`wt config state vars`](@/config.md#wt-config-state-vars) |
-| `display` | Rendered strings: `state` (schema 1's `main_state` vocabulary), `symbols`, `statusline` (with ANSI colors), `columns` (custom-column cells keyed by header) |
+| `display` | Rendered strings: `state` (schema 1's `main_state` vocabulary), `symbols`, `statusline` (with ANSI colors and OSC 8 hyperlinks), `columns` (custom-column cells keyed by header) |
Schema 1 names map directly: `commit` β†’ `head`, `working_tree` β†’
`worktree.changes`, `main` + `main_state` β†’ `default_branch` +
@@ -1100,7 +1100,7 @@ $ wt list --format=json --full | jq '.[] | select(.ci.stale) | .branch'
| `url` | string | Dev server URL from project config; absent when not configured |
| `url_active` | boolean | Whether the URL's port is listening; absent when not configured |
| `summary` | string | LLM-generated branch summary; `--full` only, then absent when not configured or no summary |
-| `statusline` | string | Pre-formatted status with ANSI colors |
+| `statusline` | string | Pre-formatted status with colors and links |
| `symbols` | string | Raw status symbols without colors (e.g., `"!?↓"`) |
| `vars` | object | Per-branch variables from [`wt config state vars`](@/config.md#wt-config-state-vars) (absent when empty) |
| `columns` | object | Rendered [custom column](#custom-columns) values keyed by header; empty cells omitted (absent when none configured) |
diff --git a/src/commands/list/ci_status/mod.rs b/src/commands/list/ci_status/mod.rs
index cfaef12a1..0ad5fb5f1 100644
--- a/src/commands/list/ci_status/mod.rs
+++ b/src/commands/list/ci_status/mod.rs
@@ -528,8 +528,9 @@ impl PrStatus {
/// known: Error and Conflicts share the warning color, so a yellow
/// `#3035` would be indistinguishable from a conflicted PR.
///
- /// When `include_link` is false, the cell is colored but not clickable
- /// (for environments without OSC 8 hyperlinks, e.g. Claude Code).
+ /// When `include_link` is false, the cell is colored but not clickable β€”
+ /// for the `wt list` table on a terminal without OSC 8, and for the picker,
+ /// which strips the sequences.
pub fn format_cell(&self, max_width: usize, include_link: bool) -> String {
match self.number {
Some(r) if !matches!(self.ci_status, CiStatus::Error) && r.width() <= max_width => {
diff --git a/src/commands/list/layout.rs b/src/commands/list/layout.rs
index d84ad371d..0a13de14a 100644
--- a/src/commands/list/layout.rs
+++ b/src/commands/list/layout.rs
@@ -599,6 +599,30 @@ struct PendingColumn<'a> {
format: ColumnFormat,
}
+/// Format the dev-server URL, optionally as an OSC 8 hyperlink.
+///
+/// A linked cell shows just the port (e.g. `:3000`) β€” the URL rides inside the
+/// escape sequence, so the cell costs the port's width rather than the whole
+/// URL's. Without links, or when the URL carries no parseable port, there is
+/// nowhere to hide the URL, so it renders in full and stays copyable.
+///
+/// Callers pass the decision rather than probing the terminal here: the
+/// statusline's stdout is a pipe to its editor, so `supports_hyperlinks` reports
+/// false there even though the consumer renders OSC 8.
+///
+/// [`estimate_url_width`] budgets the column against this, so the two have to
+/// agree on when a cell collapses to `:port` β€” hence the adjacency.
+pub(crate) fn format_url_cell(url: &str, include_link: bool) -> String {
+ if include_link && let Some(port) = parse_port_from_url(url) {
+ return format!(
+ "{}:{port}{}",
+ osc8::Hyperlink::new(url),
+ osc8::Hyperlink::END
+ );
+ }
+ url.to_string()
+}
+
/// Estimate URL column width using heuristics.
///
/// When hyperlinks are supported, URLs display as `:PORT` (6 chars for 5-digit ports).
diff --git a/src/commands/list/model/item.rs b/src/commands/list/model/item.rs
index bfa165fad..37194bfdc 100644
--- a/src/commands/list/model/item.rs
+++ b/src/commands/list/model/item.rs
@@ -12,6 +12,7 @@ use super::stats::{AheadBehind, BranchDiffTotals, CommitDetails, UpstreamStatus}
use super::status_symbols::{StatusSymbols, WorkingTreeStatus};
use crate::commands::list::ci_status::PrStatus;
use crate::commands::list::columns::ColumnKind;
+use crate::commands::list::layout::format_url_cell;
/// Compute the `WorktreeState` from `WorktreeData` metadata alone.
///
@@ -469,26 +470,15 @@ impl ListItem {
/// Format: `branch status @working commits ^branch_diff upstream ci`
/// Uses 2-space separators between non-empty parts.
pub fn format_statusline(&self) -> String {
- self.format_statusline_with_options(true)
- }
-
- /// Format this item as a single-line statusline string with link control.
- ///
- /// When `include_links` is false, CI indicators are colored but not clickable.
- /// Used for environments that don't support OSC 8 hyperlinks (e.g., Claude Code).
- pub fn format_statusline_with_options(&self, include_links: bool) -> String {
use super::statusline_segment::StatuslineSegment;
- StatuslineSegment::join(&self.format_statusline_segments(include_links))
+ StatuslineSegment::join(&self.format_statusline_segments())
}
/// Format this item as prioritized segments for smart truncation.
///
/// Returns segments with priorities matching `wt list` column priorities.
/// Use [`super::statusline_segment::StatuslineSegment::fit_to_width`] to truncate intelligently.
- pub fn format_statusline_segments(
- &self,
- include_links: bool,
- ) -> Vec<super::statusline_segment::StatuslineSegment> {
+ pub fn format_statusline_segments(&self) -> Vec<super::statusline_segment::StatuslineSegment> {
use super::statusline_segment::StatuslineSegment;
let mut segments = Vec::new();
@@ -529,7 +519,7 @@ impl ListItem {
));
}
- // 5. Branch diff vs main (priority 5)
+ // 5. Branch diff vs main (priority 6)
if let Some(branch_diff) = self.branch_diff()
&& !branch_diff.diff.is_empty()
&& let Some(formatted) = ColumnKind::BranchDiff
@@ -541,7 +531,7 @@ impl ListItem {
));
}
- // 6. Upstream status (priority 7)
+ // 6. Upstream status (priority 8)
if let Some(ref upstream) = self.upstream
&& let Some(active) = upstream.active()
&& let Some(formatted) =
@@ -553,18 +543,21 @@ impl ListItem {
));
}
- // 7. CI status (priority 9) β€” PR/MR reference when one exists,
+ // 7. CI status (priority 5) β€” PR/MR reference when one exists,
// bare `#` otherwise (no width cap in the statusline)
if let Some(Some(ref pr_status)) = self.pr_status {
segments.push(StatuslineSegment::from_column(
- pr_status.format_cell(usize::MAX, include_links),
+ pr_status.format_cell(usize::MAX, true),
ColumnKind::CiStatus,
));
}
- // 8. URL (priority 8)
+ // 8. URL (priority 9) β€” the port as a link to the dev server, as in `wt list`
if let Some(ref url) = self.url {
- segments.push(StatuslineSegment::from_column(url.clone(), ColumnKind::Url));
+ segments.push(StatuslineSegment::from_column(
+ format_url_cell(url, true),
+ ColumnKind::Url,
+ ));
}
segments
@@ -889,6 +882,44 @@ mod tests {
assert_eq!(item.head(), "abc123def");
}
+ /// The statusline links its CI segment to the PR, and the hidden URL costs
+ /// no visible width β€” segment priorities budget by rendered columns, so a
+ /// URL counted as width would truncate the line early.
+ #[test]
+ fn test_statusline_ci_segment_links_without_width_cost() {
+ use crate::commands::list::ci_status::{CiSource, CiStatus, PrRef};
+
+ let mut item = ListItem::new_branch("abc123".to_string(), "feature".to_string());
+ item.pr_status = Some(Some(PrStatus {
+ ci_status: CiStatus::Passed,
+ source: CiSource::PullRequest,
+ is_stale: false,
+ is_priming: false,
+ url: Some("https://github.com/owner/repo/pull/123".to_string()),
+ number: Some(PrRef::pr(123)),
+ review_state: None,
+ title: None,
+ body: None,
+ author: None,
+ comment_count: None,
+ updated_at: None,
+ }));
+
+ let ci = item
+ .format_statusline_segments()
+ .into_iter()
+ .find(|s| s.kind == Some(ColumnKind::CiStatus))
+ .expect("CI segment present when a PR is known");
+
+ assert!(
+ ci.content
+ .contains("\x1b]8;;https://github.com/owner/repo/pull/123"),
+ "CI segment should carry an OSC 8 link, got {:?}",
+ ci.content
+ );
+ assert_eq!(ci.width(), "#123".len());
+ }
+
#[test]
fn test_list_item_counts() {
// New items have no counts computed yet
diff --git a/src/commands/list/render.rs b/src/commands/list/render.rs
index b9ea1e06e..04d24304e 100644
--- a/src/commands/list/render.rs
+++ b/src/commands/list/render.rs
@@ -2,11 +2,10 @@ use crate::display::{format_relative_time_short, shorten_path, truncate_to_width
use anstyle::{Effects, Style};
use std::path::Path;
use unicode_width::UnicodeWidthStr;
-use worktrunk::styling::{Stream, StyledLine, hyperlink_stdout, supports_hyperlinks};
+use worktrunk::styling::{Stream, StyledLine, supports_hyperlinks};
-use super::collect::parse_port_from_url;
use super::columns::{ColumnKind, DiffVariant};
-use super::layout::{ColumnFormat, ColumnLayout, DiffColumnConfig, LayoutConfig};
+use super::layout::{ColumnFormat, ColumnLayout, DiffColumnConfig, LayoutConfig, format_url_cell};
use super::model::{ItemKind, ListItem, PositionMask};
/// Placeholder glyph for unresolved Status positions β€” both "still loading" and
@@ -568,7 +567,7 @@ impl ColumnLayout {
return StyledLine::new();
};
let mut cell = StyledLine::new();
- let formatted = format_url_cell(url);
+ let formatted = format_url_cell(url, supports_hyperlinks(Stream::Stdout));
if item.url_active == Some(true) {
cell.push_raw(formatted);
} else {
@@ -632,21 +631,6 @@ impl ColumnLayout {
}
}
-/// Format URL cell with optional hyperlink.
-///
-/// When the terminal supports OSC 8 hyperlinks, shows just the port (e.g., `:3000`)
-/// as a clickable link. Otherwise, shows the full URL.
-fn format_url_cell(url: &str) -> String {
- if supports_hyperlinks(Stream::Stdout) {
- // Extract port from URL for compact display
- if let Some(port) = parse_port_from_url(url) {
- return hyperlink_stdout(url, &format!(":{port}"));
- }
- }
- // Fallback: show full URL
- url.to_string()
-}
-
#[cfg(test)]
mod tests {
use super::*;
diff --git a/src/commands/statusline.rs b/src/commands/statusline.rs
index c8a8b36be..da4deb9a9 100644
--- a/src/commands/statusline.rs
+++ b/src/commands/statusline.rs
@@ -770,11 +770,11 @@ pub fn run(format: StatuslineFormat) -> Result<()> {
None
};
- // Git status segments (skip links in claude-code mode - OSC 8 not supported)
+ // Git status segments
if let Ok(repo) = Repository::current()
&& repo.worktree_at(&cwd).git_dir().is_ok()
{
- let git_segments = git_status_segments(&repo, &cwd, !claude_code)?;
+ let git_segments = git_status_segments(&repo, &cwd)?;
// In claude-code mode, skip branch segment if directory matches worktrunk template
let git_segments = if let Some(ref dir) = dir_str {
@@ -990,12 +990,8 @@ fn filter_redundant_branch(segments: Vec<StatuslineSegment>, dir: &str) -> Vec<S
/// Get git status as prioritized segments for the current worktree.
///
-/// When `include_links` is true, CI status includes clickable OSC 8 hyperlinks.
-fn git_status_segments(
- repo: &Repository,
- cwd: &Path,
- include_links: bool,
-) -> Result<Vec<StatuslineSegment>> {
+/// CI status and the dev-server URL render as clickable OSC 8 hyperlinks.
+fn git_status_segments(repo: &Repository, cwd: &Path) -> Result<Vec<StatuslineSegment>> {
use super::list::columns::ColumnKind;
// Get current worktree info
@@ -1065,7 +1061,7 @@ fn git_status_segments(
list::populate_item(repo, &mut item, options)?;
// Get prioritized segments
- let segments = item.format_statusline_segments(include_links);
+ let segments = item.format_statusline_segments();
if segments.is_empty() {
// Fallback: just show branch name
@@ -1211,6 +1207,85 @@ mod tests {
);
}
+ /// Width fitting must never cut inside a linked segment's OSC 8 sequence.
+ /// `truncate_visible` ends its cut with `\e[0m`, which resets colour but
+ /// leaves a hyperlink *open*, so a severed link would make the rest of the
+ /// terminal line clickable.
+ ///
+ /// What rules it out is that the two cuts can't meet. `fit_to_width` drops
+ /// whole segments, worst priority first, and stops at one; character
+ /// truncation only ever reaches that lone survivor, which is always a
+ /// best-priority segment β€” Directory (0), Branch or Model (1). Every
+ /// link-bearing segment is strictly worse β€” CI (5), URL (9) β€” so each is
+ /// dropped entire long before the survivor is cut into.
+ ///
+ /// The sweep covers both, and they leave at different pressures: URL is
+ /// the worst priority in the table, so it goes before CI.
+ #[test]
+ fn test_statusline_fitting_never_splits_a_hyperlink() {
+ use super::super::list::columns::ColumnKind;
+ use super::super::list::layout::format_url_cell;
+
+ let ci = StatuslineSegment::from_column(
+ format!(
+ "{}#3550{}",
+ osc8::Hyperlink::new("https://github.com/max-sixty/worktrunk/pull/3550"),
+ osc8::Hyperlink::END
+ ),
+ ColumnKind::CiStatus,
+ );
+ let url = StatuslineSegment::from_column(
+ format_url_cell("http://127.0.0.1:17913", true),
+ ColumnKind::Url,
+ );
+ let segments = vec![
+ StatuslineSegment::from_column(
+ "statusline-osc8-hyperlinks".to_string(),
+ ColumnKind::Branch,
+ ),
+ ci,
+ url,
+ ];
+
+ // Count of intact links seen at each width, so the sweep can prove it
+ // exercised every drop stage rather than only the roomy ones.
+ let mut seen_link_counts = std::collections::BTreeSet::new();
+ for max_width in 1usize..=90 {
+ let fitted =
+ StatuslineSegment::fit_to_width(segments.clone(), max_width.saturating_sub(1));
+ let joined = StatuslineSegment::join(&fitted);
+ let out = truncate_visible(&format!("{} {joined}", anstyle::Reset), max_width);
+
+ // Opener and closer both begin `\e]8;;`, so every surviving link
+ // contributes exactly two markers. An odd total is a link the cut
+ // landed inside.
+ let markers = out.matches("\u{1b}]8;;").count();
+ assert_eq!(
+ markers % 2,
+ 0,
+ "severed hyperlink at width {max_width} ({markers} markers): {out:?}"
+ );
+ seen_link_counts.insert(markers / 2);
+
+ // When only one link is left it must be CI's: the URL is the
+ // worst priority in the table, so it is the first to go.
+ if markers / 2 == 1 {
+ assert!(
+ out.contains("/pull/3550") && !out.contains("127.0.0.1"),
+ "URL should drop before CI, got {out:?}"
+ );
+ }
+ }
+
+ // Both links, then one, then none β€” if fitting stopped dropping them
+ // the sweep would silently cover only one regime.
+ assert_eq!(
+ seen_link_counts,
+ [0, 1, 2].into_iter().collect(),
+ "sweep should span every drop stage"
+ );
+ }
+
#[test]
fn test_statusline_truncation() {
use color_print::cformat;
diff --git a/src/styling/hyperlink.rs b/src/styling/hyperlink.rs
index 2147decf2..3db521c05 100644
--- a/src/styling/hyperlink.rs
+++ b/src/styling/hyperlink.rs
@@ -5,15 +5,6 @@ use osc8::Hyperlink;
// Re-export for direct use
pub use supports_hyperlinks::{Stream, on as supports_hyperlinks};
-/// Format text as a clickable hyperlink for stdout, or return plain text if unsupported.
-pub fn hyperlink_stdout(url: &str, text: &str) -> String {
- if supports_hyperlinks(Stream::Stdout) {
- format!("{}{}{}", Hyperlink::new(url), text, Hyperlink::END)
- } else {
- text.to_string()
- }
-}
-
/// Strip OSC 8 hyperlinks while preserving other ANSI sequences (colors).
///
/// OSC 8 terminal hyperlinks are great for terminal output (clickable links!), but can cause
@@ -64,12 +55,6 @@ pub fn strip_osc8_hyperlinks(s: &str) -> String {
mod tests {
use super::*;
- #[test]
- fn test_hyperlink_returns_text_when_not_tty() {
- let result = hyperlink_stdout("https://example.com", "link");
- assert!(result == "link" || result.contains("https://example.com"));
- }
-
#[test]
fn test_strip_osc8_hyperlinks_removes_hyperlink() {
// OSC 8 format: ESC ] 8 ; params ; URL ST TEXT ESC ] 8 ; ; ST
diff --git a/src/styling/mod.rs b/src/styling/mod.rs
index 2e14a1eba..fd73d94ef 100644
--- a/src/styling/mod.rs
+++ b/src/styling/mod.rs
@@ -36,7 +36,7 @@ pub use format::{
wrap_styled_text,
};
pub use highlighting::format_toml;
-pub use hyperlink::{Stream, hyperlink_stdout, strip_osc8_hyperlinks, supports_hyperlinks};
+pub use hyperlink::{Stream, strip_osc8_hyperlinks, supports_hyperlinks};
pub use line::{StyledLine, StyledString, truncate_visible};
pub use suggest::{suggest_command, suggest_command_in_dir};
diff --git a/tests/integration_tests/statusline.rs b/tests/integration_tests/statusline.rs
index cf43fd134..60000bc8c 100644
--- a/tests/integration_tests/statusline.rs
+++ b/tests/integration_tests/statusline.rs
@@ -402,7 +402,7 @@ url = "http://{{ branch }}.localhost:3000"
let output = run_statusline(&repo, &[], None);
// Shows `?` because writing project config creates uncommitted file
- assert_snapshot!(output, @" main ?^| @+2 http://main.localhost:3000");
+ assert_snapshot!(output, @r" main ?^| @+2 ]8;;http://main.localhost:3000\:3000]8;;\");
}
#[rstest]
@@ -423,7 +423,7 @@ url = "http://{{ branch }}.localhost:3000"
// Run statusline from feature worktree
let output = run_statusline_from_dir(&repo, &[], None, &feature_path);
- assert_snapshot!(output, @" feature _ http://feature.localhost:3000");
+ assert_snapshot!(output, @r" feature _ ]8;;http://feature.localhost:3000\:3000]8;;\");
}
// --- JSON Format Tests ---
diff --git a/tests/snapshots/integration__integration_tests__help__help_list_long.snap b/tests/snapshots/integration__integration_tests__help__help_list_long.snap
index 62f4ff9d5..beeb1fd48 100644
--- a/tests/snapshots/integration__integration_tests__help__help_list_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_list_long.snap
@@ -24,6 +24,7 @@ info:
WORKTRUNK_TEST_GEMINI_INSTALLED: "0"
WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_PARENT_SHELL: ""
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
@@ -335,7 +336,7 @@ Item fields:
dev_server {url, listening} from the project's list.url template
summary LLM branch summary (requires [list] summary = true)
vars Per-branch variables from wt config state vars
- display Rendered strings: state (schema 1's main_state vocabulary), symbols, statusline (with ANSI colors), columns (custom-column cells keyed by header)
+ display Rendered strings: state (schema 1's main_state vocabulary), symbols, statusline (with ANSI colors and OSC 8 hyperlinks), columns (custom-column cells keyed by header)
Schema 1 names map directly: commit β†’ head, working_tree β†’
worktree.changes, main + main_state β†’ default_branch +
@@ -407,7 +408,7 @@ The original bare-array format, and the default while unset:
url string Dev server URL from project config; absent when not configured
url_active boolean Whether the URL's port is listening; absent when not configured
summary string LLM-generated branch summary; --full only, then absent when not configured or no summary
- statusline string Pre-formatted status with ANSI colors
+ statusline string Pre-formatted status with colors and links
symbols string Raw status symbols without colors (e.g., "!?↓")
vars object Per-branch variables from wt config state vars (absent when empty)
columns object Rendered custom column values keyed by header; empty cells omitted (absent when none configured)
diff --git a/tests/snapshots/integration__integration_tests__help__help_list_narrow_80.snap b/tests/snapshots/integration__integration_tests__help__help_list_narrow_80.snap
index a9df5407d..f16812cb8 100644
--- a/tests/snapshots/integration__integration_tests__help__help_list_narrow_80.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_list_narrow_80.snap
@@ -24,6 +24,7 @@ info:
WORKTRUNK_TEST_GEMINI_INSTALLED: "0"
WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_PARENT_SHELL: ""
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
@@ -420,8 +421,8 @@ Item fields:
summary LLM branch summary (requires [list] summary = true)
vars Per-branch variables from wt config state vars
display Rendered strings: state (schema 1's main_state vocabulary), symbols,
- statusline (with ANSI colors), columns (custom-column cells keyed by
- header)
+ statusline (with ANSI colors and OSC 8 hyperlinks), columns
+ (custom-column cells keyed by header)
Schema 1 names map directly: commit β†’ head, working_tree β†’
worktree.changes, main + main_state β†’ default_branch +
@@ -510,7 +511,7 @@ The original bare-array format, and the default while unset:
not configured
summary string LLM-generated branch summary; --full only, then
absent when not configured or no summary
- statusline string Pre-formatted status with ANSI colors
+ statusline string Pre-formatted status with colors and links
symbols string Raw status symbols without colors (e.g., "!?↓")
vars object Per-branch variables from wt config state vars
(absent when empty)