From 5548020576041270fe13a8fe9e51f4d454434429 Mon Sep 17 00:00:00 2001 From: Canop Date: Sun, 20 Aug 2023 09:28:21 +0200 Subject: --ascii Fix #43 --- CHANGELOG.md | 3 ++ Cargo.lock | 108 ++++++++++++++++++++++++++++++++------------------- cli/Cargo.toml | 5 +-- cli/src/args.rs | 6 ++- cli/src/help.rs | 5 ++- cli/src/lib.rs | 4 +- cli/src/list_cols.rs | 7 +++- cli/src/table.rs | 33 ++++++++++++---- 8 files changed, 115 insertions(+), 56 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65298e2..429e6ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +### next +- `--ascii` - Fix #43 + ### v2.7.2 - 2023/08/03 - examples in `--help` diff --git a/Cargo.lock b/Cargo.lock index 5b902da..14f30f6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "aho-corasick" -version = "0.7.20" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" +checksum = "6748e8def348ed4d14996fa801f4122cd763fff530258cdc03f64b25f89d3a5a" dependencies = [ "memchr", ] @@ -109,12 +109,12 @@ dependencies = [ [[package]] name = "clap-help" -version = "0.6.2" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f06bd287cb07754f8337478ac48ce3737ddbcf729345a607338ffcdff0d908c" +checksum = "542031cd21cd56842924c779171af859783a04063e2ede297aa9fa0ffbb8a9b3" dependencies = [ "clap", - "termimad 0.23.2", + "termimad", "terminal-light", ] @@ -303,7 +303,7 @@ dependencies = [ "lfs-core", "serde", "serde_json", - "termimad 0.20.5", + "termimad", ] [[package]] @@ -368,7 +368,18 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae9656bf98b413727b974a451039bc00ce546c3de9440cb4a7b65222b71e17cc" dependencies = [ - "lazy-regex-proc_macros", + "lazy-regex-proc_macros 2.3.1", + "once_cell", + "regex", +] + +[[package]] +name = "lazy-regex" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57451d19ad5e289ff6c3d69c2a2424652995c42b79dafa11e9c4d5508c913c01" +dependencies = [ + "lazy-regex-proc_macros 3.0.1", "once_cell", "regex", ] @@ -385,13 +396,25 @@ dependencies = [ "syn 1.0.105", ] +[[package]] +name = "lazy-regex-proc_macros" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f0a1d9139f0ee2e862e08a9c5d0ba0470f2aa21cd1e1aa1b1562f83116c725f" +dependencies = [ + "proc-macro2", + "quote", + "regex", + "syn 2.0.26", +] + [[package]] name = "lfs-core" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c4441d37490f59d2fdc631e6be973ce8712435e4bfebe9615125b11603cd41f" dependencies = [ - "lazy-regex", + "lazy-regex 2.3.1", "libc", "snafu", ] @@ -453,18 +476,9 @@ dependencies = [ [[package]] name = "minimad" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "277639f0198568f70f8fe4ab88a52a67c96bca12f27ba5c17a76acdcb8b45834" -dependencies = [ - "once_cell", -] - -[[package]] -name = "minimad" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b136454924e4d020e55c4992e07c105b40d5c41b84662862f0e15bc0a2efef" +checksum = "f6c4610f430e49b882fcaad0186134150d4d74fc76080b0a61f7000460c2e268" dependencies = [ "once_cell", ] @@ -552,9 +566,21 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.0" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81bc1d4caf89fac26a70747fe603c130093b53c773888797a6329091246d651a" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" +checksum = "fed1ceff11a1dddaee50c9dc8e4938bd106e9d89ae372f192311e7da498e3b69" dependencies = [ "aho-corasick", "memchr", @@ -563,9 +589,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.28" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" +checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" [[package]] name = "roff" @@ -603,6 +629,20 @@ name = "serde" version = "1.0.150" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e326c9ec8042f1b5da33252c8a37e9ffbd2c9bef0155215b6e6c80c790e05f91" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.150" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42a3df25b0713732468deadad63ab9da1f1fd75a48a15024b50363f128db627e" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.105", +] [[package]] name = "serde_json" @@ -703,28 +743,16 @@ dependencies = [ [[package]] name = "termimad" -version = "0.20.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eebc2b56ff63378c3f6c99245ca8e8f910f08ef441c5c89854d63e7f687f1f04" -dependencies = [ - "coolor", - "crossbeam", - "crossterm", - "minimad 0.9.1", - "thiserror", - "unicode-width", -] - -[[package]] -name = "termimad" -version = "0.23.2" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e32883199fc52cda7e431958dee8bc3ec6898afabc152b76959b9e0e74e2202" +checksum = "29bffc8a18091227aeac7ccbf7ccc0359a4b7d4c0b53a4a7680050aae05a0b31" dependencies = [ "coolor", "crossbeam", "crossterm", - "minimad 0.12.0", + "lazy-regex 3.0.1", + "minimad", + "serde", "thiserror", "unicode-width", ] diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 97e266f..0bde4d8 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -10,14 +10,13 @@ rust-version = "1.59" [dependencies] bet = "1.0.0" clap = { version = "4.3", features = ["derive", "cargo"] } -clap-help = "0.6.2" +clap-help = "0.7.0" crossterm = "0.23.2" file-size = "1.0.3" lfs-core = "0.11.0" serde = "1.0" serde_json = "1.0" -termimad = "0.20.5" +termimad = "0.25.0" [profile.release] strip = true - diff --git a/cli/src/args.rs b/cli/src/args.rs index f1c7e56..f65eee1 100644 --- a/cli/src/args.rs +++ b/cli/src/args.rs @@ -29,10 +29,14 @@ pub struct Args { #[arg(short, long)] pub all: bool, - /// Whether to have styles and colors + /// whether to have styles and colors #[arg(long, default_value="auto", value_name = "color")] pub color: TriBool, + /// use only ASCII characters for table rendering + #[arg(long)] + pub ascii: bool, + /// fetch stats of remote volumes #[arg(long, default_value="auto", value_name = "choice")] pub remote_stats: TriBool, diff --git a/cli/src/help.rs b/cli/src/help.rs index ee6851d..f56a91e 100644 --- a/cli/src/help.rs +++ b/cli/src/help.rs @@ -75,12 +75,15 @@ static EXAMPLES: &[Example] = &[ ), ]; -pub fn print() { +pub fn print(ascii: bool) { let mut printer = clap_help::Printer::new(Args::command()) .with("introduction", INTRO_TEMPLATE) .without("author"); printer.template_keys_mut().push("examples"); printer.set_template("examples", EXAMPLES_TEMPLATE); + if ascii { + printer.skin_mut().limit_to_ascii(); + } for (i, example) in EXAMPLES.iter().enumerate() { printer .expander_mut() diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 64fd253..ec87f9b 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -34,11 +34,11 @@ pub fn run() { return; } if args.help { - help::print(); + help::print(args.ascii); return; } if args.list_cols { - list_cols::print(args.color()); + list_cols::print(args.color(), args.ascii); return; } let mut options = lfs_core::ReadOptions::default(); diff --git a/cli/src/list_cols.rs b/cli/src/list_cols.rs index b5da76f..ea680b4 100644 --- a/cli/src/list_cols.rs +++ b/cli/src/list_cols.rs @@ -25,7 +25,7 @@ ${column "#; /// Print an help text describing columns -pub fn print(color: bool) { +pub fn print(color: bool, ascii: bool) { let mut expander = OwningTemplateExpander::new(); expander.set_default(""); for &col in ALL_COLS { @@ -35,11 +35,14 @@ pub fn print(color: bool) { .set("default", if col.is_default() { "x" } else { "" }) .set("description", col.description()); } - let skin = if color { + let mut skin = if color { MadSkin::default() } else { MadSkin::no_style() }; + if ascii { + skin.limit_to_ascii(); + } skin.print_owning_expander_md(&expander, MD); } diff --git a/cli/src/table.rs b/cli/src/table.rs index d048529..7a64163 100644 --- a/cli/src/table.rs +++ b/cli/src/table.rs @@ -45,32 +45,33 @@ pub fn print(mounts: &[&Mount], color: bool, args: &Args) { } if let Some(stats) = mount.stats() { let use_share = stats.use_share(); - let pb = ProgressBar::new(use_share as f32, BAR_WIDTH); sub .set("size", units.fmt(stats.size())) .set("used", units.fmt(stats.used())) .set("use-percents", format!("{:.0}%", 100.0 * use_share)) - .set("bar", format!("{: "${type}", Col::Remote => "${remote}", Col::Used => "~~${used}~~", - Col::Use => "~~${use-percents}~~ `${bar}`~~${use-error}~~", + Col::Use => "~~${use-percents}~~ ${bar}~~${use-error}~~", Col::UsePercent => "~~${use-percents}~~", Col::Free => "*${free}*", Col::Size => "**${size}**", Col::InodesFree => "*${ifree}*", Col::InodesUsed => "~~${iused}~~", - Col::InodesUse => "~~${iuse-percents}~~ `${ibar}`", + Col::InodesUse => "~~${iuse-percents}~~ ${ibar}", Col::InodesUsePercent => "~~${iuse-percents}~~", Col::InodesCount => "**${inodes}**", Col::MountPoint => "${mount-point}", @@ -116,3 +117,21 @@ fn make_colored_skin() -> MadSkin { } } +fn progress_bar_md( + share: f64, + bar_width: usize, + ascii: bool, +) -> String { + if ascii { + let count = (share * bar_width as f64).round() as usize; + let bar: String = std::iter::repeat('=') + .take(count).collect(); + let no_bar: String = std::iter::repeat('-') + .take(bar_width-count).collect(); + format!("~~{}~~*{}*", bar, no_bar) + } else { + let pb = ProgressBar::new(share as f32, bar_width); + format!("`{: