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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
use crate::commands::constants::*;
use crate::TmuxCommand;
use std::borrow::Cow;
pub type Menu<'a> = DisplayMenu<'a>;
/// Structure for displaying a menu on target-client
///
/// # Manual
///
/// tmux ^3.2:
/// ```text
/// display-menu [-O] [-c target-client] [-t target-pane] [-T title] [-x position] [-y position] name key command ...
/// alias: menu
/// ```
///
/// tmux ^3.0:
/// ```text
/// display-menu [-c target-client] [-t target-pane] [-T title] [-x position] [-y position] name key command ...
/// alias: menu
/// ```
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
#[cfg(feature = "tmux_3_0")]
pub struct DisplayMenu<'a> {
/// `[-O]` - the menu does not close when the mouse button is released without an item selected
#[cfg(feature = "tmux_3_2")]
pub not_close: bool,
/// `[-c target-client]` - target-client
#[cfg(feature = "tmux_3_0")]
pub target_client: Option<Cow<'a, str>>,
/// `[-t target-pane]` - target-pane
#[cfg(feature = "tmux_3_0")]
pub target_pane: Option<Cow<'a, str>>,
/// `[-T title]` - title
#[cfg(feature = "tmux_3_0")]
pub title: Option<Cow<'a, str>>,
/// `[-x position]` - x position of the menu
#[cfg(feature = "tmux_3_0")]
pub x: Option<usize>,
/// `[-y position]` - y position of the menu
#[cfg(feature = "tmux_3_0")]
pub y: Option<usize>,
/// `name`
pub name: Option<Cow<'a, str>>,
/// `key`
pub key: Option<Cow<'a, str>>,
/// `command`
pub command: Option<Cow<'a, str>>,
}
impl<'a> DisplayMenu<'a> {
pub fn new() -> Self {
Default::default()
}
/// `[-O]` - the menu does not close when the mouse button is released without an item selected
#[cfg(feature = "tmux_3_2")]
pub fn not_close(mut self) -> Self {
self.not_close = true;
self
}
/// `[-c target-client]` - target-client
#[cfg(feature = "tmux_3_0")]
pub fn target_client<S: Into<Cow<'a, str>>>(mut self, target_client: S) -> Self {
self.target_client = Some(target_client.into());
self
}
/// `[-t target-pane]` - target-pane
#[cfg(feature = "tmux_3_0")]
pub fn target_pane<S: Into<Cow<'a, str>>>(mut self, target_pane: S) -> Self {
self.target_pane = Some(target_pane.into());
self
}
/// `[-T title]` - title
#[cfg(feature = "tmux_3_0")]
pub fn title<S: Into<Cow<'a, str>>>(mut self, title: S) -> Self {
self.title = Some(title.into());
self
}
/// `[-x position]` - x position of the menu
#[cfg(feature = "tmux_3_0")]
pub fn x(mut self, x: usize) -> Self {
self.x = Some(x);
self
}
/// `[-y position]` - y position of the menu
#[cfg(feature = "tmux_3_0")]
pub fn y(mut self, y: usize) -> Self {
self.y = Some(y);
self
}
/// `name`
pub fn name<S: Into<Cow<'a, str>>>(mut self, name: S) -> Self {
self.name = Some(name.into());
self
}
/// `key`
pub fn key<S: Into<Cow<'a, str>>>(mut self, key: S) -> Self {
self.key = Some(key.into());
self
}
pub fn command<S: Into<Cow<'a, str>>>(mut self, command: S) -> Self {
self.command = Some(command.into());
self
}
pub fn build(self) -> TmuxCommand<'a> {
let mut cmd = TmuxCommand::new();
cmd.name(DISPLAY_MENU);
// `[-O]` - the menu does not close when the mouse button is released without an item selected
#[cfg(feature = "tmux_3_2")]
if self.not_close {
cmd.push_flag(O_UPPERCASE_KEY);
}
// `[-c target-client]` - target-client
#[cfg(feature = "tmux_3_0")]
if let Some(target_client) = self.target_client {
cmd.push_option(C_LOWERCASE_KEY, target_client);
}
// `[-t target-pane]` - target-pane
#[cfg(feature = "tmux_3_0")]
if let Some(target_pane) = self.target_pane {
cmd.push_option(T_LOWERCASE_KEY, target_pane);
}
// `[-T title]` - title
#[cfg(feature = "tmux_3_0")]
if let Some(title) = self.title {
cmd.push_option(T_UPPERCASE_KEY, title);
}
// `[-x position]` - x position of the menu
#[cfg(feature = "tmux_3_0")]
if let Some(x) = self.x {
cmd.push_option(X_LOWERCASE_KEY, x.to_string());
}
// `[-y position]` - y position of the menu
#[cfg(feature = "tmux_3_0")]
if let Some(y) = self.y {
cmd.push_option(Y_LOWERCASE_KEY, y.to_string());
}
// `name`
if let Some(name) = self.name {
cmd.push_param(name);
}
// `key`
if let Some(key) = self.key {
cmd.push_param(key);
}
// `command`
if let Some(command) = self.command {
cmd.push_param(command);
}
cmd
}
}