(a136d13) Draw the discarded column behind a three-state visibility rotation, and bump to 0.31.1

This commit is contained in:
Ansho Rei
2026-08-25 03:33:38 +02:00
parent 5bf0fd1bfe
commit 60b43a682e
7 changed files with 321 additions and 162 deletions
+3 -2
View File
@@ -238,8 +238,9 @@ fn run_tui(paths: &[std::path::PathBuf], start: &std::path::Path) -> Result<()>
// columns took hjkl and the arrows.
KeyCode::Tab => board.select_tab(1, screen),
KeyCode::BackTab => board.select_tab(-1, screen),
// Free of the other bindings, and the footer names it in both states.
KeyCode::Char('d') => board.toggle_done(screen),
// Free of the other bindings, and the footer names what the next press
// does in every state of the rotation.
KeyCode::Char('d') => board.rotate_visibility(screen),
// An ordinary single-shot action like the rest: it opens the prompt, and
// from the next keypress on `search_key` above has the keyboard. A `/`
// typed into an open prompt is taken there as a character, and one pressed
+294 -126
View File
@@ -1,4 +1,6 @@
//! The board as four columns, redrawn when the tree underneath it moves.
//! The board as one column per status, redrawn when the tree underneath it moves. The
//! two terminal columns are hidden until `d` reveals them, one step of the rotation at
//! a time.
//!
//! Modelled on frig's TUI: event poll on a short timeout so timed work still runs when
//! nobody is typing, state refreshed on a tick, and the terminal restored whatever
@@ -494,29 +496,31 @@ impl Tab {
self.campaigns.iter().find(|row| row.uuid == uuid)
}
/// The columns that are drawn: all of them, or everything up to done.
/// The columns that are drawn: all of them, or everything up to the reach of the
/// visibility.
///
/// A prefix rather than a filter, which is what keeps `column` and `offsets` usable
/// as indices into either. Taken from where done actually is instead of assuming the
/// last slot, with a test pinning done as last so the two cannot drift apart.
fn visible(&self, show_done: bool) -> &[Column] {
&self.columns[..self.visible_count(show_done)]
/// as indices into either. Taken from where done and discarded actually sit instead
/// of assuming positions, with `the_terminal_columns_are_last_in_the_order_drawn`
/// pinning the order so the two cannot drift apart.
fn visible(&self, visibility: Visibility) -> &[Column] {
&self.columns[..self.visible_count(visibility)]
}
fn visible_count(&self, show_done: bool) -> usize {
if show_done {
return self.columns.len();
}
match self.columns.iter().position(|column| column.status == DONE) {
Some(index) => index,
fn visible_count(&self, visibility: Visibility) -> usize {
match visibility.next_reveal() {
Some(status) => self
.columns
.iter()
.position(|column| column.status == status)
.unwrap_or(self.columns.len()),
None => self.columns.len(),
}
}
/// Keep the selection on a card that exists, after the board changes under it.
fn clamp(&mut self, show_done: bool) {
let visible = self.visible_count(show_done);
fn clamp(&mut self, visibility: Visibility) {
let visible = self.visible_count(visibility);
if visible == 0 {
self.column = 0;
self.card = 0;
@@ -878,6 +882,44 @@ fn tag_matches(tag: &TagRow, query: &str) -> bool {
.is_some_and(|annotation| annotation.to_lowercase().contains(&query))
}
/// How much of the flow's tail is drawn: neither terminal column, done alone, or both.
///
/// The states are cumulative rather than independent, which is what keeps hiding a
/// prefix of the columns and the selection arithmetic that rests on it working
/// unchanged. `d` walks the rotation in this order and wraps; discarded sits last in
/// it because it is the least likely thing to be looking for. The default is the
/// board's opening state, the opinion `ls` holds: both are counted everywhere and
/// drawn nowhere until asked for.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Visibility {
#[default]
Neither,
Done,
Both,
}
impl Visibility {
/// The next state of the rotation, wrapping back to hidden from the top.
fn advance(self) -> Self {
match self {
Visibility::Neither => Visibility::Done,
Visibility::Done => Visibility::Both,
Visibility::Both => Visibility::Neither,
}
}
/// The status whose column this state reveals on the next press, which is also the
/// boundary the drawn prefix stops short of: everything before it is on screen.
/// Nothing left to reveal means nothing is hidden.
fn next_reveal(self) -> Option<&'static str> {
match self {
Visibility::Neither => Some(DONE),
Visibility::Done => Some(DISCARDED),
Visibility::Both => None,
}
}
}
/// What is on screen.
pub struct Board {
/// The monitored boards as tabs, the merge first when there is more than one.
@@ -894,11 +936,11 @@ pub struct Board {
pub picker: Option<Picker>,
/// What the last action said, until the next keypress takes it away.
pub notice: Option<Notice>,
/// Whether the done column is drawn. Off at startup, and not remembered between
/// runs: worklane has no config file, and one flag is not a reason to start one.
/// Board-wide rather than per tab: it is a preference about the flow, not about a
/// project.
pub show_done: bool,
/// How many of the terminal columns are drawn. Hidden at startup, and not
/// remembered between runs: worklane has no config file, and one flag is not a
/// reason to start one. Board-wide rather than per tab: it is a preference about
/// the flow, not about a project.
pub visibility: Visibility,
pub should_quit: bool,
projects: Vec<Project>,
digest: u64,
@@ -928,7 +970,7 @@ impl Board {
search: None,
picker: None,
notice: None,
show_done: false,
visibility: Visibility::default(),
should_quit: false,
projects,
digest: 0,
@@ -1073,7 +1115,7 @@ impl Board {
// columns is not a thing statuses do, but the resize keeps the two in step
// regardless; `resize` both pads and truncates.
tab.offsets.resize(tab.columns.len(), 0);
tab.clamp(self.show_done);
tab.clamp(self.visibility);
}
self.digest = digest_of(&self.projects);
@@ -1097,11 +1139,11 @@ impl Board {
/// The columns of the tab in view that are drawn.
pub fn visible(&self) -> &[Column] {
self.current().visible(self.show_done)
self.current().visible(self.visibility)
}
fn visible_count(&self) -> usize {
self.current().visible_count(self.show_done)
self.current().visible_count(self.visibility)
}
/// Move to another tab, cycling at either end.
@@ -1109,8 +1151,8 @@ impl Board {
/// Tabs cycle where the cards and columns clamp: a ring is what a row of tabs is
/// everywhere else, and there is no bottom of a list to run out of. The tab keeps
/// its own selection, so all this has to do is check that the selection is still on
/// a card that exists — done may have been hidden while another tab was in view —
/// and bring it into the window.
/// a card that exists — terminal columns may have been hidden while another tab was
/// in view — and bring it into the window.
pub fn select_tab(&mut self, delta: isize, screen: Size) {
let count = self.tabs.len() as isize;
if count < 2 {
@@ -1119,28 +1161,31 @@ impl Board {
self.tab = (self.tab as isize + delta).rem_euclid(count) as usize;
let show_done = self.show_done;
self.current_mut().clamp(show_done);
let visibility = self.visibility;
self.current_mut().clamp(visibility);
self.follow_selection(screen);
self.refresh_detail();
}
/// Show or hide the done column.
/// Advance the rotation one step: hide both, show done, show both, and back around.
///
/// `ls` already holds this opinion: it counts done in its summary and leaves it out
/// of the listing. Done only grows, so a quarter of the width goes to the column
/// least often read while the three being worked get squeezed for it.
/// `ls` already holds the opinion the first state takes: it counts both terminal
/// statuses in its summary and leaves them out of the listing. Done only grows, so
/// a quarter of the width went to the column least often read; discarded is the
/// same again, and the least likely thing to be looking for, which is why it is
/// last in the rotation.
///
/// Hiding is a change to what is drawn, never to what is read. The directory stays
/// scanned and stays in the digest, so the count in the footer is right and revealing
/// the column needs no rescan.
pub fn toggle_done(&mut self, screen: Size) {
self.show_done = !self.show_done;
/// Hiding is a change to what is drawn, never to what is read: the directories stay
/// scanned and stay in the digest, so the counts in the footer are right and
/// revealing a column needs no rescan.
///
/// Showing a column appends it, so nothing below is reached and the selection stays
/// exactly where it was. Only the tab in view is corrected: the others are clamped
/// as they are switched to, since a selection nobody is looking at cannot be
/// pointing at anything on screen.
pub fn rotate_visibility(&mut self, screen: Size) {
self.visibility = self.visibility.advance();
// Showing done again appends a column, so nothing below is reached and the
// selection stays exactly where it was. Only the tab in view is corrected: the
// others are clamped as they are switched to, since a selection nobody is
// looking at cannot be pointing at anything on screen.
if self.current().column < self.visible_count() {
return;
}
@@ -1148,8 +1193,8 @@ impl Board {
// Hiding the column the selection is in moves it to the last one still drawn.
// An open detail closes with it: it is showing a ticket that is no longer on the
// board, and quietly swapping it for a different ticket is worse than closing.
let show_done = self.show_done;
self.current_mut().clamp(show_done);
let visibility = self.visibility;
self.current_mut().clamp(visibility);
self.detail = None;
self.offset = 0;
self.follow_selection(screen);
@@ -1177,10 +1222,10 @@ impl Board {
// Bounded by what is drawn, so the selection cannot walk into a hidden column.
let last = visible as isize - 1;
let show_done = self.show_done;
let visibility = self.visibility;
let tab = self.current_mut();
tab.column = (tab.column as isize + delta).clamp(0, last) as usize;
tab.clamp(show_done);
tab.clamp(visibility);
// Entering a column shows the card the selection landed on rather than
// resetting to its top: the card index carries across columns, so a reset
// would open the column with the highlight below the fold whenever it was.
@@ -1998,7 +2043,7 @@ fn span_from(text: impl Into<String>, color: Option<Color>) -> Span<'static> {
Span::styled(text.into(), style)
}
/// The four columns of one board, with each card's campaign already named.
/// The columns of one board, with each card's campaign already named.
///
/// The index is read once here and handed to every card, rather than looked up per card
/// or, worse, per draw: the uuid is on the ticket and the name is in another directory,
@@ -2013,15 +2058,16 @@ fn columns_of(worklane_dir: &Path) -> (Vec<Column>, CampaignIndex, TagIndex) {
// `unwrap_or_default` on the campaigns index already avoids.
let tags = TagIndex::load(worklane_dir).unwrap_or_default();
// Over `Status::FLOW`, not `Status::ALL`: the board draws the stages work moves
// through, and a discarded column on screen is a136d13's ticket, not a side effect
// of the status existing. Each column is ordered by its own entry stamp, so the
// build needs the status itself and not just the directory to read.
let mut columns: Vec<Column> = Status::FLOW
// Over `Status::ALL`: the board draws every status, and hiding the two terminal
// ones is a change to what is drawn, never to what is read. The footer counts are
// read off these columns while the columns are hidden, so revealing one needs no
// rescan. Each column is ordered by its own entry stamp, so the build needs the
// status itself and not just the directory to read.
let mut columns: Vec<Column> = Status::ALL
.into_iter()
.map(|status| {
// An absent or unreadable directory is an empty column, not a missing one:
// the four statuses are the shape of the board.
// every status is the shape of the board.
let mut cards: Vec<Card> = collect_ticket_items(worklane_dir.join(status.as_str()))
.unwrap_or_default()
.into_iter()
@@ -2165,7 +2211,11 @@ fn retain_tag(mut columns: Vec<Column>, tag: Option<&str>) -> Vec<Column> {
/// The cards are already in hand here, and a campaign's members are exactly the cards
/// naming its uuid, so this is what `Standing::of` builds for `campaign ls` without the
/// walk of the status directories that one pays per campaign. Every column, drawn or not:
/// hiding done is a change to what is drawn and never to what is counted.
/// hiding the terminal columns is a change to what is drawn and never to what is counted.
///
/// A discarded member counts as finished, the rule `Standing::of` and `campaign ls`
/// already hold: the work was decided out of the campaign rather than left in it. One
/// spelling of that through [`is_open`], so the two counters cannot drift.
///
/// A campaign nothing names is absent rather than zeroed, which `campaign_rows` reads as
/// the default standing — `no members`, the same answer `campaign show` gives it.
@@ -2180,7 +2230,7 @@ fn standings_of(columns: &[Column]) -> HashMap<&str, Standing> {
let standing = standings.entry(uuid).or_default();
standing.total += 1;
standing.done += usize::from(column.status == DONE);
standing.done += usize::from(!is_open(column.status));
}
}
@@ -2192,7 +2242,7 @@ fn standings_of(columns: &[Column]) -> HashMap<&str, Standing> {
///
/// Every column is kept, empty ones included, for the reason `campaign show` prints every
/// status: a campaign groups across the flow rather than within one status, so the shape of
/// the answer is the four columns and the question is how many are in each. Filtered here,
/// 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> {
@@ -2253,14 +2303,17 @@ fn mark_blocked(columns: &mut [Column]) {
}
}
/// Every board's columns as one set of four, each card labelled with the project it
/// Every board's columns as one set, each card labelled with the project it
/// came from.
///
/// Sorted through `by_priority_then_title`, the order the listing uses, rather than
/// left as one project's column after another's: an overview whose order depended on
/// the argument order would bury a p1 under another project's p5.
fn merge(per_project: &[Vec<Column>], projects: &[Project]) -> Vec<Column> {
Status::FLOW
// All five, matching what `columns_of` builds: the merge is indexed beside the
// project tabs, and hiding is decided by the visibility, never by leaving a status
// out here.
Status::ALL
.into_iter()
.map(Status::as_str)
.enumerate()
@@ -3169,11 +3222,13 @@ fn draw_footer(frame: &mut Frame, board: &Board, area: Rect) {
return;
}
// While done is hidden its count goes here, which is the board's version of the
// summary line `ls` prints above a listing that leaves done out.
let done = match board.show_done {
true => "d hide done".to_string(),
false => format!("d show done ({})", done_count(board)),
// The next press names itself here, whichever state the rotation is in, and the
// column it would reveal keeps its count until it is drawn. That is the board's
// version of the summary line `ls` prints above a listing that leaves the terminal
// statuses out.
let d = match board.visibility.next_reveal() {
Some(status) => format!("d show {} ({})", status, column_count(board, status)),
None => "d hide both".to_string(),
};
// Only when there is a tab to move to, since the footer names keys that work.
@@ -3227,13 +3282,13 @@ fn draw_footer(frame: &mut Frame, board: &Board, area: Rect) {
let keys = match (board.detail.is_some(), board.current().focus) {
(true, _) => format!(
" {tabs}←→↑↓ select pgup/pgdn scroll / search y copy id enter/q close {done} {quit} "
" {tabs}←→↑↓ select pgup/pgdn scroll / search y copy id enter/q close {d} {quit} "
),
(false, Focus::Frame) => format!(
" {tabs}↓ board {height} pgup/pgdn scroll / search y copy id {done} {quit} "
" {tabs}↓ board {height} pgup/pgdn scroll / search y copy id {d} {quit} "
),
(false, Focus::Cards) => format!(
" {tabs}←→ column ↑↓ card / search {filter}y copy id enter detail {done} {quit} "
" {tabs}←→ column ↑↓ card / search {filter}y copy id enter detail {d} {quit} "
),
};
@@ -3324,13 +3379,13 @@ fn draw_picker_row(frame: &mut Frame, picker: &Picker, area: Rect) {
frame.set_cursor_position((area.x + at, area.y));
}
/// How many tickets are in done on the tab in view, drawn or not.
fn done_count(board: &Board) -> usize {
/// How many tickets are in one status on the tab in view, drawn or not.
fn column_count(board: &Board, status: &str) -> usize {
board
.current()
.columns
.iter()
.find(|column| column.status == DONE)
.find(|column| column.status == status)
.map_or(0, |column| column.cards.len())
}
@@ -3945,44 +4000,92 @@ mod tests {
}
#[test]
fn the_board_draws_the_four_statuses_as_columns_once_done_is_shown() {
fn the_board_draws_every_status_as_a_column_once_both_are_shown() {
let dir = board_dir();
write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "First one", "");
write_ticket(&dir, "committed", "22222222-0000-4000-8000-000000000000", "Second one", "");
write_ticket(&dir, DISCARDED, "55555555-0000-4000-8000-000000000000", "Gone one", "");
let mut board = one_board(&dir);
board.toggle_done(SCREEN);
let row = headings(&board, 120, 20);
board.rotate_visibility(SCREEN);
board.rotate_visibility(SCREEN);
let row = headings(&board, 140, 20);
for heading in ["backlog (1)", "committed (1)", "reviewing (0)", "done (0)"] {
for heading in [
"backlog (1)",
"committed (1)",
"reviewing (0)",
"done (0)",
"discarded (1)",
] {
assert!(row.contains(heading), "no {heading:?} in:\n{row}");
}
}
/// Done only grows, and it is the column least often read. `ls` already leaves it
/// out of its listing while counting it in the summary; this is the same opinion.
/// The terminal columns only grow, and they are the ones least often read. `ls`
/// already leaves them out of its listing while counting them in the summary; the
/// first state of the rotation is the same opinion.
#[test]
fn the_board_opens_with_the_done_column_hidden() {
fn the_board_opens_with_the_terminal_columns_hidden() {
let dir = board_dir();
write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "First one", "");
write_ticket(&dir, "done", "44444444-0000-4000-8000-000000000000", "Finished one", "");
write_ticket(&dir, DISCARDED, "55555555-0000-4000-8000-000000000000", "Dropped one", "");
let board = one_board(&dir);
assert!(!board.show_done, "done was drawn at startup");
assert_eq!(board.visibility, Visibility::Neither, "a column was drawn at startup");
let row = headings(&board, 120, 20);
for heading in ["backlog (1)", "committed (0)", "reviewing (0)"] {
assert!(row.contains(heading), "no {heading:?} in:\n{row}");
}
assert!(!row.contains("done"), "done is still a column:\n{row}");
assert!(!row.contains("discarded"), "discarded is still a column:\n{row}");
// Hidden, not unread: the count is right and revealing it needs no rescan.
assert_eq!(board.current().columns.len(), 4);
// Hidden, not unread: the counts are right and revealing either needs no rescan.
assert_eq!(board.current().columns.len(), Status::ALL.len());
assert_eq!(board.visible().len(), 3);
assert_eq!(done_count(&board), 1);
assert_eq!(column_count(&board, DONE), 1);
assert_eq!(column_count(&board, DISCARDED), 1);
let screen = render(&board, 120, 20).join("\n");
assert!(!screen.contains("Finished one"), "a hidden done ticket was drawn");
assert!(!screen.contains("Dropped one"), "a hidden discarded ticket was drawn");
}
/// The rotation itself, one press at a time: hide both, show done, show both, and
/// back to hidden. Done first because it is the more likely thing to be looking
/// for; discarded last because it is the least.
#[test]
fn d_rotates_hidden_then_done_then_both_and_back_to_hidden() {
let dir = board_dir();
write_ticket(&dir, "reviewing", "33333333-0000-4000-8000-000000000000", "Ready", "");
write_ticket(&dir, "done", "44444444-0000-4000-8000-000000000000", "Finished", "");
write_ticket(&dir, DISCARDED, "55555555-0000-4000-8000-000000000000", "Dropped", "");
let mut board = one_board(&dir);
board.rotate_visibility(SCREEN);
assert_eq!(board.visibility, Visibility::Done);
assert_eq!(board.visible().len(), 4);
assert!(headings(&board, 120, 20).contains("done (1)"), "done was not drawn");
assert!(
!render(&board, 120, 20).join("\n").contains("Finished one"),
"a hidden done ticket was drawn"
!render(&board, 140, 20).join("\n").contains("Dropped"),
"discarded came with done"
);
board.rotate_visibility(SCREEN);
assert_eq!(board.visibility, Visibility::Both);
assert_eq!(board.visible().len(), Status::ALL.len());
let row = headings(&board, 140, 20);
assert!(row.contains("discarded (1)"), "{row}");
board.rotate_visibility(SCREEN);
assert_eq!(board.visibility, Visibility::Neither);
assert_eq!(board.visible().len(), 3);
assert!(
!render(&board, 140, 20).join("\n").contains("Finished"),
"done stayed drawn after the wrap"
);
}
@@ -3996,39 +4099,62 @@ mod tests {
assert_eq!(hidden.matches('┌').count(), 3, "{hidden}");
assert!(hidden.ends_with('┐'), "the columns stop short of the edge:\n{hidden}");
board.toggle_done(SCREEN);
board.rotate_visibility(SCREEN);
let shown = headings(&board, 120, 20);
assert_eq!(shown.matches('┌').count(), 4, "{shown}");
assert!(shown.ends_with('┐'), "{shown}");
board.rotate_visibility(SCREEN);
let both = headings(&board, 140, 20);
assert_eq!(both.matches('┌').count(), 5, "{both}");
assert!(both.ends_with('┐'), "{both}");
}
/// Hiding is a prefix of the columns, which only holds while done is last of what
/// the board draws. The board leans on that, so the assumption is pinned rather
/// than assumed. Discarded being last overall is the other decided order: the stamp
/// arrival rule truncates by `Status::ALL`, so discarded after done is what lets a
/// discard keep the journey the ticket made.
/// Hiding is a prefix of the columns, which only holds while done and discarded are
/// the last two of what the board draws. The board leans on that, so the assumption
/// is pinned rather than assumed. Discarded being last overall is the other decided
/// order: the stamp arrival rule truncates by `Status::ALL`, so discarded after done
/// is what lets a discard keep the journey the ticket made.
#[test]
fn the_done_column_is_last() {
assert_eq!(Status::FLOW.last().map(|status| status.as_str()), Some(DONE));
fn the_terminal_columns_are_last_in_the_order_drawn() {
let last: Vec<&str> = Status::ALL.iter().map(|status| status.as_str()).collect();
assert_eq!(&last[last.len() - 2..], &[DONE, DISCARDED]);
assert_eq!(status_dirs().last(), Some(&DISCARDED));
}
/// Each state names what the next press does, and a column still hidden keeps its
/// count until it is drawn.
#[test]
fn the_footer_names_the_key_and_carries_the_count_while_done_is_hidden() {
fn the_footer_names_the_next_press_of_d_and_carries_the_hidden_count() {
let dir = board_dir();
for (n, title) in [("44444444", "One"), ("55555555", "Two")] {
write_ticket(&dir, "done", &format!("{n}-0000-4000-8000-000000000000"), title, "");
}
write_ticket(&dir, DISCARDED, "66666666-0000-4000-8000-000000000000", "Three", "");
let mut board = one_board(&dir);
let hidden = footer(&board, 120, 20);
assert!(hidden.contains("d show done (2)"), "{hidden}");
board.toggle_done(SCREEN);
let shown = footer(&board, 120, 20);
assert!(shown.contains("d hide done"), "{shown}");
// With the column drawn, its own heading carries the count.
assert!(!shown.contains("(2)"), "the count is printed twice:\n{shown}");
// Hidden: the next press reveals done, whose count is carried here.
let neither = footer(&board, 120, 20);
assert!(neither.contains("d show done (2)"), "{neither}");
board.rotate_visibility(SCREEN);
// Done shown: the next press reveals discarded, whose count is carried here.
let done = footer(&board, 120, 20);
assert!(done.contains("d show discarded (1)"), "{done}");
board.rotate_visibility(SCREEN);
// Both shown: their own headings carry the counts, so nothing is printed twice.
let both = footer(&board, 140, 20);
assert!(both.contains("d hide both"), "{both}");
assert!(!both.contains("(2)"), "the count is printed twice:\n{both}");
assert!(!both.contains("(1)"), "the count is printed twice:\n{both}");
// And around again.
board.rotate_visibility(SCREEN);
assert_eq!(board.visibility, Visibility::Neither, "the rotation did not wrap");
}
/// The modal footer names it too, since the key works with a ticket open.
@@ -4046,6 +4172,7 @@ mod tests {
}
/// Hiding the column under the selection has to move it, or it points at nothing.
/// Reaching hidden from both shown takes the rest of the rotation.
#[test]
fn hiding_done_under_the_selection_moves_it_to_the_last_visible_column() {
let dir = board_dir();
@@ -4053,11 +4180,16 @@ mod tests {
write_ticket(&dir, "done", "44444444-0000-4000-8000-000000000000", "Finished", "");
let mut board = one_board(&dir);
board.toggle_done(SCREEN);
board.rotate_visibility(SCREEN);
board.select_column(3, SCREEN);
assert_eq!(selected_title(&board), Some("Finished".to_string()));
board.toggle_done(SCREEN);
// Through both, where done stays drawn and the selection stays put...
board.rotate_visibility(SCREEN);
assert_eq!(selected_title(&board), Some("Finished".to_string()));
// ...and back to hidden, where the selection has to move.
board.rotate_visibility(SCREEN);
assert_eq!(board.current().column, 2, "the selection stayed on a column that is gone");
assert_eq!(selected_title(&board), Some("Ready".to_string()));
}
@@ -4072,12 +4204,15 @@ mod tests {
write_ticket(&dir, "done", "44444444-0000-4000-8000-000000000000", "Finished", "");
let mut board = one_board(&dir);
board.toggle_done(SCREEN);
board.rotate_visibility(SCREEN);
board.select_column(3, SCREEN);
board.toggle_detail();
assert!(board.detail.is_some());
board.toggle_done(SCREEN);
board.rotate_visibility(SCREEN);
assert!(board.detail.is_some(), "the detail closed while done was still drawn");
board.rotate_visibility(SCREEN);
assert!(board.detail.is_none(), "{:?}", board.detail);
}
@@ -4089,8 +4224,9 @@ mod tests {
let mut board = one_board(&dir);
board.toggle_detail();
board.toggle_done(SCREEN);
board.toggle_done(SCREEN);
board.rotate_visibility(SCREEN);
board.rotate_visibility(SCREEN);
board.rotate_visibility(SCREEN);
assert!(board.detail.is_some(), "an unrelated detail view was closed");
}
@@ -4108,7 +4244,7 @@ mod tests {
board.select_card(1, SCREEN);
let (column, card) = (board.current().column, board.current().card);
board.toggle_done(SCREEN);
board.rotate_visibility(SCREEN);
assert_eq!((board.current().column, board.current().card), (column, card));
assert_eq!(selected_title(&board), Some("Beta".to_string()));
}
@@ -4124,7 +4260,7 @@ mod tests {
assert_eq!(board.current().column, 2);
assert!(board.selected().is_none(), "the selection reached the done column");
board.toggle_done(SCREEN);
board.rotate_visibility(SCREEN);
board.select_column(9, SCREEN);
assert_eq!(board.current().column, 3);
assert_eq!(selected_title(&board), Some("Finished".to_string()));
@@ -4577,11 +4713,12 @@ mod tests {
let dir = board_dir();
let mut board = one_board(&dir);
assert_eq!(board.current().columns.len(), 4);
assert_eq!(board.current().columns.len(), Status::ALL.len());
board.toggle_done(SCREEN);
let row = headings(&board, 120, 20);
for status in Status::FLOW {
board.rotate_visibility(SCREEN);
board.rotate_visibility(SCREEN);
let row = headings(&board, 140, 20);
for status in Status::ALL {
assert!(row.contains(&format!("{} (0)", status.as_str())), "{row}");
}
}
@@ -4593,10 +4730,13 @@ mod tests {
std::fs::remove_dir_all(dir.join(DONE)).unwrap();
let mut board = one_board(&dir);
assert_eq!(board.current().columns.len(), 4);
assert_eq!(board.current().columns.len(), Status::ALL.len());
board.toggle_done(SCREEN);
assert!(headings(&board, 120, 20).contains("done (0)"));
board.rotate_visibility(SCREEN);
board.rotate_visibility(SCREEN);
let row = headings(&board, 140, 20);
assert!(row.contains("done (0)"), "{row}");
assert!(row.contains("discarded (0)"), "{row}");
}
#[test]
@@ -5529,8 +5669,8 @@ mod tests {
assert!(board.search_key(key, SCREEN), "{key:?} was not taken");
}
assert!(!board.show_done, "typing 'd' toggled the done column");
assert!(!board.should_quit, "typing 'q' quit the board");
assert_eq!(board.visibility, Visibility::Neither, "typing 'd' rotated the columns");
assert_eq!(selected_title(&board), before, "an arrow moved the selection");
// The letters landed in the query; the keys that are not characters did not.
assert_eq!(board.search.as_ref().map(|s| s.query.as_str()), Some("dqjh"));
@@ -5646,7 +5786,7 @@ mod tests {
);
board.search_key(typed(KeyCode::Esc), SCREEN);
board.toggle_done(SCREEN);
board.rotate_visibility(SCREEN);
board.open_search();
type_query(&mut board, "delta");
board.search_key(typed(KeyCode::Enter), SCREEN);
@@ -6370,12 +6510,11 @@ mod tests {
/// A discarded blocker holds nothing up, the answer `mv` gives it: there is nothing
/// left to wait for.
///
/// The board reaches it through `is_open` rather than through the blocker being
/// absent from the columns, which is what it would be today, since `columns_of`
/// builds `Status::FLOW` and discarded is not in it. That distinction is the point of
/// this test: when a136d13 draws the discarded column the blocker arrives in the map,
/// and a rule written as `!= DONE` would start marking these cards while `mv` kept
/// letting them move. The fixture writes the directory directly for that reason.
/// The board and `mv` share `is_open` for this, which is what keeps them from
/// drifting now that the blocker arrives in the map: `columns_of` builds every
/// status, so a rule written as `!= DONE` would mark these cards while `mv` kept
/// letting them move. The fixture writes the directory directly, the way a board
/// that predates a discard would hold one.
#[test]
fn a_discarded_blocker_marks_nothing() {
let dir = board_dir();
@@ -7571,7 +7710,7 @@ mod tests {
fn picking_a_tag_filters_every_column_to_the_cards_carrying_it() {
let dir = board_dir();
let mut board = tag_board(&dir);
board.show_done = true;
board.visibility = Visibility::Both;
board.select_filter(Filter::Tag("bug".to_string()), SCREEN);
@@ -7993,7 +8132,7 @@ mod tests {
assert!(headings(&board, 100, 24).contains("backlog (1)"), "the board did not draw");
}
/// Selecting a campaign turns the four columns into that campaign's members grouped
/// Selecting a campaign turns the columns into that campaign's members grouped
/// by status, which is the shape `campaign show` already answers the question in.
#[test]
fn selecting_a_campaign_filters_every_column_to_its_members() {
@@ -8013,7 +8152,7 @@ mod tests {
.collect();
assert_eq!(titles, vec!["In v1".to_string(), "Also in v1".to_string()], "{titles:?}");
// Every column is kept, empty ones included: a campaign's shape is the flow.
assert_eq!(board.current().columns.len(), Status::FLOW.len());
assert_eq!(board.current().columns.len(), Status::ALL.len());
}
/// The frame says which campaign the columns belong to, and how far it has got, from
@@ -8070,11 +8209,40 @@ mod tests {
let mut board = one_board(&dir);
board.select_filter(Filter::Campaign(V1.to_string()), SCREEN);
assert!(!board.show_done, "done is hidden at startup");
assert_eq!(board.visibility, Visibility::Neither, "a column is drawn at startup");
let standing = board.campaign().expect("no campaign selected").standing;
assert_eq!((standing.done, standing.total), (1, 2));
}
/// A member decided out of the campaign counts as finished, the rule `campaign ls`
/// holds: counting it outstanding would hold the campaign open over a ticket nobody
/// will ever do.
#[test]
fn the_standing_counts_a_discarded_member_as_finished() {
let dir = board_dir();
write_campaign(&dir, V1, "First public release", "v1", "For a tag.");
write_ticket(
&dir,
"backlog",
"11111111-0000-4000-8000-000000000000",
"Open one",
&campaign_field(V1),
);
write_ticket(
&dir,
DISCARDED,
"55555555-0000-4000-8000-000000000000",
"Dropped one",
&campaign_field(V1),
);
let mut board = one_board(&dir);
board.select_filter(Filter::Campaign(V1.to_string()), SCREEN);
let standing = board.campaign().expect("no campaign selected").standing;
assert_eq!((standing.done, standing.total), (1, 2), "the discard was not counted");
}
/// The frame takes its three rows off the columns rather than off the footer, and
/// every measurement of the board has to agree about that: a keypress that scrolled
/// against the taller board would put the selection where the draw does not.
@@ -8981,7 +9149,7 @@ mod tests {
"the picker let {code:?} through"
);
}
assert!(!board.show_done, "d reached the done column");
assert_eq!(board.visibility, Visibility::Neither, "d reached the columns");
assert!(board.picker.is_some(), "the picker closed on a key it does not use");
// `/` last, and taken by the picker's own query rather than by the board's prompt:
// the key that searches a list of cards searches this list, and the two must not
@@ -8992,7 +9160,7 @@ mod tests {
// Every other control combination is swallowed and does nothing, or `ctrl-d` would
// reach the arm bound to `d`.
board.picker_key(KeyEvent::new(KeyCode::Char('d'), KeyModifiers::CONTROL), SCREEN);
assert!(!board.show_done, "ctrl-d reached the done column");
assert_eq!(board.visibility, Visibility::Neither, "ctrl-d reached the columns");
}
/// `ctrl-c` is the one key it declines, because a terminal application always honours
+12 -22
View File
@@ -2707,8 +2707,8 @@ pub enum Status {
impl Status {
/// Every status, in flow order with discarded last. The one list, which
/// [`status_dirs`], `mv` and every caller of [`by_status_order`] read rather than
/// spelling the five names again.
/// [`status_dirs`], `mv`, the board's columns and every caller of
/// [`by_status_order`] read rather than spelling the five names again.
pub const ALL: [Status; 5] = [
Status::Backlog,
Status::Committed,
@@ -2717,19 +2717,6 @@ impl Status {
Status::Discarded,
];
/// The stages work moves through: every status but discarded, which work never
/// moves through, it only ends up in.
///
/// What the board draws its columns from, so done stays the last drawn column and
/// hiding it stays a prefix of the list. Showing a discarded column is a136d13's,
/// not a side effect of the status existing.
pub const FLOW: [Status; 4] = [
Status::Backlog,
Status::Committed,
Status::Reviewing,
Status::Done,
];
/// The field `mv` stamps on entering this status, for the four that have one.
///
/// Derived from the status rather than spelled at the call site, so the mapping is
@@ -2762,17 +2749,20 @@ pub fn status_dirs() -> Vec<&'static str> {
Status::ALL.iter().map(|status| status.as_str()).collect()
}
/// The end of the flow, and the one status both views treat differently: `ls` counts it
/// in the summary and leaves it out of the listing, and the board hides its column until
/// asked. Named because that rule now has two readers.
/// The end of the flow, and one of the two statuses both views treat differently: `ls`
/// counts it in the summary and leaves it out of the listing, and the board hides its
/// column until `d` reveals it. Named because that rule now has two readers.
///
/// It is deliberately last in [`Status::FLOW`], which is what the board draws. The board
/// leans on that: hiding done drops the final column, so the other three keep their
/// indices and the selection only has to be handled when it is sitting on done itself.
/// Done and discarded are deliberately the last two in [`Status::ALL`], which is what
/// the board builds its columns from: hiding either is then a prefix of that list, so
/// the columns before them keep their indices and the selection only has to be handled
/// when it is sitting on a column that just went away. Discarded after done is also
/// what lets the stamp arrival rule keep a discard's journey.
pub const DONE: &str = Status::Done.as_str();
/// Where a ticket that will not be done ends up: the other terminal status, and the
/// other one `ls` leaves out of the listing.
/// other one `ls` leaves out of the listing and the board keeps off the screen until
/// asked, last in the rotation because it is the least likely thing to be looking for.
///
/// A discarded ticket counts as finished wherever progress is measured, since nothing is
/// left to do, and blocks nothing. What it is not is done: the two directories keep