Skip to content

Commit

Permalink
Add tabled for nicer printing (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Sep 23, 2022
1 parent b42b08a commit 65e6496
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
34 changes: 34 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ env_logger = { version = "0.9.0", default-features = false }
crosstermion = { version = "0.10.1", optional = true, default-features = false }
futures-lite = { version = "1.12.0", optional = true, default-features = false, features = ["std"] }

# for show-progress
# for progress
owo-colors = "3.5.0"
tabled = { version = "0.8.0", default-features = false }

document-features = { version = "0.2.0", optional = true }

Expand Down
19 changes: 15 additions & 4 deletions src/plumbing/progress.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crosstermion::crossterm::style::Stylize;
use owo_colors::OwoColorize;
use std::fmt::{Display, Formatter};
use tabled::{Style, TableIteratorExt, Tabled};

#[derive(Clone)]
enum Usage {
Expand Down Expand Up @@ -52,6 +52,18 @@ struct Record {
usage: Usage,
}

impl Tabled for Record {
const LENGTH: usize = 3;

fn fields(&self) -> Vec<String> {
vec![self.usage.icon().into(), self.config.into(), self.usage.to_string()]
}

fn headers() -> Vec<String> {
vec![]
}
}

static GIT_CONFIG: &[Record] = &[
Record {
config: "fetch.output",
Expand Down Expand Up @@ -80,8 +92,7 @@ pub fn show_progress() -> anyhow::Result<()> {
v
};

for Record { config, usage } in sorted {
println!("{} {}: {usage}", usage.icon(), config.bold(),);
}
println!("{}", sorted.table().with(Style::blank()));
println!("\nTotal records: {}", GIT_CONFIG.len());
Ok(())
}

0 comments on commit 65e6496

Please sign in to comment.