Compare commits

..
2 Commits
Author SHA1 Message Date
Ansho ReiandClaude Opus 5 4502de7ee3 (e7612de) Close the detail overlay on q instead of quitting, and bump to 0.13.5
q set should_quit outright, so a reader who pressed it to put a ticket away
lost the whole board instead. That is not what q means anywhere else that
lays a document over a list, and esc two arms below already did the right
thing.

The rule is Board::dismiss: close what is open, quit when there is nothing
left to close. On Board rather than in the match arm because the dispatch in
main.rs is not reachable from a test, so a rule written there is a rule
nothing can check. q and esc now share one arm, since two arms carrying one
rule is how a later edit changes it for one key and not the other.

The footer is the other half. Its last slot answers the same question in
both states, how to get out, and with a ticket open the honest answer is
ctrl-c: it is the only key left that quits in one press. Going on saying
q quit there would be 1b78a24 in the other direction, a footer describing a
key by what it used to do. The close entry names both keys as enter/q close
rather than repeating close twice.

Criteria 3 and 7 live in a dispatch no test can reach, so
the_dispatch_gives_q_and_esc_one_arm_and_leaves_ctrl_c_quitting scans
main.rs for them, over whitespace-collapsed source so rustfmt cannot fail
it, the way util.rs is already scanned for colour_text callers.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-22 13:13:58 +02:00
Ansho ReiandClaude Opus 5 a16169ce8c (b8ce18c) Show a blocked marker on the tui card, and bump to 0.13.4
A ticket held up by an open blocker looked exactly like one that is ready,
and the board is where the next thing to pick up is chosen.

The mark is × in brightred, after the short id. Not a fourth Geometric
Shapes glyph: those are the priority meter's, two cells away, and another
circle there reads as part of that ramp. × is Latin-1, like the middle dot
the unset priority draws, so it renders wherever the meter does.

After the id rather than before it, because ahead of it the mark would push
every id in the column out of line whenever one card was blocked. 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.

No scan of the board per tick was needed after all. collect_ticket_items
also reads the ticket's own uuid and the targets of its blocked by lines,
off the file it is already holding, and mark_blocked walks the four columns
once for a uuid-to-status map and once to answer every card. The flag is on
Card rather than TicketItem: the answer is about two tickets at once, so no
card can reach it alone, and it is settled at reload the way project is.

The merge carries each card's flag from the board it came from. relate
resolves its target inside one .worklane, so a blocker in another project is
not a relation anything can record, and recomputing over the merged columns
would let one project's uuid match another project's ticket.

