diff --git a/Cargo.lock b/Cargo.lock index d03d63f..f91b5cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1563,7 +1563,7 @@ dependencies = [ [[package]] name = "worklane" -version = "0.33.12" +version = "0.33.13" dependencies = [ "anyhow", "assert_cmd", diff --git a/Cargo.toml b/Cargo.toml index 45b21d8..d44fdf6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "worklane" -version = "0.33.12" +version = "0.33.13" edition = "2024" [dependencies] diff --git a/docs/tui-board.md b/docs/tui-board.md index 3021087..4d3c480 100644 --- a/docs/tui-board.md +++ b/docs/tui-board.md @@ -84,6 +84,7 @@ The TUI: the columns, the cards, the frame, the pickers and the footer. - **`y` has nothing to copy from the pile's frame** — no id to shorten and no word a command line takes, `ls --campaign` being unable to say none — so the footer leaves the key out rather than naming it into a notice, and pressing it anyway still answers "nothing to copy" - **The picker draws two sections, open campaigns above completed, and truncates the completed tail.** One flat list by title put the finished campaigns among the open ones forever, and the tail only grows, so on a board that has run for a while the campaigns worth picking were pushed towards the bottom of the box and eventually off it. Open keeps the index's order, which is by title; completed is by `Created At` newest first, because what a reader recognises about a finished campaign is that it was finished recently. `COMPLETED_SHOWN` of them survive, behind a grey line naming how many older ones are being kept back — rows that are simply gone read as a board that never held them. An unstamped campaign sinks below every stamped one, the rule `by_status_order` holds for a column - **The tag sections are declared above undeclared, and truncate neither.** The same two-section shape with the opposite reason for the second: a completed campaign is finished with, so its tail is kept back before it pushes the pickable campaigns off the box, while an undeclared tag — a word somebody typed onto a ticket that the board never agreed on — is the row a reader most wants to see. A declared tag no ticket carries stays a row too: `tags.md` is what the board intends, and the vocabulary the listing reports is the one the picker offers. `campaign` and `campaigns` would have sat one under the other here, in different sections, the day the second was invented +- **A tag with nothing open sinks to a third section, `nothing open`, below both.** Every carrier done or discarded, or none at all, whether it is declared or not. A reader opens the picker to find work, and a tag with nothing to pick up is the row in the way of that, the reason completed campaigns sit below open ones. Not truncated, for the reason the other two are not. Each tag row trails `done/total` the way a campaign row does, off a `Standing` counted in `tag_rows` through `is_open`, so finished means the same in both lists; a tag nothing carries draws no standing, as a campaign with no members does. The tag frame keeps its plain ticket count off `standing.total` - **`picker_list` is the one place that decides what a picker row is**, and `Picker::row` counts *drawn* rows. The sections reorder the campaigns and add rows of their own, so `Tab::campaigns` and the drawn list agree about no number past the first heading, and a row number that meant one thing to the draw and another to a keypress is how a highlight comes to name a campaign nobody chose. The list is derived on every draw and every keypress and never held, which is what keeps a campaign filed elsewhere reaching an open picker on the next tick - **A heading is drawn only over rows that exist**, the bargain an untagged card's label row already makes, and it says which kind its rows are for as long as they are there — which is what a query filtering down to completed campaigns alone has to go on saying - **`open` and `completed`, not `open` and `done`.** The split is taken from `Standing::state`, so the section a campaign lands in and the state the frame draws cannot come to disagree about what finished means, but the word is the section's own: a campaign sits in no status directory, so it is not *in* done the way a ticket under that heading is. A campaign with no members is neither, per that method, and lists as open — completed means every member is done, and it holds none to be done diff --git a/src/tui.rs b/src/tui.rs index be27112..5764334 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -425,13 +425,13 @@ pub struct TagRow { /// from `None` and the reason this is not a bare string: one was agreed on and left /// unexplained, the other was never agreed on at all. pub annotation: Option, - /// How many cards on this tab carry it, drawn or not. + /// How many cards on this tab carry it, drawn or not, and how many of those are finished. /// /// Every column, done included, for the reason `standings_of` counts every column: - /// hiding done changes what is drawn and never what is counted. Zero is what a declared - /// tag nothing carries shows, which is what makes picking it and getting an empty board - /// something the reader saw coming. - pub count: usize, + /// hiding done changes what is drawn and never what is counted. A [`Standing`] rather + /// than a bare count so the picker can say what a campaign row says, how much is left, + /// and so finished means one thing for both: done or discarded, through `is_open`. + pub standing: Standing, } impl TagRow { @@ -440,6 +440,12 @@ impl TagRow { self.annotation.is_some() } + /// Whether any ticket carrying it is still open, which decides whether it sinks to the + /// bottom section. A tag nothing carries has nothing open either. + pub fn has_open(&self) -> bool { + self.standing.done < self.standing.total + } + /// The opening line of what it means, or empty for a tag with nothing said about it. /// /// The cut lives here rather than on the field, the way [`CampaignRow::summary`] takes @@ -1166,6 +1172,7 @@ const OPEN_SECTION: &str = "open"; const COMPLETED_SECTION: &str = "completed"; const DECLARED_SECTION: &str = "declared"; const UNDECLARED_SECTION: &str = "undeclared"; +const NOTHING_OPEN_SECTION: &str = "nothing open"; /// How many completed campaigns the list shows before it starts keeping them back. /// @@ -1323,7 +1330,8 @@ fn campaign_picker_rows<'a>(tab: &'a Tab, query: &str) -> Vec> { rows } -/// The tag rows: declared above undeclared, and neither truncated. +/// The tag rows: declared above undeclared above the tags with nothing open, and none +/// truncated. /// /// The same two-section shape as the campaigns and the opposite reason for the second /// section. A completed campaign is finished with and the tail of them is truncated because @@ -1335,12 +1343,19 @@ fn campaign_picker_rows<'a>(tab: &'a Tab, query: &str) -> Vec> { /// So nothing is kept back, and the headings are drawn even when only one section has rows: /// which of the two a tag is in is the fact the split is for, and a single unlabelled list /// would leave the reader to guess it. +/// +/// A tag with no open ticket, every carrier done or discarded or none at all, sinks to a +/// third section below both, whichever of the two it would otherwise sit in. A reader opens +/// the picker to find work, and a tag with nothing to pick up is the row that gets in the way +/// of that, the reason the completed campaigns sit below the open ones. fn tag_picker_rows<'a>(tab: &'a Tab, query: &str) -> Vec> { - let (declared, undeclared): (Vec<&TagRow>, Vec<&TagRow>) = tab + let (live, nothing_open): (Vec<&TagRow>, Vec<&TagRow>) = tab .tags .iter() .filter(|tag| tag_matches(tag, query)) - .partition(|tag| tag.declared()); + .partition(|tag| tag.has_open()); + let (declared, undeclared): (Vec<&TagRow>, Vec<&TagRow>) = + live.into_iter().partition(|tag| tag.declared()); let mut rows: Vec = Vec::new(); if !declared.is_empty() { @@ -1351,6 +1366,10 @@ fn tag_picker_rows<'a>(tab: &'a Tab, query: &str) -> Vec> { rows.push(PickerRow::Heading(UNDECLARED_SECTION)); rows.extend(undeclared.into_iter().map(PickerRow::Tag)); } + if !nothing_open.is_empty() { + rows.push(PickerRow::Heading(NOTHING_OPEN_SECTION)); + rows.extend(nothing_open.into_iter().map(PickerRow::Tag)); + } rows } @@ -3397,26 +3416,28 @@ fn campaign_rows( /// `Bug` and `bug` stay two rows and land next to each other, which is where a near /// duplicate is spotted. Case is kept apart because `--tag` keeps it apart. fn tag_rows(tags: &TagIndex, columns: &[Column]) -> Vec { - let mut counts: BTreeMap<&str, usize> = BTreeMap::new(); + let mut standings: BTreeMap<&str, Standing> = BTreeMap::new(); // Declared first, so a tag nothing carries still gets a row, at zero. for name in tags.names() { - counts.entry(name).or_default(); + standings.entry(name).or_default(); } for column in columns { for card in &column.cards { for tag in &card.ticket.tags { - *counts.entry(tag.as_str()).or_default() += 1; + let standing = standings.entry(tag.as_str()).or_default(); + standing.total += 1; + standing.done += usize::from(!is_open(column.status)); } } } - counts + standings .into_iter() - .map(|(name, count)| TagRow { + .map(|(name, standing)| TagRow { name: name.to_string(), annotation: tags.annotation(name).map(str::to_string), - count, + standing, }) .collect() } @@ -3439,7 +3460,8 @@ fn merged_tag_rows(per_project: &[Vec]) -> Vec { for row in rows { match merged.get_mut(row.name.as_str()) { Some(held) => { - held.count += row.count; + held.standing.done += row.standing.done; + held.standing.total += row.standing.total; if held.annotation.is_none() { held.annotation = row.annotation.clone(); } @@ -3971,7 +3993,7 @@ fn frame_content(tab: &Tab, width: u16) -> Option { }), Filter::Tag(_) => tab.selected_tag().map(|tag| FrameContent { title: tag_title(&tag.name, width), - standing: count_spans(tag.count), + standing: count_spans(tag.standing.total), prose: tag_prose(tag), }), Filter::NoCampaign => Some(FrameContent { @@ -5449,16 +5471,17 @@ fn hidden_line(count: usize) -> String { format!("… {count} older completed {campaigns} hidden") } -/// One tag row: `bug 23 What the tag means`. +/// One tag row: `bug What the tag means 5/23`. /// /// The tag in its own colour and nothing else, which is how a card draws it: the mark and /// the bold belong to a campaign label, and this list holds no campaigns to be told apart /// from. `tag_color` is a pure function of the word, so the row and the card agree without /// anything being stored. /// -/// The count is what the row is chosen on as much as the name: it says what picking this -/// will give, and a declared tag at zero says the board is about to go empty before the -/// reader presses anything. Grey, because it is context around the word being chosen. +/// The standing trails the row the way it does a campaign's in `picker_line`, grey and +/// reserved before the annotation is cut, and dropped whole when it does not fit. A tag +/// nothing carries draws none, as a campaign with no members does; the section it sits in +/// already says there is nothing under it. /// /// The annotation takes what is left and gives way first, the trade `picker_line` makes /// with a description: half a sentence still says what a tag is for. @@ -5469,18 +5492,15 @@ fn tag_picker_line(tag: &TagRow, selected: bool, width: u16) -> Line<'static> { }; let grey = Style::default().fg(Color::Grey.into()).add_modifier(emphasis); - let mut spans = vec![ - Span::styled( - tag.name.clone(), - Style::default() - .fg(tag_color(&tag.name).into()) - .add_modifier(emphasis), - ), - Span::raw(" "), - Span::styled(tag.count.to_string(), grey), - ]; + let mut spans = vec![Span::styled( + tag.name.clone(), + Style::default() + .fg(tag_color(&tag.name).into()) + .add_modifier(emphasis), + )]; - let used = spans_width(&spans); + let standing = standing_text(&tag.standing, spans_width(&spans), width); + let used = spans_width(&spans) + standing.as_ref().map_or(0, |text| text.chars().count() + 2); let summary = tag.summary(); if !summary.is_empty() && let Some(room) = (width as usize).checked_sub(used + 2).filter(|room| *room >= 3) @@ -5493,9 +5513,27 @@ fn tag_picker_line(tag: &TagRow, selected: bool, width: u16) -> Line<'static> { spans.push(Span::styled(cut, grey)); } + if let Some(text) = standing { + spans.push(Span::raw(" ")); + spans.push(Span::styled(text, grey)); + } + Line::from(spans) } +/// A standing as a picker row trails it, `2/3`, or nothing when there is nothing to count +/// or the rest of the row after `used` will not hold the whole of it: half a count reads as +/// the wrong number. +fn standing_text(standing: &Standing, used: usize, width: u16) -> Option { + if standing.total == 0 { + return None; + } + + let text = format!("{}/{}", standing.done, standing.total); + let room = (width as usize).saturating_sub(used + 2); + (text.chars().count() <= room).then_some(text) +} + /// The no-campaign row: `no campaign 12`. /// /// Words where a campaign carries an id, because that is what the filter is: not a thing on @@ -5567,18 +5605,7 @@ fn picker_line(campaign: &CampaignRow, selected: bool, width: u16) -> Line<'stat // number, so the whole of it drops when the row will not hold it. A campaign with no // members shows nothing, the way a card with no criteria spends no corner on it. let used_base = spans_width(&spans); - let standing = match campaign.standing.total { - 0 => None, - _ => { - let text = format!("{}/{}", campaign.standing.done, campaign.standing.total); - let room = (width as usize).saturating_sub(used_base + 2); - if text.chars().count() <= room { - Some(text) - } else { - None - } - } - }; + let standing = standing_text(&campaign.standing, used_base, width); let standing_w = standing.as_ref().map_or(0, |text| text.chars().count() + 2); // What the campaign is *called* takes the row first, and the prose takes what is left. @@ -11984,11 +12011,11 @@ approach"; rows, vec![ "declared", - "bug 2 Behaviour that contradicts what the tool says.", - "chore 0 Work with nothing to see.", - "cli 1 The command line surface.", - "undeclared", - "sync 1", + "bug Behaviour that contradicts what the tool says. 0/2", + "cli The command line surface. 0/1", + "nothing open", + "chore Work with nothing to see.", + "sync 1/1", ], "the picker does not list the vocabulary" ); @@ -11999,6 +12026,7 @@ approach"; #[test] fn an_undeclared_tag_sits_in_its_own_section() { let dir = board_dir(); + write_tag_ticket(&dir, "backlog", "44444444-0000-4000-8000-000000000000", "Four", "infra"); let mut board = tag_board(&dir); let rows = open_tag_picker(&mut board); @@ -12013,11 +12041,43 @@ approach"; assert!(declared < undeclared, "the sections are the wrong way round: {rows:?}"); assert!( - rows.iter().skip(undeclared).any(|row| row.starts_with("sync")), + rows.iter().skip(undeclared).any(|row| row.starts_with("infra")), "the carried tag is not under the undeclared heading: {rows:?}" ); } + /// A tag whose every ticket is finished has nothing to pick up, so it sinks below the + /// live ones whichever section it would have sat in, and a discarded ticket counts as + /// finished the way it does in a campaign. + #[test] + fn a_tag_with_nothing_open_sinks_below_both_sections() { + let dir = board_dir(); + write_tag_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "One", "cli"); + write_tag_ticket(&dir, "done", "22222222-0000-4000-8000-000000000000", "Two", "bug"); + write_tag_ticket( + &dir, + "discarded", + "33333333-0000-4000-8000-000000000000", + "Three", + "bug,cli", + ); + write_vocabulary(&dir, &[("bug", "Wrong."), ("cli", "Commands.")]); + let mut board = one_board(&dir); + + let rows = open_tag_picker(&mut board); + + assert_eq!( + rows, + vec![ + "declared", + "cli Commands. 1/2", + "nothing open", + "bug Wrong. 2/2" + ], + "{rows:?}" + ); + } + /// Every column, so a tag answers the same question the listing does. #[test] fn picking_a_tag_filters_every_column_to_the_cards_carrying_it() { @@ -12047,7 +12107,8 @@ approach"; } /// A word the board agreed on and has not used is worth picking, and an empty board is - /// the honest answer to it: the count on the row said so before it was pressed. + /// the honest answer to it: the row sitting under `nothing open` said so before it was + /// pressed. #[test] fn a_declared_tag_nothing_carries_can_be_picked_and_empties_the_board() { let dir = board_dir(); @@ -12073,7 +12134,7 @@ approach"; let rows = open_tag_picker(&mut board); - assert_eq!(rows, vec!["undeclared", "bug 1", "cli 1"], "{rows:?}"); + assert_eq!(rows, vec!["undeclared", "bug 0/1", "cli 0/1"], "{rows:?}"); } /// The query reads the annotation as well as the tag, which is the rule the campaign @@ -12102,7 +12163,7 @@ approach"; rows, vec![ "declared", - "bug 2 Behaviour that contradicts what the tool says." + "bug Behaviour that contradicts what the tool says. 0/2" ] ); } @@ -12578,7 +12639,7 @@ approach"; let rows = open_tag_picker(&mut board); assert_eq!( rows, - vec!["declared", "bug 2 Something wrong."], + vec!["declared", "bug Something wrong. 0/2"], "the tags did not merge" );