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
use std::default::Default;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Config {
max_history_size: usize,
history_duplicates: HistoryDuplicates,
history_ignore_space: bool,
completion_type: CompletionType,
completion_prompt_limit: usize,
keyseq_timeout: i32,
edit_mode: EditMode,
auto_add_history: bool,
}
impl Config {
pub fn builder() -> Builder {
Builder::new()
}
pub fn max_history_size(&self) -> usize {
self.max_history_size
}
pub fn history_duplicates(&self) -> HistoryDuplicates {
self.history_duplicates
}
pub fn history_ignore_space(&self) -> bool {
self.history_ignore_space
}
pub fn completion_type(&self) -> CompletionType {
self.completion_type
}
pub fn completion_prompt_limit(&self) -> usize {
self.completion_prompt_limit
}
pub fn keyseq_timeout(&self) -> i32 {
self.keyseq_timeout
}
pub fn edit_mode(&self) -> EditMode {
self.edit_mode
}
pub fn auto_add_history(&self) -> bool {
self.auto_add_history
}
}
impl Default for Config {
fn default() -> Config {
Config {
max_history_size: 100,
history_duplicates: HistoryDuplicates::IgnoreConsecutive,
history_ignore_space: false,
completion_type: CompletionType::Circular,
completion_prompt_limit: 100,
keyseq_timeout: -1,
edit_mode: EditMode::Emacs,
auto_add_history: false,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum HistoryDuplicates {
AlwaysAdd,
IgnoreConsecutive,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum CompletionType {
Circular,
List,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum EditMode {
Emacs,
Vi,
}
#[derive(Debug, Default)]
pub struct Builder {
p: Config,
}
impl Builder {
pub fn new() -> Builder {
Builder {
p: Config::default(),
}
}
pub fn max_history_size(mut self, max_size: usize) -> Builder {
self.p.max_history_size = max_size;
self
}
pub fn history_ignore_dups(mut self, yes: bool) -> Builder {
self.p.history_duplicates = if yes {
HistoryDuplicates::IgnoreConsecutive
} else {
HistoryDuplicates::AlwaysAdd
};
self
}
pub fn history_ignore_space(mut self, yes: bool) -> Builder {
self.p.history_ignore_space = yes;
self
}
pub fn completion_type(mut self, completion_type: CompletionType) -> Builder {
self.p.completion_type = completion_type;
self
}
pub fn completion_prompt_limit(mut self, completion_prompt_limit: usize) -> Builder {
self.p.completion_prompt_limit = completion_prompt_limit;
self
}
pub fn keyseq_timeout(mut self, keyseq_timeout_ms: i32) -> Builder {
self.p.keyseq_timeout = keyseq_timeout_ms;
self
}
pub fn edit_mode(mut self, edit_mode: EditMode) -> Builder {
self.p.edit_mode = edit_mode;
match edit_mode {
EditMode::Emacs => self.p.keyseq_timeout = -1,
EditMode::Vi => self.p.keyseq_timeout = 500,
};
self
}
pub fn auto_add_history(mut self, yes: bool) -> Builder {
self.p.auto_add_history = yes;
self
}
pub fn build(self) -> Config {
self.p
}
}