1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
use crate::commands::constants::*;
use crate::TmuxCommand;
use std::borrow::Cow;
pub type SelectW<'a> = SelectWindow<'a>;
/// Select the window at target-window.
///
/// # Manual
///
/// tmux ^1.8:
/// ```text
/// select-window [-lnpT] [-t target-window]
/// (alias: selectw)
/// ```
///
/// tmux ^1.5:
/// ```text
/// select-window [-lnp] [-t target-window]
/// (alias: selectw)
/// ```
///
/// tmux ^0.8:
/// ```text
/// select-window [-t target-window]
/// (alias: selectw)
/// ```
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct SelectWindow<'a> {
/// `[-l]` - equivalent to last-window
#[cfg(feature = "tmux_1_5")]
pub last: bool,
/// `[-n]` - equivalent to next-window
#[cfg(feature = "tmux_1_5")]
pub next: bool,
/// `[-p]` - equivalent to previous-window
#[cfg(feature = "tmux_1_5")]
pub previous: bool,
/// `[-T]` - if the selected window is already the current window, behave like last-window
#[cfg(feature = "tmux_1_8")]
pub switch: bool,
/// `[-t target-window]` - target-window
#[cfg(feature = "tmux_0_8")]
pub target_window: Option<Cow<'a, str>>,
}
impl<'a> SelectWindow<'a> {
pub fn new() -> Self {
Default::default()
}
/// `[-l]` - equivalent to last-window
#[cfg(feature = "tmux_1_5")]
pub fn last(mut self) -> Self {
self.last = true;
self
}
/// `[-n]` - equivalent to next-window
#[cfg(feature = "tmux_1_5")]
pub fn next(mut self) -> Self {
self.next = true;
self
}
/// `[-p]` - equivalent to previous-window
#[cfg(feature = "tmux_1_5")]
pub fn previous(mut self) -> Self {
self.previous = true;
self
}
/// `[-T]` - if the selected window is already the current window, behave like last-window
#[cfg(feature = "tmux_1_8")]
pub fn switch(mut self) -> Self {
self.switch = true;
self
}
/// `[-t target-window]` - target-window
#[cfg(feature = "tmux_0_8")]
pub fn target_window<S: Into<Cow<'a, str>>>(mut self, target_window: S) -> Self {
self.target_window = Some(target_window.into());
self
}
pub fn build(self) -> TmuxCommand<'a> {
let mut cmd = TmuxCommand::new();
cmd.name(SELECT_WINDOW);
// `[-l]` - equivalent to last-window
#[cfg(feature = "tmux_1_5")]
if self.last {
cmd.push_flag(L_LOWERCASE_KEY);
}
// `[-n]` - equivalent to next-window
#[cfg(feature = "tmux_1_5")]
if self.next {
cmd.push_flag(N_LOWERCASE_KEY);
}
// `[-p]` - equivalent to previous-window
#[cfg(feature = "tmux_1_5")]
if self.previous {
cmd.push_flag(P_LOWERCASE_KEY);
}
// `[-T]` - if the selected window is already the current window, behave like last-window
#[cfg(feature = "tmux_1_8")]
if self.switch {
cmd.push_flag(T_UPPERCASE_KEY);
}
// `[-t target-window]` - target-window
#[cfg(feature = "tmux_0_8")]
if let Some(target_window) = self.target_window {
cmd.push_option(T_LOWERCASE_KEY, target_window);
}
cmd
}
}