From 8b440593e232a68314c142fff3f1e01a658cbd8f Mon Sep 17 00:00:00 2001 From: Ansho Rei Date: Thu, 20 Aug 2026 17:11:43 +0200 Subject: [PATCH] (594c741) Measure heading rules on the displayed name Section rules repeated the character for the byte length of the whole heading line, so every rule ran three past its heading for the "## " prefix. The title rule in cmd_show used byte length, which over-draws for a non-ASCII title. Both now count characters of the text as displayed. Co-Authored-By: Claude Opus 5 (1M context) --- src/handlers.rs | 3 ++- src/util.rs | 26 +++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/handlers.rs b/src/handlers.rs index 0f15b28..13724ec 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -295,7 +295,8 @@ pub fn cmd_show(search: &str, worklane_dir: &Path) -> Result<()> { let ticket_uuid = parse_ticket_field(&content, "ID"); println!("{}", title); - println!("{}", "─".repeat(title.len())); + // In characters, so a non-ASCII title is not over-drawn. + println!("{}", "─".repeat(title.chars().count())); println!("\n{}", content_trim_colored(&content)); if ticket_uuid != "_Not set_" { diff --git a/src/util.rs b/src/util.rs index b267dd9..1796bca 100644 --- a/src/util.rs +++ b/src/util.rs @@ -256,12 +256,14 @@ pub fn content_trim_colored(content: &str) -> String { for line in &lines { // Track current section - if line.starts_with("## ") { + if let Some(section_name) = line.strip_prefix("## ") { current_section = line; - let section_name = &line[3..]; result.push_str(&color_text(section_name, "orange")); result.push('\n'); - result.push_str(&"─".repeat(line.len())); + // Measured on the name as displayed, in characters. The rule used to span + // the raw line, so it ran three past the heading for the "## ", and byte + // length over-drew for anything non-ASCII. + result.push_str(&"─".repeat(section_name.chars().count())); result.push('\n'); result.push('\n'); continue; @@ -839,6 +841,24 @@ mod tests { assert!(set_status_field(content, "committed", "T").is_err()); } + #[test] + fn a_section_rule_matches_the_width_of_its_name() { + let rendered = content_trim_colored("# T\n\n## Description\nbody\n"); + + // Eleven characters, not fourteen: the rule used to span "## Description" + assert!( + rendered.contains("Description\n───────────\n"), + "{rendered:?}" + ); + } + + #[test] + fn a_non_ascii_section_name_is_not_over_drawn() { + let rendered = content_trim_colored("# T\n\n## Résumé\nbody\n"); + + assert!(rendered.contains("Résumé\n──────\n"), "{rendered:?}"); + } + #[test] fn a_level_in_range_parses() { for level in 1..=5u8 {