Compare commits

...
1 Commits
Author SHA1 Message Date
Ansho ReiandClaude Opus 5 154ffbdeb3 (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>
2026-08-23 14:45:02 +02:00
7 changed files with 309 additions and 33 deletions
+5 -1
View File
@@ -219,11 +219,15 @@ and this file is for what someone changing worklane's own code needs.
- `detail_title` cuts the string itself instead of leaving it to ratatui, which truncates an overlong block title at whatever cell it reaches and would take the id with it. Cut against the inner width, so the id survives whole and the name ends in an ellipsis. The id goes first because that is how every other view addresses a ticket
- The detail view renders with colour off. ratatui draws styled spans, so an escape sequence in a paragraph would be printed as literal bytes. `content_trim` and `format_comments_with` take the colour decision for that reason
- Read only. Moving a card by keypress is a follow-up, deliberately kept out until the watch and render loop were solid
- **A card is four corners with the title between them:** mark and short id top left, due top right, owner bottom left, criteria count bottom right. The two numbers are in corners because that is where the eye goes for one, and both were invisible at the end of a line of prose
- **A card is four corners with the title between them:** mark and short id top left, due top right, owner bottom left, comment count then criteria count bottom right. The numbers are in corners because that is where the eye goes for one, and they were invisible at the end of a line of prose
- The title takes one row or two, wrapped on spaces, with an ellipsis when even two are not enough. One row when one is enough: a second, blank row on every short ticket spends the column's height on nothing
- **A card's height therefore depends on the column's width**, so `card_lines` and `card_height` both take it. `column_areas` is shared between the draw and `follow_selection` for the same reason: `Ratio` hands the remainder column to whichever slot it likes, and reproducing that arithmetic by hand is how the measurement and the draw come to disagree about where a card starts
- **A corner that will not fit is dropped whole**, never 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
- **`corner_line`'s right side is a group, single-spaced, and it gives up its items from the front.** The item nearest the edge is what the corner is *about*; anything to its left has been added beside it. So the bottom row loses its comment count before its criteria count, and the top row, with one item, behaves exactly as it did when the parameter was an `Option`. The spacing between the items lives in `corner_line` with the gap arithmetic rather than in a caller, for the reason `column_areas` is shared: geometry reproduced by hand drifts from the draw. `due_span` returns a `Span` and not an `Option<Span>` now, since the `Option` only ever existed to satisfy the old signature and the function cannot fail
- The criteria count is a field on `TicketItem`, filled in `collect_ticket_items` where the file is already being read, and counted through `criteria()` so a checkbox in a description is not counted here or numbered by `show`. Do not count per card: that re-reads every ticket body on every draw instead of on the tick that changed something. `None` rather than `[0/0]` for a ticket with no criteria
- **The comment count is the same field discipline and the one entry on that pass that costs a directory listing.** The comments live outside the ticket file, so `count_comments` is a `read_dir` rather than a parse: `.md` only, the filter `read_comments` applies, and no body is read, because a count needs none of them. `collect_ticket_items` derives the board from `status_path.parent()` instead of taking it as a second argument, so a status directory from one board cannot arrive with the comments of another. `comments_dir` spells the path once for the writer, the reader and the counter, the way `campaigns_dir` does. Zero draws nothing, not a `0` and not a blank: an uncommented card is the row it has always been, which `a_card_with_no_comments_spends_nothing_on_the_corner` pins to the exact spacing
- **The count is cyan and the mark is `COMMENT_MARK`, U+275E, a Dingbat.** It is the only coloured thing on a row whose owner and criteria count are grey, because two counts side by side otherwise read as one number in brackets and another that lost its brackets. Not U+1F4AC SPEECH BALLOON: 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. Not U+1F5E8 LEFT SPEECH BUBBLE either: text presentation and Neutral, but in a pictograph block most terminal fonts leave as tofu. Check both properties before swapping the glyph
- **`the_count_is_read_when_the_items_are_collected_and_not_per_draw` takes the comments directory away after the board is built**, and is paired with `a_comment_added_after_the_board_was_built_reaches_the_card_on_reload`, because a count that never asks the filesystem again would pass the first test by never changing. The digest already moves when a comment lands, so the reload is what recounts
- **A card names its campaign on the label row, before the tags, in bold.** `labels_line` draws both, `CAMPAIGN_MARK` (`~`) for the campaign and `#` for a tag, and the campaign takes the row's width first: two cards in one campaign is what a reader looking for a campaign is looking for, and the tags are the context around it. So a row too narrow for both drops the tags whole and keeps the campaign, the order `corner_line` and `project_label` already follow, and a campaign the row will not hold at all goes whole too. A ticket in neither spends no row, so **a ticket in no campaign renders exactly as it did before campaigns reached the card**
- **`Card::campaign` is a resolved `Cell`, not a uuid**, settled at reload the way `project` and `blocked` are. `TicketItem::campaign` already carries the uuid off the pass that builds the card; the name is in another directory, so `columns_of` reads `CampaignIndex` once per project and hands it to every card. Never per draw, the rule `criteria` and `tags` already hold. The merge carries the resolved cell rather than looking it up again, for the reason it carries `blocked`: a campaign is addressed inside one `.worklane`, so a merged lookup could answer one project's uuid with another project's campaign
- **A campaign the board does not hold labels nothing**, the answer `mark_blocked` gives a dangling blocker. `campaign_cell` renders that case as `_missing_` because a metadata table is a place to report a dangling reference; a card is not
Generated
+1 -1
View File
@@ -1503,7 +1503,7 @@ dependencies = [
[[package]]
name = "worklane"
version = "0.24.0"
version = "0.24.1"
dependencies = [
"anyhow",
"assert_cmd",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "worklane"
version = "0.24.0"
version = "0.24.1"
edition = "2024"
[dependencies]
+1 -1
View File
@@ -5,7 +5,7 @@ Worklane is a local Kanban flow for agentic software development.
## Commands
| Command | Description |
|---------|-------------|
| `worklane` or `worklane tui [path...]` | Opens the board: four status columns, redrawn when the tree changes. Read only. Opens on backlog, committed and reviewing; `d` shows or hides done, whose count stays in the footer either way. Arrows or `hjkl` to move, `enter` for detail, `pgup`/`pgdn` to scroll an open ticket, whose border carries a page indicator while there is more of it than fits, `/` to jump to the first ticket whose id or title matches, `y` to copy the selected ticket's short id to the clipboard, `c` to pick a campaign and filter the columns to its members, `q` to close whatever is open and then to quit. A card carries its campaign beside its tags, marked `~` and bold; while one is selected a frame above the columns names it and says how far it has got, and `q` on its border gives the whole board back. Each path opens the first `.worklane` at or above it, the working directory by default. Several paths are monitored together, as a tab per project plus an `all` tab that merges them, with `tab` and `shift+tab` between them |
| `worklane` or `worklane tui [path...]` | Opens the board: four status columns, redrawn when the tree changes. Read only. Opens on backlog, committed and reviewing; `d` shows or hides done, whose count stays in the footer either way. Arrows or `hjkl` to move, `enter` for detail, `pgup`/`pgdn` to scroll an open ticket, whose border carries a page indicator while there is more of it than fits, `/` to jump to the first ticket whose id or title matches, `y` to copy the selected ticket's short id to the clipboard, `c` to pick a campaign and filter the columns to its members, `q` to close whatever is open and then to quit. A card carries its campaign beside its tags, marked `~` and bold, and a comment count in its bottom right corner, the number then `❞` in cyan, before the criteria count and absent entirely when nobody has commented; while one is selected a frame above the columns names it and says how far it has got, and `q` on its border gives the whole board back. Each path opens the first `.worklane` at or above it, the working directory by default. Several paths are monitored together, as a tab per project plus an `all` tab that merges them, with `tab` and `shift+tab` between them |
| `worklane init` | Creates `.worklane/` with backlog, committed, reviewing, done directories |
| `worklane add` | Creates a ticket in backlog with `--title`, `--description`, `--acceptance`, `--plan`, `--tags`, `--due`, `--owner`, `--priority` flags. `--due` takes `YYYY-MM-DD` and refuses anything else at parse time |
| `worklane ls [status]` | Lists tickets, sorted by priority then title. Optional positional status, and `--priority <1-5>`, `--tag <tag>` and `--campaign <campaign>`, which compose in any combination. `--tag` matches a whole value of the comma-separated Tags field, case sensitively, so `--tag bug` does not list a ticket tagged `bugfix` or one tagged `Bug`. `--ids` prints one ticket per line as its short id, a tab and its title, unstyled, done included, for a script or a completion |
+2 -2
View File
@@ -445,7 +445,7 @@ pub fn cmd_show(search: &str, worklane_dir: &Path) -> Result<()> {
println!("\n{}", content_trim_colored(&content, &resolved));
if ticket_uuid != "_Not set_" {
let comments_dir = worklane_dir.join("comments").join(&ticket_uuid);
let comments_dir = comments_dir(worklane_dir, &ticket_uuid);
let comments = read_comments(&comments_dir)?;
let formatted = format_comments(&comments);
println!("{}", formatted);
@@ -731,7 +731,7 @@ pub fn cmd_comment(
return Err(anyhow!("Could not determine ticket ID."));
}
let comments_dir = worklane_dir.join("comments").join(&ticket_uuid);
let comments_dir = comments_dir(&worklane_dir, &ticket_uuid);
fs::create_dir_all(&comments_dir)?;
let stem = Local::now().format(COMMENT_FILE_FORMAT).to_string();
+189 -26
View File
@@ -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"),
+110 -1
View File
@@ -16,6 +16,32 @@ pub const TIMESTAMP_FORMAT: &str = "%Y-%m-%d %H:%M:%S";
/// Fixed width, so the lexicographic sort in `read_comments` stays chronological.
pub const COMMENT_FILE_FORMAT: &str = "%Y%m%d_%H%M%S_%6f";
/// Where a ticket's comments live, under the board.
///
/// Beside the status directories rather than among them, the way `campaigns_dir` is: a
/// comment has no status of its own. Spelled once here, so the writer, the reader and the
/// card's counter cannot disagree about the path.
pub const COMMENTS_DIR: &str = "comments";
/// The comments directory for one ticket, named by its full uuid.
pub fn comments_dir(board: &Path, uuid: &str) -> std::path::PathBuf {
board.join(COMMENTS_DIR).join(uuid)
}
/// The mark a card puts after its comment count.
///
/// A closing quotation ornament, so `2\u{275e}` reads as two things somebody said rather
/// than as a second bracketed counter beside the criteria.
///
/// Deliberately neither U+1F4AC SPEECH BALLOON nor U+1F5E8 LEFT SPEECH BUBBLE. The first
/// has emoji presentation and East Asian Width Wide, so it draws two cells where
/// `spans_width` counts one character and every corner on the card would be a cell out.
/// The second is text presentation and Neutral, but sits in a pictograph block most
/// terminal fonts leave as tofu. This one is a Dingbat, with the coverage the priority
/// meter's Geometric Shapes have, and Neutral, so it is one cell wherever `BLOCKED_MARK`
/// already is.
pub const COMMENT_MARK: &str = "\u{275e}";
/// Whether colour is wanted, from the three inputs that decide it.
///
/// Split out from the caching wrapper so it can be tested without a pty and
@@ -2734,6 +2760,14 @@ pub struct TicketItem {
/// malformed ticket is the worse failure, and is the same exception `detail_of`
/// already makes.
pub blockers: Vec<String>,
/// How many comments the ticket carries, `0` for one with none.
///
/// Read here for the reason `criteria` is: the board draws it on every card, so
/// asking per card would mean a `read_dir` per ticket per frame. It is the one field
/// on this pass that costs a directory listing rather than coming off the content
/// already in hand, which is why it is counted and never read: the bodies are the
/// detail view's business, and a count needs none of them.
pub comments: usize,
/// The file this came from. The listing ignores it; the TUI opens it for the
/// detail view rather than resolving the ticket a second time.
pub path: std::path::PathBuf,
@@ -2886,7 +2920,31 @@ pub fn display_ticket_items(items: &[TicketItem]) {
}
}
/// How many comments a ticket has, counted off the directory rather than read.
///
/// `.md` only, the filter `read_comments` applies, so a stray file dropped in there is
/// not counted as something somebody wrote. A missing directory is none, which is what a
/// ticket nobody has commented on has: no directory is created until the first comment.
fn count_comments(board: &Path, uuid: &str) -> usize {
let Ok(entries) = fs::read_dir(comments_dir(board, uuid)) else {
return 0;
};
entries
.filter_map(|entry| entry.ok())
.filter(|entry| entry.path().extension().is_some_and(|ext| ext == "md"))
.count()
}
pub fn collect_ticket_items(status_path: impl AsRef<Path>) -> Result<Vec<TicketItem>> {
let status_path = status_path.as_ref();
// The comments sit beside the status directories, so the board is this one's parent.
// Derived rather than taken as a second argument: every caller joins a status onto a
// board it already holds, and two arguments would let a status from one board arrive
// with the comments of another. `None` only for a bare relative path, which no caller
// passes and which counts nothing rather than failing.
let board = status_path.parent();
let entries: Vec<_> = fs::read_dir(status_path)?
.filter_map(|e| e.ok())
// A status directory is a plain directory, so anything can be dropped in it.
@@ -2927,6 +2985,11 @@ pub fn collect_ticket_items(status_path: impl AsRef<Path>) -> Result<Vec<TicketI
}),
};
// The ticket's own ID field, not the filename stem: a comment directory is
// named by the uuid the file records, which is what `comment` wrote it under.
let uuid = parse_ticket_field(&content, "ID");
let comments = board.map_or(0, |board| count_comments(board, &uuid));
Some(TicketItem {
title,
owner,
@@ -2937,8 +3000,9 @@ pub fn collect_ticket_items(status_path: impl AsRef<Path>) -> Result<Vec<TicketI
criteria: progress,
campaign: parse_campaign(&content),
tags: parse_tags(&content),
uuid: parse_ticket_field(&content, "ID"),
uuid,
blockers,
comments,
path: e.path(),
committed_on: parse_stamp(&content, Status::Committed),
submitted_on: parse_stamp(&content, Status::Reviewing),
@@ -3405,6 +3469,50 @@ mod tests {
fs::remove_dir_all(&dir).unwrap();
}
/// The count is a directory listing rather than a read: nothing here parses a comment,
/// and the bodies are the detail view's business.
///
/// `.md` only, the filter `read_comments` applies, so a stray file dropped in there is
/// not counted as something somebody wrote. A ticket with no directory at all has
/// none, which is every ticket until the first comment creates one.
#[test]
fn collect_ticket_items_counts_the_comments_under_the_board() {
let board = tempfile::tempdir().unwrap();
let backlog = board.path().join("backlog");
fs::create_dir_all(&backlog).unwrap();
let write = |uuid: &str| {
fs::write(
backlog.join(format!("{uuid}.md")),
format!("# T{uuid}\n\n## Metadata\n\n- **ID**: {uuid}\n- **Owner**: alice\n"),
)
.unwrap();
};
let talked_about = "11111111-0000-4000-8000-000000000001";
let quiet = "11111111-0000-4000-8000-000000000002";
write(talked_about);
write(quiet);
let comments = comments_dir(board.path(), talked_about);
fs::create_dir_all(&comments).unwrap();
fs::write(comments.join("20260823_120000_000000.md"), "**Comment**\n").unwrap();
fs::write(comments.join("20260823_120001_000000.md"), "**Comment**\n").unwrap();
// Not a comment, and not counted as one.
fs::write(comments.join("notes.txt"), "scratch\n").unwrap();
let items = collect_ticket_items(&backlog).unwrap();
let counted = |uuid: &str| {
items
.iter()
.find(|item| item.uuid == uuid)
.unwrap_or_else(|| panic!("no item for {uuid}"))
.comments
};
assert_eq!(counted(talked_about), 2);
assert_eq!(counted(quiet), 0);
}
/// The blockers come off the read that builds the item, so the board pays no second
/// pass for them, and only the `blocked by` kind is one: the other two record no
/// dependency and gate nothing.
@@ -3692,6 +3800,7 @@ mod tests {
tags: Vec::new(),
uuid: NOT_SET.to_string(),
blockers: Vec::new(),
comments: 0,
path: std::path::PathBuf::new(),
committed_on: match status {
Status::Committed => stamp.clone(),