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 {