(e4d0bb7) Colour the whole detail overlay body, not just its relations, and bump to 0.27.3
The block was the only coloured part because it arrived as rows while everything else arrived as a painted string, and the board had to ask for the unpainted one: an escape in a ratatui paragraph is drawn as literal bytes. content_parts now paints nothing. BodyPart::Text becomes BodyPart::Cells, so content_trim is the cells through paint_cells and the board is the same cells through span_from. push_heading, ordered_cells, inline_cells, metadata_cells, metadata_value_cells and tag_cells replace the painters they were. Resolved.campaign is cells too, which made reference_cell dead at its last caller. The colored flag still reaches content_parts and no longer means paint. It says whether this renderer can carry a colour at all, and one thing turns on it: **bold** gives its markers up to the colour that replaces them, so a renderer with none has to keep them. Color::Magenta.ansi() is \x1b[1;35m, so span_from adds the bold modifier on the board's side, since From<Color> carries only the colour and the same cell must not be painted two ways. show's output is pinned byte for byte against what it printed before, both by a fixture holding one of every painted run and by diffing the old binary against the new one over every ticket and campaign on this board, coloured and piped.
This commit is contained in:
+116
-19
@@ -1902,7 +1902,7 @@ fn detail_of(card: &Card) -> Detail {
|
||||
// read of one small directory beside it, for the same reason `show` pays it: the
|
||||
// field stores a uuid, and a card that displayed one raw would say nothing.
|
||||
let resolved = worklane_dir
|
||||
.and_then(|dir| crate::campaign::resolved_for(&content, dir, false).ok())
|
||||
.and_then(|dir| crate::campaign::resolved_for(&content, dir).ok())
|
||||
.unwrap_or_default();
|
||||
let comments = match worklane_dir {
|
||||
Some(worklane_dir) => {
|
||||
@@ -1911,10 +1911,16 @@ fn detail_of(card: &Card) -> Detail {
|
||||
None => Vec::new(),
|
||||
};
|
||||
|
||||
// Colour off for the text, which is what keeps escapes out of the paragraph, and the
|
||||
// relations arrive as rows so the board can style them itself.
|
||||
let mut parts = content_parts(&content, false, &resolved);
|
||||
parts.push(BodyPart::Text(format!("\n{}", format_comments_with(&comments, false))));
|
||||
// Colour on, and nothing here is painted: the body arrives as cells and the
|
||||
// relations as rows, and `detail_body` turns both into styled spans. An escape
|
||||
// sequence never enters, which is what a ratatui paragraph would draw as literal
|
||||
// bytes. The comments are still flat, being a string the board appends rather than
|
||||
// part of the rendered body.
|
||||
let mut parts = content_parts(&content, true, &resolved);
|
||||
parts.push(BodyPart::Cells(vec![Cell::plain(format!(
|
||||
"\n{}",
|
||||
format_comments_with(&comments, false)
|
||||
))]));
|
||||
|
||||
Detail {
|
||||
title: ticket.title.clone(),
|
||||
@@ -1936,17 +1942,19 @@ fn detail_body(parts: &[BodyPart]) -> Text<'static> {
|
||||
|
||||
for part in parts {
|
||||
match part {
|
||||
BodyPart::Text(text) => {
|
||||
let mut rest = text.as_str();
|
||||
while let Some((line, tail)) = rest.split_once('\n') {
|
||||
if !line.is_empty() {
|
||||
open.push(Span::raw(line.to_string()));
|
||||
BodyPart::Cells(cells) => {
|
||||
for cell in cells {
|
||||
let mut rest = cell.text.as_str();
|
||||
while let Some((line, tail)) = rest.split_once('\n') {
|
||||
if !line.is_empty() {
|
||||
open.push(span_from(line, cell.color));
|
||||
}
|
||||
lines.push(Line::from(std::mem::take(&mut open)));
|
||||
rest = tail;
|
||||
}
|
||||
if !rest.is_empty() {
|
||||
open.push(span_from(rest, cell.color));
|
||||
}
|
||||
lines.push(Line::from(std::mem::take(&mut open)));
|
||||
rest = tail;
|
||||
}
|
||||
if !rest.is_empty() {
|
||||
open.push(Span::raw(rest.to_string()));
|
||||
}
|
||||
}
|
||||
// One line each, from the same cells `render_relations` paints, so the block
|
||||
@@ -1972,10 +1980,26 @@ fn detail_body(parts: &[BodyPart]) -> Text<'static> {
|
||||
/// The other half of `paint_cells`, which is the CLI's. `From<Color>` is what makes the
|
||||
/// two agree about what the colour is.
|
||||
fn span_of(cell: Cell) -> Span<'static> {
|
||||
match cell.color {
|
||||
Some(color) => Span::styled(cell.text, Style::default().fg(color.into())),
|
||||
None => Span::raw(cell.text),
|
||||
span_from(cell.text, cell.color)
|
||||
}
|
||||
|
||||
/// The same, for a renderer holding the two halves of a cell rather than the cell.
|
||||
///
|
||||
/// The bold on magenta is not a flourish. `Color::Magenta.ansi()` is `\x1b[1;35m`, so
|
||||
/// the CLI draws every bold run bold as well as magenta, and a board that dropped the
|
||||
/// modifier would be painting the same cell differently from the CLI. The colour is the
|
||||
/// only thing `From<Color>` can carry, so the attribute has to be added on this side.
|
||||
fn span_from(text: impl Into<String>, color: Option<Color>) -> Span<'static> {
|
||||
let Some(color) = color else {
|
||||
return Span::raw(text.into());
|
||||
};
|
||||
|
||||
let mut style = Style::default().fg(color.into());
|
||||
if color == Color::Magenta {
|
||||
style = style.add_modifier(Modifier::BOLD);
|
||||
}
|
||||
|
||||
Span::styled(text.into(), style)
|
||||
}
|
||||
|
||||
/// The four columns of one board, with each card's campaign already named.
|
||||
@@ -2189,7 +2213,7 @@ fn retain_campaign(mut columns: Vec<Column>, campaign: Option<&str>) -> Vec<Colu
|
||||
|
||||
/// The label for the campaign a ticket names, or nothing when it names none.
|
||||
///
|
||||
/// Nothing, too, for a uuid the index does not hold. `campaign_cell` renders that case as
|
||||
/// Nothing, too, for a uuid the index does not hold. `campaign_cells` renders that case as
|
||||
/// `_missing_` because a metadata table is a place to report a dangling reference; a card
|
||||
/// is not, and the answer here is the one `mark_blocked` gives a blocker nobody holds.
|
||||
fn campaign_of(ticket: &TicketItem, campaigns: &CampaignIndex) -> Option<Cell> {
|
||||
@@ -6658,6 +6682,79 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
/// Every painted run in the body reaches the overlay as a style, e4d0bb7.
|
||||
///
|
||||
/// The block was the only coloured part of the body; the rest was flat because
|
||||
/// `content_parts` painted into a string and the board had to ask for the unpainted
|
||||
/// one. It hands out cells now, so the CLI paints them and the board styles them,
|
||||
/// and there is one layout behind both.
|
||||
///
|
||||
/// Paired the way the guideline demands, and both halves are load bearing here: a
|
||||
/// renderer that dropped every colour would pass the absence, and one that went back
|
||||
/// to painting strings would pass the presence.
|
||||
#[test]
|
||||
fn the_whole_body_is_styled_in_the_overlay_and_no_escape_reached_it() {
|
||||
let dir = board_dir();
|
||||
let uuid = "11111111-0000-4000-8000-000000000000";
|
||||
std::fs::write(
|
||||
dir.join("backlog").join(format!("{uuid}_a-painted-one.md")),
|
||||
format!(
|
||||
"# A painted one\n\n## Description\n\nA line with **emphasis** in it.\n\n\
|
||||
## Acceptance Criteria\n\n- [ ] Something\n\n\
|
||||
## Implementation Plan\n\n1. A step\n\n\
|
||||
## Metadata\n\n- **ID**: {uuid}\n- **Due**: _Not set_\n\
|
||||
- **Tags**: bug\n- **Status**: backlog\n"
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let mut board = one_board(&dir);
|
||||
board.toggle_detail();
|
||||
let detail = board.detail.as_ref().expect("no detail");
|
||||
|
||||
// One run per colour the guideline gives the body, each asked for by name so a
|
||||
// run that goes flat names itself in the failure.
|
||||
let heading = body_line(detail, "Description");
|
||||
assert_eq!(span_color(&heading, "Description"), Some(Color::Orange.into()));
|
||||
|
||||
let emphasis = body_line(detail, "emphasis");
|
||||
assert_eq!(span_color(&emphasis, "emphasis"), Some(Color::Magenta.into()));
|
||||
|
||||
let criterion = body_line(detail, "Something");
|
||||
assert_eq!(span_color(&criterion, "1."), Some(Color::Cyan.into()));
|
||||
assert_eq!(span_color(&criterion, "[ ]"), Some(Color::Grey.into()));
|
||||
|
||||
let step = body_line(detail, "A step");
|
||||
assert_eq!(span_color(&step, "1."), Some(Color::Cyan.into()));
|
||||
|
||||
let due = body_line(detail, "_Not set_");
|
||||
assert_eq!(span_color(&due, "Due"), Some(Color::Red.into()));
|
||||
assert_eq!(span_color(&due, "_Not set_"), Some(Color::Grey.into()));
|
||||
|
||||
let tags = body_line(detail, "bug");
|
||||
assert_eq!(span_color(&tags, "bug"), Some(tag_color("bug").into()));
|
||||
|
||||
// `Color::Magenta.ansi()` is `\x1b[1;35m`, so the CLI draws a bold run bold as
|
||||
// well as magenta. The board has to add the modifier itself, since `From<Color>`
|
||||
// carries only the colour.
|
||||
let bold = emphasis
|
||||
.spans
|
||||
.iter()
|
||||
.find(|span| span.content.as_ref() == "emphasis")
|
||||
.expect("no emphasis span");
|
||||
assert!(
|
||||
bold.style.add_modifier.contains(Modifier::BOLD),
|
||||
"the bold run is magenta but not bold: {bold:?}"
|
||||
);
|
||||
|
||||
// The other half: none of that arrived as bytes.
|
||||
assert!(
|
||||
!detail.plain().contains('\x1b'),
|
||||
"escapes reached the body: {:?}",
|
||||
detail.plain()
|
||||
);
|
||||
}
|
||||
|
||||
/// A target the board no longer holds keeps the id, which is the only thing left to
|
||||
/// go looking for, and says `_missing_` in the grey that means an unset value. The
|
||||
/// colour must not turn a gap into something that reads like a real target.
|
||||
|
||||
Reference in New Issue
Block a user