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

View File

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