(001b639) Show the comment count on a board card, and bump to 0.24.1
A card had four corners and none of them said whether anybody had written anything on the ticket. Finding out meant opening the detail view or running `show`, which is the question the board exists to answer before you commit to a card rather than after. The count goes in the bottom right, left of the criteria count. Both are about the ticket rather than about the reader, and the criteria count is what that corner has always been: this is what has been added beside it, so it is what sits further from the edge and what goes first when the column is narrow. How far along a ticket is outranks whether somebody has said something about it. `corner_line` takes the whole right-hand group now instead of one span, and the group gives up its items from the front until what is left fits. With one item that is exactly the old behaviour, which is what the top row still wants, so `due_span` returns a `Span` rather than the `Option<Span>` it only ever had to satisfy the signature. The single space between items lives in `corner_line` beside the gap arithmetic, not in the caller: the same reason `column_areas` is shared between the draw and `follow_selection`, that geometry reproduced by hand drifts from the draw. `comments` is a field on `TicketItem`, filled where `criteria` and `tags` already are, and it is the one entry on that pass that costs a directory listing rather than coming off content in hand. So it is counted, never read: `.md` only, the filter `read_comments` applies, and no body is opened, because a count needs none of them. The alternative was a `read_dir` per ticket per frame. `collect_ticket_items` derives the board from `status_path.parent()` rather than taking it as a second argument. Every caller joins a status onto a board it already holds, and two arguments would let a status directory from one board arrive with the comments of another. `comments_dir` now spells that path once for the writer, the reader and the counter, the way `campaigns_dir` does for its directory. Zero draws nothing, not a `0` and not a blank cell held open. An uncommented card is the row it has always been, down to the spacing, which is pinned exactly rather than by a `contains`. The mark is U+275E, a Dingbat, and the choice is about arithmetic as much as reading. U+1F4AC SPEECH BALLOON is emoji presentation and East Asian Width Wide, so it draws two cells where `spans_width` counts one character and every corner on the card lands a cell out. U+1F5E8 LEFT SPEECH BUBBLE is text presentation and Neutral but sits in a pictograph block most terminal fonts leave as tofu. This one has the coverage the priority meter's Geometric Shapes have. Cyan, and the only coloured thing on a row whose owner and criteria count are grey: two counts side by side otherwise read as one number in brackets and another that lost its brackets. The no-per-draw test takes the comments directory away after the board is built, and is paired with one that adds a comment and reloads, because a count that never asked the filesystem again would pass the first by never changing at all. The digest already moved on a new comment, so the reload is what recounts. Patch rather than minor: the corner was already two numbers and a mark, and this settles what it says rather than adding a view. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
50e67483d8
commit
154ffbdeb3
+189
-26
@@ -1786,7 +1786,7 @@ fn card_lines(card: &Card, selected: bool, width: u16) -> Vec<Line<'static>> {
|
||||
));
|
||||
}
|
||||
|
||||
let mut lines = vec![corner_line(left, due_span(&ticket.due), width)];
|
||||
let mut lines = vec![corner_line(left, vec![due_span(&ticket.due)], width)];
|
||||
|
||||
lines.extend(
|
||||
title_lines(&ticket.title, width)
|
||||
@@ -1798,17 +1798,33 @@ fn card_lines(card: &Card, selected: bool, width: u16) -> Vec<Line<'static>> {
|
||||
lines.push(row);
|
||||
}
|
||||
|
||||
// Comments then criteria, and the comment count goes first when the column is too
|
||||
// narrow for both: how far along a ticket is outranks whether anybody has said
|
||||
// something about it. Nothing at all when the count is zero, not a zero and not a
|
||||
// blank, so an uncommented card is the row it has always been.
|
||||
let mut right = Vec::new();
|
||||
if ticket.comments > 0 {
|
||||
// The one coloured thing on the row, where the owner and the criteria count are
|
||||
// grey: a count that has just appeared is the row's news, and the mark is what
|
||||
// says which kind of count it is.
|
||||
right.push(Span::styled(
|
||||
format!("{}{}", ticket.comments, COMMENT_MARK),
|
||||
Style::default().fg(Color::Cyan.into()),
|
||||
));
|
||||
}
|
||||
if let Some(progress) = ticket.criteria {
|
||||
right.push(Span::styled(
|
||||
format!("[{}/{}]", progress.met, progress.total),
|
||||
Style::default().fg(Color::Grey.into()),
|
||||
));
|
||||
}
|
||||
|
||||
lines.push(corner_line(
|
||||
vec![Span::styled(
|
||||
ticket.owner.clone(),
|
||||
Style::default().fg(Color::Grey.into()),
|
||||
)],
|
||||
ticket.criteria.map(|progress| {
|
||||
Span::styled(
|
||||
format!("[{}/{}]", progress.met, progress.total),
|
||||
Style::default().fg(Color::Grey.into()),
|
||||
)
|
||||
}),
|
||||
right,
|
||||
width,
|
||||
));
|
||||
lines.push(Line::from(""));
|
||||
@@ -1914,39 +1930,55 @@ fn project_label(name: &str, width: u16, used: usize) -> Option<String> {
|
||||
///
|
||||
/// The date part only: the field is not validated, so it can hold a time as well, and a
|
||||
/// corner has no room to spare on one.
|
||||
fn due_span(due: &str) -> Option<Span<'static>> {
|
||||
fn due_span(due: &str) -> Span<'static> {
|
||||
let colour = match is_unknown_value(due) {
|
||||
true => Color::Grey,
|
||||
false => Color::Cyan,
|
||||
};
|
||||
|
||||
Some(Span::styled(due_date(due).to_string(), Style::default().fg(colour.into())))
|
||||
Span::styled(due_date(due).to_string(), Style::default().fg(colour.into()))
|
||||
}
|
||||
|
||||
/// `left` at the left, `right` at the right, with the gap between them.
|
||||
///
|
||||
/// The right-hand corner is dropped whole when it will not fit rather than truncated or
|
||||
/// An item of `right` is dropped whole when it will not fit rather than truncated or
|
||||
/// wrapped: half a date reads as a different date, and a card that reflows in a narrow
|
||||
/// column changes height, which the scroll would then have to chase. The left corner is
|
||||
/// the ticket's identity and always stays.
|
||||
fn corner_line(
|
||||
left: Vec<Span<'static>>,
|
||||
right: Option<Span<'static>>,
|
||||
width: u16,
|
||||
) -> Line<'static> {
|
||||
///
|
||||
/// `right` is a group, single-spaced, and it gives up its items **from the front**. The
|
||||
/// item nearest the edge is the one the corner is about and the ones to its left are what
|
||||
/// has been added beside it, so a narrow column loses the additions and keeps the answer:
|
||||
/// the bottom row drops its comment count before its criteria count. One space is
|
||||
/// separator enough, and the spacing lives here rather than in a caller for the reason the
|
||||
/// gap does, that geometry reproduced by hand drifts from the draw.
|
||||
fn corner_line(left: Vec<Span<'static>>, right: Vec<Span<'static>>, width: u16) -> Line<'static> {
|
||||
let mut spans = left;
|
||||
let used = spans_width(&spans);
|
||||
|
||||
let Some(right) = right else {
|
||||
return Line::from(spans);
|
||||
// One space minimum between the corners, so they never touch, and one between each
|
||||
// pair of items in the group. No room for even the last item and the right corner
|
||||
// goes entirely rather than the line growing past the column.
|
||||
let mut kept = 0;
|
||||
let gap = loop {
|
||||
let group = &right[kept..];
|
||||
if group.is_empty() {
|
||||
return Line::from(spans);
|
||||
}
|
||||
|
||||
let wanted = spans_width(group) + group.len() - 1;
|
||||
match (width as usize).checked_sub(used + wanted + 1) {
|
||||
Some(gap) => break gap,
|
||||
None => kept += 1,
|
||||
}
|
||||
};
|
||||
|
||||
let wanted = right.content.chars().count();
|
||||
// One space minimum, so the two corners never touch. No room at all and the right
|
||||
// corner goes rather than the line growing past the column.
|
||||
if let Some(gap) = (width as usize).checked_sub(used + wanted + 1) {
|
||||
spans.push(Span::raw(" ".repeat(gap + 1)));
|
||||
spans.push(right);
|
||||
spans.push(Span::raw(" ".repeat(gap + 1)));
|
||||
for (index, span) in right.into_iter().skip(kept).enumerate() {
|
||||
if index > 0 {
|
||||
spans.push(Span::raw(" "));
|
||||
}
|
||||
spans.push(span);
|
||||
}
|
||||
|
||||
Line::from(spans)
|
||||
@@ -2830,10 +2862,33 @@ mod tests {
|
||||
write_tagged_card(dir, title, due, criteria, "_None_");
|
||||
}
|
||||
|
||||
/// The ticket `write_card`, `write_tagged_card` and `write_member_card` all write.
|
||||
///
|
||||
/// A const rather than a literal in each, now that a test has to name it from outside
|
||||
/// them: the comments of a ticket live in a directory named by its uuid, so a fixture
|
||||
/// that wrote a different one would silently count nothing.
|
||||
const FIXTURE_UUID: &str = "11111111-0000-4000-8000-000000000000";
|
||||
|
||||
/// Comments where `comment` puts them: under the board, in a directory named by the
|
||||
/// ticket's uuid, one `.md` per comment. The fixture uuid, since that is what
|
||||
/// `write_card` writes into the ID field the counter reads.
|
||||
fn write_comments(dir: &Path, count: usize) {
|
||||
let comments = comments_dir(dir, FIXTURE_UUID);
|
||||
std::fs::create_dir_all(&comments).unwrap();
|
||||
|
||||
for n in 0..count {
|
||||
std::fs::write(
|
||||
comments.join(format!("20260823_1200{n:02}_000000.md")),
|
||||
format!("**Comment**\n\n**Author**: alice\n**Time**: 2026-08-23 12:00:{n:02}\n\nSaid {n}.\n"),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
/// The same, with the Tags field a test can set. Untagged is `_None_`, which is
|
||||
/// what `add` writes for a ticket given no tags.
|
||||
fn write_tagged_card(dir: &Path, title: &str, due: &str, criteria: &str, tags: &str) {
|
||||
let uuid = "11111111-0000-4000-8000-000000000000";
|
||||
let uuid = FIXTURE_UUID;
|
||||
std::fs::write(
|
||||
dir.join("backlog").join(format!("{}_{}.md", uuid, slug(title))),
|
||||
format!(
|
||||
@@ -2852,7 +2907,7 @@ mod tests {
|
||||
/// callers that care about tags do not care about campaigns, and five string
|
||||
/// arguments in a row is what the Rust Style rule in AGENTS.md warns about.
|
||||
fn write_member_card(dir: &Path, title: &str, tags: &str, campaign: &str) {
|
||||
let uuid = "11111111-0000-4000-8000-000000000000";
|
||||
let uuid = FIXTURE_UUID;
|
||||
std::fs::write(
|
||||
dir.join("backlog").join(format!("{}_{}.md", uuid, slug(title))),
|
||||
format!(
|
||||
@@ -3102,6 +3157,114 @@ mod tests {
|
||||
assert!(rows[2].ends_with("[1/2]"), "the description was counted: {rows:?}");
|
||||
}
|
||||
|
||||
/// The bottom corner answers two questions now, and in this order: the comment count
|
||||
/// sits left of the criteria count with one space between them. Left, because the
|
||||
/// criteria count is what the corner has always been about and this is what has been
|
||||
/// added beside it.
|
||||
#[test]
|
||||
fn a_card_with_comments_draws_the_count_before_the_criteria_count() {
|
||||
let dir = board_dir();
|
||||
write_card(&dir, "Short", "2026-12-31", "- [x] One\n- [ ] Two");
|
||||
write_comments(&dir, 2);
|
||||
|
||||
let rows = only_card_at(&dir, 40);
|
||||
assert_eq!(
|
||||
rows[2],
|
||||
format!("alice{}2{COMMENT_MARK} [1/2]", " ".repeat(27)),
|
||||
"{rows:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// A ticket nobody has commented on draws the row it always did, down to the spacing:
|
||||
/// no count, no mark, and no cell held open for one. `[0/0]` says less than saying
|
||||
/// nothing, and so does `0` with a mark after it.
|
||||
#[test]
|
||||
fn a_card_with_no_comments_spends_nothing_on_the_corner() {
|
||||
let dir = board_dir();
|
||||
write_card(&dir, "Short", "2026-12-31", "- [x] One\n- [ ] Two");
|
||||
|
||||
let rows = only_card_at(&dir, 40);
|
||||
assert_eq!(rows[2], format!("alice{}[1/2]", " ".repeat(30)), "{rows:?}");
|
||||
assert!(!rows[2].contains(COMMENT_MARK), "{rows:?}");
|
||||
}
|
||||
|
||||
/// Cyan, and the only coloured thing on a row whose owner and criteria count are both
|
||||
/// grey. The mark is what says which kind of count the number is, and the colour is
|
||||
/// what stops two counts side by side reading as one number in brackets and another
|
||||
/// that lost its brackets.
|
||||
#[test]
|
||||
fn the_comment_count_is_cyan_where_the_criteria_count_is_grey() {
|
||||
let dir = board_dir();
|
||||
write_card(&dir, "Short", "2026-12-31", "- [x] One\n- [ ] Two");
|
||||
write_comments(&dir, 3);
|
||||
|
||||
assert_eq!(
|
||||
card_colour(&dir, 120, &format!("3{COMMENT_MARK}")),
|
||||
Some(Color::Cyan.into()),
|
||||
"the comment count is not cyan"
|
||||
);
|
||||
assert_eq!(card_colour(&dir, 120, "[1/2]"), Some(Color::Grey.into()));
|
||||
}
|
||||
|
||||
/// A column with room for one of the two keeps the criteria count: how far along a
|
||||
/// ticket is outranks whether anybody has said something about it. Dropped whole, the
|
||||
/// rule the right corner already followed, never as a bare number without its mark.
|
||||
#[test]
|
||||
fn a_column_too_narrow_for_both_counts_keeps_the_criteria_count() {
|
||||
let dir = board_dir();
|
||||
write_card(&dir, "Short", "2026-12-31", "- [x] One\n- [ ] Two");
|
||||
write_comments(&dir, 2);
|
||||
|
||||
// 14 is exactly `alice`, a space, and both counts single-spaced. 13 is not.
|
||||
assert_eq!(only_card_at(&dir, 14)[2], format!("alice 2{COMMENT_MARK} [1/2]"));
|
||||
|
||||
let narrow = only_card_at(&dir, 13);
|
||||
assert_eq!(narrow[2], "alice [1/2]", "{narrow:?}");
|
||||
assert!(!narrow[2].contains(COMMENT_MARK), "{narrow:?}");
|
||||
}
|
||||
|
||||
/// The count comes off the pass that collected the items, so a draw asks the
|
||||
/// filesystem nothing. Proved by taking the directory away after the board is built:
|
||||
/// a card that counted per draw would show nothing here.
|
||||
#[test]
|
||||
fn the_count_is_read_when_the_items_are_collected_and_not_per_draw() {
|
||||
let dir = board_dir();
|
||||
write_card(&dir, "Short", "2026-12-31", "- [x] One\n- [ ] Two");
|
||||
write_comments(&dir, 2);
|
||||
|
||||
let board = one_board(&dir);
|
||||
std::fs::remove_dir_all(comments_dir(&dir, FIXTURE_UUID)).unwrap();
|
||||
|
||||
let card = board.selected().expect("no card");
|
||||
let rows: Vec<String> = card_lines(card, false, 40)
|
||||
.iter()
|
||||
.map(|line| line.spans.iter().map(|span| span.content.as_ref()).collect())
|
||||
.collect();
|
||||
|
||||
assert!(rows[2].contains(&format!("2{COMMENT_MARK}")), "{rows:?}");
|
||||
}
|
||||
|
||||
/// The pair for the test above, and the reason that one is not enough on its own: a
|
||||
/// count that never asks the filesystem again would also never change. The digest
|
||||
/// already moves when a comment lands, so the reload is what recounts.
|
||||
#[test]
|
||||
fn a_comment_added_after_the_board_was_built_reaches_the_card_on_reload() {
|
||||
let dir = board_dir();
|
||||
write_card(&dir, "Short", "2026-12-31", "- [x] One\n- [ ] Two");
|
||||
|
||||
let mut board = one_board(&dir);
|
||||
assert!(!card_rows(&board, "Short", 40)[2].contains(COMMENT_MARK));
|
||||
|
||||
write_comments(&dir, 1);
|
||||
board.reload().unwrap();
|
||||
|
||||
assert!(
|
||||
card_rows(&board, "Short", 40)[2].contains(&format!("1{COMMENT_MARK}")),
|
||||
"{:?}",
|
||||
card_rows(&board, "Short", 40)
|
||||
);
|
||||
}
|
||||
|
||||
/// A column too narrow for both corners keeps the identity and drops the rest,
|
||||
/// rather than overflowing the border or reflowing to a taller card.
|
||||
#[test]
|
||||
@@ -3219,7 +3382,7 @@ mod tests {
|
||||
write_ticket(&dir, "backlog", uuid, "First one", "");
|
||||
let before = digest(&dir);
|
||||
|
||||
let comments = dir.join("comments").join(uuid);
|
||||
let comments = comments_dir(&dir, uuid);
|
||||
std::fs::create_dir_all(&comments).unwrap();
|
||||
std::fs::write(
|
||||
comments.join("20260821_120000_000000.md"),
|
||||
|
||||
Reference in New Issue
Block a user