diff --git a/config/theme.toml b/config/theme.toml index db1933ad7..469861f34 100644 --- a/config/theme.toml +++ b/config/theme.toml @@ -2,6 +2,8 @@ ## General ########################################## lscolors_enabled = false +# The image preview background color, only RGB colors are accepted. +# preview_background = "#FFFFFF" ########################################## ## Tabs diff --git a/docs/image_previews/README.md b/docs/image_previews/README.md index 41faef508..b82ce5b5b 100644 --- a/docs/image_previews/README.md +++ b/docs/image_previews/README.md @@ -21,6 +21,8 @@ preview_protocol = "halfblocks" ... ``` +The background color can be configured in `theme.toml`. + ## XDG-Thumbnails and thumbnails for non-image files By default, Joshuto uses thumbnails and the diff --git a/src/config/theme/mod.rs b/src/config/theme/mod.rs index d62f0704a..b809154b1 100644 --- a/src/config/theme/mod.rs +++ b/src/config/theme/mod.rs @@ -7,6 +7,7 @@ pub mod theme_raw; use std::collections::HashMap; use lscolors::LsColors; +use ratatui::style::Color; use crate::constants::config::THEME_CONFIG; use crate::error::AppResult; @@ -17,6 +18,8 @@ use style::AppStyle; use tab::TabTheme; use theme_raw::AppThemeRaw; +use self::style_raw::AppStyleRaw; + #[derive(Clone, Debug)] pub struct AppTheme { pub tabs: TabTheme, @@ -30,6 +33,7 @@ pub struct AppTheme { pub socket: AppStyle, pub ext: HashMap, pub lscolors: Option, + pub preview_background: Color, } impl AppTheme { @@ -81,6 +85,7 @@ impl From for AppTheme { } else { None }; + let preview_background = AppStyleRaw::str_to_color(&raw.preview_background); Self { selection, @@ -94,6 +99,7 @@ impl From for AppTheme { ext, tabs: TabTheme::from(tabs), lscolors, + preview_background, } } } diff --git a/src/config/theme/theme_raw.rs b/src/config/theme/theme_raw.rs index 5973cf0be..b871ca573 100644 --- a/src/config/theme/theme_raw.rs +++ b/src/config/theme/theme_raw.rs @@ -28,4 +28,6 @@ pub struct AppThemeRaw { pub ext: HashMap, #[serde(default)] pub lscolors_enabled: bool, + #[serde(default)] + pub preview_background: String, } diff --git a/src/types/state/app_state.rs b/src/types/state/app_state.rs index a60dc3401..484376ecb 100644 --- a/src/types/state/app_state.rs +++ b/src/types/state/app_state.rs @@ -2,6 +2,7 @@ use std::collections::HashSet; use std::sync::mpsc; use allmytoes::{AMTConfiguration, AMT}; +use ratatui::style::Color; use ratatui_image::picker::Picker; use crate::commands::quit::QuitAction; @@ -12,7 +13,7 @@ use crate::types::state::{ CommandLineState, MessageQueue, PreviewState, TabState, UiState, WorkerState, }; -use crate::Args; +use crate::{Args, THEME_T}; use super::{FileManagerState, ThreadPool}; @@ -30,6 +31,10 @@ impl AppState { pub fn new(config: AppConfig, args: Args) -> Self { let picker = if config.preview_options.preview_shown_hook_script.is_none() { Picker::from_termios().ok().and_then(|mut picker| { + picker.background_color = match THEME_T.preview_background { + Color::Rgb(r, g, b) => Some(image::Rgb([r, g, b])), + _ => None, + }; match config.preview_options.preview_protocol { PreviewProtocol::Auto => { picker.guess_protocol(); // Must run before Events::new() because it makes ioctl calls.