Skip to main content

detect_terminal/
options.rs

1/// Controls optional command probes and diagnostic environment capture.
2///
3/// Defaults perform environment-only detection and capture the variables consulted by the
4/// detector. Command probes are opt-in, synchronous, and have no timeout.
5/// [`capture_env_subset`](Self::capture_env_subset) controls the diagnostic map; matched
6/// identifiers and raw terminal names remain in the result regardless of this setting.
7///
8/// See [Optional command probes](crate#optional-command-probes) for commands, prerequisites, and
9/// failure behavior. Disabling capture is not a privacy filter for the rest of the result.
10///
11/// # Example
12///
13/// With a matching session marker and executable on `PATH`, inspect the attempted probes.
14/// This example can block while the external commands run.
15///
16/// ```no_run
17/// use detect_terminal::{DetectOptions, detect_with_options};
18///
19/// let env = std::env::vars_os().collect();
20/// let options = DetectOptions {
21///     allow_commands: true,
22///     ..DetectOptions::default()
23/// };
24/// let info = detect_with_options(&env, options);
25/// for probe in &info.command_probes {
26///     println!(
27///         "Command: {}; exit: {:?}; error: {:?}",
28///         probe.command, probe.status, probe.error
29///     );
30/// }
31/// ```
32#[derive(Debug, Clone, Copy, PartialEq, Eq)]
33pub struct DetectOptions {
34    /// Run tmux, screen, or zellij probes using the supplied environment. Defaults to `false`.
35    pub allow_commands: bool,
36
37    /// Retain accessed environment values in the diagnostic map. Defaults to `true`.
38    pub capture_env_subset: bool,
39}
40
41impl Default for DetectOptions {
42    fn default() -> Self {
43        Self {
44            allow_commands: false,
45            capture_env_subset: true,
46        }
47    }
48}