Skip to main content

par_term_config/config/config_struct/
tmux_config.rs

1//! tmux control-mode integration 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 serde::{Deserialize, Serialize};
8
9/// tmux control-mode integration: discovery, auto-attach and status bar.
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct TmuxConfig {
12    /// Enable tmux control mode integration
13    #[serde(default = "crate::defaults::bool_false")]
14    pub tmux_enabled: bool,
15
16    /// Path to tmux executable (default: "tmux" - uses PATH)
17    #[serde(default = "crate::defaults::tmux_path")]
18    pub tmux_path: String,
19
20    /// Default session name when creating new tmux sessions
21    #[serde(default = "crate::defaults::tmux_default_session")]
22    pub tmux_default_session: Option<String>,
23
24    /// Auto-attach to existing tmux session on startup
25    #[serde(default = "crate::defaults::bool_false")]
26    pub tmux_auto_attach: bool,
27
28    /// Session name to auto-attach to (if tmux_auto_attach is true)
29    #[serde(default = "crate::defaults::tmux_auto_attach_session")]
30    pub tmux_auto_attach_session: Option<String>,
31
32    /// Sync clipboard with tmux paste buffer
33    /// When copying in par-term, also update tmux's paste buffer via set-buffer
34    #[serde(default = "crate::defaults::bool_true")]
35    pub tmux_clipboard_sync: bool,
36
37    /// Hide the tmux control-mode gateway tab while tmux windows are active.
38    /// When enabled, the tab running `tmux -CC` is hidden from the tab bar once
39    /// the first tmux window tab appears. It is restored when the session ends.
40    /// Default: false
41    #[serde(default = "crate::defaults::bool_false")]
42    pub tmux_hide_gateway_tab: bool,
43
44    /// Profile to switch to when connected to tmux
45    /// When profiles feature is implemented, this will automatically
46    /// switch to the specified profile when entering tmux mode
47    #[serde(default)]
48    pub tmux_profile: Option<String>,
49
50    /// Show tmux status bar in par-term UI
51    /// When connected to tmux, display the status bar at the bottom of the terminal
52    #[serde(default = "crate::defaults::bool_false")]
53    pub tmux_show_status_bar: bool,
54
55    /// Tmux status bar refresh interval in milliseconds
56    /// How often to poll tmux for updated status bar content.
57    /// Lower values mean more frequent updates but slightly more CPU usage.
58    /// Default: 1000 (1 second)
59    #[serde(default = "crate::defaults::tmux_status_bar_refresh_ms")]
60    pub tmux_status_bar_refresh_ms: u64,
61
62    /// Tmux prefix key for control mode
63    /// In control mode, par-term intercepts this key combination and waits for a command key.
64    /// Format: "C-b" (Ctrl+B, default), "C-Space" (Ctrl+Space), "C-a" (Ctrl+A), etc.
65    /// The prefix + command key is translated to the appropriate tmux command.
66    #[serde(default = "crate::defaults::tmux_prefix_key")]
67    pub tmux_prefix_key: String,
68
69    /// Use native tmux format strings for status bar content
70    /// When true, queries tmux for the actual status-left and status-right values
71    /// using `display-message -p '#{T:status-left}'` command.
72    /// When false, uses par-term's configurable format strings below.
73    #[serde(default = "crate::defaults::bool_false")]
74    pub tmux_status_bar_use_native_format: bool,
75
76    /// Tmux status bar left side format string.
77    ///
78    /// Supported variables:
79    /// - `{session}` - Session name
80    /// - `{windows}` - Window list with active marker (*)
81    /// - `{pane}` - Focused pane ID
82    /// - `{time:FORMAT}` - Current time with strftime format (e.g., `{time:%H:%M}`)
83    /// - `{hostname}` - Machine hostname
84    /// - `{user}` - Current username
85    ///
86    /// Default: `[{session}] {windows}`
87    #[serde(default = "crate::defaults::tmux_status_bar_left")]
88    pub tmux_status_bar_left: String,
89
90    /// Tmux status bar right side format string.
91    ///
92    /// Same variables as `tmux_status_bar_left`.
93    ///
94    /// Default: `{pane} | {time:%H:%M}`
95    #[serde(default = "crate::defaults::tmux_status_bar_right")]
96    pub tmux_status_bar_right: String,
97}
98
99impl Default for TmuxConfig {
100    fn default() -> Self {
101        Self {
102            tmux_enabled: crate::defaults::bool_false(),
103            tmux_path: crate::defaults::tmux_path(),
104            tmux_default_session: crate::defaults::tmux_default_session(),
105            tmux_auto_attach: crate::defaults::bool_false(),
106            tmux_auto_attach_session: crate::defaults::tmux_auto_attach_session(),
107            tmux_clipboard_sync: crate::defaults::bool_true(),
108            tmux_hide_gateway_tab: crate::defaults::bool_false(),
109            tmux_profile: None,
110            tmux_show_status_bar: crate::defaults::bool_false(),
111            tmux_status_bar_refresh_ms: crate::defaults::tmux_status_bar_refresh_ms(),
112            tmux_prefix_key: crate::defaults::tmux_prefix_key(),
113            tmux_status_bar_use_native_format: crate::defaults::bool_false(),
114            tmux_status_bar_left: crate::defaults::tmux_status_bar_left(),
115            tmux_status_bar_right: crate::defaults::tmux_status_bar_right(),
116        }
117    }
118}