Compare commits

..
3 Commits
9 changed files with 603 additions and 177 deletions
+2 -1
View File
@@ -382,7 +382,7 @@ and this file is for what someone changing worklane's own code needs.
- **`colored` still reaches `content_parts`, and it no longer means paint.** It says whether *this* renderer can carry a colour at all, and one thing turns on it: `**bold**` gives its markers up to the colour that replaces them, so a renderer with none has to keep them or the emphasis is lost rather than moved. The board passes `true`, `content_trim` passes the CLI's decision, and a piped `show` still reads its markers. Nothing else in the body consults it
- **Magenta means bold, and `span_from` is where the board learns that.** `Color::Magenta.ansi()` is `\x1b[1;35m`, so the CLI draws every bold run bold as well as magenta, and `From<Color>` can carry only the colour. Without the modifier added on the board's side the same cell would be painted two ways, which is the one thing the shared layout exists to prevent
- **The conversion is pinned from both ends.** `show_prints_the_same_body_it_printed_before_the_cells_conversion` holds a body with one of every painted run and asserts the CLI's output byte for byte, written from what it printed before the change, so the risk in sharing a layout, the CLI's output drifting to suit the board, fails the suite. `the_whole_body_is_styled_in_the_overlay_and_no_escape_reached_it` is the other end and is paired the way the guideline demands: a renderer that dropped every colour passes the absence, and one that went back to painting strings passes the presence
- **The history block arrives as cells too, so nothing in the overlay is flat.** `history_cells` lays the block out once; `format_history` is those cells through `paint_cells` and the board pushes the same ones as a `Cells` part after the body, since the log lives outside the ticket file and `content_parts` never sees it. Pinned from both ends the way the body is: `show_prints_the_same_history_it_printed_before_the_cells_conversion` holds the CLI's output byte for byte, and `the_history_block_is_styled_in_the_overlay_and_no_escape_reached_it` pairs the presence with the absence (f3e099e, closing the gap e4d0bb7 left)
- **The history block arrives as segments too, so nothing in the overlay is flat.** `history_parts` splits the entries into flow runs and quoted runs in one walk; `history_cells` is their flatten, which is what makes the CLI's bytes a property of the segmentation rather than a second walker free to drift from it, and the board reads the same parts and lays each out itself. Pinned from both ends the way the body is: the pins over `format_history` hold the flatten byte for byte, and `the_block_splits_into_flow_and_quoted_parts` pins which runs are whose
### Finding the Board
- **`find_worklane_dir` classifies the entry before it follows it.** `exists()` follows a link, so a `.worklane` that was a dangling symlink answered the same as no `.worklane` at all: the walk carried on up the tree and the first board above the project became the one every write landed in, silently. `classify` reads `symlink_metadata` first and answers one of four, `Absent`, `Board`, `Dangling` or `NotADirectory`, and **`Absent` is the only one the walk carries on from**. A `.worklane` that is there but unusable is this project's board and is reported, not handed upward
@@ -501,6 +501,7 @@ and this file is for what someone changing worklane's own code needs.
### Code Organization
- **`change` and `split_change` are a pair, and they live beside each other in `history.rs`.** The mechanical body is stored as one string, `before → after`, so painting the halves means splitting it, and the separator is a constant the writer and the reader share. A renderer with its own copy of the spacing would go on splitting on a separator the writer no longer emits, and would say so by drawing a whole body as one half. The split is `split_once`, so a value carrying the arrow itself keeps it
- **The history block quotes who is talking.** Every line of a comment's body draws behind a grey bar spanning the whole run, paragraph breaks included, the way quoted text is drawn — d447e04, taking the review of 2733b10's answer over that ticket's uniform prefix and b304b17's per-line indent, both of which left the continuation at column 0. The reason under a mechanical row draws the same bar. The author line stays at column 0 and is told from a mechanical row by its `From` and its colour instead; the rule a reader learns is that a barred line is somebody's own words and a line of values at column 0 is the tool reporting itself. With colour off the glyph goes but the width it occupied stays, as spaces derived from the drawn form in `quoted_cells`, so a pipe keeps the column without an escape byte
- **A quote is one segmentation, two shapes, and the shapes split on wrapping.** The CLI prefixes each stored line — `quoted_cells`, which is why a terminal soft-wrapping a wide line draws continuations bare: a pipe has no width to honour, and `show` does not wrap by hand. The board quotes as geometry instead (8020e48): a `HistoryPart::Quoted` run becomes an overlay section laid out as two columns, a two-cell gutter holding the grey bar top to bottom and the body beside it, so a row the prose wraps onto inherits the mark from the gutter rather than from its own first characters. `Detail` holds sections for this reason — flow stretches full width, quotes beside their gutters — and the clamp sums the sections' wrapped heights, so scroll and draw measure one total. The newline history writes after every quote is consumed by the section builder rather than drawn: it used to close the quote's last line and the section boundary does that now, so drawing it would bank a blank row no entry ever had. `QUOTE_BAR` lives in `util.rs` because both renderers draw it, not because they draw it the same way
- **`history.rs` owns the log end to end**: the path, the kinds, the parse, the write, the count and the render. It came out of `util.rs` and `handlers.rs`, where the reader, the writer, the counter and the renderer sat in three files and one of them was 5,500 lines. The test for the reason is the module doc: a reader asking what an entry is has one file to open, the way `campaign.rs` and `tag.rs` answer their own questions
- The body's painters return cells, not strings: `ordered_cells`, `inline_cells`, `metadata_cells`, `metadata_value_cells`, `tag_cells` and `push_heading`. `content_trim_colored` is the CLI entry point and `paint_cells` is the only thing that writes an escape. `colorize_line` is gone: it was a `pub` alias for the bold pass with one caller, and the only thing it added was asking the terminal
- **`inline_cells` walks the line once for both inline markers**, `**bold**` and `[text](url)`, rather than running one pass over the output of the other. A second pass would be scanning text that already holds escape sequences, and `\x1b[36m` carries an opening bracket, so the link scan would take the escape for markup. The source is the only string in which either marker means what it says. It was `colorize_bold` while links lived in a branch of their own in `content_parts`; that branch is gone, which is also what gives the criteria text and the metadata `Other` rows their links, since those already went through this function
Generated
+1 -1
View File
@@ -1503,7 +1503,7 @@ dependencies = [
[[package]]
name = "worklane"
version = "0.32.3"
version = "0.32.5"
dependencies = [
"anyhow",
"assert_cmd",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "worklane"
version = "0.32.3"
version = "0.32.5"
edition = "2024"
[dependencies]
+19 -16
View File
@@ -365,30 +365,33 @@ Read the block before picking a ticket up: it says whether somebody has already
## Who your entries are attributed to
Every comment carries an author, and by default that is the git user of the machine you
are running on, which is the human whose checkout it is and not you. Set
`WORKLANE_ACTOR` in your own environment and it becomes the author of every entry you
write, so a board several agents write to says which of them said what:
Every entry carries an author, and yours comes from `WORKLANE_ACTOR`, which your harness
sets before you run anything. **Assume it is set for you, and never spell yourself out on
a call** — a plain `worklane comment` is already attributed to you, which is what keeps a
board several agents write to saying which of them said what. It is configured once,
where your session's environment lives: `env` in `~/.claude/settings.json` for Claude
Code, and the environment opencode is started with for opencode, since it passes its own
environment to the tools it runs.
**Reach for `--actor` only when the entry is somebody else's action**: the person asked
you to move a ticket, or to put words on the board as their comment, so name them on the
flag — the move was theirs and the words are theirs, and an entry carrying your name
reads later as though you decided both. Otherwise leave it off, unless your instructions
say to use it. It is spelled the same on every command that writes an entry: `comment`,
`mv`, `chown`, `set` and `assign`.
```
WORKLANE_ACTOR=claude worklane comment 1b78a24 "The offset was never passed to the widget."
worklane mv 1b78a24 --status done --actor "Ansho Rei"
```
Set it once where your session's environment is configured, not on each call: `env` in
`~/.claude/settings.json` for Claude Code, and the environment opencode is started with
for opencode, since it passes its own environment to the tools it runs. `--actor`
overrides it for one call and is spelled the same on every command that writes an entry,
`comment`, `mv`, `chown`, `set` and `assign`. An empty value counts as unset and falls
back to the
git user, and with nothing at all the author is `unknown`. It is free text, checked
against nothing: name yourself something a person reading the board will recognise.
Under a missing or empty variable the author falls back to the git user of the machine —
the human whose checkout it is — and with neither, `unknown`. It is free text, checked
against nothing: whatever name you pass, make it one a person reading the board will
recognise.
On `chown`, `--actor` is not the user argument: `worklane chown alice 1b78a24` makes alice
the ticket's owner, and `--actor` says who made that change.
If the variable is not set and you cannot set it, pass `--actor` rather than letting the
comment claim to be the user's.
## Shell completions
```
+21 -8
View File
@@ -162,22 +162,35 @@ fn tag_value(raw: &str) -> Result<String, String> {
Ok(value.to_string())
}
/// Reject an annotation line that would be read back as a tag of its own.
/// Reject an annotation the vocabulary file or the listing cannot carry.
///
/// The vocabulary is one heading per tag with its prose under it, so a line of prose
/// starting with the section marker would split the annotation and declare whatever
/// followed. Refused at parse time, where nothing has been written, rather than escaped on
/// the way in: an annotation is prose, and quietly rewriting prose is worse than asking for
/// a different line.
/// followed. A tab anywhere in the value is refused for the listing's sake rather than the
/// file's: `tags ls` prints one tag, its count and the annotation's opening line as three
/// tab-separated fields, so an annotation holding a tab reads as the start of a fourth
/// field and everything after it is silently gone.
///
/// Both are refused at parse time, where nothing has been written, rather than escaped on
/// the way in: an annotation is prose, and quietly rewriting prose is worse than asking
/// for a different line.
fn annotation_line(raw: &str) -> Result<String, String> {
match raw.lines().any(|line| line.starts_with(crate::tag::SECTION)) {
true => Err(format!(
if raw.lines().any(|line| line.starts_with(crate::tag::SECTION)) {
return Err(format!(
"an annotation line cannot start with '{}', which is how the vocabulary file \
starts a tag",
crate::tag::SECTION
)),
false => Ok(raw.to_string()),
));
}
if raw.contains('\t') {
return Err(
"an annotation cannot contain a tab, which is how `tags ls` separates its fields"
.to_string(),
);
}
Ok(raw.to_string())
}
/// What `--actor` says on every command that writes a history entry.
+126 -83
View File
@@ -24,8 +24,8 @@ use anyhow::{Result, anyhow};
use chrono::Local;
use crate::util::{
Cell, Color, MISSING, TIMESTAMP_FORMAT, is_unknown_value, paint_cells, should_use_colors,
tag_cells, tag_color,
Cell, Color, MISSING, TIMESTAMP_FORMAT, is_unknown_value, paint_cells, quoted_cells,
should_use_colors, tag_cells, tag_color,
};
/// Where a ticket's history lives, under the board.
@@ -405,53 +405,6 @@ pub fn format_history_with(entries: &[Entry], colored: bool) -> String {
paint_cells(&history_cells(entries, colored), colored)
}
/// The bar every line of a comment and of a reason draws behind, the way quoted text is
/// drawn.
///
/// Box-drawing vertical, the family the rule under HISTORY is already rendered from, so
/// it shows wherever that does. One cell wide, grey, and clear of the two vocabularies
/// it sits among: the priority meter owns the circles and the dot and the relation rows
/// own the cross and the arrows, so nothing here may read as a level or as an edge.
/// Grey is the colour the kind label carries, which names its row rather than holding a
/// value — what a quote bar does. `the_quote_bar_claims_no_glyph_another_column_means`
/// pins all three properties against the marks actually defined.
const QUOTE_BAR: &str = "\u{2502}";
/// One run of text behind [`QUOTE_BAR`], every line of it.
///
/// The bar spans the whole run rather than prefixing its first line, which is the
/// difference between a quote and an indentation: a multi-paragraph comment reads as one
/// voice start to finish, paragraph breaks included, instead of resuming halfway through
/// at column 0 — the column a line of values owns, which a single prefix handed back on
/// every line after the first. With colour off the glyph goes but the width it occupied
/// stays, as plain spaces derived from the drawn form rather than spelled beside it, so
/// a piped `show` keeps every line at the same column without carrying an escape byte.
/// One builder for both renderers, the board passing `true`: neither can draw a block
/// the other does not.
fn quoted_cells(body: &str, colored: bool) -> Vec<Cell> {
let bar = format!("{QUOTE_BAR} ");
let indent = " ".repeat(bar.chars().count());
let mut cells = Vec::new();
for (at, line) in body.split('\n').enumerate() {
if at > 0 {
cells.push(Cell::plain("\n"));
}
match (colored, line.is_empty()) {
// A paragraph break draws the bar alone rather than carrying a gap into
// nothing, which is what keeps it visibly inside the run.
(true, true) => cells.push(Cell::colored(QUOTE_BAR, Color::Grey)),
(true, false) => {
cells.push(Cell::colored(&bar, Color::Grey));
cells.push(Cell::plain(line));
}
(false, false) => cells.push(Cell::plain(format!("{indent}{line}"))),
(false, true) => {}
}
}
cells
}
/// The cells one value in a mechanical body is drawn as, per the Color Guideline.
///
/// Keyed on the kind, because the kind is what says which field the value came from: the
@@ -498,39 +451,60 @@ fn stamp_cells(entry: &Entry) -> Vec<Cell> {
]
}
/// The block laid out once, as [`Cell`]s: the CLI paints them and the board turns the
/// same ones into styled spans, so the two views cannot draw two different blocks.
/// One segment of the history block: what it is, and how a renderer lays it out.
///
/// The colour decision rides in because the quote bar is a coloured decoration: with it
/// off the cells carry the indent the bar would have provided, and no renderer has to
/// guess at that. `format_history_with` passes the CLI's decision and the board passes
/// `true`.
pub fn history_cells(entries: &[Entry], colored: bool) -> Vec<Cell> {
/// [`history_cells`] flattens these into the cells the CLI paints, and the board turns
/// each segment into its own stretch of the overlay instead: the flow runs full width
/// while a quoted run becomes a gutter column with the bar in it and the body beside it,
/// so a row the body wraps keeps the mark. One segmentation, two shapes — neither
/// renderer re-decides which runs are somebody's words.
#[derive(Debug)]
pub enum HistoryPart {
/// Headers, mechanical rows and the blank lines between entries, as they stand.
Flow(Vec<Cell>),
/// A comment's body or a move's reason: plain text, every line of it quoted, in
/// whatever shape the renderer quotes with.
Quoted(String),
}
/// The block as segments, one walk over the entries.
///
/// The order is the entries' own, oldest first, and a quoted run always sits between two
/// flow runs — the header or mechanical row before it and the blank line after it — so a
/// renderer can treat each segment as one unbroken stretch of rows.
pub fn history_parts(entries: &[Entry]) -> Vec<HistoryPart> {
let mut parts = Vec::new();
// The flow accumulating until the next quote closes it, which is why the trailing
// newline of every entry lands in the segment *after* a quote rather than being
// dropped: flattened, the parts are byte for byte the block [`history_cells`] has
// always built, which is what the CLI's pins hold it to.
let mut flow: Vec<Cell> = Vec::new();
if entries.is_empty() {
return vec![Cell::colored("No history yet.", Color::Grey)];
flow.push(Cell::colored("No history yet.", Color::Grey));
parts.push(HistoryPart::Flow(flow));
return parts;
}
let mut cells = Vec::new();
cells.push(Cell::plain("\n"));
cells.push(Cell::colored("HISTORY", Color::Orange));
cells.push(Cell::plain(format!("\n{}\n", "─".repeat(20))));
flow.push(Cell::plain("\n"));
flow.push(Cell::colored("HISTORY", Color::Orange));
flow.push(Cell::plain(format!("\n{}\n", "─".repeat(20))));
for entry in entries {
cells.push(Cell::plain("\n"));
flow.push(Cell::plain("\n"));
match entry.kind {
// As it has always read: a header naming who said it, then the text.
Kind::Comment => {
// Grey on the word, for the reason the kind label is grey: `From` names
// the line, it is not a value in it.
cells.push(Cell::colored("From", Color::Grey));
cells.push(Cell::plain(" "));
cells.extend(stamp_cells(entry));
cells.push(Cell::plain("\n"));
flow.push(Cell::colored("From", Color::Grey));
flow.push(Cell::plain(" "));
flow.extend(stamp_cells(entry));
flow.push(Cell::plain("\n"));
if !entry.body.is_empty() {
cells.extend(quoted_cells(&entry.body, colored));
parts.push(HistoryPart::Flow(std::mem::take(&mut flow)));
parts.push(HistoryPart::Quoted(entry.body.clone()));
}
cells.push(Cell::plain("\n"));
flow.push(Cell::plain("\n"));
}
// One line: a field change is one fact and a paragraph for it would bury the
// comments it sits between. A reason draws behind the same bar the comments
@@ -542,33 +516,60 @@ pub fn history_cells(entries: &[Entry], colored: bool) -> Vec<Cell> {
// an `owner` or `tags` label claimed a meaning belonging to the value
// beside it. The label is not a value at all: it names the row, which is
// what grey already says.
cells.push(Cell::colored(entry.kind.slug(), Color::Grey));
flow.push(Cell::colored(entry.kind.slug(), Color::Grey));
// Measured on the unpainted label and carried in a cell of its own, the
// rule the metadata table follows: measuring a painted string counts its
// escapes towards its width, which tilts the column when colour is on and
// not when it is off.
cells.push(Cell::plain(format!("{} ", " ".repeat(padding))));
flow.push(Cell::plain(format!("{} ", " ".repeat(padding))));
match split_change(&entry.body) {
Some((before, after)) => {
cells.extend(value_cells(entry.kind, before));
cells.push(Cell::plain(CHANGE_SEPARATOR));
cells.extend(value_cells(entry.kind, after));
flow.extend(value_cells(entry.kind, before));
flow.push(Cell::plain(CHANGE_SEPARATOR));
flow.extend(value_cells(entry.kind, after));
}
None => cells.extend(value_cells(entry.kind, &entry.body)),
None => flow.extend(value_cells(entry.kind, &entry.body)),
}
cells.push(Cell::plain(" "));
cells.extend(stamp_cells(entry));
cells.push(Cell::plain("\n"));
flow.push(Cell::plain(" "));
flow.extend(stamp_cells(entry));
flow.push(Cell::plain("\n"));
// The newline is the quote's terminator, so it exists only when there is
// one: a reasoned row draws the reason under itself and this closes it.
if !entry.reason.is_empty() {
cells.extend(quoted_cells(&entry.reason, colored));
cells.push(Cell::plain("\n"));
parts.push(HistoryPart::Flow(std::mem::take(&mut flow)));
parts.push(HistoryPart::Quoted(entry.reason.clone()));
flow.push(Cell::plain("\n"));
}
}
}
}
if !flow.is_empty() {
parts.push(HistoryPart::Flow(flow));
}
parts
}
/// The block laid out once, as [`Cell`]s: the CLI paints them and the board turns the
/// same ones into styled spans, so the two views cannot draw two different blocks.
///
/// The flatten of [`history_parts`], which is what makes the CLI's bytes a property of
/// the segmentation rather than a second walk that can drift from it: the pins over this
/// function's output are pins over the parts too. The colour decision rides in because
/// the quote bar is a coloured decoration; with it off the cells carry the indent the
/// bar would have provided. The board does not come through here — it lays each part in
/// the shape the section builder gives it — but it reads the same parts.
pub fn history_cells(entries: &[Entry], colored: bool) -> Vec<Cell> {
let mut cells = Vec::new();
for part in history_parts(entries) {
match part {
HistoryPart::Flow(run) => cells.extend(run),
HistoryPart::Quoted(body) => cells.extend(quoted_cells(&body, colored)),
}
}
cells
}
@@ -576,8 +577,8 @@ pub fn history_cells(entries: &[Entry], colored: bool) -> Vec<Cell> {
mod tests {
use super::*;
use crate::util::{
BLOCKED_MARK, Fixture, NOT_SET, PRIORITY_RANGE, Priority, REGRESSION_MARK, RELATES_MARK,
paint, priority_mark, status_dirs, status_mark,
BLOCKED_MARK, Fixture, NOT_SET, PRIORITY_RANGE, Priority, QUOTE_BAR, REGRESSION_MARK,
RELATES_MARK, paint, priority_mark, status_dirs, status_mark,
};
/// One entry, spelled the way a file on the board holds it.
@@ -1090,4 +1091,46 @@ mod tests {
fn nothing_recorded_says_so() {
assert_eq!(format_history_with(&[], false), "No history yet.");
}
/// The block as segments: the rows drawn as they stand are flow, a comment's body
/// and a move's reason are quoted, and each quote sits between two flow runs — the
/// row or header before it and the blank after it. This is the one segmentation both
/// renderers read, so it is pinned here rather than left to be discovered on the
/// board; the CLI's byte pins above hold its flatten to what it has always printed.
#[test]
fn the_block_splits_into_flow_and_quoted_parts() {
let entries = vec![
entry("status", "committed → reviewing", "claude", "2026-08-24 12:00:00"),
entry("comment", "First line.\n\nSecond.", "Ansho Rei", "2026-08-24 12:00:01"),
entry("status", "reviewing → backlog", "claude", "2026-08-24 12:00:02"),
]
.into_iter()
.enumerate()
.map(|(at, mut entry)| {
if at == 2 {
entry.reason = "sent back".to_string();
}
entry
})
.collect::<Vec<_>>();
let parts = history_parts(&entries);
let shapes: Vec<&str> = parts
.iter()
.map(|part| match part {
HistoryPart::Flow(_) => "flow",
HistoryPart::Quoted(_) => "quote",
})
.collect();
assert_eq!(shapes, ["flow", "quote", "flow", "quote", "flow"], "{parts:?}");
// The quotes carry the bare words, newlines included; laying them out is the
// renderer's decision.
for part in &parts {
if let HistoryPart::Quoted(body) = part {
assert!(!body.contains(QUOTE_BAR), "{body:?}");
}
}
assert_eq!(parts.len(), 5);
}
}
+323 -67
View File
@@ -23,7 +23,7 @@ use ratatui::text::{Line, Span, Text};
use ratatui::widgets::{Block, Borders, Clear, Paragraph, Tabs, Wrap};
use crate::campaign::{CAMPAIGNS_DIR, CampaignIndex, Standing};
use crate::history::{history_cells, history_root, read_history};
use crate::history::{HistoryPart, history_parts, history_root, read_history};
use crate::tag::{NO_ANNOTATION, TAGS_FILE, TagIndex};
use crate::util::*;
@@ -590,26 +590,61 @@ pub struct Detail {
/// 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<String>,
/// The body as the overlay draws it: lines of styled spans, not a string.
/// The body as vertical stretches, each one drawn and measured whole.
///
/// Styled here rather than painted into the text, because ratatui draws an escape
/// sequence in a paragraph as literal bytes, which is 6d327df. It is also the one
/// value the clamp and the draw both measure, so neither can wrap it differently
/// from the other.
pub body: Text<'static>,
/// A flow stretch runs full width; a quoted one is laid out as two columns at draw
/// time — a gutter the bar fills top to bottom, and the body beside it. That is what
/// keeps a comment's bar over every row its prose wraps onto, which a bar riding in
/// the text cannot do: the wrapper folds continuations underneath it. Sections are
/// also what the clamp measures, summed, so the scroll and the draw cannot disagree
/// about where any of them ends.
pub sections: Vec<DetailSection>,
}
/// One vertical stretch of the overlay, drawn and measured as a unit.
#[derive(Debug)]
pub enum DetailSection {
/// Description, metadata, mechanical history rows and the blanks between them:
/// full width, wrapped by the widget as always.
Flow(Text<'static>),
/// Somebody's words, from a [`HistoryPart::Quoted`] run. Carries the body only —
/// the bar is the gutter the draw lays beside it, not text under which a wrapped
/// row would lose it.
Quote(Text<'static>),
}
impl DetailSection {
fn text(&self) -> &Text<'static> {
match self {
DetailSection::Flow(text) | DetailSection::Quote(text) => text,
}
}
/// The width this section wraps at: the gutter takes its two cells from the rest.
fn width(&self, full: u16) -> u16 {
match self {
DetailSection::Flow(_) => full,
DetailSection::Quote(_) => full.saturating_sub(GUTTER_WIDTH),
}
}
}
/// How wide a quoted run's gutter is: the bar and the gap before the body, so a quoted
/// row reads exactly as wide as one the CLI prefixes.
const GUTTER_WIDTH: u16 = 2;
impl Detail {
/// The body as plain text, one line per drawn line.
///
/// Only the suite asks: it is what an assertion about the body reads, and what shows
/// that no escape sequence reached it. Nothing in the draw path needs it, so it is
/// not carried alongside the spans where the two could disagree.
/// not carried alongside the spans where the two could disagree. A quote's rows carry
/// no bar here, since on screen the bar is the gutter and not part of the line.
#[cfg(test)]
pub fn plain(&self) -> String {
self.body
.lines
self.sections
.iter()
.flat_map(|section| section.text().lines.iter())
.map(|line| {
line.spans
.iter()
@@ -1861,7 +1896,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.body, text) as isize;
let last = detail_last_offset(&detail.sections, text) as isize;
self.offset = (self.offset as isize + pages.saturating_mul(step)).clamp(0, last) as u16;
}
@@ -1997,39 +2032,91 @@ fn detail_of(card: &Card) -> Detail {
};
// Colour on, and nothing here is painted: the body arrives as cells, the relations
// as rows and the history block as the cells the CLI paints, and `detail_body`
// turns them all into styled spans. An escape sequence never enters, which is what
// a ratatui paragraph would draw as literal bytes.
// as rows and the history block as segments, and `detail_sections` turns them into
// stretches of spans. An escape sequence never enters, which is what a ratatui
// paragraph would draw as literal bytes.
let mut parts = content_parts(&content, true, &resolved);
let mut block = vec![Cell::plain("\n")];
// The board carries colour, so the quote bars a comment and a reason draw are the
// same cells `show` paints: one layout, two renderers.
block.extend(history_cells(&history, true));
parts.push(BodyPart::Cells(block));
parts.push(BodyPart::Cells(vec![Cell::plain("\n")]));
let sections = detail_sections(&parts, &history_parts(&history));
Detail {
title: ticket.title.clone(),
id: ticket.id.clone(),
project: card.project.clone(),
body: detail_body(&parts),
sections,
}
}
/// The rendered body as lines of spans: the text split where it says, and each relation
/// row styled from the cells the CLI paints.
/// One piece of the overlay, from either source: the ticket's own body or the log.
///
/// A part that does not end on a newline runs on into the next one rather than closing a
/// line, so the seam between text and relations is wherever the body actually put it and
/// not wherever a part happened to end.
fn detail_body(parts: &[BodyPart]) -> Text<'static> {
/// A private fold over the two input shapes, so [`detail_sections`] takes one walk
/// instead of two that could disagree about where a quote begins and ends.
enum Piece {
Cells(Vec<Cell>),
Relations(Vec<RelationRow>),
Quoted(String),
}
/// The overlay as vertical sections.
///
/// Flow pieces accumulate exactly as the one text used to — an unterminated run runs on
/// into the next part, so the seam between text and relations is wherever the body put
/// it. A quoted piece closes what is open, banks it as its own flow section, and becomes
/// a quote section carrying the bare body: the bar is geometry the draw lays beside these
/// rows, which is what keeps it over every row the prose wraps onto.
///
/// The one newline after a quoted run is consumed rather than drawn. It used to close
/// the quote's last line; now the section boundary does that, and drawing the newline
/// would bank a blank row no entry ever had. History always writes exactly that cell
/// after a quote — a comment body and a reason alike — so consuming one leading newline
/// from the next flow piece is exact, not heuristic.
fn detail_sections(parts: &[BodyPart], history: &[HistoryPart]) -> Vec<DetailSection> {
let mut pieces: Vec<Piece> = parts
.iter()
.map(|part| match part {
BodyPart::Cells(cells) => Piece::Cells(cells.clone()),
BodyPart::Relations(rows) => Piece::Relations(rows.clone()),
})
.chain(history.iter().map(|part| match part {
HistoryPart::Flow(cells) => Piece::Cells(cells.clone()),
HistoryPart::Quoted(body) => Piece::Quoted(body.clone()),
}))
.collect();
let mut sections: Vec<DetailSection> = Vec::new();
let mut lines: Vec<Line<'static>> = Vec::new();
let mut open: Vec<Span<'static>> = Vec::new();
// Set while the previous section was a quote, so the next flow piece knows to give
// up the newline that closed the quote before sections existed.
let mut after_quote = false;
for part in parts {
match part {
BodyPart::Cells(cells) => {
for piece in pieces.drain(..) {
match piece {
Piece::Quoted(body) => {
if !open.is_empty() {
lines.push(Line::from(std::mem::take(&mut open)));
}
if !lines.is_empty() {
sections.push(DetailSection::Flow(Text::from(std::mem::take(&mut lines))));
}
sections.push(DetailSection::Quote(Text::from(
body.split('\n')
.map(|line| Line::from(span_from(line, None, None)))
.collect::<Vec<Line<'static>>>(),
)));
after_quote = true;
}
Piece::Cells(cells) => {
for cell in cells {
let mut rest = cell.text.as_str();
if after_quote && rest.starts_with('\n') {
after_quote = false;
rest = &rest[1..];
if rest.is_empty() {
continue;
}
}
while let Some((line, tail)) = rest.split_once('\n') {
if !line.is_empty() {
open.push(span_from(line, cell.color, cell.modifier));
@@ -2044,8 +2131,8 @@ fn detail_body(parts: &[BodyPart]) -> Text<'static> {
}
// One line each, from the same cells `render_relations` paints, so the block
// cannot read differently here than it does in `show`.
BodyPart::Relations(rows) => {
for row in relation_cells(rows) {
Piece::Relations(rows) => {
for row in relation_cells(&rows) {
open.extend(row.into_iter().map(span_of));
lines.push(Line::from(std::mem::take(&mut open)));
}
@@ -2056,8 +2143,11 @@ fn detail_body(parts: &[BodyPart]) -> Text<'static> {
if !open.is_empty() {
lines.push(Line::from(open));
}
if !lines.is_empty() {
sections.push(DetailSection::Flow(Text::from(lines)));
}
Text::from(lines)
sections
}
/// A cell as the board draws it: the same text in the same style, as a span.
@@ -3962,6 +4052,24 @@ fn last_offset(detail: &Text<'static>, text: Rect) -> u16 {
wrapped_height(detail, text.width).saturating_sub(text.height)
}
/// How tall the whole overlay is, section by section.
///
/// Each section wraps at its own width — a quote's body shares its row with the gutter —
/// and the total is what the clamp and the indicator are derived from. One measurement
/// per section by the same [`wrapped_height`], so the draw and the scroll cannot
/// disagree about where any of them ends.
fn detail_height(sections: &[DetailSection], width: u16) -> u16 {
sections
.iter()
.map(|section| wrapped_height(section.text(), section.width(width)))
.fold(0u16, |total, height| total.saturating_add(height))
}
/// The furthest the overlay scrolls: every section's wrapped height less the viewport.
fn detail_last_offset(sections: &[DetailSection], text: Rect) -> u16 {
detail_height(sections, text.width).saturating_sub(text.height)
}
/// The step `scroll_detail` takes, a screenful less the line kept for overlap.
///
/// The page numbers are counted in it rather than in whole screenfuls, so the pages the
@@ -4021,7 +4129,7 @@ fn draw_detail(frame: &mut Frame, detail: &Detail, offset: u16, area: Rect) {
// terminal may have been resized since, and a ticket read to its end can grow
// shorter under a tick. Which is also what repages the indicator, since the wrapped
// count and the viewport both move with the width.
let last = wrapped_height(&detail.body, text.width).saturating_sub(text.height);
let last = detail_last_offset(&detail.sections, text);
let offset = offset.min(last);
let mut block = Block::default()
@@ -4044,13 +4152,68 @@ fn draw_detail(frame: &mut Frame, detail: &Detail, offset: u16, area: Rect) {
}
frame.render_widget(Clear, overlay);
frame.render_widget(
Paragraph::new(detail.body.clone())
.block(block)
.wrap(Wrap { trim: false })
.scroll((offset, 0)),
overlay,
);
frame.render_widget(block, overlay);
// The sections stack into one scroll: `top` walks the virtual rows, each section is
// clipped to what the viewport still holds, and one straddling the top is scrolled
// within itself by however much of it is above. The bar of a quote rides in its own
// column, so scrolling never has to move it.
let mut top: u16 = 0;
for section in &detail.sections {
let height = wrapped_height(section.text(), section.width(text.width));
let bottom = top.saturating_add(height);
let visible = bottom > offset && top < offset.saturating_add(text.height);
if visible {
let within = offset.saturating_sub(top);
let y = text.y + top.max(offset) - offset;
let clip = Rect {
x: text.x,
y,
width: text.width,
height: text.bottom().saturating_sub(y),
};
match section {
DetailSection::Flow(body) => frame.render_widget(
Paragraph::new(body.clone())
.wrap(Wrap { trim: false })
.scroll((within, 0)),
clip,
),
DetailSection::Quote(body) => {
let [bars, prose] =
Layout::horizontal([Constraint::Length(GUTTER_WIDTH), Constraint::Min(0)])
.areas(clip);
frame.render_widget(gutter_bars(clip.height), bars);
frame.render_widget(
Paragraph::new(body.clone())
.wrap(Wrap { trim: false })
.scroll((within, 0)),
prose,
);
}
}
}
top = bottom;
if top >= offset.saturating_add(text.height) {
break;
}
}
}
/// The gutter beside a quoted run: the bar repeated down every row the run occupies.
///
/// Geometry rather than text, which is the whole point — a comment's prose wraps inside
/// the body column and cannot take the mark off any row, paragraph breaks included.
/// Grey, as chrome; [`QUOTE_BAR`] for the same reason the CLI prefixes with it, so both
/// renderers draw one glyph.
fn gutter_bars(height: u16) -> Text<'static> {
let bar = Span::styled(format!("{QUOTE_BAR} "), Style::default().fg(Color::Grey.into()));
Text::from(vec![Line::from(bar); height as usize])
}
/// The overlay's title: the short id and the name of the ticket it has open.
@@ -4190,6 +4353,24 @@ mod tests {
.collect()
}
/// The overlay's text rows, cut out of the drawn screen by the layout's own
/// geometry, right-trimmed so an assertion reads what is on it rather than its
/// padding.
fn overlay_text_rows(lines: &[String], width: u16, height: u16) -> Vec<String> {
let text = detail_text_area(Rect::new(0, 0, width, height));
lines[text.y as usize..(text.y + text.height) as usize]
.iter()
.map(|row| {
row.chars()
.skip(text.x as usize)
.take(text.width as usize)
.collect::<String>()
.trim_end()
.to_string()
})
.collect()
}
/// The column headings, which sit on the top border row.
///
/// That row alone, because the footer names done as well: a whole-screen search for
@@ -5495,22 +5676,43 @@ mod tests {
assert_eq!(span_color(&change, "claude"), Some(tag_color("claude").into()));
assert_eq!(span_color(&change, "2026-08-21 12:00:00"), Some(Color::Cyan.into()));
// The quote bar rides in the same cells: grey, and carrying the gap before the
// text so a pipe can replace the pair with its width.
// The quote's rows carry no bar span any more — the bar is the gutter the draw
// lays beside them — so what says so on screen is a grey bar cell inside the
// overlay, distinct from the border's own verticals by its colour.
let said = body_line(detail, "And why.");
assert_eq!(span_color(&said, "│ "), Some(Color::Grey.into()));
assert!(!said.spans.iter().any(|span| span.content.contains(QUOTE_BAR)));
// Held as text rather than through the borrow: the board is scrolled below.
let plain = detail.plain();
// The log ends the overlay, so the gutter is on the last page.
for _ in 0..20 {
board.scroll_detail(1, SCREEN);
}
let mut terminal = Terminal::new(TestBackend::new(SCREEN.width, SCREEN.height)).unwrap();
terminal.draw(|frame| draw(frame, &board)).unwrap();
let buffer = terminal.backend().buffer().clone();
let overlay = detail_overlay(Rect::new(0, 0, SCREEN.width, SCREEN.height));
let grey: ratatui::style::Color = Color::Grey.into();
let bars = (overlay.y..overlay.bottom())
.flat_map(|y| (overlay.x..overlay.right()).map(move |x| (x, y)))
.filter(|&(x, y)| {
let cell = &buffer[(x, y)];
cell.symbol() == QUOTE_BAR && cell.fg == grey
})
.count();
assert!(bars > 0, "no grey gutter bar reached the screen");
// The other half: the colour arrived as styles, not as bytes.
assert!(
!detail.plain().contains('\x1b'),
"escapes reached the detail view: {:?}",
detail.plain()
);
assert!(!plain.contains('\x1b'), "escapes reached the detail view: {plain:?}");
}
/// The bar is laid out where both renderers read it, so a pasted body draws every
/// line behind it in the overlay too — not only its first, which is the bug this
/// shape replaced.
/// The bar is geometry over the rows a comment occupies, not text riding on each
/// stored line's first characters: the reported bug was that ratatui's word wrap
/// folds a long line onto continuation rows the prefix never reaches, so the quote
/// read as ending halfway through. Every drawn row of the run is asserted here,
/// wrapped continuations and the paragraph break included, and no row after it may
/// carry a bar either — a stray one would be a quote wider than its body.
#[test]
fn the_detail_view_draws_every_line_of_a_comment_behind_the_bar() {
let dir = board_dir();
@@ -5519,22 +5721,61 @@ mod tests {
let history = crate::history::history_dir(&dir, uuid);
std::fs::create_dir_all(&history).unwrap();
// One stored line long enough to wrap onto several drawn rows, then a second
// paragraph behind its own break: the two ways the old shape lost the bar.
let long_line = "alpha bravo charlie delta echo foxtrot golf hotel india juliet \
kilo lima mike november oscar papa quebec romeo sierra tango uniform victor \
whiskey xray yankee zulu";
std::fs::write(
history.join("20260821_120000_000000_comment.md"),
"**Comment**\nFirst line.\n\nSecond line.\n\n**Author**: bob\n**Time**: \
2026-08-21 12:00:00\n",
format!(
"**Comment**\n{long_line}\n\nSecond paragraph.\n\n**Author**: bob\n**Time**: \
2026-08-21 12:00:00\n"
),
)
.unwrap();
let mut board = one_board(&dir);
board.toggle_detail();
let plain = board.detail.as_ref().expect("no detail").plain();
// The log ends the overlay, so the last page is the one that holds the run.
for _ in 0..20 {
board.scroll_detail(1, SCREEN);
}
let screen = render(&board, SCREEN.width, SCREEN.height);
let rows = overlay_text_rows(&screen, SCREEN.width, SCREEN.height);
let header = rows
.iter()
.position(|row| row.starts_with("From bob"))
.expect("the comment's header is not on screen");
// The run: every row after the header up to the first one without a bar.
let mut at = header + 1;
while rows.get(at).is_some_and(|row| row.starts_with(QUOTE_BAR)) {
at += 1;
}
let run = header + 1..at;
assert!(
plain.contains("│ First line.\n│\n│ Second line."),
"the run is not quoted start to finish:\n{plain}"
run.len() >= 4,
"the fixture should wrap onto several rows, drew {run:?}:\n{rows:#?}"
);
// Nothing outside the run is quoted: no stray bar above or below the block.
assert!(
rows[at..].iter().all(|row| !row.contains(QUOTE_BAR)),
"a row past the comment carries a bar:\n{rows:#?}"
);
// The break sits inside the run as the bare glyph, and the second paragraph
// follows it behind the same bar.
assert!(
rows[run.clone()].iter().any(|row| row == QUOTE_BAR),
"no bare bar on the paragraph break:\n{rows:#?}"
);
assert!(
rows[run].iter().any(|row| row.starts_with("│ Second")),
"the second paragraph lost the bar:\n{rows:#?}"
);
assert!(!plain.contains('\x1b'), "escapes reached the detail view: {plain:?}");
}
/// The board and `show` share one layout, so the reason a move carries renders
@@ -5559,12 +5800,27 @@ mod tests {
board.toggle_detail();
let plain = board.detail.as_ref().expect("no detail").plain();
// The board carries colour, so the bar itself is on screen where a pipe would
// draw two spaces: same cells, one layout.
let expected = "status reviewing → backlog claude (2026-08-21 12:00:00)\n│ sent back, wrong \
approach";
// The reason is its own quoted stretch under the row it explains; its rows carry
// no bar in the text, since on screen the bar is the gutter beside them.
let expected = "status reviewing → backlog claude (2026-08-21 12:00:00)\nsent back, wrong \
approach";
assert!(plain.contains(expected), "{plain}");
assert!(!plain.contains('\x1b'), "escapes reached the detail view: {plain:?}");
assert!(!plain.contains(QUOTE_BAR), "the bar reached the text: {plain:?}");
// And on screen the bar stands beside it, once the log is scrolled into view.
for _ in 0..20 {
board.scroll_detail(1, SCREEN);
}
let screen = render(&board, SCREEN.width, SCREEN.height);
let rows = overlay_text_rows(&screen, SCREEN.width, SCREEN.height);
let status = rows
.iter()
.position(|row| row.starts_with("status "))
.expect("the mechanical row is not on screen");
assert!(
rows[status + 1].starts_with(&format!("{QUOTE_BAR} sent back")),
"the reason did not draw behind the bar:\n{rows:#?}"
);
}
/// The reported bug: the modal showed a description, criteria and a metadata
@@ -7424,7 +7680,7 @@ mod tests {
board.toggle_detail();
let area = detail_text_area(Rect::new(0, 0, SCREEN.width, SCREEN.height));
let last = last_offset(&board.detail.as_ref().unwrap().body, area);
let last = detail_last_offset(&board.detail.as_ref().unwrap().sections, area);
assert!(last > 0, "the fixture fits on one screen, so nothing is measured");
// Far past the end, so the clamp is what stops it.
@@ -7450,9 +7706,9 @@ mod tests {
/// is drawn in rather than reading the flattened text.
fn body_line(detail: &Detail, needle: &str) -> Line<'static> {
detail
.body
.lines
.sections
.iter()
.flat_map(|section| section.text().lines.iter())
.find(|line| {
line.spans
.iter()
@@ -7806,7 +8062,7 @@ mod tests {
}
let text = detail_text_area(Rect::new(0, 0, SCREEN.width, SCREEN.height));
let last = last_offset(&board.detail.as_ref().unwrap().body, text);
let last = detail_last_offset(&board.detail.as_ref().unwrap().sections, text);
assert_eq!(board.offset, last, "the fixture did not reach the end");
let screen = render(&board, SCREEN.width, SCREEN.height);
@@ -7838,7 +8094,7 @@ mod tests {
let text = detail_text_area(Rect::new(0, 0, width, height));
assert_eq!(
last_offset(&board.detail.as_ref().unwrap().body, text),
detail_last_offset(&board.detail.as_ref().unwrap().sections, text),
0,
"the fixture scrolls, so it proves nothing"
);
+45
View File
@@ -2552,6 +2552,51 @@ impl Cell {
}
}
/// The bar a quoted run draws behind, the way quoted text is drawn.
///
/// Box-drawing vertical, the family the rule under HISTORY is already rendered from, so
/// it shows wherever that does. One cell wide, grey, and clear of the two vocabularies
/// it sits among: the priority meter owns the circles and the dot and the relation rows
/// own the cross and the arrows, so nothing here may read as a level or as an edge.
/// Grey is the colour chrome takes everywhere else, which names its row rather than
/// holding a value — what a quote bar does. It lives beside [`Cell`] rather than in
/// `history.rs`, because the CLI prefixes stored lines with it while the board paints it
/// as a gutter column, and a glyph two renderers draw is a glyph the palette owns.
pub const QUOTE_BAR: &str = "\u{2502}";
/// One run of text behind [`QUOTE_BAR`], every stored line of it.
///
/// This is the CLI's shape of a quote: the bar rides on each line's first characters,
/// and a line the terminal soft-wraps continues without one, because a pipe has no width
/// to honour. The board quotes the same runs as geometry instead — a gutter column the
/// bar fills top to bottom — which is what keeps a wrapped row under the mark there.
/// With colour off the glyph goes but the width it occupied stays, as plain spaces
/// derived from the drawn form rather than spelled beside it, so a piped `show` keeps
/// every line at the same column without carrying an escape byte.
pub fn quoted_cells(body: &str, colored: bool) -> Vec<Cell> {
let bar = format!("{QUOTE_BAR} ");
let indent = " ".repeat(bar.chars().count());
let mut cells = Vec::new();
for (at, line) in body.split('\n').enumerate() {
if at > 0 {
cells.push(Cell::plain("\n"));
}
match (colored, line.is_empty()) {
// A paragraph break draws the bar alone rather than carrying a gap into
// nothing, which is what keeps it visibly inside the run.
(true, true) => cells.push(Cell::colored(QUOTE_BAR, Color::Grey)),
(true, false) => {
cells.push(Cell::colored(&bar, Color::Grey));
cells.push(Cell::plain(line));
}
(false, false) => cells.push(Cell::plain(format!("{indent}{line}"))),
(false, true) => {}
}
}
cells
}
/// The relations of one ticket, both directions, in the order they are shown.
///
/// Stored first: the relations the ticket holds, then the ones held against it, named
+65
View File
@@ -316,6 +316,71 @@ fn an_annotation_that_would_read_as_a_heading_is_refused() {
assert!(!temp.path().join(".worklane").join("tags.md").exists());
}
/// A tab anywhere in an annotation is refused by `tags add`, because the listing's fields
/// are tab separated: past the first tab everything after it reads as a fourth field. The
/// refusal says why, and nothing is written — the value parser refuses before the handler
/// runs, so not even a placeholder file is left behind.
#[test]
fn an_annotation_carrying_a_tab_is_refused_by_tags_add() {
let temp = TempDir::new().unwrap();
setup_worklane(&temp);
let out = run(&temp, &["tags", "add", "bug", "-a", "Something\twrong."]);
let stderr = String::from_utf8_lossy(&out.stderr);
assert!(!out.status.success(), "{stderr}");
assert!(
stderr.contains("tab") && stderr.contains("separates its fields"),
"{stderr}"
);
assert!(!temp.path().join(".worklane").join("tags.md").exists());
// No staged write survived either, so the directory holds only the status folders.
let left: Vec<_> = fs::read_dir(temp.path().join(".worklane"))
.unwrap()
.map(|e| e.unwrap().file_name())
.collect();
assert_eq!(left.len(), 4, "{left:?}");
}
/// The same value is refused by `tags set`, and the declaration that is already there is
/// untouched.
#[test]
fn an_annotation_carrying_a_tab_is_refused_by_tags_set() {
let temp = TempDir::new().unwrap();
setup_worklane(&temp);
run(&temp, &["tags", "add", "bug", "-a", "Something wrong."]);
let before = vocabulary(&temp);
let out = run(&temp, &["tags", "set", "bug", "-a", "Now\twith a tab."]);
assert!(!out.status.success(), "{}", String::from_utf8_lossy(&out.stderr));
assert_eq!(vocabulary(&temp), before);
}
/// Ordinary prose is unaffected, paragraphs included: the refusal is for the tab alone,
/// which is what keeps it from standing in front of the command's whole purpose.
#[test]
fn an_annotation_without_a_tab_is_taken_whatever_its_shape() {
let temp = TempDir::new().unwrap();
setup_worklane(&temp);
run(
&temp,
&[
"tags",
"add",
"bug",
"-a",
"A defect.",
"-a",
"",
"-a",
"--plan is prose",
],
);
assert_eq!(declared(&temp, "bug").as_deref(), Some("A defect.\n\n--plan is prose"));
}
/// The file is made on demand, the way `campaign add` makes the campaigns directory: a board
/// that predates the vocabulary must not need `worklane init` run over it.
#[test]