Skip to content

Commit

Permalink
configure preview image background color via theme.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
benjajaja committed Jul 20, 2024
1 parent d10ca32 commit 896fcd5
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions config/theme.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
## General
##########################################
lscolors_enabled = false
# The image preview background color, only RGB colors are accepted.
# preview_background = "#FFFFFF"

##########################################
## Tabs
Expand Down
2 changes: 2 additions & 0 deletions docs/image_previews/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/config/theme/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -30,6 +33,7 @@ pub struct AppTheme {
pub socket: AppStyle,
pub ext: HashMap<String, AppStyle>,
pub lscolors: Option<LsColors>,
pub preview_background: Color,
}

impl AppTheme {
Expand Down Expand Up @@ -81,6 +85,7 @@ impl From<AppThemeRaw> for AppTheme {
} else {
None
};
let preview_background = AppStyleRaw::str_to_color(&raw.preview_background);

Self {
selection,
Expand All @@ -94,6 +99,7 @@ impl From<AppThemeRaw> for AppTheme {
ext,
tabs: TabTheme::from(tabs),
lscolors,
preview_background,
}
}
}
2 changes: 2 additions & 0 deletions src/config/theme/theme_raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ pub struct AppThemeRaw {
pub ext: HashMap<String, AppStyleRaw>,
#[serde(default)]
pub lscolors_enabled: bool,
#[serde(default)]
pub preview_background: String,
}
7 changes: 6 additions & 1 deletion src/types/state/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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};

Expand All @@ -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.
Expand Down

0 comments on commit 896fcd5

Please sign in to comment.