diff --git a/Cargo.toml b/Cargo.toml index 8ec449c..d096fd1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,4 +29,4 @@ clap = { version = "4.5.35", features = ["derive", "env", "string"] } regex = { version = "1.11.1", features = ["use_std"] } color-eyre = { version = "0.6.3", default-features = false, features = ["track-caller"] } rayon = "1.10.0" -owo-colors = "3.5.0" +owo-colors = { version = "3.5.0", features = ["alloc", "supports-colors"] } diff --git a/src/main.rs b/src/main.rs index 94b0a11..13a213f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -161,6 +161,17 @@ fn main() -> eyre::Result<()> if args.len() < 4 { use owo_colors::OwoColorize; + use owo_colors::Stream; + + macro_rules! colour { + (in $name:ident: $fmt:expr => $col:ident) => { + $fmt.if_supports_color(Stream::$name, |text| text.$col()) + }; + ($fmt:expr => $col:ident) => { + colour!(in Stdout: $fmt => $col) + } + } + println!("rematch v{}: Regular-expression group matcher", env!("CARGO_PKG_VERSION")); println!(""); println!("Usage: {} ...", args[0]); @@ -168,14 +179,14 @@ fn main() -> eyre::Result<()> println!(""); println!("Enabled Features:"); if cfg!(feature="perl") { - println!("{}\t\t\tEnable PCRE2 (extended) regular-expressions.\n\t\t\tNote that PCRE2 regex engine matches on *bytes*, not *characters*; meaning if a match cuts a vlid UTF8 codepoint into an invalid one, the output will replace the invalid characters with U+FFFD REPLACEMENT CHARACTER.", disjoint!["+", "perl"].bright_red()); + println!("{}\t\t\tEnable PCRE2 (extended) regular-expressions.\n\t\t\tNote that PCRE2 regex engine matches on *bytes*, not *characters*; meaning if a match cuts a vlid UTF8 codepoint into an invalid one, the output will replace the invalid characters with U+FFFD REPLACEMENT CHARACTER.", colour!(disjoint!["+", "perl"] => bright_red)); } else { - println!("{}\t\t\tPCRE2 (extended) features are disabled; a faster but less featureful regular expression engine (that matches on UTF8 strings instead of raw bytes) is used instead.", disjoint!["-", "perl"].blue()); + println!("{}\t\t\tPCRE2 (extended) features are disabled; a faster but less featureful regular expression engine (that matches on UTF8 strings instead of raw bytes) is used instead.", colour!(disjoint!["-", "perl"] => blue)); } if cfg!(feature="unstable") { - println!("{}\t\tUnstable optimisations evailable & enabled for build.", disjoint!["+", "unstable"].red()); + println!("{}\t\tUnstable optimisations evailable & enabled for build.", colour!(disjoint!["+", "unstable"] => red)); } else { - println!("{}\t\tUnstable optimisations disabled / not available for build.", disjoint!["-", "unstable"].bright_blue()); + println!("{}\t\tUnstable optimisations disabled / not available for build.", colour!(disjoint!["-", "unstable"] => bright_blue)); } std::process::exit(1) } else {