project_label now takes the width the row has actually spent, measured off
the spans, instead of adding up the widths those spans are supposed to have.
The hand-written sum left out the space after the priority mark, so a cut
label was handed one cell more than the column had.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-22 13:02:13 +02:00
6 changed files with 507 additions and 33 deletions
+11 -2
View File
@@ -98,7 +98,7 @@ and this file is for what someone changing worklane's own code needs.
- `ensure_section` inserts against `SECTION_ORDER`, before the first following section that is actually in the file, and adds no blank line that was not already there. A handwritten `## Notes` between the plan and the metadata therefore keeps its place, and Metadata is in that list as an anchor rather than as something anything appends to
- **The blocker check runs on every move**, after the already-in-that-status return and behind `force`. An open blocker is a reason not to start and a reason not to finish, and one rule is easier to hold than a table of which transitions care. A move to the status the ticket is already in is not a move, so it is not refused. `-f` now bypasses three rules, which is the right home for it: each one is a deliberate override of something the board would otherwise keep true
- **A blocker that is not on the board warns and allows the move.** Refusing would wedge the ticket with no way out but `-f`, and a uuid nothing carries is a bookkeeping fault rather than a dependency. The refusal names **every** open blocker, since clearing the one that happened to be printed would leave the ticket blocked
- Left out on purpose: removing a relation, which 4179958 assigns to 74904dc, and a blocked marker on the TUI card, which is its own ticket. Nothing on a card is worth a scan of the board per tick until the card is designed for it
- Left out on purpose: removing a relation, which 4179958 assigns to 74904dc. The blocked marker on the card landed in b8ce18c, and it cost no scan of the board: the blockers ride along on the read that already builds the cards. See The Board View
### Campaigns
@@ -113,7 +113,7 @@ and this file is for what someone changing worklane's own code needs.
- **`Resolved` carries what `content_trim` cannot render from the file.** The relations block and the campaign cell both come from elsewhere on the board. A struct rather than two more parameters, so the next such field is one entry here instead of an edit at every call site
- `campaign show` lists **done** members, unlike `ls`, which leaves the done column out of its listing. What is finished against what is left is the whole question a campaign asks, so hiding half the answer is not an option. `ls --campaign` is the other way round: it is the ordinary board filtered, and keeps every rule `ls` already has
- `campaign ls` scans the status directories **once per campaign** to count members. That is a scan per row rather than one walk reused, and it is deliberate: the map-from-uuid version is worth writing when a board has enough campaigns to notice
- **The TUI gets neither a campaign tab nor a card marker**, for now. The detail view resolves the field because it renders the body, and that is all. A marker on a card would want a campaigns read per reload and the four corners are already spent; same reasoning as the blocked marker, which is also its own ticket
- **The TUI gets neither a campaign tab nor a card marker**, for now. The detail view resolves the field because it renders the body, and that is all. A marker on a card would want a campaigns read per reload, which is more than the blocked mark cost: that one reads the ticket's own Relations section on the pass that already builds the card, and a campaign title is in another directory
- `campaign_body()` builds the file from `DESCRIPTION` and `METADATA_HEADING` rather than its own string literals, so the two file formats cannot drift apart on the spelling of a heading. A campaign has no acceptance criteria (its definition of done is derived), no implementation plan and no Status
- The campaigns directory is created by `init` and **on demand** by `campaign add`, since every board made before campaigns existed has none and a `worklane init` over a live board to get one would be a strange thing to have to do
@@ -135,6 +135,9 @@ and this file is for what someone changing worklane's own code needs.
- The draw aligns the focused column again on its own geometry, so a resize between keypress and frame cannot hide the selection, and caps every column against blank space past its last card. The stored value may go stale after a tick shrinks the column; that is fine, because what is drawn is corrected immediately and the next navigation writes the correction back
- Entering another column follows the selection 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 — the opposite of the detail view's reset-on-selection-move, where each ticket genuinely starts at its own top. The index is shared and clamps permanently when a shorter column pulls it down, so a column you return to follows the selection to where it now sits rather than holding your old place
- **The footer names only keys that work.** It read `↑↓ scroll` when nothing scrolled at all, which sends the reader looking for their own mistake. A UI that misdescribes itself is worse than one that is merely incomplete
- **`q` and `esc` are one key: close what is open, quit when there is nothing left to close.** `q` used to set `should_quit` outright, so a reader who pressed it to put a ticket away lost the board instead, which is not what `q` does anywhere else that lays a document over a list. One match arm in `main.rs`, not two: two arms carrying one rule is how a later edit changes it for one key and not the other
- **The rule is `Board::dismiss`, not the match arm.** The dispatch in `main.rs` is not reachable from a test, so anything decided there is undecidable by the suite. The arm is the line that names the keys and nothing else. `the_dispatch_gives_q_and_esc_one_arm_and_leaves_ctrl_c_quitting` scans `main.rs` for what the arm cannot say for itself, over whitespace-collapsed source so rustfmt cannot fail it
- **The footer's last slot always answers how to get out**, and with a ticket open the honest answer is `ctrl-c`, the only key left that quits in one press. Going on saying `q quit` there would be 1b78a24 in the other direction: a footer describing a key by what it used to do
- **The overlay names its ticket on the border, not at the head of the paragraph.** `Board::detail` is a `Detail` carrying the title, the id and the text, because the name has to travel beside the body rather than inside it: `content_trim` drops the `# ` heading on purpose, since `cmd_show` prints it, and anything in the paragraph scrolls away
- `detail_title` cuts the string itself instead of leaving it to ratatui, which truncates an overlong block title at whatever cell it reaches and would take the id with it. Cut against the inner width, so the id survives whole and the name ends in an ellipsis. The id goes first because that is how every other view addresses a ticket
- The detail view renders with colour off. ratatui draws styled spans, so an escape sequence in a paragraph would be printed as literal bytes. `content_trim` and `format_comments_with` take the colour decision for that reason
@@ -146,6 +149,12 @@ and this file is for what someone changing worklane's own code needs.
- The criteria count is a field on `TicketItem`, filled in `collect_ticket_items` where the file is already being read, and counted through `criteria()` so a checkbox in a description is not counted here or numbered by `show`. Do not count per card: that re-reads every ticket body on every draw instead of on the tick that changed something. `None` rather than `[0/0]` for a ticket with no criteria
- **The tags go under the title, dimmed, each prefixed with `#`.** The field was invisible on the board: nothing said a ticket was tagged `bug` without opening it. The marker is what stops the row reading as a third line of the title, since a tag is an ordinary word and the title sits directly above it. The row is dropped whole when the column will not hold it, the rule a corner follows, and an untagged ticket spends no row at all, the way a short title spends no second one
- `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 `×` after its id, in brightred.** 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
- **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
Generated
+1 -1
View File
@@ -1494,7 +1494,7 @@ dependencies = [
[[package]]
name = "worklane"
version = "0.13.3"
version = "0.13.5"
dependencies = [
"anyhow",
"assert_cmd",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "worklane"
version = "0.13.3"
version = "0.13.5"
edition = "2024"
[dependencies]
+8 -7
View File
@@ -164,16 +164,17 @@ fn run_tui(paths: &[std::path::PathBuf], start: &std::path::Path) -> Result<()>
}
match key.code {
KeyCode::Char('q') => board.should_quit = true,
// One arm, because the two keys mean one thing: close what is open, and
// quit when there is nothing left to close. Two arms carrying one rule
// is how a later edit changes it for one key and not the other, which is
// what `q` quitting out from under an open ticket already was. The rule
// itself is `Board::dismiss`, where a test can reach it.
KeyCode::Esc | KeyCode::Char('q') => board.dismiss(),
// The only key that leaves the board from an open ticket, which is why
// the footer names it there.
KeyCode::Char('c') if key.modifiers.contains(KeyModifiers::CONTROL) => {
board.should_quit = true
}
// Esc closes the detail view, and only quits when there is nothing
// left to dismiss.
KeyCode::Esc => match board.detail {
Some(_) => board.toggle_detail(),
None => board.should_quit = true,
},
KeyCode::Enter | KeyCode::Char(' ') => board.toggle_detail(),
KeyCode::Left | KeyCode::Char('h') => board.select_column(-1, screen),
KeyCode::Right | KeyCode::Char('l') => board.select_column(1, screen),
+417 -22
View File
@@ -7,6 +7,7 @@
//! **Read only.** Moving a card by keypress is a follow-up. Everything here observes.
use std::collections::hash_map::DefaultHasher;
use std::collections::HashMap;
use std::hash::{Hash, Hasher};
use std::path::{Path, PathBuf};
use std::time::{Duration, SystemTime};
@@ -100,6 +101,14 @@ fn project_name(dir: &Path) -> String {
pub struct Card {
pub ticket: TicketItem,
pub project: Option<String>,
/// Whether a ticket this one is `blocked by` is on the board and not done.
///
/// Decided at reload like `project`, and for a stronger reason: the answer lives on
/// two tickets at once, so no card can reach it alone and asking per draw would mean
/// reading the tree per frame. Computed on the board the ticket came from and
/// carried into the merge unchanged — `relate` resolves its target against one
/// `.worklane`, so there is no such thing as a blocker in another project.
pub blocked: bool,
}
/// One status and the cards in it.
@@ -462,6 +471,26 @@ impl Board {
};
}
/// Put away what is open, and quit when there is nothing left to put away.
///
/// What `esc` has always done, and now what `q` does too. `q` used to set
/// `should_quit` outright, so a reader who pressed it to close a ticket lost the
/// whole board instead, which is not what `q` means anywhere else that lays a
/// document over a list.
///
/// Here rather than in the match arm in `main.rs`: that dispatch is not reachable
/// from a test, so a rule written into it is a rule nothing can check. The arm is
/// left as the one line that names the keys.
///
/// `ctrl-c` is therefore the only key that leaves the board while a ticket is open,
/// and the footer says so rather than leaving the reader to find out.
pub fn dismiss(&mut self) {
match self.detail {
Some(_) => self.toggle_detail(),
None => self.should_quit = true,
}
}
/// Scroll the open detail view by whole screenfuls, one line kept for overlap.
///
/// Up and down move the selection, so the scroll is on PageUp and PageDown. That is
@@ -534,7 +563,7 @@ fn detail_of(card: &Card) -> Detail {
/// The four columns of one board.
fn columns_of(worklane_dir: &Path) -> Vec<Column> {
status_dirs()
let mut columns: Vec<Column> = status_dirs()
.into_iter()
.map(|status| {
// An absent or unreadable directory is an empty column, not a missing one:
@@ -545,11 +574,47 @@ fn columns_of(worklane_dir: &Path) -> Vec<Column> {
.map(|ticket| Card {
ticket,
project: None,
blocked: false,
})
.collect();
Column { status, cards }
})
.collect()
.collect();
mark_blocked(&mut columns);
columns
}
/// Set `blocked` on every card whose ticket waits on one that is not done.
///
/// Two walks of what `columns_of` has just read, not a lookup per relation: the status
/// of a blocker is on another card, so the pass builds the uuid to status map once and
/// then answers every card from it. Nothing is read from disk here, which is the point
/// — the blockers came off the same read that built the cards.
///
/// A blocker the board does not hold marks nothing, the answer `mv` already gives it: a
/// uuid nothing carries is a bookkeeping fault rather than a dependency. A ticket with
/// no ID field is left out of the map entirely, or every ticket missing one would block
/// every other ticket missing one, which is the guard `RelationIndex::inbound` makes.
fn mark_blocked(columns: &mut [Column]) {
let status_of: HashMap<String, &'static str> = columns
.iter()
.flat_map(|column| {
column
.cards
.iter()
.map(|card| (card.ticket.uuid.clone(), column.status))
})
.filter(|(uuid, _)| !uuid.trim().is_empty() && !is_unknown_value(uuid))
.collect();
for column in columns.iter_mut() {
for card in column.cards.iter_mut() {
card.blocked = card.ticket.blockers.iter().any(|blocker| {
matches!(status_of.get(blocker.as_str()), Some(status) if *status != DONE)
});
}
}
}
/// Every board's columns as one set of four, each card labelled with the project it
@@ -571,6 +636,10 @@ fn merge(per_project: &[Vec<Column>], projects: &[Project]) -> Vec<Column> {
cards.extend(column.cards.iter().map(|card| Card {
ticket: card.ticket.clone(),
project: Some(project.name.clone()),
// Already answered on the board the card came from. Recomputing it
// over the merged columns would let one project's uuid resolve
// against another's ticket, which is a relation nothing can record.
blocked: card.blocked,
}));
}
@@ -824,6 +893,15 @@ fn aligned_offset(offset: u16, start: u16, end: u16, inner: u16, total: u16) ->
offset.min(total.saturating_sub(inner))
}
/// The mark a card carries while it waits on a ticket that is not done.
///
/// Not a fourth circle. The Geometric Shapes glyphs belong to the priority meter, and
/// another one two cells away from it would read as part of that ramp rather than as a
/// different fact. A multiplication sign is Latin-1, like the middle dot the unset
/// priority draws, so it renders wherever the meter already does. That is the same
/// safe-glyph rule that took the quadrant circles out of the ramp.
const BLOCKED_MARK: &str = "\u{d7}";
/// One card as four corners with the title between them:
///
/// ```text
@@ -845,6 +923,10 @@ fn aligned_offset(offset: u16, start: u16, end: u16, inner: u16, total: u16) ->
///
/// The tags sit between the title and the bottom corners, on a row a ticket without
/// them does not spend. See [`tags_line`].
///
/// A held-up ticket carries [`BLOCKED_MARK`] after its id, ahead of the project and the
/// due date, both of which 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.
fn card_lines(card: &Card, selected: bool, width: u16) -> Vec<Line<'static>> {
let ticket = &card.ticket;
let (glyph, colour) = priority_mark(ticket.priority);
@@ -865,10 +947,25 @@ fn card_lines(card: &Card, selected: bool, width: u16) -> Vec<Line<'static>> {
Style::default().fg(Color::Red.into()).add_modifier(emphasis),
),
];
// After the id, not before it: inserted ahead of the id the mark would push it out
// of line, and a column of ids that do not start at the same cell is harder to read
// than one card's worth of state is worth. Dropped whole when the row cannot hold
// the identity and the mark together, the rule a corner follows, rather than
// wrapping or cutting it.
if card.blocked && spans_width(&left) + 1 + BLOCKED_MARK.chars().count() <= width as usize {
left.push(Span::raw(" "));
left.push(Span::styled(
BLOCKED_MARK.to_string(),
Style::default()
.fg(Color::BrightRed.into())
.add_modifier(emphasis),
));
}
let label = card
.project
.as_deref()
.and_then(|name| project_label(name, width));
.and_then(|name| project_label(name, width, spans_width(&left)));
if let Some(label) = label {
left.push(Span::raw(" "));
// Grey like the owner and the criteria count: the shape carries which project
@@ -957,21 +1054,24 @@ fn tags_line(tags: &[String], width: u16) -> Option<Line<'static>> {
Some(Line::from(spans))
}
/// The project name as it fits beside the mark and the id.
/// The project name as it fits beside whatever the row already carries.
///
/// The mark and the id are the ticket's identity and never give way, so the label takes
/// what the row has left and ends in an ellipsis where it was cut. It is measured before
/// the due date, which is what gives the project the narrow column: on the All tab the
/// project matters more than the date, and `corner_line` drops the date when what is
/// left will not hold it.
/// The mark, the id and the blocked mark are the ticket's identity and its state, and
/// neither gives way, so the label takes what the row has left and ends in an ellipsis
/// where it was cut. It is measured before the due date, which is what gives the project
/// the narrow column: on the All tab the project matters more than the date, and
/// `corner_line` drops the date when what is left will not hold it.
///
/// `used` is measured off the spans already built rather than added up from the widths
/// they are supposed to have. The hand-written version left out the space after the
/// priority mark, so the label was handed one cell more than the row had and a narrow
/// column drew a card one character wider than its column.
///
/// Under three characters there is nothing left to say, and a single letter and a dot
/// would only crowd the corner, so the label goes instead.
fn project_label(name: &str, width: u16) -> Option<String> {
// The mark and the space after it, the id in its brackets, and the space before the
// label.
let used = 2 + SHORT_ID_WIDTH + 2 + 1;
let room = (width as usize).checked_sub(used)?;
fn project_label(name: &str, width: u16, used: usize) -> Option<String> {
// The space between the label and what precedes it.
let room = (width as usize).checked_sub(used + 1)?;
if room < 3 {
return None;
}
@@ -1010,7 +1110,7 @@ fn corner_line(
width: u16,
) -> Line<'static> {
let mut spans = left;
let used: usize = spans.iter().map(|span| span.content.chars().count()).sum();
let used = spans_width(&spans);
let Some(right) = right else {
return Line::from(spans);
@@ -1027,6 +1127,11 @@ fn corner_line(
Line::from(spans)
}
/// The cells a run of spans takes, counted in characters rather than bytes.
fn spans_width(spans: &[Span<'static>]) -> usize {
spans.iter().map(|span| span.content.chars().count()).sum()
}
/// The title over one row or two, wrapped on spaces, cut with an ellipsis if even two
/// are not enough.
///
@@ -1114,9 +1219,13 @@ fn draw_footer(frame: &mut Frame, board: &Board, area: Rect) {
false => "",
};
// The last slot answers the same question in both states: how to get out of here.
// With a ticket open `q` closes it, so the honest answer there is `ctrl-c`, which is
// the only key left that quits in one press. Naming `q quit` over an open overlay
// would be the fault 1b78a24 was, a footer describing a key by what it used to do.
let keys = match board.detail {
Some(_) => {
format!(" {tabs}←→↑↓ select pgup/pgdn scroll enter close {done} q quit ")
format!(" {tabs}←→↑↓ select pgup/pgdn scroll enter/q close {done} ctrl-c quit ")
}
None => format!(" {tabs}←→ column ↑↓ card enter detail {done} q quit "),
};
@@ -2482,6 +2591,73 @@ mod tests {
assert_eq!(board.offset, offset);
}
// ------------------------------------------------------------- close or quit --
/// A reader pressing `q` to put a ticket away lost the whole board instead.
#[test]
fn dismiss_closes_an_open_overlay_and_leaves_the_board_up() {
let dir = board_dir();
write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "First one", "");
let mut board = one_board(&dir);
board.toggle_detail();
assert!(board.detail.is_some(), "nothing was open to dismiss");
board.dismiss();
assert!(board.detail.is_none(), "the overlay stayed open");
assert!(!board.should_quit, "closing a ticket took the board with it");
// Still on the ticket it was opened from, so the next `enter` reopens it.
assert_eq!(selected_title(&board).as_deref(), Some("First one"));
}
/// With nothing over the board there is nothing to put away, so the key means what
/// it has always meant.
#[test]
fn dismiss_quits_when_there_is_nothing_left_to_dismiss() {
let dir = board_dir();
write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "First one", "");
let mut board = one_board(&dir);
board.dismiss();
assert!(board.should_quit, "the board stayed up with nothing to close");
}
/// The rule is `Board::dismiss`, which the two tests above reach. What is left to
/// guard is the dispatch that cannot be reached: that both keys arrive there from
/// one arm, and that `ctrl-c` still quits outright, since after this it is the only
/// key that leaves the board while a ticket is open.
///
/// Scanned the way `nothing_the_body_renders_asks_the_terminal_for_the_colour_decision`
/// scans, and over whitespace-collapsed source so rustfmt cannot fail it.
#[test]
fn the_dispatch_gives_q_and_esc_one_arm_and_leaves_ctrl_c_quitting() {
let source = include_str!("main.rs")
.split_whitespace()
.collect::<Vec<_>>()
.join(" ");
assert!(
source.contains("KeyCode::Esc | KeyCode::Char('q') => board.dismiss(),"),
"`q` and `esc` mean one thing and have to reach `Board::dismiss` from one \
arm. Two arms carrying one rule is how a later edit changes it for one key \
and not the other, which is what this ticket already was."
);
let at = source
.find("KeyCode::Char('c') if key.modifiers.contains(KeyModifiers::CONTROL)")
.expect("no ctrl-c arm in the dispatch");
// What the arm does, not what is anywhere near it: the arms after this one call
// the board and would answer a whole-file search.
let arm = &source[at..(at + 120).min(source.len())];
assert!(
arm.contains("=> { board.should_quit = true }"),
"`ctrl-c` has to keep quitting outright: with `q` closing an open ticket it \
is the only key that leaves the board in one press, and the footer says so. \
Found instead: {arm}"
);
}
/// The footer is what sent the reporter looking for their own mistake, so it has to
/// name the keys that exist and only those.
#[test]
@@ -2502,11 +2678,32 @@ mod tests {
assert!(closed.contains("enter detail"), "{closed}");
assert!(!closed.contains("scroll"), "a scroll offered with nothing open:\n{closed}");
assert!(closed.contains("q quit"), "nothing says how to leave:\n{closed}");
board.toggle_detail();
let open = render(&board, SCREEN.width, SCREEN.height).join("\n");
assert!(open.contains("pgup/pgdn scroll"), "{open}");
assert!(open.contains("select"), "{open}");
assert!(open.contains("enter close"), "{open}");
assert!(open.contains("enter/q close"), "{open}");
}
/// The other half of giving `q` a second meaning. A footer that goes on saying
/// `q quit` over an open ticket describes the key by what it used to do, which is
/// the fault 1b78a24 was in the other direction.
#[test]
fn the_footer_names_q_as_the_close_key_while_a_ticket_is_open() {
let dir = board_dir();
write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "First one", "");
let mut board = one_board(&dir);
board.toggle_detail();
let row = footer(&board, 120, 20);
assert!(row.contains("enter/q close"), "q is not named as the close key:\n{row}");
assert!(!row.contains("q quit"), "q still offered as the quit key:\n{row}");
// And the last slot still answers how to get out, which from here is the one
// key that does it in a single press.
assert!(row.contains("ctrl-c quit"), "nothing says what quits from here:\n{row}");
}
// ------------------------------------------------------- several boards at once --
@@ -2676,13 +2873,211 @@ mod tests {
/// The label takes what the row has left, never the mark or the id, and says it was
/// cut. A column too narrow for even that keeps the identity alone.
///
/// The mark, a space and the id in its brackets, which is what `card_lines` has
/// built by the time it asks.
#[test]
fn the_project_label_gives_way_to_the_mark_and_the_id() {
assert_eq!(project_label("alpha", 38).as_deref(), Some("alpha"));
// Room for four characters of a longer name, the last of them the ellipsis.
assert_eq!(project_label("factry-core", 16).as_deref(), Some("fac…"));
assert_eq!(project_label("factry-core", 13), None);
assert_eq!(project_label("alpha", 4), None);
const IDENTITY: usize = 2 + 1 + SHORT_ID_WIDTH + 2;
assert_eq!(project_label("alpha", 38, IDENTITY).as_deref(), Some("alpha"));
// Room for three characters of a longer name, the last of them the ellipsis.
assert_eq!(
project_label("factry-core", 16, IDENTITY).as_deref(),
Some("fa…")
);
assert_eq!(project_label("factry-core", 13, IDENTITY), None);
assert_eq!(project_label("alpha", 4, IDENTITY), None);
}
/// The label plus everything before it has to fit the column it is drawn in. The
/// arithmetic this replaced left out the space after the priority mark, so the row
/// came out one cell wider than the column at every width the label was cut at.
#[test]
fn the_project_label_leaves_the_row_inside_the_column() {
const IDENTITY: usize = 2 + 1 + SHORT_ID_WIDTH + 2;
for width in 13u16..40 {
let Some(label) = project_label("factry-core", width, IDENTITY) else {
continue;
};
let row = IDENTITY + 1 + label.chars().count();
assert!(row <= width as usize, "row {row} over column {width}");
}
}
// ------------------------------------------------------- the blocked mark --
const BLOCKER: &str = "aaaaaaaa-0000-4000-8000-000000000000";
const WAITER: &str = "bbbbbbbb-0000-4000-8000-000000000000";
const ELSEWHERE: &str = "cccccccc-0000-4000-8000-000000000000";
/// A Relations section as `relate` writes it, for the `extra` a fixture appends.
///
/// It lands after the Metadata rather than in `SECTION_ORDER`'s place for it, which
/// `section_body` reads all the same: these tests are about what the section says,
/// not where the writer puts it.
fn blocked_by(uuid: &str) -> String {
format!("\n## Relations\n\n- blocked by {uuid}\n")
}
/// Whether the board decided the named ticket is held up.
///
/// Over every column, done included: the flag is filled whether or not the column
/// is drawn, the same way `reload` scans done while `d` hides it.
fn marked_blocked(board: &Board, title: &str) -> bool {
board
.current()
.columns
.iter()
.flat_map(|column| &column.cards)
.find(|card| card.ticket.title == title)
.unwrap_or_else(|| panic!("no card titled '{title}'"))
.blocked
}
/// The rows of the named ticket's card, laid out in a column of `inner` characters.
fn card_rows(board: &Board, title: &str, inner: u16) -> Vec<String> {
let card = board
.current()
.columns
.iter()
.flat_map(|column| &column.cards)
.find(|card| card.ticket.title == title)
.unwrap_or_else(|| panic!("no card titled '{title}'"));
card_lines(card, false, inner)
.iter()
.map(|line| line.spans.iter().map(|span| span.content.as_ref()).collect())
.collect()
}
/// The one thing on a card that says do not start this. Without it a ticket whose
/// blocker is still open reads exactly like one that is ready.
#[test]
fn a_card_waiting_on_an_open_ticket_carries_the_blocked_mark() {
let dir = board_dir();
write_ticket(&dir, "committed", BLOCKER, "The blocker", "");
write_ticket(&dir, "backlog", WAITER, "The waiter", &blocked_by(BLOCKER));
let board = one_board(&dir);
assert!(marked_blocked(&board, "The waiter"));
// The far end of the relation is not held up by holding somebody else up.
assert!(!marked_blocked(&board, "The blocker"));
let screen = render(&board, 120, 20).join("\n");
assert!(
screen.contains(&format!("({}) {}", short_id(WAITER), BLOCKED_MARK)),
"no mark after the id:\n{screen}"
);
}
/// The mark is the state of the dependency, not a note that one was ever recorded.
#[test]
fn a_card_whose_blockers_are_all_done_carries_none() {
let dir = board_dir();
write_ticket(&dir, "done", BLOCKER, "The blocker", "");
write_ticket(&dir, "backlog", WAITER, "The waiter", &blocked_by(BLOCKER));
let board = one_board(&dir);
assert!(!marked_blocked(&board, "The waiter"));
let screen = render(&board, 120, 20).join("\n");
assert!(
!screen.contains(BLOCKED_MARK),
"a cleared blocker still marked:\n{screen}"
);
}
/// One open blocker out of two is still a reason not to start, the rule `mv` applies
/// when it names every open blocker rather than the first.
#[test]
fn a_card_is_marked_while_any_one_of_its_blockers_is_open() {
let dir = board_dir();
write_ticket(&dir, "done", BLOCKER, "The blocker", "");
write_ticket(&dir, "reviewing", ELSEWHERE, "The other blocker", "");
write_ticket(
&dir,
"backlog",
WAITER,
"The waiter",
&format!("\n## Relations\n\n- blocked by {BLOCKER}\n- blocked by {ELSEWHERE}\n"),
);
assert!(marked_blocked(&one_board(&dir), "The waiter"));
}
/// The answer `mv` gives a dangling uuid: a bookkeeping fault, not a dependency.
#[test]
fn a_blocker_the_board_does_not_hold_marks_nothing() {
let dir = board_dir();
write_ticket(&dir, "backlog", WAITER, "The waiter", &blocked_by(ELSEWHERE));
assert!(!marked_blocked(&one_board(&dir), "The waiter"));
}
/// Nothing but `relate` writes the section, so a line that is not a relation means a
/// hand-edited file. `show` and `mv` are where that is reported; the board draws the
/// ticket unmarked, the exception `detail_of` already makes for the same reason.
#[test]
fn a_relations_section_that_cannot_be_parsed_leaves_the_board_drawable() {
let dir = board_dir();
write_ticket(
&dir,
"backlog",
WAITER,
"The waiter",
"\n## Relations\n\n- waits for the other one\n",
);
let board = one_board(&dir);
assert!(!marked_blocked(&board, "The waiter"));
let screen = render(&board, 120, 20).join("\n");
assert!(screen.contains("The waiter"), "the board lost the ticket:\n{screen}");
}
/// Dropped whole in a column that cannot hold the identity and the mark together,
/// the rule a corner follows. The id keeps its place either way: a column of ids
/// starting at different cells costs more than one card's state is worth.
#[test]
fn a_column_too_narrow_for_the_mark_drops_it() {
let dir = board_dir();
write_ticket(&dir, "committed", BLOCKER, "The blocker", "");
write_ticket(&dir, "backlog", WAITER, "The waiter", &blocked_by(BLOCKER));
let board = one_board(&dir);
// The mark, a space, the id in its brackets, and the space the mark needs.
let identity = (2 + 1 + SHORT_ID_WIDTH + 2) as u16;
let id = format!("({})", short_id(WAITER));
let wide = card_rows(&board, "The waiter", identity + 2);
assert!(wide[0].contains(BLOCKED_MARK), "no mark with room for it: {:?}", wide[0]);
let narrow = card_rows(&board, "The waiter", identity);
assert!(!narrow[0].contains(BLOCKED_MARK), "mark kept over the column: {:?}", narrow[0]);
assert!(narrow[0].contains(&id), "the identity gave way instead: {:?}", narrow[0]);
assert!(narrow[0].chars().count() <= identity as usize, "row over the column");
}
/// The merge resolves nothing of its own. A relation names a uuid `relate` looked up
/// in one `.worklane`, so a blocker in another project is not a thing that exists,
/// and the flag each card arrives with is the one its own board worked out.
#[test]
fn the_blocked_mark_follows_a_card_onto_the_merge() {
let (first, second) = (board_dir(), board_dir());
write_ticket(&first, "committed", BLOCKER, "The blocker", "");
write_ticket(&first, "backlog", WAITER, "The waiter", &blocked_by(BLOCKER));
write_ticket(&second, "backlog", ELSEWHERE, "Elsewhere", &blocked_by(BLOCKER));
// The merge tab is where the view opens.
let board = boards(&[("alpha", &first), ("beta", &second)]);
assert_eq!(board.current().name, ALL);
assert!(marked_blocked(&board, "The waiter"));
assert!(
!marked_blocked(&board, "Elsewhere"),
"a uuid on another board was read as a blocker"
);
}
/// A change in any monitored board has to redraw, not only one in the first.
+69
View File
@@ -1986,6 +1986,27 @@ pub struct TicketItem {
/// asking per card would re-read every ticket body on every draw rather than on the
/// tick that changed something.
pub tags: Vec<String>,
/// The full uuid from the ticket's own ID field, as a relation stores it.
///
/// `id` is the seven characters a listing prints; a relation names the whole uuid,
/// so pairing a stored blocker with the ticket it points at needs the whole thing.
/// Absent or unset reads as `_Not set_`, the way every other field does, and the
/// board guards for it rather than matching on it.
pub uuid: String,
/// The uuids of the tickets this one records a `blocked by` against, empty when it
/// records none.
///
/// Read here for the reason `criteria` is: the board marks every held-up card on
/// every tick, and asking per card would re-read every ticket body on every draw.
/// The uuids only, never the answer: whether a blocker is still open is a fact
/// about another ticket, so it belongs to whoever holds the whole board.
///
/// A Relations section that cannot be parsed reads as no blockers rather than as a
/// ticket that cannot be listed. `show` and `mv` still refuse it, which is where a
/// hand-edited file has to be reported; a board or a listing that stops on one
/// malformed ticket is the worse failure, and is the same exception `detail_of`
/// already makes.
pub blockers: Vec<String>,
/// The file this came from. The listing ignores it; the TUI opens it for the
/// detail view rather than resolving the ticket a second time.
pub path: std::path::PathBuf,
@@ -2121,6 +2142,13 @@ pub fn collect_ticket_items(status_path: impl AsRef<Path>) -> Result<Vec<TicketI
let filename = e.path().file_stem()?.to_string_lossy().to_string();
let created_at = parse_ticket_field(&content, "Created At");
let blockers = parse_relations(&content, &title)
.unwrap_or_default()
.into_iter()
.filter(|relation| relation.kind == RelationKind::BlockedBy)
.map(|relation| relation.target)
.collect();
// Through `criteria()`, so the card and the numbers `show` prints cannot
// disagree: a checkbox written into a description is not a criterion there
// and is not counted here.
@@ -2143,6 +2171,8 @@ pub fn collect_ticket_items(status_path: impl AsRef<Path>) -> Result<Vec<TicketI
criteria: progress,
campaign: parse_campaign(&content),
tags: parse_tags(&content),
uuid: parse_ticket_field(&content, "ID"),
blockers,
path: e.path(),
})
})
@@ -2555,6 +2585,45 @@ mod tests {
fs::remove_dir_all(&dir).unwrap();
}
/// The blockers come off the read that builds the item, so the board pays no second
/// pass for them, and only the `blocked by` kind is one: the other two record no
/// dependency and gate nothing.
///
/// A section that cannot be parsed reads as no blockers rather than as a ticket that
/// cannot be listed. `show` and `mv` are where a hand-edited file is reported; a
/// listing that stops on one malformed ticket is the worse failure.
#[test]
fn collect_ticket_items_reads_the_uuid_and_the_blockers_it_records() {
let dir = std::env::temp_dir().join(format!("worklane-blocked-{}", uuid::Uuid::new_v4()));
fs::create_dir_all(&dir).unwrap();
let uuid = |tail: &str| format!("11111111-0000-4000-8000-00000000000{tail}");
let write = |name: &str, relations: &str| {
fs::write(
dir.join(format!("{}.md", uuid(name))),
format!(
"# T{name}\n\n## Relations\n{relations}\n## Metadata\n\n- **ID**: {}\n",
uuid(name)
),
)
.unwrap();
};
write("1", &format!("\n- blocked by {}\n- relates to {}\n", uuid("2"), uuid("3")));
write("2", "\n- regression of 99999999-0000-4000-8000-000000000000\n");
write("3", "\n- waits for the other one\n");
let items = collect_ticket_items(&dir).unwrap();
let of = |title: &str| items.iter().find(|item| item.title == title).unwrap();
assert_eq!(of("T1").uuid, uuid("1"));
assert_eq!(of("T1").blockers, vec![uuid("2")]);
assert!(of("T2").blockers.is_empty(), "a regression was read as a blocker");
assert!(of("T3").blockers.is_empty(), "an unreadable section was not survived");
fs::remove_dir_all(&dir).unwrap();
}
/// Whole values, so a filter or a card cannot confuse two tags that share a prefix.
#[test]
fn parse_tags_splits_on_commas_and_keeps_whole_values() {