(f6af387) Add the board view, and bump to 0.7.0

worklane was one-shot commands only, so reading the board meant running ls again
and again and nothing ever showed the four statuses side by side, which is the
one view a kanban flow is for.

Four columns, a card per ticket carrying the priority mark, short id, title,
owner and due. Arrows or hjkl to move, enter for the detail view, q to quit.
Read only: moving a card by keypress is a follow-up, kept out until the watch
and render loop were solid.

Modelled on frig throughout, same crates and same shape: event poll on a 250ms
timeout so the tick runs when nobody is typing, a panic hook that leaves the
alternate screen before the backtrace, and the terminal restored on the error
path as well as on quit. A bare worklane opens it, as a bare frig does, so
Cli::command is now an Option.

The watch looks at files, not directories. A directory's mtime only moves on
create and rename, so a ticket edited in place would be missed; the digest
hashes every ticket and comment file's path, length and mtime. Comment files
are in it because a comment added elsewhere has to reach the detail view. It
guards the rescan rather than the draw, since ratatui diffs its buffer but
reading the tree every frame would not be free. notify is deliberately not a
dependency, and the reason is on the ticket.

Two orderings are deliberate. The worklane directory is looked for before the
terminal, so running outside one gives the usual message rather than a complaint
about the tty, and both errors stay testable without a pty. And a missing tty is
refused by name, since raw mode on a pipe fails with a bare "No such device or
address" that explains nothing.

The palette is now a Color enum rather than a string, so the escape the CLI
writes and the ratatui colour the board draws come from one definition and a
colour missing from either is a compile error. That retires the test which
existed only to catch a name with no entry, the failure that once left magenta
undefined.

