Skip to main content

par_term_config/config/config_struct/
cursor_config.rs

1//! Cursor appearance and behavior settings for the terminal emulator.
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//!
7//! Covers cursor style, blink, color, visibility locks, guide lines, shadows,
8//! boost/glow, and unfocused cursor behavior.
9
10use crate::types::{CursorStyle, UnfocusedCursorStyle};
11use serde::{Deserialize, Serialize};
12
13/// Cursor appearance and behavior configuration.
14///
15/// Controls the visual style, blinking, color, visibility locks, guide line,
16/// shadow, boost/glow, and unfocused cursor appearance.
17#[derive(Debug, Clone, Serialize, Deserialize)]
18pub struct CursorConfig {
19    // --- Blinking ---
20    /// Enable cursor blinking
21    #[serde(default = "crate::defaults::bool_false")]
22    pub cursor_blink: bool,
23
24    /// Cursor blink interval in milliseconds
25    #[serde(default = "crate::defaults::cursor_blink_interval")]
26    pub cursor_blink_interval: u64,
27
28    // --- Style ---
29    /// Cursor style (block, beam, underline)
30    #[serde(default)]
31    pub cursor_style: CursorStyle,
32
33    // --- Color ---
34    /// Cursor color [R, G, B] (0-255)
35    #[serde(default = "crate::defaults::cursor_color")]
36    pub cursor_color: [u8; 3],
37
38    /// Color of text under block cursor [R, G, B] (0-255)
39    /// If not set (None), uses automatic contrast color
40    /// Only affects block cursor style (beam and underline don't obscure text)
41    #[serde(default)]
42    pub cursor_text_color: Option<[u8; 3]>,
43
44    // --- Visibility/Style Locks ---
45    /// Lock cursor visibility - prevent applications from hiding the cursor
46    /// When true, the cursor remains visible regardless of DECTCEM escape sequences
47    #[serde(default = "crate::defaults::bool_false")]
48    pub lock_cursor_visibility: bool,
49
50    /// Lock cursor style - prevent applications from changing the cursor style
51    /// When true, the cursor style from config is always used, ignoring DECSCUSR escape sequences
52    #[serde(default = "crate::defaults::bool_false")]
53    pub lock_cursor_style: bool,
54
55    /// Lock cursor blink - prevent applications from enabling cursor blink
56    /// When true and cursor_blink is false, applications cannot enable blinking cursor
57    #[serde(default = "crate::defaults::bool_false")]
58    pub lock_cursor_blink: bool,
59
60    // --- Guide Line ---
61    /// Enable horizontal guide line at cursor row for better tracking in wide terminals
62    #[serde(default = "crate::defaults::bool_false")]
63    pub cursor_guide_enabled: bool,
64
65    /// Cursor guide color [R, G, B, A] (0-255), subtle highlight spanning full terminal width
66    #[serde(default = "crate::defaults::cursor_guide_color")]
67    pub cursor_guide_color: [u8; 4],
68
69    // --- Shadow ---
70    /// Enable drop shadow behind cursor for better visibility against varying backgrounds
71    #[serde(default = "crate::defaults::bool_false")]
72    pub cursor_shadow_enabled: bool,
73
74    /// Cursor shadow color [R, G, B, A] (0-255)
75    #[serde(default = "crate::defaults::cursor_shadow_color")]
76    pub cursor_shadow_color: [u8; 4],
77
78    /// Cursor shadow offset in pixels [x, y]
79    #[serde(default = "crate::defaults::cursor_shadow_offset")]
80    pub cursor_shadow_offset: [f32; 2],
81
82    /// Cursor shadow blur radius in pixels
83    #[serde(default = "crate::defaults::cursor_shadow_blur")]
84    pub cursor_shadow_blur: f32,
85
86    // --- Boost / Glow ---
87    /// Cursor boost (glow) intensity (0.0 = off, 1.0 = maximum boost)
88    /// Adds a glow/highlight effect around the cursor for visibility
89    #[serde(default = "crate::defaults::cursor_boost")]
90    pub cursor_boost: f32,
91
92    /// Cursor boost glow color [R, G, B] (0-255)
93    #[serde(default = "crate::defaults::cursor_boost_color")]
94    pub cursor_boost_color: [u8; 3],
95
96    // --- Unfocused ---
97    /// Cursor appearance when window is unfocused
98    /// - hollow: Show outline-only block cursor (default, standard terminal behavior)
99    /// - same: Keep same cursor style as when focused
100    /// - hidden: Hide cursor completely when unfocused
101    #[serde(default)]
102    pub unfocused_cursor_style: UnfocusedCursorStyle,
103}
104
105impl Default for CursorConfig {
106    fn default() -> Self {
107        Self {
108            cursor_blink: crate::defaults::bool_false(),
109            cursor_blink_interval: crate::defaults::cursor_blink_interval(),
110            cursor_style: CursorStyle::default(),
111            cursor_color: crate::defaults::cursor_color(),
112            cursor_text_color: None,
113            lock_cursor_visibility: crate::defaults::bool_false(),
114            lock_cursor_style: crate::defaults::bool_false(),
115            lock_cursor_blink: crate::defaults::bool_false(),
116            cursor_guide_enabled: crate::defaults::bool_false(),
117            cursor_guide_color: crate::defaults::cursor_guide_color(),
118            cursor_shadow_enabled: crate::defaults::bool_false(),
119            cursor_shadow_color: crate::defaults::cursor_shadow_color(),
120            cursor_shadow_offset: crate::defaults::cursor_shadow_offset(),
121            cursor_shadow_blur: crate::defaults::cursor_shadow_blur(),
122            cursor_boost: crate::defaults::cursor_boost(),
123            cursor_boost_color: crate::defaults::cursor_boost_color(),
124            unfocused_cursor_style: UnfocusedCursorStyle::default(),
125        }
126    }
127}