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
|
use crate::app::Status;
use crate::modes::{
Edit, InputCompleted, InputSimple, MarkAction, Navigate, NeedConfirmation, PasswordKind,
PasswordUsage,
};
pub trait LineDisplay {
/// Returns a displayable representation of the object as a vector of `String`s
fn line_display(&self, status: &Status) -> Vec<String>;
}
impl LineDisplay for Edit {
fn line_display(&self, status: &Status) -> Vec<String> {
match self {
Self::Navigate(mode) => mode.line_display(status),
Self::InputSimple(mode) => mode.line_display(status),
Self::InputCompleted(mode) => mode.line_display(status),
Self::NeedConfirmation(mode) => mode.line_display(status),
Self::Nothing => vec![],
}
}
}
impl LineDisplay for NeedConfirmation {
fn line_display(&self, _status: &Status) -> Vec<String> {
vec![format!("{self}"), " (y/n)".to_owned()]
}
}
impl LineDisplay for Navigate {
fn line_display(&self, _status: &Status) -> Vec<String> {
match self {
Self::Marks(MarkAction::Jump) => {
vec!["Jump to...".to_owned()]
}
Self::Marks(MarkAction::New) => {
vec!["Save mark...".to_owned()]
}
_ => {
vec![Edit::Navigate(*self).to_string()]
}
}
}
}
impl LineDisplay for InputCompleted {
fn line_display(&self, status: &Status) -> Vec<String> {
let tab = status.current_tab();
let mut completion_strings = vec![tab.edit_mode.to_string(), status.menu.input.string()];
if let Some(completion) = status
.menu
.completion
.complete_input_string(&status.menu.input.string())
{
completion_strings.push(completion.to_owned());
}
if matches!(*self, Self::Exec) {
if let Ok(selected) = tab.current_file() {
completion_strings.push(format!(" {}", selected.path.display()));
}
}
completion_strings
}
}
impl LineDisplay for InputSimple {
fn line_display(&self, status: &Status) -> Vec<String> {
match self {
Self::Password(_, PasswordUsage::CRYPTSETUP(PasswordKind::CRYPTSETUP)) => {
vec![
PasswordKind::CRYPTSETUP.to_string(),
status.menu.input.password(),
]
}
Self::Password(_, _) => {
vec![PasswordKind::SUDO.to_string(), status.menu.input.password()]
}
_ => {
vec![
Edit::InputSimple(*self).to_string(),
status.menu.input.string(),
]
}
}
}
}
|