par_term_config/config/config_struct/background_config.rs
1//! Terminal background image and transparency settings.
2//!
3//! Extracted from the top-level [`super::Config`] struct via `#[serde(flatten)]`.
4//! All fields serialise at the top level of the YAML config file -- existing
5//! config files remain 100% compatible.
6
7use crate::types::BackgroundImageMode;
8use serde::{Deserialize, Serialize};
9
10/// Background image source and how window transparency applies to cells and text.
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct BackgroundConfig {
13 /// When true, only the default terminal background is transparent.
14 /// Colored backgrounds (syntax highlighting, status bars, etc.) remain opaque.
15 /// This keeps text readable while allowing window transparency.
16 #[serde(default = "crate::defaults::bool_true")]
17 pub transparency_affects_only_default_background: bool,
18
19 /// When true, text is always rendered at full opacity regardless of window transparency.
20 /// This ensures text remains crisp and readable even with transparent backgrounds.
21 #[serde(default = "crate::defaults::bool_true")]
22 pub keep_text_opaque: bool,
23
24 /// Background image path (optional, supports ~ for home directory)
25 #[serde(default)]
26 pub background_image: Option<String>,
27
28 /// Enable or disable background image rendering (even if a path is set)
29 #[serde(default = "crate::defaults::bool_true")]
30 pub background_image_enabled: bool,
31
32 /// Background image display mode
33 /// - fit: Scale to fit window while maintaining aspect ratio
34 /// - fill: Scale to fill window while maintaining aspect ratio (may crop)
35 /// - stretch: Stretch to fill window, ignoring aspect ratio (default)
36 /// - tile: Repeat image in a tiled pattern
37 /// - center: Center image at original size
38 #[serde(default)]
39 pub background_image_mode: BackgroundImageMode,
40
41 /// Background image opacity (0.0 = fully transparent, 1.0 = fully opaque)
42 #[serde(default = "crate::defaults::background_image_opacity")]
43 pub background_image_opacity: f32,
44}
45
46impl Default for BackgroundConfig {
47 fn default() -> Self {
48 Self {
49 transparency_affects_only_default_background: crate::defaults::bool_true(),
50 keep_text_opaque: crate::defaults::bool_true(),
51 background_image: None,
52 background_image_enabled: crate::defaults::bool_true(),
53 background_image_mode: BackgroundImageMode::default(),
54 background_image_opacity: crate::defaults::background_image_opacity(),
55 }
56 }
57}