diff --git a/AGENTS.md b/AGENTS.md index 9cc1e66..c6caf6b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -277,7 +277,7 @@ and this file is for what someone changing worklane's own code needs. - **The expanded height is a share, not a second constant: half of what the frame and the columns divide.** That is the screen less the tab row and the footer, so the split is even between the two of them rather than even against rows neither gets all of. Half rather than most of it for the same reason the frame is not an overlay: the columns below are the campaign's members, and a reader inspecting the campaign has to go on seeing what it is made of. Floored, so the odd row goes to the cards. `Chrome::frame_rows` takes the height because of this, and `screen_rows` is where it is called, since that is the one place that already has an area to take a share of — which is what keeps `Chrome` itself pure and copyable from `Board::chrome` with no screen to hand - **The share is bounded at both ends, and `COLUMN_MIN_ROWS` is why.** `Constraint::Min(COLUMN_MIN_ROWS)` would take rows back from a frame that asked for too many, silently, and the frame's own measurement would then disagree with what is drawn — the fault `Chrome` exists to prevent. So the share is capped at what leaves the columns those rows, and floored at `FRAME_ROWS`, since expanding must never shrink the frame. On a board too short to divide, `enter` gives the collapsed height back rather than a height nothing measured. `the_expanded_share_is_bounded_at_both_ends` sweeps every height from 4 to 60, tabbed and not, because one screen that happens to work says nothing about the arithmetic - **The frame says the rest of what it has to say on its borders**, the trade the detail overlay makes with its title and its page indicator: `(id) ~codename · Name` on the top one, the standing on the bottom right, and `q board` then the page indicator on the bottom left. Every row spent here is a row of cards -- **The frame slot is shared between the two filters, not doubled.** One filter is on at a time, per `Filter`, so a tag frame is the campaign frame with its three slots filled differently: `#tag` in `tag_color` on the top border where the campaign's identity goes, how many tickets carry it on the bottom right where the standing goes, and the annotation in the prose rows. `FrameContent` is what the two are told apart into, and **`frame_content` is the one place they are told apart at all** — the borders, the colour, `q board`, the page indicator, the scroll and the focus are all the campaign frame's, and a second `match` on the filter below that is how the two frames come to behave differently in a way nobody decided +- **The frame slot is shared between the filters, not doubled.** One filter is on at a time, per `Filter`, so a tag frame is the campaign frame with its three slots filled differently: `#tag` in `tag_color` on the top border where the campaign's identity goes, how many tickets carry it on the bottom right where the standing goes, and the annotation in the prose rows. `FrameContent` is what they are told apart into, and **`frame_content` is the one place they are told apart at all** — the borders, the colour, `q board`, the page indicator, the scroll and the focus are all the campaign frame's, and a second `match` on the filter below that is how the frames come to behave differently in a way nobody decided - **A tag frame draws the annotation, which is the payoff for declaring a tag.** Whoever is browsing a tag is deciding whether the next ticket belongs in it, and the sentence saying when the tag is appropriate is then on the screen at that moment rather than in `tags.md`, which they would have to know to open. An undeclared tag draws `NO_ANNOTATION` in grey, which is also the frame saying the word was never agreed on — the vocabulary file's own placeholder rather than the description section's, so the frame and the file say the same thing about the same tag. A tag declared with nothing said about it draws the same, since here the two have the same nothing to show; the picker's sections are where the difference is actionable - **A tag has no id, so `y` on its frame copies the word.** A tag *is* its name, matched whole by `ls --tag`, so there are no seven characters to shorten and the `#` the border draws is not part of it — `--tag "#bug"` matches nothing. The footer says `y copy tag` there for the same reason: naming it an id would send the reader looking for a short id on a border that prints a word - **The count on a tag frame is every column's, drawn or not**, the rule the standing holds. With the filter on, those columns *are* the tickets carrying the tag, so it counts what is below it without counting it a second way. The noun is spelled out and pluralised, because a bare number on a border says nothing about what was counted, and there is no derived state beside it: a tag is a word and not a piece of work, so there is no `[open]` to be in @@ -296,7 +296,12 @@ and this file is for what someone changing worklane's own code needs. - **The picker's rows are `Tab::campaigns`, not a copy taken when it opened**, so a campaign filed elsewhere appears in an open picker on the next tick. It opens on the campaign already selected, so `c` on a filtered board says where you are as well as offering somewhere to go, and a board with no campaigns gets a `Notice` rather than an empty box that has to be dismissed to learn it was empty - **`t` opens the same picker over the tags instead, and taking a tag filters every column to the cards carrying it.** Every tag the board declares or carries, matched whole and case sensitively the way `ls --tag` matches — the box completes the filter, so offering what the filter would refuse is the one bug it must not have. It opens on the tag already applied, the courtesy `c` pays a campaign-filtered board, and a board carrying no tag gets the same `Notice` a board with no campaigns gets - **A picker row draws a real codename only.** The row opens with the short id, so the card's `~` fallback would print it twice and say nothing the second time -- **One picker serves both lists, and `PickerRow::key` is what keeps it one.** A second picker would have been a second keyboard, query and highlight to keep in step with the first; instead `PickerKind` decides only which list is built and what the answer filters, and everything between the keypress and the filter runs once against the key — a campaign is keyed by its uuid and a tag by itself, both strings the tab can be filtered by. Picking either clears the other without either setter remembering to, because `select_filter` replaces one `Filter`: one field, which is the same reason the frame slot is shared +- **One picker serves both lists, and `PickerRow::key` is what keeps it one.** A second picker would have been a second keyboard, query and highlight to keep in step with the first; instead `PickerKind` decides only which list is built, and everything between the keypress and the filter runs once against the key — which since the pile arrived is a `PickerKey` enum rather than a bare string, because one of the answers filters on an *absence* and carries no string to hand back. `take_picked` reads the kind off the answer rather than off which list was open. Picking any of them clears the others without either setter remembering to, because `select_filter` replaces one `Filter`: one field, which is the same reason the frame slot is shared +- **The campaign picker opens with a row for the tickets in no campaign**, above both sections and never truncated: the pile is the one question about a board of campaigns that no single campaign answers, and on a board whose completed tail is being kept back it would be pushed off the box if it listed among them. It draws its count where a campaign row draws its standing, so picking an empty pile is seen coming; under a query it answers "no campaign" and "none" and hides like any other row. **It selects `Filter::NoCampaign`, its own variant** — `retain_campaign` compares the field to the uuid it is given, so the absence case is a different predicate beside it (`retain_no_campaign`) and not a different value in it, and a magic uuid meaning none is exactly the thing that later matches a real one. A dangling uuid is *set* wrongly and stays out of the view, as it draws `_missing_` on its card rather than nothing at all +- **The pile crosses boards where a campaign cannot, so it is pickable on the merge tab.** An unset field means the same thing in every `.worklane`, the property that lets a tag filter travel there; the count adds across boards, taken at reload off the unfiltered columns like the standings are (`Tab::no_campaign`), never per draw and never off the filtered columns, which would answer zero about themselves +- **The opening highlight still lands on the first campaign, not on the pile.** Campaigns are what this list opens for; the row sits above the list without claiming it — one step up reaches it, it holds the highlight whenever it was the row selected, and only when every campaign is hidden does it take the opening one +- **The frame speaks for the pile in its own words, because the frame question stays `is_whole()`.** Exempting one variant from either half of that rule would be a state where the selection rests on a frame that is not drawn — the one thing `Focus` exists to make unrepresentable. So the title is grey `no campaign` (no id to shorten and no mark, which keeps `~` meaning a campaign and `#` a tag), the standing corner takes the count, and the prose is one grey sentence the board owns, since no file holds words for an absence +- **`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 - **`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 @@ -306,7 +311,7 @@ and this file is for what someone changing worklane's own code needs. - **`/` in the picker is the key it already is on the board**, and `picker_key` can take it because printable keys used to fall through `_ => {}`. Typing filters case insensitively against the short id, the codename and the title — the three things the row draws and the three a campaign is chosen by. Not the summary: a query that matched prose would answer `disk` with every campaign whose description mentions one. A tag answers by itself or by its annotation, which is a reader who cannot remember the word finding it by what it was for — case insensitive here though `--tag` is not, because matching a tag is the filter and searching for one is a reader typing. **An empty query matches everything**, the opposite of `first_match`'s answer and right for the opposite reason: a jump with nothing typed has nowhere to go, while a filter with nothing typed is not filtering, and pressing `/` must not empty the list - **A query turns the truncation off**, which is the point of having one: the campaign a reader is searching for is exactly the one the truncation hid - **The query is a layer, and `esc` takes it off before it takes the picker off**, the order `dismiss` closes the board's own layers in. So the list is whole again after that press, not still filtered with nothing on screen saying why. Movement and `enter` stay live under an open query, because a filtered list nothing can move in is a list nothing can be chosen from; every *printable* key goes into the buffer, so `q` types and so does `j` -- **The highlight follows its row, not its row number.** `place_picker` takes a key — a uuid or a tag, whichever list is open — the same string `Tab::filter` holds for either filter: typing, clearing the query and a tick that finishes a campaign all reshape the list, and a number kept across that names whichever campaign now sits at it. One the list no longer holds drops the highlight to the first row that does, which is where an incremental filter puts it. `reload` reads the highlighted key before the lists are rebuilt and puts it back after +- **The highlight follows its row, not its row number.** `place_picker` takes a key — whichever answer `PickerRow::key` hands back, the same shape `Tab::filter` holds for any of them: typing, clearing the query and a tick that finishes a campaign all reshape the list, and a number kept across that names whichever campaign now sits at it. One the list no longer holds drops the highlight to the first row that does, which is where an incremental filter puts it. `reload` reads the highlighted key before the lists are rebuilt and puts it back after - **A miss is a row in the box, `no match` in brightred**, where the search prompt puts its own, and `enter` on it leaves the picker and the query exactly as they are so the query can be corrected in place. An empty box says nothing about why it is empty - **The picker's footer becomes its query**, the trade `draw_search` makes: with every printable key going into a buffer, a list of keys describes nothing that works. `/ search` is named only on the closed query, and the open one names what `esc` does to *it* rather than what it does to the picker - **The title says both counts while a query is open**, `campaigns (2 of 6)`. The bare total is what the box is, but over a list a query has cut down it is a lie about what is on screen diff --git a/Cargo.lock b/Cargo.lock index aa579fa..4fa1feb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1503,7 +1503,7 @@ dependencies = [ [[package]] name = "worklane" -version = "0.32.8" +version = "0.32.9" dependencies = [ "anyhow", "assert_cmd", diff --git a/Cargo.toml b/Cargo.toml index 5fce8d1..31f6c03 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "worklane" -version = "0.32.8" +version = "0.32.9" edition = "2024" [dependencies] diff --git a/src/tui.rs b/src/tui.rs index 6b11491..617652f 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -159,7 +159,8 @@ pub enum Focus { Frame, } -/// What a tab's columns are cut down to: one campaign, one tag, or the whole board. +/// What a tab's columns are cut down to: one campaign, one tag, no campaign at all, 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 @@ -174,6 +175,13 @@ pub enum Focus { /// 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. +/// +/// The absence of a campaign is its own variant rather than a value inside [`Filter::Campaign`]: +/// [`retain_campaign`] compares the field to the uuid it is given, so the tickets in no +/// campaign are a different predicate over the field and not a different value in it — and a +/// magic uuid meaning none is exactly the kind of thing that later matches a real one. Being +/// keyed on nothing is also why it crosses boards where a campaign cannot, the property a +/// tag filter already has on the merge tab. #[derive(Clone, Debug, Default, PartialEq, Eq)] pub enum Filter { /// Every card the tab holds, which is where a tab opens. @@ -181,15 +189,18 @@ pub enum Filter { Whole, Campaign(String), Tag(String), + /// Only the cards whose Campaign field is unset: the pile no campaign gathers. + NoCampaign, } impl Filter { - /// The campaign this filters to, or nothing for a tag filter or none. + /// The campaign this filters to, or nothing for any other filter. /// - /// What the campaign frame draws itself from, and what tells a filter that resolves - /// against the campaigns directory from one that resolves against nothing. The frame, - /// the focus and the geometry ask [`Filter::is_whole`] instead: either filter draws a - /// frame, so either can hold the selection above the columns. + /// What tells a filter that resolves against the campaigns directory from one that + /// resolves against nothing. The no-campaign filter answers nothing here too, being a + /// predicate over the field rather than a value in it; the frame, the focus and the + /// geometry ask [`Filter::is_whole`] instead: every filter draws a frame, so any can + /// hold the selection above the columns. pub fn campaign(&self) -> Option<&str> { match self { Filter::Campaign(uuid) => Some(uuid), @@ -312,6 +323,10 @@ pub struct Column { pub cards: Vec, } +/// What one reload builds for one tab: its columns, what it can be filtered by, and how +/// many tickets on it name no campaign. +type Reloaded = (Vec, Vec, Vec, usize); + /// A campaign as the board holds it: what the picker lists and what the frame draws. /// /// Read at reload from the one pass over the campaigns directory, the same pass that names @@ -446,7 +461,18 @@ pub struct Tab { /// 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. + /// How many tickets on this tab name no campaign, drawn or not. + /// + /// Counted at reload off the columns before either filter is applied to them, for the + /// reason the standings are: how many tickets are in no campaign is not a question about + /// what the tab is currently showing, and a count taken off the filtered columns would + /// answer zero about itself. The picker's first row draws it and the frame repeats it. + /// + /// On the merge tab it is every board's, summed — an unset field means the same thing in + /// every `.worklane`, which is why this filter crosses boards where a campaign cannot. + pub no_campaign: usize, + /// What the columns are cut down to: one campaign, one tag, no campaign, 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 @@ -486,6 +512,7 @@ impl Tab { offsets: Vec::new(), campaigns: Vec::new(), tags: Vec::new(), + no_campaign: 0, filter: Filter::default(), focus: Focus::default(), expanded: false, @@ -715,8 +742,8 @@ pub struct Picker { /// 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. + /// either way; this decides only what `picker_list` builds, the answer carrying its own + /// kind back to `take_picked`. 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 @@ -763,31 +790,68 @@ const COMPLETED_SHOWN: usize = 2; /// is. Nothing here is held on the `Picker`: the rows are derived on every draw and every /// keypress, which is what lets a campaign filed elsewhere reach an open picker on the next /// tick instead of being missing from a copy taken when it opened. +#[derive(Debug)] enum PickerRow<'a> { /// A section heading, naming what the rows under it are. Heading(&'static str), Campaign(&'a CampaignRow), Tag(&'a TagRow), + /// The tickets whose Campaign field is unset, with how many they are. + NoCampaign(usize), /// 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, } +/// What taking a picker row selects, kept across a rebuild of the list. +/// +/// A campaign is keyed by its uuid and a tag by itself — both strings the tab can be +/// filtered by, which is what [`PickerRow::key`] handed back when those were the only two +/// rows. The third answer names nothing on any file: the no-campaign row filters on the +/// *absence* of a value, so it is its own variant here rather than an empty string standing +/// in for one, and `take_picked` reads the kind off the key instead of off which list was +/// open. +/// +/// Owned rather than borrowed, because the highlight has to outlive the rows it was read +/// from: `reload` takes it before the lists are rebuilt and puts it back after. +#[derive(Clone, Debug, PartialEq, Eq)] +enum PickerKey { + Campaign(String), + Tag(String), + NoCampaign, +} + +impl PickerKey { + /// What a test would call this answer, so a highlight can be named without reaching + /// for a row number the sections have already moved. + #[cfg(test)] + fn name(&self) -> &str { + match self { + PickerKey::Campaign(uuid) => uuid, + PickerKey::Tag(name) => name, + PickerKey::NoCampaign => NO_CAMPAIGN_ROW, + } + } +} + +/// What the no-campaign row and its frame are called, everywhere they are drawn. +const NO_CAMPAIGN_ROW: &str = "no campaign"; + 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. + /// value `enter` takes — be written once. /// /// `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> { + fn key(&self) -> Option { match self { - PickerRow::Campaign(campaign) => Some(&campaign.uuid), - PickerRow::Tag(tag) => Some(&tag.name), + PickerRow::Campaign(campaign) => Some(PickerKey::Campaign(campaign.uuid.clone())), + PickerRow::Tag(tag) => Some(PickerKey::Tag(tag.name.clone())), + PickerRow::NoCampaign(_) => Some(PickerKey::NoCampaign), _ => None, } } @@ -830,7 +894,7 @@ fn picker_list<'a>(tab: &'a Tab, picker: &Picker) -> Vec> { rows } -/// The campaign rows: open above completed, the completed tail truncated. +/// The campaign rows: the tickets in no campaign above open above completed. fn campaign_picker_rows<'a>(tab: &'a Tab, query: &str) -> Vec> { let (mut completed, open): (Vec<&CampaignRow>, Vec<&CampaignRow>) = tab .campaigns @@ -845,6 +909,13 @@ fn campaign_picker_rows<'a>(tab: &'a Tab, query: &str) -> Vec> { } let mut rows: Vec = Vec::new(); + // First and never truncated, so it is reachable without scrolling on a board whose + // completed tail would otherwise push it down: the pile is the one question about a + // board of campaigns that no single campaign answers. Not under either heading — it + // is not a campaign, and a section naming what its rows are would be lying about it. + if no_campaign_matches(query) { + rows.push(PickerRow::NoCampaign(tab.no_campaign)); + } if !open.is_empty() { rows.push(PickerRow::Heading(OPEN_SECTION)); rows.extend(open.into_iter().map(PickerRow::Campaign)); @@ -914,6 +985,22 @@ fn picker_matches(campaign: &CampaignRow, query: &str) -> bool { || campaign.title.to_lowercase().contains(&query) } +/// Whether the no-campaign row answers the query: the words a reader would type for it. +/// +/// "no campaign" is what the row says, and "none" is the shorter way to ask for the same +/// thing; both are matched as substrings, so a query still being typed narrows the same way +/// it does over the campaigns. The row carries no id, no codename and no title — there is +/// nothing else on it to be found by, which is the rule `picker_matches` holds: a row is +/// found by what it draws. +fn no_campaign_matches(query: &str) -> bool { + let query = query.trim().to_lowercase(); + if query.is_empty() { + return true; + } + + NO_CAMPAIGN_ROW.to_lowercase().contains(&query) || "none".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. @@ -1094,6 +1181,7 @@ impl Board { let mut per_columns: Vec> = Vec::new(); let mut per_campaigns: Vec> = Vec::new(); let mut per_tags: Vec> = Vec::new(); + let mut per_no_campaign: Vec = Vec::new(); for project in &self.projects { 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 @@ -1110,6 +1198,8 @@ impl Board { // 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)); + // And this one beside them: how many tickets name no campaign at all. + per_no_campaign.push(no_campaign_count(&columns)); per_columns.push(columns); } @@ -1118,17 +1208,18 @@ impl Board { // survive the rebuild, the way `Tab::campaign` is a uuid and not an index. let highlighted = self.picked(); - let mut built: Vec<(Vec, Vec, Vec)> = Vec::new(); + let mut built: 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. + // board. The unset field adds across boards, being keyed on nothing. let campaigns = per_campaigns.iter().flatten().cloned().collect(); built.push(( merge(&per_columns, &self.projects), campaigns, merged_tag_rows(&per_tags), + per_no_campaign.iter().sum(), )); } built.extend( @@ -1136,12 +1227,16 @@ impl Board { .into_iter() .zip(per_campaigns) .zip(per_tags) - .map(|((columns, campaigns), tags)| (columns, campaigns, tags)), + .zip(per_no_campaign) + .map(|(((columns, campaigns), tags), no_campaign)| { + (columns, campaigns, tags, no_campaign) + }), ); - for (tab, (columns, campaigns, tags)) in self.tabs.iter_mut().zip(built) { + for (tab, (columns, campaigns, tags, no_campaign)) in self.tabs.iter_mut().zip(built) { tab.campaigns = campaigns; tab.tags = tags; + tab.no_campaign = no_campaign; // 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 @@ -1168,8 +1263,15 @@ impl Board { tab.expanded = false; tab.frame_offset = 0; } - tab.columns = - retain_tag(retain_campaign(columns, tab.filter.campaign()), tab.filter.tag()); + // The campaign filter and its opposite are two predicates over the one field, + // which is why they are decided in the same breath here rather than by a flag + // somewhere on the filter. + let columns = match &tab.filter { + Filter::Campaign(uuid) => retain_campaign(columns, uuid), + Filter::NoCampaign => retain_no_campaign(columns), + Filter::Whole | Filter::Tag(_) => columns, + }; + tab.columns = retain_tag(columns, 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. @@ -1182,7 +1284,7 @@ impl Board { // And put back, on the campaign rather than on the number: one filed or finished // elsewhere splits the list differently, so the row that held it has moved. if self.picker.is_some() { - self.place_picker(highlighted.as_deref()); + self.place_picker(highlighted.as_ref()); } // The selected ticket may have moved or gone, so the open detail follows it. @@ -1417,10 +1519,20 @@ impl Board { 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)), + PickerKind::Campaign => ( + tab.campaigns.is_empty(), + // Either campaign answer holds its row: a filter to one campaign opens on + // it, and a filter to no campaign opens on that row. + match &tab.filter { + Filter::Campaign(uuid) => Some(PickerKey::Campaign(uuid.clone())), + Filter::NoCampaign => Some(PickerKey::NoCampaign), + Filter::Whole | Filter::Tag(_) => None, + }, + ), + PickerKind::Tag => ( + tab.tags.is_empty(), + tab.filter.tag().map(|tag| PickerKey::Tag(tag.to_string())), + ), }; if empty { @@ -1433,14 +1545,15 @@ impl Board { } self.picker = Some(Picker { kind, ..Picker::default() }); - self.place_picker(held.as_deref()); + self.place_picker(held.as_ref()); // 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); } - /// 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. + /// What the highlight is on, as the answer taking it would filter the board to: a + /// campaign, a tag, or no campaign. Nothing when the picker is closed or the highlight + /// is on chrome. /// /// 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, @@ -1449,31 +1562,39 @@ impl Board { /// 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 { + fn picked(&self) -> Option { let picker = self.picker.as_ref()?; - picker_list(self.current(), picker) - .get(picker.row)? - .key() - .map(str::to_string) + picker_list(self.current(), picker).get(picker.row)?.key() } - /// Put the highlight on `uuid`, or on the first row that can be taken. + /// Put the highlight on `key`, or on the first row that can be taken. /// - /// By uuid rather than by keeping the number, the answer `Tab::campaign` gives for the + /// By key rather than by keeping the number, the answer `Tab::campaign` gives for the /// filter: a query typed into or a tick that finishes a campaign reshapes the list, and - /// a number kept across that names whichever campaign now sits at it. A campaign the - /// list no longer holds leaves nothing to hold on to, so the highlight goes to the top - /// of what is there — which is where an incremental filter puts it anyway. + /// a number kept across that names whichever campaign now sits at it. A row the list no + /// longer holds leaves nothing to hold on to, so the highlight goes to the top of what + /// is there — which is where an incremental filter puts it anyway. + /// + /// The top is deliberately not where it starts: the fallback skips the no-campaign row + /// and lands on the first campaign, which is what this picker has always opened on and + /// still the common thing asked of it. The no-campaign row sits above the list without + /// claiming it — reachable in one step up, and holding the highlight whenever it was the + /// row selected. Only when every campaign is hidden — a query matching the pile alone — + /// does it take the opening highlight. /// /// 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, key: Option<&str>) { + fn place_picker(&mut self, key: Option<&PickerKey>) { let Some(picker) = &self.picker else { return }; let rows = picker_list(self.current(), picker); - let held = key.and_then(|key| rows.iter().position(|row| row.key() == Some(key))); + let held = key.and_then(|key| rows.iter().position(|row| row.key().as_ref() == Some(key))); let at = held + .or_else(|| { + rows.iter() + .position(|row| row.key().is_some_and(|key| key != PickerKey::NoCampaign)) + }) .or_else(|| rows.iter().position(|row| row.key().is_some())) .unwrap_or(0); @@ -1561,7 +1682,7 @@ impl Board { }; edit(&mut picker.query); - self.place_picker(held.as_deref()); + self.place_picker(held.as_ref()); self.align_picker(screen); } @@ -1619,29 +1740,27 @@ impl Board { picker.offset = aligned_offset(picker.offset, start, start + 1, height, count); } - /// Take the highlighted campaign and close the picker. + /// Take the highlighted row and close the picker. /// /// A highlight on nothing takeable — the `no match` row, or a list of chrome — leaves /// the picker and the query exactly as they are, so the query can be corrected in place. /// 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(picker) = &self.picker else { return }; - let kind = picker.kind; let Some(key) = self.picked() else { return; }; self.picker = None; - // 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, - ); + // The key carries which list it came from: a campaign row keys a campaign and a tag + // row keys a tag, so the kind is read off the answer rather than asked of a picker + // that has just been put away. + let filter = match key { + PickerKey::Campaign(uuid) => Filter::Campaign(uuid), + PickerKey::Tag(name) => Filter::Tag(name), + PickerKey::NoCampaign => Filter::NoCampaign, + }; + self.select_filter(filter, screen); } /// Cut the tab in view down to one campaign or one tag, or back to the whole board. @@ -1833,11 +1952,16 @@ impl Board { /// command that takes a campaign resolves. A tag has no id to shorten: it *is* its name, /// which is what `ls --tag` matches whole and case sensitively, so the whole word goes /// on the clipboard and the hash the border draws does not — `--tag` would not match it. + /// + /// The no-campaign frame has neither: no id to shorten, and no word a command line takes, + /// since `ls --campaign` cannot say none — that spelling is its own ticket. `y` on this + /// frame answers "nothing to copy", and the footer leaves it unnamed rather than naming + /// a key into a notice. fn frame_id(&self) -> Option { let tab = self.current(); match &tab.filter { - Filter::Whole => None, + Filter::Whole | Filter::NoCampaign => None, Filter::Campaign(_) => tab .selected_campaign() .map(|campaign| short_id(&campaign.uuid).to_string()), @@ -2396,11 +2520,7 @@ fn standings_of(columns: &[Column]) -> HashMap<&str, Standing> { /// the answer is one column per status and the question is how many are in each. Filtered here, /// where the columns are built, so nothing downstream has to ask whether a campaign is /// selected — the board simply holds fewer cards. -fn retain_campaign(mut columns: Vec, campaign: Option<&str>) -> Vec { - let Some(uuid) = campaign else { - return columns; - }; - +fn retain_campaign(mut columns: Vec, uuid: &str) -> Vec { for column in columns.iter_mut() { column .cards @@ -2410,6 +2530,39 @@ fn retain_campaign(mut columns: Vec, campaign: Option<&str>) -> Vec) -> Vec { + for column in columns.iter_mut() { + column.cards.retain(|card| card.ticket.campaign.is_none()); + } + + columns +} + +/// How many tickets name no campaign, counted off one board's columns. +fn no_campaign_count(columns: &[Column]) -> usize { + columns + .iter() + .map(|column| { + column + .cards + .iter() + .filter(|card| card.ticket.campaign.is_none()) + .count() + }) + .sum() +} + /// The label for the campaign a ticket names, or nothing when it names none. /// /// Nothing, too, for a uuid the index does not hold. `campaign_cells` renders that case as @@ -2708,11 +2861,17 @@ struct FrameContent { /// What the tab's filter has to say for itself, or nothing when it is showing the whole /// board. /// -/// **The one place the two filters are told apart above the columns.** Everything the draw +/// **The one place the filters are told apart above the columns.** Everything the draw /// does with this is the same either way — the borders, the colour, the way out, the page /// indicator and the scroll are all the campaign frame's, and a tag fills its slots rather /// than inventing a second shape. A second `match` on the filter anywhere below here is how -/// the two frames come to behave differently in a way nobody decided. +/// the frames come to behave differently in a way nobody decided. +/// +/// The no-campaign filter fills the same slots in its own words rather than being left +/// frameless: `is_whole()` is what decides both that a frame is drawn and that +/// [`Focus::Frame`] can hold the selection, and exempting one variant from either half would +/// be a state where the selection rests on a frame that is not drawn — the one thing +/// [`Focus`] exists to make unrepresentable. /// /// Nothing, too, for a filter that resolves to no row: `reload` clears both of those, so /// this is the answer to a draw that arrives before it rather than a state the board holds. @@ -2729,6 +2888,11 @@ fn frame_content(tab: &Tab, width: u16) -> Option { standing: count_spans(tag.count), prose: tag_prose(tag), }), + Filter::NoCampaign => Some(FrameContent { + title: no_campaign_title(width), + standing: count_spans(tab.no_campaign), + prose: no_campaign_prose(), + }), } } @@ -2911,6 +3075,19 @@ fn tag_prose(tag: &TagRow) -> Text<'static> { } } +/// What the no-campaign view is, as its frame says it. +/// +/// The title names the filter and this says what the columns under it are, which a tag's +/// annotation and a campaign's description answer for their own frames. No file holds words +/// for an absence, so the sentence is the board's own — grey like the title, being the same +/// fact about the same unset field rather than prose anyone wrote. +fn no_campaign_prose() -> Text<'static> { + Text::from(Line::from(Span::styled( + "Tickets that name no campaign.", + Style::default().fg(Color::Grey.into()), + ))) +} + /// The tag frame's title: `#tag`, in the colour a card draws it in, cut to the border. /// /// The hash is what a card and `labels_line` already put in front of a tag, and it earns its @@ -2991,6 +3168,29 @@ fn campaign_title(campaign: &CampaignRow, frame_width: u16) -> Vec ] } +/// The no-campaign frame's title: the words, and nothing else. +/// +/// No id — there is no thing on the board to address — and no mark, which keeps `~` meaning +/// a campaign and `#` meaning a tag. Grey, because this view is the Campaign field's unset +/// state drawn out, and grey is what the palette gives `_Not set_`: the border around it says +/// where the reader is, the words say what they are looking at. Cut by hand like +/// [`tag_title`] and [`campaign_title`], since ratatui truncates a block title at whatever +/// cell it reaches. +fn no_campaign_title(frame_width: u16) -> Vec> { + let room = frame_width.saturating_sub(2) as usize; + let whole = format!(" {NO_CAMPAIGN_ROW} "); + + let text = match whole.chars().count() <= room { + true => whole, + false => match room.checked_sub(3).filter(|keep| *keep > 0) { + Some(keep) => format!(" {} ", with_ellipsis(NO_CAMPAIGN_ROW, keep)), + None => String::new(), + }, + }; + + vec![Span::styled(text, Style::default().fg(Color::Grey.into()))] +} + fn draw_columns(frame: &mut Frame, board: &Board, area: Rect) { // Only the drawn columns are measured, so hiding done gives its width back to the // three that are left rather than leaving a gap where it was. @@ -3599,10 +3799,13 @@ fn draw_footer(frame: &mut Frame, board: &Board, area: Rect) { }; // What `y` copies where the selection is. A tag is its own id, so naming it one would - // send the reader looking for seven characters on a border that prints a word. + // send the reader looking for seven characters on a border that prints a word. Nothing + // on the no-campaign frame, which has neither — the key is left out of its footer + // rather than named into a notice. let copied = match board.current().filter { - Filter::Tag(_) => "copy tag", - _ => "copy id", + Filter::Tag(_) => Some("copy tag"), + Filter::NoCampaign => None, + Filter::Whole | Filter::Campaign(_) => Some("copy id"), }; let mut hints: Vec<(&str, &str)> = Vec::new(); @@ -3631,13 +3834,17 @@ fn draw_footer(frame: &mut Frame, board: &Board, area: Rect) { ("y", "copy id"), ("↵/q", "close"), ]), - (false, Focus::Frame) => hints.extend([ - ("↓", "board"), - ("↵", height), - ("pgup/pgdn", "scroll"), - ("/", "search"), - ("y", copied), - ]), + (false, Focus::Frame) => { + hints.extend([ + ("↓", "board"), + ("↵", height), + ("pgup/pgdn", "scroll"), + ("/", "search"), + ]); + if let Some(copied) = copied { + hints.push(("y", copied)); + } + } (false, Focus::Cards) => { hints.extend([("←→", "column"), ("↑↓", "card"), ("/", "search")]); hints.extend_from_slice(filter); @@ -3874,6 +4081,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::NoCampaign(count) => no_campaign_line(*count, selected), PickerRow::Heading(name) => { Line::from(Span::styled((*name).to_string(), grey.add_modifier(Modifier::BOLD))) } @@ -3947,6 +4155,30 @@ fn tag_picker_line(tag: &TagRow, selected: bool, width: u16) -> Line<'static> { Line::from(spans) } +/// 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 +/// the board but the absence of one, with nothing to mark and nothing to shorten. Grey, for +/// the same reason the frame's title is — the Campaign field of everything this view holds is +/// unset, and grey is what the palette gives `_Not set_`. +/// +/// The count is what the row is chosen on as much as its name, the trade `tag_picker_line` +/// makes: it says what picking this will give, including zero, so an empty board is seen +/// coming before the reader presses anything. +fn no_campaign_line(count: usize, selected: bool) -> Line<'static> { + let emphasis = match selected { + true => Modifier::REVERSED, + false => Modifier::empty(), + }; + let grey = Style::default().fg(Color::Grey.into()).add_modifier(emphasis); + + Line::from(vec![ + Span::styled(NO_CAMPAIGN_ROW.to_string(), grey), + Span::raw(" "), + Span::styled(count.to_string(), grey), + ]) +} + /// 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 @@ -8352,7 +8584,7 @@ approach"; /// 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.picked() + board.picked().map(|key| key.name().to_string()) } /// Which drawn row is exactly this heading, since a heading is the whole of its row. @@ -10383,7 +10615,12 @@ approach"; board.select_filter(Filter::Campaign(V1.to_string()), SCREEN); board.open_picker(PickerKind::Campaign, SCREEN); - assert_eq!(board.picked().as_deref(), Some(V1), "the highlight is on no campaign"); + let held = board.picked(); + assert_eq!( + held.as_ref().map(PickerKey::name), + Some(V1), + "the highlight is on no campaign" + ); } /// A board with no campaigns says so in words rather than opening an empty box that @@ -10716,15 +10953,18 @@ approach"; } /// Section headings and the truncation line take no number: they are not campaigns, so - /// a highlight resting on one would give enter nothing to do. + /// a highlight resting on one would give enter nothing to do. The no-campaign row is not + /// chrome, though — it takes the highlight when the walk reaches it, but never the + /// opening one. #[test] fn the_highlight_moves_over_campaigns_and_never_onto_the_chrome() { let dir = board_dir(); let mut board = tail_board(&dir); 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); + // It opens on the first campaign, not on the no-campaign row or the heading between + // them: campaigns are what this list opens for. + assert_eq!(board.picker.as_ref().expect("no picker").row, 2); // Down until it stops, which is the last campaign and not the truncation line under // it. Four campaigns are drawn: two open, and the two the truncation kept. @@ -10742,7 +10982,8 @@ approach"; assert_eq!(walked[3], FINISHED[2].0, "the walk stopped short: {walked:?}"); // And back up is the same walk in reverse, over the second heading rather than onto - // it, ending on the first campaign rather than the first row. + // it — ending one further than it began, on the row above the list rather than on + // its heading. let mut back = Vec::new(); loop { let before = board.picker.as_ref().expect("no picker").row; @@ -10753,7 +10994,8 @@ approach"; back.push(highlighted(&board).expect("the highlight landed on chrome")); } back.reverse(); - assert_eq!(back, walked[..3], "the walk back is not the walk out"); + assert_eq!(back[1..], walked[..3], "the walk back is not the walk out"); + assert_eq!(back[0], NO_CAMPAIGN_ROW, "the walk back stopped short of the pile"); } /// The highlight follows the campaign it was on rather than the number it was at: a @@ -10953,4 +11195,265 @@ approach"; board.select_tab(-1, SCREEN); assert_eq!(board.current().filter.campaign(), Some(V1)); } + + // --------------------------------------------------- the no-campaign filter -- + + /// A board like [`campaign_board`] but with a loose ticket and the finished tail behind + /// it, which is what would push the pile down if it were listed among the sections + /// instead of above them. + fn tailed_campaign_board(dir: &Path) -> Board { + write_ticket(dir, "backlog", "66666666-0000-4000-8000-000000000000", "In neither", ""); + tail_board(dir) + } + + /// The opposite question to picking a campaign: what is on this board that nobody + /// grouped into anything. Every column kept, empty ones included, the rule + /// `retain_campaign` holds. + #[test] + fn picking_no_campaign_filters_every_column_to_the_unset_field() { + let dir = board_dir(); + let mut board = campaign_board(&dir); + board.visibility = Visibility::Both; + + board.select_filter(Filter::NoCampaign, SCREEN); + + let headings = headings(&board, 120, 20); + assert!(headings.contains("backlog (1)"), "{headings}"); + assert!(headings.contains("committed (0)"), "{headings}"); + assert!(headings.contains("done (0)"), "{headings}"); + } + + /// A Campaign field naming a uuid no campaign carries is *set* wrongly, not unset: the + /// view answers what the field says, and the field does not say nothing here. + #[test] + fn a_dangling_campaign_uuid_is_set_and_not_unset() { + let dir = board_dir(); + write_ticket( + &dir, + "backlog", + "11111111-0000-4000-8000-000000000000", + "Dangling", + &campaign_field("99999999-0000-4000-8000-000000000000"), + ); + write_ticket(&dir, "backlog", "22222222-0000-4000-8000-000000000000", "Free", ""); + let mut board = one_board(&dir); + + board.select_filter(Filter::NoCampaign, SCREEN); + + let held: Vec = board.current().columns[0] + .cards + .iter() + .map(|card| card.ticket.title.clone()) + .collect(); + assert_eq!(held, vec!["Free"], "the dangling uuid read as unset"); + } + + /// First, above both sections, and never truncated: on a board whose completed tail is + /// being kept back the pile is still row zero, reachable without scrolling — which is + /// the whole reason it is not a member of either list. + #[test] + fn the_picker_draws_the_pile_above_the_sections_and_never_truncates_it() { + let dir = board_dir(); + let mut board = tailed_campaign_board(&dir); + board.open_picker(PickerKind::Campaign, SCREEN); + + let rows = picker_rows(&board, 100, 24); + let open = row_at(&rows, OPEN_SECTION); + + // The count sits where a campaign row's standing sits, saying what picking this + // will give before it is pressed. + assert!(rows[0].starts_with(NO_CAMPAIGN_ROW), "the pile was not first: {rows:?}"); + assert!(rows[0].contains(" 1"), "the count is not on the row: {:?}", rows[0]); + assert!(open > 0, "the sections did not follow it: {rows:?}"); + } + + /// A word a reader would type for it finds it; a query naming a campaign hides it like + /// any other row; and a query matching nothing at all says so rather than leaving the + /// pile up as a consolation row. + #[test] + fn a_query_finds_the_pile_and_hides_it_like_any_other_row() { + let dir = board_dir(); + let mut board = tailed_campaign_board(&dir); + board.open_picker(PickerKind::Campaign, SCREEN); + + // By the shorter word, which hides every campaign and leaves the pile holding the + // highlight, since it is the only thing left to take. + type_picker_query(&mut board, "none"); + assert_eq!( + highlighted(&board).as_deref(), + Some(NO_CAMPAIGN_ROW), + "the query missed the pile" + ); + + // A query naming a campaign hides it like any other row. + board.picker = None; + board.open_picker(PickerKind::Campaign, SCREEN); + type_picker_query(&mut board, "BEAV"); + assert!( + !picker_rows(&board, 100, 24)[0].contains(NO_CAMPAIGN_ROW), + "the pile survived" + ); + assert_eq!(picked_ids(&board), vec![BEAVER.to_string()]); + + // And nothing matched at all. + board.picker = None; + board.open_picker(PickerKind::Campaign, SCREEN); + type_picker_query(&mut board, "zzz"); + assert_eq!(highlighted(&board), None, "the miss took a row"); + assert!(picker_rows(&board, 100, 24)[0].contains("no match")); + } + + /// Taking the pile from under a query filters to it, which is how the row is found. + #[test] + fn taking_the_pile_under_a_query_filters_to_it() { + let dir = board_dir(); + let mut board = tailed_campaign_board(&dir); + board.open_picker(PickerKind::Campaign, SCREEN); + + type_picker_query(&mut board, "none"); + press(&mut board, KeyCode::Enter); + + assert!(board.picker.is_none(), "the picker stayed open"); + assert_eq!(board.current().filter, Filter::NoCampaign); + } + + /// Reopening the picker while the pile is selected opens on its row, the courtesy `c` + /// pays a filtered board: it says where you are as well as offering somewhere to go. + #[test] + fn reopening_the_picker_while_the_pile_is_selected_opens_on_its_row() { + let dir = board_dir(); + let mut board = campaign_board(&dir); + board.select_filter(Filter::NoCampaign, SCREEN); + + board.open_picker(PickerKind::Campaign, SCREEN); + assert_eq!( + highlighted(&board).as_deref(), + Some(NO_CAMPAIGN_ROW), + "the highlight is elsewhere" + ); + + // And taking it again changes nothing: the filter is what was asked for. + press(&mut board, KeyCode::Enter); + assert!(board.picker.is_none()); + assert_eq!(board.current().filter, Filter::NoCampaign); + } + + /// `q` takes the filter off, as it does a campaign or tag filter, because every filter + /// draws the frame whose border names it. + #[test] + fn q_gives_the_whole_board_back_from_the_no_campaign_filter() { + let dir = board_dir(); + let mut board = campaign_board(&dir); + board.select_filter(Filter::NoCampaign, SCREEN); + + board.dismiss(SCREEN); + + assert!(board.current().filter.is_whole(), "the filter survived q"); + assert_eq!(board.current().focus, Focus::Cards, "the focus outlived the frame"); + assert!(!board.should_quit, "q quit out from under the filter"); + } + + /// The frame speaks in its own words: what the view is on the top border, how many on + /// the bottom right, and one grey sentence between them. + #[test] + fn the_no_campaign_frame_says_what_it_is_and_how_many() { + let dir = board_dir(); + let mut board = campaign_board(&dir); + board.select_filter(Filter::NoCampaign, SCREEN); + + let rows = frame_lines(&board, 120, 20); + let prose = &rows[1..rows.len() - 1]; + + assert!(rows[0].contains(NO_CAMPAIGN_ROW), "{:?}", rows[0]); + assert!(rows[rows.len() - 1].contains("1 ticket"), "{:?}", rows[rows.len() - 1]); + assert!( + prose + .iter() + .any(|row| row.contains("Tickets that name no campaign.")), + "{prose:?}" + ); + } + + /// The frame question stays `is_whole()` — every filter draws one — so the selection can + /// go up onto this frame the way it goes onto any other, and there is no state where it + /// rests on a frame that is not drawn. + #[test] + fn the_selection_reaches_the_no_campaign_frame_because_one_is_drawn() { + let dir = board_dir(); + let mut board = campaign_board(&dir); + board.select_filter(Filter::NoCampaign, SCREEN); + + board.select_card(-1, SCREEN); + + assert_eq!(board.current().focus, Focus::Frame, "up did not reach the frame"); + let rows = frame_lines(&board, 120, 20); + assert!(rows[0].contains(NO_CAMPAIGN_ROW), "the frame was not drawn: {rows:?}"); + } + + /// An unset field means the same thing on every board, so the pile is pickable on the + /// merge tab where one campaign is not: the count adds across boards and the filter cuts + /// all of them at once. + #[test] + fn the_pile_can_be_picked_on_the_merge_tab_where_a_campaign_cannot() { + let one = board_dir(); + let two = board_dir(); + write_campaign(&one, V1, "First public release", "v1", "For a public tag."); + write_ticket( + &one, + "backlog", + "11111111-0000-4000-8000-000000000000", + "In v1", + &campaign_field(V1), + ); + write_ticket(&one, "backlog", "22222222-0000-4000-8000-000000000000", "Loose", ""); + write_ticket(&two, "backlog", "44444444-0000-4000-8000-000000000000", "Adrift", ""); + + let mut board = boards(&[("one", &one), ("two", &two)]); + + // The merged pile is two: one loose ticket per board. + board.open_picker(PickerKind::Campaign, SCREEN); + let rows = picker_list(board.current(), board.picker.as_ref().expect("no picker")); + assert!( + matches!(rows.first(), Some(PickerRow::NoCampaign(2))), + "the merged count is not the sum: {rows:?}" + ); + + type_picker_query(&mut board, "none"); + press(&mut board, KeyCode::Enter); + + let headings = headings(&board, 120, 20); + assert!(headings.contains("backlog (2)"), "{headings}"); + let held: Vec = board.current().columns[0] + .cards + .iter() + .map(|card| card.ticket.title.clone()) + .collect(); + assert_eq!(held, vec!["Adrift", "Loose"], "the merge was not cut across boards"); + + // And a campaign filter could not have done that: it belongs to the tab, keyed on a + // uuid from one board. + board.select_tab(1, SCREEN); + assert!(board.current().filter.is_whole(), "the filter crossed to a project"); + } + + /// The frame has neither an id nor a word a command line takes, so `y` is left out of + /// its footer rather than named into a notice — and pressing it anyway still says so, + /// never an empty string over the reader's clipboard. + #[test] + fn y_has_nothing_to_copy_from_the_no_campaign_frame() { + let dir = board_dir(); + let mut board = campaign_board(&dir); + board.select_filter(Filter::NoCampaign, SCREEN); + board.select_card(-1, SCREEN); + assert_eq!(board.copy_text(), None); + + let row = footer(&board, 120, 20); + assert!(!row.contains("copy"), "the footer names a key into a notice: {row:?}"); + + let mut taken = None; + board.copy_selected_id(recorder(&mut taken)); + assert_eq!(taken, None, "something reached the clipboard"); + let notice = board.notice.as_ref().expect("nothing was said"); + assert_eq!(notice.text, "nothing to copy"); + } }