Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Choose Theme Based on The Terminal's Color Scheme #2896

Merged
merged 30 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1423dd9
Choose theme based on the terminal's color scheme
bash Apr 16, 2024
de79639
Deprecate old `default_theme` function
bash Apr 16, 2024
cda363a
Use `default_theme()` function from theme module
bash Apr 16, 2024
cea45e0
Expose new theme selection in CLI
bash Jul 18, 2024
9a1bfe9
Update completions and man page
bash Apr 16, 2024
14ce668
Add generated powershell completion to ignore list
bash Apr 16, 2024
ff81cfd
Move actual detection into library
bash Apr 16, 2024
30b0143
Make default_theme pub
bash Jul 18, 2024
6498615
Improve upon the documentation
bash Apr 16, 2024
e8ca6ec
Remove cargo feature
bash Apr 16, 2024
594b141
Update readme
bash Apr 16, 2024
c3b190d
Disable color detection in test
bash Apr 16, 2024
06b6454
Add changelog entry
bash Apr 16, 2024
1b0a6da
Use new `default_theme` fn for --list-themes
bash Apr 16, 2024
5c69747
Respect --detect-color-scheme flag when listing themes
bash May 1, 2024
abf9dad
Remove `HighlightingAssets::default_theme()`
bash Jul 18, 2024
b9b981f
Generalize --detect-color-scheme to --color-scheme
bash Jul 18, 2024
bc42149
Merge color scheme options into theme / BAT_THEME
bash Aug 18, 2024
89ce060
Update help, man page and completions
bash Aug 18, 2024
5095847
Return theme alongside detected color scheme
bash Aug 23, 2024
16d9b99
Flatten preference enum
bash Sep 4, 2024
e075fee
Add infallible constructor
bash Sep 7, 2024
60e4027
Expose theme env vars
bash Sep 7, 2024
10e823c
Rename internal function
bash Sep 7, 2024
f6cbee9
Update docs
bash Sep 7, 2024
0ebb9cb
Add Display impl
bash Sep 7, 2024
02ae6ef
Remove redundant guard
bash Sep 7, 2024
b747184
Accept `impl Into<String>` to avoid cloning strings
bash Sep 8, 2024
60693db
Merge branch 'master' into dark-light
keith-hall Nov 13, 2024
08047a6
Merge branch 'master' into dark-light
keith-hall Nov 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use default_theme() function from theme module
  • Loading branch information
bash committed Aug 16, 2024
commit cda363a3f742fe4ef112ffcd4a61bb756332c16c
27 changes: 8 additions & 19 deletions src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::error::*;
use crate::input::{InputReader, OpenedInput};
use crate::syntax_mapping::ignored_suffixes::IgnoredSuffixes;
use crate::syntax_mapping::MappingTarget;
use crate::theme::{default_theme, ColorScheme};
use crate::{bat_warning, SyntaxMapping};

use lazy_theme_set::LazyThemeSet;
Expand Down Expand Up @@ -94,33 +95,18 @@ impl HighlightingAssets {
pub fn default_theme() -> &'static str {
#[cfg(not(target_os = "macos"))]
{
Self::default_dark_theme()
default_theme(ColorScheme::Dark)
}
#[cfg(target_os = "macos")]
{
if macos_dark_mode_active() {
Self::default_dark_theme()
default_theme(ColorScheme::Dark)
} else {
Self::default_light_theme()
default_theme(ColorScheme::Light)
}
}
}

/**
* The default theme that looks good on a dark background.
*/
fn default_dark_theme() -> &'static str {
"Monokai Extended"
}

/**
* The default theme that looks good on a light background.
*/
#[cfg(target_os = "macos")]
fn default_light_theme() -> &'static str {
"Monokai Extended Light"
}

pub fn from_cache(cache_path: &Path) -> Result<Self> {
Ok(HighlightingAssets::new(
SerializedSyntaxSet::FromFile(cache_path.join("syntaxes.bin")),
Expand Down Expand Up @@ -249,7 +235,10 @@ impl HighlightingAssets {
bat_warning!("Unknown theme '{}', using default.", theme)
}
self.get_theme_set()
.get(self.fallback_theme.unwrap_or_else(Self::default_theme))
.get(
self.fallback_theme
.unwrap_or_else(|| default_theme(ColorScheme::Dark)),
)
.expect("something is very wrong if the default theme is missing")
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn detect(when: DetectColorScheme, detector: &dyn ColorSchemeDetector) -> Option
should_detect.then(|| detector.detect()).flatten()
}

const fn default_theme(color_scheme: ColorScheme) -> &'static str {
pub(crate) const fn default_theme(color_scheme: ColorScheme) -> &'static str {
match color_scheme {
ColorScheme::Dark => "Monokai Extended",
ColorScheme::Light => "Monokai Extended Light",
Expand Down