-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathmod.rs
More file actions
229 lines (211 loc) · 7.43 KB
/
mod.rs
File metadata and controls
229 lines (211 loc) · 7.43 KB
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
use serde::{Deserialize, Serialize};
use crate::{
Res,
app::{App, State},
item_data::ItemData,
menu::Menu,
term::Term,
};
use std::{fmt::Display, rc::Rc};
pub(crate) mod branch;
pub(crate) mod commit;
pub(crate) mod copy_hash;
pub(crate) mod discard;
pub(crate) mod editor;
pub(crate) mod fetch;
pub(crate) mod log;
pub(crate) mod merge;
pub(crate) mod preview;
pub(crate) mod pull;
pub(crate) mod push;
pub(crate) mod rebase;
pub(crate) mod remote;
pub(crate) mod reset;
pub(crate) mod revert;
pub(crate) mod show;
pub(crate) mod show_refs;
pub(crate) mod stage;
pub(crate) mod stash;
pub(crate) mod unstage;
pub(crate) type Action = Rc<dyn FnMut(&mut App, &mut Term) -> Res<()>>;
pub(crate) trait OpTrait {
/// Get the implementation (which may or may not exist) of the Op given some TargetData.
/// This indirection allows Gitu to show a contextual menu of applicable actions.
fn get_action(&self, target: &ItemData) -> Option<Action>;
/// This indicates whether the Op is meant to read and
/// act on TargetData. Those are listed differently in the help menu.
fn is_target_op(&self) -> bool {
false
}
fn display(&self, state: &State) -> String;
}
#[derive(Clone, PartialOrd, Ord, PartialEq, Eq, Debug, Serialize, Deserialize, strum::AsRefStr)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub(crate) enum Op {
AddRemote,
Checkout,
CheckoutNewBranch,
Spinoff,
Delete,
Commit,
CommitAmend,
CommitExtend,
FetchAll,
FetchElsewhere,
LogCurrent,
Preview,
PullFromPushRemote,
PullFromUpstream,
PullFromElsewhere,
PushToPushRemote,
PushToUpstream,
PushToElsewhere,
RebaseAbort,
RebaseContinue,
RebaseElsewhere,
RemoveRemote,
RenameRemote,
ShowRefs,
Stash,
StashApply,
StashIndex,
StashWorktree,
StashKeepIndex,
StashPop,
StashDrop,
CommitFixup,
CommitInstantFixup,
LogOther,
RebaseAutosquash,
RebaseInteractive,
ResetSoft,
ResetMixed,
ResetHard,
RevertAbort,
RevertContinue,
RevertCommit,
Merge,
MergeAbort,
MergeContinue,
Stage,
Unstage,
Show,
Discard,
CopyHash,
ToggleSection,
MoveUp,
MoveDown,
MoveUpLine,
MoveDownLine,
MovePrevSection,
MoveNextSection,
MoveParentSection,
HalfPageUp,
HalfPageDown,
Refresh,
Quit,
#[serde(untagged)]
OpenMenu(Menu),
#[serde(untagged)]
ToggleArg(String),
#[serde(untagged)]
MoveToScreenLine(usize),
}
impl Op {
pub fn implementation(self) -> Box<dyn OpTrait> {
match self {
Op::Quit => Box::new(editor::Quit),
Op::OpenMenu(menu) => Box::new(editor::OpenMenu(menu)),
Op::Refresh => Box::new(editor::Refresh),
Op::ToggleArg(name) => Box::new(editor::ToggleArg(name)),
Op::ToggleSection => Box::new(editor::ToggleSection),
Op::MoveDown => Box::new(editor::MoveDown),
Op::MoveUp => Box::new(editor::MoveUp),
Op::MoveDownLine => Box::new(editor::MoveDownLine),
Op::MoveUpLine => Box::new(editor::MoveUpLine),
Op::MoveToScreenLine(screen_line) => Box::new(editor::MoveToScreenLine(screen_line)),
Op::MoveNextSection => Box::new(editor::MoveNextSection),
Op::MovePrevSection => Box::new(editor::MovePrevSection),
Op::MoveParentSection => Box::new(editor::MoveParentSection),
Op::HalfPageUp => Box::new(editor::HalfPageUp),
Op::HalfPageDown => Box::new(editor::HalfPageDown),
Op::Checkout => Box::new(branch::Checkout),
Op::CheckoutNewBranch => Box::new(branch::CheckoutNewBranch),
Op::Spinoff => Box::new(branch::Spinoff),
Op::Delete => Box::new(branch::Delete),
Op::Commit => Box::new(commit::Commit),
Op::CommitAmend => Box::new(commit::CommitAmend),
Op::CommitExtend => Box::new(commit::CommitExtend),
Op::FetchAll => Box::new(fetch::FetchAll),
Op::FetchElsewhere => Box::new(fetch::FetchElsewhere),
Op::LogCurrent => Box::new(log::LogCurrent),
Op::Preview => Box::new(preview::Preview),
Op::PullFromPushRemote => Box::new(pull::PullFromPushRemote),
Op::PullFromUpstream => Box::new(pull::PullFromUpstream),
Op::PullFromElsewhere => Box::new(pull::PullFromElsewhere),
Op::PushToPushRemote => Box::new(push::PushToPushRemote),
Op::PushToUpstream => Box::new(push::PushToUpstream),
Op::PushToElsewhere => Box::new(push::PushToElsewhere),
Op::RebaseAbort => Box::new(rebase::RebaseAbort),
Op::RebaseContinue => Box::new(rebase::RebaseContinue),
Op::RebaseElsewhere => Box::new(rebase::RebaseElsewhere),
Op::ShowRefs => Box::new(show_refs::ShowRefs),
Op::Stash => Box::new(stash::Stash),
Op::StashApply => Box::new(stash::StashApply),
Op::StashIndex => Box::new(stash::StashIndex),
Op::StashWorktree => Box::new(stash::StashWorktree),
Op::StashKeepIndex => Box::new(stash::StashKeepIndex),
Op::StashPop => Box::new(stash::StashPop),
Op::StashDrop => Box::new(stash::StashDrop),
Op::CommitFixup => Box::new(commit::CommitFixup),
Op::CommitInstantFixup => Box::new(commit::CommitInstantFixup),
Op::Discard => Box::new(discard::Discard),
Op::LogOther => Box::new(log::LogOther),
Op::RebaseAutosquash => Box::new(rebase::RebaseAutosquash),
Op::RebaseInteractive => Box::new(rebase::RebaseInteractive),
Op::ResetSoft => Box::new(reset::ResetSoft),
Op::ResetMixed => Box::new(reset::ResetMixed),
Op::ResetHard => Box::new(reset::ResetHard),
Op::RevertAbort => Box::new(revert::RevertAbort),
Op::RevertContinue => Box::new(revert::RevertContinue),
Op::RevertCommit => Box::new(revert::RevertCommit),
Op::Show => Box::new(show::Show),
Op::Stage => Box::new(stage::Stage),
Op::Unstage => Box::new(unstage::Unstage),
Op::CopyHash => Box::new(copy_hash::CopyHash),
Op::AddRemote => Box::new(remote::AddRemote),
Op::RemoveRemote => Box::new(remote::RemoveRemote),
Op::RenameRemote => Box::new(remote::RenameRemote),
Op::Merge => Box::new(merge::Merge),
Op::MergeAbort => Box::new(merge::MergeAbort),
Op::MergeContinue => Box::new(merge::MergeContinue),
}
}
}
impl Display for Menu {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
Menu::Root => "Root",
Menu::Branch => "Branch",
Menu::Commit => "Commit",
Menu::Fetch => "Fetch",
Menu::Help => "Help",
Menu::Log => "Log",
Menu::Merge => "Merge",
Menu::Remote => "Remote",
Menu::Pull => "Pull",
Menu::Push => "Push",
Menu::Rebase => "Rebase",
Menu::Reset => "Reset",
Menu::Revert => "Revert",
Menu::Stash => "Stash",
})
}
}
pub(crate) fn confirm(app: &mut App, term: &mut Term, prompt: &'static str) -> Res<()> {
app.confirm(term, prompt)
}
pub(crate) fn selected_rev(state: &App) -> Option<String> {
state.selected_rev()
}