tmux_interface/commands/windows_and_panes/
kill_pane.rs1use crate::commands::constants::*;
2use crate::TmuxCommand;
3use std::borrow::Cow;
4
5pub type KillP<'a> = KillPane<'a>;
6
7#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
29pub struct KillPane<'a> {
30 #[cfg(feature = "tmux_1_1")]
32 pub all: bool,
33
34 #[cfg(feature = "tmux_1_0")]
36 pub target_pane: Option<Cow<'a, str>>,
37
38 #[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_0")))]
40 pub pane_index: Option<Cow<'a, str>>,
41
42 #[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 #[cfg(feature = "tmux_1_1")]
54 pub fn all(mut self) -> Self {
55 self.all = true;
56 self
57 }
58
59 #[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 #[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 #[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 #[cfg(feature = "tmux_1_1")]
87 if self.all {
88 cmd.push_flag(A_LOWERCASE_KEY);
89 }
90
91 #[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 #[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 #[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}