Skip to content

Preserve terminal theme contrast for status labels - #2592

Merged
j178 merged 3 commits into
j178:masterfrom
gurgeous:status-colors
Aug 24, 2026
Merged

j178 merged 3 commits into
j178:masterfrom
gurgeous:status-colors

Conversation

@gurgeous

@gurgeous gurgeous commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Love prek, I am using it in all my projects now. There is just one tiny thing I would like to fix... See #1310, which is still a problem for many terminal themes (like mine).

We should probably be using fully specified ansi colors for bg/fg since you can't rely on the user's theme for bg colors. This PR switches to ANSI 256 colors (from ANSI 16). Also consider adding a space on either side of the text to make it prettier, but that's a separate thing. Thanks guys!

NEW

new

OLD

old

Fixes #1310

@gurgeous
gurgeous requested a review from j178 as a code owner August 21, 2026 22:32

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5c0c83e16c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread crates/prek/src/cli/run/run.rs Outdated
@codecov

codecov Bot commented Aug 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.87%. Comparing base (8c88c2d) to head (298ae47).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2592      +/-   ##
==========================================
- Coverage   93.87%   93.87%   -0.01%     
==========================================
  Files         140      140              
  Lines       29060    29047      -13     
==========================================
- Hits        27280    27267      -13     
  Misses       1780     1780              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@prek-ci-bot

prek-ci-bot Bot commented Aug 21, 2026 •

Copy link
Copy Markdown

📦 Cargo Bloat Comparison

.text size change: -0.80% (12.5 MiB → 12.4 MiB)

Expand for cargo-bloat output

Head Branch Results

