Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Refactor CI indicator formatting with link control option
Maximilian Roos2fae19356457
diff --git a/src/commands/list/ci_status.rs b/src/commands/list/ci_status.rsindex da3e83fac..ee3ef1374 100644--- a/src/commands/list/ci_status.rs+++ b/src/commands/list/ci_status.rs@@ -430,6 +430,36 @@ mod tests {assert!(formatted.contains("●"), "Should contain indicator");}+ #[test]+ fn test_format_indicator_with_options_skips_link() {+ // When include_link=false, should not include OSC 8 even when URL is present+ let pr_with_url = PrStatus {+ ci_status: CiStatus::Passed,+ source: CiSource::PullRequest,+ is_stale: false,+ url: Some("https://github.com/owner/repo/pull/123".to_string()),+ };++ let with_link = pr_with_url.format_indicator_with_options(true);+ let without_link = pr_with_url.format_indicator_with_options(false);++ // With link should contain OSC 8+ assert!(+ with_link.contains("\x1b]8;;"),+ "include_link=true should contain OSC 8"+ );++ // Without link should NOT contain OSC 8+ assert!(+ !without_link.contains("\x1b]8;;"),+ "include_link=false should not contain OSC 8"+ );++ // Both should contain the indicator+ assert!(with_link.contains("●"), "Should contain indicator");+ assert!(without_link.contains("●"), "Should contain indicator");+ }+#[test]fn test_pr_status_error_constructor() {let error = PrStatus::error();@@ -1280,13 +1310,22 @@ impl PrStatus {}}- /// Format CI status as a colored indicator.+ /// Format CI status as a colored indicator with clickable link.////// Returns a string like "●" with appropriate ANSI color./// If a PR URL is available, adds underline and wraps in an OSC 8 hyperlink.pub fn format_indicator(&self) -> String {+ self.format_indicator_with_options(true)+ }++ /// Format CI status with control over link inclusion.+ ///+ /// When `include_link` is false, the indicator is colored but not clickable.+ /// Used for environments that don't support OSC 8 hyperlinks (e.g., Claude Code).+ pub fn format_indicator_with_options(&self, include_link: bool) -> String {let indicator = self.indicator();- if let Some(ref url) = self.url {+ if include_link && self.url.is_some() {+ let url = self.url.as_ref().unwrap();let style = self.style().underline();format!("{}{}{}{}{}",diff --git a/src/commands/list/model.rs b/src/commands/list/model.rsindex 13e12572c..6162af6b2 100644--- a/src/commands/list/model.rs+++ b/src/commands/list/model.rs@@ -369,11 +369,19 @@ impl ListItem {self.is_potentially_removable() == Some(true)}- /// Format this item as a single-line statusline string.+ /// Format this item as a single-line statusline string with clickable links.////// 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 {let mut parts: Vec<String> = Vec::new();// 1. Branch name@@ -426,7 +434,7 @@ impl ListItem {// 7. CI statusif let Some(Some(ref pr_status)) = self.pr_status {- parts.push(pr_status.format_indicator());+ parts.push(pr_status.format_indicator_with_options(include_links));}parts.join(" ")diff --git a/src/commands/statusline.rs b/src/commands/statusline.rsindex d0f3233fe..95967f20c 100644--- a/src/commands/statusline.rs+++ b/src/commands/statusline.rs@@ -154,10 +154,10 @@ pub fn run(claude_code: bool) -> Result<()> {None};- // Git status+ // Git status (skip links in claude-code mode - OSC 8 not supported)let repo = Repository::at(&cwd);if repo.git_dir().is_ok()- && let Some(status_line) = get_git_status(&repo, &cwd)?+ && let Some(status_line) = get_git_status(&repo, &cwd, !claude_code)?{// In claude-code mode, skip branch name if directory matches worktrunk template// TODO: Use actual configured template from config instead of hardcoding ".{branch}"@@ -207,7 +207,9 @@ pub fn run(claude_code: bool) -> Result<()> {}/// Get git status line for the current worktree-fn get_git_status(repo: &Repository, cwd: &Path) -> Result<Option<String>> {+///+/// When `include_links` is true, CI status includes clickable OSC 8 hyperlinks.+fn get_git_status(repo: &Repository, cwd: &Path, include_links: bool) -> Result<Option<String>> {// Get current worktree infolet worktrees = repo.list_worktrees()?;let current_worktree = worktrees.iter().find(|wt| cwd.starts_with(&wt.path));@@ -252,12 +254,13 @@ fn get_git_status(repo: &Repository, cwd: &Path) -> Result<Option<String>> {CollectOptions::default(),)?;- // Return the pre-formatted statusline- if let Some(ref statusline) = item.display.statusline {- Ok(Some(statusline.clone()))- } else {+ // Format statusline with link control+ let statusline = item.format_statusline_with_options(include_links);+ if statusline.is_empty() {// Fallback: just show branch nameOk(Some(wt.branch.as_deref().unwrap_or("HEAD").to_string()))+ } else {+ Ok(Some(statusline))}}