(101c2444) Add colours to ls command

This commit is contained in:
2026-05-15 02:18:04 +02:00
parent d668a24a3d
commit aef8002d23
3 changed files with 81 additions and 10 deletions
+41
View File
@@ -0,0 +1,41 @@
# AGENTS.md
## Project Structure
- `src/main.rs` - All application logic (init, add, ls, show, mv commands)
- `src/command.rs` - CLI argument definitions using clap derive
- `tests/` - Integration tests using `assert_cmd` and `assert_fs`
- Ticket files stored as `.md` in `.worklane/<status>/` directories
## Commands
| Command | Description |
|---------|-------------|
| `worklane init` | Creates `.worklane/` with backlog, committed, reviewing, done directories |
| `worklane add` | Creates a ticket in backlog with `--title`, `--description`, `--acceptance`, `--plan`, `--tags`, `--due`, `--owner` flags |
| `worklane ls` | Lists tickets, optionally filtered by `--status` |
| `worklane show <id>` | Shows ticket by UUID prefix or title |
| `worklane mv <id> --status <target> [-f]` | Moves ticket between statuses. Default: forward only, one stage at a time. `-f` bypasses both restrictions |
## Ticket File Format
Filenames: `<uuid_v4>_<slug>.md`
Metadata fields parsed: `ID`, `Tags`, `Due`, `Owner`, `Created At`, `Status`
## Status Workflow
`backlog` -> `committed` -> `reviewing` -> `done`
## Testing
Run: `cargo test`
Tests create temporary `.worklane` directories with all four status folders pre-created via `setup_worklane()`. Ticket helper `create_ticket()` writes fully-formed markdown files directly.
## Key Implementation Notes
- No database or index - tickets resolved by scanning all status directories
- `resolve_ticket()` matches by UUID prefix (8+ chars), title substring, or filename substring
- Ambiguous searches (multiple matches) exit with list of options
- Ticket metadata uses `**Field**:` format for parsing
- Color output uses ANSI escape codes in `content_trim_colored()`
## Agent workflow
- When working on a ticket use `worklane show [ticketID]` to read the ticket.
- If the ticket is in the backlog, move it to committed using `worklane mv --status committed [ticketID]`.
- When your changes meet the acceptance criteria and the code compiles, move the ticket to reviewing using `worklane mv --status reviewing [ticketID]`
+40 -5
View File
@@ -2,12 +2,36 @@ use anyhow::{Result, anyhow};
use chrono::Local;
use clap::Parser;
use std::fs;
use std::io::IsTerminal;
use std::path::Path;
mod command;
use command::*;
fn should_use_colors() -> bool {
std::io::stdout().is_terminal()
}
fn get_color(color: &str) -> &'static str {
match color {
"red" => "\x1b[31m",
"cyan" => "\x1b[36m",
"orange" => "\x1b[33m",
"green" => "\x1b[32m",
"grey" => "\x1b[90m",
_ => "",
}
}
fn color_text(text: &str, color: &str) -> String {
if should_use_colors() {
format!("{}{}{}", get_color(color), text, "\x1b[0m")
} else {
text.to_string()
}
}
fn find_worklane_dir(start: &Path) -> Result<std::path::PathBuf> {
let mut current = start.canonicalize()?;
@@ -139,12 +163,17 @@ fn cmd_ls(status_filter: &Option<String>, worklane_dir: &Path) -> Result<()> {
println!("Tickets in '{}' status:\n", status);
for (title, owner, due, uuid, ts) in items {
let uuid_colored = color_text(&uuid, "red");
if ts.is_empty() {
println!(" ({}) {} | Owner: {} | Due: {}", uuid, title, owner, due);
println!(
" ({}) {} | Owner: {} | Due: {}",
uuid_colored, title, owner, due
);
} else {
let ts_colored = color_text(&ts, "cyan");
println!(
" {} ({}) {} | Owner: {} | Due: {}",
ts, uuid, title, owner, due
ts_colored, uuid_colored, title, owner, due
);
}
}
@@ -198,14 +227,20 @@ fn cmd_ls(status_filter: &Option<String>, worklane_dir: &Path) -> Result<()> {
})
.collect();
items.sort_by(|a, b| a.0.to_lowercase().cmp(&b.0.to_lowercase()));
println!("\n[{}]", status.to_uppercase());
let status_header = color_text(&format!("[{}]", status.to_uppercase()), "orange");
println!("\n{}", status_header);
for (title, owner, due, uuid, ts) in items {
let uuid_colored = color_text(&uuid, "red");
if ts.is_empty() {
println!(" ({}) {} | Owner: {} | Due: {}", uuid, title, owner, due);
println!(
" ({}) {} | Owner: {} | Due: {}",
uuid_colored, title, owner, due
);
} else {
let ts_colored = color_text(&ts, "cyan");
println!(
" {} ({}) {} | Owner: {} | Due: {}",
ts, uuid, title, owner, due
ts_colored, uuid_colored, title, owner, due
);
}
}
-5
View File
@@ -64,11 +64,6 @@ fn get_stdout(cmd: &mut Command) -> String {
String::from_utf8(assert.get_output().stdout.clone()).unwrap()
}
fn get_stderr(cmd: &mut Command) -> String {
let assert = cmd.assert();
String::from_utf8(assert.get_output().stderr.clone()).unwrap()
}
#[test]
fn show_displays_ticket_by_full_uuid() {
let temp = TempDir::new().unwrap();