diff --git a/AGENTS.md b/AGENTS.md index 3843c88..ec18036 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -109,7 +109,21 @@ and this file is for what someone changing worklane's own code needs. - `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 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 +- **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 + +### Monitoring Several Boards +- `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 +- 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. That comparator is exported for this and is the one `collect_ticket_items` uses, so the two orders cannot drift +- `Card` wraps a `TicketItem` with the project it came from, `Some` only on the merge tab. Decided at reload rather than passed down to `card_lines` as a "which tab is this" flag. `TicketItem` is therefore `Clone`: the merge holds a second copy rather than re-reading every tree +- **The project follows the id, on the card and on the overlay border.** Across boards the id is not an address: two projects can hold the same title, and seven characters do not say where they live. `project_label` takes what the row has left after the mark and the id and ends in an ellipsis, and it is measured before the due date, so on the merge the project wins the narrow column and the date is what `corner_line` drops +- `tab` and `shift+tab` cycle rather than clamp, unlike the cards and columns: a row of tabs is a ring, and there is no end of a list to run off. Both were free of every other binding — the columns took `hjkl` and the arrows +- **The tab row is drawn only when there is more than one board**, so a single board is the view it has always been. `frame_rows()` gives it `Length(0)` otherwise, which keeps the row indices the same for both cases and is shared with `card_width` and `column_text_height` for the reason `column_areas` is: geometry reproduced by hand drifts from the draw +- `digest_of` hashes each board's `digest` into one value, so a change in any of them redraws. Do not watch only the first ### Shipping the Agent Assets - The skill is embedded with `include_str!` from `assets/SKILL.md`, not copied by an install script. `cargo install` places binaries and nothing else, so an installed document that is not in the binary is a document that drifts from it diff --git a/Cargo.lock b/Cargo.lock index f253ed4..c0353cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1494,7 +1494,7 @@ dependencies = [ [[package]] name = "worklane" -version = "0.8.5" +version = "0.9.0" dependencies = [ "anyhow", "assert_cmd", diff --git a/Cargo.toml b/Cargo.toml index 1fdce1c..ac8676e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "worklane" -version = "0.8.5" +version = "0.9.0" edition = "2024" [dependencies] diff --git a/README.md b/README.md index fe48776..3f1e3dd 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` | 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. Arrows or `hjkl` to move, `enter` for detail, `pgup`/`pgdn` to scroll an open ticket, `q` to quit | +| `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. Arrows or `hjkl` to move, `enter` for detail, `pgup`/`pgdn` to scroll an open ticket, `q` to quit. 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 directories | | `worklane add` | Creates a ticket in backlog with `--title`, `--description`, `--acceptance`, `--plan`, `--tags`, `--due`, `--owner`, `--priority` flags | | `worklane ls [status]` | Lists tickets, sorted by priority then title. Optional positional status, and `--priority <1-5>` | diff --git a/src/command.rs b/src/command.rs index 306fb38..df37437 100644 --- a/src/command.rs +++ b/src/command.rs @@ -110,7 +110,11 @@ pub enum Command { Append(AppendArgs), /// Open the board view - Tui, + Tui { + /// Projects to monitor, each resolved to the first `.worklane` at or above it. + /// Several are shown as tabs. Defaults to the working directory + paths: Vec, + }, /// Tick an acceptance criterion Check(CheckArgs), diff --git a/src/main.rs b/src/main.rs index 7a11e3b..b11d19e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,8 +38,10 @@ fn main() -> Result<()> { let start = std::env::current_dir()?; match cli.command { - // No subcommand opens the board, the way a bare `frig` does. - None | Some(Command::Tui) => run_tui(&start), + // No subcommand opens the board, the way a bare `frig` does, and with no path + // it opens the board above the working directory. + None => run_tui(&[], &start), + Some(Command::Tui { paths }) => run_tui(&paths, &start), Some(Command::Init) => cmd_init(&start), Some(Command::Add(args)) => cmd_add(&args, &start), Some(Command::Ls { status, priority }) => { @@ -92,14 +94,14 @@ fn restore_terminal() -> std::io::Result<()> { ) } -fn run_tui(start: &std::path::Path) -> Result<()> { +fn run_tui(paths: &[std::path::PathBuf], start: &std::path::Path) -> Result<()> { use crossterm::event::{self, Event, KeyCode, KeyEventKind, KeyModifiers}; use std::io::IsTerminal; - // The board is looked for before the terminal is, so running this outside a + // The boards are looked for before the terminal is, so running this outside a // worklane directory gives the same message every other command gives rather than // a complaint about the terminal. - let worklane_dir = find_worklane_dir(start)?; + let projects = tui::projects(paths, start)?; // Without this, entering raw mode on a pipe fails with a bare "No such device or // address (os error 6)", which says nothing about the actual mistake. A bare @@ -113,7 +115,7 @@ fn run_tui(start: &std::path::Path) -> Result<()> { )); } - let mut board = tui::Board::new(&worklane_dir)?; + let mut board = tui::Board::new(projects)?; install_panic_hook(); crossterm::terminal::enable_raw_mode()?; @@ -161,6 +163,11 @@ fn run_tui(start: &std::path::Path) -> Result<()> { KeyCode::Down | KeyCode::Char('j') => board.select_card(1, screen), KeyCode::PageUp => board.scroll_detail(-1, screen), KeyCode::PageDown => board.scroll_detail(1, screen), + // Tabs cycle rather than clamp, the way tabs everywhere do, and are + // a no-op with a single board. Free of every other binding: the + // 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), _ => {} diff --git a/src/tui.rs b/src/tui.rs index 90a8156..95ac00e 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -11,11 +11,11 @@ use std::hash::{Hash, Hasher}; use std::path::{Path, PathBuf}; use std::time::{Duration, SystemTime}; -use anyhow::Result; +use anyhow::{Context, Result}; use ratatui::layout::{Constraint, Direction, Layout, Margin, Rect, Size}; use ratatui::style::{Modifier, Style}; use ratatui::text::{Line, Span}; -use ratatui::widgets::{Block, Borders, Clear, Paragraph, Wrap}; +use ratatui::widgets::{Block, Borders, Clear, Paragraph, Tabs, Wrap}; use ratatui::Frame; use crate::handlers::read_comments; @@ -24,10 +24,158 @@ use crate::util::*; /// How long the event poll waits before letting the tick run. pub const POLL: Duration = Duration::from_millis(250); -/// One status and the tickets in it. +/// The tab that throws every monitored board into one set of columns. +/// +/// Lowercase like the column headings, since it sits in the same row of chrome and is +/// a label rather than a sentence. +const ALL: &str = "all"; + +/// One monitored board: where it lives, and what to call it. +#[derive(Debug)] +pub struct Project { + /// The directory holding the `.worklane`, which is what its tab is named after. + pub name: String, + /// The `.worklane` directory itself. + pub dir: PathBuf, +} + +/// The boards to monitor, resolved from the paths given on the command line. +/// +/// Each path is resolved the way every other command resolves the working directory: +/// the first `.worklane` at or above it. No paths at all is the working directory, +/// which is what a bare `worklane` has always done. +pub fn projects(paths: &[PathBuf], start: &Path) -> Result> { + let named = !paths.is_empty(); + let wanted: Vec = match named { + true => paths.to_vec(), + false => vec![start.to_path_buf()], + }; + + let mut projects: Vec = Vec::new(); + for path in &wanted { + // The path is named in the failure, because with several arguments "No + // .worklane directory found" does not say which one of them was wrong. Only + // when one was given: a bare `worklane` has no path to name, and prefixing + // the working directory would only bury the message every other command gives. + let dir = match named { + true => find_worklane_dir(path) + .with_context(|| format!("no board at or above {}", path.display()))?, + false => find_worklane_dir(path)?, + }; + + // Two paths inside one project reach the same board. Monitoring it twice would + // draw the same tickets under two tabs and count every change twice. + if projects.iter().any(|project| project.dir == dir) { + continue; + } + + projects.push(Project { + name: project_name(&dir), + dir, + }); + } + + Ok(projects) +} + +/// What a tab is called: the directory holding the `.worklane`. +/// +/// The board directory is always named `.worklane`, so it is the parent that names the +/// project. A `.worklane` with no parent means the filesystem root, and falls back to +/// the path so a tab is never blank. +fn project_name(dir: &Path) -> String { + dir.parent() + .and_then(|parent| parent.file_name()) + .map(|name| name.to_string_lossy().to_string()) + .unwrap_or_else(|| dir.to_string_lossy().to_string()) +} + +/// A ticket as the board holds it, and the project it came from when the view mixes +/// several. +/// +/// The label is `None` on a project's own tab, where the tab name already says it, and +/// on a single board, where there is nothing to confuse it with. Set at reload rather +/// than asked for at draw time, so nothing has to thread "which tab is this" down into +/// the card renderer. +pub struct Card { + pub ticket: TicketItem, + pub project: Option, +} + +/// One status and the cards in it. pub struct Column { pub status: &'static str, - pub tickets: Vec, + pub cards: Vec, +} + +/// One tab: a monitored board, or the merge across all of them. +/// +/// The selection and the column offsets live here rather than on the board, so +/// switching tabs returns to where that tab was left instead of pointing the shared +/// indices at whatever ticket happens to sit at the same place in another project. +pub struct Tab { + pub name: String, + pub columns: Vec, + pub column: usize, + pub card: usize, + /// First visible line of each column, counted in card lines. Parallel to + /// `columns`, so a tick that reshapes the board resizes it in step. + pub offsets: Vec, +} + +impl Tab { + fn new(name: String) -> Self { + Tab { + name, + columns: Vec::new(), + column: 0, + card: 0, + offsets: Vec::new(), + } + } + + /// The columns that are drawn: all of them, or everything up to done. + /// + /// 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)] + } + + 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, + 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); + if visible == 0 { + self.column = 0; + self.card = 0; + return; + } + + self.column = self.column.min(visible - 1); + let count = self.columns[self.column].cards.len(); + self.card = match count { + 0 => 0, + count => self.card.min(count - 1), + }; + } + + fn selected(&self) -> Option<&Card> { + self.columns + .get(self.column) + .and_then(|column| column.cards.get(self.card)) + } } /// What the detail view holds while it is open: the ticket it belongs to, then its @@ -40,53 +188,89 @@ pub struct Column { pub struct Detail { pub title: String, pub id: String, + /// The project the ticket belongs to, on the All tab only. The overlay covers the + /// card that said so, and the id alone is not an address across several boards: + /// acting on the ticket means knowing which project to run the command in. + pub project: Option, pub text: String, } /// What is on screen. pub struct Board { - pub columns: Vec, - pub column: usize, - pub card: usize, - /// First visible line of each column, counted in card lines. Parallel to - /// `columns`, so a tick that reshapes the board resizes it in step. - pub offsets: Vec, + /// The monitored boards as tabs, the merge first when there is more than one. + /// Never empty, so `tab` is always a valid index. + pub tabs: Vec, + pub tab: usize, /// The open detail view, when one is open. pub detail: Option, /// First visible line of the detail view, counted in wrapped lines. pub offset: u16, /// 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, pub should_quit: bool, - worklane_dir: PathBuf, + projects: Vec, digest: u64, } impl Board { - pub fn new(worklane_dir: &Path) -> Result { + pub fn new(projects: Vec) -> Result { + if projects.is_empty() { + return Err(anyhow::anyhow!("no board to monitor")); + } + + // The tabs are fixed for the run: a project cannot be added or dropped without + // restarting, so only their contents are rebuilt on a tick. The merge goes + // first because it is the reason to monitor several boards at once, and it is + // therefore where the view opens. + let mut tabs: Vec = Vec::new(); + if projects.len() > 1 { + tabs.push(Tab::new(ALL.to_string())); + } + tabs.extend( + projects + .iter() + .map(|project| Tab::new(project.name.clone())), + ); + let mut board = Board { - columns: Vec::new(), - column: 0, - card: 0, - offsets: Vec::new(), + tabs, + tab: 0, detail: None, offset: 0, show_done: false, should_quit: false, - worklane_dir: worklane_dir.to_path_buf(), + projects, digest: 0, }; board.reload()?; Ok(board) } - /// Re-read the tree only when the digest says it moved. + /// Whether the tab row is drawn, which is whether there is more than one board. + /// + /// A single board keeps the view it has always had: no tabs, and the columns + /// starting on the first row. + pub fn tabbed(&self) -> bool { + self.tabs.len() > 1 + } + + pub fn current(&self) -> &Tab { + &self.tabs[self.tab] + } + + fn current_mut(&mut self) -> &mut Tab { + &mut self.tabs[self.tab] + } + + /// Re-read the trees only when the digest says one of them moved. /// /// The scan is the expensive part, not the draw, so this is what the tick guards. /// ratatui diffs its buffer, so drawing every iteration costs nothing. pub fn tick(&mut self) -> Result { - let now = digest(&self.worklane_dir); + let now = digest_of(&self.projects); if now == self.digest { return Ok(false); } @@ -96,24 +280,30 @@ impl Board { } fn reload(&mut self) -> Result<()> { - self.columns = status_dirs() - .into_iter() - .map(|status| { - let path = self.worklane_dir.join(status); - // An absent or unreadable directory is an empty column, not a missing - // one: the four statuses are the shape of the board. - let tickets = collect_ticket_items(&path).unwrap_or_default(); - Column { status, tickets } - }) + // Each tree is read once. The merge is built from those cards rather than by + // scanning every project a second time. + let per_project: Vec> = self + .projects + .iter() + .map(|project| columns_of(&project.dir)) .collect(); - // One scroll position per column, kept by index. A tick that adds or removes - // columns is not a thing statuses do, but the resize keeps the two in step - // regardless; `resize` both pads and truncates. - self.offsets.resize(self.columns.len(), 0); + let mut built: Vec> = Vec::new(); + if self.projects.len() > 1 { + built.push(merge(&per_project, &self.projects)); + } + built.extend(per_project); - self.digest = digest(&self.worklane_dir); - self.clamp(); + for (tab, columns) in self.tabs.iter_mut().zip(built) { + tab.columns = columns; + // One scroll position per column, kept by index. A tick that adds or removes + // columns is not a thing statuses do, but the resize keeps the two in step + // regardless; `resize` both pads and truncates. + tab.offsets.resize(tab.columns.len(), 0); + tab.clamp(self.show_done); + } + + self.digest = digest_of(&self.projects); // The selected ticket may have moved or gone, so the open detail follows it. // The scroll offset stays where the reader put it: an edit elsewhere in the tree @@ -126,24 +316,34 @@ impl Board { Ok(()) } - /// The columns that are drawn: all of them, or everything up to done. - /// - /// 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. + /// The columns of the tab in view that are drawn. pub fn visible(&self) -> &[Column] { - &self.columns[..self.visible_count()] + self.current().visible(self.show_done) } fn visible_count(&self) -> usize { - if self.show_done { - return self.columns.len(); + self.current().visible_count(self.show_done) + } + + /// Move to another tab, cycling at either end. + /// + /// 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. + pub fn select_tab(&mut self, delta: isize, screen: Size) { + let count = self.tabs.len() as isize; + if count < 2 { + return; } - match self.columns.iter().position(|column| column.status == DONE) { - Some(index) => index, - None => self.columns.len(), - } + self.tab = (self.tab as isize + delta).rem_euclid(count) as usize; + + let show_done = self.show_done; + self.current_mut().clamp(show_done); + self.follow_selection(screen); + self.refresh_detail(); } /// Show or hide the done column. @@ -159,54 +359,40 @@ impl Board { self.show_done = !self.show_done; // Showing done again appends a column, so nothing below is reached and the - // selection stays exactly where it was. - if self.column < self.visible_count() { + // 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; } // 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. - self.clamp(); + let show_done = self.show_done; + self.current_mut().clamp(show_done); self.detail = None; self.offset = 0; self.follow_selection(screen); } - /// Keep the selection on a card that exists, after the board changes under it. - fn clamp(&mut self) { - let visible = self.visible_count(); - if visible == 0 { - self.column = 0; - self.card = 0; - return; - } - - self.column = self.column.min(visible - 1); - let count = self.columns[self.column].tickets.len(); - self.card = match count { - 0 => 0, - count => self.card.min(count - 1), - }; - } - - pub fn selected(&self) -> Option<&TicketItem> { - self.columns - .get(self.column) - .and_then(|column| column.tickets.get(self.card)) + pub fn selected(&self) -> Option<&Card> { + self.current().selected() } /// Move between columns, keeping the card index where it can land. pub fn select_column(&mut self, delta: isize, screen: Size) { - if self.visible_count() == 0 { + let visible = self.visible_count(); + if visible == 0 { return; } // Bounded by what is drawn, so the selection cannot walk into a hidden column. - let last = self.visible_count() as isize - 1; - let next = (self.column as isize + delta).clamp(0, last); - self.column = next as usize; - self.clamp(); + let last = visible as isize - 1; + let show_done = self.show_done; + let tab = self.current_mut(); + tab.column = (tab.column as isize + delta).clamp(0, last) as usize; + tab.clamp(show_done); // 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. @@ -216,16 +402,16 @@ impl Board { } pub fn select_card(&mut self, delta: isize, screen: Size) { - let count = match self.columns.get(self.column) { - Some(column) => column.tickets.len(), + let tab = self.current_mut(); + let count = match tab.columns.get(tab.column) { + Some(column) => column.cards.len(), None => return, }; if count == 0 { return; } - let next = (self.card as isize + delta).clamp(0, count as isize - 1); - self.card = next as usize; + tab.card = (tab.card as isize + delta).clamp(0, count as isize - 1) as usize; self.follow_selection(screen); self.refresh_detail(); } @@ -239,28 +425,32 @@ impl Board { /// on its own geometry, so a resize between this and the next frame is corrected /// there; what is stored here is the place an unfocused column keeps. fn follow_selection(&mut self, screen: Size) { - // The width the next draw will give this column, since a card's height depends - // on how much of the title has to wrap. Measured before the borrows below. - let width = card_width(screen, self.visible_count(), self.column); + // The width and height the next draw will give this column, since a card's + // height depends on how much of the title has to wrap and the tab row takes a + // row off the columns. Measured before the borrows below. + let column = self.current().column; + let width = card_width(screen, self.tabbed(), self.visible_count(), column); + let inner = column_text_height(screen, self.tabbed()); - let Some(column) = self.columns.get(self.column) else { + let tab = self.current_mut(); + let Some(column) = tab.columns.get(tab.column) else { return; }; - let Some(slot) = self.offsets.get_mut(self.column) else { + let Some(slot) = tab.offsets.get_mut(tab.column) else { return; }; - let height = |ticket: &TicketItem| card_height(ticket, width); + let height = |card: &Card| card_height(card, width); let start: u16 = column - .tickets - .get(..self.card) + .cards + .get(..tab.card) .map(|before| before.iter().map(height).sum()) .unwrap_or(0); - let end = start + column.tickets.get(self.card).map(height).unwrap_or(0); - let total: u16 = column.tickets.iter().map(height).sum(); + let end = start + column.cards.get(tab.card).map(height).unwrap_or(0); + let total: u16 = column.cards.iter().map(height).sum(); - *slot = aligned_offset(*slot, start, end, column_text_height(screen), total); + *slot = aligned_offset(*slot, start, end, inner, total); } /// Open the detail view on the selected card, or close it if it is already open. @@ -308,7 +498,8 @@ impl Board { /// /// Plain rather than coloured, since ratatui draws styled spans and an escape sequence /// in a paragraph would be printed as literal bytes. -fn detail_of(ticket: &TicketItem) -> Detail { +fn detail_of(card: &Card) -> Detail { + let ticket = &card.ticket; let content = std::fs::read_to_string(&ticket.path).unwrap_or_default(); let mut out = content_trim(&content, false); @@ -325,10 +516,68 @@ fn detail_of(ticket: &TicketItem) -> Detail { Detail { title: ticket.title.clone(), id: ticket.id.clone(), + project: card.project.clone(), text: out, } } +/// The four columns of one board. +fn columns_of(worklane_dir: &Path) -> Vec { + status_dirs() + .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. + let cards = collect_ticket_items(worklane_dir.join(status)) + .unwrap_or_default() + .into_iter() + .map(|ticket| Card { + ticket, + project: None, + }) + .collect(); + Column { status, cards } + }) + .collect() +} + +/// Every board's columns as one set of four, 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_dirs() + .into_iter() + .enumerate() + .map(|(index, status)| { + let mut cards: Vec = Vec::new(); + for (columns, project) in per_project.iter().zip(projects) { + let Some(column) = columns.get(index) else { + continue; + }; + cards.extend(column.cards.iter().map(|card| Card { + ticket: card.ticket.clone(), + project: Some(project.name.clone()), + })); + } + + cards.sort_by(|a, b| by_priority_then_title(&a.ticket, &b.ticket)); + Column { status, cards } + }) + .collect() +} + +/// The fingerprint of every monitored board, so a change in any of them redraws. +fn digest_of(projects: &[Project]) -> u64 { + let mut hasher = DefaultHasher::new(); + for project in projects { + digest(&project.dir).hash(&mut hasher); + } + hasher.finish() +} + /// A fingerprint of every ticket and comment file: name, length and modified time. /// /// Names alone would miss a ticket edited in place, and a directory's own mtime only @@ -384,19 +633,56 @@ pub fn digest(worklane_dir: &Path) -> u64 { pub fn draw(frame: &mut Frame, board: &Board) { let area = frame.area(); - let rows = Layout::default() - .direction(Direction::Vertical) - .constraints([Constraint::Min(3), Constraint::Length(1)]) - .split(area); + let rows = frame_rows(area, board.tabbed()); - draw_columns(frame, board, rows[0]); - draw_footer(frame, board, rows[1]); + if board.tabbed() { + draw_tabs(frame, board, rows[0]); + } + draw_columns(frame, board, rows[1]); + draw_footer(frame, board, rows[2]); if let Some(detail) = &board.detail { draw_detail(frame, detail, board.offset, area); } } +/// The rows of the frame: the tab row, the columns, the footer. +/// +/// One place, shared with the measurement in `card_width` and `column_text_height`, for +/// the same reason `column_areas` is shared: geometry reproduced by hand is geometry +/// that comes to disagree with the draw. With one board the tab row is zero rows high, +/// so the indices hold either way and rendering into it draws nothing. +fn frame_rows(area: Rect, tabbed: bool) -> std::rc::Rc<[Rect]> { + Layout::default() + .direction(Direction::Vertical) + .constraints([ + Constraint::Length(u16::from(tabbed)), + Constraint::Min(3), + Constraint::Length(1), + ]) + .split(area) +} + +/// One tab per monitored board, plus the merge, named after the directory each lives in. +/// +/// Cyan for the one in view, the colour the focused column's border already uses, and +/// grey for the rest. +fn draw_tabs(frame: &mut Frame, board: &Board, area: Rect) { + let names: Vec = board.tabs.iter().map(|tab| tab.name.clone()).collect(); + + frame.render_widget( + Tabs::new(names) + .select(board.tab) + .style(Style::default().fg(Color::Grey.into())) + .highlight_style( + Style::default() + .fg(Color::Cyan.into()) + .add_modifier(Modifier::BOLD), + ), + area, + ); +} + fn draw_columns(frame: &mut Frame, board: &Board, area: Rect) { // Only the drawn columns are measured, so hiding done gives its width back to the // three that are left rather than leaving a gap where it was. @@ -404,8 +690,8 @@ fn draw_columns(frame: &mut Frame, board: &Board, area: Rect) { let areas = column_areas(area, columns.len()); for (index, column) in columns.iter().enumerate() { - let focused = index == board.column; - let title = format!(" {} ({}) ", column.status, column.tickets.len()); + let focused = index == board.current().column; + let title = format!(" {} ({}) ", column.status, column.cards.len()); let block = Block::default() .borders(Borders::ALL) @@ -431,13 +717,13 @@ fn draw_columns(frame: &mut Frame, board: &Board, area: Rect) { let text = areas[index].inner(Margin::new(1, 1)); let mut lines: Vec = Vec::new(); let mut starts: Vec = Vec::new(); - for (card, ticket) in column.tickets.iter().enumerate() { - let selected = focused && card == board.card; + for (at, card) in column.cards.iter().enumerate() { + let selected = focused && at == board.current().card; starts.push(lines.len() as u16); - lines.extend(card_lines(ticket, selected, text.width)); + lines.extend(card_lines(card, selected, text.width)); } let total = lines.len() as u16; - let stored = board.offsets.get(index).copied().unwrap_or(0); + let stored = board.current().offsets.get(index).copied().unwrap_or(0); // The focused column follows its selection here as well as on the keypress: // the terminal can be resized between the two, and a tick can shorten the @@ -445,8 +731,9 @@ fn draw_columns(frame: &mut Frame, board: &Board, area: Rect) { // the place it was left in, capped so it cannot show blank space past its // last card. let offset = if focused { - let start = starts.get(board.card).copied().unwrap_or(total); - let end = starts.get(board.card + 1).copied().unwrap_or(total); + let card = board.current().card; + let start = starts.get(card).copied().unwrap_or(total); + let end = starts.get(card + 1).copied().unwrap_or(total); aligned_offset(stored, start, end, text.height, total) } else { stored.min(total.saturating_sub(text.height)) @@ -466,8 +753,8 @@ fn draw_columns(frame: &mut Frame, board: &Board, area: Rect) { /// /// Width-dependent, because the title wraps: the same ticket is four rows in a wide /// column and five in a narrow one. -fn card_height(ticket: &TicketItem, width: u16) -> u16 { - card_lines(ticket, false, width).len() as u16 +fn card_height(card: &Card, width: u16) -> u16 { + card_lines(card, false, width).len() as u16 } /// The rectangles the columns are drawn in, from one place. @@ -488,23 +775,24 @@ fn column_areas(area: Rect, count: usize) -> std::rc::Rc<[Rect]> { } /// The width a card has inside one column, as the next draw will lay it out. -fn card_width(screen: Size, count: usize, column: usize) -> u16 { - // The footer takes the last row; the columns get everything above it, which is the - // area `draw` hands to `draw_columns`. - let board = Rect::new(0, 0, screen.width, screen.height.saturating_sub(1)); - column_areas(board, count) +fn card_width(screen: Size, tabbed: bool, count: usize, column: usize) -> u16 { + column_areas(board_area(screen, tabbed), count) .get(column) .map(|area| area.inner(Margin::new(1, 1)).width) .unwrap_or(0) } -/// The rows a column's cards share: above the footer row and inside the border. +/// The rows a column's cards share: inside the border of the area the columns get. /// -/// Mirrors the vertical layout in `draw`: one footer row, then a border row on either -/// side of the text. The draw measures the real inner rectangle instead, so a terminal -/// too short for this arithmetic is corrected there. -fn column_text_height(screen: Size) -> u16 { - screen.height.saturating_sub(3) +/// A border row on either side of the text. The draw measures the real inner rectangle +/// instead, so a terminal too short for this arithmetic is corrected there. +fn column_text_height(screen: Size, tabbed: bool) -> u16 { + board_area(screen, tabbed).height.saturating_sub(2) +} + +/// The area the columns are drawn in, which is what `draw` hands to `draw_columns`. +fn board_area(screen: Size, tabbed: bool) -> Rect { + frame_rows(Rect::new(0, 0, screen.width, screen.height), tabbed)[1] } /// The offset that keeps the lines `start..end` in view, inside content `0..total`. @@ -538,7 +826,12 @@ fn aligned_offset(offset: u16, start: u16, end: u16, inner: u16, total: u16) -> /// eye goes for a number, and both were invisible at the end of a line of prose. The /// title gets two rows because worklane's own titles are routinely longer than a /// quarter of a terminal, and one row cut them off mid-word with nothing to say so. -fn card_lines(ticket: &TicketItem, selected: bool, width: u16) -> Vec> { +/// +/// On the All tab the project follows the id in that top left corner, since across +/// several boards the id alone is not an address: two projects can hold the same title, +/// and seven characters do not say where they live. +fn card_lines(card: &Card, selected: bool, width: u16) -> Vec> { + let ticket = &card.ticket; let (glyph, colour) = priority_mark(ticket.priority); let emphasis = if selected { Modifier::REVERSED @@ -546,21 +839,32 @@ fn card_lines(ticket: &TicketItem, selected: bool, width: u16) -> Vec Vec Option { + // 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)?; + if room < 3 { + return None; + } + + match name.chars().count() <= room { + true => Some(name.to_string()), + false => Some(with_ellipsis(name, room)), + } +} + /// A set due in the timestamp colour, an unset one dimmed, per the colour guideline. /// /// The date part only: the field is not validated, so it can hold a time as well, and a @@ -713,9 +1042,17 @@ fn draw_footer(frame: &mut Frame, board: &Board, area: Rect) { false => format!("d show done ({})", done_count(board)), }; + // Only when there is a tab to move to, since the footer names keys that work. + let tabs = match board.tabbed() { + true => "tab project ", + false => "", + }; + let keys = match board.detail { - Some(_) => format!(" ←→↑↓ select pgup/pgdn scroll enter close {done} q quit "), - None => format!(" ←→ column ↑↓ card enter detail {done} q quit "), + Some(_) => { + format!(" {tabs}←→↑↓ select pgup/pgdn scroll enter close {done} q quit ") + } + None => format!(" {tabs}←→ column ↑↓ card enter detail {done} q quit "), }; frame.render_widget( @@ -724,13 +1061,14 @@ fn draw_footer(frame: &mut Frame, board: &Board, area: Rect) { ); } -/// How many tickets are in done, drawn or not. +/// How many tickets are in done on the tab in view, drawn or not. fn done_count(board: &Board) -> usize { board + .current() .columns .iter() .find(|column| column.status == DONE) - .map_or(0, |column| column.tickets.len()) + .map_or(0, |column| column.cards.len()) } /// Where the detail overlay sits in the frame. @@ -806,13 +1144,21 @@ fn draw_detail(frame: &mut Frame, detail: &Detail, offset: u16, area: Rect) { /// write on — the id survives whole and the name ends in an ellipsis where it was /// trimmed. On an overlay too narrow for even the id, what fits is what shows. fn detail_title(detail: &Detail, overlay_width: u16) -> String { + // The project rides in the prefix, beside the id, so what survives the cut is the + // whole address rather than half of one. Absent on a single board and on a + // project's own tab, where the overlay reads exactly as it always has. + let project = match &detail.project { + Some(name) => format!("{name} "), + None => String::new(), + }; + let room = overlay_width.saturating_sub(2) as usize; - let full = format!(" ({}) · {} ", detail.id, detail.title); + let full = format!(" ({}) {}· {} ", detail.id, project, detail.title); if full.chars().count() <= room { return full; } - let prefix = format!(" ({}) · ", detail.id); + let prefix = format!(" ({}) {}· ", detail.id, project); match room.checked_sub(prefix.chars().count() + 1) { Some(keep) if keep > 0 => { let name: String = detail.title.chars().take(keep).collect(); @@ -829,6 +1175,9 @@ mod tests { use ratatui::backend::TestBackend; /// A board on disk, since everything here is about reading a real tree. + /// + /// The directory stands in for a `.worklane`, so its parent is the temp directory + /// and `project_name` reads the generated name off it. fn board_dir() -> PathBuf { let dir = std::env::temp_dir().join(format!("worklane-tui-{}", uuid::Uuid::new_v4())); for status in status_dirs() { @@ -837,6 +1186,35 @@ mod tests { dir } + /// The single board case, which is what most of these tests are about. + fn one_board(dir: &Path) -> Board { + Board::new(vec![project_at(dir)]).unwrap() + } + + fn project_at(dir: &Path) -> Project { + Project { + name: project_name(dir), + dir: dir.to_path_buf(), + } + } + + /// Several boards, named so a test can tell their cards apart. + fn boards(dirs: &[(&str, &Path)]) -> Board { + Board::new( + dirs.iter() + .map(|(name, dir)| Project { + name: name.to_string(), + dir: dir.to_path_buf(), + }) + .collect(), + ) + .unwrap() + } + + fn selected_title(board: &Board) -> Option { + board.selected().map(|card| card.ticket.title.clone()) + } + fn write_ticket(dir: &Path, status: &str, uuid: &str, title: &str, extra: &str) -> PathBuf { let path = dir.join(status).join(format!("{}_{}.md", uuid, slug(title))); std::fs::write( @@ -887,8 +1265,16 @@ mod tests { /// /// That row alone, because the footer names done as well: a whole-screen search for /// `done (0)` passes on the footer whether the column is drawn or not, which is how - /// three of these tests came to be vacuous the moment done was hidden. + /// three of these tests came to be vacuous the moment done was hidden. Located + /// through the layout rather than assumed to be row zero, since a tab row sits above + /// it when more than one board is monitored. fn headings(board: &Board, width: u16, height: u16) -> String { + let top = board_area(Size { width, height }, board.tabbed()).y as usize; + render(board, width, height).remove(top) + } + + /// The tab row, which is the top row whenever it is drawn at all. + fn tab_row(board: &Board, width: u16, height: u16) -> String { render(board, width, height).remove(0) } @@ -914,7 +1300,7 @@ mod tests { write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "First one", ""); write_ticket(&dir, "committed", "22222222-0000-4000-8000-000000000000", "Second one", ""); - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); board.toggle_done(SCREEN); let row = headings(&board, 120, 20); @@ -931,7 +1317,7 @@ mod tests { write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "First one", ""); write_ticket(&dir, "done", "44444444-0000-4000-8000-000000000000", "Finished one", ""); - let board = Board::new(&dir).unwrap(); + let board = one_board(&dir); assert!(!board.show_done, "done was drawn at startup"); let row = headings(&board, 120, 20); @@ -941,7 +1327,7 @@ mod tests { assert!(!row.contains("done"), "done is still a column:\n{row}"); // Hidden, not unread: the count is right and revealing it needs no rescan. - assert_eq!(board.columns.len(), 4); + assert_eq!(board.current().columns.len(), 4); assert_eq!(board.visible().len(), 3); assert_eq!(done_count(&board), 1); assert!( @@ -954,7 +1340,7 @@ mod tests { #[test] fn the_visible_columns_share_the_full_width() { let dir = board_dir(); - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); let hidden = headings(&board, 120, 20); assert_eq!(hidden.matches('┌').count(), 3, "{hidden}"); @@ -980,7 +1366,7 @@ mod tests { write_ticket(&dir, "done", &format!("{n}-0000-4000-8000-000000000000"), title, ""); } - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); let hidden = footer(&board, 120, 20); assert!(hidden.contains("d show done (2)"), "{hidden}"); @@ -997,7 +1383,7 @@ mod tests { let dir = board_dir(); write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "First one", ""); - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); board.toggle_detail(); let row = footer(&board, 120, 20); @@ -1012,14 +1398,14 @@ mod tests { write_ticket(&dir, "reviewing", "33333333-0000-4000-8000-000000000000", "Ready", ""); write_ticket(&dir, "done", "44444444-0000-4000-8000-000000000000", "Finished", ""); - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); board.toggle_done(SCREEN); board.select_column(3, SCREEN); - assert_eq!(board.selected().map(|t| t.title.clone()), Some("Finished".to_string())); + assert_eq!(selected_title(&board), Some("Finished".to_string())); board.toggle_done(SCREEN); - assert_eq!(board.column, 2, "the selection stayed on a column that is gone"); - assert_eq!(board.selected().map(|t| t.title.clone()), Some("Ready".to_string())); + assert_eq!(board.current().column, 2, "the selection stayed on a column that is gone"); + assert_eq!(selected_title(&board), Some("Ready".to_string())); } /// And an open detail of a done ticket goes with it: showing a ticket that is no @@ -1031,7 +1417,7 @@ mod tests { write_ticket(&dir, "reviewing", "33333333-0000-4000-8000-000000000000", "Ready", ""); write_ticket(&dir, "done", "44444444-0000-4000-8000-000000000000", "Finished", ""); - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); board.toggle_done(SCREEN); board.select_column(3, SCREEN); board.toggle_detail(); @@ -1047,7 +1433,7 @@ mod tests { let dir = board_dir(); write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "First one", ""); - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); board.toggle_detail(); board.toggle_done(SCREEN); board.toggle_done(SCREEN); @@ -1063,14 +1449,14 @@ mod tests { write_ticket(&dir, "committed", "33333333-0000-4000-8000-000000000000", "Beta", ""); write_ticket(&dir, "done", "44444444-0000-4000-8000-000000000000", "Finished", ""); - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); board.select_column(1, SCREEN); board.select_card(1, SCREEN); - let (column, card) = (board.column, board.card); + let (column, card) = (board.current().column, board.current().card); board.toggle_done(SCREEN); - assert_eq!((board.column, board.card), (column, card)); - assert_eq!(board.selected().map(|t| t.title.clone()), Some("Beta".to_string())); + assert_eq!((board.current().column, board.current().card), (column, card)); + assert_eq!(selected_title(&board), Some("Beta".to_string())); } /// The selection cannot walk into a column that is not drawn. @@ -1079,15 +1465,15 @@ mod tests { let dir = board_dir(); write_ticket(&dir, "done", "44444444-0000-4000-8000-000000000000", "Finished", ""); - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); board.select_column(9, SCREEN); - assert_eq!(board.column, 2); + assert_eq!(board.current().column, 2); assert!(board.selected().is_none(), "the selection reached the done column"); board.toggle_done(SCREEN); board.select_column(9, SCREEN); - assert_eq!(board.column, 3); - assert_eq!(board.selected().map(|t| t.title.clone()), Some("Finished".to_string())); + assert_eq!(board.current().column, 3); + assert_eq!(selected_title(&board), Some("Finished".to_string())); } /// The card has to carry enough to identify the ticket without opening it. @@ -1096,7 +1482,7 @@ mod tests { let dir = board_dir(); write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "First one", ""); - let board = Board::new(&dir).unwrap(); + let board = one_board(&dir); let screen = render(&board, 120, 20).join("\n"); assert!(screen.contains("(1111111)"), "no short id in:\n{screen}"); @@ -1123,8 +1509,8 @@ mod tests { /// The rows of the only card on the board, at the width the column gives it. fn only_card(dir: &Path, width: u16, height: u16) -> Vec { - let board = Board::new(dir).unwrap(); - let inner = card_width(Size { width, height }, board.visible().len(), 0); + let board = one_board(dir); + let inner = card_width(Size { width, height }, board.tabbed(), board.visible().len(), 0); let ticket = board.selected().expect("no card"); card_lines(ticket, false, inner) .iter() @@ -1135,8 +1521,8 @@ mod tests { /// The foreground of the span whose text is `needle`, which `render` cannot show: /// it drops styling on the way out of the buffer. fn card_colour(dir: &Path, width: u16, needle: &str) -> Option { - let board = Board::new(dir).unwrap(); - let inner = card_width(Size { width, height: 20 }, board.visible().len(), 0); + let board = one_board(dir); + let inner = card_width(Size { width, height: 20 }, board.tabbed(), board.visible().len(), 0); let ticket = board.selected().expect("no card"); card_lines(ticket, false, inner) @@ -1162,7 +1548,7 @@ mod tests { ); let rows = only_card(&dir, 120, 20); - let inner = card_width(Size { width: 120, height: 20 }, 3, 0) as usize; + let inner = card_width(Size { width: 120, height: 20 }, false, 3, 0) as usize; assert_eq!(rows.len(), 5, "expected two title rows and a blank: {rows:?}"); assert!(rows[1].starts_with("A title long"), "{rows:?}"); @@ -1265,7 +1651,7 @@ mod tests { write_card(&dir, "Short", "2026-12-31", "- [ ] One"); let rows = only_card(&dir, 52, 14); - let inner = card_width(Size { width: 52, height: 14 }, 3, 0) as usize; + let inner = card_width(Size { width: 52, height: 14 }, false, 3, 0) as usize; assert!(rows[0].starts_with("\u{25cf}\u{25d0} (1111111)"), "{rows:?}"); assert!(!rows[0].contains("2026"), "the due overran the column: {rows:?}"); @@ -1279,8 +1665,8 @@ mod tests { fn an_empty_status_renders_as_an_empty_column() { let dir = board_dir(); - let mut board = Board::new(&dir).unwrap(); - assert_eq!(board.columns.len(), 4); + let mut board = one_board(&dir); + assert_eq!(board.current().columns.len(), 4); board.toggle_done(SCREEN); let row = headings(&board, 120, 20); @@ -1295,8 +1681,8 @@ mod tests { let dir = board_dir(); std::fs::remove_dir_all(dir.join(DONE)).unwrap(); - let mut board = Board::new(&dir).unwrap(); - assert_eq!(board.columns.len(), 4); + let mut board = one_board(&dir); + assert_eq!(board.current().columns.len(), 4); board.toggle_done(SCREEN); assert!(headings(&board, 120, 20).contains("done (0)")); @@ -1389,27 +1775,27 @@ mod tests { write_ticket(&dir, "backlog", "22222222-0000-4000-8000-000000000000", "Beta", ""); write_ticket(&dir, "committed", "33333333-0000-4000-8000-000000000000", "Gamma", ""); - let mut board = Board::new(&dir).unwrap(); - assert_eq!(board.selected().map(|t| t.title.clone()), Some("Alpha".to_string())); + let mut board = one_board(&dir); + assert_eq!(selected_title(&board), Some("Alpha".to_string())); board.select_card(1, SCREEN); - assert_eq!(board.selected().map(|t| t.title.clone()), Some("Beta".to_string())); + assert_eq!(selected_title(&board), Some("Beta".to_string())); // Clamped at both ends rather than wrapping board.select_card(5, SCREEN); - assert_eq!(board.selected().map(|t| t.title.clone()), Some("Beta".to_string())); + assert_eq!(selected_title(&board), Some("Beta".to_string())); board.select_card(-9, SCREEN); - assert_eq!(board.selected().map(|t| t.title.clone()), Some("Alpha".to_string())); + assert_eq!(selected_title(&board), Some("Alpha".to_string())); board.select_column(1, SCREEN); - assert_eq!(board.selected().map(|t| t.title.clone()), Some("Gamma".to_string())); + assert_eq!(selected_title(&board), Some("Gamma".to_string())); // reviewing is empty, so there is nothing selected there board.select_column(1, SCREEN); assert!(board.selected().is_none()); board.select_column(-9, SCREEN); - assert_eq!(board.column, 0); + assert_eq!(board.current().column, 0); } /// Moving from a column with three cards to one with one must not leave the @@ -1422,12 +1808,12 @@ mod tests { } write_ticket(&dir, "committed", "44444444-0000-4000-8000-000000000000", "Delta", ""); - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); board.select_card(2, SCREEN); board.select_column(1, SCREEN); - assert_eq!(board.card, 0); - assert_eq!(board.selected().map(|t| t.title.clone()), Some("Delta".to_string())); + assert_eq!(board.current().card, 0); + assert_eq!(selected_title(&board), Some("Delta".to_string())); } /// A column long enough that one window cannot hold it: twelve cards at four lines @@ -1451,7 +1837,7 @@ mod tests { let dir = board_dir(); fill_column(&dir, "backlog", 12); - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); let top = render(&board, SCREEN.width, SCREEN.height).join("\n"); assert!(top.contains("Ticket 01"), "{top}"); @@ -1476,12 +1862,12 @@ mod tests { let dir = board_dir(); fill_column(&dir, "backlog", 12); - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); board.select_card(11, SCREEN); - assert_eq!(board.offsets[0], 31); + assert_eq!(board.current().offsets[0], 31); board.select_card(-99, SCREEN); - assert_eq!(board.offsets[0], 0, "the column stayed where the bottom left it"); + assert_eq!(board.current().offsets[0], 0, "the column stayed where the bottom left it"); let top = render(&board, SCREEN.width, SCREEN.height).join("\n"); assert!(top.contains("Ticket 01"), "{top}"); @@ -1495,15 +1881,15 @@ mod tests { let dir = board_dir(); fill_column(&dir, "backlog", 12); - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); // More downs than the column has, since the clamp and the cap are what stop it. for _ in 0..30 { board.select_card(1, SCREEN); } - assert_eq!(board.card, 11); + assert_eq!(board.current().card, 11); // Twelve cards at four lines, seventeen visible rows. - assert_eq!(board.offsets[0], 48 - 17); + assert_eq!(board.current().offsets[0], 48 - 17); let end = render(&board, SCREEN.width, SCREEN.height).join("\n"); assert!(end.contains("Ticket 12"), "the end is out of reach:\n{end}"); @@ -1518,7 +1904,7 @@ mod tests { let dir = board_dir(); fill_column(&dir, "backlog", 12); - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); board.select_card(11, SCREEN); for n in 6..=12 { @@ -1528,7 +1914,7 @@ mod tests { } assert!(board.tick().unwrap(), "the tick saw no change"); - assert_eq!(board.card, 4, "the selection was not clamped to the new end"); + assert_eq!(board.current().card, 4, "the selection was not clamped to the new end"); let shrunk = render(&board, SCREEN.width, SCREEN.height).join("\n"); assert!(shrunk.contains("Ticket 05"), "the new end is out of reach:\n{shrunk}"); @@ -1537,7 +1923,7 @@ mod tests { // The stored value is stale until the next navigation, which is fine: the draw // corrected what was shown, and this is what writes the correction back. board.select_card(0, SCREEN); - assert_eq!(board.offsets[0], 3); + assert_eq!(board.current().offsets[0], 3); } /// Each column keeps its own place: leaving one must not snap it back to the top, @@ -1556,12 +1942,12 @@ mod tests { ); } - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); board.select_card(11, SCREEN); board.select_column(1, SCREEN); // The card index carried over and clamps onto committed's last card. - assert_eq!(board.card, 2); + assert_eq!(board.current().card, 2); let away = render(&board, SCREEN.width, SCREEN.height).join("\n"); assert!( @@ -1574,7 +1960,7 @@ mod tests { // Back in backlog the selection is card 2: the index is shared and it moved // while we were away, so the column follows where it is now rather than // holding a scroll position for a highlight it no longer has. - assert_eq!(board.card, 2); + assert_eq!(board.current().card, 2); let back = render(&board, SCREEN.width, SCREEN.height).join("\n"); assert!( back.contains("Ticket 03"), @@ -1596,9 +1982,9 @@ mod tests { height: 60, }; - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); board.select_card(11, roomy); - assert_eq!(board.offsets[0], 0); + assert_eq!(board.current().offsets[0], 0); let shrunk = render(&board, SCREEN.width, SCREEN.height).join("\n"); assert!( @@ -1622,7 +2008,7 @@ mod tests { ) .unwrap(); - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); assert!(board.detail.is_none()); board.toggle_detail(); @@ -1651,7 +2037,7 @@ mod tests { let dir = board_dir(); write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "First one", ""); - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); board.toggle_detail(); let screen = render(&board, SCREEN.width, SCREEN.height); @@ -1680,7 +2066,7 @@ mod tests { &long_section(60), ); - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); board.toggle_detail(); for _ in 0..20 { board.scroll_detail(1, SCREEN); @@ -1704,7 +2090,7 @@ mod tests { let title = format!("Head {} tailmarker", "filler ".repeat(20)); write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", &title, ""); - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); board.toggle_detail(); let screen = render(&board, SCREEN.width, SCREEN.height); @@ -1725,7 +2111,7 @@ mod tests { let uuid = "11111111-0000-4000-8000-000000000000"; write_ticket(&dir, "backlog", uuid, "First one", ""); - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); board.toggle_detail(); assert!(!board.detail.as_ref().unwrap().text.contains("A late note.")); @@ -1750,7 +2136,7 @@ mod tests { let dir = board_dir(); write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "First one", ""); - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); assert!(!board.tick().unwrap()); } @@ -1770,7 +2156,7 @@ mod tests { ) .unwrap(); - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); board.toggle_detail(); let top = render(&board, SCREEN.width, SCREEN.height).join("\n"); @@ -1801,7 +2187,7 @@ mod tests { &long_section(60), ); - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); board.toggle_detail(); for _ in 0..20 { @@ -1844,7 +2230,7 @@ mod tests { height: 60, }; - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); board.toggle_detail(); let before = render(&board, roomy.width, roomy.height); @@ -1861,7 +2247,7 @@ mod tests { write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "Alpha", ""); write_ticket(&dir, "backlog", "22222222-0000-4000-8000-000000000000", "Beta", ""); - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); board.toggle_detail(); // By id in the text: the heading is stripped from the body, and the title // travels beside it for the block title instead. @@ -1872,7 +2258,7 @@ mod tests { ); board.select_card(1, SCREEN); - assert_eq!(board.selected().map(|t| t.title.clone()), Some("Beta".to_string())); + assert_eq!(selected_title(&board), Some("Beta".to_string())); assert!( board.detail.as_ref().unwrap().text.contains("22222222"), "{:?}", @@ -1889,7 +2275,7 @@ mod tests { write_ticket(&dir, "backlog", "22222222-0000-4000-8000-000000000000", "Beta", &long); write_ticket(&dir, "committed", "33333333-0000-4000-8000-000000000000", "Gamma", &long); - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); board.toggle_detail(); board.scroll_detail(1, SCREEN); @@ -1914,7 +2300,7 @@ mod tests { &long_section(60), ); - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); board.toggle_detail(); board.scroll_detail(1, SCREEN); assert!(board.offset > 0); @@ -1931,7 +2317,7 @@ mod tests { let uuid = "11111111-0000-4000-8000-000000000000"; write_ticket(&dir, "backlog", uuid, "First one", &long_section(60)); - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); board.toggle_detail(); board.scroll_detail(1, SCREEN); let offset = board.offset; @@ -1961,7 +2347,7 @@ mod tests { &long_section(60), ); - let mut board = Board::new(&dir).unwrap(); + let mut board = one_board(&dir); let closed = render(&board, SCREEN.width, SCREEN.height).join("\n"); assert!(closed.contains("↑↓ card"), "{closed}"); @@ -1975,6 +2361,298 @@ mod tests { assert!(open.contains("enter close"), "{open}"); } + // ------------------------------------------------------- several boards at once -- + + /// A project tree: a directory holding a `.worklane`, which is what a path argument + /// is resolved to. + fn project_tree(name: &str) -> PathBuf { + let root = std::env::temp_dir() + .join(format!("worklane-project-{}", uuid::Uuid::new_v4())) + .join(name); + for status in status_dirs() { + std::fs::create_dir_all(root.join(".worklane").join(status)).unwrap(); + } + root + } + + /// No path is the working directory, which is what a bare `worklane` has always + /// done, and the tab is named after the project rather than after `.worklane`. + #[test] + fn no_path_resolves_the_working_directory() { + let root = project_tree("alpha"); + + let found = projects(&[], &root).unwrap(); + assert_eq!(found.len(), 1); + assert_eq!(found[0].name, "alpha"); + assert_eq!(found[0].dir.file_name().unwrap(), ".worklane"); + } + + /// A path is resolved the way the working directory is: the first board at or above + /// it, so pointing at a subdirectory finds the project it belongs to. + #[test] + fn a_path_resolves_the_first_board_at_or_above_it() { + let root = project_tree("alpha"); + let deep = root.join("src").join("nested"); + std::fs::create_dir_all(&deep).unwrap(); + + let found = projects(&[deep], &std::env::temp_dir()).unwrap(); + assert_eq!(found.len(), 1); + assert_eq!(found[0].name, "alpha"); + } + + #[test] + fn several_paths_are_monitored_together() { + let (alpha, beta) = (project_tree("alpha"), project_tree("beta")); + + let found = projects(&[alpha, beta], &std::env::temp_dir()).unwrap(); + let names: Vec<&str> = found.iter().map(|p| p.name.as_str()).collect(); + assert_eq!(names, ["alpha", "beta"]); + } + + /// With several arguments, "No .worklane directory found" does not say which one was + /// wrong, so the path is named. + #[test] + fn a_path_with_no_board_fails_naming_that_path() { + let alpha = project_tree("alpha"); + let bare = std::env::temp_dir().join(format!("worklane-bare-{}", uuid::Uuid::new_v4())); + std::fs::create_dir_all(&bare).unwrap(); + + let error = projects(&[alpha, bare.clone()], &std::env::temp_dir()).unwrap_err(); + let printed = format!("{error:#}"); + + assert!( + printed.contains(&bare.display().to_string()), + "the failing path is not named: {printed}" + ); + // And the usual message is still there, underneath the path. + assert!(printed.contains("No .worklane directory found"), "{printed}"); + } + + /// Two paths inside one project reach one board, and drawing it twice would show the + /// same tickets under two tabs. + #[test] + fn two_paths_reaching_one_board_are_monitored_once() { + let root = project_tree("alpha"); + let deep = root.join("src"); + std::fs::create_dir_all(&deep).unwrap(); + + let found = projects(&[root, deep], &std::env::temp_dir()).unwrap(); + assert_eq!(found.len(), 1, "the same board was monitored twice"); + } + + /// One board is the view it has always been: no tabs, columns on the top row. + #[test] + fn a_single_board_has_no_tab_row() { + let dir = board_dir(); + write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "Alpha", ""); + + let board = one_board(&dir); + assert!(!board.tabbed()); + assert_eq!(board.tabs.len(), 1); + + let top = tab_row(&board, 120, 20); + assert!(top.starts_with('┌'), "something took the top row:\n{top}"); + assert!(top.contains("backlog (1)"), "{top}"); + } + + /// A tab per project, plus the merge, and the merge is where the view opens: it is + /// the reason to monitor several boards at once. + #[test] + fn several_boards_get_a_tab_each_beside_the_all_tab() { + let (first, second) = (board_dir(), board_dir()); + + let board = boards(&[("alpha", &first), ("beta", &second)]); + assert!(board.tabbed()); + + let names: Vec<&str> = board.tabs.iter().map(|tab| tab.name.as_str()).collect(); + assert_eq!(names, [ALL, "alpha", "beta"]); + assert_eq!(board.current().name, ALL); + + let row = tab_row(&board, 120, 20); + for name in [ALL, "alpha", "beta"] { + assert!(row.contains(name), "no {name:?} in the tab row:\n{row}"); + } + + // The columns moved down a row rather than being drawn over. + assert!(headings(&board, 120, 20).contains("backlog (0)")); + } + + /// The merge holds every board's tickets, in the order the listing uses rather than + /// one project's column after another's. + #[test] + fn the_all_tab_holds_every_board_in_one_set_of_columns() { + let (first, second) = (board_dir(), board_dir()); + // Written the wrong way round on purpose: the merge has to sort, not concatenate. + write_ticket(&first, "backlog", "22222222-0000-4000-8000-000000000000", "Beta", ""); + write_ticket(&second, "backlog", "11111111-0000-4000-8000-000000000000", "Alpha", ""); + write_ticket(&second, "committed", "33333333-0000-4000-8000-000000000000", "Gamma", ""); + + let board = boards(&[("alpha", &first), ("beta", &second)]); + + let titles: Vec<&str> = board.current().columns[0] + .cards + .iter() + .map(|card| card.ticket.title.as_str()) + .collect(); + assert_eq!(titles, ["Alpha", "Beta"], "the merge kept the argument order"); + + let row = headings(&board, 120, 20); + assert!(row.contains("backlog (2)"), "{row}"); + assert!(row.contains("committed (1)"), "{row}"); + + // And each project's own tab still holds only its own tickets. + let mut board = board; + board.select_tab(1, SCREEN); + assert_eq!(board.current().name, "alpha"); + assert_eq!(board.current().columns[0].cards.len(), 1); + } + + /// Two boards can hold the same title, and seven characters of uuid do not say where + /// a ticket lives, so the card on the merge names its project. + #[test] + fn a_card_on_the_all_tab_names_its_project() { + let (first, second) = (board_dir(), board_dir()); + write_ticket(&first, "backlog", "11111111-0000-4000-8000-000000000000", "Same name", ""); + write_ticket(&second, "backlog", "22222222-0000-4000-8000-000000000000", "Same name", ""); + + let mut board = boards(&[("alpha", &second), ("beta", &first)]); + let merged = render(&board, 120, 20).join("\n"); + assert!(merged.contains("alpha"), "no project on the card:\n{merged}"); + assert!(merged.contains("beta"), "no project on the card:\n{merged}"); + + // Not on a project's own tab, where the tab name already says it. + board.select_tab(1, SCREEN); + let own = board.current().columns[0].cards[0].project.as_deref(); + assert_eq!(own, None, "the label was drawn where the tab says it"); + } + + /// 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. + #[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); + } + + /// A change in any monitored board has to redraw, not only one in the first. + #[test] + fn the_digest_covers_every_monitored_board() { + let (first, second) = (board_dir(), board_dir()); + let projects = vec![project_at(&first), project_at(&second)]; + let before = digest_of(&projects); + + write_ticket(&second, "backlog", "11111111-0000-4000-8000-000000000000", "Alpha", ""); + assert_ne!(before, digest_of(&projects), "the second board went unwatched"); + } + + #[test] + fn a_tick_picks_up_a_ticket_added_to_the_second_board() { + let (first, second) = (board_dir(), board_dir()); + let mut board = boards(&[("alpha", &first), ("beta", &second)]); + assert!(!render(&board, 120, 20).join("\n").contains("Late one")); + + write_ticket(&second, "backlog", "11111111-0000-4000-8000-000000000000", "Late one", ""); + + assert!(board.tick().unwrap(), "the tick saw no change"); + let screen = render(&board, 120, 20).join("\n"); + assert!(screen.contains("Late one"), "{screen}"); + } + + /// Each tab keeps its own place. Sharing one column and card index across projects + /// would land the selection on whatever unrelated ticket sits at the same spot. + #[test] + fn each_tab_keeps_its_own_selection() { + let (first, second) = (board_dir(), board_dir()); + write_ticket(&first, "backlog", "11111111-0000-4000-8000-000000000000", "Alpha", ""); + write_ticket(&first, "committed", "22222222-0000-4000-8000-000000000000", "Beta", ""); + write_ticket(&second, "backlog", "33333333-0000-4000-8000-000000000000", "Gamma", ""); + + let mut board = boards(&[("alpha", &first), ("beta", &second)]); + + // On alpha's tab, move to its committed column. + board.select_tab(1, SCREEN); + board.select_column(1, SCREEN); + assert_eq!(selected_title(&board), Some("Beta".to_string())); + + // beta has nothing in committed, so its own tab opens where it was left. + board.select_tab(1, SCREEN); + assert_eq!(board.current().name, "beta"); + assert_eq!(board.current().column, 0); + assert_eq!(selected_title(&board), Some("Gamma".to_string())); + + // And alpha is where it was, not reset by having been left. + board.select_tab(-1, SCREEN); + assert_eq!(board.current().column, 1); + assert_eq!(selected_title(&board), Some("Beta".to_string())); + } + + /// Tabs cycle, which is what a row of tabs does everywhere else, and there is no + /// end of a list to run off. + #[test] + fn the_tabs_cycle_at_both_ends() { + let (first, second) = (board_dir(), board_dir()); + let mut board = boards(&[("alpha", &first), ("beta", &second)]); + + board.select_tab(-1, SCREEN); + assert_eq!(board.current().name, "beta", "back from the first tab went nowhere"); + + board.select_tab(1, SCREEN); + assert_eq!(board.current().name, ALL); + } + + /// A single board has no tab to move to, so the key does nothing and the footer does + /// not offer it. + #[test] + fn the_tab_key_and_its_footer_entry_need_more_than_one_board() { + let dir = board_dir(); + let mut single = one_board(&dir); + single.select_tab(1, SCREEN); + assert_eq!(single.tab, 0); + assert!(!footer(&single, 120, 20).contains("tab project")); + + let other = board_dir(); + let board = boards(&[("alpha", &dir), ("beta", &other)]); + let row = footer(&board, 120, 20); + assert!(row.contains("tab project"), "{row}"); + } + + /// Two boards can hold tickets with the same title, so the overlay has to open the + /// one the card came from, and say which project that was. + #[test] + fn the_detail_view_from_the_all_tab_opens_the_right_ticket() { + let (first, second) = (board_dir(), board_dir()); + write_ticket(&first, "backlog", "11111111-0000-4000-8000-000000000000", "Same name", ""); + write_ticket(&second, "backlog", "22222222-0000-4000-8000-000000000000", "Same name", ""); + + let mut board = boards(&[("alpha", &first), ("beta", &second)]); + board.toggle_detail(); + + let detail = board.detail.as_ref().expect("no detail"); + let project = detail.project.clone().expect("no project on the overlay"); + let uuid = match project.as_str() { + "alpha" => "11111111", + _ => "22222222", + }; + assert!( + detail.text.contains(uuid), + "the overlay opened another project's ticket: {project} {:?}", + detail.text + ); + + let screen = render(&board, SCREEN.width, SCREEN.height); + let row = overlay_title_row(&screen, SCREEN.width, SCREEN.height); + assert!(row.contains(&project), "the border does not say which project:\n{row}"); + + // The next card down is the other project's, and the modal follows it. + board.select_card(1, SCREEN); + let moved = board.detail.as_ref().expect("no detail"); + assert_ne!(moved.project, Some(project), "the modal stayed on one project"); + assert!(!moved.text.contains(uuid), "{:?}", moved.text); + } + /// The board and the listing draw from the same palette, so a colour cannot exist /// for one and not the other. The enum makes that a compile error; this pins the /// mapping itself. diff --git a/src/util.rs b/src/util.rs index 7c97e1b..59b2819 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1169,6 +1169,10 @@ pub struct Progress { pub total: usize, } +/// `Clone` because the board's All tab holds the same ticket twice: once under its +/// own project's tab and once in the merge across projects. Re-reading the file for +/// the second copy would scan every tree twice on every tick that changed anything. +#[derive(Clone)] pub struct TicketItem { pub title: String, pub owner: String, @@ -1338,16 +1342,22 @@ pub fn collect_ticket_items(status_path: impl AsRef) -> Result std::cmp::Ordering { + a.priority + .rank() + .cmp(&b.priority.rank()) + .then_with(|| a.title.to_lowercase().cmp(&b.title.to_lowercase())) +} + #[cfg(test)] mod tests { use super::*; diff --git a/tests/cmd_tui.rs b/tests/cmd_tui.rs index a6db4f4..48a04fc 100644 --- a/tests/cmd_tui.rs +++ b/tests/cmd_tui.rs @@ -13,6 +13,20 @@ fn setup_worklane(temp: &TempDir) { } } +/// A project inside the temp directory, for the path arguments. The temp directory +/// itself is left without a board, so a path that resolves has to resolve to this one. +fn setup_project(temp: &TempDir, name: &str) -> std::path::PathBuf { + let project = temp.child(name); + let worklane = project.child(".worklane"); + worklane.create_dir_all().unwrap(); + + for dir in ["backlog", "committed", "reviewing", "done"] { + worklane.child(dir).create_dir_all().unwrap(); + } + + project.path().to_path_buf() +} + fn run(temp: &TempDir, args: &[&str]) -> std::process::Output { let mut cmd = Command::cargo_bin(BIN_NAME).unwrap(); cmd.current_dir(temp.path()).args(args); @@ -69,6 +83,60 @@ fn an_unknown_subcommand_is_still_a_usage_error() { assert_eq!(run(&temp, &["--bogus"]).status.code(), Some(2)); } +/// A path argument is resolved before the terminal is, the same way the working +/// directory is: reaching the tty complaint is what says the board was found. +#[test] +fn a_path_argument_names_the_board_to_open() { + let temp = TempDir::new().unwrap(); + let project = setup_project(&temp, "project"); + + // Run from a directory with no board of its own, so only the argument can find one. + let out = run(&temp, &["tui", project.to_str().unwrap()]); + let stderr = String::from_utf8_lossy(&out.stderr); + + assert_eq!(out.status.code(), Some(1), "{stderr:?}"); + assert!(stderr.contains("needs a terminal"), "{stderr:?}"); +} + +/// And several of them, which is the point of taking paths at all. +#[test] +fn several_path_arguments_are_accepted() { + let temp = TempDir::new().unwrap(); + let first = setup_project(&temp, "first"); + let second = setup_project(&temp, "second"); + + let out = run( + &temp, + &["tui", first.to_str().unwrap(), second.to_str().unwrap()], + ); + let stderr = String::from_utf8_lossy(&out.stderr); + + assert_eq!(out.status.code(), Some(1), "{stderr:?}"); + assert!(stderr.contains("needs a terminal"), "{stderr:?}"); +} + +/// With several paths, "No .worklane directory found" does not say which one was wrong. +#[test] +fn a_path_with_no_board_is_named_in_the_failure() { + let temp = TempDir::new().unwrap(); + let project = setup_project(&temp, "project"); + + let elsewhere = temp.child("elsewhere"); + elsewhere.create_dir_all().unwrap(); + let path = elsewhere.path().to_str().unwrap().to_string(); + + // The first path resolves, the second does not. + let out = run(&temp, &["tui", project.to_str().unwrap(), &path]); + let stderr = String::from_utf8_lossy(&out.stderr); + + assert_eq!(out.status.code(), Some(1), "{stderr:?}"); + assert!(stderr.contains(&path), "the failing path is not named: {stderr:?}"); + assert!( + stderr.contains("No .worklane directory found"), + "the usual message is gone: {stderr:?}" + ); +} + /// `tui` has to appear in the help, or nothing points at it. #[test] fn the_help_lists_the_tui_command() {