(1e7b1a9) Colour a tag by its name, and bump to 0.13.2

FNV-1a over the tag bytes into an eight-colour reserved palette, so the same
tag is the same colour on every card and on every board with nothing stored.
The hash is written out rather than taken from std, whose output is not
promised stable across releases.

The index is multiply-shift, not `% len`. The length is a power of two, so a
modulus keeps the low three bits of the hash, and FNV-1a's low bits carry
only the low bits of the input bytes: nothing moves information downwards.
Every pair of tags differing above bit 2 landed in one slot, `bug` and `BUG`
among them. It looked like a good palette, two colliding cards in sixty-four
on this board, because the vocabulary had been folded into a handful of
slots. Using the whole hash gives 14/64, which is the real arithmetic for
eight colours.

The palette is reserved as a list and disjoint from the seven colours that
already mean something: a tag in red reads as a uuid, in green as a title.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ansho Rei
2026-08-22 03:13:56 +02:00
co-authored by Claude Opus 5
parent 8d8ae8abfe
commit 7a0dd625ce
5 changed files with 302 additions and 12 deletions
+33 -9
View File
@@ -921,6 +921,10 @@ fn card_lines(card: &Card, selected: bool, width: u16) -> Vec<Line<'static>> {
/// corner: a cut list reads as a shorter one, and `bug` and `bugfix` truncated to the
/// same width say the same thing. An untagged ticket spends no row at all, the way a
/// short title spends no second one.
///
/// Each tag carries its own colour, from `tag_color`, so the same tag is the same
/// colour on every card in every column. The row is spans rather than one string for
/// that reason alone; it is still measured as one string.
fn tags_line(tags: &[String], width: u16) -> Option<Line<'static>> {
if tags.is_empty() {
return None;
@@ -932,14 +936,25 @@ fn tags_line(tags: &[String], width: u16) -> Option<Line<'static>> {
.collect::<Vec<_>>()
.join(" ");
// Measured on the raw row, before anything is styled. What fits must not depend on
// the colour decision, or a card would hold its tags in one render and drop them in
// the other.
if row.chars().count() > width as usize {
return None;
}
Some(Line::from(Span::styled(
row,
Style::default().fg(Color::Grey.into()),
)))
let mut spans = Vec::with_capacity(tags.len() * 2);
for (index, tag) in tags.iter().enumerate() {
if index > 0 {
spans.push(Span::raw(" "));
}
spans.push(Span::styled(
format!("#{tag}"),
Style::default().fg(tag_color(tag).into()),
));
}
Some(Line::from(spans))
}
/// The project name as it fits beside the mark and the id.
@@ -1645,14 +1660,23 @@ mod tests {
assert!(rows[3].starts_with("alice"), "the owner moved: {rows:?}");
}
/// Dimmed like the owner and the count beside it: the row is there to be scanned,
/// not to compete with the title.
/// Each tag carries its own colour, so the row can be scanned for one tag rather
/// than read word by word. The row used to be a single grey span, which is what
/// made a card of three tags one undifferentiated run.
#[test]
fn the_tag_row_is_dimmed() {
fn each_tag_on_a_card_carries_its_own_colour() {
let dir = board_dir();
write_tagged_card(&dir, "Short", "2026-12-31", "- [ ] One", "cli, tui");
write_tagged_card(&dir, "Short", "2026-12-31", "- [ ] One", "cli, docs");
assert_eq!(card_colour(&dir, 120, "#cli #tui"), Some(Color::Grey.into()));
let cli = card_colour(&dir, 120, "#cli");
let docs = card_colour(&dir, 120, "#docs");
// Through `tag_color`, not against a literal: the card has to use the mapping,
// and the mapping is pinned by its own test in util.rs.
assert_eq!(cli, Some(tag_color("cli").into()));
assert_eq!(docs, Some(tag_color("docs").into()));
assert_ne!(cli, docs, "two tags rendered in one colour");
assert_ne!(cli, Some(Color::Grey.into()), "the row is still flat grey");
}
/// And an untagged one spends no row on them, the way a short title spends no