tmux_interface/commands/buffers/
save_buffer.rs1use crate::commands::constants::*;
2use crate::TmuxCommand;
3use std::borrow::Cow;
4
5pub type SaveB<'a> = SaveBuffer<'a>;
6
7#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
29pub struct SaveBuffer<'a> {
30 #[cfg(feature = "tmux_0_8")]
32 pub append: bool,
33
34 #[cfg(feature = "tmux_2_0")]
36 pub buffer_name: Option<Cow<'a, str>>,
37
38 #[cfg(all(feature = "tmux_0_8", not(feature = "tmux_2_0")))]
40 pub buffer_index: Option<Cow<'a, str>>,
41
42 #[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_5")))]
44 pub target_session: Option<Cow<'a, str>>,
45
46 #[cfg(feature = "tmux_0_8")]
48 pub path: Option<Cow<'a, str>>,
49}
50
51impl<'a> SaveBuffer<'a> {
52 pub fn new() -> Self {
53 Default::default()
54 }
55
56 #[cfg(feature = "tmux_0_8")]
58 pub fn append(mut self) -> Self {
59 self.append = true;
60 self
61 }
62
63 #[cfg(feature = "tmux_2_0")]
65 pub fn buffer_name<S: Into<Cow<'a, str>>>(mut self, buffer_name: S) -> Self {
66 self.buffer_name = Some(buffer_name.into());
67 self
68 }
69
70 #[cfg(all(feature = "tmux_0_8", not(feature = "tmux_2_0")))]
72 pub fn buffer_index<S: Into<Cow<'a, str>>>(mut self, buffer_index: S) -> Self {
73 self.buffer_index = Some(buffer_index.into());
74 self
75 }
76
77 #[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_5")))]
79 pub fn target_session<S: Into<Cow<'a, str>>>(mut self, target_session: S) -> Self {
80 self.target_session = Some(target_session.into());
81 self
82 }
83
84 #[cfg(feature = "tmux_0_8")]
86 pub fn path<S: Into<Cow<'a, str>>>(mut self, path: S) -> Self {
87 self.path = Some(path.into());
88 self
89 }
90
91 pub fn build(self) -> TmuxCommand<'a> {
92 let mut cmd = TmuxCommand::new();
93
94 cmd.name(SAVE_BUFFER);
95
96 #[cfg(feature = "tmux_0_8")]
98 if self.append {
99 cmd.push_flag(A_LOWERCASE_KEY);
100 }
101
102 #[cfg(feature = "tmux_2_0")]
104 if let Some(buffer_name) = self.buffer_name {
105 cmd.push_option(B_LOWERCASE_KEY, buffer_name);
106 }
107
108 #[cfg(all(feature = "tmux_0_8", not(feature = "tmux_2_0")))]
110 if let Some(buffer_index) = self.buffer_index {
111 cmd.push_option(B_LOWERCASE_KEY, buffer_index);
112 }
113
114 #[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_5")))]
116 if let Some(target_session) = self.target_session {
117 cmd.push_option(T_LOWERCASE_KEY, target_session);
118 }
119
120 #[cfg(feature = "tmux_0_8")]
122 if let Some(path) = self.path {
123 cmd.push_param(path);
124 }
125
126 cmd
127 }
128}