(2733b10) Colour the history block, and indent a comment's body deeper, and bump to 0.31.3
The block shipped with three painted things: the heading, the kind label and the actor with its timestamp as one cyan span. Every value in it was plain, so a status entry drew two status names in no colour while the same names are orange in the metadata table three lines above, and a tags entry drew its tags without the slots every other view gives them. The kind label is now grey, as chrome that names a row. It was orange, which means Status everywhere else, so an `owner` or `tags` label claimed a meaning belonging to the value beside it. `From` on a comment's author line goes grey for the same reason. Each value takes the meaning its field carries in the metadata table: status orange, tags through the same `tag_cells` the Tags field uses, a campaign codename through `tag_color` bare the way `Codename` is, an owner plain, and `_Not set_`, `_None_` and `_missing_` grey. The separator is a constant beside `change`, with `split_change` next to it, so the writer and the reader cannot disagree about what divides the two halves. The actor is drawn through `tag_color`, so one writer is one colour in every entry it wrote, and cyan goes back to meaning the timestamp alone. A comment's body moves to four spaces and the author line stays at column 0, so an indented line is somebody's own words and a line of values at column 0 is the tool reporting itself. The padding is still measured on the unpainted label, now pinned with the alignment test running both ways. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
ab337ca7f8
commit
45b513bdce
+276
-75
@@ -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<Cell> {
|
||||
// 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<Cell> {
|
||||
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<Cell> {
|
||||
@@ -397,15 +480,18 @@ pub fn history_cells(entries: &[Entry]) -> Vec<Cell> {
|
||||
|
||||
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<Cell> {
|
||||
// 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<Cell> {
|
||||
#[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<Entry> = 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<usize> = 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<usize> {
|
||||
// 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]
|
||||
|
||||
Reference in New Issue
Block a user