Skip to content

Commit

Permalink
Use new default_theme fn for --list-themes
Browse files Browse the repository at this point in the history
  • Loading branch information
bash committed Apr 16, 2024
1 parent 1c6d40f commit 4409c56
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/bin/bat/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ use directories::PROJECT_DIRS;
use globset::GlobMatcher;

use bat::{
assets::HighlightingAssets,
config::Config,
controller::Controller,
error::*,
input::Input,
style::{StyleComponent, StyleComponents},
MappingTarget, PagingMode,
theme, MappingTarget, PagingMode,
};

const THEME_PREVIEW_DATA: &[u8] = include_bytes!("../../../assets/theme_preview.rs");
Expand Down Expand Up @@ -201,10 +200,15 @@ pub fn list_themes(cfg: &Config, config_dir: &Path, cache_dir: &Path) -> Result<
let mut stdout = stdout.lock();

if config.colored_output {
let default_theme = HighlightingAssets::default_theme();
use theme::{color_scheme, default_theme, ColorScheme, DetectColorScheme};
let default_theme = default_theme(color_scheme(DetectColorScheme::Auto));
for theme in assets.themes() {
let default_theme_info = if default_theme == theme {
" (default)"
} else if theme::default_theme(ColorScheme::Dark) == theme {
" (default dark)"
} else if theme::default_theme(ColorScheme::Light) == theme {
" (default light)"
} else {
""
};
Expand Down
5 changes: 5 additions & 0 deletions src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ pub const fn default_theme(color_scheme: ColorScheme) -> &'static str {
}
}

/// Detects the color scheme from the terminal.
pub fn color_scheme(when: DetectColorScheme) -> ColorScheme {
detect(when, &TerminalColorSchemeDetector).unwrap_or_default()
}

/// Options for configuring the theme used for syntax highlighting.
/// Used together with [`theme`].
#[derive(Debug, Default, PartialEq, Eq)]
Expand Down

0 comments on commit 4409c56

Please sign in to comment.