(3b7edd7) Show priority as a glyph, and bump to 0.2.0
A bare digit in a listing is easy to skip over. Levels render as a two-segment meter that empties as the level rises: ●● 1, ●◐ 2, ●○ 3, ◐○ 4, ○○ 5, with ·· for unset and ?? for a value outside the range. Only ●, ◐, ○ and · are used, because they are what frig draws for its status indicators and so are known to be in the terminal font. The first cut of this used the quadrant circles ◕ and ◔, which are in a quarter as many fonts, so terminals substituted them from a fallback that drew them oversized and the column came out ragged. Two cells of a three-level ramp gives five steps of ink, 2, 1.5, 1, 0.5, 0, without leaving that safe set. Tests pin the safe set, the equal width and the monotonic emptying. The mark carries the level on its own, because colour cannot. Output is colourless whenever it is piped, which is how the opencode tools and every script read it, and NO_COLOR turns it off in a terminal too. Colour only accentuates: brightred, red, orange, cyan, grey, skipping green because green means title. The number counts up while the meter empties, since 1 is the most urgent. That is the convention, but it reads as a bug unless written down, so it is in AGENTS.md and in the legend. Both the ramp and the legend come from priority_mark, and `ls --help` prints the legend, since nothing in a listing explains a mark. brightred is indexed like grey, for the same reason: it is the spelling that renders. Minor bump: two new flags, a new metadata field and a changed ls row, covering dca0b61 and this ticket. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
ddbd45e332
commit
2503f9aee9
+8
-1
@@ -1,6 +1,12 @@
|
||||
use clap::Parser;
|
||||
|
||||
use crate::util::PRIORITY_RANGE;
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use crate::util::{PRIORITY_RANGE, priority_legend};
|
||||
|
||||
/// clap wants a `&str` with a long enough lifetime, and the legend is built from
|
||||
/// the same ramp the listing uses rather than spelled out a second time.
|
||||
static PRIORITY_LEGEND: LazyLock<String> = LazyLock::new(priority_legend);
|
||||
|
||||
/// Reject a level outside the range at parse time, so no command has to.
|
||||
fn priority_level(raw: &str) -> Result<u8, String> {
|
||||
@@ -72,6 +78,7 @@ pub enum Command {
|
||||
},
|
||||
|
||||
/// List tickets, optionally filtered by status
|
||||
#[command(after_help = PRIORITY_LEGEND.as_str())]
|
||||
Ls {
|
||||
/// Filter by status (backlog, committed, reviewing, done)
|
||||
status: Option<String>,
|
||||
|
||||
+168
-6
@@ -67,6 +67,8 @@ pub fn get_color(color: &str) -> &'static str {
|
||||
// Bold, per the guideline in AGENTS.md. Its absence meant colorize_line
|
||||
// asked for a colour that did not exist and got an empty prefix.
|
||||
"magenta" => "\x1b[1;35m",
|
||||
// Indexed, for the same reason grey is: this is the spelling that renders.
|
||||
"brightred" => "\x1b[38;5;9m",
|
||||
_ => "",
|
||||
}
|
||||
}
|
||||
@@ -349,6 +351,21 @@ pub fn colorize_metadata(line: &str) -> String {
|
||||
return line.to_string();
|
||||
}
|
||||
|
||||
// Priority reads as a glyph here too, while the file keeps storing the number.
|
||||
if let Some(value) = line.split("**Priority**:").nth(1) {
|
||||
let priority = match value.trim().parse::<u8>() {
|
||||
Ok(level) if PRIORITY_RANGE.contains(&level) => Priority::Level(level),
|
||||
_ if is_unknown_value(value.trim()) => Priority::Unset,
|
||||
_ => Priority::Invalid,
|
||||
};
|
||||
return format!(
|
||||
"- {}: {} {}",
|
||||
color_text("Priority", "red"),
|
||||
show_priority(priority),
|
||||
value.trim()
|
||||
);
|
||||
}
|
||||
|
||||
let content = line;
|
||||
let open_pos = match content.find("**") {
|
||||
Some(p) => p,
|
||||
@@ -557,15 +574,54 @@ fn dim_if_unset(value: &str) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/// How a level reads in a listing.
|
||||
fn show_priority(priority: Priority) -> String {
|
||||
/// The mark and colour for a level, from one place.
|
||||
///
|
||||
/// A two-segment meter that empties as the level rises, so the level is legible
|
||||
/// from shape alone: colour is off whenever output is piped, and NO_COLOR turns it
|
||||
/// off in a terminal too, so colour accentuates and never encodes.
|
||||
///
|
||||
/// Only three glyphs, the ones frig uses for its status indicators and which are
|
||||
/// therefore known to render here. The quadrant circles this first used are in a
|
||||
/// quarter as many fonts, so terminals substituted them from a fallback font that
|
||||
/// draws them oversized. Two cells of a three-level ramp gives five steps of ink,
|
||||
/// 2, 1.5, 1, 0.5, 0, without leaving that safe set.
|
||||
///
|
||||
/// The number counts up while the mark empties out, because 1 is the most urgent.
|
||||
/// That is the convention every tracker uses and what the p1 tags this replaced
|
||||
/// already meant.
|
||||
pub fn priority_mark(priority: Priority) -> (&'static str, &'static str) {
|
||||
match priority {
|
||||
Priority::Level(level) => level.to_string(),
|
||||
Priority::Unset => color_text("-", "grey"),
|
||||
Priority::Invalid => color_text("?", "red"),
|
||||
Priority::Level(1) => ("\u{25cf}\u{25cf}", "brightred"),
|
||||
Priority::Level(2) => ("\u{25cf}\u{25d0}", "red"),
|
||||
Priority::Level(3) => ("\u{25cf}\u{25cb}", "orange"),
|
||||
Priority::Level(4) => ("\u{25d0}\u{25cb}", "cyan"),
|
||||
Priority::Level(5) => ("\u{25cb}\u{25cb}", "grey"),
|
||||
// Unreachable while Level is only built by parse_priority, which checks
|
||||
// the range, but a level added later should not silently render blank.
|
||||
Priority::Level(_) | Priority::Invalid => ("??", "brightred"),
|
||||
Priority::Unset => ("\u{b7}\u{b7}", "grey"),
|
||||
}
|
||||
}
|
||||
|
||||
/// The legend, for help text. Nothing else in a listing explains the glyphs.
|
||||
pub fn priority_legend() -> String {
|
||||
let levels = PRIORITY_RANGE
|
||||
.map(|level| {
|
||||
let (glyph, _) = priority_mark(Priority::Level(level));
|
||||
format!("{} {}", glyph, level)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ");
|
||||
|
||||
let (unset, _) = priority_mark(Priority::Unset);
|
||||
format!("Priority: {levels} {unset} unset 1 is most urgent")
|
||||
}
|
||||
|
||||
fn show_priority(priority: Priority) -> String {
|
||||
let (glyph, colour) = priority_mark(priority);
|
||||
color_text(glyph, colour)
|
||||
}
|
||||
|
||||
pub fn display_ticket_items(items: &[TicketItem]) {
|
||||
for item in items {
|
||||
let id = color_text(&item.id, "red");
|
||||
@@ -720,9 +776,115 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn each_level_gets_its_own_glyph_and_colour() {
|
||||
let marks: Vec<_> = PRIORITY_RANGE
|
||||
.map(|level| priority_mark(Priority::Level(level)))
|
||||
.collect();
|
||||
|
||||
let glyphs: std::collections::HashSet<_> = marks.iter().map(|(g, _)| *g).collect();
|
||||
assert_eq!(glyphs.len(), marks.len(), "two levels share a glyph");
|
||||
|
||||
let colours: std::collections::HashSet<_> = marks.iter().map(|(_, c)| *c).collect();
|
||||
assert_eq!(colours.len(), marks.len(), "two levels share a colour");
|
||||
}
|
||||
|
||||
/// The glyph has to carry the level with colour off, which is how every pipe
|
||||
/// and every opencode tool reads it.
|
||||
#[test]
|
||||
fn the_glyph_alone_distinguishes_every_state() {
|
||||
let mut seen = std::collections::HashSet::new();
|
||||
for state in PRIORITY_RANGE.map(Priority::Level).chain([Priority::Unset, Priority::Invalid]) {
|
||||
let (glyph, _) = priority_mark(state);
|
||||
assert!(seen.insert(glyph), "{glyph} is used for more than one state");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_fullest_mark_is_the_most_urgent() {
|
||||
assert_eq!(priority_mark(Priority::Level(1)).0, "\u{25cf}\u{25cf}");
|
||||
assert_eq!(priority_mark(Priority::Level(5)).0, "\u{25cb}\u{25cb}");
|
||||
}
|
||||
|
||||
/// Every mark is the same width, or the column stops lining up.
|
||||
#[test]
|
||||
fn every_mark_is_the_same_width() {
|
||||
let widths: std::collections::HashSet<usize> = PRIORITY_RANGE
|
||||
.map(Priority::Level)
|
||||
.chain([Priority::Unset, Priority::Invalid])
|
||||
.map(|p| priority_mark(p).0.chars().count())
|
||||
.collect();
|
||||
assert_eq!(widths, std::collections::HashSet::from([2]));
|
||||
}
|
||||
|
||||
/// The marks are built only from what frig already renders in this terminal:
|
||||
/// the quadrant circles are in a quarter as many fonts and got substituted
|
||||
/// from a fallback font that drew them oversized.
|
||||
#[test]
|
||||
fn marks_use_only_the_glyphs_known_to_render() {
|
||||
let allowed = ['\u{25cf}', '\u{25d0}', '\u{25cb}', '\u{b7}', '?'];
|
||||
for state in PRIORITY_RANGE
|
||||
.map(Priority::Level)
|
||||
.chain([Priority::Unset, Priority::Invalid])
|
||||
{
|
||||
for ch in priority_mark(state).0.chars() {
|
||||
assert!(allowed.contains(&ch), "{ch:?} is outside the safe set");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_meter_empties_as_the_level_rises() {
|
||||
let ink = |p: Priority| -> f32 {
|
||||
priority_mark(p)
|
||||
.0
|
||||
.chars()
|
||||
.map(|c| match c {
|
||||
'\u{25cf}' => 1.0,
|
||||
'\u{25d0}' => 0.5,
|
||||
_ => 0.0,
|
||||
})
|
||||
.sum()
|
||||
};
|
||||
let mut previous = f32::MAX;
|
||||
for level in PRIORITY_RANGE {
|
||||
let current = ink(Priority::Level(level));
|
||||
assert!(current < previous, "level {level} does not empty further");
|
||||
previous = current;
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_invalid_level_is_marked_wrong_not_unset() {
|
||||
assert_eq!(priority_mark(Priority::Invalid).0, "??");
|
||||
assert_ne!(
|
||||
priority_mark(Priority::Invalid),
|
||||
priority_mark(Priority::Unset)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_legend_covers_every_level_and_says_which_way_it_runs() {
|
||||
let legend = priority_legend();
|
||||
for level in PRIORITY_RANGE {
|
||||
let (glyph, _) = priority_mark(Priority::Level(level));
|
||||
assert!(legend.contains(glyph), "{glyph} missing from the legend");
|
||||
assert!(legend.contains(&level.to_string()));
|
||||
}
|
||||
assert!(legend.contains("most urgent"), "direction not spelled out");
|
||||
}
|
||||
|
||||
/// Green means title; a priority must not borrow it.
|
||||
#[test]
|
||||
fn the_ramp_avoids_green() {
|
||||
for level in PRIORITY_RANGE {
|
||||
assert_ne!(priority_mark(Priority::Level(level)).1, "green");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_colour_the_code_asks_for_exists() {
|
||||
for colour in ["red", "cyan", "orange", "green", "grey", "magenta"] {
|
||||
for colour in ["red", "cyan", "orange", "green", "grey", "magenta", "brightred"] {
|
||||
assert!(!get_color(colour).is_empty(), "{colour} is not defined");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user