Skip to main content

tmux_interface/commands/buffers/
delete_buffer.rs

1// auto-generated file
2//
3
4use crate::commands::constants::*;
5use crate::TmuxCommand;
6use std::borrow::Cow;
7
8pub type DeleteB<'a> = DeleteBuffer<'a>;
9
10/// Delete the buffer named buffer-name, or the most recently added automatically named buffer
11/// if not specified.
12///
13/// # Manual
14///
15/// tmux >=2.0:
16/// ```text
17/// delete-buffer [-b buffer-name]
18/// (alias: deleteb)
19/// ```
20///
21/// tmux >=1.5 && <2.0:
22/// ```text
23/// delete-buffer [-b buffer-index]
24/// (alias: deleteb)
25/// ```
26///
27/// tmux >=0.8:
28/// ```text
29/// delete-buffer [-b buffer-index] [-t target-session]
30/// (alias: deleteb)
31/// ```
32#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
33pub struct DeleteBuffer<'a> {
34    /// `[-b buffer-index]`
35    #[cfg(all(feature = "tmux_0_8", not(feature = "tmux_2_0")))]
36    pub buffer_index: Option<Cow<'a, str>>,
37
38    /// `[-b buffer-name]`
39    #[cfg(feature = "tmux_2_0")]
40    pub buffer_name: Option<Cow<'a, str>>,
41
42    /// `[-t target-session]`
43    #[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_5")))]
44    pub target_session: Option<Cow<'a, str>>,
45}
46
47impl<'a> DeleteBuffer<'a> {
48    pub fn new() -> Self {
49        Default::default()
50    }
51
52    /// `[-b buffer-index]`
53    #[cfg(all(feature = "tmux_0_8", not(feature = "tmux_2_0")))]
54    pub fn buffer_index<S: Into<Cow<'a, str>>>(mut self, buffer_index: S) -> Self {
55        self.buffer_index = Some(buffer_index.into());
56        self
57    }
58
59    /// `[-b buffer-name]`
60    #[cfg(feature = "tmux_2_0")]
61    pub fn buffer_name<S: Into<Cow<'a, str>>>(mut self, buffer_name: S) -> Self {
62        self.buffer_name = Some(buffer_name.into());
63        self
64    }
65
66    /// `[-t target-session]`
67    #[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_5")))]
68    pub fn target_session<S: Into<Cow<'a, str>>>(mut self, target_session: S) -> Self {
69        self.target_session = Some(target_session.into());
70        self
71    }
72
73    /// build command with arguments in right order
74    pub fn build(self) -> TmuxCommand<'a> {
75        let mut cmd = TmuxCommand::new();
76
77        cmd.name(DELETE_BUFFER);
78
79        // `[-b buffer-index]`
80        #[cfg(all(feature = "tmux_0_8", not(feature = "tmux_2_0")))]
81        if let Some(buffer_index) = self.buffer_index {
82            cmd.push_option(B_LOWERCASE_KEY, buffer_index);
83        }
84
85        // `[-b buffer-name]`
86        #[cfg(feature = "tmux_2_0")]
87        if let Some(buffer_name) = self.buffer_name {
88            cmd.push_option(B_LOWERCASE_KEY, buffer_name);
89        }
90
91        // `[-t target-session]`
92        #[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_5")))]
93        if let Some(target_session) = self.target_session {
94            cmd.push_option(T_LOWERCASE_KEY, target_session);
95        }
96
97        cmd
98    }
99}