Skip to main content

par_term_config/config/config_struct/
shell_config.rs

1//! Shell launch and lifecycle 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::{ShellExitAction, StartupDirectoryMode};
8use serde::{Deserialize, Serialize};
9
10/// Which shell runs, where it starts, what it is sent, and what happens when it exits.
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct ShellConfig {
13    /// Action to take when the shell process exits
14    /// Supports: close, keep, restart_immediately, restart_with_prompt, restart_after_delay
15    /// For backward compatibility, also accepts boolean values (true=close, false=keep)
16    #[serde(
17        default,
18        deserialize_with = "super::deserialize_shell_exit_action",
19        alias = "exit_on_shell_exit",
20        alias = "close_on_shell_exit"
21    )]
22    pub shell_exit_action: ShellExitAction,
23
24    /// Custom shell command (defaults to system shell if not specified)
25    #[serde(default)]
26    pub custom_shell: Option<String>,
27
28    /// Arguments to pass to the shell
29    #[serde(default)]
30    pub shell_args: Option<Vec<String>>,
31
32    /// Working directory for the shell (legacy, use startup_directory_mode instead)
33    /// When set, overrides startup_directory_mode for backward compatibility
34    #[serde(default)]
35    pub working_directory: Option<String>,
36
37    /// Startup directory mode: controls where new sessions start
38    /// - home: Start in user's home directory (default)
39    /// - previous: Remember and restore last working directory from previous session
40    /// - custom: Start in the directory specified by startup_directory
41    #[serde(default)]
42    pub startup_directory_mode: StartupDirectoryMode,
43
44    /// Custom startup directory (used when startup_directory_mode is "custom")
45    /// Supports ~ for home directory expansion
46    #[serde(default)]
47    pub startup_directory: Option<String>,
48
49    /// Last working directory from previous session (auto-managed)
50    /// Used when startup_directory_mode is "previous"
51    #[serde(default)]
52    pub last_working_directory: Option<String>,
53
54    /// Environment variables to set for the shell
55    #[serde(default)]
56    pub shell_env: Option<std::collections::HashMap<String, String>>,
57
58    /// Whether to spawn the shell as a login shell (passes -l flag)
59    /// This is important on macOS to properly initialize PATH from Homebrew, /etc/paths.d, etc.
60    /// Default: true
61    #[serde(default = "crate::defaults::login_shell")]
62    pub login_shell: bool,
63
64    /// Text to send automatically when a terminal session starts
65    /// Supports escape sequences: \n (newline), \r (carriage return), \t (tab), \xHH (hex), \e (ESC)
66    #[serde(default = "crate::defaults::initial_text")]
67    pub initial_text: String,
68
69    /// Delay in milliseconds before sending the initial text (to allow shell to be ready)
70    #[serde(default = "crate::defaults::initial_text_delay_ms")]
71    pub initial_text_delay_ms: u64,
72
73    /// Whether to append a newline after sending the initial text
74    #[serde(default = "crate::defaults::initial_text_send_newline")]
75    pub initial_text_send_newline: bool,
76
77    /// Answerback string sent in response to ENQ (0x05) control character
78    /// This is a legacy terminal feature used for terminal identification.
79    /// Default: empty (disabled) for security
80    /// Common values: "par-term", "vt100", or custom identification
81    /// Security note: Setting this may expose terminal identification to applications
82    #[serde(default = "crate::defaults::answerback_string")]
83    pub answerback_string: String,
84
85    /// Show confirmation dialog before quitting the application
86    /// When enabled, closing the window will show a confirmation dialog
87    /// if there are any open terminal sessions.
88    /// Default: false (close immediately without confirmation)
89    #[serde(default = "crate::defaults::bool_false")]
90    pub prompt_on_quit: bool,
91
92    /// Show confirmation dialog before closing a tab with running jobs
93    /// When enabled, closing a tab that has a running command will show a confirmation dialog.
94    /// Default: false (close immediately without confirmation)
95    #[serde(default = "crate::defaults::bool_false")]
96    pub confirm_close_running_jobs: bool,
97
98    /// List of job/process names to ignore when checking for running jobs
99    /// These jobs will not trigger a close confirmation dialog.
100    /// Common examples: "bash", "zsh", "fish", "cat", "less", "man", "sleep"
101    /// Default: common shell names that shouldn't block tab close
102    #[serde(default = "crate::defaults::jobs_to_ignore")]
103    pub jobs_to_ignore: Vec<String>,
104}
105
106impl Default for ShellConfig {
107    fn default() -> Self {
108        Self {
109            shell_exit_action: ShellExitAction::default(),
110            custom_shell: None,
111            shell_args: None,
112            working_directory: None,
113            startup_directory_mode: StartupDirectoryMode::default(),
114            startup_directory: None,
115            last_working_directory: None,
116            shell_env: None,
117            login_shell: crate::defaults::login_shell(),
118            initial_text: crate::defaults::initial_text(),
119            initial_text_delay_ms: crate::defaults::initial_text_delay_ms(),
120            initial_text_send_newline: crate::defaults::initial_text_send_newline(),
121            answerback_string: crate::defaults::answerback_string(),
122            prompt_on_quit: crate::defaults::bool_false(),
123            confirm_close_running_jobs: crate::defaults::bool_false(),
124            jobs_to_ignore: crate::defaults::jobs_to_ignore(),
125        }
126    }
127}