Make the title headers on the view command always as big as the terminal width
This commit is contained in:
parent
8ce7882b38
commit
1e1835636f
1 changed files with 14 additions and 5 deletions
|
@ -2,20 +2,28 @@ use crate::cli::FormatMode;
|
|||
use crate::jira_config::JiraConfig;
|
||||
use crate::renderer::{hyperlink, render_doc};
|
||||
use crossterm::style::{Color, Stylize};
|
||||
use crossterm::terminal;
|
||||
use libjirac::client::commands::IssueGetCommand;
|
||||
use libjirac::client::JiraClient;
|
||||
use libjirac::entities::issue::{Description, JiraIssue};
|
||||
use std::io::Write;
|
||||
|
||||
fn print_header(title: &str, columns: usize) {
|
||||
let padding = columns - (title.len() + 4);
|
||||
println!("\n== {} {:=<width$}", title, "", width = padding);
|
||||
}
|
||||
|
||||
fn pretty_print(config: &JiraConfig, issue: &JiraIssue) -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("\n== Title {:=<71}", "");
|
||||
let (columns, _) = terminal::size()?;
|
||||
|
||||
print_header("Title", columns.into());
|
||||
println!(
|
||||
"{}: {}",
|
||||
issue.key.clone().green(),
|
||||
issue.fields.summary.clone().bold().green()
|
||||
);
|
||||
|
||||
println!("\n== Details {:=<69}", "");
|
||||
print_header("Details", columns.into());
|
||||
let mut tw = tabwriter::TabWriter::new(vec![]);
|
||||
writeln!(tw, "{}:\t{}", "Priority".blue(), issue.fields.priority.name)?;
|
||||
writeln!(tw, "{}:\t{}", "Status".blue(), issue.fields.status.name)?;
|
||||
|
@ -63,7 +71,7 @@ fn pretty_print(config: &JiraConfig, issue: &JiraIssue) -> Result<(), Box<dyn st
|
|||
|
||||
let written = String::from_utf8(tw.into_inner().unwrap()).unwrap();
|
||||
print!("{}", written);
|
||||
println!("\n== Description {:=<65}", "");
|
||||
print_header("Description", columns.into());
|
||||
match issue.fields.description.clone() {
|
||||
Some(x) => match x {
|
||||
Description::Doc(doc) => render_doc(doc)?,
|
||||
|
@ -71,7 +79,7 @@ fn pretty_print(config: &JiraConfig, issue: &JiraIssue) -> Result<(), Box<dyn st
|
|||
None => println!("(Issue does not have a description)"),
|
||||
}
|
||||
|
||||
println!("\n== Comments {:=<68}", "");
|
||||
print_header("Comments", columns.into());
|
||||
for comment in issue.fields.comment.clone().unwrap_or_default().comments {
|
||||
println!(
|
||||
"{} at {}",
|
||||
|
@ -80,7 +88,8 @@ fn pretty_print(config: &JiraConfig, issue: &JiraIssue) -> Result<(), Box<dyn st
|
|||
);
|
||||
render_doc(comment.body)?;
|
||||
}
|
||||
println!("\n== Actions {:=<69}", "");
|
||||
|
||||
print_header("Actions", columns.into());
|
||||
println!(
|
||||
"{}",
|
||||
hyperlink(
|
||||
|
|
Loading…
Reference in a new issue