(10a07b8) Filter the board to the tickets in no campaign, from the campaign picker, and bump to 0.32.9

This commit is contained in:
Ansho Rei
2026-08-26 02:07:16 +02:00
parent c3efebe9b3
commit d0a8f9a284
4 changed files with 592 additions and 84 deletions
+582 -79
View File
@@ -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<String>` 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<Card>,
}
/// 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<Column>, Vec<CampaignRow>, Vec<TagRow>, 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<TagRow>,
/// 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<PickerKey> {
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<PickerRow<'a>> {
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<PickerRow<'a>> {
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<PickerRow<'a>> {
}
let mut rows: Vec<PickerRow> = 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<Column>> = Vec::new();
let mut per_campaigns: Vec<Vec<CampaignRow>> = Vec::new();
let mut per_tags: Vec<Vec<TagRow>> = Vec::new();
let mut per_no_campaign: Vec<usize> = 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<Column>, Vec<CampaignRow>, Vec<TagRow>)> = Vec::new();
let mut built: Vec<Reloaded> = 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<String> {
fn picked(&self) -> Option<PickerKey> {
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<String> {
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<Column>, campaign: Option<&str>) -> Vec<Column> {
let Some(uuid) = campaign else {
return columns;
};
fn retain_campaign(mut columns: Vec<Column>, uuid: &str) -> Vec<Column> {
for column in columns.iter_mut() {
column
.cards
@@ -2410,6 +2530,39 @@ fn retain_campaign(mut columns: Vec<Column>, campaign: Option<&str>) -> Vec<Colu
columns
}
/// The opposite predicate over the same field: only the tickets that name no campaign.
///
/// A different question from [`retain_campaign`] and not a different value in it — comparing
/// against a uuid that means none would be one rename or one reused id away from matching a
/// real campaign. The field's absence is the whole test: a ticket whose Campaign names a uuid
/// no campaign carries is *set* wrongly, not unset, and stays out of this view the way it
/// draws `_missing_` on its own card rather than nothing at all.
///
/// Every column kept, empty ones included, for the reason `retain_campaign` keeps them. The
/// count beside this filter is [`Tab::no_campaign`], taken off the unfiltered columns; what
/// this answers is which cards survive it.
fn retain_no_campaign(mut columns: Vec<Column>) -> Vec<Column> {
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<FrameContent> {
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<Span<'static>
]
}
/// 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<Span<'static>> {
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<String> {
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<String> = 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<String> = 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");
}
}