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
use crate::commands::constants::*;
use crate::TmuxCommand;
use std::borrow::Cow;
pub type ResizeW<'a> = ResizeWindow<'a>;
/// Resize a window, up, down, left or right
///
/// # Manual
///
/// tmux ^2.9:
/// ```text
/// resize-window [-aADLRU] [-t target-window] [-x width] [-y height] [adjustment]
/// (alias: resizew)
/// ```
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct ResizeWindow<'a> {
/// `[-a]` - set the size of the smallest session containing the window
pub smallest: bool,
/// `[-A]` - set the size of the largest session containing the window
pub largest: bool,
/// `[-D]` - resize down by adjustment
pub down: bool,
/// `[-L]` - resize left by adjustment
pub left: bool,
/// `[-R]` - resize right by adjustment
pub right: bool,
/// `[-U]` - resize up by adjustment
pub up: bool,
/// `[-t target-window]` - target-window
pub target_window: Option<Cow<'a, str>>,
/// `[-x width]` - absolute size
pub width: Option<usize>,
/// `[-y height]` - absolute size
pub height: Option<usize>,
/// `[adjustment]` - adjustment
pub adjustment: Option<Cow<'a, str>>,
}
impl<'a> ResizeWindow<'a> {
pub fn new() -> Self {
Default::default()
}
/// `[-a]` - set the size of the smallest session containing the window
pub fn smallest(mut self) -> Self {
self.smallest = true;
self
}
/// `[-A]` - set the size of the largest session containing the window
pub fn largest(mut self) -> Self {
self.largest = true;
self
}
/// `[-D]` - resize down by adjustment
pub fn down(mut self) -> Self {
self.down = true;
self
}
/// `[-L]` - resize left by adjustment
pub fn left(mut self) -> Self {
self.left = true;
self
}
/// `[-R]` - resize right by adjustment
pub fn right(mut self) -> Self {
self.right = true;
self
}
/// `[-U]` - resize up by adjustment
pub fn up(mut self) -> Self {
self.up = true;
self
}
/// `[-t target-window]` - target-window
pub fn target_window<S: Into<Cow<'a, str>>>(mut self, target_window: S) -> Self {
self.target_window = Some(target_window.into());
self
}
/// `[-x width]` - absolute size
pub fn width(mut self, width: usize) -> Self {
self.width = Some(width);
self
}
/// `[-y height]` - absolute size
pub fn height(mut self, height: usize) -> Self {
self.height = Some(height);
self
}
/// `[adjustment]` - adjustment
pub fn adjustment<S: Into<Cow<'a, str>>>(mut self, adjustment: S) -> Self {
self.adjustment = Some(adjustment.into());
self
}
pub fn build(self) -> TmuxCommand<'a> {
let mut cmd = TmuxCommand::new();
cmd.name(RESIZE_WINDOW);
// `[-a]` - set the size of the smallest session containing the window
if self.smallest {
cmd.push_flag(A_LOWERCASE_KEY);
}
// `[-A]` - set the size of the largest session containing the window
if self.largest {
cmd.push_flag(A_UPPERCASE_KEY);
}
// `[-D]` - resize down by adjustment
if self.down {
cmd.push_flag(D_UPPERCASE_KEY);
}
// `[-L]` - resize left by adjustment
if self.left {
cmd.push_flag(L_UPPERCASE_KEY);
}
// `[-R]` - resize right by adjustment
if self.right {
cmd.push_flag(R_UPPERCASE_KEY);
}
// `[-U]` - resize up by adjustment
if self.up {
cmd.push_flag(U_UPPERCASE_KEY);
}
// `[-t target-window]` - target-window
if let Some(target_window) = self.target_window {
cmd.push_option(T_LOWERCASE_KEY, target_window);
}
// `[-x width]` - absolute size
if let Some(width) = self.width {
cmd.push_option(X_LOWERCASE_KEY, width.to_string());
}
// `[-y height]` - absolute size
if let Some(height) = self.height {
cmd.push_option(Y_LOWERCASE_KEY, height.to_string());
}
// `[adjustment]` - adjustment
if let Some(adjustment) = self.adjustment {
cmd.push_param(adjustment);
}
cmd
}
}