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
|
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use serde::{Deserialize, Serialize};
use std::{fs::File, path::PathBuf};
use struct_patch::traits::Patch as PatchTrait;
use struct_patch::Patch;
#[derive(Debug, PartialOrd, Clone, Copy, Serialize, Deserialize)]
pub struct GituiKeyEvent {
pub code: KeyCode,
pub modifiers: KeyModifiers,
}
impl GituiKeyEvent {
pub const fn new(code: KeyCode, modifiers: KeyModifiers) -> Self {
Self { code, modifiers }
}
}
pub fn key_match(ev: &KeyEvent, binding: GituiKeyEvent) -> bool {
ev.code == binding.code && ev.modifiers == binding.modifiers
}
impl PartialEq for GituiKeyEvent {
fn eq(&self, other: &Self) -> bool {
let ev: KeyEvent = self.into();
let other: KeyEvent = other.into();
ev == other
}
}
impl From<&GituiKeyEvent> for KeyEvent {
fn from(other: &GituiKeyEvent) -> Self {
Self::new(other.code, other.modifiers)
}
}
#[derive(Debug, Clone, Patch)]
#[patch_derive(Deserialize, Debug)]
pub struct KeysList {
pub tab_status: GituiKeyEvent,
pub tab_log: GituiKeyEvent,
pub tab_files: GituiKeyEvent,
pub tab_stashing: GituiKeyEvent,
pub tab_stashes: GituiKeyEvent,
pub tab_toggle: GituiKeyEvent,
pub tab_toggle_reverse: GituiKeyEvent,
pub toggle_workarea: GituiKeyEvent,
pub exit: GituiKeyEvent,
pub quit: GituiKeyEvent,
pub exit_popup: GituiKeyEvent,
pub open_commit: GituiKeyEvent,
pub open_commit_editor: GituiKeyEvent,
pub open_help: GituiKeyEvent,
pub open_options: GituiKeyEvent,
pub move_left: GituiKeyEvent,
pub move_right: GituiKeyEvent,
pub move_up: GituiKeyEvent,
pub move_down: GituiKeyEvent,
pub tree_collapse_recursive: GituiKeyEvent,
pub tree_expand_recursive: GituiKeyEvent,
pub home: GituiKeyEvent,
pub end: GituiKeyEvent,
pub popup_up: GituiKeyEvent,
pub popup_down: GituiKeyEvent,
pub page_down: GituiKeyEvent,
pub page_up: GituiKeyEvent,
pub shift_up: GituiKeyEvent,
pub shift_down: GituiKeyEvent,
pub enter: GituiKeyEvent,
pub blame: GituiKeyEvent,
pub file_history: GituiKeyEvent,
pub edit_file: GituiKeyEvent,
pub status_stage_all: GituiKeyEvent,
pub status_reset_item: GituiKeyEvent,
pub status_ignore_file: GituiKeyEvent,
pub diff_stage_lines: GituiKeyEvent,
pub diff_reset_lines: GituiKeyEvent,
pub stashing_save: GituiKeyEvent,
pub stashing_toggle_untracked: GituiKeyEvent,
pub stashing_toggle_index: GituiKeyEvent,
pub stash_apply: GituiKeyEvent,
pub stash_open: GituiKeyEvent,
pub stash_drop: GituiKeyEvent,
pub cmd_bar_toggle: GituiKeyEvent,
pub log_tag_commit: GituiKeyEvent,
pub log_mark_commit: GituiKeyEvent,
pub log_checkout_commit: GituiKeyEvent,
pub log_reset_comit: GituiKeyEvent,
pub log_reword_comit: GituiKeyEvent,
pub log_find: GituiKeyEvent,
pub find_commit_sha: GituiKeyEvent,
pub commit_amend: GituiKeyEvent,
pub toggle_signoff: GituiKeyEvent,
pub toggle_verify: GituiKeyEvent,
pub copy: GituiKeyEvent,
pub create_branch: GituiKeyEvent,
pub rename_branch: GituiKeyEvent,
pub select_branch: GituiKeyEvent,
pub delete_branch: GituiKeyEvent,
pub merge_branch: GituiKeyEvent,
pub rebase_branch: GituiKeyEvent,
pub compare_commits: GituiKeyEvent,
pub tags: GituiKeyEvent,
pub delete_tag: GituiKeyEvent,
pub select_tag: GituiKeyEvent,
pub push: GituiKeyEvent,
pub open_file_tree: GituiKeyEvent,
pub file_find: GituiKeyEvent,
pub branch_find: GituiKeyEvent,
pub force_push: GituiKeyEvent,
pub fetch: GituiKeyEvent,
pub pull: GituiKeyEvent,
pub abort_merge: GituiKeyEvent,
pub undo_commit: GituiKeyEvent,
pub diff_hunk_next: GituiKeyEvent,
pub diff_hunk_prev: GituiKeyEvent,
pub stage_unstage_item: GituiKeyEvent,
pub tag_annotate: GituiKeyEvent,
pub view_submodules: GituiKeyEvent,
pub view_submodule_parent: GituiKeyEvent,
pub update_submodule: GituiKeyEvent,
pub commit_history_next: GituiKeyEvent,
pub commit: GituiKeyEvent,
pub newline: GituiKeyEvent,
}
#[rustfmt::skip]
impl Default for KeysList {
fn default() -> Self {
Self {
tab_status: GituiKeyEvent::new(KeyCode::Char('1'), KeyModifiers::empty()),
tab_log: GituiKeyEvent::new(KeyCode::Char('2'), KeyModifiers::empty()),
tab_files: GituiKeyEvent::new(KeyCode::Char('3'), KeyModifiers::empty()),
tab_stashing: GituiKeyEvent::new(KeyCode::Char('4'), KeyModifiers::empty()),
tab_stashes: GituiKeyEvent::new(KeyCode::Char('5'), KeyModifiers::empty()),
tab_toggle: GituiKeyEvent::new(KeyCode::Tab, KeyModifiers::empty()),
tab_toggle_reverse: GituiKeyEvent::new(KeyCode::BackTab, KeyModifiers::SHIFT),
toggle_workarea: GituiKeyEvent::new(KeyCode::Char('w'), KeyModifiers::empty()),
exit: GituiKeyEvent::new(KeyCode::Char('c'), KeyModifiers::CONTROL),
quit: GituiKeyEvent::new(KeyCode::Char('q'), KeyModifiers::empty()),
exit_popup: GituiKeyEvent::new(KeyCode::Esc, KeyModifiers::empty()),
open_commit: GituiKeyEvent::new(KeyCode::Char('c'), KeyModifiers::empty()),
open_commit_editor: GituiKeyEvent::new(KeyCode::Char('e'), KeyModifiers::CONTROL),
open_help: GituiKeyEvent::new(KeyCode::Char('h'), KeyModifiers::empty()),
open_options: GituiKeyEvent::new(KeyCode::Char('o'), KeyModifiers::empty()),
move_left: GituiKeyEvent::new(KeyCode::Left, KeyModifiers::empty()),
move_right: GituiKeyEvent::new(KeyCode::Right, KeyModifiers::empty()),
tree_collapse_recursive: GituiKeyEvent::new(KeyCode::Left, KeyModifiers::SHIFT),
tree_expand_recursive: GituiKeyEvent::new(KeyCode::Right, KeyModifiers::SHIFT),
home: GituiKeyEvent::new(KeyCode::Home, KeyModifiers::empty()),
end: GituiKeyEvent::new(KeyCode::End, KeyModifiers::empty()),
move_up: GituiKeyEvent::new(KeyCode::Up, KeyModifiers::empty()),
move_down: GituiKeyEvent::new(KeyCode::Down, KeyModifiers::empty()),
popup_up: GituiKeyEvent::new(KeyCode::Up, KeyModifiers::empty()),
popup_down: GituiKeyEvent::new(KeyCode::Down, KeyModifiers::empty()),
page_down: GituiKeyEvent::new(KeyCode::PageDown, KeyModifiers::empty()),
page_up: GituiKeyEvent::new(KeyCode::PageUp, KeyModifiers::empty()),
shift_up: GituiKeyEvent::new(KeyCode::Up, KeyModifiers::SHIFT),
shift_down: GituiKeyEvent::new(KeyCode::Down, KeyModifiers::SHIFT),
enter: GituiKeyEvent::new(KeyCode::Enter, KeyModifiers::empty()),
blame: GituiKeyEvent::new(KeyCode::Char('B'), KeyModifiers::SHIFT),
file_history: GituiKeyEvent::new(KeyCode::Char('H'), KeyModifiers::SHIFT),
edit_file: GituiKeyEvent::new(KeyCode::Char('e'), KeyModifiers::empty()),
status_stage_all: GituiKeyEvent::new(KeyCode::Char('a'), KeyModifiers::empty()),
status_reset_item: GituiKeyEvent::new(KeyCode::Char('D'), KeyModifiers::SHIFT),
diff_reset_lines: GituiKeyEvent::new(KeyCode::Char('d'), KeyModifiers::empty()),
status_ignore_file: GituiKeyEvent::new(KeyCode::Char('i'), KeyModifiers::empty()),
diff_stage_lines: GituiKeyEvent::new(KeyCode::Char('s'), KeyModifiers::empty()),
stashing_save: GituiKeyEvent::new(KeyCode::Char('s'), KeyModifiers::empty()),
stashing_toggle_untracked: GituiKeyEvent::new(KeyCode::Char('u'), KeyModifiers::empty()),
stashing_toggle_index: GituiKeyEvent::new(KeyCode::Char('i'), KeyModifiers::empty()),
stash_apply: GituiKeyEvent::new(KeyCode::Char('a'), KeyModifiers::empty()),
stash_open: GituiKeyEvent::new(KeyCode::Right, KeyModifiers::empty()),
stash_drop: GituiKeyEvent::new(KeyCode::Char('D'), KeyModifiers::SHIFT),
cmd_bar_toggle: GituiKeyEvent::new(KeyCode::Char('.'), KeyModifiers::empty()),
log_tag_commit: GituiKeyEvent::new(KeyCode::Char('t'), KeyModifiers::empty()),
log_mark_commit: GituiKeyEvent::new(KeyCode::Char(' '), KeyModifiers::empty()),
log_checkout_commit: GituiKeyEvent { code: KeyCode::Char('S'), modifiers: KeyModifiers::SHIFT },
log_reset_comit: GituiKeyEvent { code: KeyCode::Char('R'), modifiers: KeyModifiers::SHIFT },
log_reword_comit: GituiKeyEvent { code: KeyCode::Char('r'), modifiers: KeyModifiers::empty() },
log_find: GituiKeyEvent { code: KeyCode::Char('f'), modifiers: KeyModifiers::empty() },
find_commit_sha: GituiKeyEvent::new(KeyCode::Char('j'), KeyModifiers::CONTROL),
commit_amend: GituiKeyEvent::new(KeyCode::Char('a'), KeyModifiers::CONTROL),
toggle_signoff: GituiKeyEvent::new(
|