Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c606b5ba43 | ||
|
|
90b313952b | ||
|
|
7240fc263b | ||
|
|
580e3cf7f0 |
@@ -94,8 +94,16 @@ 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
|
||||
- **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
|
||||
- Read only. Moving a card by keypress is a follow-up, deliberately kept out until the watch and render loop were solid
|
||||
- **A card is four corners with the title between them:** mark and short id top left, due top right, owner bottom left, criteria count bottom right. The two numbers are in corners because that is where the eye goes for one, and both were invisible at the end of a line of prose
|
||||
- The title takes one row or two, wrapped on spaces, with an ellipsis when even two are not enough. One row when one is enough: a second, blank row on every short ticket spends the column's height on nothing
|
||||
- **A card's height therefore depends on the column's width**, so `card_lines` and `card_height` both take it. `column_areas` is shared between the draw and `follow_selection` for the same reason: `Ratio` hands the remainder column to whichever slot it likes, and reproducing that arithmetic by hand is how the measurement and the draw come to disagree about where a card starts
|
||||
- **A corner that will not fit is dropped whole**, never truncated or wrapped: half a date reads as a different date, and a card that reflows in a narrow column changes height, which the scroll would then have to chase. The left corner is the ticket's identity and always stays
|
||||
- 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
|
||||
- `due_date` cuts a due value back to its date only when it has one. The field is not validated (daa0e79), so it can hold a time or free text, and taking the first word regardless would turn "next friday" into "next"
|
||||
- **Done is hidden until `d` asks for it.** Not a new opinion: `ls` already counts done in its summary and leaves it out of the listing. Done only grows, so a quarter of the width was going to the column least often read. The footer carries its count while it is hidden, which is the board's version of that summary line
|
||||
- **Hiding is a change to what is drawn, never to what is read.** `reload` still scans the done directory and `digest` still watches it, so the footer count is right and revealing the column needs no rescan. Do not "optimise" that into a conditional scan
|
||||
- `visible()` returns a prefix of `columns`, not a filter, which is what keeps `column` and `offsets` valid as indices into either. It is derived from where `DONE` actually sits rather than assuming the last slot, and `the_done_column_is_last` pins the assumption. A status inserted after done would otherwise hide two columns in silence
|
||||
@@ -115,6 +123,9 @@ and this file is for what someone changing worklane's own code needs.
|
||||
|
||||
### Color and Output
|
||||
- Use `color_text()` for coloured output — it respects `should_use_colors()` (terminal detection), and `paint()` is the same with the decision passed in
|
||||
- **`color_text()` is for the CLI's own printing only. Anything reachable from `content_trim` takes the decision as an argument and calls `paint()`**, because the board renders with colour off and an escape sequence in a ratatui paragraph is drawn as literal bytes. `nothing_the_body_renders_asks_the_terminal_for_the_colour_decision` scans this file and fails on a new caller; the allowlist is `ambiguous`, which builds a failed-search message for stderr
|
||||
- A function that takes an `enabled` flag must use it all the way down. `colorize_bold` honoured its flag on the early return and then asked `should_use_colors()` for the bold run, which made the flag a lie in half the function
|
||||
- **A test that asserts an absence has to be paired with one that asserts the presence.** The guard for this, an assert that the detail view holds no escape byte, could not fail: a test binary has no tty, so `should_use_colors()` was false and the leaking branch was never taken. The pair is now `content_trim(.., false)` has no escape and `content_trim(.., true)` still colours, which pins the flag as the only thing that decides
|
||||
- **The palette is the `Color` enum, not a string.** `Color::ansi()` gives the CLI its SGR sequence and `From<Color> for ratatui::style::Color` gives the TUI its equivalent, so a colour that exists for one renderer and not the other is a compile error. The stringly-typed version needed a test for exactly that, and a missing entry silently produced an empty prefix, which is how `magenta` came to be undefined
|
||||
- Reset color with `\x1b[0m` after colored text
|
||||
- Bold uses `\x1b[1;35m` (magenta bold)
|
||||
@@ -131,7 +142,7 @@ and this file is for what someone changing worklane's own code needs.
|
||||
- Grey is indexed colour 8 in the 256-colour form, not SGR 90 or 37. Both of those failed on a real palette: 90 leans on the bright-black slot and 37 can sit on top of the default foreground. `\x1b[38;5;8m` is byte for byte what crossterm emits for ratatui's `Color::DarkGray`, the grey frig and pantop use for dimmed rows
|
||||
|
||||
### Code Organization
|
||||
- Colorization functions (`colorize_line`, `colorize_ordered`, `content_trim_colored`) handle markdown formatting
|
||||
- Colorization functions (`colorize_ordered`, `colorize_bold`, `content_trim_colored`) handle markdown formatting. `colorize_line` is gone: it was a `pub` alias for `colorize_bold` with one caller, and the only thing it added was asking the terminal
|
||||
- `show` renders the Metadata section as a two column table via `render_metadata_table`, not line by line. Column width is measured on the raw field names in characters and padding is applied before anything is styled: measuring a coloured string counts its escapes towards its width. `paint()` is `color_text()` with the colour decision passed in, which is what lets a test render both ways in one process
|
||||
- The title is printed once, by `cmd_show`. `content_trim_colored` skips the `# ` heading in the file content
|
||||
- Rules under headings are measured on the displayed name in characters, never on the raw line or in bytes
|
||||
|
||||
Generated
+1
-1
@@ -1494,7 +1494,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "worklane"
|
||||
version = "0.8.2"
|
||||
version = "0.8.5"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"assert_cmd",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "worklane"
|
||||
version = "0.8.2"
|
||||
version = "0.8.5"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
||||
+546
-58
@@ -30,6 +30,19 @@ pub struct Column {
|
||||
pub tickets: Vec<TicketItem>,
|
||||
}
|
||||
|
||||
/// What the detail view holds while it is open: the ticket it belongs to, then its
|
||||
/// body and comments as one plain text.
|
||||
///
|
||||
/// The title travels beside the text rather than inside it, because it does not
|
||||
/// scroll: it names the overlay from the border, where no amount of reading can
|
||||
/// carry it off the screen.
|
||||
#[derive(Debug)]
|
||||
pub struct Detail {
|
||||
pub title: String,
|
||||
pub id: String,
|
||||
pub text: String,
|
||||
}
|
||||
|
||||
/// What is on screen.
|
||||
pub struct Board {
|
||||
pub columns: Vec<Column>,
|
||||
@@ -38,8 +51,8 @@ pub struct Board {
|
||||
/// 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<u16>,
|
||||
/// The body and comments of the selected ticket, when the detail view is open.
|
||||
pub detail: Option<String>,
|
||||
/// The open detail view, when one is open.
|
||||
pub detail: Option<Detail>,
|
||||
/// 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
|
||||
@@ -226,6 +239,10 @@ 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);
|
||||
|
||||
let Some(column) = self.columns.get(self.column) else {
|
||||
return;
|
||||
};
|
||||
@@ -233,18 +250,15 @@ impl Board {
|
||||
return;
|
||||
};
|
||||
|
||||
let height = |ticket: &TicketItem| card_height(ticket, width);
|
||||
|
||||
let start: u16 = column
|
||||
.tickets
|
||||
.get(..self.card)
|
||||
.map(|before| before.iter().map(card_height).sum())
|
||||
.map(|before| before.iter().map(height).sum())
|
||||
.unwrap_or(0);
|
||||
let end = start
|
||||
+ column
|
||||
.tickets
|
||||
.get(self.card)
|
||||
.map(card_height)
|
||||
.unwrap_or(0);
|
||||
let total: u16 = column.tickets.iter().map(card_height).sum();
|
||||
let end = start + column.tickets.get(self.card).map(height).unwrap_or(0);
|
||||
let total: u16 = column.tickets.iter().map(height).sum();
|
||||
|
||||
*slot = aligned_offset(*slot, start, end, column_text_height(screen), total);
|
||||
}
|
||||
@@ -274,7 +288,7 @@ impl Board {
|
||||
let text = detail_text_area(Rect::new(0, 0, screen.width, screen.height));
|
||||
// A screenful less a line, so the eye has something to land on after the jump.
|
||||
let step = text.height.saturating_sub(1).max(1) as isize;
|
||||
let last = last_offset(detail, text) as isize;
|
||||
let last = last_offset(&detail.text, text) as isize;
|
||||
|
||||
self.offset = (self.offset as isize + pages.saturating_mul(step)).clamp(0, last) as u16;
|
||||
}
|
||||
@@ -289,11 +303,12 @@ impl Board {
|
||||
}
|
||||
}
|
||||
|
||||
/// The whole ticket as plain text: the body as `show` renders it, then the comments.
|
||||
/// The ticket as the detail view holds it: its name and short id, then the body as
|
||||
/// `show` renders it and the comments.
|
||||
///
|
||||
/// 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) -> String {
|
||||
fn detail_of(ticket: &TicketItem) -> Detail {
|
||||
let content = std::fs::read_to_string(&ticket.path).unwrap_or_default();
|
||||
let mut out = content_trim(&content, false);
|
||||
|
||||
@@ -307,7 +322,11 @@ fn detail_of(ticket: &TicketItem) -> String {
|
||||
|
||||
out.push('\n');
|
||||
out.push_str(&format_comments_with(&comments, false));
|
||||
out
|
||||
Detail {
|
||||
title: ticket.title.clone(),
|
||||
id: ticket.id.clone(),
|
||||
text: out,
|
||||
}
|
||||
}
|
||||
|
||||
/// A fingerprint of every ticket and comment file: name, length and modified time.
|
||||
@@ -382,15 +401,7 @@ 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.
|
||||
let columns = board.visible();
|
||||
let widths: Vec<Constraint> = columns
|
||||
.iter()
|
||||
.map(|_| Constraint::Ratio(1, columns.len().max(1) as u32))
|
||||
.collect();
|
||||
|
||||
let areas = Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.constraints(widths)
|
||||
.split(area);
|
||||
let areas = column_areas(area, columns.len());
|
||||
|
||||
for (index, column) in columns.iter().enumerate() {
|
||||
let focused = index == board.column;
|
||||
@@ -417,15 +428,15 @@ fn draw_columns(frame: &mut Frame, board: &Board, area: Rect) {
|
||||
// The cards go into one paragraph, and where each card starts is recorded as
|
||||
// it is added: the scroll has to measure what is really drawn, not assume a
|
||||
// card size the renderer has to agree with.
|
||||
let text = areas[index].inner(Margin::new(1, 1));
|
||||
let mut lines: Vec<Line> = Vec::new();
|
||||
let mut starts: Vec<u16> = Vec::new();
|
||||
for (card, ticket) in column.tickets.iter().enumerate() {
|
||||
let selected = focused && card == board.card;
|
||||
starts.push(lines.len() as u16);
|
||||
lines.extend(card_lines(ticket, selected));
|
||||
lines.extend(card_lines(ticket, selected, text.width));
|
||||
}
|
||||
let total = lines.len() as u16;
|
||||
let text = areas[index].inner(Margin::new(1, 1));
|
||||
let stored = board.offsets.get(index).copied().unwrap_or(0);
|
||||
|
||||
// The focused column follows its selection here as well as on the keypress:
|
||||
@@ -452,8 +463,39 @@ fn draw_columns(frame: &mut Frame, board: &Board, area: Rect) {
|
||||
}
|
||||
|
||||
/// The lines one card occupies, measured the way `draw_columns` renders it.
|
||||
fn card_height(ticket: &TicketItem) -> u16 {
|
||||
card_lines(ticket, false).len() as u16
|
||||
///
|
||||
/// 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
|
||||
}
|
||||
|
||||
/// The rectangles the columns are drawn in, from one place.
|
||||
///
|
||||
/// Shared with the measurement in `follow_selection`, so the width a card lays itself
|
||||
/// out in is the width it is drawn in. `Ratio` leaves a remainder column to whichever
|
||||
/// slot ratatui gives it, and guessing that arithmetic by hand is how the two come to
|
||||
/// disagree about where a card starts.
|
||||
fn column_areas(area: Rect, count: usize) -> std::rc::Rc<[Rect]> {
|
||||
let widths: Vec<Constraint> = (0..count)
|
||||
.map(|_| Constraint::Ratio(1, count.max(1) as u32))
|
||||
.collect();
|
||||
|
||||
Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.constraints(widths)
|
||||
.split(area)
|
||||
}
|
||||
|
||||
/// 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)
|
||||
.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.
|
||||
@@ -483,8 +525,20 @@ fn aligned_offset(offset: u16, start: u16, end: u16, inner: u16, total: u16) ->
|
||||
offset.min(total.saturating_sub(inner))
|
||||
}
|
||||
|
||||
/// One card: the priority mark and short id, the title, then owner and due.
|
||||
fn card_lines(ticket: &TicketItem, selected: bool) -> Vec<Line<'static>> {
|
||||
/// One card as four corners with the title between them:
|
||||
///
|
||||
/// ```text
|
||||
/// ●◐ (1b78a24) 2026-12-31
|
||||
/// The tui detail view cannot
|
||||
/// scroll, and the footer says…
|
||||
/// Ansho Rei [3/9]
|
||||
/// ```
|
||||
///
|
||||
/// The due date and the criteria count are on the right because a corner is where the
|
||||
/// 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<Line<'static>> {
|
||||
let (glyph, colour) = priority_mark(ticket.priority);
|
||||
let emphasis = if selected {
|
||||
Modifier::REVERSED
|
||||
@@ -492,8 +546,8 @@ fn card_lines(ticket: &TicketItem, selected: bool) -> Vec<Line<'static>> {
|
||||
Modifier::empty()
|
||||
};
|
||||
|
||||
vec![
|
||||
Line::from(vec![
|
||||
let mut lines = vec![corner_line(
|
||||
vec![
|
||||
Span::styled(
|
||||
glyph.to_string(),
|
||||
Style::default().fg(colour.into()).add_modifier(emphasis),
|
||||
@@ -501,21 +555,154 @@ fn card_lines(ticket: &TicketItem, selected: bool) -> Vec<Line<'static>> {
|
||||
Span::raw(" "),
|
||||
Span::styled(
|
||||
format!("({})", ticket.id),
|
||||
Style::default()
|
||||
.fg(Color::Red.into())
|
||||
.add_modifier(emphasis),
|
||||
Style::default().fg(Color::Red.into()).add_modifier(emphasis),
|
||||
),
|
||||
]),
|
||||
],
|
||||
due_span(&ticket.due),
|
||||
width,
|
||||
)];
|
||||
|
||||
lines.extend(title_lines(&ticket.title, width).into_iter().map(|line| {
|
||||
Line::from(Span::styled(
|
||||
ticket.title.clone(),
|
||||
line,
|
||||
Style::default().add_modifier(emphasis),
|
||||
)),
|
||||
Line::from(Span::styled(
|
||||
format!("{} · {}", ticket.owner, ticket.due),
|
||||
))
|
||||
}));
|
||||
|
||||
lines.push(corner_line(
|
||||
vec![Span::styled(
|
||||
ticket.owner.clone(),
|
||||
Style::default().fg(Color::Grey.into()),
|
||||
)),
|
||||
Line::from(""),
|
||||
]
|
||||
)],
|
||||
ticket.criteria.map(|progress| {
|
||||
Span::styled(
|
||||
format!("[{}/{}]", progress.met, progress.total),
|
||||
Style::default().fg(Color::Grey.into()),
|
||||
)
|
||||
}),
|
||||
width,
|
||||
));
|
||||
lines.push(Line::from(""));
|
||||
|
||||
lines
|
||||
}
|
||||
|
||||
/// 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
|
||||
/// corner has no room to spare on one.
|
||||
fn due_span(due: &str) -> Option<Span<'static>> {
|
||||
let colour = match is_unknown_value(due) {
|
||||
true => Color::Grey,
|
||||
false => Color::Cyan,
|
||||
};
|
||||
|
||||
Some(Span::styled(
|
||||
due_date(due).to_string(),
|
||||
Style::default().fg(colour.into()),
|
||||
))
|
||||
}
|
||||
|
||||
/// `left` at the left, `right` at the right, with the gap between them.
|
||||
///
|
||||
/// The right-hand corner is dropped whole when it will not fit rather than truncated or
|
||||
/// wrapped: half a date reads as a different date, and a card that reflows in a narrow
|
||||
/// column changes height, which the scroll would then have to chase. The left corner is
|
||||
/// the ticket's identity and always stays.
|
||||
fn corner_line(
|
||||
left: Vec<Span<'static>>,
|
||||
right: Option<Span<'static>>,
|
||||
width: u16,
|
||||
) -> Line<'static> {
|
||||
let mut spans = left;
|
||||
let used: usize = spans.iter().map(|span| span.content.chars().count()).sum();
|
||||
|
||||
let Some(right) = right else {
|
||||
return Line::from(spans);
|
||||
};
|
||||
|
||||
let wanted = right.content.chars().count();
|
||||
// One space minimum, so the two corners never touch. No room at all and the right
|
||||
// corner goes rather than the line growing past the column.
|
||||
if let Some(gap) = (width as usize).checked_sub(used + wanted + 1) {
|
||||
spans.push(Span::raw(" ".repeat(gap + 1)));
|
||||
spans.push(right);
|
||||
}
|
||||
|
||||
Line::from(spans)
|
||||
}
|
||||
|
||||
/// The title over one row or two, wrapped on spaces, cut with an ellipsis if even two
|
||||
/// are not enough.
|
||||
///
|
||||
/// One row when one is enough: a second, blank row on every short ticket would spend
|
||||
/// the column's height on nothing. A word longer than the column is broken rather than
|
||||
/// left to overflow, since a uuid or a path has no space to break at.
|
||||
fn title_lines(title: &str, width: u16) -> Vec<String> {
|
||||
let width = width.max(1) as usize;
|
||||
let mut rows: Vec<String> = Vec::new();
|
||||
let mut row = String::new();
|
||||
|
||||
for word in title.split_whitespace() {
|
||||
let room = width - row.chars().count().min(width);
|
||||
let space = usize::from(!row.is_empty());
|
||||
|
||||
if word.chars().count() + space <= room {
|
||||
if space == 1 {
|
||||
row.push(' ');
|
||||
}
|
||||
row.push_str(word);
|
||||
continue;
|
||||
}
|
||||
|
||||
if !row.is_empty() {
|
||||
rows.push(std::mem::take(&mut row));
|
||||
}
|
||||
// A word too long for a row of its own is broken across rows.
|
||||
for chunk in chars_in_chunks(word, width) {
|
||||
if row.chars().count() + chunk.chars().count() > width {
|
||||
rows.push(std::mem::take(&mut row));
|
||||
}
|
||||
row.push_str(&chunk);
|
||||
}
|
||||
}
|
||||
if !row.is_empty() {
|
||||
rows.push(row);
|
||||
}
|
||||
|
||||
if rows.len() > 2 {
|
||||
rows.truncate(2);
|
||||
rows[1] = with_ellipsis(&rows[1], width);
|
||||
}
|
||||
if rows.is_empty() {
|
||||
rows.push(String::new());
|
||||
}
|
||||
|
||||
rows
|
||||
}
|
||||
|
||||
fn chars_in_chunks(word: &str, width: usize) -> Vec<String> {
|
||||
let chars: Vec<char> = word.chars().collect();
|
||||
chars
|
||||
.chunks(width)
|
||||
.map(|chunk| chunk.iter().collect())
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The row with an ellipsis on the end, making room for it if the row is full.
|
||||
fn with_ellipsis(row: &str, width: usize) -> String {
|
||||
let keep = match row.chars().count() < width {
|
||||
true => row.chars().count(),
|
||||
false => width.saturating_sub(1),
|
||||
};
|
||||
|
||||
let mut cut: String = row.chars().take(keep).collect();
|
||||
// Trailing space before an ellipsis reads as a gap rather than a cut.
|
||||
while cut.ends_with(' ') {
|
||||
cut.pop();
|
||||
}
|
||||
cut.push('…');
|
||||
cut
|
||||
}
|
||||
|
||||
fn draw_footer(frame: &mut Frame, board: &Board, area: Rect) {
|
||||
@@ -581,24 +768,24 @@ fn last_offset(detail: &str, text: Rect) -> u16 {
|
||||
.saturating_sub(text.height)
|
||||
}
|
||||
|
||||
fn draw_detail(frame: &mut Frame, detail: &str, offset: u16, area: Rect) {
|
||||
fn draw_detail(frame: &mut Frame, detail: &Detail, offset: u16, area: Rect) {
|
||||
let overlay = detail_overlay(area);
|
||||
|
||||
// Clamped here as well as on the keypress: the terminal may have been resized since,
|
||||
// and a ticket read to its end can grow shorter under a tick.
|
||||
let offset = offset.min(last_offset(detail, detail_text_area(area)));
|
||||
let offset = offset.min(last_offset(&detail.text, detail_text_area(area)));
|
||||
|
||||
let block = Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_style(Style::default().fg(Color::Cyan.into()))
|
||||
.title(Span::styled(
|
||||
" ticket ",
|
||||
detail_title(detail, overlay.width),
|
||||
Style::default().fg(Color::Orange.into()),
|
||||
));
|
||||
|
||||
frame.render_widget(Clear, overlay);
|
||||
frame.render_widget(
|
||||
Paragraph::new(detail.to_string())
|
||||
Paragraph::new(detail.text.to_string())
|
||||
.block(block)
|
||||
.wrap(Wrap { trim: false })
|
||||
.scroll((offset, 0)),
|
||||
@@ -606,6 +793,35 @@ fn draw_detail(frame: &mut Frame, detail: &str, offset: u16, area: Rect) {
|
||||
);
|
||||
}
|
||||
|
||||
/// The overlay's title: the short id and the name of the ticket it has open.
|
||||
///
|
||||
/// The id goes first because that is how every other view addresses a ticket, and the
|
||||
/// name after it because that is what the id is shorthand for. Both sit on the border
|
||||
/// rather than at the head of the paragraph, so reading to the end of a long ticket
|
||||
/// cannot carry them off the screen.
|
||||
///
|
||||
/// The string is cut here rather than left to the renderer, which truncates an
|
||||
/// overlong title at whatever cell it reaches and would take the id with it. Cut
|
||||
/// against the inner width — a border column on either side is not the title's to
|
||||
/// 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 {
|
||||
let room = overlay_width.saturating_sub(2) as usize;
|
||||
let full = format!(" ({}) · {} ", detail.id, detail.title);
|
||||
if full.chars().count() <= room {
|
||||
return full;
|
||||
}
|
||||
|
||||
let prefix = format!(" ({}) · ", detail.id);
|
||||
match room.checked_sub(prefix.chars().count() + 1) {
|
||||
Some(keep) if keep > 0 => {
|
||||
let name: String = detail.title.chars().take(keep).collect();
|
||||
format!("{prefix}{name}…")
|
||||
}
|
||||
_ => full.chars().take(room).collect(),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -680,6 +896,18 @@ mod tests {
|
||||
render(board, width, height).pop().expect("no rows rendered")
|
||||
}
|
||||
|
||||
/// The overlay's top border row, where the block title sits.
|
||||
///
|
||||
/// Counted in characters rather than bytes: the rows carry multi-byte glyphs.
|
||||
fn overlay_title_row(lines: &[String], width: u16, height: u16) -> String {
|
||||
let overlay = detail_overlay(Rect::new(0, 0, width, height));
|
||||
lines[overlay.y as usize]
|
||||
.chars()
|
||||
.skip(overlay.x as usize)
|
||||
.take(overlay.width as usize)
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_board_draws_the_four_statuses_as_columns_once_done_is_shown() {
|
||||
let dir = board_dir();
|
||||
@@ -877,6 +1105,175 @@ mod tests {
|
||||
assert!(screen.contains("2026-12-31"), "no due date in:\n{screen}");
|
||||
}
|
||||
|
||||
/// One ticket in backlog, written by hand so a test can set the fields the shared
|
||||
/// fixture pins: the due value, and the criteria.
|
||||
fn write_card(dir: &Path, title: &str, due: &str, criteria: &str) {
|
||||
let uuid = "11111111-0000-4000-8000-000000000000";
|
||||
std::fs::write(
|
||||
dir.join("backlog").join(format!("{}_{}.md", uuid, slug(title))),
|
||||
format!(
|
||||
"# {title}\n\n## Description\nA description.\n\n## Acceptance Criteria\n\
|
||||
{criteria}\n\n## Metadata\n\n- **ID**: {uuid}\n- **Priority**: 2\n\
|
||||
- **Tags**: _None_\n- **Due**: {due}\n- **Owner**: alice\n\
|
||||
- **Created At**: 2026-08-21 02:00:00\n- **Status**: backlog\n"
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
/// 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<String> {
|
||||
let board = Board::new(dir).unwrap();
|
||||
let inner = card_width(Size { width, height }, board.visible().len(), 0);
|
||||
let ticket = board.selected().expect("no card");
|
||||
card_lines(ticket, false, inner)
|
||||
.iter()
|
||||
.map(|line| line.spans.iter().map(|span| span.content.as_ref()).collect())
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// 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<ratatui::style::Color> {
|
||||
let board = Board::new(dir).unwrap();
|
||||
let inner = card_width(Size { width, height: 20 }, board.visible().len(), 0);
|
||||
let ticket = board.selected().expect("no card");
|
||||
|
||||
card_lines(ticket, false, inner)
|
||||
.iter()
|
||||
.flat_map(|line| line.spans.clone())
|
||||
.find(|span| span.content == needle)
|
||||
.and_then(|span| span.style.fg)
|
||||
}
|
||||
|
||||
/// worklane's own titles are routinely longer than a quarter of a terminal, and one
|
||||
/// row cut them mid-word with nothing to say so.
|
||||
#[test]
|
||||
fn a_long_title_takes_two_rows_and_is_cut_visibly() {
|
||||
let dir = board_dir();
|
||||
// Three rows' worth at the width three columns give a 120 wide terminal, so the
|
||||
// second row has to end in a cut rather than the title simply fitting.
|
||||
write_card(
|
||||
&dir,
|
||||
"A title long enough to need a second row, and then a third one after that, \
|
||||
which is where it has to give up",
|
||||
"2026-12-31",
|
||||
"- [ ] One",
|
||||
);
|
||||
|
||||
let rows = only_card(&dir, 120, 20);
|
||||
let inner = card_width(Size { width: 120, height: 20 }, 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:?}");
|
||||
// Wrapped on a space, not cut mid-word, where there was room to choose.
|
||||
assert!(!rows[1].ends_with('…'), "the first row was cut: {rows:?}");
|
||||
assert!(rows[2].ends_with('…'), "the cut is invisible: {rows:?}");
|
||||
for row in &rows {
|
||||
assert!(row.chars().count() <= inner, "row past the column: {row:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// And a title that fits gets one row, or the second is wasted on every short
|
||||
/// ticket in the column.
|
||||
#[test]
|
||||
fn a_short_title_leaves_the_card_four_rows() {
|
||||
let dir = board_dir();
|
||||
write_card(&dir, "Short", "2026-12-31", "- [ ] One");
|
||||
|
||||
let rows = only_card(&dir, 120, 20);
|
||||
assert_eq!(rows.len(), 4, "{rows:?}");
|
||||
assert_eq!(rows[1], "Short");
|
||||
}
|
||||
|
||||
/// The corners: id and due on top, owner and progress at the bottom.
|
||||
#[test]
|
||||
fn the_due_date_and_the_criteria_count_sit_on_the_right() {
|
||||
let dir = board_dir();
|
||||
write_card(&dir, "Short", "2026-12-31", "- [x] One\n- [ ] Two\n- [ ] Three");
|
||||
|
||||
let rows = only_card(&dir, 120, 20);
|
||||
assert!(rows[0].starts_with("\u{25cf}\u{25d0} (1111111)"), "{rows:?}");
|
||||
assert!(rows[0].ends_with("2026-12-31"), "the due is not on the right: {rows:?}");
|
||||
assert!(rows[2].starts_with("alice"), "{rows:?}");
|
||||
assert!(rows[2].ends_with("[1/3]"), "the count is not on the right: {rows:?}");
|
||||
}
|
||||
|
||||
/// The field is not validated, so it can hold a time. A corner has no room for one.
|
||||
#[test]
|
||||
fn a_due_with_a_time_shows_the_date_only() {
|
||||
let dir = board_dir();
|
||||
write_card(&dir, "Short", "2026-12-31 09:30:00", "- [ ] One");
|
||||
|
||||
let rows = only_card(&dir, 120, 20);
|
||||
assert!(rows[0].ends_with("2026-12-31"), "{rows:?}");
|
||||
assert!(!rows[0].contains("09:30"), "the time reached the card: {rows:?}");
|
||||
}
|
||||
|
||||
/// Greyed like everywhere else, rather than left as an empty corner. The set case is
|
||||
/// the timestamp colour, which is what makes the corner worth looking at.
|
||||
#[test]
|
||||
fn an_unset_due_is_dimmed_and_a_set_one_carries_the_timestamp_colour() {
|
||||
let dir = board_dir();
|
||||
write_card(&dir, "Short", "_Not set_", "- [ ] One");
|
||||
assert_eq!(
|
||||
card_colour(&dir, 120, "_Not set_"),
|
||||
Some(Color::Grey.into()),
|
||||
"an unset due is not dimmed"
|
||||
);
|
||||
|
||||
let dir = board_dir();
|
||||
write_card(&dir, "Short", "2026-12-31", "- [ ] One");
|
||||
assert_eq!(card_colour(&dir, 120, "2026-12-31"), Some(Color::Cyan.into()));
|
||||
}
|
||||
|
||||
/// `[0/0]` says less than saying nothing.
|
||||
#[test]
|
||||
fn a_ticket_with_no_criteria_shows_no_count() {
|
||||
let dir = board_dir();
|
||||
write_card(&dir, "Short", "2026-12-31", "_No acceptance criteria provided._");
|
||||
|
||||
let rows = only_card(&dir, 120, 20);
|
||||
assert_eq!(rows[2], "alice", "a count appeared from nowhere: {rows:?}");
|
||||
}
|
||||
|
||||
/// Counted through `criteria()`, so the card and the numbers `show` prints cannot
|
||||
/// disagree: a checkbox in a description is not a criterion in either.
|
||||
#[test]
|
||||
fn a_checkbox_outside_the_criteria_section_is_not_counted() {
|
||||
let dir = board_dir();
|
||||
let uuid = "11111111-0000-4000-8000-000000000000";
|
||||
std::fs::write(
|
||||
dir.join("backlog").join(format!("{uuid}_short.md")),
|
||||
format!(
|
||||
"# Short\n\n## Description\n- [x] not a criterion\n\n## Acceptance Criteria\n\
|
||||
- [x] One\n- [ ] Two\n\n## Metadata\n\n- **ID**: {uuid}\n- **Priority**: 2\n\
|
||||
- **Due**: 2026-12-31\n- **Owner**: alice\n- **Status**: backlog\n"
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let rows = only_card(&dir, 120, 20);
|
||||
assert!(rows[2].ends_with("[1/2]"), "the description was counted: {rows:?}");
|
||||
}
|
||||
|
||||
/// A column too narrow for both corners keeps the identity and drops the rest,
|
||||
/// rather than overflowing the border or reflowing to a taller card.
|
||||
#[test]
|
||||
fn a_narrow_column_drops_the_right_corner() {
|
||||
let dir = board_dir();
|
||||
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;
|
||||
|
||||
assert!(rows[0].starts_with("\u{25cf}\u{25d0} (1111111)"), "{rows:?}");
|
||||
assert!(!rows[0].contains("2026"), "the due overran the column: {rows:?}");
|
||||
for row in &rows {
|
||||
assert!(row.chars().count() <= inner, "row past the column: {row:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// An empty status is a column with nothing in it, not a column that is missing.
|
||||
#[test]
|
||||
fn an_empty_status_renders_as_an_empty_column() {
|
||||
@@ -1229,20 +1626,98 @@ mod tests {
|
||||
assert!(board.detail.is_none());
|
||||
|
||||
board.toggle_detail();
|
||||
let detail = board.detail.clone().expect("no detail");
|
||||
let detail = board.detail.as_ref().expect("no detail");
|
||||
|
||||
assert!(detail.contains("A description."), "{detail}");
|
||||
assert!(detail.contains("Crit one"), "{detail}");
|
||||
assert!(detail.contains("A note from elsewhere."), "{detail}");
|
||||
assert!(detail.contains("bob"), "{detail}");
|
||||
assert!(detail.text.contains("A description."), "{}", detail.text);
|
||||
assert!(detail.text.contains("Crit one"), "{}", detail.text);
|
||||
assert!(detail.text.contains("A note from elsewhere."), "{}", detail.text);
|
||||
assert!(detail.text.contains("bob"), "{}", detail.text);
|
||||
|
||||
// Plain text, since ratatui would print an escape as literal bytes
|
||||
assert!(!detail.contains('\x1b'), "escapes reached the detail view: {detail:?}");
|
||||
assert!(
|
||||
!detail.text.contains('\x1b'),
|
||||
"escapes reached the detail view: {:?}",
|
||||
detail.text
|
||||
);
|
||||
|
||||
board.toggle_detail();
|
||||
assert!(board.detail.is_none());
|
||||
}
|
||||
|
||||
/// The reported bug: the modal showed a description, criteria and a metadata
|
||||
/// table belonging to a ticket it never named.
|
||||
#[test]
|
||||
fn the_detail_view_names_the_ticket_it_has_open() {
|
||||
let dir = board_dir();
|
||||
write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "First one", "");
|
||||
|
||||
let mut board = Board::new(&dir).unwrap();
|
||||
board.toggle_detail();
|
||||
|
||||
let screen = render(&board, SCREEN.width, SCREEN.height);
|
||||
let row = overlay_title_row(&screen, SCREEN.width, SCREEN.height);
|
||||
assert!(row.contains("(1111111)"), "no short id on the border:\n{row}");
|
||||
assert!(row.contains("First one"), "no title on the border:\n{row}");
|
||||
|
||||
// The heading stays out of the text: `show` prints it and here the border
|
||||
// carries it, so it is on screen once rather than twice.
|
||||
assert!(
|
||||
!board.detail.as_ref().unwrap().text.contains("First one"),
|
||||
"{:?}",
|
||||
board.detail
|
||||
);
|
||||
}
|
||||
|
||||
/// Scrolled to the end of a long ticket, the name is still where it started.
|
||||
#[test]
|
||||
fn the_name_stays_on_screen_at_the_end_of_a_long_ticket() {
|
||||
let dir = board_dir();
|
||||
write_ticket(
|
||||
&dir,
|
||||
"backlog",
|
||||
"11111111-0000-4000-8000-000000000000",
|
||||
"First one",
|
||||
&long_section(60),
|
||||
);
|
||||
|
||||
let mut board = Board::new(&dir).unwrap();
|
||||
board.toggle_detail();
|
||||
for _ in 0..20 {
|
||||
board.scroll_detail(1, SCREEN);
|
||||
}
|
||||
|
||||
let screen = render(&board, SCREEN.width, SCREEN.height);
|
||||
assert!(screen.join("\n").contains("Line 060"), "nothing scrolled:\n{}", screen.join("\n"));
|
||||
|
||||
let row = overlay_title_row(&screen, SCREEN.width, SCREEN.height);
|
||||
assert!(row.contains("(1111111)"), "the id scrolled away:\n{row}");
|
||||
assert!(row.contains("First one"), "the title scrolled away:\n{row}");
|
||||
}
|
||||
|
||||
/// A title longer than the overlay is cut to the border — corners intact, id
|
||||
/// whole, ellipsis where the name gave up — not overrun and not dropped whole.
|
||||
#[test]
|
||||
fn a_long_title_is_cut_to_the_border_it_sits_on() {
|
||||
let dir = board_dir();
|
||||
// Long enough to pass the overlay's inner width many times over, short enough
|
||||
// that its slug still fits a filename.
|
||||
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();
|
||||
board.toggle_detail();
|
||||
|
||||
let screen = render(&board, SCREEN.width, SCREEN.height);
|
||||
let row = overlay_title_row(&screen, SCREEN.width, SCREEN.height);
|
||||
|
||||
assert!(row.starts_with('┌'), "the left corner gave way:\n{row}");
|
||||
assert!(row.ends_with('┐'), "the right corner gave way:\n{row}");
|
||||
assert!(row.contains("(1111111)"), "the id did not survive the cut:\n{row}");
|
||||
assert!(row.contains("Head"), "the border was left blank:\n{row}");
|
||||
assert!(row.contains('…'), "the cut read as a complete title:\n{row}");
|
||||
assert!(!row.contains("tailmarker"), "the title overran the border:\n{row}");
|
||||
}
|
||||
|
||||
/// A comment added while the detail view is open shows up on the next tick.
|
||||
#[test]
|
||||
fn a_tick_picks_up_a_comment_added_under_an_open_detail_view() {
|
||||
@@ -1252,7 +1727,7 @@ mod tests {
|
||||
|
||||
let mut board = Board::new(&dir).unwrap();
|
||||
board.toggle_detail();
|
||||
assert!(!board.detail.clone().unwrap().contains("A late note."));
|
||||
assert!(!board.detail.as_ref().unwrap().text.contains("A late note."));
|
||||
|
||||
let comments = dir.join("comments").join(uuid);
|
||||
std::fs::create_dir_all(&comments).unwrap();
|
||||
@@ -1263,7 +1738,11 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
assert!(board.tick().unwrap(), "the tick saw no change");
|
||||
assert!(board.detail.clone().unwrap().contains("A late note."), "{:?}", board.detail);
|
||||
assert!(
|
||||
board.detail.as_ref().unwrap().text.contains("A late note."),
|
||||
"{:?}",
|
||||
board.detail
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1384,13 +1863,21 @@ mod tests {
|
||||
|
||||
let mut board = Board::new(&dir).unwrap();
|
||||
board.toggle_detail();
|
||||
// By id rather than title: the body leaves the title to the caller that prints
|
||||
// the heading, so the detail text does not carry it.
|
||||
assert!(board.detail.clone().unwrap().contains("11111111"), "{:?}", board.detail);
|
||||
// By id in the text: the heading is stripped from the body, and the title
|
||||
// travels beside it for the block title instead.
|
||||
assert!(
|
||||
board.detail.as_ref().unwrap().text.contains("11111111"),
|
||||
"{:?}",
|
||||
board.detail
|
||||
);
|
||||
|
||||
board.select_card(1, SCREEN);
|
||||
assert_eq!(board.selected().map(|t| t.title.clone()), Some("Beta".to_string()));
|
||||
assert!(board.detail.clone().unwrap().contains("22222222"), "{:?}", board.detail);
|
||||
assert!(
|
||||
board.detail.as_ref().unwrap().text.contains("22222222"),
|
||||
"{:?}",
|
||||
board.detail
|
||||
);
|
||||
}
|
||||
|
||||
/// A newly selected ticket starts at its own top, not where the last one was left.
|
||||
@@ -1500,4 +1987,5 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+195
-9
@@ -403,7 +403,7 @@ pub fn content_trim(content: &str, colored: bool) -> String {
|
||||
|
||||
// Implementation Plan - color numbers in cyan
|
||||
if current_section == "## Implementation Plan" {
|
||||
result.push_str(&colorize_ordered(line));
|
||||
result.push_str(&colorize_ordered(line, colored));
|
||||
result.push('\n');
|
||||
continue;
|
||||
}
|
||||
@@ -454,7 +454,13 @@ pub fn content_trim(content: &str, colored: bool) -> String {
|
||||
result
|
||||
}
|
||||
|
||||
pub fn colorize_ordered(line: &str) -> String {
|
||||
/// Colour the `1.` at the head of a numbered line, leaving the rest alone.
|
||||
///
|
||||
/// Takes the decision rather than asking for it. Asking is what put `\x1b[36m` and
|
||||
/// `\x1b[0m` around every Implementation Plan number in the board's detail view,
|
||||
/// which renders with colour off precisely because a paragraph is not a place an
|
||||
/// escape sequence can go.
|
||||
fn colorize_ordered(line: &str, colored: bool) -> String {
|
||||
if line.chars().next().is_none_or(|c| !c.is_ascii_digit()) {
|
||||
return line.to_string();
|
||||
}
|
||||
@@ -468,7 +474,7 @@ pub fn colorize_ordered(line: &str) -> String {
|
||||
// still scanning digits
|
||||
} else if *c == '.' && i + 1 < chars.len() && chars[i + 1] == ' ' {
|
||||
let number = &line[..i + 1];
|
||||
result.push_str(&color_text(number, Color::Cyan));
|
||||
result.push_str(&paint(number, Color::Cyan, colored));
|
||||
result.push_str(&line[i + 1..]);
|
||||
return result;
|
||||
} else {
|
||||
@@ -558,7 +564,10 @@ fn render_metadata_table(lines: &[&str], colored: bool) -> String {
|
||||
result.push_str(METADATA_GUTTER);
|
||||
result.push_str(&metadata_value_cell(name, value, colored));
|
||||
}
|
||||
MetadataRow::Other(text) => result.push_str(&colorize_line(text)),
|
||||
// The decision this row is rendered under, not the one the terminal
|
||||
// would give: `colorize_line` asked `should_use_colors()` here, which is
|
||||
// how escapes reached the board's detail view.
|
||||
MetadataRow::Other(text) => result.push_str(&colorize_bold(text, colored)),
|
||||
}
|
||||
result.push('\n');
|
||||
}
|
||||
@@ -571,10 +580,6 @@ pub fn is_unknown_value(value: &str) -> bool {
|
||||
trimmed == "_None_" || trimmed == "_Not set_" || trimmed == "-None-" || trimmed == "-Not set-"
|
||||
}
|
||||
|
||||
pub fn colorize_line(line: &str) -> String {
|
||||
colorize_bold(line, should_use_colors())
|
||||
}
|
||||
|
||||
/// Replace `**bold**` with colour, or leave the line exactly as it is.
|
||||
///
|
||||
/// Taking `enabled` rather than asking makes both paths testable, and the
|
||||
@@ -600,7 +605,9 @@ fn colorize_bold(line: &str, enabled: bool) -> String {
|
||||
match (i + 2..chars.len()).find(|&at| is_delimiter(&chars, at)) {
|
||||
Some(close) => {
|
||||
let bold: String = chars[i + 2..close].iter().collect();
|
||||
result.push_str(&color_text(&bold, Color::Magenta));
|
||||
// `enabled`, not `should_use_colors()`. Asking again here made the
|
||||
// flag a lie: the early return above respected it and this did not.
|
||||
result.push_str(&paint(&bold, Color::Magenta, enabled));
|
||||
i = close + 2;
|
||||
}
|
||||
// Unterminated: the rest is literal. The old scan walked off the end
|
||||
@@ -1152,6 +1159,16 @@ pub fn parse_priority(content: &str) -> Priority {
|
||||
priority_from_value(&parse_ticket_field(content, "Priority"))
|
||||
}
|
||||
|
||||
/// How far along a ticket is: criteria ticked against criteria written.
|
||||
///
|
||||
/// `total` is never zero. A ticket with no criteria has no progress to show, and a card
|
||||
/// reading `[0/0]` says less than a card saying nothing, so the absence is `None`.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct Progress {
|
||||
pub met: usize,
|
||||
pub total: usize,
|
||||
}
|
||||
|
||||
pub struct TicketItem {
|
||||
pub title: String,
|
||||
pub owner: String,
|
||||
@@ -1159,11 +1176,42 @@ pub struct TicketItem {
|
||||
pub id: String,
|
||||
pub created: String,
|
||||
pub priority: Priority,
|
||||
/// Ticked against total, or `None` for a ticket with no criteria.
|
||||
///
|
||||
/// Counted where the file is already being read, so the board pays nothing for it
|
||||
/// beyond the count itself: the alternative, counting per card, would re-read every
|
||||
/// ticket body on every draw rather than on the tick that changed something. The
|
||||
/// listing ignores it, as it ignores `path`.
|
||||
pub criteria: Option<Progress>,
|
||||
/// 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,
|
||||
}
|
||||
|
||||
/// The date part of a due value, for a view with only a corner to spend on it.
|
||||
///
|
||||
/// The field is not validated, see daa0e79, so it holds whatever a caller typed: a bare
|
||||
/// date, a date and a time, or free text. Only a real `YYYY-MM-DD` prefix is cut back
|
||||
/// to. Taking the first word regardless would turn a free-text due into its first word,
|
||||
/// which is worse than showing what is stored and letting the column decide.
|
||||
pub fn due_date(due: &str) -> &str {
|
||||
let candidate = due.split([' ', 'T']).next().unwrap_or(due);
|
||||
match is_ymd(candidate) {
|
||||
true => candidate,
|
||||
false => due,
|
||||
}
|
||||
}
|
||||
|
||||
fn is_ymd(value: &str) -> bool {
|
||||
let bytes = value.as_bytes();
|
||||
bytes.len() == 10
|
||||
&& bytes[4] == b'-'
|
||||
&& bytes[7] == b'-'
|
||||
&& [0, 1, 2, 3, 5, 6, 8, 9]
|
||||
.iter()
|
||||
.all(|at| bytes[*at].is_ascii_digit())
|
||||
}
|
||||
|
||||
/// Grey for a value that is not set, per the colour guideline.
|
||||
///
|
||||
/// `show` already did this in its metadata rendering, so the listing was the one
|
||||
@@ -1265,6 +1313,18 @@ 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");
|
||||
|
||||
// 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.
|
||||
let counted = criteria(&content);
|
||||
let progress = match counted.len() {
|
||||
0 => None,
|
||||
total => Some(Progress {
|
||||
met: counted.iter().filter(|criterion| criterion.checked).count(),
|
||||
total,
|
||||
}),
|
||||
};
|
||||
|
||||
Some(TicketItem {
|
||||
title,
|
||||
owner,
|
||||
@@ -1272,6 +1332,7 @@ pub fn collect_ticket_items(status_path: impl AsRef<Path>) -> Result<Vec<TicketI
|
||||
id: short_id(&filename).to_string(),
|
||||
created: format_created_at(&created_at),
|
||||
priority: parse_priority(&content),
|
||||
criteria: progress,
|
||||
path: e.path(),
|
||||
})
|
||||
})
|
||||
@@ -1552,6 +1613,131 @@ mod tests {
|
||||
assert_eq!(rendered, format!("Priority {glyph} _Not set_\n"));
|
||||
}
|
||||
|
||||
/// A ticket with the two things that used to leak: a numbered plan, and a
|
||||
/// hand-written line inside the Metadata section.
|
||||
const BOTH_LEAKS: &str = "# T\n\n## Implementation Plan\n1. First step\n2. Second step\n\
|
||||
\n## Metadata\n\n- **ID**: abc\nA **handwritten** note\n";
|
||||
|
||||
/// The bug: the board asks for `content_trim(content, false)` because a paragraph
|
||||
/// is no place for an escape sequence, and two paths asked the terminal instead.
|
||||
#[test]
|
||||
fn the_body_carries_no_escape_when_the_colour_is_off() {
|
||||
let rendered = content_trim(BOTH_LEAKS, false);
|
||||
|
||||
assert!(
|
||||
!rendered.contains('\x1b'),
|
||||
"an escape survived colour being off: {rendered:?}"
|
||||
);
|
||||
// And the content is all still there, in plain form.
|
||||
assert!(rendered.contains("1. First step"), "{rendered:?}");
|
||||
assert!(rendered.contains("**handwritten**"), "{rendered:?}");
|
||||
}
|
||||
|
||||
/// The other half of the pair, and the one that makes the first mean something:
|
||||
/// with the flag on, both paths still colour. Without this, the passing test above
|
||||
/// could be a colouring path that was simply deleted.
|
||||
#[test]
|
||||
fn the_body_colours_the_plan_number_and_a_metadata_note_when_the_colour_is_on() {
|
||||
let rendered = content_trim(BOTH_LEAKS, true);
|
||||
|
||||
assert!(
|
||||
rendered.contains(&format!("{}1.", Color::Cyan.ansi())),
|
||||
"the plan number lost its colour: {rendered:?}"
|
||||
);
|
||||
assert!(
|
||||
rendered.contains(&format!("{}handwritten", Color::Magenta.ansi())),
|
||||
"the bold run lost its colour: {rendered:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// The flag has to be the only thing that decides, or the disabled path is just
|
||||
/// the terminal's answer in disguise — which is why the leak survived a test
|
||||
/// asserting the detail view holds no escapes. In a test binary there is no tty,
|
||||
/// so `should_use_colors()` is false and the leaking branch was never taken.
|
||||
#[test]
|
||||
fn nothing_the_body_renders_asks_the_terminal_for_the_colour_decision() {
|
||||
let callers = callers_of_color_text(include_str!("util.rs"));
|
||||
|
||||
// `ambiguous` is the one that may: it builds the candidate list for a failed
|
||||
// search, reaches the user on stderr, and is not reachable from `content_trim`.
|
||||
assert_eq!(
|
||||
callers,
|
||||
vec!["ambiguous".to_string()],
|
||||
"`color_text` asks `should_use_colors()`. Everything reachable from \
|
||||
`content_trim` has to take the decision as an argument and pass it to \
|
||||
`paint` instead, because the board renders with colour off and an escape \
|
||||
in a ratatui paragraph is drawn as literal bytes. If the new caller really \
|
||||
is CLI-only, add it here and say why."
|
||||
);
|
||||
}
|
||||
|
||||
/// Which functions in this file call `color_text`, by name, definitions and the
|
||||
/// test module excluded.
|
||||
fn callers_of_color_text(source: &str) -> Vec<String> {
|
||||
let body = match source.find("\n#[cfg(test)]") {
|
||||
Some(end) => &source[..end],
|
||||
None => source,
|
||||
};
|
||||
|
||||
let mut current = String::new();
|
||||
let mut callers = Vec::new();
|
||||
for line in body.lines() {
|
||||
if let Some(rest) = line.strip_prefix("fn ").or_else(|| line.strip_prefix("pub fn ")) {
|
||||
current = rest.split('(').next().unwrap_or_default().to_string();
|
||||
continue;
|
||||
}
|
||||
if line.contains("color_text(") && !callers.contains(¤t) {
|
||||
callers.push(current.clone());
|
||||
}
|
||||
}
|
||||
|
||||
callers
|
||||
}
|
||||
|
||||
/// The field is not validated, see daa0e79, so the card cannot trust it to be a
|
||||
/// bare date. Only a real date prefix is cut back to: free text is left alone,
|
||||
/// since turning "next friday" into "next" would be a worse answer than the width.
|
||||
#[test]
|
||||
fn a_due_value_is_cut_back_to_its_date_only_when_it_has_one() {
|
||||
assert_eq!(due_date("2026-12-31"), "2026-12-31");
|
||||
assert_eq!(due_date("2026-12-31 09:30:00"), "2026-12-31");
|
||||
assert_eq!(due_date("2026-12-31T09:30:00Z"), "2026-12-31");
|
||||
assert_eq!(due_date("_Not set_"), "_Not set_");
|
||||
assert_eq!(due_date("next friday"), "next friday");
|
||||
assert_eq!(due_date("2026-1-1 09:30"), "2026-1-1 09:30");
|
||||
}
|
||||
|
||||
/// The count on a card comes from `criteria()`, the same function that numbers them
|
||||
/// in `show`, so the two cannot disagree about what a criterion is.
|
||||
#[test]
|
||||
fn collect_ticket_items_counts_the_criteria_show_would_number() {
|
||||
let dir = std::env::temp_dir().join(format!("worklane-count-{}", uuid::Uuid::new_v4()));
|
||||
fs::create_dir_all(&dir).unwrap();
|
||||
|
||||
let write = |name: &str, body: &str| {
|
||||
fs::write(
|
||||
dir.join(format!("11111111-0000-4000-8000-00000000000{name}.md")),
|
||||
format!("# T{name}\n\n{body}\n\n## Metadata\n\n- **Owner**: alice\n"),
|
||||
)
|
||||
.unwrap();
|
||||
};
|
||||
|
||||
// A checkbox in the description is not a criterion, in either view.
|
||||
write(
|
||||
"1",
|
||||
"## Description\n- [x] not a criterion\n\n## Acceptance Criteria\n- [x] One\n- [ ] Two",
|
||||
);
|
||||
write("2", "## Acceptance Criteria\n_No acceptance criteria provided._");
|
||||
|
||||
let items = collect_ticket_items(&dir).unwrap();
|
||||
let counted: Vec<Option<Progress>> = items.iter().map(|item| item.criteria).collect();
|
||||
|
||||
assert!(counted.contains(&Some(Progress { met: 1, total: 2 })), "{counted:?}");
|
||||
assert!(counted.contains(&None), "a ticket with no criteria got a count: {counted:?}");
|
||||
|
||||
fs::remove_dir_all(&dir).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_section_rule_matches_the_width_of_its_name() {
|
||||
let rendered = content_trim_colored("# T\n\n## Description\nbody\n");
|
||||
|
||||
Reference in New Issue
Block a user