(d447e04) Render each comment behind a grey bar spanning its length, and bump to 0.32.3
This commit is contained in:
+164
-35
@@ -402,23 +402,55 @@ pub fn format_history(entries: &[Entry]) -> String {
|
||||
|
||||
/// As above, with the colour decision passed in.
|
||||
pub fn format_history_with(entries: &[Entry], colored: bool) -> String {
|
||||
paint_cells(&history_cells(entries), colored)
|
||||
paint_cells(&history_cells(entries, colored), colored)
|
||||
}
|
||||
|
||||
/// How far the reason under a mechanical row sits from the margin.
|
||||
/// The bar every line of a comment and of a reason draws behind, the way quoted text is
|
||||
/// drawn.
|
||||
///
|
||||
/// 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 = " ";
|
||||
/// Box-drawing vertical, the family the rule under HISTORY is already rendered from, so
|
||||
/// it shows wherever that does. One cell wide, grey, and clear of the two vocabularies
|
||||
/// it sits among: the priority meter owns the circles and the dot and the relation rows
|
||||
/// own the cross and the arrows, so nothing here may read as a level or as an edge.
|
||||
/// Grey is the colour the kind label carries, which names its row rather than holding a
|
||||
/// value — what a quote bar does. `the_quote_bar_claims_no_glyph_another_column_means`
|
||||
/// pins all three properties against the marks actually defined.
|
||||
const QUOTE_BAR: &str = "\u{2502}";
|
||||
|
||||
/// How far a comment's body sits from the margin.
|
||||
/// One run of text behind [`QUOTE_BAR`], every line of it.
|
||||
///
|
||||
/// 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 bar spans the whole run rather than prefixing its first line, which is the
|
||||
/// difference between a quote and an indentation: a multi-paragraph comment reads as one
|
||||
/// voice start to finish, paragraph breaks included, instead of resuming halfway through
|
||||
/// at column 0 — the column a line of values owns, which a single prefix handed back on
|
||||
/// every line after the first. With colour off the glyph goes but the width it occupied
|
||||
/// stays, as plain spaces derived from the drawn form rather than spelled beside it, so
|
||||
/// a piped `show` keeps every line at the same column without carrying an escape byte.
|
||||
/// One builder for both renderers, the board passing `true`: neither can draw a block
|
||||
/// the other does not.
|
||||
fn quoted_cells(body: &str, colored: bool) -> Vec<Cell> {
|
||||
let bar = format!("{QUOTE_BAR} ");
|
||||
let indent = " ".repeat(bar.chars().count());
|
||||
|
||||
let mut cells = Vec::new();
|
||||
for (at, line) in body.split('\n').enumerate() {
|
||||
if at > 0 {
|
||||
cells.push(Cell::plain("\n"));
|
||||
}
|
||||
match (colored, line.is_empty()) {
|
||||
// A paragraph break draws the bar alone rather than carrying a gap into
|
||||
// nothing, which is what keeps it visibly inside the run.
|
||||
(true, true) => cells.push(Cell::colored(QUOTE_BAR, Color::Grey)),
|
||||
(true, false) => {
|
||||
cells.push(Cell::colored(&bar, Color::Grey));
|
||||
cells.push(Cell::plain(line));
|
||||
}
|
||||
(false, false) => cells.push(Cell::plain(format!("{indent}{line}"))),
|
||||
(false, true) => {}
|
||||
}
|
||||
}
|
||||
cells
|
||||
}
|
||||
|
||||
/// The cells one value in a mechanical body is drawn as, per the Color Guideline.
|
||||
///
|
||||
@@ -468,7 +500,12 @@ fn stamp_cells(entry: &Entry) -> Vec<Cell> {
|
||||
|
||||
/// 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> {
|
||||
///
|
||||
/// The colour decision rides in because the quote bar is a coloured decoration: with it
|
||||
/// off the cells carry the indent the bar would have provided, and no renderer has to
|
||||
/// guess at that. `format_history_with` passes the CLI's decision and the board passes
|
||||
/// `true`.
|
||||
pub fn history_cells(entries: &[Entry], colored: bool) -> Vec<Cell> {
|
||||
if entries.is_empty() {
|
||||
return vec![Cell::colored("No history yet.", Color::Grey)];
|
||||
}
|
||||
@@ -491,14 +528,14 @@ pub fn history_cells(entries: &[Entry]) -> Vec<Cell> {
|
||||
cells.extend(stamp_cells(entry));
|
||||
cells.push(Cell::plain("\n"));
|
||||
if !entry.body.is_empty() {
|
||||
cells.push(Cell::plain(format!("{}{}", COMMENT_INDENT, entry.body)));
|
||||
cells.extend(quoted_cells(&entry.body, colored));
|
||||
}
|
||||
cells.push(Cell::plain("\n"));
|
||||
}
|
||||
// One line: a field change is one fact and a paragraph for it would bury the
|
||||
// comments it sits between. A reason grows an indented line under the row,
|
||||
// the way a comment's text sits under its From header, so it reads as
|
||||
// attached to the transition it explains rather than as the next entry.
|
||||
// comments it sits between. A reason draws behind the same bar the comments
|
||||
// draw, since it shares their shape and their gap, so it reads as attached
|
||||
// to the transition it explains rather than as the next entry.
|
||||
_ => {
|
||||
let padding = Kind::LABEL_WIDTH.saturating_sub(entry.kind.slug().chars().count());
|
||||
// Grey, as chrome. It was orange, which means Status everywhere else, so
|
||||
@@ -525,7 +562,7 @@ pub fn history_cells(entries: &[Entry]) -> Vec<Cell> {
|
||||
cells.extend(stamp_cells(entry));
|
||||
cells.push(Cell::plain("\n"));
|
||||
if !entry.reason.is_empty() {
|
||||
cells.push(Cell::plain(format!("{}{}", REASON_INDENT, entry.reason)));
|
||||
cells.extend(quoted_cells(&entry.reason, colored));
|
||||
cells.push(Cell::plain("\n"));
|
||||
}
|
||||
}
|
||||
@@ -538,7 +575,10 @@ pub fn history_cells(entries: &[Entry]) -> Vec<Cell> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::util::{Fixture, NOT_SET, paint};
|
||||
use crate::util::{
|
||||
BLOCKED_MARK, Fixture, NOT_SET, PRIORITY_RANGE, Priority, REGRESSION_MARK, RELATES_MARK,
|
||||
paint, priority_mark, status_dirs, status_mark,
|
||||
};
|
||||
|
||||
/// One entry, spelled the way a file on the board holds it.
|
||||
fn entry(kind: &str, body: &str, author: &str, time: &str) -> Entry {
|
||||
@@ -775,12 +815,14 @@ mod tests {
|
||||
] {
|
||||
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
|
||||
// The body keeps the width the bar occupied, and the author line did not move
|
||||
assert!(
|
||||
rendered
|
||||
.contains("From Ansho Rei (2026-08-24 12:00:04)\n The offset was never passed"),
|
||||
.contains("From Ansho Rei (2026-08-24 12:00:04)\n The offset was never passed"),
|
||||
"{rendered}"
|
||||
);
|
||||
// A single line draws no glyph in a pipe, and it is not spared the indent
|
||||
assert!(!rendered.contains(QUOTE_BAR), "{rendered:?}");
|
||||
assert!(!rendered.contains('\x1b'), "colour off still painted: {rendered:?}");
|
||||
}
|
||||
|
||||
@@ -788,10 +830,12 @@ mod tests {
|
||||
/// way `show_prints_the_same_body_it_printed_before_the_cells_conversion` pins the
|
||||
/// body.
|
||||
///
|
||||
/// 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.
|
||||
/// Rewritten three times, 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. Then
|
||||
/// d447e04 put the single-line body behind the grey quote bar, which is what the
|
||||
/// `{bar}` in the middle of the expected string is.
|
||||
///
|
||||
/// 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
|
||||
@@ -820,8 +864,9 @@ mod tests {
|
||||
paint(time, Color::Cyan, true)
|
||||
)
|
||||
};
|
||||
let bar = paint(&format!("{QUOTE_BAR} "), Color::Grey, true);
|
||||
let expected = format!(
|
||||
"\n{}\n{}\n\n{} {} → {} {}\n\n{} {}\n The offset was never passed\n\n{} {} → {} {}\n\n{} {} → alice {}\n\n{} {} → {}, {} {}\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::Grey, true),
|
||||
@@ -830,6 +875,7 @@ mod tests {
|
||||
stamp("claude", "2026-08-24 12:00:00"),
|
||||
paint("From", Color::Grey, true),
|
||||
stamp("Ansho Rei", "2026-08-24 12:00:01"),
|
||||
bar,
|
||||
paint("campaign", Color::Grey, true),
|
||||
paint(NOT_SET, Color::Grey, true),
|
||||
paint("v1", tag_color("v1"), true),
|
||||
@@ -878,10 +924,10 @@ mod tests {
|
||||
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
|
||||
/// it always did.
|
||||
/// The reason is the row's, so it renders behind the same bar the comments draw,
|
||||
/// 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 it always did.
|
||||
#[test]
|
||||
fn a_reason_renders_indented_under_its_row() {
|
||||
let entries = vec![
|
||||
@@ -893,8 +939,9 @@ mod tests {
|
||||
entry("comment", "And why.", "Ansho Rei", "2026-08-24 12:00:01"),
|
||||
];
|
||||
|
||||
let bar = paint(&format!("{QUOTE_BAR} "), Color::Grey, true);
|
||||
let expected = format!(
|
||||
"\n{}\n{}\n\n{} {} → {} {} ({})\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::Grey, true),
|
||||
@@ -902,18 +949,100 @@ mod tests {
|
||||
paint("backlog", Color::Orange, true),
|
||||
paint("claude", tag_color("claude"), true),
|
||||
paint("2026-08-24 12:00:00", Color::Cyan, true),
|
||||
bar,
|
||||
paint("From", Color::Grey, true),
|
||||
paint("Ansho Rei", tag_color("Ansho Rei"), true),
|
||||
paint("2026-08-24 12:00:01", Color::Cyan, true),
|
||||
bar,
|
||||
);
|
||||
|
||||
assert_eq!(format_history_with(&entries, true), expected);
|
||||
// Colour off keeps the reason exactly where a pipe has always read it, at the
|
||||
// width the bar occupied, and carries no glyph doing it.
|
||||
let plain = format_history_with(&entries, false);
|
||||
assert!(
|
||||
format_history_with(&entries, false)
|
||||
.contains("claude (2026-08-24 12:00:00)\n sent back, the first plan was wrong"),
|
||||
"colour off lost the reason: {}",
|
||||
format_history_with(&entries, false)
|
||||
plain.contains("claude (2026-08-24 12:00:00)\n sent back, the first plan was wrong"),
|
||||
"colour off lost the reason: {plain}"
|
||||
);
|
||||
assert!(!plain.contains(QUOTE_BAR) && !plain.contains('\x1b'), "{plain:?}");
|
||||
}
|
||||
|
||||
/// The reported shape: every line of a run sits behind the bar, so a two-paragraph
|
||||
/// comment reads as one voice start to finish. This is what a single prefix got
|
||||
/// wrong — b304b17's symptom — with every line after the first back at column 0,
|
||||
/// which 2733b10 had just given a meaning to.
|
||||
#[test]
|
||||
fn a_multi_line_comment_draws_every_line_behind_the_bar() {
|
||||
let entries = vec![entry(
|
||||
"comment",
|
||||
"First paragraph.\n\nSecond one, still theirs.",
|
||||
"Ansho Rei",
|
||||
"2026-08-24 12:00:00",
|
||||
)];
|
||||
|
||||
let bar = paint(&format!("{QUOTE_BAR} "), Color::Grey, true);
|
||||
let bare = paint(QUOTE_BAR, Color::Grey, true);
|
||||
let rendered = format_history_with(&entries, true);
|
||||
|
||||
// Both content lines prefixed, and the break between them inside the run as the
|
||||
// bare glyph rather than a gap running nowhere.
|
||||
let expected = format!(
|
||||
"\n{}\n{}\n\n{} {} ({})\n{}First paragraph.\n{}\n{}Second one, still theirs.\n",
|
||||
paint("HISTORY", Color::Orange, true),
|
||||
"─".repeat(20),
|
||||
paint("From", Color::Grey, true),
|
||||
paint("Ansho Rei", tag_color("Ansho Rei"), true),
|
||||
paint("2026-08-24 12:00:00", Color::Cyan, true),
|
||||
bar,
|
||||
bare,
|
||||
bar,
|
||||
);
|
||||
assert_eq!(rendered, expected);
|
||||
}
|
||||
|
||||
/// Paired with the one above, the way the guideline demands: colour off drops the
|
||||
/// glyph but keeps the width it occupied, derived from the drawn form, so every
|
||||
/// content line still starts at the same column and no escape byte reaches a pipe.
|
||||
/// The flag is the only thing that decides the bar.
|
||||
#[test]
|
||||
fn colour_off_keeps_the_indent_and_drops_the_glyph() {
|
||||
let entries = vec![entry(
|
||||
"comment",
|
||||
"First paragraph.\n\nSecond one, still theirs.",
|
||||
"Ansho Rei",
|
||||
"2026-08-24 12:00:00",
|
||||
)];
|
||||
|
||||
let rendered = format_history_with(&entries, false);
|
||||
let expected = format!(
|
||||
"\nHISTORY\n{}\n\nFrom Ansho Rei (2026-08-24 12:00:00)\n First paragraph.\n\n Second one, still theirs.\n",
|
||||
"─".repeat(20),
|
||||
);
|
||||
assert_eq!(rendered, expected);
|
||||
}
|
||||
|
||||
/// The bar is chrome like the kind label, so it takes grey; it is one cell wide; and
|
||||
/// it claims nothing another column already means: the circles and the dot belong to
|
||||
/// the priority meter, the cross and arrows to the relation rows, and the status
|
||||
/// marks reuse both sets. Pinned against the marks actually defined rather than a
|
||||
/// list written out here, so a mark added later fails this instead of sharing.
|
||||
#[test]
|
||||
fn the_quote_bar_claims_no_glyph_another_column_means() {
|
||||
assert_eq!(QUOTE_BAR.chars().count(), 1);
|
||||
|
||||
let mut taken = String::new();
|
||||
for level in PRIORITY_RANGE {
|
||||
taken.push_str(priority_mark(Priority::Level(level)).0);
|
||||
}
|
||||
taken.push_str(priority_mark(Priority::Unset).0);
|
||||
taken.push_str(BLOCKED_MARK);
|
||||
taken.push_str(RELATES_MARK);
|
||||
taken.push_str(REGRESSION_MARK);
|
||||
for status in status_dirs() {
|
||||
taken.push_str(status_mark(Some(status)).0);
|
||||
}
|
||||
|
||||
assert!(!taken.contains(QUOTE_BAR), "{taken:?} already means something");
|
||||
}
|
||||
|
||||
/// Padded to the longest of the four, so every body starts in the same column
|
||||
|
||||
Reference in New Issue
Block a user