Skip to main content

tmux_interface/commands/buffers/
save_buffer_macro.rs

1// auto-generated file
2//
3
4/// Save the contents of the specified paste buffer to path.
5///
6/// # Manual
7///
8/// tmux >=2.0:
9/// ```text
10/// save-buffer [-a] [-b buffer-name] path
11/// (alias: saveb)
12/// ```
13///
14/// tmux >=1.5:
15/// ```text
16/// save-buffer [-a] [-b buffer-index] path
17/// (alias: saveb)
18/// ```
19///
20/// tmux >=0.8:
21/// ```text
22/// save-buffer [-a] [-b buffer-index] [-t target-session] path
23/// (alias: saveb)
24/// ```
25#[macro_export]
26macro_rules! save_buffer {
27    // `[-a]`
28    (@cmd ($cmd:expr) -a, $($tail:tt)*) => {{
29        $crate::save_buffer!(@cmd ({
30            $cmd.append()
31        }) $($tail)*)
32    }};
33
34    // `[-b buffer]`
35    (@cmd ($cmd:expr) -b $buffer:expr, $($tail:tt)*) => {{
36        $crate::save_buffer!(@cmd ({
37            #[cfg(all(feature = "tmux_0_8", not(feature = "tmux_2_0")))]
38            {
39                $cmd.buffer_index($buffer)
40            }
41            #[cfg(feature = "tmux_2_0")]
42            {
43                $cmd.buffer_name($buffer)
44            }
45        }) $($tail)*)
46    }};
47
48    // `[-t target-session]`
49    (@cmd ($cmd:expr) -t $target_session:expr, $($tail:tt)*) => {{
50        $crate::save_buffer!(@cmd ({
51            $cmd.target_session($target_session)
52        }) $($tail)*)
53    }};
54
55    // `[path]`
56    (@cmd ($cmd:expr) $path:expr, $($tail:tt)*) => {{
57        $crate::save_buffer!(@cmd ({
58            $cmd.path($path)
59        }) $($tail)*)
60    }};
61
62    //(@cmd ($cmd:expr) -$unknown:tt, $($tail:tt)*) => {{
63        //::std::compile_error!("unknown flag, option or parameter: {}", $unknown);
64    //}};
65    (@cmd ($cmd:expr)) => {{
66        $cmd
67    }};
68    () => {{
69        $crate::SaveBuffer::new()
70    }};
71    (($cmd:expr), $($tail:tt)*) => {{
72        $crate::save_buffer!(@cmd ($cmd) $($tail)*,)
73    }};
74    ($($tail:tt)*) => {{
75        $crate::save_buffer!(@cmd ({ $crate::SaveBuffer::new() }) $($tail)*,)
76    }};
77}
78
79#[test]
80fn save_buffer_macro() {
81    use std::borrow::Cow;
82
83    // Save the contents of the specified paste buffer to path.
84    //
85    // # Manual
86    //
87    // tmux >=2.0:
88    // ```text
89    // save-buffer [-a] [-b buffer-name] path
90    // (alias: saveb)
91    // ```
92    //
93    // tmux >=1.5:
94    // ```text
95    // save-buffer [-a] [-b buffer-index] path
96    // (alias: saveb)
97    // ```
98    //
99    // tmux >=0.8:
100    // ```text
101    // save-buffer [-a] [-b buffer-index] [-t target-session] path
102    // (alias: saveb)
103    // ```
104
105    let save_buffer = save_buffer!();
106    #[cfg(feature = "tmux_0_8")]
107    let save_buffer = save_buffer!((save_buffer), -a);
108    #[cfg(all(feature = "tmux_0_8", not(feature = "tmux_2_0")))]
109    let save_buffer = save_buffer!((save_buffer), -b "1");
110    #[cfg(feature = "tmux_2_0")]
111    let save_buffer = save_buffer!((save_buffer), -b "2");
112    #[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_5")))]
113    let save_buffer = save_buffer!((save_buffer), -t "3");
114    #[cfg(feature = "tmux_0_8")]
115    let save_buffer = save_buffer!((save_buffer), "4");
116
117    #[cfg(not(feature = "cmd_alias"))]
118    let cmd = "save-buffer";
119    #[cfg(feature = "cmd_alias")]
120    let cmd = "saveb";
121
122    let mut s = Vec::new();
123    s.push(cmd);
124    #[cfg(feature = "tmux_0_8")]
125    s.push("-a");
126    #[cfg(all(feature = "tmux_0_8", not(feature = "tmux_2_0")))]
127    s.extend_from_slice(&["-b", "1"]);
128    #[cfg(feature = "tmux_2_0")]
129    s.extend_from_slice(&["-b", "2"]);
130    #[cfg(all(feature = "tmux_0_8", not(feature = "tmux_1_5")))]
131    s.extend_from_slice(&["-t", "3"]);
132    #[cfg(feature = "tmux_0_8")]
133    s.push("4");
134    let s: Vec<Cow<str>> = s.into_iter().map(|a| a.into()).collect();
135    let save_buffer = save_buffer.build().to_vec();
136
137    assert_eq!(save_buffer, s);
138}