diff --git a/AGENTS.md b/AGENTS.md index 057f436..6b5bb18 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -459,6 +459,10 @@ and this file is for what someone changing worklane's own code needs. - Relation status mark → grey `○` backlog, orange `◐` committed, cyan `◐` reviewing, green `●` done, grey `●` discarded, grey `?` for a target the board does not hold. Discarded takes the full circle of done in the grey of the untouched pile: nothing is left to do, and it is not an achievement. The *pair* is what has to be unique, which is the same bargain the two half circles already take, and `every_status_has_a_mark` pins it against `status_dirs`. The second ramp in that column: the shape says how far the target has got and the colour tells the two middle stages apart, since both are half circles. **Green is here and deliberately absent from the priority ramp**, where it would sit on a whole line and read as a title; on a one-cell mark with no title behind it, it is the obvious colour for finished and nothing else wants it. Orange keeps the meaning it already has, Status, and grey keeps unset for the one row with no status to show - Markdown link → cyan, markers and url kept. Not a new meaning for the colour: the plan numbers, the criterion numbers and the `relates to` mark are already cyan inside a rendered body, and a link is the same kind of thing, a pointer the reader may follow rather than a value. The url is not hidden behind the text the way a renderer would hide it, because `show` prints to a terminal worklane cannot assume will make it clickable, and a link whose target cannot be read is worse than a long line - Chrome → grey. The footer's key names, a rendered `[ ]`, and the overlay's page indicator. Not a new slot: grey already means "what a reader skips", which is the other half of the unset-value meaning, and none of these is a value. The indicator in orange would read as the title it faces across the overlay, in cyan as a timestamp, and in the priority ramp's colours as a level +- Chrome → grey, in the history block too: the kind label at the head of a mechanical row, and the `From` on a comment's author line. Both name their row rather than holding a value, which is what grey already says. The label was orange, which means Status everywhere else, so an `owner` or `tags` label claimed a meaning belonging to the value beside it +- **A value in the history block takes the colour it has in the metadata table three lines above.** A status is orange, a tags entry goes through the same `tag_cells` the Tags field does, a campaign codename takes `tag_color` bare the way `Codename` does, and `_Not set_`, `_None_` and `_missing_` are grey. An owner stays plain: a person's name is the one value the palette has no meaning for, and spending a colour on the field that needs it least is how a colour stops meaning anything. The block's job is to be scanned, and it is not worth scanning if it has a palette of its own to learn first +- History actor → its name through `tag_color`, the way a campaign codename is. Not a new meaning for a reserved colour but the existing use of the tag slots, a name that groups rows: one writer is one colour in every entry it wrote, so a reader sees who has been working a ticket without reading the same name four times. `claude`, `opencode` and a person each get their own +- History timestamp → cyan, and its own span. It shared one with the actor while the two were formatted as `name (time)`, which spent the timestamp's colour on a name. The parentheses are plain: they are punctuation, not chrome with something to say - Campaign label → its codename through `tag_color`, bold, marked `~`. The colour is what groups a campaign across the cards that carry it, which is exactly what a tag's colour is for, and one word is one colour in every view because `tag_color` is a pure function of it. The mark and the bold are what tell it from a tag on a row that holds both: the mark is not `#`, or the row would read as a list of tags with a stranger in it, and not `@`, which reads as a person on every board anyone has used. `Codename` in a metadata table takes the colour without the mark, since the field name has already said what it is - Campaign label with no codename → grey. The label is then the short id, and grey keeps a reserved meaning off a `TAG_COLORS` slot in the one case where it would land on one: red is the uuid's everywhere else, and grey already means what a reader skips, which is what a campaign with no codename has to say for itself - **The palette splits in two: seven colours that each mean one thing, and `TAG_COLORS`, the eight a tag may be drawn in.** A tag in red would read as a uuid, in green as a title, in grey as an unset value, so the tag slots are reserved as a list rather than picked at the call site. Do not assign a new meaning to a colour in `TAG_COLORS`, and do not draw a tag in one outside it @@ -469,6 +473,8 @@ and this file is for what someone changing worklane's own code needs. - Grey is indexed colour 8 in the 256-colour form, not SGR 90 or 37. Both of those failed on a real palette: 90 leans on the bright-black slot and 37 can sit on top of the default foreground. `\x1b[38;5;8m` is byte for byte what crossterm emits for ratatui's `Color::DarkGray`, the grey frig and pantop use for dimmed rows ### Code Organization +- **`change` and `split_change` are a pair, and they live beside each other in `history.rs`.** The mechanical body is stored as one string, `before → after`, so painting the halves means splitting it, and the separator is a constant the writer and the reader share. A renderer with its own copy of the spacing would go on splitting on a separator the writer no longer emits, and would say so by drawing a whole body as one half. The split is `split_once`, so a value carrying the arrow itself keeps it +- **The history block indents by who is talking.** A comment's body sits at four spaces and the reason under a mechanical row at two; the author line stays at column 0 and is told from a mechanical row by its `From` and its colour instead. The rule a reader learns is that an indented line is somebody's own words and a line of values at column 0 is the tool reporting itself - **`history.rs` owns the log end to end**: the path, the kinds, the parse, the write, the count and the render. It came out of `util.rs` and `handlers.rs`, where the reader, the writer, the counter and the renderer sat in three files and one of them was 5,500 lines. The test for the reason is the module doc: a reader asking what an entry is has one file to open, the way `campaign.rs` and `tag.rs` answer their own questions - The body's painters return cells, not strings: `ordered_cells`, `inline_cells`, `metadata_cells`, `metadata_value_cells`, `tag_cells` and `push_heading`. `content_trim_colored` is the CLI entry point and `paint_cells` is the only thing that writes an escape. `colorize_line` is gone: it was a `pub` alias for the bold pass with one caller, and the only thing it added was asking the terminal - **`inline_cells` walks the line once for both inline markers**, `**bold**` and `[text](url)`, rather than running one pass over the output of the other. A second pass would be scanning text that already holds escape sequences, and `\x1b[36m` carries an opening bracket, so the link scan would take the escape for markup. The source is the only string in which either marker means what it says. It was `colorize_bold` while links lived in a branch of their own in `content_parts`; that branch is gone, which is also what gives the criteria text and the metadata `Other` rows their links, since those already went through this function diff --git a/Cargo.lock b/Cargo.lock index bd6814b..7337d0a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1503,7 +1503,7 @@ dependencies = [ [[package]] name = "worklane" -version = "0.31.2" +version = "0.31.3" dependencies = [ "anyhow", "assert_cmd", diff --git a/Cargo.toml b/Cargo.toml index 524b67a..0b77557 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "worklane" -version = "0.31.2" +version = "0.31.3" edition = "2024" [dependencies] diff --git a/assets/SKILL.md b/assets/SKILL.md index a3f868d..f27adfe 100644 --- a/assets/SKILL.md +++ b/assets/SKILL.md @@ -319,7 +319,7 @@ HISTORY status backlog → committed claude (2026-08-24 12:45:00) From claude (2026-08-24 13:10:22) - The offset was never passed to the widget. + The offset was never passed to the widget. owner _Not set_ → Ansho Rei claude (2026-08-24 13:11:04) diff --git a/src/handlers.rs b/src/handlers.rs index af6c441..a730875 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -1621,7 +1621,7 @@ pub fn cmd_assign( Some(old) => CampaignIndex::load(&worklane_dir)? .get(&old) .map(|was| was.name().to_string()) - .unwrap_or_else(|| "_missing_".to_string()), + .unwrap_or_else(|| MISSING.to_string()), }; write_entry( &worklane_dir, diff --git a/src/history.rs b/src/history.rs index a7b71b4..7f6275d 100644 --- a/src/history.rs +++ b/src/history.rs @@ -23,7 +23,10 @@ use std::path::{Path, PathBuf}; use anyhow::{Result, anyhow}; use chrono::Local; -use crate::util::{Cell, Color, TIMESTAMP_FORMAT, paint_cells, should_use_colors}; +use crate::util::{ + Cell, Color, MISSING, TIMESTAMP_FORMAT, is_unknown_value, paint_cells, should_use_colors, + tag_cells, tag_color, +}; /// Where a ticket's history lives, under the board. /// @@ -365,13 +368,32 @@ pub fn write_entry( write_new(&dir, &stem, &content) } +/// What joins the two halves of a mechanical body, and the only thing that tells them +/// apart. +/// +/// Spelled once, beside the writer that puts it in and the reader that takes it out, so +/// the two cannot disagree about where one value ends and the next begins. A renderer +/// carrying its own copy of the spacing would go on splitting on a separator this one no +/// longer writes, and would say so by drawing a whole body as one half. +const CHANGE_SEPARATOR: &str = " → "; + /// What a mechanical entry records: the field before the edit and after it. /// /// The values as the ticket holds them, sentinels included, so `_Not set_` reads the way /// the field it came from does rather than being translated into a word this module /// invented. pub fn change(before: &str, after: &str) -> String { - format!("{} → {}", before, after) + format!("{}{}{}", before, CHANGE_SEPARATOR, after) +} + +/// The before and after of a mechanical body, or `None` for a body not shaped as one. +/// +/// Everything [`change`] writes splits, but an entry read off a board is whatever the +/// file holds, and a body that does not split is drawn whole rather than as a half of +/// something. `split_once`, so a value that carries the arrow itself keeps it: only the +/// first separator is the one this module wrote. +fn split_change(body: &str) -> Option<(&str, &str)> { + body.split_once(CHANGE_SEPARATOR) } pub fn format_history(entries: &[Entry]) -> String { @@ -383,6 +405,67 @@ pub fn format_history_with(entries: &[Entry], colored: bool) -> String { paint_cells(&history_cells(entries), colored) } +/// How far the reason under a mechanical row sits from the margin. +/// +/// One step, which is where a comment's body used to sit too. It stays here because the +/// reason belongs to the row above it: it is read as part of that transition, not as an +/// entry of its own. +const REASON_INDENT: &str = " "; + +/// How far a comment's body sits from the margin. +/// +/// One step deeper than a reason, so the column says who is talking: a line indented this +/// far is somebody's own words and a line of values at column 0 is the tool reporting +/// itself. The author line stays at column 0 and is told from a mechanical row by its +/// `From` and its colour instead, which is the trade this shape accepts. +const COMMENT_INDENT: &str = " "; + +/// The cells one value in a mechanical body is drawn as, per the Color Guideline. +/// +/// Keyed on the kind, because the kind is what says which field the value came from: the +/// same word is a status in one entry and a tag in another, and nothing in the value +/// itself could tell them apart. Every meaning here is the one the value already carries +/// in the metadata table three lines above, which is the whole point — the block is not +/// worth scanning if it has a palette of its own to learn first. +fn value_cells(kind: Kind, value: &str) -> Vec { + // The sentinels first, whichever field they stand in. `_Not set_` in a tag colour + // would read as a campaign somebody named that, and grey is what an absent value is + // drawn in everywhere else. `_missing_` joins them here rather than in + // `is_unknown_value`: the field was set, and what it pointed at is gone. + if is_unknown_value(value) || value == MISSING { + return vec![Cell::colored(value, Color::Grey)]; + } + + match kind { + Kind::Status => vec![Cell::colored(value, Color::Orange)], + Kind::Tags => tag_cells(value), + // The codename in the colour that groups it everywhere else, and without the `~` + // a card's label carries: the kind at the head of the row has already said what + // this is, which is the same reason the `Codename` field takes the colour bare. + Kind::Campaign => vec![Cell::colored(value, tag_color(value))], + // A name is a value the palette has no meaning for, and spending one on the field + // that needs it least is how a colour stops meaning anything. `Comment` is here + // for the compiler: a comment's body is not a value and never reaches this. + Kind::Owner | Kind::Comment => vec![Cell::plain(value)], + } +} + +/// Who wrote an entry and when, as two spans rather than one. +/// +/// The actor through `tag_color`, the way a campaign codename is drawn. Not a new meaning +/// for a reserved colour but the existing use of the tag slots — a name that groups rows +/// — and it is what lets a reader see who has been working a ticket without reading the +/// same name four times. Cyan goes back to meaning the timestamp alone, which is what it +/// means everywhere else; it covered the name too while the two were one string. +fn stamp_cells(entry: &Entry) -> Vec { + vec![ + Cell::colored(entry.author.as_str(), tag_color(&entry.author)), + Cell::plain(" ("), + Cell::colored(entry.time.as_str(), Color::Cyan), + Cell::plain(")"), + ] +} + /// The block laid out once, as [`Cell`]s: the CLI paints them and the board turns the /// same ones into styled spans, so the two views cannot draw two different blocks. pub fn history_cells(entries: &[Entry]) -> Vec { @@ -397,15 +480,18 @@ pub fn history_cells(entries: &[Entry]) -> Vec { for entry in entries { cells.push(Cell::plain("\n")); - let stamp = format!("{} ({})", entry.author, entry.time); match entry.kind { // As it has always read: a header naming who said it, then the text. Kind::Comment => { - cells.push(Cell::colored(format!("From {}", stamp), Color::Cyan)); + // Grey on the word, for the reason the kind label is grey: `From` names + // the line, it is not a value in it. + cells.push(Cell::colored("From", Color::Grey)); + cells.push(Cell::plain(" ")); + cells.extend(stamp_cells(entry)); cells.push(Cell::plain("\n")); if !entry.body.is_empty() { - cells.push(Cell::plain(format!(" {}", entry.body))); + cells.push(Cell::plain(format!("{}{}", COMMENT_INDENT, entry.body))); } cells.push(Cell::plain("\n")); } @@ -415,14 +501,31 @@ pub fn history_cells(entries: &[Entry]) -> Vec { // attached to the transition it explains rather than as the next entry. _ => { let padding = Kind::LABEL_WIDTH.saturating_sub(entry.kind.slug().chars().count()); - cells.push(Cell::colored(entry.kind.slug(), Color::Orange)); + // Grey, as chrome. It was orange, which means Status everywhere else, so + // an `owner` or `tags` label claimed a meaning belonging to the value + // beside it. The label is not a value at all: it names the row, which is + // what grey already says. + cells.push(Cell::colored(entry.kind.slug(), Color::Grey)); + // Measured on the unpainted label and carried in a cell of its own, the + // rule the metadata table follows: measuring a painted string counts its + // escapes towards its width, which tilts the column when colour is on and + // not when it is off. cells.push(Cell::plain(format!("{} ", " ".repeat(padding)))); - cells.push(Cell::plain(entry.body.clone())); + + match split_change(&entry.body) { + Some((before, after)) => { + cells.extend(value_cells(entry.kind, before)); + cells.push(Cell::plain(CHANGE_SEPARATOR)); + cells.extend(value_cells(entry.kind, after)); + } + None => cells.extend(value_cells(entry.kind, &entry.body)), + } + cells.push(Cell::plain(" ")); - cells.push(Cell::colored(stamp, Color::Cyan)); + cells.extend(stamp_cells(entry)); cells.push(Cell::plain("\n")); if !entry.reason.is_empty() { - cells.push(Cell::plain(format!(" {}", entry.reason))); + cells.push(Cell::plain(format!("{}{}", REASON_INDENT, entry.reason))); cells.push(Cell::plain("\n")); } } @@ -435,7 +538,32 @@ pub fn history_cells(entries: &[Entry]) -> Vec { #[cfg(test)] mod tests { use super::*; - use crate::util::{Fixture, paint}; + use crate::util::{Fixture, NOT_SET, paint}; + + /// One entry, spelled the way a file on the board holds it. + fn entry(kind: &str, body: &str, author: &str, time: &str) -> Entry { + let marker = format!("**{}{}**", kind[..1].to_uppercase(), &kind[1..]); + parse_entry( + &format!("20260824_120000_000000_{kind}"), + &format!("{marker}\n{body}\n\n**Author**: {author}\n**Time**: {time}\n"), + ) + } + + /// What a painted block reads as once the escapes are taken off, so a test can + /// measure a column without counting sequences that occupy none. + fn strip_escapes(text: &str) -> String { + let mut out = String::with_capacity(text.len()); + let mut rest = text; + while let Some(at) = rest.find('\x1b') { + out.push_str(&rest[..at]); + match rest[at..].find('m') { + Some(end) => rest = &rest[at + end + 1..], + None => return out, + } + } + out.push_str(rest); + out + } fn board() -> Fixture { Fixture::new("worklane-history") @@ -619,71 +747,137 @@ mod tests { assert_eq!(kind_from_stem("20260820_143012_123456_status_01"), Kind::Status); } + /// The other half of the pair below: with colour off the block is words and spaces, + /// and the flag is the only thing that decides. A renderer that painted regardless + /// would pass the pin and fail here. #[test] - fn a_mechanical_entry_renders_as_one_line_and_a_comment_as_it_did() { + fn a_mechanical_entry_renders_as_one_line_and_a_comment_under_its_author() { let entries = vec![ - parse_entry( - "20260824_120000_000000_status", - "**Status**\ncommitted → reviewing\n\n**Author**: claude\n**Time**: 2026-08-24 12:00:00\n", - ), - parse_entry( - "20260824_120001_000000_comment", - "**Comment**\nThe offset was never passed\n\n**Author**: Ansho Rei\n**Time**: 2026-08-24 12:00:01\n", + entry("status", "committed → reviewing", "claude", "2026-08-24 12:00:00"), + entry("owner", "_Not set_ → alice", "claude", "2026-08-24 12:00:01"), + entry("tags", "bug → bug, cli", "claude", "2026-08-24 12:00:02"), + entry("campaign", "_Not set_ → v1", "claude", "2026-08-24 12:00:03"), + entry( + "comment", + "The offset was never passed", + "Ansho Rei", + "2026-08-24 12:00:04", ), ]; let rendered = format_history_with(&entries, false); assert!(rendered.contains("HISTORY"), "{rendered}"); - assert!( - rendered.contains("status committed → reviewing claude (2026-08-24 12:00:00)\n"), - "{rendered}" - ); + for row in [ + "status committed → reviewing claude (2026-08-24 12:00:00)\n", + "owner _Not set_ → alice claude (2026-08-24 12:00:01)\n", + "tags bug → bug, cli claude (2026-08-24 12:00:02)\n", + "campaign _Not set_ → v1 claude (2026-08-24 12:00:03)\n", + ] { + assert!(rendered.contains(row), "missing {row:?} in {rendered}"); + } + // The body sits a step deeper than a reason does, and the author line did not move assert!( rendered - .contains("From Ansho Rei (2026-08-24 12:00:01)\n The offset was never passed"), + .contains("From Ansho Rei (2026-08-24 12:00:04)\n The offset was never passed"), "{rendered}" ); assert!(!rendered.contains('\x1b'), "colour off still painted: {rendered:?}"); } - /// The pin for the cells conversion: `show` prints the block exactly as it printed - /// it before, every painted run spelled out, the way - /// `show_prints_the_same_body_it_printed_before_the_cells_conversion` pins the body. + /// The pin: `show` prints the block byte for byte, every painted run spelled out, the + /// way `show_prints_the_same_body_it_printed_before_the_cells_conversion` pins the + /// body. /// - /// Updated once since, deliberately: `campaign` widened the label column from 6 to - /// 8, and the campaign row itself joined the pin (f774a33). + /// Rewritten twice, deliberately. `campaign` widened the label column from 6 to 8 and + /// put its own row in the pin (f774a33). Then 2733b10 painted the values: the label + /// went grey as chrome, each value took the meaning it carries in the metadata table, + /// and the actor and the timestamp came apart into two spans. + /// + /// Every kind is here rather than a representative one, since what each row proves is + /// different: status is the orange it is three lines above, tags go through the same + /// `tag_cells` the Tags field does, campaign takes its codename's colour, owner is the + /// one value the palette says nothing about, and the sentinel in the owner row is grey + /// on the same side of an arrow whose other side is not. #[test] - fn show_prints_the_same_history_it_printed_before_the_cells_conversion() { + fn colour_on_paints_every_value_by_what_the_kind_says_it_is() { let entries = vec![ - parse_entry( - "20260824_120000_000000_status", - "**Status**\ncommitted → reviewing\n\n**Author**: claude\n**Time**: 2026-08-24 12:00:00\n", - ), - parse_entry( - "20260824_120001_000000_comment", - "**Comment**\nThe offset was never passed\n\n**Author**: Ansho Rei\n**Time**: 2026-08-24 12:00:01\n", - ), - parse_entry( - "20260824_120002_000000_campaign", - "**Campaign**\n_Not set_ → v1\n\n**Author**: claude\n**Time**: 2026-08-24 12:00:02\n", + entry("status", "committed → reviewing", "claude", "2026-08-24 12:00:00"), + entry( + "comment", + "The offset was never passed", + "Ansho Rei", + "2026-08-24 12:00:01", ), + entry("campaign", "_Not set_ → v1", "claude", "2026-08-24 12:00:02"), + entry("owner", "_Not set_ → alice", "claude", "2026-08-24 12:00:03"), + entry("tags", "bug → bug, cli", "claude", "2026-08-24 12:00:04"), ]; + let stamp = |actor: &str, time: &str| { + format!( + "{} ({})", + paint(actor, tag_color(actor), true), + paint(time, Color::Cyan, true) + ) + }; let expected = format!( - "\n{}\n{}\n\n{} committed → reviewing {}\n\n{}\n The offset was never passed\n\n{} _Not set_ → v1 {}\n", + "\n{}\n{}\n\n{} {} → {} {}\n\n{} {}\n The offset was never passed\n\n{} {} → {} {}\n\n{} {} → alice {}\n\n{} {} → {}, {} {}\n", paint("HISTORY", Color::Orange, true), "─".repeat(20), - paint("status", Color::Orange, true), - paint("claude (2026-08-24 12:00:00)", Color::Cyan, true), - paint("From Ansho Rei (2026-08-24 12:00:01)", Color::Cyan, true), - paint("campaign", Color::Orange, true), - paint("claude (2026-08-24 12:00:02)", Color::Cyan, true), + paint("status", Color::Grey, true), + paint("committed", Color::Orange, true), + paint("reviewing", Color::Orange, true), + stamp("claude", "2026-08-24 12:00:00"), + paint("From", Color::Grey, true), + stamp("Ansho Rei", "2026-08-24 12:00:01"), + paint("campaign", Color::Grey, true), + paint(NOT_SET, Color::Grey, true), + paint("v1", tag_color("v1"), true), + stamp("claude", "2026-08-24 12:00:02"), + paint("owner", Color::Grey, true), + paint(NOT_SET, Color::Grey, true), + stamp("claude", "2026-08-24 12:00:03"), + paint("tags", Color::Grey, true), + paint("bug", tag_color("bug"), true), + paint("bug", tag_color("bug"), true), + paint("cli", tag_color("cli"), true), + stamp("claude", "2026-08-24 12:00:04"), ); assert_eq!(format_history_with(&entries, true), expected); assert_eq!(format_history_with(&[], true), paint("No history yet.", Color::Grey, true)); } + /// The actor groups its rows: one writer is one colour wherever it wrote, and it is + /// not the timestamp's. Asserted through `tag_color` rather than against a literal, + /// so the row has to use the mapping and not a colour that happens to match it today. + #[test] + fn the_actor_is_one_colour_in_every_entry_and_the_timestamp_keeps_cyan() { + let entries = vec![ + entry("status", "backlog → committed", "claude", "2026-08-24 12:00:00"), + entry("comment", "Said something", "claude", "2026-08-24 12:00:01"), + entry("owner", "_Not set_ → alice", "Ansho Rei", "2026-08-24 12:00:02"), + ]; + + let rendered = format_history_with(&entries, true); + let painted = paint("claude", tag_color("claude"), true); + assert_eq!(rendered.matches(&painted).count(), 2, "{rendered}"); + assert!( + rendered.contains(&paint("Ansho Rei", tag_color("Ansho Rei"), true)), + "{rendered}" + ); + // Two writers, two colours, and neither of them cyan: that is the timestamp's + assert_ne!(tag_color("claude"), tag_color("Ansho Rei")); + for time in [ + "2026-08-24 12:00:00", + "2026-08-24 12:00:01", + "2026-08-24 12:00:02", + ] { + assert!(rendered.contains(&paint(time, Color::Cyan, true)), "{rendered}"); + } + assert!(!rendered.contains(&paint("claude (", Color::Cyan, true)), "still one span"); + } + /// The reason is the row's, so it renders indented under the row it explains and /// before whatever entry follows, in both renderers — this is the one layout they /// share. Paired with the pin above: an entry without a reason renders exactly as @@ -696,19 +890,21 @@ mod tests { "**Status**\nreviewing → backlog\n\n**Author**: claude\n**Time**: 2026-08-24 \ 12:00:00\n**Reason**: sent back, the first plan was wrong\n", ), - parse_entry( - "20260824_120001_000000_comment", - "**Comment**\nAnd why.\n\n**Author**: Ansho Rei\n**Time**: 2026-08-24 12:00:01\n", - ), + entry("comment", "And why.", "Ansho Rei", "2026-08-24 12:00:01"), ]; let expected = format!( - "\n{}\n{}\n\n{} reviewing → backlog {}\n sent back, the first plan was wrong\n\n{}\n And why.\n", + "\n{}\n{}\n\n{} {} → {} {} ({})\n sent back, the first plan was wrong\n\n{} {} ({})\n And why.\n", paint("HISTORY", Color::Orange, true), "─".repeat(20), - paint("status", Color::Orange, true), - paint("claude (2026-08-24 12:00:00)", Color::Cyan, true), - paint("From Ansho Rei (2026-08-24 12:00:01)", Color::Cyan, true), + paint("status", Color::Grey, true), + paint("reviewing", Color::Orange, true), + paint("backlog", Color::Orange, true), + paint("claude", tag_color("claude"), true), + paint("2026-08-24 12:00:00", Color::Cyan, true), + paint("From", Color::Grey, true), + paint("Ansho Rei", tag_color("Ansho Rei"), true), + paint("2026-08-24 12:00:01", Color::Cyan, true), ); assert_eq!(format_history_with(&entries, true), expected); @@ -722,8 +918,14 @@ mod tests { /// Padded to the longest of the four, so every body starts in the same column /// however short the label above it is. + /// + /// Run both ways, which is the whole point of the pairing: the padding is measured on + /// the unpainted label and carried in a cell of its own, so the column a value lands + /// in cannot depend on the colour decision. Measuring a painted label would count its + /// escapes towards its width and tilt the table with colour on and not with it off, + /// which is exactly the bug the metadata table already learned. #[test] - fn the_mechanical_labels_are_aligned() { + fn the_mechanical_labels_are_aligned_with_colour_on_and_off() { let bodies = [ ("status", "backlog → committed"), ("owner", "_Not set_ → alice"), @@ -732,28 +934,27 @@ mod tests { ]; let entries: Vec = bodies .into_iter() - .map(|(kind, body)| { - let marker = format!("**{}{}**", kind[..1].to_uppercase(), &kind[1..]); - parse_entry( - &format!("20260824_120000_000000_{kind}"), - &format!( - "{marker}\n{body}\n\n**Author**: claude\n**Time**: 2026-08-24 12:00:00\n" - ), - ) - }) + .map(|(kind, body)| entry(kind, body, "claude", "2026-08-24 12:00:00")) .collect(); - let rendered = format_history_with(&entries, false); - let columns: Vec = bodies - .into_iter() - .map(|(_, body)| rendered.find(body).expect("body missing")) - .map(|at| { - let line_start = rendered[..at].rfind('\n').map_or(0, |nl| nl + 1); - at - line_start - }) - .collect(); - assert_eq!(columns.len(), 4); - assert!(columns.windows(2).all(|pair| pair[0] == pair[1]), "{rendered}"); + let columns = |colored: bool| -> Vec { + // Stripped before it is measured, so an escape counts for the nothing it + // occupies on screen and the two renderings are compared on what a reader sees + let rendered = strip_escapes(&format_history_with(&entries, colored)); + bodies + .into_iter() + .map(|(_, body)| rendered.find(body).expect("body missing")) + .map(|at| { + let line_start = rendered[..at].rfind('\n').map_or(0, |nl| nl + 1); + at - line_start + }) + .collect() + }; + + let plain = columns(false); + assert_eq!(plain.len(), 4); + assert!(plain.windows(2).all(|pair| pair[0] == pair[1]), "{plain:?}"); + assert_eq!(columns(true), plain, "the colour decision moved the column"); } #[test] diff --git a/src/tui.rs b/src/tui.rs index 54b7898..ebc1987 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -5120,6 +5120,11 @@ mod tests { /// /// Paired the way the guideline demands: a renderer that dropped every colour would /// pass the no-escape half, so the presence is asserted beside it. + /// + /// The spans it looks for are 2733b10's: the label went grey as chrome, the values + /// took the meanings they carry in the metadata table, and the actor came away from + /// the timestamp so a name is one colour and cyan is the stamp's alone. Asserted on + /// the board as well as in `show`, because these are the cells both render. #[test] fn the_history_block_is_styled_in_the_overlay_and_no_escape_reached_it() { let dir = board_dir(); @@ -5147,17 +5152,16 @@ mod tests { assert_eq!(span_color(&heading, "HISTORY"), Some(Color::Orange.into())); let from = body_line(detail, "From bob"); - assert_eq!( - span_color(&from, "From bob (2026-08-21 12:00:01)"), - Some(Color::Cyan.into()) - ); + assert_eq!(span_color(&from, "From"), Some(Color::Grey.into())); + assert_eq!(span_color(&from, "bob"), Some(tag_color("bob").into())); + assert_eq!(span_color(&from, "2026-08-21 12:00:01"), Some(Color::Cyan.into())); let change = body_line(detail, "backlog → committed"); - assert_eq!(span_color(&change, "status"), Some(Color::Orange.into())); - assert_eq!( - span_color(&change, "claude (2026-08-21 12:00:00)"), - Some(Color::Cyan.into()) - ); + assert_eq!(span_color(&change, "status"), Some(Color::Grey.into())); + assert_eq!(span_color(&change, "backlog"), Some(Color::Orange.into())); + assert_eq!(span_color(&change, "committed"), Some(Color::Orange.into())); + assert_eq!(span_color(&change, "claude"), Some(tag_color("claude").into())); + assert_eq!(span_color(&change, "2026-08-21 12:00:00"), Some(Color::Cyan.into())); // The other half: the colour arrived as styles, not as bytes. assert!( diff --git a/src/util.rs b/src/util.rs index 49e0300..a223587 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1006,7 +1006,11 @@ fn metadata_value_cells(name: &str, value: &str, campaign: &[Cell]) -> Vec /// holds come back unchanged. `bug, cli` and `bug,cli` are both written by hand at some /// point, and a cell that normalised them would be the display quietly disagreeing with /// the file it is showing. -fn tag_cells(value: &str) -> Vec { +/// +/// Shared with the history block, which draws the two halves of a tags entry through it: +/// a tag list is a tag list wherever it is printed, and the alternative was a second +/// splitter that would drift from this one the first time either changed. +pub(crate) fn tag_cells(value: &str) -> Vec { let mut cells = Vec::new(); for (index, piece) in value.split(',').enumerate() { @@ -1091,6 +1095,15 @@ pub const NOT_SET: &str = "_Not set_"; /// distinction `add` already makes and clearing has to keep. pub const NONE: &str = "_None_"; +/// What stands in for something the board no longer holds. +/// +/// Not an unset value, so [`is_unknown_value`] does not read it: a field pointing at a +/// campaign that has been removed is set, and what it is set to is gone. Drawn in the +/// same grey all the same, which is what it shares with an unset value and why the +/// spelling is a constant — the relations block writes it, `assign` records it in a +/// history entry, and the two have to be the same word for the third place to paint it. +pub const MISSING: &str = "_missing_"; + /// Whether a field holds one of the two markers that mean it holds nothing. /// /// The two constants and nothing else. `-None-` and `-Not set-` were accepted here from @@ -2247,7 +2260,7 @@ pub fn reference_cells(uuid: &str, name: Option<&str>) -> Vec { match name { Some(name) => cells.push(Cell::plain(name)), - None => cells.push(Cell::colored("_missing_", Color::Grey)), + None => cells.push(Cell::colored(MISSING, Color::Grey)), } cells