(94a9d69) Add colours to show output
This commit is contained in:
+173
-14
@@ -60,20 +60,18 @@ fn cmd_init(start: &Path) -> Result<()> {
|
||||
}
|
||||
|
||||
fn parse_ticket_field(content: &str, field: &str) -> String {
|
||||
let pattern = format!("**{}**", field);
|
||||
let pattern = format!("**{}**:", field);
|
||||
content
|
||||
.lines()
|
||||
.find(|line| line.contains(&pattern))
|
||||
.map(|line| {
|
||||
line.split(':')
|
||||
line.splitn(2, &pattern)
|
||||
.nth(1)
|
||||
.unwrap_or("")
|
||||
.trim()
|
||||
.trim_matches('_')
|
||||
.unwrap_or("_Not set_")
|
||||
.trim()
|
||||
.to_string()
|
||||
})
|
||||
.unwrap_or("_Not set_")
|
||||
.to_string()
|
||||
.unwrap_or("_Not set_".to_string())
|
||||
}
|
||||
|
||||
fn format_created_at(created_at: &str) -> String {
|
||||
@@ -252,10 +250,10 @@ fn cmd_add(
|
||||
- **ID**: {}\n\
|
||||
- **Tags**: {}\n\
|
||||
- **Due**: {}\n\
|
||||
- **Owner**: {}\n\
|
||||
- **Created At**: {}\n\
|
||||
- **Status**: backlog\n\
|
||||
",
|
||||
- **Owner**: {}\n\
|
||||
- **Created At**: {}\n\
|
||||
- **Status**: backlog\n\
|
||||
",
|
||||
title,
|
||||
description_text,
|
||||
if acceptance.is_empty() {
|
||||
@@ -354,13 +352,174 @@ fn cmd_show(search: &str, worklane_dir: &Path) -> Result<()> {
|
||||
|
||||
let (_status, title, content) = matches.remove(0);
|
||||
|
||||
println!("{}\n", title);
|
||||
println!("{} ", "─".repeat(title.len()));
|
||||
println!("\n{}", content.trim());
|
||||
println!("{}", title);
|
||||
println!("{}", "─".repeat(title.len()));
|
||||
println!("\n{}", content_trim_colored(&content));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn content_trim_colored(content: &str) -> String {
|
||||
let lines: Vec<&str> = content.trim().lines().collect();
|
||||
let mut result = String::new();
|
||||
let mut current_section = "";
|
||||
|
||||
for (_, line) in lines.iter().enumerate() {
|
||||
// Track current section
|
||||
if line.starts_with("## ") {
|
||||
current_section = line;
|
||||
let section_name = &line[3..];
|
||||
result.push_str(&format!("\x1b[33m{}\x1b[0m", section_name));
|
||||
result.push('\n');
|
||||
result.push_str(&"─".repeat(line.len()));
|
||||
result.push('\n');
|
||||
result.push('\n');
|
||||
continue;
|
||||
}
|
||||
|
||||
// First line is the title header - color it in green
|
||||
if line.starts_with("# ") && current_section.is_empty() {
|
||||
let header = &line[2..]; // Remove "# "
|
||||
result.push_str(&format!("\x1b[32m{}\x1b[0m", header));
|
||||
result.push('\n');
|
||||
continue;
|
||||
}
|
||||
|
||||
// Implementation Plan - color numbers in cyan
|
||||
if current_section == "## Implementation Plan" {
|
||||
result.push_str(&colorize_ordered(line));
|
||||
result.push('\n');
|
||||
continue;
|
||||
}
|
||||
|
||||
// Metadata - color field names in RED
|
||||
if current_section == "## Metadata" {
|
||||
result.push_str(&colorize_metadata(line));
|
||||
result.push('\n');
|
||||
continue;
|
||||
}
|
||||
|
||||
// Acceptance Criteria checkboxes
|
||||
if line.starts_with("- [ ]") {
|
||||
result.push_str("\x1b[90m- [ ]\x1b[0m");
|
||||
result.push_str(&line[5..]);
|
||||
result.push('\n');
|
||||
continue;
|
||||
}
|
||||
|
||||
// Standard markdown link colorization in cyan
|
||||
if line.contains("[") && line.contains("(") && line.contains("]") {
|
||||
if let Some(start) = line.find("[") {
|
||||
let bracket_text = &line[start..];
|
||||
if let Some(end_bracket) = bracket_text.find("](") {
|
||||
let link_start = start + end_bracket + 1;
|
||||
if let Some(end) = line[link_start..].find(']') {
|
||||
let absolute_end = link_start + end + 1;
|
||||
result.push_str("\x1b[36m");
|
||||
result.push_str(&line[start..absolute_end]);
|
||||
result.push_str("\x1b[0m");
|
||||
result.push('\n');
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Regular content - colorize **bold** in magenta
|
||||
result.push_str(&colorize_line(line));
|
||||
result.push('\n');
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
fn colorize_ordered(line: &str) -> String {
|
||||
if line.chars().next().map_or(true, |c| !c.is_ascii_digit()) {
|
||||
return line.to_string();
|
||||
}
|
||||
|
||||
// Match "1. " pattern and color the number in cyan
|
||||
let mut result = String::new();
|
||||
let chars: Vec<char> = line.chars().collect();
|
||||
|
||||
for (i, c) in chars.iter().enumerate() {
|
||||
if c.is_ascii_digit() {
|
||||
// still scanning digits
|
||||
} else if *c == '.' && i + 1 < chars.len() && chars[i + 1] == ' ' {
|
||||
let number = &line[..i + 1];
|
||||
result.push_str(&format!("\x1b[36m{}\x1b[0m", number));
|
||||
result.push_str(&line[i + 1..]);
|
||||
return result;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
line.to_string()
|
||||
}
|
||||
|
||||
fn colorize_metadata(line: &str) -> String {
|
||||
if !line.contains("**") {
|
||||
return line.to_string();
|
||||
}
|
||||
|
||||
let content = line;
|
||||
let open_pos = match content.find("**") {
|
||||
Some(p) => p,
|
||||
None => return content.to_string(),
|
||||
};
|
||||
|
||||
let after_open = open_pos + 2;
|
||||
let remaining = &content[after_open..];
|
||||
let close_pos = match remaining.find("**") {
|
||||
Some(p) => p,
|
||||
None => return content.to_string(),
|
||||
};
|
||||
|
||||
let field_name = &content[after_open..after_open + close_pos];
|
||||
let after_field = &content[after_open + close_pos + 2..];
|
||||
|
||||
format!(
|
||||
"{}{}{}{}",
|
||||
&content[..open_pos],
|
||||
"\x1b[31m",
|
||||
field_name,
|
||||
"\x1b[0m"
|
||||
) + after_field
|
||||
}
|
||||
|
||||
fn colorize_line(line: &str) -> String {
|
||||
let mut result = String::new();
|
||||
let chars: Vec<char> = line.chars().collect();
|
||||
let len = chars.len();
|
||||
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(&format!("\x1b[1;35m{}\x1b[0m", bold_text));
|
||||
i = end + 2;
|
||||
continue;
|
||||
}
|
||||
|
||||
result.push(chars[i]);
|
||||
i += 1;
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let cli = Cli::parse();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user