From efc2b6d6b63f7f3d1ea56dadf81cd9047e4e0436 Mon Sep 17 00:00:00 2001 From: Fahmi Akbar Wildana Date: Wed, 11 Sep 2019 10:22:34 +0700 Subject: [PATCH 1/4] Enable ColoredHelp for mask and all subcommands --- Cargo.lock | 35 +++++++++++++++++++++++++++++++++++ Cargo.toml | 5 ++++- src/main.rs | 3 ++- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4321377..91bce9a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -105,6 +105,7 @@ dependencies = [ "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "term_size 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -223,6 +224,15 @@ name = "itoa" version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "kernel32-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "lazy_static" version = "1.3.0" @@ -540,6 +550,16 @@ dependencies = [ "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "term_size" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "termion" version = "1.5.3" @@ -556,6 +576,7 @@ name = "textwrap" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ + "term_size 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -620,6 +641,11 @@ dependencies = [ "winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "winapi" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "winapi" version = "0.3.7" @@ -629,6 +655,11 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "winapi-build" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -685,6 +716,7 @@ dependencies = [ "checksum globwalk 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "89fa2e29859da05acd066bd45996f05c271b271d7ec4a781f909682328f65d25" "checksum ignore 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8dc57fa12805f367736a38541ac1a9fc6a52812a0ca959b1d4d4b640a89eb002" "checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" +"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" "checksum libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)" = "6281b86796ba5e4366000be6e9e18bf35580adf9e63fbe2294aadb587613a319" "checksum log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c275b6ad54070ac2d665eef9197db647b32239c9d244bfb6f041a766d00da5b3" @@ -724,6 +756,7 @@ dependencies = [ "checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" "checksum syn 0.15.39 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d960b829a55e56db167e861ddb43602c003c7be0bee1d345021703fac2fb7c" "checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" +"checksum term_size 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9e5b9a66db815dcfd2da92db471106457082577c3c278d4138ab3e3b4e189327" "checksum termion 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6a8fb22f7cde82c8220e5aeacb3258ed7ce996142c77cba193f203515e26c330" "checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" @@ -736,7 +769,9 @@ dependencies = [ "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" "checksum walkdir 2.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "c7904a7e2bb3cdf0cf5e783f44204a85a37a93151738fa349f06680f59a98b45" +"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770" +"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index e67af32..4e03e81 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,10 +16,13 @@ name = "mask" path = "src/lib.rs" [dependencies] -clap = "2.33.0" # https://github.com/clap-rs/clap colored = "1.8.0" # https://github.com/mackwic/colored pulldown-cmark = { version = "0.5", default-features = false } # https://github.com/raphlinus/pulldown-cmark +[dependencies.clap] # https://github.com/clap-rs/clap +version = "2.33.0" +features = ["wrap_help", "color"] + [dev-dependencies] assert_cmd = "0.11.1" # https://github.com/assert-rs/assert_cmd assert_fs = "0.11.3" # https://github.com/assert-rs/assert_fs diff --git a/src/main.rs b/src/main.rs index d9df59f..206ff46 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,6 +14,7 @@ fn main() { let cli_app = App::new(crate_name!()) .setting(AppSettings::VersionlessSubcommands) .setting(AppSettings::SubcommandRequired) + .setting(AppSettings::ColoredHelp) .version(crate_version!()) .author(crate_authors!()) .about(crate_description!()) @@ -89,7 +90,7 @@ fn build_subcommands<'a, 'b>( subcommands: &'a Vec, ) -> App<'a, 'b> { for c in subcommands { - let mut subcmd = SubCommand::with_name(&c.name).about(c.desc.as_ref()); + let mut subcmd = SubCommand::with_name(&c.name).about(c.desc.as_ref()).setting(AppSettings::ColoredHelp); if !c.subcommands.is_empty() { subcmd = build_subcommands(subcmd, &c.subcommands); // If this parent command has no script source, require a subcommand. From 2885f7ab2c4fe8a804c1be9952aaf7807ce04e5a Mon Sep 17 00:00:00 2001 From: Fahmi Akbar Wildana Date: Wed, 11 Sep 2019 10:38:04 +0700 Subject: [PATCH 2/4] Disable clap color on blind terminal --- Cargo.lock | 1 + Cargo.toml | 2 ++ src/main.rs | 15 +++++++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 91bce9a..fa3ae85 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -260,6 +260,7 @@ version = "0.5.0" dependencies = [ "assert_cmd 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)", "assert_fs 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", + "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "colored 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "predicates 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 4e03e81..39fc2ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,8 @@ name = "mask" path = "src/lib.rs" [dependencies] +# see https://rust-lang-nursery.github.io/cli-wg/in-depth/machine-communication.html?highlight=atty#whos-reading-this +atty = "0.2" # https://github.com/softprops/atty colored = "1.8.0" # https://github.com/mackwic/colored pulldown-cmark = { version = "0.5", default-features = false } # https://github.com/raphlinus/pulldown-cmark diff --git a/src/main.rs b/src/main.rs index 206ff46..a2b0207 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use std::env; use std::path::Path; +use atty::{self, Stream}; use clap::{ crate_authors, crate_description, crate_name, crate_version, App, AppSettings, Arg, ArgMatches, SubCommand, @@ -14,7 +15,11 @@ fn main() { let cli_app = App::new(crate_name!()) .setting(AppSettings::VersionlessSubcommands) .setting(AppSettings::SubcommandRequired) - .setting(AppSettings::ColoredHelp) + .setting(if atty::is(Stream::Stdout) { + AppSettings::ColoredHelp + } else { + AppSettings::ColorNever // in case it run on terminal without color support + }) .version(crate_version!()) .author(crate_authors!()) .about(crate_description!()) @@ -90,7 +95,13 @@ fn build_subcommands<'a, 'b>( subcommands: &'a Vec, ) -> App<'a, 'b> { for c in subcommands { - let mut subcmd = SubCommand::with_name(&c.name).about(c.desc.as_ref()).setting(AppSettings::ColoredHelp); + let mut subcmd = SubCommand::with_name(&c.name) + .about(c.desc.as_ref()) + .setting(if atty::is(Stream::Stdout) { + AppSettings::ColoredHelp + } else { + AppSettings::ColorNever // in case it run on terminal without color support + }); if !c.subcommands.is_empty() { subcmd = build_subcommands(subcmd, &c.subcommands); // If this parent command has no script source, require a subcommand. From 8c2c03b693cfba17b4ebf7e89d0273e0cc717b90 Mon Sep 17 00:00:00 2001 From: Fahmi Akbar Wildana Date: Wed, 18 Sep 2019 02:26:37 +0700 Subject: [PATCH 3/4] Remove atty https://github.com/jakedeichert/mask/pull/30#pullrequestreview-288380928 --- Cargo.lock | 1 - Cargo.toml | 2 -- src/main.rs | 13 ++----------- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fa3ae85..91bce9a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -260,7 +260,6 @@ version = "0.5.0" dependencies = [ "assert_cmd 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)", "assert_fs 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", - "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "colored 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "predicates 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 39fc2ad..4e03e81 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,8 +16,6 @@ name = "mask" path = "src/lib.rs" [dependencies] -# see https://rust-lang-nursery.github.io/cli-wg/in-depth/machine-communication.html?highlight=atty#whos-reading-this -atty = "0.2" # https://github.com/softprops/atty colored = "1.8.0" # https://github.com/mackwic/colored pulldown-cmark = { version = "0.5", default-features = false } # https://github.com/raphlinus/pulldown-cmark diff --git a/src/main.rs b/src/main.rs index a2b0207..d9e6103 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,6 @@ use std::env; use std::path::Path; -use atty::{self, Stream}; use clap::{ crate_authors, crate_description, crate_name, crate_version, App, AppSettings, Arg, ArgMatches, SubCommand, @@ -15,11 +14,7 @@ fn main() { let cli_app = App::new(crate_name!()) .setting(AppSettings::VersionlessSubcommands) .setting(AppSettings::SubcommandRequired) - .setting(if atty::is(Stream::Stdout) { - AppSettings::ColoredHelp - } else { - AppSettings::ColorNever // in case it run on terminal without color support - }) + .setting(AppSettings::ColoredHelp) .version(crate_version!()) .author(crate_authors!()) .about(crate_description!()) @@ -97,11 +92,7 @@ fn build_subcommands<'a, 'b>( for c in subcommands { let mut subcmd = SubCommand::with_name(&c.name) .about(c.desc.as_ref()) - .setting(if atty::is(Stream::Stdout) { - AppSettings::ColoredHelp - } else { - AppSettings::ColorNever // in case it run on terminal without color support - }); + .setting(AppSettings::ColoredHelp); if !c.subcommands.is_empty() { subcmd = build_subcommands(subcmd, &c.subcommands); // If this parent command has no script source, require a subcommand. From 702afada9d007bf4c5f0a3ba4f74d0ccddb0d295 Mon Sep 17 00:00:00 2001 From: Fahmi Akbar Wildana Date: Tue, 24 Sep 2019 17:11:39 +0700 Subject: [PATCH 4/4] Update Cargo.toml Co-Authored-By: Jake Deichert --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 4e03e81..4e6160b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ pulldown-cmark = { version = "0.5", default-features = false } # https: [dependencies.clap] # https://github.com/clap-rs/clap version = "2.33.0" -features = ["wrap_help", "color"] +features = ["wrap_help"] [dev-dependencies] assert_cmd = "0.11.1" # https://github.com/assert-rs/assert_cmd