cli: Use term::Table to print list of issues

Signed-off-by: Slack Coder <slackcoder@server.ky>
This commit is contained in:
Slack Coder 2022-12-19 13:08:41 -05:00 committed by Alexis Sellier
parent 946d6ac675
commit 6b67e0571e
No known key found for this signature in database
2 changed files with 10 additions and 6 deletions

View File

@ -233,6 +233,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
} }
} }
Operation::List => { Operation::List => {
let mut t = term::Table::new(term::table::TableOptions::default());
for result in issues.all()? { for result in issues.all()? {
let (id, issue, _) = result?; let (id, issue, _) = result?;
@ -241,12 +242,13 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
.map(|p| p.to_string()) .map(|p| p.to_string())
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(", "); .join(", ");
if assigned.is_empty() { t.push([
println!("{} \"{}\"", id, issue.title().escape_default()); id.to_string(),
} else { format!("{:?}", issue.title()),
println!("{} {:?} {}", id, issue.title().escape_default(), &assigned,); assigned.to_string(),
} ]);
} }
t.render();
} }
Operation::Delete { id } => { Operation::Delete { id } => {
issues.remove(&id)?; issues.remove(&id)?;

View File

@ -59,10 +59,12 @@ impl<const W: usize> Table<W> {
.ok(); .ok();
} }
} }
let output = output.trim_end();
println!( println!(
"{}", "{}",
if let Some(width) = width { if let Some(width) = width {
console::truncate_str(&output, width - 1, "") console::truncate_str(output, width - 1, "")
} else { } else {
output.into() output.into()
} }