(f3e099e) Colour the history block in the detail overlay, and bump to 0.29.1
The board appended the block as a pre-rendered string with colour off, the last flat piece of a body e4d0bb7 had fully styled. history_cells lays the block out once: format_history is those cells painted for the CLI, and detail_of pushes the same ones as a Cells part, so the overlay styles them and no escape can enter. The CLI's output is pinned byte for byte, and the overlay test pairs the presence of the colours with the absence of escapes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
f454d212a4
commit
9d17f55860
+56
-28
@@ -23,7 +23,7 @@ use std::path::{Path, PathBuf};
|
||||
use anyhow::{Result, anyhow};
|
||||
use chrono::Local;
|
||||
|
||||
use crate::util::{Color, TIMESTAMP_FORMAT, paint, should_use_colors};
|
||||
use crate::util::{Cell, Color, TIMESTAMP_FORMAT, paint_cells, should_use_colors};
|
||||
|
||||
/// Where a ticket's history lives, under the board.
|
||||
///
|
||||
@@ -341,59 +341,58 @@ pub fn format_history(entries: &[Entry]) -> String {
|
||||
format_history_with(entries, should_use_colors())
|
||||
}
|
||||
|
||||
/// As above, with the colour decision passed in for the TUI.
|
||||
/// As above, with the colour decision passed in.
|
||||
pub fn format_history_with(entries: &[Entry], colored: bool) -> String {
|
||||
paint_cells(&history_cells(entries), colored)
|
||||
}
|
||||
|
||||
/// 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> {
|
||||
if entries.is_empty() {
|
||||
return paint("No history yet.", Color::Grey, colored);
|
||||
return vec![Cell::colored("No history yet.", Color::Grey)];
|
||||
}
|
||||
|
||||
let mut result = String::new();
|
||||
result.push('\n');
|
||||
result.push_str(&paint("HISTORY", Color::Orange, colored));
|
||||
result.push_str(&format!("\n{}\n", "─".repeat(20)));
|
||||
let mut cells = Vec::new();
|
||||
cells.push(Cell::plain("\n"));
|
||||
cells.push(Cell::colored("HISTORY", Color::Orange));
|
||||
cells.push(Cell::plain(format!("\n{}\n", "─".repeat(20))));
|
||||
|
||||
for entry in entries {
|
||||
result.push('\n');
|
||||
let stamp = paint(&format!("{} ({})", entry.author, entry.time), Color::Cyan, colored);
|
||||
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 => {
|
||||
result.push_str(&paint(
|
||||
&format!("From {} ({})", entry.author, entry.time),
|
||||
Color::Cyan,
|
||||
colored,
|
||||
));
|
||||
result.push('\n');
|
||||
cells.push(Cell::colored(format!("From {}", stamp), Color::Cyan));
|
||||
cells.push(Cell::plain("\n"));
|
||||
if !entry.body.is_empty() {
|
||||
result.push_str(" ");
|
||||
result.push_str(&entry.body);
|
||||
cells.push(Cell::plain(format!(" {}", entry.body)));
|
||||
}
|
||||
result.push('\n');
|
||||
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.
|
||||
_ => {
|
||||
let label = paint(entry.kind.slug(), Color::Orange, colored);
|
||||
let padding = Kind::LABEL_WIDTH.saturating_sub(entry.kind.slug().chars().count());
|
||||
result.push_str(&format!(
|
||||
"{}{} {} {}\n",
|
||||
label,
|
||||
" ".repeat(padding),
|
||||
entry.body,
|
||||
stamp
|
||||
));
|
||||
cells.push(Cell::colored(entry.kind.slug(), Color::Orange));
|
||||
cells.push(Cell::plain(format!("{} ", " ".repeat(padding))));
|
||||
cells.push(Cell::plain(entry.body.clone()));
|
||||
cells.push(Cell::plain(" "));
|
||||
cells.push(Cell::colored(stamp, Color::Cyan));
|
||||
cells.push(Cell::plain("\n"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
cells
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::util::Fixture;
|
||||
use crate::util::{Fixture, paint};
|
||||
|
||||
fn board() -> Fixture {
|
||||
Fixture::new("worklane-history")
|
||||
@@ -572,6 +571,35 @@ mod tests {
|
||||
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.
|
||||
#[test]
|
||||
fn show_prints_the_same_history_it_printed_before_the_cells_conversion() {
|
||||
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",
|
||||
),
|
||||
];
|
||||
|
||||
let expected = format!(
|
||||
"\n{}\n{}\n\n{} committed → reviewing {}\n\n{}\n The offset was never passed\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),
|
||||
);
|
||||
|
||||
assert_eq!(format_history_with(&entries, true), expected);
|
||||
assert_eq!(format_history_with(&[], true), paint("No history yet.", Color::Grey, true));
|
||||
}
|
||||
|
||||
/// Padded to the longest of the three, so every body starts in the same column
|
||||
/// however short the label above it is.
|
||||
#[test]
|
||||
|
||||
+65
-13
@@ -21,7 +21,7 @@ use ratatui::text::{Line, Span, Text};
|
||||
use ratatui::widgets::{Block, Borders, Clear, Paragraph, Tabs, Wrap};
|
||||
|
||||
use crate::campaign::{CAMPAIGNS_DIR, CampaignIndex, Standing};
|
||||
use crate::history::{format_history_with, history_root, read_history};
|
||||
use crate::history::{history_cells, history_root, read_history};
|
||||
use crate::tag::{NO_ANNOTATION, TAGS_FILE, TagIndex};
|
||||
use crate::util::*;
|
||||
|
||||
@@ -1885,10 +1885,10 @@ impl Board {
|
||||
}
|
||||
|
||||
/// The ticket as the detail view holds it: its name and short id, then the body as
|
||||
/// `show` renders it and the comments.
|
||||
/// `show` renders it and the history.
|
||||
///
|
||||
/// Plain rather than coloured, since ratatui draws styled spans and an escape sequence
|
||||
/// in a paragraph would be printed as literal bytes.
|
||||
/// Styled spans rather than painted text, since an escape sequence in a ratatui
|
||||
/// paragraph would be printed as literal bytes.
|
||||
fn detail_of(card: &Card) -> Detail {
|
||||
let ticket = &card.ticket;
|
||||
let content = std::fs::read_to_string(&ticket.path).unwrap_or_default();
|
||||
@@ -1909,16 +1909,14 @@ fn detail_of(card: &Card) -> Detail {
|
||||
None => Vec::new(),
|
||||
};
|
||||
|
||||
// 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 history block is still flat, being a string the board appends rather
|
||||
// than part of the rendered body.
|
||||
// Colour on, and nothing here is painted: the body arrives as cells, the relations
|
||||
// as rows and the history block as the cells the CLI paints, and `detail_body`
|
||||
// turns them all into styled spans. An escape sequence never enters, which is what
|
||||
// a ratatui paragraph would draw as literal bytes.
|
||||
let mut parts = content_parts(&content, true, &resolved);
|
||||
parts.push(BodyPart::Cells(vec![Cell::plain(format!(
|
||||
"\n{}",
|
||||
format_history_with(&history, false)
|
||||
))]));
|
||||
let mut block = vec![Cell::plain("\n")];
|
||||
block.extend(history_cells(&history));
|
||||
parts.push(BodyPart::Cells(block));
|
||||
|
||||
Detail {
|
||||
title: ticket.title.clone(),
|
||||
@@ -4968,6 +4966,60 @@ mod tests {
|
||||
assert!(!plain.contains('\x1b'), "escapes reached the detail view: {plain:?}");
|
||||
}
|
||||
|
||||
/// The history block was the last flat part of the overlay, f3e099e: the board
|
||||
/// appended it as a pre-rendered string after the body, so it drew plain under a
|
||||
/// body e4d0bb7 had fully styled. It arrives as cells now, in the colours `show`
|
||||
/// paints.
|
||||
///
|
||||
/// 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.
|
||||
#[test]
|
||||
fn the_history_block_is_styled_in_the_overlay_and_no_escape_reached_it() {
|
||||
let dir = board_dir();
|
||||
let uuid = "11111111-0000-4000-8000-000000000000";
|
||||
write_ticket(&dir, "backlog", uuid, "First one", "");
|
||||
|
||||
let history = crate::history::history_dir(&dir, uuid);
|
||||
std::fs::create_dir_all(&history).unwrap();
|
||||
std::fs::write(
|
||||
history.join("20260821_120000_000000_status.md"),
|
||||
"**Status**\nbacklog → committed\n\n**Author**: claude\n**Time**: 2026-08-21 12:00:00\n",
|
||||
)
|
||||
.unwrap();
|
||||
std::fs::write(
|
||||
history.join("20260821_120001_000000_comment.md"),
|
||||
"**Comment**\nAnd why.\n\n**Author**: bob\n**Time**: 2026-08-21 12:00:01\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let mut board = one_board(&dir);
|
||||
board.toggle_detail();
|
||||
let detail = board.detail.as_ref().expect("no detail");
|
||||
|
||||
let heading = body_line(detail, "HISTORY");
|
||||
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())
|
||||
);
|
||||
|
||||
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())
|
||||
);
|
||||
|
||||
// The other half: the colour arrived as styles, not as bytes.
|
||||
assert!(
|
||||
!detail.plain().contains('\x1b'),
|
||||
"escapes reached the detail view: {:?}",
|
||||
detail.plain()
|
||||
);
|
||||
}
|
||||
|
||||
/// The reported bug: the modal showed a description, criteria and a metadata
|
||||
/// table belonging to a ticket it never named.
|
||||
#[test]
|
||||
|
||||
+1
-1
@@ -2378,7 +2378,7 @@ impl Cell {
|
||||
Cell { text: text.into(), color: None }
|
||||
}
|
||||
|
||||
fn colored(text: impl Into<String>, color: Color) -> Self {
|
||||
pub(crate) fn colored(text: impl Into<String>, color: Color) -> Self {
|
||||
Cell {
|
||||
text: text.into(),
|
||||
color: Some(color),
|
||||
|
||||
Reference in New Issue
Block a user