File  .text     Size             Crate Name
0.1%   2.6% 332.0KiB        aws_lc_sys aws_lc_0_44_0_aes_gcm_encrypt_avx512
0.1%   2.6% 332.0KiB        aws_lc_sys aws_lc_0_44_0_aes_gcm_decrypt_avx512
0.0%   0.9% 113.8KiB              prek <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
0.0%   0.4%  52.1KiB              prek prek::run::{closure#0}
0.0%   0.4%  49.7KiB              prek <<prek::config::hook::HookWire as serde_core::de::Deserialize>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map::<<serde_saphyr::de::deserializer::YamlDeserializer as serde_core::de::Deserializer>::deserialize_map::MA>
0.0%   0.4%  48.7KiB annotate_snippets annotate_snippets::renderer::render::render
0.0%   0.4%  44.5KiB              prek <<prek::config::Config as serde_core::de::Deserialize>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map::<<serde_saphyr::de::deserializer::YamlDeserializer as serde_core::de::Deserializer>::deserialize_map::MA>
0.0%   0.3%  37.1KiB              prek <prek::cli::RunOptions as clap_builder::derive::Args>::augment_args
0.0%   0.2%  29.3KiB              prek prek::cli::run::run::run::{closure#0}
0.0%   0.2%  28.8KiB              prek prek::archive::unpack::<fs_err::tokio::file::File, &std::path::PathBuf>::{closure#0}
0.0%   0.2%  28.6KiB      serde_saphyr <granit_parser::scanner::Scanner<granit_parser::input::str::StrInput>>::fetch_more_tokens
0.0%   0.2%  28.5KiB              toml <toml::de::deserializer::value::ValueDeserializer as serde_core::de::Deserializer>::deserialize_any::<<prek::config::hook::HookWire as serde_core::de::Deserialize>::deserialize::__Visitor>
0.0%   0.2%  28.0KiB        aws_lc_sys aws_lc_0_44_0_edwards25519_scalarmuldouble_alt
0.0%   0.2%  27.8KiB      serde_saphyr <granit_parser::scanner::Scanner<granit_parser::input::str::StrInput>>::fetch_more_tokens
0.0%   0.2%  27.8KiB              prek prek::archive::unpack::<fs_err::tokio::file::File, &std::path::PathBuf>::{closure#0}
0.0%   0.2%  27.5KiB        aws_lc_sys aws_lc_0_44_0_edwards25519_scalarmuldouble
0.0%   0.2%  27.4KiB              prek <prek::languages::deno::installer::DenoInstaller>::install::{closure#0}
0.0%   0.2%  27.0KiB              prek prek::archive::unpack::<fs_err::tokio::file::File, &std::path::PathBuf>::{closure#0}
0.0%   0.2%  27.0KiB              prek prek::archive::unpack::<fs_err::tokio::file::File, &std::path::PathBuf>::{closure#0}
0.0%   0.2%  27.0KiB              prek prek::archive::unpack::<fs_err::tokio::file::File, &std::path::PathBuf>::{closure#0}
4.2%  86.5%  10.7MiB                   And 20118 smaller methods. Use -n N to show more.
4.8% 100.0%  12.4MiB                   .text section size, the file size is 256.4MiB

Base Branch Results

File  .text     Size             Crate Name
0.1%   2.6% 332.0KiB        aws_lc_sys aws_lc_0_44_0_aes_gcm_encrypt_avx512
0.1%   2.6% 332.0KiB        aws_lc_sys aws_lc_0_44_0_aes_gcm_decrypt_avx512
0.0%   0.9% 113.8KiB              prek <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
0.0%   0.4%  52.0KiB              prek prek::run::{closure#0}
0.0%   0.4%  49.7KiB              prek <<prek::config::hook::HookWire as serde_core::de::Deserialize>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map::<<serde_saphyr::de::deserializer::YamlDeserializer as serde_core::de::Deserializer>::deserialize_map::MA>
0.0%   0.4%  48.7KiB annotate_snippets annotate_snippets::renderer::render::render
0.0%   0.3%  44.5KiB              prek <<prek::config::Config as serde_core::de::Deserialize>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map::<<serde_saphyr::de::deserializer::YamlDeserializer as serde_core::de::Deserializer>::deserialize_map::MA>
0.0%   0.3%  37.1KiB              prek <prek::cli::RunOptions as clap_builder::derive::Args>::augment_args
0.0%   0.2%  29.3KiB              prek prek::cli::run::run::run::{closure#0}
0.0%   0.2%  28.9KiB              prek prek::archive::unpack::<fs_err::tokio::file::File, &std::path::PathBuf>::{closure#0}
0.0%   0.2%  28.6KiB      serde_saphyr <granit_parser::scanner::Scanner<granit_parser::input::str::StrInput>>::fetch_more_tokens
0.0%   0.2%  28.5KiB              toml <toml::de::deserializer::value::ValueDeserializer as serde_core::de::Deserializer>::deserialize_any::<<prek::config::hook::HookWire as serde_core::de::Deserialize>::deserialize::__Visitor>
0.0%   0.2%  28.0KiB        aws_lc_sys aws_lc_0_44_0_edwards25519_scalarmuldouble_alt
0.0%   0.2%  27.8KiB      serde_saphyr <granit_parser::scanner::Scanner<granit_parser::input::str::StrInput>>::fetch_more_tokens
0.0%   0.2%  27.8KiB              prek prek::archive::unpack::<fs_err::tokio::file::File, &std::path::PathBuf>::{closure#0}
0.0%   0.2%  27.5KiB        aws_lc_sys aws_lc_0_44_0_edwards25519_scalarmuldouble
0.0%   0.2%  27.4KiB              prek <prek::languages::deno::installer::DenoInstaller>::install::{closure#0}
0.0%   0.2%  27.0KiB              prek prek::archive::unpack::<fs_err::tokio::file::File, &std::path::PathBuf>::{closure#0}
0.0%   0.2%  27.0KiB              prek prek::archive::unpack::<fs_err::tokio::file::File, &std::path::PathBuf>::{closure#0}
0.0%   0.2%  27.0KiB              prek prek::archive::unpack::<fs_err::tokio::file::File, &std::path::PathBuf>::{closure#0}
4.2%  86.7%  10.9MiB                   And 20230 smaller methods. Use -n N to show more.
4.9% 100.0%  12.5MiB                   .text section size, the file size is 256.7MiB

@prek-ci-bot

prek-ci-bot Bot commented Aug 21, 2026 •

Copy link
Copy Markdown

⚡️ Hyperfine Benchmarks

Summary: 0 regressions, 0 improvements above the 10% threshold.

Environment
  • OS: Linux 6.17.0-1022-azure
  • CPU: 4 cores
  • prek version: prek 0.4.14+18 (0e4ceb6 2026-08-23)
  • Rust version: rustc 1.98.0 (88d9e12ae 2026-08-18)
  • Hyperfine version: hyperfine 1.20.0
CLI Commands

Benchmarking basic commands in the main repo:

prek --version

Command Mean [ms] Min [ms] Max [ms] Relative
prek-base --version 2.3 ± 0.1 2.1 2.5 1.06 ± 0.07
prek-head --version 2.2 ± 0.1 2.0 2.4 1.00

prek list

Command Mean [ms] Min [ms] Max [ms] Relative
prek-base list 9.0 ± 0.3 8.8 11.3 1.03 ± 0.03
prek-head list 8.8 ± 0.1 8.6 9.2 1.00

prek validate-config .pre-commit-config.yaml

⏭️ Skipped: .pre-commit-config.yaml not found

prek sample-config

Command Mean [ms] Min [ms] Max [ms] Relative
prek-base sample-config 2.5 ± 0.1 2.4 2.8 1.06 ± 0.06
prek-head sample-config 2.4 ± 0.1 2.3 3.3 1.00
Cold vs Warm Runs

Comparing first run (cold) vs subsequent runs (warm cache):

prek run --all-files (cold - no cache)

Command Mean [ms] Min [ms] Max [ms] Relative
prek-base run --all-files 38.7 ± 1.2 37.1 40.6 1.02 ± 0.04
prek-head run --all-files 38.1 ± 1.0 37.3 40.2 1.00

prek run --all-files (warm - with cache)

Command Mean [ms] Min [ms] Max [ms] Relative
prek-base run --all-files 39.3 ± 1.5 36.9 42.5 1.01 ± 0.05
prek-head run --all-files 39.0 ± 1.1 36.9 40.6 1.00
Full Hook Suite

Running the builtin hook suite on the benchmark workspace:

prek run --all-files (full builtin hook suite)

Command Mean [ms] Min [ms] Max [ms] Relative
prek-base run --all-files 38.5 ± 1.1 35.8 40.9 1.01 ± 0.04
prek-head run --all-files 38.2 ± 1.1 35.1 41.2 1.00
Individual Hook Performance

Benchmarking each hook individually on the test repo:

prek run trailing-whitespace --all-files

Command Mean [ms] Min [ms] Max [ms] Relative
prek-base run trailing-whitespace --all-files 13.0 ± 0.3 12.6 13.8 1.01 ± 0.03
prek-head run trailing-whitespace --all-files 12.8 ± 0.3 12.1 13.4 1.00

prek run end-of-file-fixer --all-files

Command Mean [ms] Min [ms] Max [ms] Relative
prek-base run end-of-file-fixer --all-files 11.0 ± 0.3 10.3 11.8 1.01 ± 0.05
prek-head run end-of-file-fixer --all-files 10.8 ± 0.5 10.2 12.7 1.00

prek run check-json --all-files

Command Mean [ms] Min [ms] Max [ms] Relative
prek-base run check-json --all-files 7.8 ± 0.2 7.5 8.3 1.01 ± 0.04
prek-head run check-json --all-files 7.8 ± 0.3 7.4 8.4 1.00

prek run check-yaml --all-files

Command Mean [ms] Min [ms] Max [ms] Relative
prek-base run check-yaml --all-files 7.8 ± 0.1 7.5 8.0 1.04 ± 0.03
prek-head run check-yaml --all-files 7.5 ± 0.2 7.2 7.9 1.00

prek run check-toml --all-files

Command Mean [ms] Min [ms] Max [ms] Relative
prek-base run check-toml --all-files 7.8 ± 0.3 7.4 8.4 1.03 ± 0.06
prek-head run check-toml --all-files 7.6 ± 0.4 7.2 8.9 1.00

prek run check-xml --all-files

Command Mean [ms] Min [ms] Max [ms] Relative
prek-base run check-xml --all-files 7.6 ± 0.2 7.3 8.1 1.02 ± 0.05
prek-head run check-xml --all-files 7.5 ± 0.3 7.1 8.1 1.00

prek run detect-private-key --all-files

Command Mean [ms] Min [ms] Max [ms] Relative
prek-base run detect-private-key --all-files 11.0 ± 0.5 10.1 12.1 1.03 ± 0.07
prek-head run detect-private-key --all-files 10.7 ± 0.5 9.7 11.5 1.00

prek run fix-byte-order-marker --all-files

Command Mean [ms] Min [ms] Max [ms] Relative
prek-base run fix-byte-order-marker --all-files 13.3 ± 0.8 11.9 14.9 1.01 ± 0.12
prek-head run fix-byte-order-marker --all-files 13.2 ± 1.3 11.8 18.5 1.00
Installation Performance

Benchmarking hook installation (fast path hooks skip Python setup):

prek install-hooks (cold - no cache)

Command Mean [ms] Min [ms] Max [ms] Relative
prek-base install-hooks 4.5 ± 0.1 4.5 4.6 1.04 ± 0.02
prek-head install-hooks 4.4 ± 0.1 4.3 4.5 1.00

prek install-hooks (warm - with cache)

Command Mean [ms] Min [ms] Max [ms] Relative
prek-base install-hooks 4.6 ± 0.1 4.5 4.7 1.04 ± 0.02
prek-head install-hooks 4.4 ± 0.1 4.3 4.5 1.00
File Filtering/Scoping Performance

Testing different file selection modes:

prek run (staged files only)

Command Mean [ms] Min [ms] Max [ms] Relative
prek-base run 23.6 ± 0.2 23.2 24.1 1.01 ± 0.02
prek-head run 23.5 ± 0.3 22.9 24.0 1.00

prek run --files '*.json' (specific file type)

Command Mean [ms] Min [ms] Max [ms] Relative
prek-base run --files '*.json' 5.2 ± 0.1 5.1 5.4 1.06 ± 0.02
prek-head run --files '*.json' 5.0 ± 0.0 4.9 5.1 1.00
Workspace Discovery & Initialization

Benchmarking hook discovery and initialization overhead:

prek run --dry-run --all-files (measures init overhead)

Command Mean [ms] Min [ms] Max [ms] Relative
prek-base run --dry-run --all-files 6.9 ± 0.2 6.8 7.6 1.04 ± 0.03
prek-head run --dry-run --all-files 6.7 ± 0.1 6.6 6.8 1.00
Meta Hooks Performance

Benchmarking meta hooks separately:

prek run check-hooks-apply --all-files

Command Mean [ms] Min [ms] Max [ms] Relative
prek-base run check-hooks-apply --all-files 8.1 ± 0.1 8.0 8.2 1.03 ± 0.01
prek-head run check-hooks-apply --all-files 7.8 ± 0.1 7.7 8.0 1.00

prek run check-useless-excludes --all-files

Command Mean [ms] Min [ms] Max [ms] Relative
prek-base run check-useless-excludes --all-files 8.1 ± 0.1 7.9 8.2 1.03 ± 0.02
prek-head run check-useless-excludes --all-files 7.8 ± 0.1 7.7 8.0 1.00

prek run identity --all-files

Command Mean [ms] Min [ms] Max [ms] Relative
prek-base run identity --all-files 7.0 ± 0.1 6.9 7.1 1.03 ± 0.02
prek-head run identity --all-files 6.8 ± 0.1 6.7 7.0 1.00

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 84be964f6f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread crates/prek/src/cli/run/run.rs Outdated
Comment thread crates/prek/src/cli/run/run.rs Outdated
@pygarap

pygarap commented Aug 22, 2026

Copy link
Copy Markdown

@gurgeous Why are you using ANSI 256 colors instead of explicit 24-bit Truecolor?

@j178 j178 added the enhancement New feature or request label Aug 22, 2026
@j178 j178 changed the title use ANSI-256 colors for readable statuses Use ANSI-256 colors for readable statuses Aug 22, 2026
@gurgeous

Copy link
Copy Markdown
Contributor Author

@gurgeous Why are you using ANSI 256 colors instead of explicit 24-bit Truecolor?

I have no preference personally. There are still a few terminals that don't support truecolor. Last time I looked the two major laggards were gitlab CI and Apple Terminal pre-Tahoe. Popular software (like prek) might encounter those in the wild, so sometimes it's easier to just use ansi 256. Totally up to you, of course.

@j178 j178 changed the title Use ANSI-256 colors for readable statuses Preserve terminal theme contrast for status labels Aug 23, 2026
@j178

j178 commented Aug 23, 2026

Copy link
Copy Markdown
Owner

@gurgeous @pygarap Hi, I tried a different approach that preserves the terminal theme’s contrast. Could you check whether this improves readability in your terminal?

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 298ae473d5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/prek/src/cli/run/mod.rs
@gurgeous

Copy link
Copy Markdown
Contributor Author

This is an improvement in most cases. Still pretty easy to find themes that look bad. For example, ghostty ciapre. This is just how it goes when you try to reverse the user's completely unknown color theme...

image

@j178

j178 commented Aug 24, 2026

Copy link
Copy Markdown
Owner

Thanks for confirming! I think any terminal theme should at least keep these predefined colors readable against its default background, so reverse video seems like the safest option here.

@j178
j178 merged commit 55b7fd4 into j178:master Aug 24, 2026
36 checks passed
@gurgeous

Copy link
Copy Markdown
Contributor Author

BTW I added a tool on ansi.md to illustrate for next time, in case anyone is interested. Still love prek and use it in all my projects, thank you for this fix. See https://ansi.md/bad-colors.

"theme bg" on "ansi green" looks ok, though there are a few themes that are hard to read.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix coloring of Passed

3 participants