tmux_interface/commands/windows_and_panes/
kill_pane.rs

1use crate::commands::constants::*;
2use crate::TmuxCommand;
3use std::borrow::Cow;
4
5pub type KillP<'a> = KillPane<'a>;
6
7/// Destroy the given pane
8///
9/// # Manual
10///
11/// tmux ^1.1:
12/// ```text
13/// kill-pane [-a] [-t target-pane]
14/// (alias: killp)
15/// ```
16///
17/// tmux ^1.0:
18/// ```text
19/// kill-pane [-t target-pane]
20/// (alias: killp)
21/// ```
22///
23/// tmux ^0.8:
24/// ```text
25/// kill-pane [-p pane-index] [-t target-window]
26/// (alias: killp)
27/// ```
28#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
29pub struct KillPane<'a> {
30    /// `[-a]`
31    #[cfg(feature = "tmux_1_1")]
32    pub all: bool,
33
34    /// `[-t target-pane]`
35    #[cfg(feature = "tmux_1_0")]
36    pub target_pane: Option<Cow<'a, str>>,
37
38    /// `[-p pane-index]`
39    #[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_0")))]
40    pub pane_index: Option<Cow<'a, str>>,
41
42    /// `[-t target-window]`
43    #[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_0")))]
44    pub target_window: Option<Cow<'a, str>>,
45}
46
47impl<'a> KillPane<'a> {
48    pub fn new() -> Self {
49        Default::default()
50    }
51
52    /// `[-a]`
53    #[cfg(feature = "tmux_1_1")]
54    pub fn all(mut self) -> Self {
55        self.all = true;
56        self
57    }
58
59    /// `[-t target-pane]`
60    #[cfg(feature = "tmux_1_0")]
61    pub fn target_pane<S: Into<Cow<'a, str>>>(mut self, target_pane: S) -> Self {
62        self.target_pane = Some(target_pane.into());
63        self
64    }
65
66    /// `[-p pane-index]`
67    #[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_0")))]
68    pub fn pane_index<S: Into<Cow<'a, str>>>(mut self, pane_index: S) -> Self {
69        self.pane_index = Some(pane_index.into());
70        self
71    }
72
73    /// `[-t target-window]`
74    #[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_0")))]
75    pub fn target_window<S: Into<Cow<'a, str>>>(mut self, target_window: S) -> Self {
76        self.target_window = Some(target_window.into());
77        self
78    }
79
80    pub fn build(self) -> TmuxCommand<'a> {
81        let mut cmd = TmuxCommand::new();
82
83        cmd.name(KILL_PANE);
84
85        // `[-a]`
86        #[cfg(feature = "tmux_1_1")]
87        if self.all {
88            cmd.push_flag(A_LOWERCASE_KEY);
89        }
90
91        // `[-t target-pane]`
92        #[cfg(feature = "tmux_1_0")]
93        if let Some(target_pane) = self.target_pane {
94            cmd.push_option(T_LOWERCASE_KEY, target_pane);
95        }
96
97        // `[-p pane-index]`
98        #[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_0")))]
99        if let Some(pane_index) = self.pane_index {
100            cmd.push_option(P_LOWERCASE_KEY, pane_index);
101        }
102
103        // `[-t target-window]`
104        #[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_0")))]
105        if let Some(target_window) = self.target_window {
106            cmd.push_option(T_LOWERCASE_KEY, target_window);
107        }
108
109        cmd
110    }
111}