diff --git a/AGENTS.md b/AGENTS.md index 198194f..057f436 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -28,7 +28,7 @@ - Metadata fields parsed by `parse_ticket_field()`: `ID`, `Priority`, `Tags`, `Due`, `Owner`, `Created At`, `Committed On`, `Submitted On`, `Completed On`, `Discarded On`, `Campaign`, `Status`. The last five are the ones no ticket is born with: `add` writes none of them, so they are inserted on demand, against `METADATA_ORDER`, which is also what keeps `Status` last - The four stamps are `mv`'s, written by `set_status_stamp` from `Status::stamp_field`, and they **accumulate**: entering a status writes its field, re-entering restamps, and arriving anywhere removes the fields of every status *after* the target. One arrival rule keyed off `Status::ALL`, not a case per move, which is why a backward move truncates the journey at the target (`done` back to `reviewing` drops `Completed On`, anything back to `backlog` drops all three) and a forward skip under `-f` stamps only where it lands rather than fabricating the stages it jumped. A ticket that walks the whole flow ends with `Created At`, `Committed On`, `Submitted On` and `Completed On` side by side, so presence means *got this far and has not been sent back past it*, not *is here now* — `Status` is what says where it is. Not the history log either: these answer how far and when, once per stage, and every change along the way is the log's. `backlog` has no stamp, `Created At` already answers for it - **`Discarded` is last in `Status::ALL`, and that placement is what makes the stamp rule fall out right.** Nothing sits after it, so a discard clears nothing: a ticket abandoned from reviewing keeps `Committed On` and `Submitted On`, and the file still says how far it got before it was dropped. It also makes every move out of discarded a backward move, so un-discarding needs `-f` without a rule of its own. `Discarded On` is its stamp, and `Completed On` stays untouched, because a discarded ticket was never done -- **Each status column is ordered by its own entry stamp, through `by_status_order`.** Priority is the clock in the backlog and that column keeps priority then title; past it the question changes, so committed sorts by `Committed On` ascending, reviewing by `Submitted On` ascending, and done and discarded by their stamp descending. Said once: the head of every column is what the reader acts on next. An unstamped ticket sinks below every stamped one in its column, because a missing time is unknown rather than ancient and unknown must not claim the head of a queue; equal stamps and both-unstamped fall through to `by_priority_then_title`. One function keyed on the `Status`, taken by both `cmd_ls` branches, `list_ids`, `columns_of` and `campaign::members`, which is why those loops walk `Status::ALL` (or `Status::FLOW`) rather than `status_dirs()`. The stamps are read in `collect_ticket_items`' existing pass, the rule `criteria` and `tags` already hold, and compared as strings: `%Y-%m-%d %H:%M:%S` is lexicographic in chronological order, the property `Due` already relies on, so nothing parses a date at sort time +- **Each status column is ordered by its own entry stamp, through `by_status_order`.** Priority is the clock in the backlog and that column keeps priority then title; past it the question changes, so committed sorts by `Committed On` ascending, reviewing by `Submitted On` ascending, and done and discarded by their stamp descending. Said once: the head of every column is what the reader acts on next. An unstamped ticket sinks below every stamped one in its column, because a missing time is unknown rather than ancient and unknown must not claim the head of a queue; equal stamps and both-unstamped fall through to `by_priority_then_title`. One function keyed on the `Status`, taken by both `cmd_ls` branches, `list_ids`, `columns_of` and `campaign::members`, which is why those loops walk `Status::ALL` rather than `status_dirs()`. The stamps are read in `collect_ticket_items`' existing pass, the rule `criteria` and `tags` already hold, and compared as strings: `%Y-%m-%d %H:%M:%S` is lexicographic in chronological order, the property `Due` already relies on, so nothing parses a date at sort time - Format: `**Field Name**: value` - Ticket structure: `# Title` → `## Description` → `## Acceptance Criteria` → `## Implementation Plan` → `## Metadata` - A **campaign** file carries `ID`, `Codename`, `Owner` and `Created At`, in that order, and no `Status`. `Codename` sits directly under the ID because that is what it is, a second way to say which campaign this is; it is written by `campaign add --codename` alone and is `_Not set_` when the flag was not given. It is not in `METADATA_ORDER`, which is the anchor list for the *upsert* on a ticket, and nothing upserts a campaign @@ -37,7 +37,7 @@ ## Status Workflow `backlog` → `committed` → `reviewing` → `done`, and `discarded` off to one side -- **`Status::ALL` and `Status::FLOW` are two different questions, and picking the wrong one is the mistake to watch for here.** `ALL` is every directory that can hold a ticket, which is what the tree walkers want: `status_dirs`, `RelationIndex::load`, `collect_ticket_items`' callers, `cmd_tags`, `list_ids`, the resolver and the digest all have to see a discarded ticket or it becomes unaddressable. `FLOW` is the four stages work moves through, which is what the *board* draws: a discarded column on screen is a136d13's ticket, not a side effect of the status existing, and keeping it out of `FLOW` is also what keeps done the last drawn column so hiding it stays a prefix +- **`Status::ALL` is every directory that can hold a ticket, and that is the only list left.** It is what the tree walkers want: `status_dirs`, `RelationIndex::load`, `collect_ticket_items`' callers, `cmd_tags`, `list_ids`, the resolver, the digest and the board's own columns all have to see a discarded ticket or it becomes unaddressable. There was a second list, `FLOW`, the four stages work moves through, which used to be what the board drew from; a136d13 drew the discarded column behind a visibility prefix instead, which took FLOW's last reader away, so it is gone. Hiding is decided by `Visibility`, never by leaving a status out of the walk: what is drawn changes, what is read does not. The prefix property survives on the order alone — done and discarded are deliberately the last two in `ALL` — and `the_terminal_columns_are_last_in_the_order_drawn` pins it - **Discarding is not a stage, so the walk rules do not apply to entering it.** `mv --status discarded` is allowed from any status with no `-f`, because a backlog ticket that turns out to be a duplicate should not have to be walked through committed and reviewing to be abandoned. Leaving it needs `-f`, which comes free from the backward-move rule - **The two dependency guards look opposite ways, and `mv` picks by direction.** `check_blockers` asks what this ticket waits on and gates work moves; `check_dependents` asks who waits on this ticket and gates the discard. A ticket being abandoned owes nothing to its own blockers, but the tickets blocked *by* it recorded a dependency on work that is about to be declared never-happening, so those plans get a look before the ground moves. `-f` is the caller saying they looked. Both name every offender rather than the first, and both skip targets that are themselves done or discarded - **Discarded satisfies a block the way done does.** There is nothing left to wait for, and whether the dependent still makes sense was asked at discard time by the guard above, which is what makes it safe to pass here rather than a second place to re-ask @@ -254,7 +254,7 @@ and this file is for what someone changing worklane's own code needs. - **A card names its campaign on the label row, before the tags, in bold.** `labels_line` draws both, `CAMPAIGN_MARK` (`~`) for the campaign and `#` for a tag, and the campaign takes the row's width first: two cards in one campaign is what a reader looking for a campaign is looking for, and the tags are the context around it. So a row too narrow for both drops the tags whole and keeps the campaign, the order `corner_line` and `project_label` already follow, and a campaign the row will not hold at all goes whole too. A ticket in neither spends no row, so **a ticket in no campaign renders exactly as it did before campaigns reached the card** - **`Card::campaign` is a resolved `Cell`, not a uuid**, settled at reload the way `project` and `blocked` are. `TicketItem::campaign` already carries the uuid off the pass that builds the card; the name is in another directory, so `columns_of` reads `CampaignIndex` once per project and hands it to every card. Never per draw, the rule `criteria` and `tags` already hold. The merge carries the resolved cell rather than looking it up again, for the reason it carries `blocked`: a campaign is addressed inside one `.worklane`, so a merged lookup could answer one project's uuid with another project's campaign - **A campaign the board does not hold labels nothing**, the answer `mark_blocked` gives a dangling blocker. `campaign_cells` renders that case as `_missing_` because a metadata table is a place to report a dangling reference; a card is not -- **`c` opens the campaign picker, and taking a campaign filters the tab's columns to its members.** Not a fifth tab: a campaign groups across the flow, so the shape of the answer is the four statuses with fewer cards in them, which is what `campaign show` already answers the question in. Every column is kept, empty ones included. The filter is applied in `reload`, where the columns are built, so nothing downstream has to ask whether a campaign is selected — the board simply holds fewer cards, and `first_match`, `done_count` and the copy key all keep working unchanged +- **`c` opens the campaign picker, and taking a campaign filters the tab's columns to its members.** Not a fifth tab: a campaign groups across the flow, so the shape of the answer is the statuses with fewer cards in them, which is what `campaign show` already answers the question in. Every column is kept, empty ones included. The filter is applied in `reload`, where the columns are built, so nothing downstream has to ask whether a campaign is selected — the board simply holds fewer cards, and `first_match`, `column_count` and the copy key all keep working unchanged - **`Tab::campaign` is a uuid on the tab, not on the `Board`.** A campaign belongs to one `.worklane`, so a filter carried onto another project's tab would empty it and say nothing about why. It is looked up by uuid rather than held as an index, and a selection whose campaign has left the board is cleared by `reload` rather than left filtering the board to nothing - **The frame above the columns has two heights, and `Chrome` is what every measurement takes.** `Chrome::campaign` is an `Option`, not a bool: `None` for a tab showing the whole board, and `Collapsed` or `Expanded` for one filtered to a campaign, because both heights have to be measured the same way by everything that measures the board. `frame_rows` grew a row, so the two bools that decide the geometry became one `Chrome`, copied from `Board::chrome`: adjacent same-typed parameters are what the Rust Style rule warns about, and the draw and `follow_selection` have to measure one answer or a keypress scrolls against a board the next frame does not draw. The row indices are named (`TAB_ROW`, `CAMPAIGN_ROW`, `BOARD_ROW`, `FOOTER_ROW`), since an index written out by hand goes on meaning what it used to - **The whole description is carried off the one read, and the cut is on the view.** `section_prose` replaced `section_opening`, which cut to the opening line at read time: the campaign file is only in hand while the campaigns directory is being read, so what that read has to carry is everything a view might want, and `CampaignRow::summary` takes the one line the picker draws back off it. Two fields, one cut from the other, are two strings free to come from different reads of the same file @@ -296,15 +296,15 @@ and this file is for what someone changing worklane's own code needs. - `tags` is a field on `TicketItem`, filled in `collect_ticket_items` through `parse_tags`, for the reason the criteria count is. `parse_tags` splits the comma-separated field into whole trimmed values, so a caller asking for `bug` is not answered by `bugfix`, and reads absent, `_None_` and empty as the same answer - **A held-up card carries `BLOCKED_MARK`, `×`, after its id, in brightred.** The constant lives in `util.rs` and the relations block draws the same one, since both say the same word. A ticket waiting on an open blocker looked exactly like one that is ready, and the board is where the next thing to pick up is chosen. Not a fourth circle from Geometric Shapes: those belong to the priority meter two cells away and would read as part of that ramp. The multiplication sign is Latin-1, like the middle dot the unset priority draws, so it renders wherever the meter does - **The mark goes after the id, not before it.** Ahead of the id it would push every id in the column out of line whenever one card was blocked, which costs more than one card's state is worth. It is measured before the project label and the due date, so both give way to it: those are context for a ticket somebody can start, and this is the one thing on a card that says not to. Dropped whole when the row cannot hold the identity and the mark together, the rule a corner follows -- **`blocked` is on `Card`, not on `TicketItem`.** The answer lives on two tickets at once, so no card can reach it alone, and it is settled at reload the way `project` is. What `collect_ticket_items` fills is the ticket's own `uuid` and its `blockers`, both read off the file it is already holding; `mark_blocked` then walks the four columns once for a uuid-to-status map and once to answer every card. No file is read twice and nothing is asked per draw +- **`blocked` is on `Card`, not on `TicketItem`.** The answer lives on two tickets at once, so no card can reach it alone, and it is settled at reload the way `project` is. What `collect_ticket_items` fills is the ticket's own `uuid` and its `blockers`, both read off the file it is already holding; `mark_blocked` then walks the columns once for a uuid-to-status map and once to answer every card. No file is read twice and nothing is asked per draw - **A blocker the board does not hold marks nothing**, the answer `mv` already gives a dangling uuid. A Relations section that cannot be parsed reads as no blockers, the exception `detail_of` makes for the same reason: `show` and `mv` are where a hand-edited file is reported, and a board that will not draw because one ticket is malformed is the worse failure - **The merge carries the flag rather than recomputing it.** `relate` resolves its target inside one `.worklane`, so a blocker in another project is not a relation anything can record; resolving over the merged columns would let one project's uuid match another project's ticket. That is b8ce18c's fourth plan step and the answer is no - `project_label` takes the width the row has already spent, measured off the spans, rather than adding up the widths those spans are supposed to have. The hand-written version left out the space after the priority mark, so a cut label was handed one cell more than the column had; `the_project_label_leaves_the_row_inside_the_column` pins it - `due_date` cuts a due value back to its date only when it has one. The field is not validated (daa0e79), so it can hold a time or free text, and taking the first word regardless would turn "next friday" into "next" -- **Done is hidden until `d` asks for it.** Not a new opinion: `ls` already counts done in its summary and leaves it out of the listing. Done only grows, so a quarter of the width was going to the column least often read. The footer carries its count while it is hidden, which is the board's version of that summary line -- **Hiding is a change to what is drawn, never to what is read.** `reload` still scans the done directory and `digest` still watches it, so the footer count is right and revealing the column needs no rescan. Do not "optimise" that into a conditional scan -- `visible()` returns a prefix of `columns`, not a filter, which is what keeps `column` and `offsets` valid as indices into either. It is derived from where `DONE` actually sits rather than assuming the last slot, and `the_done_column_is_last` pins the assumption. A status inserted after done would otherwise hide two columns in silence -- Hiding the column under the selection moves the selection to the last drawn column and **closes an open detail view**. The alternative, refreshing the modal onto whichever ticket the selection landed on, swaps what someone is reading without saying so, which is how a person acts on the wrong ticket. Showing done again is a no-op for the selection, since a column is appended rather than inserted +- **The terminal columns are hidden until `d` asks for them, one step at a time.** Not a new opinion: `ls` already counts both in its summary and leaves them out of the listing. Done only grows, so a quarter of the width was going to the column least often read, and discarded arriving made it two. So `d` rotates three states — hide both, show done, show both, and back around — through the `Visibility` enum on `Board`, discarded last in the rotation because it is the least likely thing to be looking for. The footer names what the *next* press does and carries the count of the column still hidden, which is the board's version of that summary line. Hiding is a prefix of the columns: done and discarded are the last two in what the board draws, so revealing either appends it and the columns before keep their indices +- **Hiding is a change to what is drawn, never to what is read.** `reload` still scans the done and discarded directories and `digest` still watches them, so the footer counts are right and revealing either column needs no rescan. Do not "optimise" that into a conditional scan +- `visible()` returns a prefix of `columns`, not a filter, which is what keeps `column` and `offsets` valid as indices into either. It is derived from where `DONE` and `DISCARDED` actually sit rather than assuming positions, and `the_terminal_columns_are_last_in_the_order_drawn` pins the assumption. A status inserted after discarded would otherwise hide two columns in silence +- Hiding the column under the selection moves the selection to the last drawn column and **closes an open detail view**. The alternative, refreshing the modal onto whichever ticket the selection landed on, swaps what someone is reading without saying so, which is how a person acts on the wrong ticket. Showing another column is a no-op for the selection, since a column is appended rather than inserted - The choice is not remembered between runs. worklane has no config file and one flag is not a reason to start one; if it should persist, that is its own ticket - **Assert a column heading against the top border row, not the whole screen.** The footer names done too, so `screen.contains("done (0)")` passes on the footer whether the column is drawn or not. Three tests went vacuous that way the moment done was hidden; `headings()` and `footer()` exist so the next one does not. `headings()` locates the row through `board_area()` rather than taking row zero, since the tab row sits above it when more than one board is monitored @@ -372,7 +372,7 @@ and this file is for what someone changing worklane's own code needs. - `worklane tui ...` takes any number of paths, each resolved through `find_worklane_dir` the way the working directory is: the first `.worklane` at or above it. No path is the working directory, so a bare `worklane` and `worklane tui` are unchanged - The failure **names the path** that had no board, since with several arguments "No .worklane directory found" does not say which one was wrong. Only when a path was given: a bare `worklane` has no path to name and keeps the message every other command gives, which is what its integration test asserts - Two paths inside one project resolve to the same `.worklane` and are monitored once. `projects()` dedupes on the resolved directory, not on the argument -- **`Tab` owns the selection**, `column`, `card` and `offsets`, not `Board`. Sharing them across projects would point the selection at whatever unrelated ticket sat at the same place in the tab you switched to. `Board::current()` is the tab in view, and `show_done` stays on the board because it is a preference about the flow rather than about a project +- **`Tab` owns the selection**, `column`, `card` and `offsets`, not `Board`. Sharing them across projects would point the selection at whatever unrelated ticket sat at the same place in the tab you switched to. `Board::current()` is the tab in view, and `visibility` stays on the board because it is a preference about the flow rather than about a project - The tabs are fixed for the run: a project cannot be added or dropped without restarting, so `Board::new` builds the tab list once and `reload` only refills each tab's columns. `reload` clamps **every** tab, and `select_tab` clamps again on arrival, because done may have been hidden while another tab was in view - The merge tab goes **first** and is where the view opens: it is the reason to monitor several boards at once. It is materialised in `reload`, from the cards already read, rather than computed per draw — the same reason the criteria count is filled in `collect_ticket_items` - The merge is **sorted**, through `by_priority_then_title` in `util.rs`, not concatenated. An overview whose order depended on the order of the arguments would bury one project's p1 under another's p5. It keeps priority then title where every other column takes `by_status_order`: the merge spans statuses, so no single entry stamp governs it diff --git a/Cargo.lock b/Cargo.lock index 4e273e5..143a5dd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1503,7 +1503,7 @@ dependencies = [ [[package]] name = "worklane" -version = "0.31.0" +version = "0.31.1" dependencies = [ "anyhow", "assert_cmd", diff --git a/Cargo.toml b/Cargo.toml index f6a7a24..4ccdd95 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "worklane" -version = "0.31.0" +version = "0.31.1" edition = "2024" [dependencies] diff --git a/README.md b/README.md index 9fa3a9c..4608c44 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Worklane is a local Kanban flow for agentic software development. ## Commands | Command | Description | |---------|-------------| -| `worklane` or `worklane tui [path...]` | Opens the board: four status columns, redrawn when the tree changes. Read only. Opens on backlog, committed and reviewing; `d` shows or hides done, whose count stays in the footer either way. Discarded tickets are not drawn yet, `worklane ls discarded` is where they are read. Arrows or `hjkl` to move, `enter` for detail, `pgup`/`pgdn` to scroll an open ticket or the campaign frame, whichever the selection is on, with a page indicator on its border while there is more of it than fits, `/` to jump to the first ticket whose id or title matches, `y` to copy the selected ticket's short id to the clipboard, `c` to pick a campaign and filter the columns to its members, `q` to close whatever is open and then to quit. A card carries its campaign beside its tags, marked `~` and bold, and a comment count in its bottom right corner, the number then `❞` in cyan, before the criteria count and absent entirely when nobody has commented; while one is selected a frame above the columns names it, shows three rows of its description and says how far it has got, and `q` on its border gives the whole board back; up from the top card of a column moves the selection to that frame, where the scroll keys page through the description, `enter` gives it half the board and takes the rows back again, and down returns to the column it came from, leaving the frame at whatever height it was. Each path opens the first `.worklane` at or above it, the working directory by default. Several paths are monitored together, as a tab per project plus an `all` tab that merges them, with `tab` and `shift+tab` between them | +| `worklane` or `worklane tui [path...]` | Opens the board: one column per status, redrawn when the tree changes. Read only. Opens with done and discarded hidden, their counts in the footer; `d` rotates hide both, show done, show both, and back around. Arrows or `hjkl` to move, `enter` for detail, `pgup`/`pgdn` to scroll an open ticket or the campaign frame, whichever the selection is on, with a page indicator on its border while there is more of it than fits, `/` to jump to the first ticket whose id or title matches, `y` to copy the selected ticket's short id to the clipboard, `c` to pick a campaign and filter the columns to its members, `q` to close whatever is open and then to quit. A card carries its campaign beside its tags, marked `~` and bold, and a comment count in its bottom right corner, the number then `❞` in cyan, before the criteria count and absent entirely when nobody has commented; while one is selected a frame above the columns names it, shows three rows of its description and says how far it has got, and `q` on its border gives the whole board back; up from the top card of a column moves the selection to that frame, where the scroll keys page through the description, `enter` gives it half the board and takes the rows back again, and down returns to the column it came from, leaving the frame at whatever height it was. Each path opens the first `.worklane` at or above it, the working directory by default. Several paths are monitored together, as a tab per project plus an `all` tab that merges them, with `tab` and `shift+tab` between them | | `worklane init` | Creates `.worklane/` with backlog, committed, reviewing, done, discarded directories | | `worklane add` | Creates a ticket in backlog with `--title`, `--description`, `--acceptance`, `--plan`, `--tags`, `--due`, `--owner`, `--priority` flags. `--due` takes `YYYY-MM-DD` and refuses anything else at parse time | | `worklane ls [status]` | Lists tickets, sorted by priority then title. Optional positional status, and `--priority <1-5>`, `--tag ` and `--campaign `, which compose in any combination. `--tag` matches a whole value of the comma-separated Tags field, case sensitively, so `--tag bug` does not list a ticket tagged `bugfix` or one tagged `Bug`. `--ids` prints one ticket per line as its short id, a tab and its title, unstyled, done included, for a script or a completion | diff --git a/src/main.rs b/src/main.rs index f4a3ed8..42d11d5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 diff --git a/src/tui.rs b/src/tui.rs index 86abd21..291967f 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -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, /// What the last action said, until the next keypress takes it away. pub notice: Option, - /// 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, 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, color: Option) -> 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, 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 = 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 = 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 = collect_ticket_items(worklane_dir.join(status.as_str())) .unwrap_or_default() .into_iter() @@ -2165,7 +2211,11 @@ fn retain_tag(mut columns: Vec, tag: Option<&str>) -> Vec { /// 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, campaign: Option<&str>) -> Vec { @@ -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], projects: &[Project]) -> Vec { - 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 diff --git a/src/util.rs b/src/util.rs index fd162d3..49e0300 100644 --- a/src/util.rs +++ b/src/util.rs @@ -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