Skip to content

Commit 3a29410

Browse files
committed
fix: Improve color env variable support
- `CLICOLOR=1` now works correctly - `NO_COLOR=` now works correctly - Auto-enable colors in CI For running `typos` on the Linux kernel (176,210 typos to be printed), we went from 20.082s to <20.450s. Where in that range is unclear due to jitter in my system. ```console $ hyperfine -L typos ./typos-main,./typos-anstream "{typos} ../../../linux" -i Benchmark 1: ./typos-main ../../../linux Time (mean ± σ): 20.082 s ± 0.111 s [User: 39.668 s, System: 0.474 s] Range (min … max): 19.961 s … 20.331 s 10 runs Warning: Ignoring non-zero exit code. Benchmark 2: ./typos-anstream ../../../linux Time (mean ± σ): 20.426 s ± 0.104 s [User: 40.301 s, System: 0.523 s] Range (min … max): 20.316 s … 20.661 s 10 runs Warning: Ignoring non-zero exit code. Summary './typos-main ../../../linux' ran 1.02 ± 0.01 times faster than './typos-anstream ../../../linux' $ CLICOLOR_FORCE=1 hyperfine -L typos ./typos-anstream "{typos} ../../../linux" -i Benchmark 1: ./typos-anstream ../../../linux Time (mean ± σ): 20.262 s ± 0.075 s [User: 39.961 s, System: 0.542 s] Range (min … max): 20.154 s … 20.420 s 10 runs Warning: Ignoring non-zero exit code. $ CLICOLOR=0 hyperfine -L typos ./typos-anstream "{typos} ../../../linux" -i Benchmark 1: ./typos-anstream ../../../linux Time (mean ± σ): 20.296 s ± 0.065 s [User: 40.003 s, System: 0.565 s] Range (min … max): 20.169 s … 20.383 s 10 runs Warning: Ignoring non-zero exit code. ```
1 parent 28e7f17 commit 3a29410

File tree

4 files changed

+170
-83
lines changed

4 files changed

+170
-83
lines changed

Cargo.lock

+82-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/typos-cli/Cargo.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ toml = "0.7.2"
5656
log = "0.4"
5757
env_logger = { version = "0.10", default-features = false, features = ["auto-color"] }
5858
atty = "0.2.14"
59-
yansi = "0.5.1"
60-
concolor = { version = "0.0.12" }
61-
concolor-clap = { version = "0.0.14", features = ["api_unstable"] }
59+
concolor = { version = "0.1.1" }
60+
concolor-clap = { version = "0.1.0", features = ["api"] }
6261
bstr = "1.3"
6362
once_cell = "1.17.1"
6463
ahash = "0.8"
@@ -79,6 +78,8 @@ unicode-width = "0.1.10"
7978
unic-emoji-char = "0.9.0"
8079
thread_local = "1.1.7"
8180
globset = "0.4.10"
81+
anstyle = "0.3.1"
82+
anstyle-stream = "0.2.0"
8283

8384
[dev-dependencies]
8485
assert_fs = "1.0"

crates/typos-cli/src/bin/typos-cli/main.rs

+4-17
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,12 @@ fn run() -> proc_exit::ExitResult {
3131

3232
init_logging(args.verbose.log_level());
3333

34-
let stdout_palette = if concolor::get(concolor::Stream::Stdout).ansi_color() {
35-
report::Palette::colored()
36-
} else {
37-
report::Palette::plain()
38-
};
39-
let stderr_palette = if concolor::get(concolor::Stream::Stderr).ansi_color() {
40-
report::Palette::colored()
41-
} else {
42-
report::Palette::plain()
43-
};
44-
4534
if let Some(output_path) = args.dump_config.as_ref() {
4635
run_dump_config(&args, output_path)
4736
} else if args.type_list {
4837
run_type_list(&args)
4938
} else {
50-
run_checks(&args, stdout_palette, stderr_palette)
39+
run_checks(&args)
5140
}
5241
}
5342

@@ -149,11 +138,7 @@ fn run_type_list(args: &args::Args) -> proc_exit::ExitResult {
149138
Ok(())
150139
}
151140

152-
fn run_checks(
153-
args: &args::Args,
154-
stdout_palette: report::Palette,
155-
stderr_palette: report::Palette,
156-
) -> proc_exit::ExitResult {
141+
fn run_checks(args: &args::Args) -> proc_exit::ExitResult {
157142
let global_cwd = std::env::current_dir().to_sysexits()?;
158143

159144
let storage = typos_cli::policy::ConfigStorage::new();
@@ -219,6 +204,8 @@ fn run_checks(
219204
let output_reporter = if args.diff {
220205
Box::new(crate::report::PrintSilent)
221206
} else {
207+
let stdout_palette = report::Palette::colored();
208+
let stderr_palette = report::Palette::colored();
222209
args.format.reporter(stdout_palette, stderr_palette)
223210
};
224211
let status_reporter = report::MessageStatus::new(output_reporter.as_ref());

0 commit comments

Comments
 (0)