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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
|
//! Handles cli and configuration options
use crate::cli::Command;
use crate::data::InputMode;
use clap::{ArgEnum, Args};
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use std::str::FromStr;
#[derive(Copy, Clone, Debug, PartialEq, Deserialize, Serialize, ArgEnum)]
pub enum OnForceClose {
#[serde(alias = "quit")]
Quit,
#[serde(alias = "detach")]
Detach,
}
impl Default for OnForceClose {
fn default() -> Self {
Self::Detach
}
}
impl FromStr for OnForceClose {
type Err = Box<dyn std::error::Error>;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"quit" => Ok(Self::Quit),
"detach" => Ok(Self::Detach),
e => Err(e.to_string().into()),
}
}
}
#[derive(Clone, Default, Debug, PartialEq, Deserialize, Serialize, Args)]
/// Options that can be set either through the config file,
/// or cli flags - cli flags should take precedence over the config file
/// TODO: In order to correctly parse boolean flags, this is currently split
/// into Options and CliOptions, this could be a good canditate for a macro
pub struct Options {
/// Allow plugins to use a more simplified layout
/// that is compatible with more fonts (true or false)
#[clap(long, value_parser)]
#[serde(default)]
pub simplified_ui: Option<bool>,
/// Set the default theme
#[clap(long, value_parser)]
pub theme: Option<String>,
/// Set the default mode
#[clap(long, arg_enum, hide_possible_values = true, value_parser)]
pub default_mode: Option<InputMode>,
/// Set the default shell
#[clap(long, value_parser)]
pub default_shell: Option<PathBuf>,
/// Set the default layout
#[clap(long, value_parser)]
pub default_layout: Option<PathBuf>,
/// Set the layout_dir, defaults to
/// subdirectory of config dir
#[clap(long, value_parser)]
pub layout_dir: Option<PathBuf>,
/// Set the theme_dir, defaults to
/// subdirectory of config dir
#[clap(long, value_parser)]
pub theme_dir: Option<PathBuf>,
#[clap(long, value_parser)]
#[serde(default)]
/// Set the handling of mouse events (true or false)
/// Can be temporarily bypassed by the [SHIFT] key
pub mouse_mode: Option<bool>,
#[clap(long, value_parser)]
#[serde(default)]
/// Set display of the pane frames (true or false)
pub pane_frames: Option<bool>,
#[clap(long, value_parser)]
#[serde(default)]
/// Mirror session when multiple users are connected (true or false)
pub mirror_session: Option<bool>,
/// Set behaviour on force close (quit or detach)
#[clap(long, arg_enum, hide_possible_values = true, value_parser)]
pub on_force_close: Option<OnForceClose>,
#[clap(long, value_parser)]
pub scroll_buffer_size: Option<usize>,
/// Switch to using a user supplied command for clipboard instead of OSC52
#[clap(long, value_parser)]
#[serde(default)]
pub copy_command: Option<String>,
/// OSC52 destination clipboard
#[clap(
long,
arg_enum,
ignore_case = true,
conflicts_with = "copy-command",
value_parser
)]
#[serde(default)]
pub copy_clipboard: Option<Clipboard>,
/// Automatically copy when selecting text (true or false)
#[clap(long, value_parser)]
#[serde(default)]
pub copy_on_select: Option<bool>,
/// Explicit full path to open the scrollback editor (default is $EDITOR or $VISUAL)
#[clap(long, value_parser)]
pub scrollback_editor: Option<PathBuf>,
/// The name of the session to create when starting Zellij
#[clap(long, value_parser)]
#[serde(default)]
pub session_name: Option<String>,
/// Whether to attach to a session specified in "session-name" if it exists
#[clap(long, value_parser)]
#[serde(default)]
pub attach_to_session: Option<bool>,
/// Whether to lay out panes in a predefined set of layouts whenever possible
#[clap(long, value_parser)]
#[serde(default)]
pub auto_layout: Option<bool>,
}
#[derive(ArgEnum, Deserialize, Serialize, Debug, Clone, Copy, PartialEq)]
pub enum Clipboard {
#[serde(alias = "system")]
System,
#[serde(alias = "primary")]
Primary,
}
impl Default for Clipboard {
fn default() -> Self {
Self::System
}
}
impl FromStr for Clipboard {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"System" | "system" => Ok(Self::System),
"Primary" | "primary" => Ok(Self::Primary),
_ => Err(format!("No such clipboard: {}", s)),
}
}
}
impl Options {
pub fn from_yaml(from_yaml: Option<Options>) -> Options {
if let Some(opts) = from_yaml {
opts
} else {
Options::default()
}
}
/// Merges two [`Options`] structs, a `Some` in `other`
/// will supersede a `Some` in `self`
// TODO: Maybe a good candidate for a macro?
pub fn merge(&self, other: Options) -> Options {
let mouse_mode = other.mouse_mode.or(self.mouse_mode);
let pane_frames = other.pane_frames.or(self.pane_frames);
let auto_layout = other.auto_layout.or(self.auto_layout);
let mirror_session = other.mirror_session.or(self.mirror_session);
let simplified_ui = other.simplified_ui.or(self.simplified_ui);
let default_mode = other.default_mode.or(self.default_mode);
let default_shell = other.default_shell.or_else(|| self.default_shell.clone());
let default_layout = other.default_layout.or_else(|| self.default_layout.clone());
let layout_dir = other.layout_dir.or_else(|| self.layout_dir.clone());
let theme_dir = other.theme_dir.or_else(|| self.theme_dir.clone());
let theme = other.theme.or_else(|| self.theme.clone());
let on_force_close = other.on_force_close.or(self.on_force_close);
let scroll_buffer_size = other.scroll_buffer_size.or(self.scroll_buffer_size);
let copy_command = other.copy_command.or_else(|| self.copy_command.clone());
let copy_clipboard = other.copy_clipboard.or(self.copy_clipboard);
let copy_on_select = other.copy_on_select.or(self.copy_on_select);
let scrollback_editor = other
.scrollback_editor
.or_else(|| self.scrollback_editor.clone());
let session_name = other.session_name.or_else(|| self.session_name.clon
|