Fixed colour output being printed to non-TTY outputs & to `NO_COLOR` environments.

This branch is basically done now; merge back to `cli` after patching the colouring code (& merging `ext.rs`) to `master` (and bumping its BF version.)

Fortune for rematch's current commit: Blessing − 吉
old-interface-extra-help-info
Avril 5 days ago
parent 003986677f
commit e2358483c9
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -29,4 +29,4 @@ clap = { version = "4.5.35", features = ["derive", "env", "string"] }
regex = { version = "1.11.1", features = ["use_std"] } regex = { version = "1.11.1", features = ["use_std"] }
color-eyre = { version = "0.6.3", default-features = false, features = ["track-caller"] } color-eyre = { version = "0.6.3", default-features = false, features = ["track-caller"] }
rayon = "1.10.0" rayon = "1.10.0"
owo-colors = "3.5.0" owo-colors = { version = "3.5.0", features = ["alloc", "supports-colors"] }

@ -161,6 +161,17 @@ fn main() -> eyre::Result<()>
if args.len() < 4 { if args.len() < 4 {
use owo_colors::OwoColorize; 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!("rematch v{}: Regular-expression group matcher", env!("CARGO_PKG_VERSION"));
println!(""); println!("");
println!("Usage: {} <str> <regex> <group>...", args[0]); println!("Usage: {} <str> <regex> <group>...", args[0]);
@ -168,14 +179,14 @@ fn main() -> eyre::Result<()>
println!(""); println!("");
println!("Enabled Features:"); println!("Enabled Features:");
if cfg!(feature="perl") { 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 { } 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") { 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 { } 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) std::process::exit(1)
} else { } else {

Loading…
Cancel
Save