Compare commits

...
4 Commits
Author SHA1 Message Date
Ansho ReiandClaude Opus 5 b7781a830c (482ff01) Grey unset Due and Owner in ls, and bump to 0.1.2
display_ticket_items printed both fields raw, so a ticket with no due date
showed _Not set_ in the default foreground. show already honoured the
guideline through colorize_metadata, leaving the listing as the one place
that ignored it. Reuses is_unknown_value rather than matching the markers
a second time.

Grey is indexed colour 8 in the 256-colour form. Two SGR spellings were
tried against a real terminal and both read as white: 90 leans on the
palette's bright-black slot, and 37 can sit right on top of the default
foreground. \x1b[38;5;8m is byte for byte what crossterm emits for
ratatui's Color::DarkGray, which is the grey frig and pantop already use
for dimmed rows, so this is the spelling known to render here. Pinned by a
test and written down in AGENTS.md, since only an eye in a real terminal
would catch it drifting back.

Patch bump covering the three colour tickets, 9991698, 934bf1a and this
one, as one body of work: nothing new, three places where output did not
do what the guideline said.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-20 15:24:42 +02:00
Ansho ReiandClaude Opus 5 3abe8755c8 (934bf1a) Define magenta and keep bold markers when colour is off
colorize_line asked color_text for magenta, which get_color never
defined, so it returned an empty prefix: in a terminal the bold text got
a reset with no colour, and piped it lost the ** markers with nothing put
in their place. Every piped show and everything the opencode tools read
saw plain text where the ticket had emphasis.

Define magenta as the bold escape the guideline names, and leave the line
untouched when colour is off, because there the markers are the emphasis.
The scan is rewritten to hand back an unterminated run verbatim rather
than walking off the end, which used to drop the final character.

The scan now takes the enabled flag instead of asking for it, so both
paths are tested rather than only the one a test process happens to get.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-20 15:05:32 +02:00
Ansho ReiandClaude Opus 5 b6d0b55d4b (9991698) Respect NO_COLOR and non-capable terminals
should_use_colors only asked whether stdout was a terminal, so there was
no way to turn colour off in one, and it was re-evaluated on every
color_text call.

Honour NO_COLOR by the no-color.org rule, set and non-empty disables
whatever the value, with an empty value treated as unset so an inherited
one can be cleared. Treat TERM=dumb and an empty TERM as no colour.
Decide once in a OnceLock, since none of the three inputs change mid-run.

The decision itself is a pure function of its three inputs, so it is
tested without a pty. Verified under a real one as well: colour on by
default, absent with NO_COLOR=1, absent with TERM=dumb, present again
with NO_COLOR set to empty.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-20 15:04:41 +02:00
Ansho ReiandClaude Opus 5 3fcb0ddc0a Require a local tag alongside every version bump
Records the rule in the Version Bumps section: a bump carries a matching
annotated v<version> tag on the bump commit, kept local unless a push is
asked for. Tagged v0.1.1 on 8563218 retroactively, which was bumped
before the rule existed.

Docs only, so no bump and no tag for this one.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-20 15:01:56 +02:00
4 changed files with 189 additions and 26 deletions
+5 -2
View File
@@ -33,7 +33,7 @@
### Color and Output
- Use `color_text()` helper for colored output — it respects `should_use_colors()` (terminal detection)
- Color codes are defined in `get_color()`: red (31), cyan (36), orange (33), green (32), grey (90)
- Color codes are defined in `get_color()`: red (31), cyan (36), orange (33), green (32), grey (38;5;8), magenta (1;35)
- Reset color with `\x1b[0m` after colored text
- Bold uses `\x1b[1;35m` (magenta bold)
- Always test color output works correctly in both terminal and pipe modes
@@ -43,7 +43,8 @@
- Status → orange (33)
- Timestamp → cyan (36)
- Title → green (32)
- Unknown values (`_None_`, `_Not set_`) → grey (90)
- Unknown values (`_None_`, `_Not set_`) → grey (38;5;8)
- Grey is indexed colour 8 in the 256-colour form, not SGR 90 or 37. Both of those failed on a real palette: 90 leans on the bright-black slot and 37 can sit on top of the default foreground. `\x1b[38;5;8m` is byte for byte what crossterm emits for ratatui's `Color::DarkGray`, the grey frig and pantop use for dimmed rows
### Code Organization
- Colorization functions (`colorize_line`, `colorize_metadata`, `colorize_ordered`, `content_trim_colored`) handle markdown formatting
@@ -68,4 +69,6 @@
- No bump for docs-only, tests-only or `--fixup` commits
- When one body of work spans several commits, bump once on the final commit rather than on each
- Bump `Cargo.toml` and the `worklane` entry in `Cargo.lock` together, in the commit that carries the bump
- Every bump gets a matching annotated tag, `v<version>`, on the bump commit — a bumped version is never left untagged
- Tag locally only; never push a tag unless asked
- `worklane --version` reports the crate version alongside the build sha, so the bump is what makes one release distinguishable from another
Generated
+1 -1
View File
@@ -1029,7 +1029,7 @@ dependencies = [
[[package]]
name = "worklane"
version = "0.1.1"
version = "0.1.2"
dependencies = [
"anyhow",
"assert_cmd",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "worklane"
version = "0.1.1"
version = "0.1.2"
edition = "2024"
[dependencies]
+182 -22
View File
@@ -3,6 +3,7 @@ use chrono::NaiveDateTime;
use std::fs;
use std::io::IsTerminal;
use std::path::Path;
use std::sync::OnceLock;
/// How timestamps are written into tickets and comments, and therefore how they
/// are read back. Shared so the writer and the reader cannot drift apart.
@@ -15,8 +16,40 @@ pub const TIMESTAMP_FORMAT: &str = "%Y-%m-%d %H:%M:%S";
/// Fixed width, so the lexicographic sort in `read_comments` stays chronological.
pub const COMMENT_FILE_FORMAT: &str = "%Y%m%d_%H%M%S_%6f";
/// Whether colour is wanted, from the three inputs that decide it.
///
/// Split out from the caching wrapper so it can be tested without a pty and
/// without touching the process environment.
///
/// `NO_COLOR` follows the no-color.org convention: set and non-empty disables,
/// whatever the value. An empty value is treated as unset, which is what lets a
/// wrapper script clear an inherited one.
fn colors_wanted(is_terminal: bool, no_color: Option<&str>, term: Option<&str>) -> bool {
if no_color.is_some_and(|value| !value.is_empty()) {
return false;
}
if matches!(term, Some("dumb") | Some("")) {
return false;
}
is_terminal
}
pub fn should_use_colors() -> bool {
std::io::stdout().is_terminal()
// Decided once: it cannot change mid-run, and color_text asks on every call.
static ENABLED: OnceLock<bool> = OnceLock::new();
*ENABLED.get_or_init(|| {
let no_color = std::env::var("NO_COLOR").ok();
let term = std::env::var("TERM").ok();
colors_wanted(
std::io::stdout().is_terminal(),
no_color.as_deref(),
term.as_deref(),
)
})
}
pub fn get_color(color: &str) -> &'static str {
@@ -25,7 +58,15 @@ pub fn get_color(color: &str) -> &'static str {
"cyan" => "\x1b[36m",
"orange" => "\x1b[33m",
"green" => "\x1b[32m",
"grey" => "\x1b[90m",
// 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",
_ => "",
}
}
@@ -346,37 +387,53 @@ pub fn is_unknown_value(value: &str) -> bool {
}
pub fn colorize_line(line: &str) -> String {
let mut result = String::new();
colorize_bold(line, should_use_colors())
}
/// Replace `**bold**` with colour, or leave the line exactly as it is.
///
/// Taking `enabled` rather than asking makes both paths testable, and the
/// disabled path matters: stripping the markers when there is no colour to
/// replace them with loses the emphasis altogether, which is what happens to
/// every piped `show` and to everything the opencode tools read.
fn colorize_bold(line: &str, enabled: bool) -> String {
if !enabled {
return line.to_string();
}
let chars: Vec<char> = line.chars().collect();
let len = chars.len();
let mut result = String::new();
let mut i = 0;
while i < len {
// Check for **bold** markdown
if i + 1 < len && chars[i] == '*' && chars[i + 1] == '*' {
// Find closing **
let start = i + 2;
let mut end = start;
while end + 1 < len && !(chars[end] == '*' && chars[end + 1] == '*') {
if chars[end] == '\n' {
break;
}
end += 1;
}
let bold_text: String = chars[start..end].iter().collect();
result.push_str(&color_text(&bold_text, "magenta"));
i = end + 2;
while i < chars.len() {
if !is_delimiter(&chars, i) {
result.push(chars[i]);
i += 1;
continue;
}
result.push(chars[i]);
i += 1;
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"));
i = close + 2;
}
// Unterminated: the rest is literal. The old scan walked off the end
// here and dropped the final character.
None => {
result.extend(&chars[i..]);
return result;
}
}
}
result
}
fn is_delimiter(chars: &[char], at: usize) -> bool {
chars.get(at) == Some(&'*') && chars.get(at + 1) == Some(&'*')
}
pub fn parse_ticket_field(content: &str, field: &str) -> String {
let pattern = format!("**{}**:", field);
content
@@ -441,9 +498,24 @@ pub fn status_dirs() -> Vec<&'static str> {
pub type TicketItem = (String, String, String, String, String);
/// Grey for a value that is not set, per the colour guideline.
///
/// `show` already did this through `colorize_metadata`, so the listing was the
/// one place that ignored the rule.
fn dim_if_unset(value: &str) -> String {
if is_unknown_value(value) {
color_text(value, "grey")
} else {
value.to_string()
}
}
pub fn display_ticket_items(items: &Vec<TicketItem>) {
for (title, owner, due, uuid, ts) in items {
let uuid_colored = color_text(uuid, "red");
let owner = dim_if_unset(owner);
let due = dim_if_unset(due);
if ts.is_empty() {
println!(
" ({}) {} | Owner: {} | Due: {}",
@@ -495,6 +567,94 @@ pub fn collect_ticket_items(status_path: impl AsRef<Path>) -> Result<Vec<TicketI
mod tests {
use super::*;
#[test]
fn no_color_disables_colour_on_a_terminal() {
assert!(!colors_wanted(true, Some("1"), Some("xterm-256color")));
// Any value at all, per the convention
assert!(!colors_wanted(true, Some("0"), Some("xterm-256color")));
assert!(!colors_wanted(true, Some("false"), Some("xterm-256color")));
}
/// An empty value counts as unset, so a wrapper script can clear one it
/// inherited.
#[test]
fn an_empty_no_color_is_ignored() {
assert!(colors_wanted(true, Some(""), Some("xterm-256color")));
}
#[test]
fn a_dumb_terminal_gets_no_colour() {
assert!(!colors_wanted(true, None, Some("dumb")));
assert!(!colors_wanted(true, None, Some("")));
}
#[test]
fn colour_needs_a_terminal() {
assert!(colors_wanted(true, None, Some("xterm-256color")));
assert!(!colors_wanted(false, None, Some("xterm-256color")));
// No TERM at all is fine as long as it is a terminal
assert!(colors_wanted(true, None, None));
}
#[test]
fn unset_values_are_dimmed_and_set_ones_are_not() {
// Colour is off in a test process, so this asserts the decision, not the escape
for unset in ["_Not set_", "_None_"] {
assert!(is_unknown_value(unset), "{unset} should count as unset");
assert_eq!(dim_if_unset(unset), unset);
}
for set in ["alice", "2026-12-31", "bug,frontend"] {
assert!(!is_unknown_value(set));
assert_eq!(dim_if_unset(set), set);
}
}
#[test]
fn every_colour_the_code_asks_for_exists() {
for colour in ["red", "cyan", "orange", "green", "grey", "magenta"] {
assert!(!get_color(colour).is_empty(), "{colour} is not defined");
}
}
/// Pinned deliberately. Both SGR spellings of grey failed on a real palette,
/// 90 reading nearly as light as the foreground and 37 sitting on top of it.
/// This is the exact sequence crossterm emits for ratatui's Color::DarkGray,
/// 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");
}
/// With no colour to carry the emphasis, the markers are the emphasis.
#[test]
fn bold_markers_survive_when_colour_is_off() {
let line = "Some **bold** text";
assert_eq!(colorize_bold(line, false), line);
}
#[test]
fn bold_markers_are_replaced_when_colour_is_on() {
let out = colorize_bold("Some **bold** text", true);
assert!(out.contains("bold"), "was {out:?}");
assert!(!out.contains("**"), "markers left behind in {out:?}");
}
/// The old scan ran past the end here and dropped the last character.
#[test]
fn an_unterminated_marker_keeps_the_whole_line() {
for line in ["a **bold", "**", "***", "trailing **"] {
assert_eq!(colorize_bold(line, true), line, "for {line:?}");
}
}
#[test]
fn several_bold_runs_on_one_line_all_survive() {
let out = colorize_bold("**one** and **two** and rest", true);
assert!(out.contains("one") && out.contains("two") && out.ends_with("and rest"));
assert!(!out.contains("**"), "was {out:?}");
}
#[test]
fn short_id_shortens_a_full_uuid() {
assert_eq!(short_id("c230d2c6-d78a-44a5-8f5f-88fb28f84493"), "c230d2c");