Use light variant of theme automatically when terminal background is light
Description
This PR adds the ability to detect the background color of the terminal, using the terminal-colorsaurus library. This library has extensive support for terminals, and is pretty quick at detecting the color or failing gracefully. Popular tools such as delta and bat also use this.
Issue
Closes: #1284
Testing
If relevant, please state how this was tested. All changes must be tested to work:
If this is a code change, please also indicate which platforms were tested:
- [x] Windows
- [x] macOS
- [ ] Linux
Checklist
If relevant, ensure the following have been met:
- [x] Areas your change affects have been linted using rustfmt (
cargo fmt) - [x] The change has been tested and doesn't appear to cause any unintended breakage
- [x] Documentation has been added/updated if needed (
README.md, help menu, doc pages, etc.) - [ ] The pull request passes the provided CI pipeline
- [x] There are no merge conflicts
- [ ] If relevant, new tests were added (don't worry too much about coverage)
Codecov Report
:x: Patch coverage is 91.42857% with 3 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 35.84%. Comparing base (873ba20) to head (a9355d5).
:warning: Report is 3 commits behind head on main.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| src/options/config/style.rs | 91.42% | 3 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #1843 +/- ##
===========================================
- Coverage 53.95% 35.84% -18.11%
===========================================
Files 115 115
Lines 16096 16121 +25
===========================================
- Hits 8684 5778 -2906
- Misses 7412 10343 +2931
| Flag | Coverage Δ | |
|---|---|---|
| macos-14 | 37.00% <91.42%> (-0.99%) |
:arrow_down: |
| ubuntu-latest | 37.00% <91.42%> (-19.02%) |
:arrow_down: |
| windows-2022 | 37.32% <91.42%> (-1.01%) |
:arrow_down: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
The CI seems to be failing in a file unrelated to my changes, should I fix it?
Ugh, that's my bad. I think it's fine, it's because the new stable rust means I'm failing a clippy check in the main branch. I'll push a fix to main later.
I see. And should I add tests for this as well? Codecov seems to be complaining.
If you could add a test that might be nice, but it might be tricky to add one? Especially for CI, it might make sense to skip it there (or I guess ensure it handles it as expected if the terminal is a CI one). I'll leave that call up to you I suppose.
Will review in a bit (probably sometime in the next few days, currently travelling). Just fixed main so that CI shouldn't break either.
Okay sure, no rush