(8020e48) Quote a comment behind a gutter bar that survives wrapping, and bump to 0.32.4
This commit is contained in:
+126
-83
@@ -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
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user