Skip to content

Commit

Permalink
upgrade tabled and setup wordwrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Dec 29, 2023
1 parent 29c5904 commit a78caba
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 9 deletions.
125 changes: 120 additions & 5 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,10 @@ tracing = { version = "0.1.37", optional = true }

# for progress
owo-colors = "4.0.0"
tabled = { version = "0.10.0", default-features = false }

# for config-tree
tabled = { version = "0.15.0", features = ["ansi"] }
terminal_size = "0.3.0"

# Avoid pre-compiled binaries, see https://github.com/serde-rs/serde/issues/2538 and https://github.com/serde-rs/serde/pull/2590
serde_derive = ">=1.0.185"
Expand Down
18 changes: 15 additions & 3 deletions src/plumbing/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use std::{

use crosstermion::crossterm::style::Stylize;
use owo_colors::OwoColorize;
use tabled::{Style, TableIteratorExt, Tabled};
use tabled::settings::peaker::PriorityMax;
use tabled::settings::{Extract, Style, Width};
use tabled::Tabled;

#[derive(Clone)]
enum Usage {
Expand Down Expand Up @@ -95,7 +97,7 @@ impl Tabled for Record {
}

fn headers() -> Vec<Cow<'static, str>> {
vec![]
vec!["icon".into(), "key".into(), "info".into()]
}
}

Expand Down Expand Up @@ -572,7 +574,17 @@ pub fn show_progress() -> anyhow::Result<()> {
.filter(|e| matches!(e.usage, NotApplicable { .. }))
.count()
)?;
println!("{}", sorted.table().with(Style::blank()));

let mut table = tabled::Table::new(sorted);
let table = table.with(Style::blank()).with(Extract::rows(1..));
println!(
"{}",
if let Some((terminal_size::Width(w), _)) = terminal_size::terminal_size() {
table.with(Width::wrap(w as usize).keep_words().priority::<PriorityMax>())
} else {
table
}
);
println!("{buf}");
Ok(())
}

0 comments on commit a78caba

Please sign in to comment.