(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) <noreply@anthropic.com>
This commit is contained in:
Ansho Rei
2026-08-20 17:11:43 +02:00
co-authored by Claude Opus 5
parent ab1dae098c
commit 8b440593e2
2 changed files with 25 additions and 4 deletions
+2 -1
View File
@@ -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_" {
+23 -3
View File
@@ -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 {