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
//! Vim-style `:` command input bar
//! Ported from pinel's hotkey/command_input.rs, adapted for iced.
#[derive(Default)]
pub struct CommandInput {
pub open: bool,
pub input: String,
}
impl CommandInput {
pub fn open(&mut self) {
self.open = true;
self.input.clear();
}
pub fn close(&mut self) {
self.open = false;
}
/// Process the command in a vim command style
///
/// # Arguments
///
/// - `&self` (`undefined`) - Provides variables and functions avaiable for `Self` usage
///
/// # Returns
///
/// - `Option<String>` - Returns the option chosen based on the input
pub fn process_command(&self) -> Option<String> {
let cmd = self.input.trim();
if cmd.is_empty() {
return None;
}
match cmd {
"w" | "write" => Some("Save File".to_string()),
"q" | "quit" => Some("Quit".to_string()),
"wq" => Some("Save and Quit".to_string()),
"e" | "edit" => Some("Open File".to_string()),
"new" => Some("New File".to_string()),
_ => None,
}
}
}