(e41802b) Show a ticket's tags on its tui card, and bump to 0.12.1

The Tags field was invisible on the board: a card carried the mark, the short id,
the due date, the owner and the criteria count, and nothing said a ticket was
tagged bug without opening it.

TicketItem gains a tags field, filled in collect_ticket_items through parse_tags
where the file is already being read, for the reason the criteria count is: the
board draws them on every card, and asking per card would re-read every ticket
body on every draw. parse_tags splits the comma-separated field into whole
trimmed values, so a caller asking for bug is not answered by bugfix, and reads
absent, _None_ and empty as one answer. That is step one of 2f3796e5, lifted here
because the board cannot read the field before it exists.

The row sits under the title, dimmed like the owner and the count, each tag
prefixed with # so it does not read as a third line of the title. It is dropped
whole when the column will not hold it, the rule a corner follows, and an
untagged ticket spends no row at all.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ansho Rei
2026-08-22 01:07:40 +02:00
co-authored by Claude Opus 5
parent 5b0bac9c2d
commit 91bbc19c32
5 changed files with 162 additions and 3 deletions
+114 -1
View File
@@ -830,6 +830,7 @@ fn aligned_offset(offset: u16, start: u16, end: u16, inner: u16, total: u16) ->
/// ●◐ (1b78a24) 2026-12-31
/// The tui detail view cannot
/// scroll, and the footer says…
/// #cli #tui
/// Ansho Rei [3/9]
/// ```
///
@@ -841,6 +842,9 @@ fn aligned_offset(offset: u16, start: u16, end: u16, inner: u16, total: u16) ->
/// On the All tab the project follows the id in that top left corner, since across
/// several boards the id alone is not an address: two projects can hold the same title,
/// and seven characters do not say where they live.
///
/// The tags sit between the title and the bottom corners, on a row a ticket without
/// them does not spend. See [`tags_line`].
fn card_lines(card: &Card, selected: bool, width: u16) -> Vec<Line<'static>> {
let ticket = &card.ticket;
let (glyph, colour) = priority_mark(ticket.priority);
@@ -884,6 +888,10 @@ fn card_lines(card: &Card, selected: bool, width: u16) -> Vec<Line<'static>> {
))
}));
if let Some(row) = tags_line(&ticket.tags, width) {
lines.push(row);
}
lines.push(corner_line(
vec![Span::styled(
ticket.owner.clone(),
@@ -902,6 +910,38 @@ fn card_lines(card: &Card, selected: bool, width: u16) -> Vec<Line<'static>> {
lines
}
/// The ticket's tags under the title, or nothing when it has none.
///
/// Each tag is prefixed with `#` and the row is dimmed like the owner and the criteria
/// count: what a card is for is telling tickets apart at a glance, and colour here
/// accentuates rather than encodes. Without the marker the row reads as a third line of
/// the title, since a tag is an ordinary word and the title sits directly above it.
///
/// A row the column will not hold is dropped whole, the rule `corner_line` applies to a
/// corner: a cut list reads as a shorter one, and `bug` and `bugfix` truncated to the
/// same width say the same thing. An untagged ticket spends no row at all, the way a
/// short title spends no second one.
fn tags_line(tags: &[String], width: u16) -> Option<Line<'static>> {
if tags.is_empty() {
return None;
}
let row = tags
.iter()
.map(|tag| format!("#{tag}"))
.collect::<Vec<_>>()
.join(" ");
if row.chars().count() > width as usize {
return None;
}
Some(Line::from(Span::styled(
row,
Style::default().fg(Color::Grey.into()),
)))
}
/// The project name as it fits beside the mark and the id.
///
/// The mark and the id are the ticket's identity and never give way, so the label takes
@@ -1505,13 +1545,19 @@ mod tests {
/// One ticket in backlog, written by hand so a test can set the fields the shared
/// fixture pins: the due value, and the criteria.
fn write_card(dir: &Path, title: &str, due: &str, criteria: &str) {
write_tagged_card(dir, title, due, criteria, "_None_");
}
/// 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";
std::fs::write(
dir.join("backlog").join(format!("{}_{}.md", uuid, slug(title))),
format!(
"# {title}\n\n## Description\nA description.\n\n## Acceptance Criteria\n\
{criteria}\n\n## Metadata\n\n- **ID**: {uuid}\n- **Priority**: 2\n\
- **Tags**: _None_\n- **Due**: {due}\n- **Owner**: alice\n\
- **Tags**: {tags}\n- **Due**: {due}\n- **Owner**: alice\n\
- **Created At**: 2026-08-21 02:00:00\n- **Status**: backlog\n"
),
)
@@ -1529,6 +1575,20 @@ mod tests {
.collect()
}
/// The rows of the only card, laid out in a column of exactly `inner` characters.
///
/// Takes the width directly rather than deriving it from a terminal size, so a test
/// about a narrow column says which width it means instead of solving `card_width`
/// backwards for a screen that produces one.
fn only_card_at(dir: &Path, inner: u16) -> Vec<String> {
let board = one_board(dir);
let ticket = board.selected().expect("no card");
card_lines(ticket, false, inner)
.iter()
.map(|line| line.spans.iter().map(|span| span.content.as_ref()).collect())
.collect()
}
/// The foreground of the span whose text is `needle`, which `render` cannot show:
/// it drops styling on the way out of the buffer.
fn card_colour(dir: &Path, width: u16, needle: &str) -> Option<ratatui::style::Color> {
@@ -1571,6 +1631,59 @@ mod tests {
}
}
/// A tagged ticket says so on the card: the Tags field was invisible on the board,
/// so nothing told you a ticket was tagged bug without opening it.
#[test]
fn a_card_shows_its_tags_under_the_title() {
let dir = board_dir();
write_tagged_card(&dir, "Short", "2026-12-31", "- [ ] One", "cli, tui");
let rows = only_card(&dir, 120, 20);
assert_eq!(rows.len(), 5, "the tag row is missing: {rows:?}");
assert_eq!(rows[1], "Short");
assert_eq!(rows[2], "#cli #tui");
assert!(rows[3].starts_with("alice"), "the owner moved: {rows:?}");
}
/// Dimmed like the owner and the count beside it: the row is there to be scanned,
/// not to compete with the title.
#[test]
fn the_tag_row_is_dimmed() {
let dir = board_dir();
write_tagged_card(&dir, "Short", "2026-12-31", "- [ ] One", "cli, tui");
assert_eq!(card_colour(&dir, 120, "#cli #tui"), Some(Color::Grey.into()));
}
/// And an untagged one spends no row on them, the way a short title spends no
/// second row.
#[test]
fn an_untagged_card_spends_no_row_on_tags() {
let dir = board_dir();
write_tagged_card(&dir, "Short", "2026-12-31", "- [ ] One", "_None_");
let rows = only_card(&dir, 120, 20);
assert_eq!(rows.len(), 4, "{rows:?}");
assert!(!rows.iter().any(|row| row.contains('#')), "{rows:?}");
}
/// A row too wide for the column goes whole, the rule a corner follows: a cut list
/// reads as a shorter one, and bug and bugfix cut to the same width say the same
/// thing.
#[test]
fn a_tag_row_too_wide_for_the_column_is_dropped_whole() {
let dir = board_dir();
write_tagged_card(&dir, "Short", "2026-12-31", "- [ ] One", "frontend, operations");
// One character short of "#frontend #operations", and one over it.
let narrow = only_card_at(&dir, 20);
assert_eq!(narrow.len(), 4, "the row was kept: {narrow:?}");
assert!(!narrow.iter().any(|row| row.contains('#')), "{narrow:?}");
let fits = only_card_at(&dir, 21);
assert_eq!(fits[2], "#frontend #operations", "{fits:?}");
}
/// And a title that fits gets one row, or the second is wasted on every short
/// ticket in the column.
#[test]
+44
View File
@@ -902,6 +902,26 @@ pub fn parse_campaign(content: &str) -> Option<String> {
}
}
/// The tags a ticket carries, from the comma-separated field.
///
/// Whole values, trimmed: the field is written as `bug, frontend` by `add` and as
/// `bug,frontend` by hand, and a caller asking whether a ticket is tagged `bug` must
/// not be answered by a ticket tagged `bugfix`. Absent, unset and empty are one
/// answer, as they are for [`parse_campaign`]: no tags.
pub fn parse_tags(content: &str) -> Vec<String> {
let value = parse_ticket_field(content, "Tags");
if is_unknown_value(&value) {
return Vec::new();
}
value
.split(',')
.map(str::trim)
.filter(|tag| !tag.is_empty())
.map(str::to_string)
.collect()
}
/// The metadata fields in the order `add` writes them, with `Campaign` in its place
/// among them.
///
@@ -1809,6 +1829,13 @@ pub struct TicketItem {
/// Read here for the reason `criteria` is: `ls --campaign` filters on what this
/// pass already produced, rather than reading every ticket a second time to ask.
pub campaign: Option<String>,
/// The tags the ticket carries, split out of the comma-separated field, or empty
/// for an untagged one.
///
/// Read here for the reason `criteria` is: the board draws them on every card, and
/// asking per card would re-read every ticket body on every draw rather than on the
/// tick that changed something.
pub tags: Vec<String>,
/// 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,
@@ -1965,6 +1992,7 @@ pub fn collect_ticket_items(status_path: impl AsRef<Path>) -> Result<Vec<TicketI
priority: parse_priority(&content),
criteria: progress,
campaign: parse_campaign(&content),
tags: parse_tags(&content),
path: e.path(),
})
})
@@ -2377,6 +2405,22 @@ mod tests {
fs::remove_dir_all(&dir).unwrap();
}
/// Whole values, so a filter or a card cannot confuse two tags that share a prefix.
#[test]
fn parse_tags_splits_on_commas_and_keeps_whole_values() {
let content = "# T\n\n## Metadata\n\n- **Tags**: bug, frontend,bugfix\n";
assert_eq!(parse_tags(content), vec!["bug", "frontend", "bugfix"]);
}
/// Absent, unset and empty are one answer: no tags.
#[test]
fn parse_tags_reads_an_unset_or_missing_field_as_none() {
assert_eq!(parse_tags("# T\n\n## Metadata\n\n- **Tags**: _None_\n"), Vec::<String>::new());
assert_eq!(parse_tags("# T\n\n## Metadata\n\n- **Tags**:\n"), Vec::<String>::new());
assert_eq!(parse_tags("# T\n\n## Metadata\n\n- **Owner**: alice\n"), Vec::<String>::new());
assert_eq!(parse_tags("# T\n\n## Metadata\n\n- **Tags**: , ,\n"), Vec::<String>::new());
}
#[test]
fn collect_ticket_items_lists_only_md_files() {
let dir = std::env::temp_dir().join(format!("worklane-stray-{}", uuid::Uuid::new_v4()));