From 75e9ea230908ea5f285e99518e54a23f3e9e5e25 Mon Sep 17 00:00:00 2001 From: Ansho Rei Date: Fri, 15 May 2026 17:21:20 +0200 Subject: [PATCH] (1240895) Add colour to disambiguation --- src/util.rs | 25 +++++++++++++++++-------- tests/cmd_show.rs | 3 +++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/util.rs b/src/util.rs index 40c0a7e..c1d0a65 100644 --- a/src/util.rs +++ b/src/util.rs @@ -72,7 +72,7 @@ pub fn get_git_user() -> Option { } pub fn resolve_ticket(search: &str, worklane_dir: &Path) -> Result<(String, String, String)> { let statuses = status_dirs(); - let mut matches: Vec<(String, String, String)> = Vec::new(); + let mut matches: Vec<(String, String, String, String)> = Vec::new(); for status in &statuses { let status_path = worklane_dir.join(status); @@ -99,18 +99,19 @@ pub fn resolve_ticket(search: &str, worklane_dir: &Path) -> Result<(String, Stri .file_stem() .map(|s| s.to_string_lossy().to_string()) .unwrap_or_default(); - let id = filename.split('_').next().unwrap_or(""); + let short_id = filename.split('_').next().unwrap_or(""); let search_lower = search.to_lowercase(); let title_lower = title.to_lowercase(); let filename_lower = filename.to_lowercase(); - let id_match = id.to_lowercase().starts_with(&search_lower) && id.len() >= 8; + let id_match = + short_id.to_lowercase().starts_with(&search_lower) && short_id.len() >= 8; let title_match = title_lower.contains(&search_lower); let filename_match = filename_lower.contains(&search_lower); if id_match || title_match || filename_match { - matches.push((status.to_string(), title, content)); + matches.push((status.to_string(), title, content, short_id.to_string())); } } } @@ -121,14 +122,22 @@ pub fn resolve_ticket(search: &str, worklane_dir: &Path) -> Result<(String, Stri if matches.len() > 1 { println!("Multiple tickets found matching '{}':", search); - for (i, (status, title, _)) in matches.iter().enumerate() { - println!(" {}. {} ({})", i + 1, title, status); + for (i, (status, title, _, short_id)) in matches.iter().enumerate() { + let display_id = &short_id[..7]; + println!( + " {}. ({}) {} [{}]", + i + 1, + color_text(display_id, "red"), + title, + color_text(status, "orange"), + ); } - println!("\nTry a more specific search term."); + println!("\nUse the displayed ID or a more specific search term to select."); std::process::exit(1); } - Ok(matches.remove(0)) + let (status, title, content, _short_id) = matches.remove(0); + Ok((status, title, content)) } pub fn format_comments(comments: &[(String, String, String, String)]) -> String { if comments.is_empty() { diff --git a/tests/cmd_show.rs b/tests/cmd_show.rs index c80a61c..48c524c 100644 --- a/tests/cmd_show.rs +++ b/tests/cmd_show.rs @@ -260,6 +260,9 @@ fn show_asks_for_disambiguation_when_multiple_matches() { assert!(stdout.contains("Multiple tickets found")); assert!(stdout.contains("Test Ticket A")); assert!(stdout.contains("Test Ticket B")); + assert!(stdout.contains("abc123d")); + assert!(stdout.contains("fedcba0")); + assert!(stdout.contains("Use the displayed ID")); } #[test]