From 7126138d462f3fd6172a840a7ac1db672e2ddca1 Mon Sep 17 00:00:00 2001 From: Ansho Rei Date: Mon, 24 Aug 2026 10:03:29 +0200 Subject: [PATCH] (0fd1ddc) Pick a tag in the tui, and bump to 0.27.1 The board could be cut by campaign and not by the axis `ls --tag` has answered since 2f3796e. `t` opens a picker of every tag the board declares or carries, and taking one filters every column to the cards carrying it, matched whole and case sensitively the way the listing matches. The picker is one piece of machinery over two lists rather than a second picker. `PickerRow::key` is what made that cheap: a campaign is keyed by its uuid and a tag by itself, both strings, so stepping over selectable rows, keeping the highlight across a rebuild and taking a row with `enter` are written once. Only the list and what the answer filters differ. `Tab::campaign` became `Tab::filter`, an enum of whole, campaign or tag, with `select_filter` its only writer. Picking either clears the other because they are one field rather than because two setters remember to, which is also what the shared frame slot needs: it holds one frame and can now only be asked to name one thing. The tag sections are declared above undeclared and neither is truncated, where the completed campaigns are: a finished campaign is done with and that tail only grows, while an undeclared tag is the row a reader most wants to see. `campaign` and `campaigns` would have sat one under the other here the day the second was invented. The digest stamps `tags.md`, or a tag declared elsewhere would never reach an open picker. The footer names the tag in its own colour beside `q board`, because a tag draws no frame until 2a83bd4 and nothing else would say why the cards are missing. Co-Authored-By: Claude Opus 5 (1M context) --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 6 +- src/tag.rs | 10 + src/tui.rs | 1153 ++++++++++++++++++++++++++++++++++++++++++++------- 5 files changed, 1014 insertions(+), 159 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 369c6ad..6b224f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1503,7 +1503,7 @@ dependencies = [ [[package]] name = "worklane" -version = "0.27.0" +version = "0.27.1" dependencies = [ "anyhow", "assert_cmd", diff --git a/Cargo.toml b/Cargo.toml index 24f13b3..06526f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "worklane" -version = "0.27.0" +version = "0.27.1" edition = "2024" [dependencies] diff --git a/src/main.rs b/src/main.rs index 2aff9ff..598583b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -248,7 +248,11 @@ fn run_tui(paths: &[std::path::PathBuf], start: &std::path::Path) -> Result<()> // The way in to the campaign picker, like `/` is to the search prompt: from // the next keypress on `picker_key` above has the keyboard. Free of every // other binding, and `ctrl-c` is matched above this so quitting still wins. - KeyCode::Char('c') => board.open_picker(), + KeyCode::Char('c') => board.open_picker(tui::PickerKind::Campaign, screen), + // The other axis the board is cut along, and the one `ls --tag` has + // answered since 2f3796e. Free of every other binding: `tab` is its own + // key code, not this letter. + KeyCode::Char('t') => board.open_picker(tui::PickerKind::Tag, screen), _ => {} } } diff --git a/src/tag.rs b/src/tag.rs index d07edc8..ba75ee2 100644 --- a/src/tag.rs +++ b/src/tag.rs @@ -163,6 +163,16 @@ impl TagIndex { self.tags.keys().map(String::as_str) } + /// What a tag means, whole, or `None` for a tag the file does not declare. + /// + /// The raw section, paragraphs and all, where [`Self::summary`] is the one line a + /// listing has room for. `Some("")` is a tag declared with nothing said about it, which + /// the caller has to tell apart from `None`: the board draws the two in different + /// sections. + pub fn annotation(&self, tag: &str) -> Option<&str> { + self.tags.get(tag).map(String::as_str) + } + /// The opening line of what a tag means, or `None` for a tag the file does not declare. /// /// The cut to one line lives here rather than on the parse, the way diff --git a/src/tui.rs b/src/tui.rs index 76aa919..1c5b60e 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -6,8 +6,8 @@ //! //! **Read only.** Moving a card by keypress is a follow-up. Everything here observes. -use std::collections::HashMap; use std::collections::hash_map::DefaultHasher; +use std::collections::{BTreeMap, HashMap}; use std::hash::{Hash, Hasher}; use std::path::{Path, PathBuf}; use std::time::{Duration, SystemTime}; @@ -22,6 +22,7 @@ use ratatui::widgets::{Block, Borders, Clear, Paragraph, Tabs, Wrap}; use crate::campaign::{CAMPAIGNS_DIR, CampaignIndex, Standing}; use crate::handlers::read_comments; +use crate::tag::{NO_ANNOTATION, TAGS_FILE, TagIndex}; use crate::util::*; /// How long the event poll waits before letting the tick run. @@ -150,6 +151,60 @@ pub enum Focus { Frame, } +/// What a tab's columns are cut down to: one campaign, one tag, or the whole board. +/// +/// A type rather than two `Option` fields and a rule that only one may be set. The +/// board has one frame slot above the columns and it names what the columns are showing, so +/// a tab filtered by a campaign *and* a tag would have two things to say there and no room +/// to say either; a reader would also have no way to tell which of the two emptied a +/// column. Making them mutually exclusive here is what stops that state existing at all, +/// the way [`Focus`] made the third place a selection can be something every key answers +/// for. +/// +/// A campaign is held by uuid, which is what a card names and what resolves inside one +/// `.worklane`. A tag is held as itself: it has no id, it is the string `--tag` matches +/// whole and case sensitively, and the same word means the same thing on every board. That +/// is why the merge tab can carry a tag filter where it could not carry another project's +/// campaign. +#[derive(Clone, Debug, Default, PartialEq, Eq)] +pub enum Filter { + /// Every card the tab holds, which is where a tab opens. + #[default] + Whole, + Campaign(String), + Tag(String), +} + +impl Filter { + /// The campaign this filters to, or nothing for a tag filter or none. + /// + /// The frame, the focus and the geometry all ask this rather than whether a filter is + /// on: only a campaign draws a frame, so only a campaign can hold the selection above + /// the columns. + pub fn campaign(&self) -> Option<&str> { + match self { + Filter::Campaign(uuid) => Some(uuid), + _ => None, + } + } + + pub fn tag(&self) -> Option<&str> { + match self { + Filter::Tag(name) => Some(name), + _ => None, + } + } + + /// Whether the tab is showing everything it holds. + /// + /// What `dismiss` asks, and what the footer asks to decide whether `q` takes a filter + /// off or leaves the board: both are about there being a filter at all rather than + /// about which kind it is. + pub fn is_whole(&self) -> bool { + matches!(self, Filter::Whole) + } +} + /// One monitored board: where it lives, and what to call it. #[derive(Debug)] pub struct Project { @@ -306,6 +361,58 @@ impl CampaignRow { } } +/// A tag as the board holds it: what the picker lists and what the frame will draw. +/// +/// The union of the two vocabularies, built at reload: the tags the tickets carry, counted +/// off the cards the reload is already holding, and the tags `.worklane/tags.md` declares, +/// which no ticket has to carry for the board to know about them. Which of the two a row +/// came from is the split the picker draws, so it is a field rather than something derived +/// from the count: a declared tag nothing carries and an undeclared tag are both real, and +/// telling them apart is the whole reason the vocabulary file exists. +/// +/// The annotation is carried whole rather than as the one line the picker row shows, the +/// trade [`CampaignRow`] makes with its description: the file is only in hand while the +/// board is being read, and the frame that pages through the rest of it is the next ticket. +#[derive(Clone, Debug)] +pub struct TagRow { + /// The tag itself, which is also its identity: `--tag` matches it whole and case + /// sensitively, and there is no id to hold it by. + pub name: String, + /// What the vocabulary says the tag means, or `None` for a tag no board declares. + /// + /// `Some("")` is a tag declared with nothing said about it, which is a different answer + /// 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. + /// + /// 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, +} + +impl TagRow { + /// Whether the vocabulary file declares this tag, which is the section it lands in. + pub fn declared(&self) -> bool { + self.annotation.is_some() + } + + /// 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 + /// one line off a description held whole. + pub fn summary(&self) -> &str { + let annotation = self.annotation.as_deref().unwrap_or_default(); + + match annotation == NO_ANNOTATION { + true => "", + false => annotation.lines().next().unwrap_or_default(), + } + } +} + /// One tab: a monitored board, or the merge across all of them. /// /// The selection and the column offsets live here rather than on the board, so @@ -322,12 +429,22 @@ pub struct Tab { /// The campaigns this tab can be filtered to: the ones on its own board, or every /// board's on the merge. Rebuilt at reload beside the columns. pub campaigns: Vec, - /// The uuid of the campaign the columns are filtered to, or `None` for the whole board. + /// The tags this tab can be filtered to: every tag its board declares or carries, and + /// on the merge the union across every board. Rebuilt at reload beside the columns. + /// + /// A union rather than a per-board list, unlike `campaigns`, which carries the project + /// each was filed in. A tag is a string and the same string on every board, so the merge + /// tab's `bug` is one row standing for every board's, and filtering to it cuts all of + /// them at once. + pub tags: Vec, + /// What the columns are cut down to: one campaign, one tag, or the whole board. /// /// Per tab rather than on the `Board`, the way the selection is. A campaign belongs to /// one `.worklane`, so a filter carried across to another project's tab would empty it - /// and say nothing about why. - pub campaign: Option, + /// and say nothing about why. A tag would survive the crossing, being a string every + /// board can carry, but it goes on the tab beside the campaign because the two are one + /// filter and one field. + pub filter: Filter, /// Whether the selection is on a card or on the campaign frame above the columns. /// /// Per tab like the rest of the selection, so switching away and back returns to where @@ -359,7 +476,8 @@ impl Tab { card: 0, offsets: Vec::new(), campaigns: Vec::new(), - campaign: None, + tags: Vec::new(), + filter: Filter::default(), focus: Focus::default(), expanded: false, frame_offset: 0, @@ -372,7 +490,7 @@ impl Tab { /// campaign cannot leave the frame pointing at a different one. A selection whose /// campaign has since left the board resolves to nothing, which `reload` then clears. fn selected_campaign(&self) -> Option<&CampaignRow> { - let uuid = self.campaign.as_deref()?; + let uuid = self.filter.campaign()?; self.campaigns.iter().find(|row| row.uuid == uuid) } @@ -534,6 +652,14 @@ impl Notice { /// than in a copy of the list that has gone stale. #[derive(Debug, Default)] pub struct Picker { + /// Which list is open, since the box is one piece of machinery over two. + /// + /// On the picker rather than on the board, for the reason the row and the query are: + /// "a picker is open" and "what it is choosing between" cannot disagree, and closing it + /// leaves nothing to reset. Everything about moving, querying and scrolling is the same + /// either way; this decides only what `picker_list` builds and what `take_picked` does + /// with the answer. + pub kind: PickerKind, /// Which *drawn* row the highlight is on, headings and the truncation line included, /// so it and `offset` are counted in the same units and `picker_list` is the one place /// that decides what a row number means. @@ -551,8 +677,18 @@ pub struct Picker { /// Lowercase like the column headings, since they are the same kind of chrome, and /// `completed` rather than the `done` `Standing::state` spells: a campaign sits in no /// status directory, so it is not *in* done the way a ticket under that heading is. +/// Which of the two lists a picker is showing. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +pub enum PickerKind { + #[default] + Campaign, + Tag, +} + const OPEN_SECTION: &str = "open"; const COMPLETED_SECTION: &str = "completed"; +const DECLARED_SECTION: &str = "declared"; +const UNDECLARED_SECTION: &str = "undeclared"; /// How many completed campaigns the list shows before it starts keeping them back. /// @@ -573,12 +709,32 @@ enum PickerRow<'a> { /// A section heading, naming what the rows under it are. Heading(&'static str), Campaign(&'a CampaignRow), + Tag(&'a TagRow), /// How many older completed campaigns the truncation is keeping back. Hidden(usize), /// The query matched nothing, said in the box rather than left as an empty one. Missed, } +impl PickerRow<'_> { + /// What taking this row would filter the board to, or nothing for a row of chrome. + /// + /// One accessor for both kinds, which is what lets everything between the keypress and + /// the filter — the step over selectable rows, the highlight kept across a rebuild, the + /// value `enter` takes — be written once. A campaign is keyed by its uuid and a tag by + /// itself, and both are a string the tab can be filtered by. + /// + /// `None` is also the test of whether a row can be highlighted at all, so a heading or + /// the truncation line is stepped over rather than landed on. + fn key(&self) -> Option<&str> { + match self { + PickerRow::Campaign(campaign) => Some(&campaign.uuid), + PickerRow::Tag(tag) => Some(&tag.name), + _ => None, + } + } +} + /// The rows the picker draws: open campaigns above completed, filtered by the query. /// /// One flat list ordered by title put the completed campaigns among the open ones forever. @@ -602,6 +758,22 @@ enum PickerRow<'a> { fn picker_list<'a>(tab: &'a Tab, picker: &Picker) -> Vec> { let query = picker.query.as_deref().unwrap_or_default(); + let mut rows = match picker.kind { + PickerKind::Campaign => campaign_picker_rows(tab, query), + PickerKind::Tag => tag_picker_rows(tab, query), + }; + + // A box with nothing in it says nothing about why, and the query that emptied it is + // still on the footer to be corrected. + if rows.is_empty() { + rows.push(PickerRow::Missed); + } + + rows +} + +/// The campaign rows: open above completed, the completed tail truncated. +fn campaign_picker_rows<'a>(tab: &'a Tab, query: &str) -> Vec> { let (mut completed, open): (Vec<&CampaignRow>, Vec<&CampaignRow>) = tab .campaigns .iter() @@ -627,10 +799,36 @@ fn picker_list<'a>(tab: &'a Tab, picker: &Picker) -> Vec> { rows.push(PickerRow::Hidden(found - completed.len())); } - // A box with nothing in it says nothing about why, and the query that emptied it is - // still on the footer to be corrected. - if rows.is_empty() { - rows.push(PickerRow::Missed); + rows +} + +/// The tag rows: declared above undeclared, and neither 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 +/// it only grows; an undeclared tag is the one a reader most wants to see, since it is a +/// word somebody typed onto a ticket that the board never agreed on. `campaign` and +/// `campaigns` would have sat one under the other here, in different sections, the day the +/// second was invented. +/// +/// 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. +fn tag_picker_rows<'a>(tab: &'a Tab, query: &str) -> Vec> { + let (declared, undeclared): (Vec<&TagRow>, Vec<&TagRow>) = tab + .tags + .iter() + .filter(|tag| tag_matches(tag, query)) + .partition(|tag| tag.declared()); + + let mut rows: Vec = Vec::new(); + if !declared.is_empty() { + rows.push(PickerRow::Heading(DECLARED_SECTION)); + rows.extend(declared.into_iter().map(PickerRow::Tag)); + } + if !undeclared.is_empty() { + rows.push(PickerRow::Heading(UNDECLARED_SECTION)); + rows.extend(undeclared.into_iter().map(PickerRow::Tag)); } rows @@ -658,6 +856,28 @@ fn picker_matches(campaign: &CampaignRow, query: &str) -> bool { || campaign.title.to_lowercase().contains(&query) } +/// Whether a tag answers the query: the tag itself, or what it is annotated to mean. +/// +/// The two things the row draws, which is the rule `picker_matches` follows for a campaign. +/// The annotation is in because a reader who cannot remember the word can often remember +/// what it was for, which is the whole reason the vocabulary is written down. +/// +/// Case insensitive, unlike `--tag` itself. Matching a tag is the filter and has to keep +/// `Bug` and `bug` apart; searching for one is a reader typing, and a query that had to be +/// cased right would be a worse way to find the tag than scrolling. +fn tag_matches(tag: &TagRow, query: &str) -> bool { + let query = query.trim().to_lowercase(); + if query.is_empty() { + return true; + } + + tag.name.to_lowercase().contains(&query) + || tag + .annotation + .as_deref() + .is_some_and(|annotation| annotation.to_lowercase().contains(&query)) +} + /// What is on screen. pub struct Board { /// The monitored boards as tabs, the merge first when there is more than one. @@ -734,7 +954,7 @@ impl Board { let tab = self.current(); Chrome { tabbed: self.tabbed(), - campaign: tab.campaign.is_some().then_some(match tab.expanded { + campaign: tab.filter.campaign().is_some().then_some(match tab.expanded { true => FrameSize::Expanded, false => FrameSize::Collapsed, }), @@ -772,8 +992,9 @@ impl Board { let merged = self.projects.len() > 1; let mut per_columns: Vec> = Vec::new(); let mut per_campaigns: Vec> = Vec::new(); + let mut per_tags: Vec> = Vec::new(); for project in &self.projects { - let (columns, campaigns) = columns_of(&project.dir); + let (columns, campaigns, tags) = columns_of(&project.dir); // The project is named on a row only where it has to be. On a single board // there is nothing to tell a campaign apart from, the bargain a card's project // label already takes. @@ -785,40 +1006,69 @@ impl Board { // filter is applied to them further down: a campaign's standing is how far it // has got, which is not a question about what the tab is currently showing. per_campaigns.push(campaign_rows(&campaigns, label, &columns)); + // Counted off the same unfiltered columns, and for the same reason: how many + // tickets carry a tag is not a question about what the tab is showing. + per_tags.push(tag_rows(&tags, &columns)); per_columns.push(columns); } // The campaign the picker is highlighting, taken before the lists are rebuilt. The // row is an index into a list a tick can reshape, so it is the uuid that has to // survive the rebuild, the way `Tab::campaign` is a uuid and not an index. - let highlighted = self.picker_highlight().map(|row| row.uuid.clone()); + let highlighted = self.picked(); - let mut built: Vec<(Vec, Vec)> = Vec::new(); + let mut built: Vec<(Vec, Vec, Vec)> = Vec::new(); if merged { // Every board's campaigns under the merge, each carrying the project it was // filed in: on that tab an id says which campaign but not which board holds it. + // The tags merge by name instead, since the same word is the same tag on every + // board. let campaigns = per_campaigns.iter().flatten().cloned().collect(); - built.push((merge(&per_columns, &self.projects), campaigns)); + built.push(( + merge(&per_columns, &self.projects), + campaigns, + merged_tag_rows(&per_tags), + )); } - built.extend(per_columns.into_iter().zip(per_campaigns)); + built.extend( + per_columns + .into_iter() + .zip(per_campaigns) + .zip(per_tags) + .map(|((columns, campaigns), tags)| (columns, campaigns, tags)), + ); - for (tab, (columns, campaigns)) in self.tabs.iter_mut().zip(built) { + for (tab, (columns, campaigns, tags)) in self.tabs.iter_mut().zip(built) { tab.campaigns = campaigns; + tab.tags = tags; // A selection whose campaign has left the board goes back to the whole board // rather than filtering it to nothing: the frame would have nothing to name and // every column would be empty, which reads as a board that has lost its // tickets. - if tab.selected_campaign().is_none() { - tab.campaign = None; - // And the frame goes with it, both the focus and the place its prose was - // scrolled to: a frame that is no longer drawn must not be holding the - // selection, and the next campaign selected starts at the top of its own - // description rather than partway down the last one's. + if tab.filter.campaign().is_some() && tab.selected_campaign().is_none() { + tab.filter = Filter::Whole; + } + // A tag filter outlives its cards, which a campaign filter does not: a declared + // tag nothing carries is a real thing to be looking at, and an empty board is + // the honest answer to picking it. What it does not outlive is leaving the + // vocabulary altogether, when it is neither declared nor carried anywhere. + if let Some(tag) = tab.filter.tag() + && !tab.tags.iter().any(|row| row.name == tag) + { + tab.filter = Filter::Whole; + } + // The frame goes with the campaign, both the focus and the place its prose was + // scrolled to: a frame that is no longer drawn must not be holding the + // selection, and the next campaign selected starts at the top of its own + // description rather than partway down the last one's. Keyed off the campaign + // rather than off there being a filter, because a tag filter draws no frame. + if tab.filter.campaign().is_none() { tab.focus = Focus::Cards; tab.expanded = false; tab.frame_offset = 0; } - tab.columns = retain_campaign(columns, tab.campaign.as_deref()); + tab.columns = + retain_tag(retain_campaign(columns, tab.filter.campaign()), tab.filter.tag()); // One scroll position per column, kept by index. A tick that adds or removes // columns is not a thing statuses do, but the resize keeps the two in step // regardless; `resize` both pads and truncates. @@ -969,7 +1219,7 @@ impl Board { }; let count = column.cards.len(); - if delta < 0 && tab.card == 0 && tab.campaign.is_some() && !open { + if delta < 0 && tab.card == 0 && tab.filter.campaign().is_some() && !open { self.current_mut().focus = Focus::Frame; return; } @@ -1054,39 +1304,59 @@ impl Board { self.current().selected_campaign() } - /// Open the picker on the campaign in view, or say there is nothing to pick from. + /// Open a picker on the filter in view, or say there is nothing to pick from. /// - /// A board with no campaigns gets a notice rather than an empty box: the box would - /// have to be dismissed to learn that it was empty, and `Notice` is what the board - /// already uses to say something in words. Failed, because the key was pressed and - /// nothing came of it, which is the same answer a copy off an empty column gives. + /// A board with nothing of that kind gets a notice rather than an empty box: the box + /// would have to be dismissed to learn that it was empty, and `Notice` is what the + /// board already uses to say something in words. Failed, because the key was pressed + /// and nothing came of it, which is the same answer a copy off an empty column gives. /// - /// It opens on the campaign already selected, so `c` on a filtered board is a way to - /// look at where you are as much as a way to move, and on the first row otherwise. - pub fn open_picker(&mut self) { - if self.current().campaigns.is_empty() { - self.notice = Some(Notice::failed("no campaigns on this board")); + /// It opens on the filter already applied, so `c` or `t` on a filtered board is a way + /// to look at where you are as much as a way to move — and only when the open list is + /// the kind that filter is, since a tag picker has nothing to highlight on a board + /// filtered to a campaign. On the first row otherwise. + pub fn open_picker(&mut self, kind: PickerKind, screen: Size) { + let tab = self.current(); + let (empty, held) = match kind { + PickerKind::Campaign => { + (tab.campaigns.is_empty(), tab.filter.campaign().map(str::to_string)) + } + PickerKind::Tag => (tab.tags.is_empty(), tab.filter.tag().map(str::to_string)), + }; + + if empty { + let what = match kind { + PickerKind::Campaign => "campaigns", + PickerKind::Tag => "tags", + }; + self.notice = Some(Notice::failed(format!("no {what} on this board"))); return; } - let selected = self.current().campaign.clone(); - self.picker = Some(Picker::default()); - self.place_picker(selected.as_deref()); + self.picker = Some(Picker { kind, ..Picker::default() }); + self.place_picker(held.as_deref()); + // The list is taller than the box on a board with many tags, so the highlight has + // to be brought into it rather than left at an offset the last picker had. + self.align_picker(screen); } - /// The campaign the highlight is on, or nothing when the picker is closed or the - /// highlight is on chrome. + /// What the highlight is on, as the string that would filter the board: a campaign's + /// uuid or a tag. Nothing when the picker is closed or the highlight is on chrome. /// - /// Through the drawn list rather than by indexing `Tab::campaigns`, because that is - /// what the row number counts: the sections reorder the campaigns and add rows of their - /// own, so the two lists agree about no number past the first heading. - fn picker_highlight(&self) -> Option<&CampaignRow> { + /// Through the drawn list rather than by indexing the tab's own list, because that is + /// what the row number counts: the sections reorder the rows and add rows of their own, + /// so the two lists agree about no number past the first heading. + /// + /// Owned rather than borrowed, unlike the campaign row it used to hand back. Every + /// caller wanted the key and cloned it, and a borrow of the board is exactly what a + /// caller about to mutate the board cannot hold. + fn picked(&self) -> Option { let picker = self.picker.as_ref()?; - match picker_list(self.current(), picker).into_iter().nth(picker.row)? { - PickerRow::Campaign(campaign) => Some(campaign), - _ => None, - } + picker_list(self.current(), picker) + .get(picker.row)? + .key() + .map(str::to_string) } /// Put the highlight on `uuid`, or on the first row that can be taken. @@ -1099,16 +1369,13 @@ impl Board { /// /// A list of nothing but chrome puts it on row zero, where `take_picked` finds no /// campaign and does nothing. - fn place_picker(&mut self, uuid: Option<&str>) { + fn place_picker(&mut self, key: Option<&str>) { let Some(picker) = &self.picker else { return }; let rows = picker_list(self.current(), picker); - let held = uuid.and_then(|uuid| { - rows.iter() - .position(|row| matches!(row, PickerRow::Campaign(held) if held.uuid == uuid)) - }); + let held = key.and_then(|key| rows.iter().position(|row| row.key() == Some(key))); let at = held - .or_else(|| rows.iter().position(|row| matches!(row, PickerRow::Campaign(_)))) + .or_else(|| rows.iter().position(|row| row.key().is_some())) .unwrap_or(0); if let Some(picker) = &mut self.picker { @@ -1188,7 +1455,7 @@ impl Board { /// empty query filters nothing but a closed one also untruncates nothing, and closing /// one that had cut the list down gives every hidden row back. fn requery(&mut self, screen: Size, edit: impl FnOnce(&mut Option)) { - let held = self.picker_highlight().map(|campaign| campaign.uuid.clone()); + let held = self.picked(); let Some(picker) = &mut self.picker else { return; @@ -1228,7 +1495,7 @@ impl Board { loop { at += delta; let at = usize::try_from(at).ok()?; - if matches!(rows.get(at)?, PickerRow::Campaign(_)) { + if rows.get(at)?.key().is_some() { return Some(at); } } @@ -1260,15 +1527,31 @@ impl Board { /// That is what the search prompt does with a miss, and for the same reason: doing /// nothing visible is what makes a reader retype a query that was already right. fn take_picked(&mut self, screen: Size) { - let Some(uuid) = self.picker_highlight().map(|campaign| campaign.uuid.clone()) else { + let Some(picker) = &self.picker else { return }; + let kind = picker.kind; + let Some(key) = self.picked() else { return; }; self.picker = None; - self.select_campaign(Some(uuid), screen); + // The key is a uuid or a tag depending on which list was open, which is the one + // thing about a picker that its kind decides rather than its rows. + self.select_filter( + match kind { + PickerKind::Campaign => Filter::Campaign(key), + PickerKind::Tag => Filter::Tag(key), + }, + screen, + ); } - /// Filter the tab in view to one campaign, or back to the whole board. + /// Cut the tab in view down to one campaign or one tag, or back to the whole board. + /// + /// **The one place either filter is set**, which is what makes picking a tag clear a + /// campaign and picking a campaign clear a tag: they are one field, so setting either + /// is replacing whatever was there. Two setters keeping each other in step is the state + /// [`Filter`] exists to stop being representable, and this is the other half of that — + /// one writer, the way one command writes each field of a ticket. /// /// The filter is applied where the columns are built, so this reloads rather than /// filtering what is already on the tab: a filtered column is not something the @@ -1278,12 +1561,12 @@ impl Board { /// An open detail view closes, the answer hiding the done column already gives: the /// ticket it is showing may not be on the filtered board at all, and quietly swapping /// it for a different ticket is worse than closing. - pub fn select_campaign(&mut self, campaign: Option, screen: Size) { - if self.current().campaign == campaign { + pub fn select_filter(&mut self, filter: Filter, screen: Size) { + if self.current().filter == filter { return; } - self.current_mut().campaign = campaign; + self.current_mut().filter = filter; self.detail = None; self.offset = 0; // A selection kept from the unfiltered board would point at a card that is no @@ -1294,7 +1577,7 @@ impl Board { tab.offsets.iter_mut().for_each(|offset| *offset = 0); // The frame is a different campaign's now, or gone, so the selection comes back to // the cards and its prose starts at the top — the answer `refresh_detail` gives the - // overlay when the ticket under it changes. + // overlay when the ticket under it changes. A tag filter never had one. tab.focus = Focus::Cards; tab.expanded = false; tab.frame_offset = 0; @@ -1335,8 +1618,8 @@ impl Board { // itself: it is a view the reader put on and has to be able to take off. Quitting // out from under it instead is exactly what `q` used to do to an open ticket, and // the footer says which of the two this key is about to do. - if self.current().campaign.is_some() { - self.select_campaign(None, screen); + if !self.current().filter.is_whole() { + self.select_filter(Filter::Whole, screen); return; } @@ -1702,8 +1985,13 @@ fn span_of(cell: Cell) -> Span<'static> { /// so the cheapest honest place for the join is the pass that is already building the /// cards. An unreadable campaigns directory is an empty index, which leaves every card in /// no campaign and the board drawable. -fn columns_of(worklane_dir: &Path) -> (Vec, CampaignIndex) { +fn columns_of(worklane_dir: &Path) -> (Vec, CampaignIndex, TagIndex) { let campaigns = CampaignIndex::load(worklane_dir).unwrap_or_default(); + // Unreadable is an empty vocabulary here, where the CLI treats it as an error: the CLI + // is about to rewrite the file and an empty read would erase it, and the board only + // draws. A board that refused to open because of one unreadable file would be the fault + // `unwrap_or_default` on the campaigns index already avoids. + let tags = TagIndex::load(worklane_dir).unwrap_or_default(); // Over `Status::ALL` rather than the names: each column is ordered by its own entry // stamp, so the build needs the status itself and not just the directory to read. @@ -1728,7 +2016,7 @@ fn columns_of(worklane_dir: &Path) -> (Vec, CampaignIndex) { .collect(); mark_blocked(&mut columns); - (columns, campaigns) + (columns, campaigns, tags) } /// The campaigns of one board as the picker and the frame hold them. @@ -1761,6 +2049,95 @@ fn campaign_rows( .collect() } +/// The tags of one board as the picker holds them. +/// +/// The union of what the file declares and what the cards carry, which is the same union +/// `tags ls` prints and for the same reason: a declared tag nothing carries is a word the +/// board agreed on and has not used, and a carried tag nothing declares is a word somebody +/// invented in a hurry. Either one is worth being able to pick. +/// +/// Ordered by byte, which is what `BTreeMap` gives and what `worklane tags` prints in: +/// `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(); + + // Declared first, so a tag nothing carries still gets a row, at zero. + for name in tags.names() { + counts.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; + } + } + } + + counts + .into_iter() + .map(|(name, count)| TagRow { + name: name.to_string(), + annotation: tags.annotation(name).map(str::to_string), + count, + }) + .collect() +} + +/// Every board's tags as one list, for the merge tab. +/// +/// By name, unlike the campaigns on that tab, which are concatenated and each labelled with +/// the project it was filed in. A tag is the same string wherever it appears, so two boards +/// carrying `bug` are one row here and filtering to it cuts both: that is what makes a tag +/// the axis the merge tab can actually be cut along. +/// +/// The counts add. The annotation is the first one any board declares, in tab order, and a +/// tag declared differently on two boards is therefore shown as the first board means it. +/// That is a real ambiguity and this is the cheap answer to it: the alternative is a row per +/// board, which is the per-board list this function exists to avoid. +fn merged_tag_rows(per_project: &[Vec]) -> Vec { + let mut merged: BTreeMap<&str, TagRow> = BTreeMap::new(); + + for rows in per_project { + for row in rows { + match merged.get_mut(row.name.as_str()) { + Some(held) => { + held.count += row.count; + if held.annotation.is_none() { + held.annotation = row.annotation.clone(); + } + } + None => { + merged.insert(row.name.as_str(), row.clone()); + } + } + } + } + + merged.into_values().collect() +} + +/// The columns filtered to the cards carrying one tag, or left as they are when none is +/// selected. +/// +/// Matched whole and case sensitively, which is exactly how `ls --tag` matches: the board +/// and the listing must not disagree about what carrying a tag means, or the same question +/// asked two ways gives two answers. Every column is kept, empty ones included, for the +/// reason `retain_campaign` keeps them. +fn retain_tag(mut columns: Vec, tag: Option<&str>) -> Vec { + let Some(tag) = tag else { + return columns; + }; + + for column in columns.iter_mut() { + column + .cards + .retain(|card| card.ticket.tags.iter().any(|held| held == tag)); + } + + columns +} + /// How far every campaign on one board has got, counted in one pass over its cards. /// /// The cards are already in hand here, and a campaign's members are exactly the cards @@ -1949,6 +2326,20 @@ fn digest_of(projects: &[Project]) -> u64 { pub fn digest(worklane_dir: &Path) -> u64 { let mut entries: Vec<(String, u64, Duration)> = Vec::new(); + // The vocabulary, for the reason the campaigns are: a tag declared elsewhere has to + // reach the picker, and an annotation changed by `tags set` has to reach the row that + // draws it. One file rather than a directory, so it is stamped here rather than visited, + // and stamped before the walk so the closure below owns the borrow uncontested. + let vocabulary = worklane_dir.join(TAGS_FILE); + if let Ok(meta) = std::fs::metadata(&vocabulary) { + let modified = meta + .modified() + .ok() + .and_then(|at| at.duration_since(SystemTime::UNIX_EPOCH).ok()) + .unwrap_or_default(); + entries.push((vocabulary.to_string_lossy().to_string(), meta.len(), modified)); + } + let mut visit = |dir: PathBuf| { let Ok(read) = std::fs::read_dir(&dir) else { return; @@ -2774,19 +3165,23 @@ fn draw_footer(frame: &mut Frame, board: &Board, area: Rect) { // answer is `ctrl-c`, the only key left that quits in one press. Naming `q quit` over // either would be the fault 1b78a24 was, a footer describing a key by what it used to // do — and with a campaign selected it names what that press actually does instead. - let quit = match board.detail.is_some() || board.campaign().is_some() { + let quit = match board.detail.is_some() || !board.current().filter.is_whole() { true => "ctrl-c quit", false => "q quit", }; - // `c` is named where a reader has to find it: on the board, with nothing selected. Over - // an open ticket and on a board already filtered to a campaign it is left out, because - // the frame's own border then says how to put the campaign away and the row is at its - // width naming eight keys. Incomplete rather than wrong, which is the trade this row is - // allowed to make: what it must never do is name a key by what it used to do. - let campaign = match board.campaign().is_some() { - true => "", - false => "c campaign ", + // The two filters share a slot, because with one on the row has the same thing to say + // whichever it is: how to take it off, rather than how to put another on. + // + // `c` and `t` are named where a reader has to find them: on the board, with nothing + // filtered. A campaign says how to leave on its own frame border, so the slot is spent + // on nothing there and the row is not at its width naming nine keys. A tag has no frame + // to say it, so the row does, and the tag itself is drawn ahead of the keys below — + // otherwise nothing on a filtered board would say why its cards are missing. + let filter = match board.current().filter { + Filter::Whole => "c campaign t tag ", + Filter::Campaign(_) => "", + Filter::Tag(_) => "q board ", }; // Three states, because the frame is a third place the selection can be and the row @@ -2816,14 +3211,21 @@ fn draw_footer(frame: &mut Frame, board: &Board, area: Rect) { " {tabs}↓ board {height} pgup/pgdn scroll / search y copy id {done} {quit} " ), (false, Focus::Cards) => format!( - " {tabs}←→ column ↑↓ card / search {campaign}y copy id enter detail {done} {quit} " + " {tabs}←→ column ↑↓ card / search {filter}y copy id enter detail {done} {quit} " ), }; - frame.render_widget( - Paragraph::new(Span::styled(keys, Style::default().fg(Color::Grey.into()))), - area, - ); + // The tag the board is filtered to, in its own colour, ahead of the keys. A span of its + // own rather than a word inside the key string, because the keys are grey and a tag is + // drawn in a `TAG_COLORS` slot or it is drawn wrong: grey already means what a reader + // skips, which is the opposite of what this word is doing there. + let mut spans = Vec::new(); + if let Some(tag) = board.current().filter.tag() { + spans.push(Span::styled(format!(" {tag}"), Style::default().fg(tag_color(tag).into()))); + } + spans.push(Span::styled(keys, Style::default().fg(Color::Grey.into()))); + + frame.render_widget(Paragraph::new(Line::from(spans)), area); } /// What the last keypress did, where the keys would otherwise be. @@ -3007,19 +3409,29 @@ fn draw_picker(frame: &mut Frame, tab: &Tab, picker: &Picker, area: Rect) { /// cuts the list down makes the total alone a lie about what is on screen, so it says both /// — and the reader can see at a glance whether the query is narrow enough. fn picker_title(tab: &Tab, picker: &Picker) -> String { - let total = tab.campaigns.len(); let query = picker.query.as_deref().unwrap_or_default(); + + let (what, total, found) = match picker.kind { + PickerKind::Campaign => ( + "campaigns", + tab.campaigns.len(), + tab.campaigns + .iter() + .filter(|campaign| picker_matches(campaign, query)) + .count(), + ), + PickerKind::Tag => ( + "tags", + tab.tags.len(), + tab.tags.iter().filter(|tag| tag_matches(tag, query)).count(), + ), + }; + if query.trim().is_empty() { - return format!(" campaigns ({total}) "); + return format!(" {what} ({total}) "); } - let found = tab - .campaigns - .iter() - .filter(|campaign| picker_matches(campaign, query)) - .count(); - - format!(" campaigns ({found} of {total}) ") + format!(" {what} ({found} of {total}) ") } /// One drawn row: a campaign, a section heading, the truncation line, or the miss. @@ -3033,6 +3445,7 @@ fn picker_row_line(row: &PickerRow, selected: bool, width: u16) -> Line<'static> match row { PickerRow::Campaign(campaign) => picker_line(campaign, selected, width), + PickerRow::Tag(tag) => tag_picker_line(tag, selected, width), PickerRow::Heading(name) => { Line::from(Span::styled((*name).to_string(), grey.add_modifier(Modifier::BOLD))) } @@ -3059,6 +3472,53 @@ fn hidden_line(count: usize) -> String { format!("… {count} older completed {campaigns} hidden") } +/// One tag row: `bug 23 What the tag means`. +/// +/// 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 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. +fn tag_picker_line(tag: &TagRow, selected: bool, width: u16) -> Line<'static> { + let emphasis = match selected { + true => Modifier::REVERSED, + false => Modifier::empty(), + }; + 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 used = spans_width(&spans); + let summary = tag.summary(); + if !summary.is_empty() + && let Some(room) = (width as usize).checked_sub(used + 2).filter(|room| *room >= 3) + { + let cut = match summary.chars().count() <= room { + true => summary.to_string(), + false => with_ellipsis(summary, room), + }; + spans.push(Span::raw(" ")); + spans.push(Span::styled(cut, grey)); + } + + Line::from(spans) +} + /// One picker row: `(1b78a24) ~beaver What the campaign is for`. /// /// The highlight is `REVERSED`, the way a selected card is, so the row reads the same @@ -6714,7 +7174,7 @@ mod tests { /// The uuid the highlight is on, so a test can name it without reaching for a row /// number the sections have already moved. fn highlighted(board: &Board) -> Option { - board.picker_highlight().map(|campaign| campaign.uuid.clone()) + board.picked() } /// Which drawn row is exactly this heading, since a heading is the whole of its row. @@ -6797,6 +7257,386 @@ mod tests { .collect() } + // ------------------------------------------------------- the tag picker -- + + /// A ticket carrying `tags`, in `status`, so a test can build a board with a vocabulary + /// spread across the columns. + fn write_tag_ticket(dir: &Path, status: &str, uuid: &str, title: &str, tags: &str) { + std::fs::write( + dir.join(status).join(format!("{}_{}.md", uuid, slug(title))), + format!( + "# {title}\n\n## Description\nA description.\n\n## Metadata\n\n\ + - **ID**: {uuid}\n- **Priority**: 2\n- **Tags**: {tags}\n\ + - **Due**: _Not set_\n- **Owner**: alice\n\ + - **Created At**: 2026-08-21 02:00:00\n- **Status**: {status}\n" + ), + ) + .unwrap(); + } + + /// The vocabulary file, written the way `tags add` writes it. + fn write_vocabulary(dir: &Path, declared: &[(&str, &str)]) { + let mut index = TagIndex::default(); + for (tag, annotation) in declared { + index.declare(tag, annotation); + } + std::fs::write(dir.join(TAGS_FILE), index.render()).unwrap(); + } + + /// Three tags across three columns, two of them declared: `bug` and `cli` are in the + /// vocabulary, `sync` is a word somebody typed onto a ticket, and `chore` is declared + /// and carried by nothing. + fn tag_board(dir: &Path) -> Board { + write_tag_ticket(dir, "backlog", "11111111-0000-4000-8000-000000000000", "One", "bug,cli"); + write_tag_ticket(dir, "committed", "22222222-0000-4000-8000-000000000000", "Two", "bug"); + write_tag_ticket(dir, "done", "33333333-0000-4000-8000-000000000000", "Three", "sync"); + write_vocabulary( + dir, + &[ + ("bug", "Behaviour that contradicts what the tool says."), + ("chore", "Work with nothing to see."), + ("cli", "The command line surface."), + ], + ); + + one_board(dir) + } + + /// The tag rows of an open picker, without the chrome around them. + fn open_tag_picker(board: &mut Board) -> Vec { + board.open_picker(PickerKind::Tag, SCREEN); + picker_rows(board, SCREEN.width, SCREEN.height) + .into_iter() + .map(|row| row.trim_end().to_string()) + .filter(|row| !row.is_empty()) + .collect() + } + + /// The board could be cut by campaign and not by the other axis it has always had. + #[test] + fn the_tag_picker_lists_every_tag_the_board_declares_or_carries() { + let dir = board_dir(); + let mut board = tag_board(&dir); + + let rows = open_tag_picker(&mut board); + + assert_eq!( + 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", + ], + "the picker does not list the vocabulary" + ); + } + + /// The split is the point of the list: a word nobody agreed on sits under the ones that + /// were, which is where `campaign` against `campaigns` would have been caught. + #[test] + fn an_undeclared_tag_sits_in_its_own_section() { + let dir = board_dir(); + let mut board = tag_board(&dir); + + let rows = open_tag_picker(&mut board); + let declared = rows + .iter() + .position(|row| row == "declared") + .expect("no declared heading"); + let undeclared = rows + .iter() + .position(|row| row == "undeclared") + .expect("no undeclared heading"); + + assert!(declared < undeclared, "the sections are the wrong way round: {rows:?}"); + assert!( + rows.iter().skip(undeclared).any(|row| row.starts_with("sync")), + "the carried tag is not under the undeclared heading: {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() { + let dir = board_dir(); + let mut board = tag_board(&dir); + board.show_done = true; + + board.select_filter(Filter::Tag("bug".to_string()), SCREEN); + + let headings = headings(&board, 120, 20); + assert!(headings.contains("backlog (1)"), "{headings}"); + assert!(headings.contains("committed (1)"), "{headings}"); + assert!(headings.contains("done (0)"), "{headings}"); + } + + /// Case sensitively, exactly as `--tag` matches, or the same question asked on the board + /// and at the command line gives two answers. + #[test] + fn a_tag_filter_keeps_case_apart_the_way_the_listing_does() { + let dir = board_dir(); + write_tag_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "One", "bug"); + write_tag_ticket(&dir, "backlog", "22222222-0000-4000-8000-000000000000", "Two", "Bug"); + let mut board = one_board(&dir); + + board.select_filter(Filter::Tag("bug".to_string()), SCREEN); + assert!(headings(&board, 120, 20).contains("backlog (1)"), "case was folded"); + } + + /// 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. + #[test] + fn a_declared_tag_nothing_carries_can_be_picked_and_empties_the_board() { + let dir = board_dir(); + let mut board = tag_board(&dir); + + board.select_filter(Filter::Tag("chore".to_string()), SCREEN); + + assert!(headings(&board, 120, 20).contains("backlog (0)"), "the filter was refused"); + assert_eq!( + board.current().filter.tag(), + Some("chore"), + "the filter came off with nothing to show" + ); + } + + /// A board that predates the vocabulary still has tags, and every one of them is a word + /// nobody declared. + #[test] + fn a_board_with_no_vocabulary_lists_every_tag_as_undeclared() { + let dir = board_dir(); + write_tag_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "One", "bug,cli"); + let mut board = one_board(&dir); + + let rows = open_tag_picker(&mut board); + + assert_eq!(rows, vec!["undeclared", "bug 1", "cli 1"], "{rows:?}"); + } + + /// The query reads the annotation as well as the tag, which is the rule the campaign + /// picker follows: a row is searched by what it draws. A reader who cannot remember the + /// word can often remember what it was for. + #[test] + fn the_tag_query_matches_the_annotation_as_well_as_the_tag() { + let dir = board_dir(); + let mut board = tag_board(&dir); + board.open_picker(PickerKind::Tag, SCREEN); + + for typed in "contradicts".chars() { + board.picker_key(KeyEvent::new(KeyCode::Char(typed), KeyModifiers::NONE), SCREEN); + } + board.picker_key(KeyEvent::new(KeyCode::Char('/'), KeyModifiers::NONE), SCREEN); + for typed in "contradicts".chars() { + board.picker_key(KeyEvent::new(KeyCode::Char(typed), KeyModifiers::NONE), SCREEN); + } + + let rows: Vec = picker_rows(&board, SCREEN.width, SCREEN.height) + .into_iter() + .map(|row| row.trim_end().to_string()) + .filter(|row| !row.is_empty()) + .collect(); + assert_eq!( + rows, + vec![ + "declared", + "bug 2 Behaviour that contradicts what the tool says." + ] + ); + } + + /// `esc` takes the query off before it takes the picker off, one layer at a time, the + /// order `dismiss` closes the board's own layers in. Shared machinery, tested here too + /// because it is a criterion of the tag picker and not only of the campaign one. + #[test] + fn esc_clears_the_tag_query_before_it_closes_the_picker() { + let dir = board_dir(); + let mut board = tag_board(&dir); + board.open_picker(PickerKind::Tag, SCREEN); + + board.picker_key(KeyEvent::new(KeyCode::Char('/'), KeyModifiers::NONE), SCREEN); + board.picker_key(KeyEvent::new(KeyCode::Char('b'), KeyModifiers::NONE), SCREEN); + let rows: Vec = picker_rows(&board, SCREEN.width, SCREEN.height) + .into_iter() + .map(|row| row.trim_end().to_string()) + .filter(|row| !row.is_empty()) + .collect(); + assert_eq!(rows.len(), 2, "the query did not filter the rows: {rows:?}"); + + board.picker_key(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE), SCREEN); + assert!(board.picker.is_some(), "esc closed the picker with a query open"); + assert!( + board + .picker + .as_ref() + .is_some_and(|picker| picker.query.is_none()), + "the query survived esc" + ); + + board.picker_key(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE), SCREEN); + assert!(board.picker.is_none(), "the second esc left the picker open"); + assert!(board.current().filter.is_whole(), "esc filtered the board"); + } + + /// One filter at a time, which is what `Filter` makes true rather than what two setters + /// remember: the frame above the columns names what they are, and it has one thing to + /// say. + #[test] + fn picking_a_tag_clears_a_campaign_and_picking_a_campaign_clears_a_tag() { + let dir = board_dir(); + write_campaign(&dir, V1, "First public release", "v1", "For a public tag."); + write_member_card(&dir, "Short", "cli", V1); + let mut board = one_board(&dir); + + board.select_filter(Filter::Campaign(V1.to_string()), SCREEN); + board.select_filter(Filter::Tag("cli".to_string()), SCREEN); + assert_eq!(board.current().filter.campaign(), None, "the campaign survived a tag"); + assert_eq!(board.current().filter.tag(), Some("cli")); + + board.select_filter(Filter::Campaign(V1.to_string()), SCREEN); + assert_eq!(board.current().filter.tag(), None, "the tag survived a campaign"); + assert_eq!(board.current().filter.campaign(), Some(V1)); + } + + /// A tag that leaves the board altogether takes its filter with it, the answer a + /// campaign that leaves already gets: a filter on a word nothing declares and nothing + /// carries would empty every column and say nothing about why. Being carried by nothing + /// is not the same thing, which is the case above. + #[test] + fn a_tag_that_leaves_the_vocabulary_gives_the_whole_board_back() { + let dir = board_dir(); + let path = dir + .join("backlog") + .join(format!("{}_{}.md", "11111111-0000-4000-8000-000000000000", "one")); + write_tag_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "One", "bug"); + let mut board = one_board(&dir); + board.select_filter(Filter::Tag("bug".to_string()), SCREEN); + + // The only ticket carrying it, and no vocabulary declaring it: the word is gone. + std::fs::remove_file(&path).unwrap(); + board.tick().unwrap(); + + assert!(board.current().filter.is_whole(), "the filter outlived its tag"); + } + + /// `q` takes off whatever view is on, and a tag filter is one, the way a campaign is. + #[test] + fn q_gives_the_whole_board_back_from_a_tag() { + let dir = board_dir(); + let mut board = tag_board(&dir); + board.select_filter(Filter::Tag("bug".to_string()), SCREEN); + + board.dismiss(SCREEN); + + assert!(board.current().filter.is_whole(), "the filter survived q"); + assert!(!board.should_quit, "q quit out from under the filter"); + } + + /// A tag draws no frame yet, 2a83bd4, so nothing above the columns can hold the + /// selection: `up` from the top card must not reach a frame that is not there. + #[test] + fn a_tag_filter_draws_no_frame_and_cannot_hold_the_selection() { + let dir = board_dir(); + let mut board = tag_board(&dir); + board.select_filter(Filter::Tag("bug".to_string()), SCREEN); + + assert_eq!(board.chrome().campaign, None, "a tag drew a campaign frame"); + + board.select_card(-1, SCREEN); + assert_eq!(board.current().focus, Focus::Cards, "the selection left the cards"); + } + + /// The row names both filters where a reader has to find them, and says how to leave a + /// tag: the campaign frame says it on its own border and a tag has no frame to say it. + #[test] + fn the_footer_names_the_tag_key_and_the_way_back() { + let dir = board_dir(); + let mut board = tag_board(&dir); + + let plain = footer(&board, 120, 20); + assert!(plain.contains("t tag"), "the tag key is not named: {plain}"); + assert!(plain.contains("c campaign"), "{plain}"); + + board.select_filter(Filter::Tag("bug".to_string()), SCREEN); + let filtered = footer(&board, 120, 20); + assert!(filtered.contains("bug"), "the filter does not say what it is: {filtered}"); + assert!(filtered.contains("q board"), "the way back is not named: {filtered}"); + assert!(filtered.contains("ctrl-c quit"), "{filtered}"); + } + + /// A tag is a string and the same string on every board, so the merge tab carries one + /// row per word and filtering to it cuts every project at once. A campaign cannot do + /// this: its uuid resolves inside one `.worklane`. + #[test] + fn a_tag_on_the_merge_tab_reaches_every_board() { + let first = board_dir(); + let second = board_dir(); + write_tag_ticket(&first, "backlog", "11111111-0000-4000-8000-000000000000", "One", "bug"); + write_tag_ticket(&second, "backlog", "22222222-0000-4000-8000-000000000000", "Two", "bug"); + write_vocabulary(&first, &[("bug", "Something wrong.")]); + + let mut board = boards(&[("first", &first), ("second", &second)]); + + let rows = open_tag_picker(&mut board); + assert_eq!( + rows, + vec!["declared", "bug 2 Something wrong."], + "the tags did not merge" + ); + + board.picker = None; + board.select_filter(Filter::Tag("bug".to_string()), SCREEN); + assert!(headings(&board, 120, 20).contains("backlog (2)"), "one board was left out"); + } + + /// The vocabulary is read on the tick like everything else the board draws, so a tag + /// declared elsewhere reaches an open picker rather than a copy of the list taken when + /// it opened. + #[test] + fn declaring_a_tag_elsewhere_changes_the_digest() { + let dir = board_dir(); + write_tag_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "One", "bug"); + + let before = digest(&dir); + write_vocabulary(&dir, &[("bug", "Something wrong.")]); + + assert_ne!(before, digest(&dir), "the vocabulary is outside the digest"); + } + + /// A board with no tags at all says so in words rather than opening an empty box, the + /// answer the campaign picker already gives. + #[test] + fn a_board_with_no_tags_says_so_rather_than_opening_an_empty_picker() { + let dir = board_dir(); + write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "Untagged", ""); + let mut board = one_board(&dir); + + board.open_picker(PickerKind::Tag, SCREEN); + + assert!(board.picker.is_none(), "an empty picker opened"); + let notice = board.notice.as_ref().expect("nothing was said"); + assert!(notice.text.contains("no tags"), "{}", notice.text); + assert!(notice.failed, "the notice did not read as a key that did nothing"); + } + + /// `t` has to reach the tag picker from the dispatch, which is not reachable from a + /// test: the arm is the only place the binding exists. + #[test] + fn the_dispatch_binds_t_to_the_tag_picker() { + let source = include_str!("main.rs") + .split_whitespace() + .collect::>() + .join(" "); + + assert!( + source + .contains("KeyCode::Char('t') => board.open_picker(tui::PickerKind::Tag, screen),"), + "`t` has to reach the tag picker, and it is the only way in to it" + ); + } + /// The card said nothing about which release a ticket belonged to, which is the one /// thing a board is read to decide. #[test] @@ -6955,7 +7795,7 @@ mod tests { let all: usize = board.current().columns.iter().map(|c| c.cards.len()).sum(); assert_eq!(all, 4, "the fixture changed"); - board.select_campaign(Some(V1.to_string()), SCREEN); + board.select_filter(Filter::Campaign(V1.to_string()), SCREEN); let titles: Vec = board .current() @@ -6974,7 +7814,7 @@ mod tests { fn the_frame_names_the_campaign_and_its_standing() { let dir = board_dir(); let mut board = campaign_board(&dir); - board.select_campaign(Some(V1.to_string()), SCREEN); + board.select_filter(Filter::Campaign(V1.to_string()), SCREEN); let rows = frame_lines(&board, 100, 24); assert_eq!( @@ -7020,7 +7860,7 @@ mod tests { ); let mut board = one_board(&dir); - board.select_campaign(Some(V1.to_string()), SCREEN); + board.select_filter(Filter::Campaign(V1.to_string()), SCREEN); assert!(!board.show_done, "done is hidden at startup"); let standing = board.campaign().expect("no campaign selected").standing; @@ -7037,7 +7877,7 @@ mod tests { let screen = Size { width: 100, height: 24 }; let plain = board_area(screen, board.chrome()); - board.select_campaign(Some(V1.to_string()), screen); + board.select_filter(Filter::Campaign(V1.to_string()), screen); let framed = board_area(screen, board.chrome()); assert_eq!(framed.y, plain.y + Chrome::CAMPAIGN_ROWS, "the columns did not move down"); @@ -7068,7 +7908,7 @@ mod tests { write_campaign(dir, V1, "First public release", "v1", &long_description(lines)); let mut board = one_board(dir); - board.select_campaign(Some(V1.to_string()), SCREEN); + board.select_filter(Filter::Campaign(V1.to_string()), SCREEN); board } @@ -7226,7 +8066,7 @@ mod tests { ); let mut board = one_board(&dir); - board.select_campaign(Some(V1.to_string()), SCREEN); + board.select_filter(Filter::Campaign(V1.to_string()), SCREEN); board.toggle_detail(); assert!(board.detail.is_some(), "nothing opened"); @@ -7288,7 +8128,7 @@ mod tests { fn a_description_that_fits_leaves_the_frame_selectable_and_the_keys_inert() { let dir = board_dir(); let mut board = campaign_board(&dir); - board.select_campaign(Some(V1.to_string()), SCREEN); + board.select_filter(Filter::Campaign(V1.to_string()), SCREEN); board.select_card(-1, SCREEN); assert_eq!(board.current().focus, Focus::Frame, "the short frame was unreachable"); @@ -7319,7 +8159,7 @@ mod tests { ); let mut board = one_board(&dir); - board.select_campaign(Some(V1.to_string()), SCREEN); + board.select_filter(Filter::Campaign(V1.to_string()), SCREEN); let rows = frame_lines(&board, 120, 20); assert!( @@ -7421,7 +8261,7 @@ mod tests { board.select_card(-1, SCREEN); board.dismiss(SCREEN); - assert_eq!(board.current().campaign, None, "the campaign is still selected"); + assert_eq!(board.current().filter.campaign(), None, "the campaign is still selected"); assert_eq!( board.current().focus, Focus::Cards, @@ -7473,7 +8313,7 @@ mod tests { write_ticket(&two, "backlog", "77777777-0000-4000-8000-000000000000", "Elsewhere", ""); let mut board = boards(&[("one", &one), ("two", &two)]); - board.select_campaign(Some(V1.to_string()), SCREEN); + board.select_filter(Filter::Campaign(V1.to_string()), SCREEN); board.select_card(-1, SCREEN); board.scroll_page(1, SCREEN); @@ -7500,7 +8340,7 @@ mod tests { board.scroll_page(1, SCREEN); assert!(board.current().frame_offset > 0, "nothing scrolled"); - board.select_campaign(Some(BEAVER.to_string()), SCREEN); + board.select_filter(Filter::Campaign(BEAVER.to_string()), SCREEN); assert_eq!(board.current().frame_offset, 0, "the new campaign opened partway down"); assert_eq!(board.current().focus, Focus::Cards, "the selection stayed on the frame"); } @@ -7703,7 +8543,7 @@ mod tests { fn a_short_description_still_expands_the_frame() { let dir = board_dir(); let mut board = campaign_board(&dir); - board.select_campaign(Some(V1.to_string()), SCREEN); + board.select_filter(Filter::Campaign(V1.to_string()), SCREEN); board.select_card(-1, SCREEN); board.toggle_focused(SCREEN); @@ -7726,7 +8566,7 @@ mod tests { assert!(board.current().expanded, "nothing expanded"); board.dismiss(SCREEN); - assert_eq!(board.current().campaign, None, "q was spent collapsing the frame"); + assert_eq!(board.current().filter.campaign(), None, "q was spent collapsing the frame"); assert!(!board.current().expanded, "the height outlived the frame"); assert!(!board.should_quit, "the board quit out from under the frame"); @@ -7813,7 +8653,7 @@ mod tests { write_ticket(&two, "backlog", "77777777-0000-4000-8000-000000000000", "Elsewhere", ""); let mut board = boards(&[("one", &one), ("two", &two)]); - board.select_campaign(Some(V1.to_string()), SCREEN); + board.select_filter(Filter::Campaign(V1.to_string()), SCREEN); board.select_card(-1, SCREEN); board.toggle_focused(SCREEN); assert!(board.current().expanded, "nothing expanded"); @@ -7835,7 +8675,7 @@ mod tests { board.select_card(-1, SCREEN); board.toggle_focused(SCREEN); - board.select_campaign(Some(BEAVER.to_string()), SCREEN); + board.select_filter(Filter::Campaign(BEAVER.to_string()), SCREEN); assert!(!board.current().expanded, "the new campaign opened at half the board"); assert_eq!(frame_height(&board, SCREEN), Chrome::CAMPAIGN_ROWS); } @@ -7861,7 +8701,7 @@ mod tests { "the campaign file is not watched" ); - assert_eq!(board.current().campaign, None, "the filter survived its campaign"); + assert_eq!(board.current().filter.campaign(), None, "the filter survived its campaign"); assert_eq!( board.current().focus, Focus::Cards, @@ -7877,10 +8717,10 @@ mod tests { fn dismiss_takes_off_the_campaign_before_the_board() { let dir = board_dir(); let mut board = campaign_board(&dir); - board.select_campaign(Some(V1.to_string()), SCREEN); + board.select_filter(Filter::Campaign(V1.to_string()), SCREEN); board.dismiss(SCREEN); - assert_eq!(board.current().campaign, None, "the campaign is still selected"); + assert_eq!(board.current().filter.campaign(), None, "the campaign is still selected"); assert!(!board.should_quit, "the board quit out from under the filter"); // And the whole board is back, not an empty one. let all: usize = board.current().columns.iter().map(|c| c.cards.len()).sum(); @@ -7895,13 +8735,13 @@ mod tests { fn dismiss_closes_the_overlay_before_the_campaign() { let dir = board_dir(); let mut board = campaign_board(&dir); - board.select_campaign(Some(V1.to_string()), SCREEN); + board.select_filter(Filter::Campaign(V1.to_string()), SCREEN); board.toggle_detail(); assert!(board.detail.is_some(), "nothing opened"); board.dismiss(SCREEN); assert!(board.detail.is_none(), "the overlay stayed open"); - assert_eq!(board.current().campaign, Some(V1.to_string()), "the filter came off too"); + assert_eq!(board.current().filter.campaign(), Some(V1), "the filter came off too"); } /// Selecting a campaign closes an open ticket, the answer hiding the done column @@ -7914,7 +8754,7 @@ mod tests { board.toggle_detail(); assert!(board.detail.is_some(), "nothing opened"); - board.select_campaign(Some(BEAVER.to_string()), SCREEN); + board.select_filter(Filter::Campaign(BEAVER.to_string()), SCREEN); assert!(board.detail.is_none(), "the overlay survived the filter"); } @@ -7925,7 +8765,7 @@ mod tests { fn the_picker_swallows_every_key_it_is_given() { let dir = board_dir(); let mut board = campaign_board(&dir); - board.open_picker(); + board.open_picker(PickerKind::Campaign, SCREEN); for code in [KeyCode::Char('d'), KeyCode::Char('y'), KeyCode::Char('/')] { assert!( @@ -7953,7 +8793,7 @@ mod tests { fn the_picker_declines_ctrl_c() { let dir = board_dir(); let mut board = campaign_board(&dir); - board.open_picker(); + board.open_picker(PickerKind::Campaign, SCREEN); assert!( !board.picker_key(KeyEvent::new(KeyCode::Char('c'), KeyModifiers::CONTROL), SCREEN) @@ -7965,7 +8805,7 @@ mod tests { fn enter_in_the_picker_takes_the_highlighted_campaign() { let dir = board_dir(); let mut board = campaign_board(&dir); - board.open_picker(); + board.open_picker(PickerKind::Campaign, SCREEN); // By title, which is the index's order, so the first row is Beaver migration. let first = board.current().campaigns[0].uuid.clone(); @@ -7973,7 +8813,7 @@ mod tests { board.picker_key(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE), SCREEN); assert!(board.picker.is_none(), "the picker stayed open"); - assert_eq!(board.current().campaign, Some(BEAVER.to_string())); + assert_eq!(board.current().filter.campaign(), Some(BEAVER)); } /// Esc leaves the board exactly as it was, so opening the list is never a commitment. @@ -7981,13 +8821,13 @@ mod tests { fn esc_in_the_picker_changes_nothing() { let dir = board_dir(); let mut board = campaign_board(&dir); - board.select_campaign(Some(V1.to_string()), SCREEN); - board.open_picker(); + board.select_filter(Filter::Campaign(V1.to_string()), SCREEN); + board.open_picker(PickerKind::Campaign, SCREEN); board.picker_key(KeyEvent::new(KeyCode::Down, KeyModifiers::NONE), SCREEN); board.picker_key(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE), SCREEN); assert!(board.picker.is_none(), "the picker stayed open"); - assert_eq!(board.current().campaign, Some(V1.to_string()), "the filter moved"); + assert_eq!(board.current().filter.campaign(), Some(V1), "the filter moved"); } /// It opens on the campaign already selected, so `c` on a filtered board says where @@ -7996,13 +8836,10 @@ mod tests { fn the_picker_opens_on_the_campaign_in_view() { let dir = board_dir(); let mut board = campaign_board(&dir); - board.select_campaign(Some(V1.to_string()), SCREEN); - board.open_picker(); + board.select_filter(Filter::Campaign(V1.to_string()), SCREEN); + board.open_picker(PickerKind::Campaign, SCREEN); - let highlighted = board - .picker_highlight() - .expect("the highlight is on no campaign"); - assert_eq!(highlighted.uuid, V1); + assert_eq!(board.picked().as_deref(), Some(V1), "the highlight is on no campaign"); } /// A board with no campaigns says so in words rather than opening an empty box that @@ -8013,7 +8850,7 @@ mod tests { write_member_card(&dir, "Short", "cli", NOT_SET); let mut board = one_board(&dir); - board.open_picker(); + board.open_picker(PickerKind::Campaign, SCREEN); assert!(board.picker.is_none(), "an empty picker opened"); let notice = board.notice.as_ref().expect("nothing was said"); @@ -8027,7 +8864,7 @@ mod tests { fn the_picker_rows_name_the_id_the_codename_and_the_description() { let dir = board_dir(); let mut board = campaign_board(&dir); - board.open_picker(); + board.open_picker(PickerKind::Campaign, SCREEN); let rows = picker_rows(&board, 100, 24); let row = rows @@ -8051,7 +8888,7 @@ mod tests { write_member_card(&dir, "Short", "cli", V1); let mut board = one_board(&dir); - board.open_picker(); + board.open_picker(PickerKind::Campaign, SCREEN); let rows = picker_rows(&board, 100, 24); let row = rows @@ -8091,12 +8928,12 @@ mod tests { fn a_campaign_that_leaves_the_board_returns_the_tab_to_it() { let dir = board_dir(); let mut board = campaign_board(&dir); - board.select_campaign(Some(V1.to_string()), SCREEN); + board.select_filter(Filter::Campaign(V1.to_string()), SCREEN); std::fs::remove_dir_all(dir.join(CAMPAIGNS_DIR)).unwrap(); board.reload().unwrap(); - assert_eq!(board.current().campaign, None, "the filter outlived its campaign"); + assert_eq!(board.current().filter.campaign(), None, "the filter outlived its campaign"); let all: usize = board.current().columns.iter().map(|c| c.cards.len()).sum(); assert_eq!(all, 4, "the board stayed filtered to nothing"); } @@ -8108,7 +8945,7 @@ mod tests { fn the_picker_draws_open_campaigns_above_completed() { let dir = board_dir(); let mut board = tail_board(&dir); - board.open_picker(); + board.open_picker(PickerKind::Campaign, SCREEN); let rows = picker_rows(&board, 100, 24); let open = row_at(&rows, OPEN_SECTION); @@ -8133,7 +8970,7 @@ mod tests { fn a_campaign_is_completed_only_when_it_holds_members_and_every_one_is_done() { let dir = board_dir(); let mut board = tail_board(&dir); - board.open_picker(); + board.open_picker(PickerKind::Campaign, SCREEN); let campaigns = &board.current().campaigns; let beaver = campaigns @@ -8165,7 +9002,7 @@ mod tests { fn the_completed_section_keeps_the_most_recent_and_names_what_it_hid() { let dir = board_dir(); let mut board = tail_board(&dir); - board.open_picker(); + board.open_picker(PickerKind::Campaign, SCREEN); let rows = picker_rows(&board, 100, 24); // By `Created At` newest first, and not by title: "Disk migration" and "Log rework" @@ -8207,7 +9044,7 @@ mod tests { fn a_query_filters_the_picker_by_id_codename_and_title() { let dir = board_dir(); let mut board = tail_board(&dir); - board.open_picker(); + board.open_picker(PickerKind::Campaign, SCREEN); // The codename, in the wrong case, since a query that has to be typed exactly is // not worth typing. @@ -8216,13 +9053,13 @@ mod tests { // The title, in the middle of it. board.picker = None; - board.open_picker(); + board.open_picker(PickerKind::Campaign, SCREEN); type_picker_query(&mut board, "public rel"); assert_eq!(picked_ids(&board), vec![V1.to_string()], "the title missed"); // And the short id the row opens with. board.picker = None; - board.open_picker(); + board.open_picker(PickerKind::Campaign, SCREEN); type_picker_query(&mut board, short_id(FINISHED[3].0)); assert_eq!(picked_ids(&board), vec![FINISHED[3].0.to_string()], "the id missed"); } @@ -8233,7 +9070,7 @@ mod tests { fn a_query_does_not_match_the_summary_the_row_draws() { let dir = board_dir(); let mut board = tail_board(&dir); - board.open_picker(); + board.open_picker(PickerKind::Campaign, SCREEN); // Beaver's summary reads "Move the store off one disk." and its title does not. type_picker_query(&mut board, "disk"); @@ -8246,7 +9083,7 @@ mod tests { fn a_query_finds_the_completed_campaigns_the_truncation_hid() { let dir = board_dir(); let mut board = tail_board(&dir); - board.open_picker(); + board.open_picker(PickerKind::Campaign, SCREEN); let hidden = FINISHED[0].0; assert!( @@ -8275,7 +9112,7 @@ mod tests { fn the_query_takes_q_and_esc_closes_it_before_the_picker() { let dir = board_dir(); let mut board = tail_board(&dir); - board.open_picker(); + board.open_picker(PickerKind::Campaign, SCREEN); type_picker_query(&mut board, "q"); assert!(board.picker.is_some(), "q closed the picker"); @@ -8300,7 +9137,7 @@ mod tests { fn enter_under_a_query_takes_the_highlighted_campaign() { let dir = board_dir(); let mut board = tail_board(&dir); - board.open_picker(); + board.open_picker(PickerKind::Campaign, SCREEN); type_picker_query(&mut board, "beav"); assert_eq!( @@ -8311,7 +9148,7 @@ mod tests { press(&mut board, KeyCode::Enter); assert!(board.picker.is_none(), "the picker stayed open"); - assert_eq!(board.current().campaign, Some(BEAVER.to_string())); + assert_eq!(board.current().filter.campaign(), Some(BEAVER)); } /// A query that matches nothing keeps the picker and the query open, and says so in the @@ -8321,7 +9158,7 @@ mod tests { fn a_query_that_matches_nothing_keeps_the_picker_and_the_query_open() { let dir = board_dir(); let mut board = tail_board(&dir); - board.open_picker(); + board.open_picker(PickerKind::Campaign, SCREEN); type_picker_query(&mut board, "zzz"); let rows = picker_rows(&board, 100, 24); @@ -8331,7 +9168,7 @@ mod tests { press(&mut board, KeyCode::Enter); assert!(board.picker.is_some(), "enter on a miss closed the picker"); assert_eq!(query_of(&board).as_deref(), Some("zzz"), "the query was taken away"); - assert_eq!(board.current().campaign, None, "a miss selected something"); + assert_eq!(board.current().filter.campaign(), None, "a miss selected something"); } /// Section headings and the truncation line take no number: they are not campaigns, so @@ -8340,7 +9177,7 @@ mod tests { fn the_highlight_moves_over_campaigns_and_never_onto_the_chrome() { let dir = board_dir(); let mut board = tail_board(&dir); - board.open_picker(); + board.open_picker(PickerKind::Campaign, SCREEN); // It opens on the first campaign, not on the heading above it. assert_eq!(board.picker.as_ref().expect("no picker").row, 1); @@ -8382,7 +9219,7 @@ mod tests { fn the_highlight_follows_its_campaign_through_a_query() { let dir = board_dir(); let mut board = tail_board(&dir); - board.open_picker(); + board.open_picker(PickerKind::Campaign, SCREEN); press(&mut board, KeyCode::Down); assert_eq!(highlighted(&board).as_deref(), Some(V1), "down did not reach v1"); @@ -8402,7 +9239,7 @@ mod tests { fn a_query_that_excludes_the_highlight_moves_it_to_the_first_match() { let dir = board_dir(); let mut board = tail_board(&dir); - board.open_picker(); + board.open_picker(PickerKind::Campaign, SCREEN); assert_eq!(highlighted(&board).as_deref(), Some(BEAVER)); type_picker_query(&mut board, "polish"); @@ -8415,7 +9252,7 @@ mod tests { fn the_picker_footer_names_the_search_key_and_then_becomes_the_query() { let dir = board_dir(); let mut board = tail_board(&dir); - board.open_picker(); + board.open_picker(PickerKind::Campaign, SCREEN); assert!(footer(&board, 100, 24).contains("/ search"), "the key is unfindable"); @@ -8432,7 +9269,7 @@ mod tests { fn the_picker_title_says_how_many_a_query_left() { let dir = board_dir(); let mut board = tail_board(&dir); - board.open_picker(); + board.open_picker(PickerKind::Campaign, SCREEN); let title = |board: &Board| { let picker = board.picker.as_ref().expect("no picker"); @@ -8451,7 +9288,7 @@ mod tests { fn the_standings_are_read_when_the_cards_are_and_not_per_draw() { let dir = board_dir(); let mut board = tail_board(&dir); - board.open_picker(); + board.open_picker(PickerKind::Campaign, SCREEN); // Taken away after the board was built, so a standing that asked the filesystem // again would have nothing left to ask it. @@ -8477,7 +9314,7 @@ mod tests { fn a_member_finished_after_the_board_was_built_completes_its_campaign() { let dir = board_dir(); let mut board = tail_board(&dir); - board.open_picker(); + board.open_picker(PickerKind::Campaign, SCREEN); let rows = picker_rows(&board, 100, 24); assert!( @@ -8506,7 +9343,7 @@ mod tests { fn the_highlight_survives_a_campaign_filed_under_an_open_picker() { let dir = board_dir(); let mut board = tail_board(&dir); - board.open_picker(); + board.open_picker(PickerKind::Campaign, SCREEN); press(&mut board, KeyCode::Down); assert_eq!(highlighted(&board).as_deref(), Some(V1)); @@ -8530,7 +9367,7 @@ mod tests { assert!(footer(&board, 120, 24).contains("c campaign"), "the key is unfindable"); - board.select_campaign(Some(V1.to_string()), SCREEN); + board.select_filter(Filter::Campaign(V1.to_string()), SCREEN); let footer = footer(&board, 120, 24); assert!(footer.contains("ctrl-c quit"), "q still claims to quit: {footer:?}"); assert!(!footer.contains("q quit"), "{footer:?}"); @@ -8559,13 +9396,17 @@ mod tests { assert_eq!(board.current().campaigns.len(), 1); assert_eq!(board.current().campaigns[0].project.as_deref(), Some("one")); - board.select_campaign(Some(V1.to_string()), SCREEN); - assert_eq!(board.current().campaign, Some(V1.to_string())); + board.select_filter(Filter::Campaign(V1.to_string()), SCREEN); + assert_eq!(board.current().filter.campaign(), Some(V1)); board.select_tab(1, SCREEN); - assert_eq!(board.current().campaign, None, "the filter followed the tab change"); + assert_eq!( + board.current().filter.campaign(), + None, + "the filter followed the tab change" + ); // And the tab it was set on kept it. board.select_tab(-1, SCREEN); - assert_eq!(board.current().campaign, Some(V1.to_string())); + assert_eq!(board.current().filter.campaign(), Some(V1)); } }