Cards come from collect_ticket_items, so there is no second parser;
TicketItem gained the path the detail view opens. content_trim and
format_comments_with take the colour decision, because ratatui draws spans and
would print an escape as literal bytes.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ansho Rei
2026-08-21 11:44:37 +02:00
co-authored by Claude Opus 5
parent bbb1568a0f
commit 78831f1a39
10 changed files with 1532 additions and 105 deletions
+137 -56
View File
@@ -52,24 +52,74 @@ pub fn should_use_colors() -> bool {
})
}
pub fn get_color(color: &str) -> &'static str {
match color {
"red" => "\x1b[31m",
"cyan" => "\x1b[36m",
"orange" => "\x1b[33m",
"green" => "\x1b[32m",
// Indexed colour 8 in the 256-colour form, which is byte for byte what
// crossterm emits for ratatui's Color::DarkGray, the grey frig and pantop
// use for dimmed rows. Neither SGR 90 nor 37 renders as grey on every
// palette: 90 leans on the bright-black slot and 37 can sit right on top
// of the default foreground.
"grey" => "\x1b[38;5;8m",
// Bold, per the guideline in AGENTS.md. Its absence meant colorize_line
// asked for a colour that did not exist and got an empty prefix.
"magenta" => "\x1b[1;35m",
// Indexed, for the same reason grey is: this is the spelling that renders.
"brightred" => "\x1b[38;5;9m",
_ => "",
/// The palette, as a type rather than a set of strings.
///
/// One definition for both renderers. The CLI needs an escape sequence and the TUI
/// needs a `ratatui::style::Color`, and an enum makes a colour that exists for one and
/// not the other a compile error instead of something a test has to go looking for.
/// The stringly-typed version needed exactly such a test, and a missing entry silently
/// produced an empty prefix, which is how `magenta` came to be undefined.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Color {
Red,
Cyan,
Orange,
Green,
Grey,
Magenta,
BrightRed,
}
impl Color {
/// The SGR sequence the CLI writes.
pub fn ansi(self) -> &'static str {
match self {
Color::Red => "\x1b[31m",
Color::Cyan => "\x1b[36m",
Color::Orange => "\x1b[33m",
Color::Green => "\x1b[32m",
// Indexed colour 8 in the 256-colour form, which is byte for byte what
// crossterm emits for ratatui's Color::DarkGray, the grey frig and pantop
// use for dimmed rows. Neither SGR 90 nor 37 renders as grey on every
// palette: 90 leans on the bright-black slot and 37 can sit right on top
// of the default foreground.
Color::Grey => "\x1b[38;5;8m",
// Bold, per the guideline in AGENTS.md.
Color::Magenta => "\x1b[1;35m",
// Indexed, for the same reason grey is: this is the spelling that renders.
Color::BrightRed => "\x1b[38;5;9m",
}
}
/// Every colour in the palette, so a test can walk them without listing them.
pub const ALL: [Color; 7] = [
Color::Red,
Color::Cyan,
Color::Orange,
Color::Green,
Color::Grey,
Color::Magenta,
Color::BrightRed,
];
}
/// The same palette as ratatui sees it.
///
/// Chosen to match what crossterm emits for the escape above, so a card in the TUI and
/// a row in the listing are the same colour rather than two guesses at it.
impl From<Color> for ratatui::style::Color {
fn from(color: Color) -> Self {
use ratatui::style::Color as Tui;
match color {
Color::Red => Tui::Red,
Color::Cyan => Tui::Cyan,
Color::Orange => Tui::Yellow,
Color::Green => Tui::Green,
Color::Grey => Tui::DarkGray,
Color::Magenta => Tui::Magenta,
Color::BrightRed => Tui::LightRed,
}
}
}
@@ -77,15 +127,15 @@ pub fn get_color(color: &str) -> &'static str {
///
/// The seam matters for anything that aligns columns: a caller has to be able to
/// render both ways in one process to prove the padding does not depend on it.
pub fn paint(text: &str, color: &str, enabled: bool) -> String {
pub fn paint(text: &str, color: Color, enabled: bool) -> String {
if enabled {
format!("{}{}{}", get_color(color), text, "\x1b[0m")
format!("{}{}{}", color.ansi(), text, "\x1b[0m")
} else {
text.to_string()
}
}
pub fn color_text(text: &str, color: &str) -> String {
pub fn color_text(text: &str, color: Color) -> String {
paint(text, color, should_use_colors())
}
@@ -167,9 +217,9 @@ fn ambiguous(search: &str, matches: &[(String, String, String, String)]) -> anyh
message.push_str(&format!(
" {}. ({}) {} [{}]\n",
i + 1,
color_text(short_id(id), "red"),
color_text(short_id(id), Color::Red),
title,
color_text(status, "orange"),
color_text(status, Color::Orange),
));
}
@@ -263,18 +313,26 @@ pub fn resolve_ticket(search: &str, worklane_dir: &Path) -> Result<(String, Stri
Ok((status, title, content))
}
pub fn format_comments(comments: &[(String, String, String, String)]) -> String {
format_comments_with(comments, should_use_colors())
}
/// As above, with the colour decision passed in for the TUI.
pub fn format_comments_with(
comments: &[(String, String, String, String)],
colored: bool,
) -> String {
if comments.is_empty() {
return color_text("No comments yet.", "grey");
return paint("No comments yet.", Color::Grey, colored);
}
let mut result = String::new();
result.push_str("\n");
result.push_str(&color_text("COMMENTS", "orange"));
result.push_str(&paint("COMMENTS", Color::Orange, colored));
result.push_str(&format!("\n{}\n", "─".repeat(20)));
for (_filename, author, time, body) in comments {
result.push_str("\n");
result.push_str(&color_text(&format!("From {} ({})", author, time), "cyan"));
result.push_str(&paint(&format!("From {} ({})", author, time), Color::Cyan, colored));
result.push_str("\n");
if !body.is_empty() {
result.push_str(&" ".to_string());
@@ -286,8 +344,15 @@ pub fn format_comments(comments: &[(String, String, String, String)]) -> String
result
}
pub fn content_trim_colored(content: &str) -> String {
content_trim(content, should_use_colors())
}
/// The ticket body rendered for display, with the colour decision passed in.
///
/// The TUI needs the plain form: ratatui draws styled spans, and an escape sequence
/// embedded in a paragraph would be printed as literal bytes.
pub fn content_trim(content: &str, colored: bool) -> String {
let lines: Vec<&str> = content.trim().lines().collect();
let colored = should_use_colors();
let mut result = String::new();
let mut current_section = "";
let mut criterion = 0;
@@ -299,7 +364,7 @@ pub fn content_trim_colored(content: &str) -> String {
// Track current section
if let Some(section_name) = line.strip_prefix("## ") {
current_section = line;
result.push_str(&paint(section_name, "orange", colored));
result.push_str(&paint(section_name, Color::Orange, colored));
result.push('\n');
// Measured on the name as displayed, in characters. The rule used to span
// the raw line, so it ran three past the heading for the "## ", and byte
@@ -350,15 +415,15 @@ pub fn content_trim_colored(content: &str) -> String {
&& let Some((checked, text)) = checkbox(line)
{
criterion += 1;
result.push_str(&paint(&format!("{}.", criterion), "cyan", colored));
result.push_str(&paint(&format!("{}.", criterion), Color::Cyan, colored));
result.push(' ');
result.push_str(&paint(
if checked { "[x]" } else { "[ ]" },
"grey",
Color::Grey,
colored,
));
result.push(' ');
result.push_str(&colorize_line(text));
result.push_str(&colorize_bold(text, colored));
result.push('\n');
continue;
}
@@ -371,7 +436,7 @@ pub fn content_trim_colored(content: &str) -> String {
let link_start = start + end_bracket + 1;
if let Some(end) = line[link_start..].find(']') {
let absolute_end = link_start + end + 1;
result.push_str(&color_text(&line[start..absolute_end], "cyan"));
result.push_str(&paint(&line[start..absolute_end], Color::Cyan, colored));
result.push('\n');
continue;
}
@@ -380,7 +445,7 @@ pub fn content_trim_colored(content: &str) -> String {
}
// Regular content - colorize **bold** in magenta
result.push_str(&colorize_line(line));
result.push_str(&colorize_bold(line, colored));
result.push('\n');
}
@@ -401,7 +466,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, "cyan"));
result.push_str(&color_text(number, Color::Cyan));
result.push_str(&line[i + 1..]);
return result;
} else {
@@ -450,7 +515,7 @@ fn metadata_value_cell(name: &str, value: &str, colored: bool) -> String {
}
if is_unknown_value(value) {
return paint(value, "grey", colored);
return paint(value, Color::Grey, colored);
}
value.to_string()
@@ -486,7 +551,7 @@ fn render_metadata_table(lines: &[&str], colored: bool) -> String {
for row in &rows {
match row {
MetadataRow::Field { name, value } => {
result.push_str(&paint(name, "red", colored));
result.push_str(&paint(name, Color::Red, colored));
result.push_str(&" ".repeat(field_width - name.chars().count()));
result.push_str(METADATA_GUTTER);
result.push_str(&metadata_value_cell(name, value, colored));
@@ -533,7 +598,7 @@ 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, "magenta"));
result.push_str(&color_text(&bold, Color::Magenta));
i = close + 2;
}
// Unterminated: the rest is literal. The old scan walked off the end
@@ -929,10 +994,10 @@ pub fn numbered_criteria(criteria: &[Criterion], shown: &[usize]) -> String {
.map(|(offset, criterion)| {
format!(
" {} {} {}",
paint(&format!("{}.", offset + 1), "cyan", colored),
paint(&format!("{}.", offset + 1), Color::Cyan, colored),
paint(
if criterion.checked { "[x]" } else { "[ ]" },
"grey",
Color::Grey,
colored
),
criterion.text
@@ -1083,6 +1148,9 @@ pub struct TicketItem {
pub id: String,
pub created: String,
pub priority: Priority,
/// 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,
}
/// Grey for a value that is not set, per the colour guideline.
@@ -1091,7 +1159,7 @@ pub struct TicketItem {
/// place that ignored the rule.
fn dim_if_unset(value: &str, colored: bool) -> String {
if is_unknown_value(value) {
paint(value, "grey", colored)
paint(value, Color::Grey, colored)
} else {
value.to_string()
}
@@ -1112,17 +1180,17 @@ fn dim_if_unset(value: &str, colored: bool) -> String {
/// The number counts up while the mark empties out, because 1 is the most urgent.
/// That is the convention every tracker uses and what the p1 tags this replaced
/// already meant.
pub fn priority_mark(priority: Priority) -> (&'static str, &'static str) {
pub fn priority_mark(priority: Priority) -> (&'static str, Color) {
match priority {
Priority::Level(1) => ("\u{25cf}\u{25cf}", "brightred"),
Priority::Level(2) => ("\u{25cf}\u{25d0}", "red"),
Priority::Level(3) => ("\u{25cf}\u{25cb}", "orange"),
Priority::Level(4) => ("\u{25d0}\u{25cb}", "cyan"),
Priority::Level(5) => ("\u{25cb}\u{25cb}", "grey"),
Priority::Level(1) => ("\u{25cf}\u{25cf}", Color::BrightRed),
Priority::Level(2) => ("\u{25cf}\u{25d0}", Color::Red),
Priority::Level(3) => ("\u{25cf}\u{25cb}", Color::Orange),
Priority::Level(4) => ("\u{25d0}\u{25cb}", Color::Cyan),
Priority::Level(5) => ("\u{25cb}\u{25cb}", Color::Grey),
// Unreachable while Level is only built by parse_priority, which checks
// the range, but a level added later should not silently render blank.
Priority::Level(_) | Priority::Invalid => ("??", "brightred"),
Priority::Unset => ("\u{b7}\u{b7}", "grey"),
Priority::Level(_) | Priority::Invalid => ("??", Color::BrightRed),
Priority::Unset => ("\u{b7}\u{b7}", Color::Grey),
}
}
@@ -1149,7 +1217,7 @@ pub fn display_ticket_items(items: &[TicketItem]) {
let colored = should_use_colors();
for item in items {
let id = paint(&item.id, "red", colored);
let id = paint(&item.id, Color::Red, colored);
let owner = dim_if_unset(&item.owner, colored);
let due = dim_if_unset(&item.due, colored);
let priority = show_priority(item.priority, colored);
@@ -1160,7 +1228,7 @@ pub fn display_ticket_items(items: &[TicketItem]) {
priority, id, item.title, owner, due
);
} else {
let created = paint(&item.created, "cyan", colored);
let created = paint(&item.created, Color::Cyan, colored);
println!(
" {} {} ({}) {} | Owner: {} | Due: {}",
priority, created, id, item.title, owner, due
@@ -1193,6 +1261,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),
path: e.path(),
})
})
.collect();
@@ -1247,7 +1316,7 @@ mod tests {
for unset in ["_Not set_", "_None_"] {
assert!(is_unknown_value(unset), "{unset} should count as unset");
assert_eq!(dim_if_unset(unset, false), unset);
assert_eq!(dim_if_unset(unset, true), paint(unset, "grey", true));
assert_eq!(dim_if_unset(unset, true), paint(unset, Color::Grey, true));
}
for set in ["alice", "2026-12-31", "bug,frontend"] {
@@ -1690,15 +1759,27 @@ mod tests {
#[test]
fn the_ramp_avoids_green() {
for level in PRIORITY_RANGE {
assert_ne!(priority_mark(Priority::Level(level)).1, "green");
assert_ne!(priority_mark(Priority::Level(level)).1, Color::Green);
}
}
#[test]
fn every_colour_the_code_asks_for_exists() {
for colour in ["red", "cyan", "orange", "green", "grey", "magenta", "brightred"] {
assert!(!get_color(colour).is_empty(), "{colour} is not defined");
fn every_colour_has_an_escape_and_a_ratatui_equivalent() {
// The old version of this test guarded against a name with no entry, which the
// enum now makes a compile error. What is left worth asserting is that no
// variant renders as nothing, and that the two renderers agree on the set.
let mut seen = std::collections::HashSet::new();
for colour in Color::ALL {
assert!(!colour.ansi().is_empty(), "{colour:?} has no escape");
assert!(
colour.ansi().starts_with("\x1b["),
"{colour:?} is not an SGR sequence"
);
assert!(seen.insert(ratatui::style::Color::from(colour)), "{colour:?} shares its ratatui colour");
}
assert_eq!(seen.len(), Color::ALL.len());
}
/// Pinned deliberately. Both SGR spellings of grey failed on a real palette,
@@ -1707,7 +1788,7 @@ mod tests {
/// so worklane's grey is the one frig and pantop already render.
#[test]
fn grey_matches_the_indexed_colour_frig_uses() {
assert_eq!(get_color("grey"), "\x1b[38;5;8m");
assert_eq!(Color::Grey.ansi(), "\x1b[38;5;8m");
}
/// With no colour to carry the emphasis, the markers are the emphasis.