diff --git a/src/cli.rs b/src/cli.rs index ede5de4..ca58d29 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -12,6 +12,7 @@ pub struct Cli { pub enum FormatMode { Pretty, Json, + Compact, } impl std::fmt::Display for FormatMode { diff --git a/src/cmd/search.rs b/src/cmd/search.rs index 5781443..e2dd050 100644 --- a/src/cmd/search.rs +++ b/src/cmd/search.rs @@ -1,6 +1,6 @@ use crate::cli::FormatMode; use crate::jira_config::JiraConfig; -use crate::types::issue::{display_issues_json, display_issues_pretty}; +use crate::types::issue::{display_issues_compact, display_issues_json, display_issues_pretty}; pub async fn exec(output: FormatMode, jql: &str) -> Result<(), Box> { let config = JiraConfig::load().map_err(|e| format!("Configuration error: {}", e))?; @@ -26,6 +26,10 @@ pub async fn exec(output: FormatMode, jql: &str) -> Result<(), Box display_issues_json(&result.issues)?, (FormatMode::Json, true) => println!("[]"), + (FormatMode::Compact, false) => display_issues_compact(&result.issues)?, + (FormatMode::Compact, true) => { + println!("No results found for query."); + } } Ok(()) diff --git a/src/cmd/view.rs b/src/cmd/view.rs index 72cdeda..752fe5d 100644 --- a/src/cmd/view.rs +++ b/src/cmd/view.rs @@ -1,5 +1,6 @@ use crate::cli::FormatMode; use crate::jira_config::JiraConfig; +use crate::term::hyperlink; use crate::types::issue::JiraIssue; use crossterm::style::{Color, Stylize}; use std::io::Write; @@ -99,9 +100,11 @@ fn pretty_print(issue: &JiraIssue) -> Result<(), Box> { } println!("\n== Actions {:=<69}", ""); println!( - "\u{1b}]8;;{}\u{7}{}\u{1b}]8;;\u{7}", - issue.href, - "Open Issue".green().underline(Color::Green) + "{}", + hyperlink( + &issue.href, + &"Open Issue".green().underline(Color::Green).to_string() + ) ); Ok(()) @@ -142,6 +145,7 @@ pub async fn exec(output: FormatMode, issue_key: &str) -> Result<(), Box pretty_print(&fetched_issue)?, FormatMode::Json => json_print(&fetched_issue)?, + FormatMode::Compact => todo!(), } Ok(()) diff --git a/src/main.rs b/src/main.rs index 33d5ec2..199f533 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ mod cli; mod cmd; mod jira_config; mod jql; +mod term; mod types; use clap::Parser; @@ -19,7 +20,8 @@ async fn main() -> Result<(), Box> { markdown_file, } => cmd::create::create(project, open, markdown_file).await?, Commands::List { output } => { - let jql = "assignee = currentUser() AND resolution = Unresolved order by updated DESC"; + let jql = + "assignee = currentUser() AND resolution = Unresolved order by project,updated ASC"; cmd::search::exec(output, jql).await? } Commands::Search { output, jql } => cmd::search::exec(output, &jql).await?, diff --git a/src/term.rs b/src/term.rs new file mode 100644 index 0000000..1f2203c --- /dev/null +++ b/src/term.rs @@ -0,0 +1,3 @@ +pub fn hyperlink(url: &str, text: &str) -> String { + format!("\u{1b}]8;;{}\u{7}{}\u{1b}]8;;\u{7}", url, text) +} diff --git a/src/types/issue.rs b/src/types/issue.rs index 455cb1b..ac009a8 100644 --- a/src/types/issue.rs +++ b/src/types/issue.rs @@ -1,4 +1,5 @@ -use crossterm::style::Stylize; +use crate::term::hyperlink; +use crossterm::style::{Color, Stylize}; use serde::{Deserialize, Serialize}; use std::io::Write; @@ -107,9 +108,8 @@ pub fn display_issues_pretty(issues: &[JiraIssue]) -> Result<(), Box Result<(), Box Result<(), Box> { + println!("Found {} issues:", issues.len()); + println!("{:-<80}", ""); + + let mut tw = tabwriter::TabWriter::new(vec![]); + for issue in issues { + writeln!( + tw, + "{}:\t{}", + hyperlink( + &issue.href, + &issue.key.clone().blue().underline(Color::Blue).to_string() + ), + issue.fields.summary.clone().green() + )?; + } + + tw.flush().unwrap(); + let written = String::from_utf8(tw.into_inner().unwrap()).unwrap(); + print!("{}", written); + + Ok(()) +} + pub fn display_issues_json(issues: &[JiraIssue]) -> Result<(), Box> { let j = serde_json::to_string_pretty(issues)?; println!("{}", j);