(6ce2c47) Mark each relation with the status of the ticket it names
The Relations block named each target and said nothing about where it was, so the question actually asked of it, whether a blocker is finished, meant closing the overlay and going to find the other ticket. Each row now carries a mark for its target's status, ahead of the id, where it describes the target rather than the row. A rising bar, U+2581 through U+2588 for backlog to done, and ? for a target the board no longer holds. Not a circle: the cards spend those on the priority meter two cells from nothing at all, and another circle would be read as a level. The ramp is also the meaning, so the shape says which status it is. The colour could not. Every colour in the guideline already means one thing and the eight tag slots are reserved, so four status colours could only have come out of something else's meaning. So the shape carries the status and the colour says only that it is one: orange, which is what Status already means, and grey on the missing mark, beside the _missing_ that grey already spells. An unrecognised status reads as missing rather than as a fifth stage, and every_status_has_a_mark pins the pairing against status_dirs so a status added later fails a test instead of quietly reading as ?. The plain text was the real cost. Detail.text was one String drawn by a Paragraph, deliberately uncoloured because an escape sequence there is drawn as literal bytes, which is 6d327df. So the block cannot arrive pre-painted. Resolved.relations is now rows, content_parts returns the body as BodyPart::Text and BodyPart::Relations with the text painted and the rows untouched, and the two renderers take it from there: content_trim paints the rows into escapes, and the board styles the same cells as spans. One builder, two painters. relation_rows decides which edges there are, what they are called and which direction leads; relation_cells decides the layout, the mark and the colours; paint_cells and span_of are the only things that differ. Cell is the unit both take, the same shape the palette uses to stop a colour existing for one renderer and not the other. reference_cells is now the one spelling of a cross reference, shared with the Campaign field. Detail.body is a ratatui Text and is the only thing measured, so last_offset and the Paragraph cannot wrap the body two ways. Detail::plain() flattens it for the suite and is cfg(test): a second representation carried beside the spans is a second thing to disagree. show carries the same mark, decided here rather than discovered later. The rows are one builder so it was free, and two views disagreeing about what a relation shows is a difference nobody can explain afterwards. That is a change to what the CLI prints, so the minor goes on the last commit of this pair. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
c437d87e9e
commit
ece201e3ab
+256
-34
@@ -16,7 +16,7 @@ use anyhow::{Context, Result};
|
||||
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
||||
use ratatui::layout::{Constraint, Direction, Layout, Margin, Rect, Size};
|
||||
use ratatui::style::{Modifier, Style};
|
||||
use ratatui::text::{Line, Span};
|
||||
use ratatui::text::{Line, Span, Text};
|
||||
use ratatui::widgets::{Block, Borders, Clear, Paragraph, Tabs, Wrap};
|
||||
use ratatui::Frame;
|
||||
|
||||
@@ -202,7 +202,35 @@ pub struct Detail {
|
||||
/// card that said so, and the id alone is not an address across several boards:
|
||||
/// acting on the ticket means knowing which project to run the command in.
|
||||
pub project: Option<String>,
|
||||
pub text: String,
|
||||
/// The body as the overlay draws it: lines of styled spans, not a string.
|
||||
///
|
||||
/// Styled here rather than painted into the text, because ratatui draws an escape
|
||||
/// sequence in a paragraph as literal bytes, which is 6d327df. It is also the one
|
||||
/// value the clamp and the draw both measure, so neither can wrap it differently
|
||||
/// from the other.
|
||||
pub body: Text<'static>,
|
||||
}
|
||||
|
||||
impl Detail {
|
||||
/// The body as plain text, one line per drawn line.
|
||||
///
|
||||
/// Only the suite asks: it is what an assertion about the body reads, and what shows
|
||||
/// that no escape sequence reached it. Nothing in the draw path needs it, so it is
|
||||
/// not carried alongside the spans where the two could disagree.
|
||||
#[cfg(test)]
|
||||
pub fn plain(&self) -> String {
|
||||
self.body
|
||||
.lines
|
||||
.iter()
|
||||
.map(|line| {
|
||||
line.spans
|
||||
.iter()
|
||||
.map(|span| span.content.as_ref())
|
||||
.collect::<String>()
|
||||
})
|
||||
.collect::<Vec<String>>()
|
||||
.join("\n")
|
||||
}
|
||||
}
|
||||
|
||||
/// The open search prompt: what has been typed, and whether the last enter missed.
|
||||
@@ -702,7 +730,7 @@ impl Board {
|
||||
let text = detail_text_area(Rect::new(0, 0, screen.width, screen.height));
|
||||
// A screenful less a line, so the eye has something to land on after the jump.
|
||||
let step = text.height.saturating_sub(1).max(1) as isize;
|
||||
let last = last_offset(&detail.text, text) as isize;
|
||||
let last = last_offset(&detail.body, text) as isize;
|
||||
|
||||
self.offset = (self.offset as isize + pages.saturating_mul(step)).clamp(0, last) as u16;
|
||||
}
|
||||
@@ -744,15 +772,73 @@ fn detail_of(card: &Card) -> Detail {
|
||||
None => Vec::new(),
|
||||
};
|
||||
|
||||
let mut out = content_trim(&content, false, &resolved);
|
||||
// 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)
|
||||
)));
|
||||
|
||||
out.push('\n');
|
||||
out.push_str(&format_comments_with(&comments, false));
|
||||
Detail {
|
||||
title: ticket.title.clone(),
|
||||
id: ticket.id.clone(),
|
||||
project: card.project.clone(),
|
||||
text: out,
|
||||
body: detail_body(&parts),
|
||||
}
|
||||
}
|
||||
|
||||
/// The rendered body as lines of spans: the text split where it says, and each relation
|
||||
/// row styled from the cells the CLI paints.
|
||||
///
|
||||
/// A part that does not end on a newline runs on into the next one rather than closing a
|
||||
/// line, so the seam between text and relations is wherever the body actually put it and
|
||||
/// not wherever a part happened to end.
|
||||
fn detail_body(parts: &[BodyPart]) -> Text<'static> {
|
||||
let mut lines: Vec<Line<'static>> = Vec::new();
|
||||
let mut open: Vec<Span<'static>> = Vec::new();
|
||||
|
||||
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()));
|
||||
}
|
||||
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
|
||||
// cannot read differently here than it does in `show`.
|
||||
BodyPart::Relations(rows) => {
|
||||
for row in relation_cells(rows) {
|
||||
open.extend(row.into_iter().map(span_of));
|
||||
lines.push(Line::from(std::mem::take(&mut open)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !open.is_empty() {
|
||||
lines.push(Line::from(open));
|
||||
}
|
||||
|
||||
Text::from(lines)
|
||||
}
|
||||
|
||||
/// A cell as the board draws it: the same text in the same colour, as a span.
|
||||
///
|
||||
/// 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),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1571,8 +1657,8 @@ fn detail_text_area(area: Rect) -> Rect {
|
||||
/// Measured by the widget rather than counted by hand, since it wraps on words. A clamp
|
||||
/// on the raw lines would stop short of the end on a wrapped ticket, and one that
|
||||
/// ignored the wrapping the other way would scroll past it into blank space.
|
||||
fn last_offset(detail: &str, text: Rect) -> u16 {
|
||||
let wrapped = Paragraph::new(detail)
|
||||
fn last_offset(detail: &Text<'static>, text: Rect) -> u16 {
|
||||
let wrapped = Paragraph::new(detail.clone())
|
||||
.wrap(Wrap { trim: false })
|
||||
.line_count(text.width);
|
||||
|
||||
@@ -1586,7 +1672,7 @@ fn draw_detail(frame: &mut Frame, detail: &Detail, offset: u16, area: Rect) {
|
||||
|
||||
// Clamped here as well as on the keypress: the terminal may have been resized since,
|
||||
// and a ticket read to its end can grow shorter under a tick.
|
||||
let offset = offset.min(last_offset(&detail.text, detail_text_area(area)));
|
||||
let offset = offset.min(last_offset(&detail.body, detail_text_area(area)));
|
||||
|
||||
let block = Block::default()
|
||||
.borders(Borders::ALL)
|
||||
@@ -1598,7 +1684,7 @@ fn draw_detail(frame: &mut Frame, detail: &Detail, offset: u16, area: Rect) {
|
||||
|
||||
frame.render_widget(Clear, overlay);
|
||||
frame.render_widget(
|
||||
Paragraph::new(detail.text.to_string())
|
||||
Paragraph::new(detail.body.clone())
|
||||
.block(block)
|
||||
.wrap(Wrap { trim: false })
|
||||
.scroll((offset, 0)),
|
||||
@@ -2571,16 +2657,16 @@ mod tests {
|
||||
board.toggle_detail();
|
||||
let detail = board.detail.as_ref().expect("no detail");
|
||||
|
||||
assert!(detail.text.contains("A description."), "{}", detail.text);
|
||||
assert!(detail.text.contains("Crit one"), "{}", detail.text);
|
||||
assert!(detail.text.contains("A note from elsewhere."), "{}", detail.text);
|
||||
assert!(detail.text.contains("bob"), "{}", detail.text);
|
||||
assert!(detail.plain().contains("A description."), "{}", detail.plain());
|
||||
assert!(detail.plain().contains("Crit one"), "{}", detail.plain());
|
||||
assert!(detail.plain().contains("A note from elsewhere."), "{}", detail.plain());
|
||||
assert!(detail.plain().contains("bob"), "{}", detail.plain());
|
||||
|
||||
// Plain text, since ratatui would print an escape as literal bytes
|
||||
assert!(
|
||||
!detail.text.contains('\x1b'),
|
||||
!detail.plain().contains('\x1b'),
|
||||
"escapes reached the detail view: {:?}",
|
||||
detail.text
|
||||
detail.plain()
|
||||
);
|
||||
|
||||
board.toggle_detail();
|
||||
@@ -2605,7 +2691,7 @@ mod tests {
|
||||
// The heading stays out of the text: `show` prints it and here the border
|
||||
// carries it, so it is on screen once rather than twice.
|
||||
assert!(
|
||||
!board.detail.as_ref().unwrap().text.contains("First one"),
|
||||
!board.detail.as_ref().unwrap().plain().contains("First one"),
|
||||
"{:?}",
|
||||
board.detail
|
||||
);
|
||||
@@ -2670,7 +2756,7 @@ mod tests {
|
||||
|
||||
let mut board = one_board(&dir);
|
||||
board.toggle_detail();
|
||||
assert!(!board.detail.as_ref().unwrap().text.contains("A late note."));
|
||||
assert!(!board.detail.as_ref().unwrap().plain().contains("A late note."));
|
||||
|
||||
let comments = dir.join("comments").join(uuid);
|
||||
std::fs::create_dir_all(&comments).unwrap();
|
||||
@@ -2682,7 +2768,7 @@ mod tests {
|
||||
|
||||
assert!(board.tick().unwrap(), "the tick saw no change");
|
||||
assert!(
|
||||
board.detail.as_ref().unwrap().text.contains("A late note."),
|
||||
board.detail.as_ref().unwrap().plain().contains("A late note."),
|
||||
"{:?}",
|
||||
board.detail
|
||||
);
|
||||
@@ -2809,7 +2895,7 @@ mod tests {
|
||||
// By id in the text: the heading is stripped from the body, and the title
|
||||
// travels beside it for the block title instead.
|
||||
assert!(
|
||||
board.detail.as_ref().unwrap().text.contains("11111111"),
|
||||
board.detail.as_ref().unwrap().plain().contains("11111111"),
|
||||
"{:?}",
|
||||
board.detail
|
||||
);
|
||||
@@ -2817,7 +2903,7 @@ mod tests {
|
||||
board.select_card(1, SCREEN);
|
||||
assert_eq!(selected_title(&board), Some("Beta".to_string()));
|
||||
assert!(
|
||||
board.detail.as_ref().unwrap().text.contains("22222222"),
|
||||
board.detail.as_ref().unwrap().plain().contains("22222222"),
|
||||
"{:?}",
|
||||
board.detail
|
||||
);
|
||||
@@ -3299,7 +3385,7 @@ mod tests {
|
||||
let mut board = one_board(&dir);
|
||||
board.toggle_detail();
|
||||
assert!(
|
||||
board.detail.as_ref().unwrap().text.contains("11111111"),
|
||||
board.detail.as_ref().unwrap().plain().contains("11111111"),
|
||||
"{:?}",
|
||||
board.detail
|
||||
);
|
||||
@@ -3310,7 +3396,7 @@ mod tests {
|
||||
|
||||
let detail = board.detail.as_ref().expect("the overlay closed on a jump");
|
||||
assert_eq!(detail.title, "Gamma third");
|
||||
assert!(detail.text.contains("33333333"), "{detail:?}");
|
||||
assert!(detail.plain().contains("33333333"), "{detail:?}");
|
||||
}
|
||||
|
||||
/// With no prompt open the keyboard belongs to the action arms, so `search_key` has
|
||||
@@ -4007,9 +4093,9 @@ mod tests {
|
||||
_ => "22222222",
|
||||
};
|
||||
assert!(
|
||||
detail.text.contains(uuid),
|
||||
detail.plain().contains(uuid),
|
||||
"the overlay opened another project's ticket: {project} {:?}",
|
||||
detail.text
|
||||
detail.plain()
|
||||
);
|
||||
|
||||
let screen = render(&board, SCREEN.width, SCREEN.height);
|
||||
@@ -4020,7 +4106,7 @@ mod tests {
|
||||
board.select_card(1, SCREEN);
|
||||
let moved = board.detail.as_ref().expect("no detail");
|
||||
assert_ne!(moved.project, Some(project), "the modal stayed on one project");
|
||||
assert!(!moved.text.contains(uuid), "{:?}", moved.text);
|
||||
assert!(!moved.plain().contains(uuid), "{:?}", moved.plain());
|
||||
}
|
||||
|
||||
/// The board and the listing draw from the same palette, so a colour cannot exist
|
||||
@@ -4037,6 +4123,141 @@ mod tests {
|
||||
|
||||
|
||||
|
||||
/// The style of the first cell drawing `symbol`, so a test can ask what colour a
|
||||
/// glyph actually reached the screen in rather than trusting the span it was built
|
||||
/// from.
|
||||
fn drawn_color(
|
||||
board: &Board,
|
||||
width: u16,
|
||||
height: u16,
|
||||
symbol: char,
|
||||
) -> Option<ratatui::style::Color> {
|
||||
let mut terminal = Terminal::new(TestBackend::new(width, height)).unwrap();
|
||||
terminal.draw(|frame| draw(frame, board)).unwrap();
|
||||
let buffer = terminal.backend().buffer().clone();
|
||||
|
||||
(0..buffer.area.height)
|
||||
.flat_map(|y| (0..buffer.area.width).map(move |x| (x, y)))
|
||||
.find(|(x, y)| buffer[(*x, *y)].symbol() == symbol.to_string())
|
||||
.map(|(x, y)| buffer[(x, y)].fg)
|
||||
}
|
||||
|
||||
/// A board holding one relation, so the tests below have a block to look at.
|
||||
///
|
||||
/// The section goes where `relate` writes it, ahead of the metadata, rather than in
|
||||
/// `write_ticket`'s trailer: the block has to be on screen for a test to read the
|
||||
/// colour off the drawn buffer.
|
||||
fn related_board() -> PathBuf {
|
||||
let dir = board_dir();
|
||||
let holder = "11111111-0000-4000-8000-000000000000";
|
||||
let target = "22222222-0000-4000-8000-000000000000";
|
||||
|
||||
std::fs::write(
|
||||
dir.join("backlog").join(format!("{holder}_a-holder.md")),
|
||||
format!(
|
||||
"# A holder\n\n## Description\nA description.\n\n## Relations\n\
|
||||
- blocked by {target}\n\n## Metadata\n\n- **ID**: {holder}\n\
|
||||
- **Priority**: 2\n- **Status**: backlog\n"
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
write_ticket(&dir, "reviewing", target, "The target", "");
|
||||
dir
|
||||
}
|
||||
|
||||
/// The mark is a ratatui style, not an escape sequence in the body. Passing `true`
|
||||
/// to the body renderers would put `\x1b[33m` in the paragraph and draw it as literal
|
||||
/// bytes, which is 6d327df; this asserts the colour arrived and the escape did not.
|
||||
#[test]
|
||||
fn the_relation_mark_is_drawn_as_a_style_and_not_as_an_escape() {
|
||||
let dir = related_board();
|
||||
let mut board = one_board(&dir);
|
||||
board.toggle_detail();
|
||||
|
||||
let (mark, colour) = status_mark(Some("reviewing"));
|
||||
let detail = board.detail.as_ref().expect("no detail");
|
||||
assert!(
|
||||
detail.plain().contains(mark),
|
||||
"the target's mark is not in the body: {:?}",
|
||||
detail.plain()
|
||||
);
|
||||
assert!(
|
||||
!detail.plain().contains('\x1b'),
|
||||
"an escape reached the body: {:?}",
|
||||
detail.plain()
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
drawn_color(&board, SCREEN.width, SCREEN.height, mark),
|
||||
Some(colour.into()),
|
||||
"the mark was drawn without its colour"
|
||||
);
|
||||
}
|
||||
|
||||
/// One layout, two painters. The overlay draws the block from the same cells the CLI
|
||||
/// paints, so the two views cannot come to list different edges in a different order
|
||||
/// or pad them differently.
|
||||
#[test]
|
||||
fn the_overlay_and_the_listing_draw_the_same_block() {
|
||||
let dir = related_board();
|
||||
let mut board = one_board(&dir);
|
||||
board.toggle_detail();
|
||||
|
||||
let content = std::fs::read_to_string(
|
||||
board.selected().expect("no selection").ticket.path.clone(),
|
||||
)
|
||||
.unwrap();
|
||||
let rows = relations_for(&content, &dir).unwrap();
|
||||
let printed = render_relations(&rows, false);
|
||||
|
||||
assert!(!printed.is_empty(), "the fixture has no relations");
|
||||
assert!(
|
||||
board.detail.as_ref().unwrap().plain().contains(printed.trim_end()),
|
||||
"the overlay drew a different block than the listing prints: {printed:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// The body is no longer one string, so the clamp and the draw could measure two
|
||||
/// different things. They take the same `Text`, and this is what says so: a ticket
|
||||
/// whose relations run past the overlay scrolls to its last row.
|
||||
#[test]
|
||||
fn the_scroll_measures_the_relations_block_with_the_rest_of_the_body() {
|
||||
let dir = board_dir();
|
||||
let holder = "11111111-0000-4000-8000-000000000000";
|
||||
let mut relations = String::from("\n## Relations\n");
|
||||
for n in 0..20 {
|
||||
let target = format!("2222222{n:x}-0000-4000-8000-000000000000");
|
||||
relations.push_str(&format!("- blocked by {target}\n"));
|
||||
write_ticket(&dir, "done", &target, &format!("Target {n:02}"), "");
|
||||
}
|
||||
write_ticket(&dir, "backlog", holder, "A holder", &relations);
|
||||
|
||||
let mut board = one_board(&dir);
|
||||
board.toggle_detail();
|
||||
|
||||
let area = detail_text_area(Rect::new(0, 0, SCREEN.width, SCREEN.height));
|
||||
let last = last_offset(&board.detail.as_ref().unwrap().body, area);
|
||||
assert!(last > 0, "the fixture fits on one screen, so nothing is measured");
|
||||
|
||||
// Far past the end, so the clamp is what stops it.
|
||||
for _ in 0..20 {
|
||||
board.scroll_detail(1, SCREEN);
|
||||
}
|
||||
assert_eq!(board.offset, last, "the clamp and the body disagree");
|
||||
|
||||
// The relations sit at the end of this fixture, so the last row and the comments
|
||||
// line are what the last screenful has to hold.
|
||||
let screen = render(&board, SCREEN.width, SCREEN.height).join("\n");
|
||||
assert!(
|
||||
screen.contains("Target 19"),
|
||||
"the last relation is not on screen:\n{screen}"
|
||||
);
|
||||
assert!(
|
||||
screen.contains("No comments yet."),
|
||||
"the body ends past the last screenful:\n{screen}"
|
||||
);
|
||||
}
|
||||
|
||||
/// The detail view is the second renderer of a ticket body, so it resolves a
|
||||
/// relation the way `show` does rather than printing the uuid the file stores.
|
||||
///
|
||||
@@ -4058,8 +4279,9 @@ mod tests {
|
||||
let mut board = one_board(&dir);
|
||||
board.toggle_detail();
|
||||
|
||||
let text = &board.detail.as_ref().expect("no detail").text;
|
||||
assert!(text.contains("blocked by (2222222) The target"), "{text:?}");
|
||||
let text = &board.detail.as_ref().expect("no detail").plain();
|
||||
// Marked with the target's status, backlog, and the mark sits ahead of the id.
|
||||
assert!(text.contains("blocked by \u{2581} (2222222) The target"), "{text:?}");
|
||||
assert!(!text.contains(target), "the bare uuid was drawn: {text:?}");
|
||||
}
|
||||
|
||||
@@ -4082,8 +4304,8 @@ mod tests {
|
||||
board.select_card(1, SCREEN);
|
||||
board.toggle_detail();
|
||||
|
||||
let text = &board.detail.as_ref().expect("no detail").text;
|
||||
assert!(text.contains("blocks (1111111) A holder"), "{text:?}");
|
||||
let text = &board.detail.as_ref().expect("no detail").plain();
|
||||
assert!(text.contains("blocks \u{2581} (1111111) A holder"), "{text:?}");
|
||||
}
|
||||
|
||||
/// The detail view resolves the Campaign field the way `show` does. The field stores
|
||||
@@ -4109,7 +4331,7 @@ mod tests {
|
||||
let mut board = one_board(&dir);
|
||||
board.toggle_detail();
|
||||
|
||||
let text = &board.detail.as_ref().expect("no detail").text;
|
||||
let text = &board.detail.as_ref().expect("no detail").plain();
|
||||
assert!(text.contains("(ccccccc) v1 release"), "{text:?}");
|
||||
assert!(!text.contains(campaign), "the bare uuid reached the screen: {text:?}");
|
||||
}
|
||||
@@ -4130,7 +4352,7 @@ mod tests {
|
||||
let mut board = one_board(&dir);
|
||||
board.toggle_detail();
|
||||
|
||||
let text = &board.detail.as_ref().expect("no detail").text;
|
||||
let text = &board.detail.as_ref().expect("no detail").plain();
|
||||
assert!(text.contains("A description."), "the body was lost: {text:?}");
|
||||
// No campaigns to resolve against, so the reference reads as gone.
|
||||
assert!(text.contains("_missing_"), "{text:?}");
|
||||
@@ -4152,7 +4374,7 @@ mod tests {
|
||||
let mut board = one_board(&dir);
|
||||
board.toggle_detail();
|
||||
|
||||
let text = &board.detail.as_ref().expect("no detail").text;
|
||||
let text = &board.detail.as_ref().expect("no detail").plain();
|
||||
assert!(text.contains("A description."), "the body was lost: {text:?}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user