summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorextrawurst <mail@rusticorn.com>2022-08-17 21:46:55 +0200
committerextrawurst <776816+extrawurst@users.noreply.github.com>2022-08-17 22:12:39 +0200
commit8e54bfd3645a43dc2de4eccfb92e94b36d06f273 (patch)
treee6533699f303d7b0d480717247fd6f1dd3e79ad8 /src
parent2eee7e9b0e16e88b46f74c598cc20693600a7c1b (diff)
upgrade crossterm/tui
Diffstat (limited to 'src')
-rw-r--r--src/app.rs73
-rw-r--r--src/components/blame_file.rs52
-rw-r--r--src/components/branchlist.rs47
-rw-r--r--src/components/changes.rs28
-rw-r--r--src/components/commit.rs18
-rw-r--r--src/components/commit_details/compare_details.rs2
-rw-r--r--src/components/commit_details/details.rs41
-rw-r--r--src/components/commit_details/mod.rs19
-rw-r--r--src/components/commitlist.rs29
-rw-r--r--src/components/compare_commits.rs23
-rw-r--r--src/components/create_branch.rs6
-rw-r--r--src/components/cred.rs7
-rw-r--r--src/components/diff.rs52
-rw-r--r--src/components/externaleditor.rs2
-rw-r--r--src/components/fetch.rs2
-rw-r--r--src/components/file_find_popup.rs20
-rw-r--r--src/components/file_revlog.rs56
-rw-r--r--src/components/help.rs17
-rw-r--r--src/components/inspect_commit.rs28
-rw-r--r--src/components/mod.rs4
-rw-r--r--src/components/msg.rs9
-rw-r--r--src/components/options_popup.rs24
-rw-r--r--src/components/pull.rs2
-rw-r--r--src/components/push.rs10
-rw-r--r--src/components/push_tags.rs10
-rw-r--r--src/components/rename_branch.rs6
-rw-r--r--src/components/reset.rs8
-rw-r--r--src/components/revision_files.rs27
-rw-r--r--src/components/revision_files_popup.rs8
-rw-r--r--src/components/stashmsg.rs6
-rw-r--r--src/components/status_tree.rs32
-rw-r--r--src/components/syntax_text.rs2
-rw-r--r--src/components/tag_commit.rs12
-rw-r--r--src/components/taglist.rs60
-rw-r--r--src/components/textinput.rs5
-rw-r--r--src/input.rs2
-rw-r--r--src/keys/key_config.rs20
-rw-r--r--src/keys/key_list.rs319
-rw-r--r--src/keys/key_list_file.rs147
-rw-r--r--src/keys/mod.rs1
-rw-r--r--src/main.rs2
-rw-r--r--src/tabs/files.rs2
-rw-r--r--src/tabs/revlog.rs47
-rw-r--r--src/tabs/stashing.rs24
-rw-r--r--src/tabs/stashlist.rs21
-rw-r--r--src/tabs/status.rs66
-rw-r--r--src/ui/mod.rs24
47 files changed, 854 insertions, 568 deletions
diff --git a/src/app.rs b/src/app.rs
index 2425dd75..c00c8351 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -14,7 +14,7 @@ use crate::{
TagCommitComponent, TagListComponent,
},
input::{Input, InputEvent, InputState},
- keys::{KeyConfig, SharedKeyConfig},
+ keys::{key_match, KeyConfig, SharedKeyConfig},
popup_stack::PopupStack,
queue::{
Action, InternalEvent, NeedsUpdate, Queue, StackablePopupOpen,
@@ -345,38 +345,57 @@ impl App {
log::trace!("event: {:?}", ev);
if let InputEvent::Input(ev) = ev {
- if self.check_hard_exit(ev) || self.check_quit(ev) {
+ if self.check_hard_exit(&ev) || self.check_quit(&ev) {
return Ok(());
}
let mut flags = NeedsUpdate::empty();
- if event_pump(ev, self.components_mut().as_mut_slice())?
+ if event_pump(&ev, self.components_mut().as_mut_slice())?
.is_consumed()
{
flags.insert(NeedsUpdate::COMMANDS);
- } else if let Event::Key(k) = ev {
- let new_flags = if k
- == self.key_config.keys.tab_toggle
- {
+ } else if let Event::Key(k) = &ev {
+ let new_flags = if key_match(
+ k,
+ self.key_config.keys.tab_toggle,
+ ) {
self.toggle_tabs(false)?;
NeedsUpdate::COMMANDS
- } else if k == self.key_config.keys.tab_toggle_reverse
- {
+ } else if key_match(
+ k,
+ self.key_config.keys.tab_toggle_reverse,
+ ) {
self.toggle_tabs(true)?;
NeedsUpdate::COMMANDS
- } else if k == self.key_config.keys.tab_status
- || k == self.key_config.keys.tab_log
- || k == self.key_config.keys.tab_files
- || k == self.key_config.keys.tab_stashing
- || k == self.key_config.keys.tab_stashes
- {
+ } else if key_match(
+ k,
+ self.key_config.keys.tab_status,
+ ) || key_match(
+ k,
+ self.key_config.keys.tab_log,
+ ) || key_match(
+ k,
+ self.key_config.keys.tab_files,
+ ) || key_match(
+ k,
+ self.key_config.keys.tab_stashing,
+ ) || key_match(
+ k,
+ self.key_config.keys.tab_stashes,
+ ) {
self.switch_tab(k)?;
NeedsUpdate::COMMANDS
- } else if k == self.key_config.keys.cmd_bar_toggle {
+ } else if key_match(
+ k,
+ self.key_config.keys.cmd_bar_toggle,
+ ) {
self.cmdbar.borrow_mut().toggle_more();
NeedsUpdate::empty()
- } else if k == self.key_config.keys.open_options {
+ } else if key_match(
+ k,
+ self.key_config.keys.open_options,
+ ) {
self.options_popup.show()?;
NeedsUpdate::ALL
} else {
@@ -563,12 +582,12 @@ impl App {
]
);
- fn check_quit(&mut self, ev: Event) -> bool {
+ fn check_quit(&mut self, ev: &Event) -> bool {
if self.any_popup_visible() {
return false;
}
if let Event::Key(e) = ev {
- if e == self.key_config.keys.quit {
+ if key_match(e, self.key_config.keys.quit) {
self.do_quit = true;
return true;
}
@@ -576,9 +595,9 @@ impl App {
false
}
- fn check_hard_exit(&mut self, ev: Event) -> bool {
+ fn check_hard_exit(&mut self, ev: &Event) -> bool {
if let Event::Key(e) = ev {
- if e == self.key_config.keys.exit {
+ if key_match(e, self.key_config.keys.exit) {
self.do_quit = true;
return true;
}
@@ -607,16 +626,16 @@ impl App {
self.set_tab(new_tab)
}
- fn switch_tab(&mut self, k: KeyEvent) -> Result<()> {
- if k == self.key_config.keys.tab_status {
+ fn switch_tab(&mut self, k: &KeyEvent) -> Result<()> {
+ if key_match(k, self.key_config.keys.tab_status) {
self.set_tab(0)?;
- } else if k == self.key_config.keys.tab_log {
+ } else if key_match(k, self.key_config.keys.tab_log) {
self.set_tab(1)?;
- } else if k == self.key_config.keys.tab_files {
+ } else if key_match(k, self.key_config.keys.tab_files) {
self.set_tab(2)?;
- } else if k == self.key_config.keys.tab_stashing {
+ } else if key_match(k, self.key_config.keys.tab_stashing) {
self.set_tab(3)?;
- } else if k == self.key_config.keys.tab_stashes {
+ } else if key_match(k, self.key_config.keys.tab_stashes) {
self.set_tab(4)?;
}
diff --git a/src/components/blame_file.rs b/src/components/blame_file.rs
index 7411c297..6d7fcc74 100644
--- a/src/components/blame_file.rs
+++ b/src/components/blame_file.rs
@@ -5,7 +5,7 @@ use super::{
};
use crate::{
components::{utils::string_width_align, ScrollType},
- keys::SharedKeyConfig,
+ keys::{key_match, SharedKeyConfig},
queue::{InternalEvent, Queue, StackablePopupOpen},
string_utils::tabs_to_spaces,
strings,
@@ -183,29 +183,48 @@ impl Component for BlameFileComponent {
fn event(
&mut self,
- event: crossterm::event::Event,
+ event: &crossterm::event::Event,
) -> Result<EventState> {
if self.is_visible() {
if let Event::Key(key) = event {
- if key == self.key_config.keys.exit_popup {
+ if key_match(key, self.key_config.keys.exit_popup) {
self.hide_stacked(false);
- } else if key == self.key_config.keys.move_up {
+ } else if key_match(key, self.key_config.keys.move_up)
+ {
self.move_selection(ScrollType::Up);
- } else if key == self.key_config.keys.move_down {
+ } else if key_match(
+ key,
+ self.key_config.keys.move_down,
+ ) {
self.move_selection(ScrollType::Down);
- } else if key == self.key_config.keys.shift_up
- || key == self.key_config.keys.home
- {
+ } else if key_match(
+ key,
+ self.key_config.keys.shift_up,
+ ) || key_match(
+ key,
+ self.key_config.keys.home,
+ ) {
self.move_selection(ScrollType::Home);
- } else if key == self.key_config.keys.shift_down
- || key == self.key_config.keys.end
- {
+ } else if key_match(
+ key,
+ self.key_config.keys.shift_down,
+ ) || key_match(
+ key,
+ self.key_config.keys.end,
+ ) {
self.move_selection(ScrollType::End);
- } else if key == self.key_config.keys.page_down {
+ } else if key_match(
+ key,
+ self.key_config.keys.page_down,
+ ) {
self.move_selection(ScrollType::PageDown);
- } else if key == self.key_config.keys.page_up {
+ } else if key_match(key, self.key_config.keys.page_up)
+ {
self.move_selection(ScrollType::PageUp);
- } else if key == self.key_config.keys.focus_right {
+ } else if key_match(
+ key,
+ self.key_config.keys.focus_right,
+ ) {
if let Some(commit_id) = self.selected_commit() {
self.hide_stacked(true);
self.queue.push(InternalEvent::OpenPopup(
@@ -214,7 +233,10 @@ impl Component for BlameFileComponent {
),
));
}
- } else if key == self.key_config.keys.file_history {
+ } else if key_match(
+ key,
+ self.key_config.keys.file_history,
+ ) {
if let Some(filepath) = self
.params
.as_ref()
diff --git a/src/components/branchlist.rs b/src/components/branchlist.rs
index 52b819c9..b5336ebf 100644
--- a/src/components/branchlist.rs
+++ b/src/components/branchlist.rs
@@ -5,7 +5,7 @@ use super::{
};
use crate::{
components::ScrollType,
- keys::SharedKeyConfig,
+ keys::{key_match, SharedKeyConfig},
queue::{
Action, InternalEvent, NeedsUpdate, Queue, StackablePopupOpen,
},
@@ -212,62 +212,62 @@ impl Component for BranchListComponent {
//TODO: cleanup
#[allow(clippy::cognitive_complexity)]
- fn event(&mut self, ev: Event) -> Result<EventState> {
+ fn event(&mut self, ev: &Event) -> Result<EventState> {
if !self.visible {
return Ok(EventState::NotConsumed);
}
if let Event::Key(e) = ev {
- if e == self.key_config.keys.exit_popup {
+ if key_match(e, self.key_config.keys.exit_popup) {
self.hide();
- } else if e == self.key_config.keys.move_down {
+ } else if key_match(e, self.key_config.keys.move_down) {
return self
.move_selection(ScrollType::Up)
.map(Into::into);
- } else if e == self.key_config.keys.move_up {
+ } else if key_match(e, self.key_config.keys.move_up) {
return self
.move_selection(ScrollType::Down)
.map(Into::into);
- } else if e == self.key_config.keys.page_down {
+ } else if key_match(e, self.key_config.keys.page_down) {
return self
.move_selection(ScrollType::PageDown)
.map(Into::into);
- } else if e == self.key_config.keys.page_up {
+ } else if key_match(e, self.key_config.keys.page_up) {
return self
.move_selection(ScrollType::PageUp)
.map(Into::into);
- } else if e == self.key_config.keys.home {
+ } else if key_match(e, self.key_config.keys.home) {
return self
.move_selection(ScrollType::Home)
.map(Into::into);
- } else if e == self.key_config.keys.end {
+ } else if key_match(e, self.key_config.keys.end) {
return self
.move_selection(ScrollType::End)
.map(Into::into);
- } else if e == self.key_config.keys.tab_toggle {
+ } else if key_match(e, self.key_config.keys.tab_toggle) {
self.local = !self.local;
self.check_remotes();
self.update_branches()?;
- } else if e == self.key_config.keys.enter {
+ } else if key_match(e, self.key_config.keys.enter) {
try_or_popup!(
self,
"switch branch error:",
self.switch_to_selected_branch()
);
- } else if e == self.key_config.keys.create_branch
+ } else if key_match(e, self.key_config.keys.create_branch)
&& self.local
{
self.queue.push(InternalEvent::CreateBranch);
- } else if e == self.key_config.keys.rename_branch
+ } else if key_match(e, self.key_config.keys.rename_branch)
&& self.valid_selection()
{
self.rename_branch();
- } else if e == self.key_config.keys.delete_branch
+ } else if key_match(e, self.key_config.keys.delete_branch)
&& !self.selection_is_cur_branch()
&& self.valid_selection()
{
self.delete_branch();
- } else if e == self.key_config.keys.merge_branch
+ } else if key_match(e, self.key_config.keys.merge_branch)
&& !self.selection_is_cur_branch()
&& self.valid_selection()
{
@@ -276,7 +276,7 @@ impl Component for BranchListComponent {
"merge branch error:",
self.merge_branch()
);
- } else if e == self.key_config.keys.rebase_branch
+ } else if key_match(e, self.key_config.keys.rebase_branch)
&& !self.selection_is_cur_branch()
&& self.valid_selection()
{
@@ -285,12 +285,14 @@ impl Component for BranchListComponent {
"rebase error:",
self.rebase_branch()
);
- } else if e == self.key_config.keys.move_right
+ } else if key_match(e, self.key_config.keys.move_right)
&& self.valid_selection()
{
self.inspect_head_of_branch();
- } else if e == self.key_config.keys.compare_commits
- && self.valid_selection()
+ } else if key_match(
+ e,
+ self.key_config.keys.compare_commits,
+ ) && self.valid_selection()
{
self.hide();
if let Some(commit_id) = self.get_selected() {
@@ -300,11 +302,14 @@ impl Component for BranchListComponent {
),
));
}
- } else if e == self.key_config.keys.pull
+ } else if key_match(e, self.key_config.keys.pull)
&& !self.local && self.has_remotes
{
self.queue.push(InternalEvent::FetchRemotes);
- } else if e == self.key_config.keys.cmd_bar_toggle {
+ } else if key_match(
+ e,
+ self.key_config.keys.cmd_bar_toggle,
+ ) {
//do not consume if its the more key
return Ok(EventState::NotConsumed);
}
diff --git a/src/components/changes.rs b/src/components/changes.rs
index 35996392..ca3df299 100644
--- a/src/components/changes.rs
+++ b/src/components/changes.rs
@@ -5,7 +5,7 @@ use super::{
};
use crate::{
components::{CommandInfo, Component, EventState},
- keys::SharedKeyConfig,
+ keys::{key_match, SharedKeyConfig},
queue::{Action, InternalEvent, NeedsUpdate, Queue, ResetItem},
strings, try_or_popup,
ui::style::SharedTheme,
@@ -256,15 +256,17 @@ impl Component for ChangesComponent {
CommandBlocking::PassingOn
}
- fn event(&mut self, ev: Event) -> Result<EventState> {
+ fn event(&mut self, ev: &Event) -> Result<EventState> {
if self.files.event(ev)?.is_consumed() {
return Ok(EventState::Consumed);
}
if self.focused() {
if let Event::Key(e) = ev {
- return if e == self.key_config.keys.stage_unstage_item
- {
+ return if key_match(
+ e,
+ self.key_config.keys.stage_unstage_item,
+ ) {
try_or_popup!(
self,
"staging error:",
@@ -275,8 +277,10 @@ impl Component for ChangesComponent {
NeedsUpdate::ALL,
));
Ok(EventState::Consumed)
- } else if e == self.key_config.keys.status_stage_all
- && !self.is_empty()
+ } else if key_match(
+ e,
+ self.key_config.keys.status_stage_all,
+ ) && !self.is_empty()
{
if self.is_working_dir {
try_or_popup!(
@@ -290,12 +294,16 @@ impl Component for ChangesComponent {
self.queue
.push(InternalEvent::StatusLastFileMoved);
Ok(EventState::Consumed)
- } else if e == self.key_config.keys.status_reset_item
- && self.is_working_dir
+ } else if key_match(
+ e,
+ self.key_config.keys.status_reset_item,
+ ) && self.is_working_dir
{
Ok(self.dispatch_reset_workdir().into())
- } else if e == self.key_config.keys.status_ignore_file
- && self.is_working_dir
+ } else if key_match(
+ e,
+ self.key_config.keys.status_ignore_file,
+ ) && self.is_working_dir
&& !self.is_empty()
{
Ok(self.add_to_ignore().into())
diff --git a/src/components/commit.rs b/src/components/commit.rs
index e783e794..5128d99c 100644
--- a/src/components/commit.rs
+++ b/src/components/commit.rs
@@ -4,7 +4,7 @@ use super::{
EventState, ExternalEditorComponent,
};
use crate::{
- keys::SharedKeyConfig,
+ keys::{key_match, SharedKeyConfig},
queue::{InternalEvent, NeedsUpdate, Queue},
strings, try_or_popup,
ui::style::SharedTheme,
@@ -333,14 +333,14 @@ impl Component for CommitComponent {
visibility_blocking(self)
}
- fn event(&mut self, ev: Event) -> Result<EventState> {
+ fn event(&mut self, ev: &Event) -> Result<EventState> {
if self.is_visible() {
if self.input.event(ev)?.is_consumed() {
return Ok(EventState::Consumed);
}
if let Event::Key(e) = ev {
- if e == self.key_config.keys.enter
+ if key_match(e, self.key_config.keys.enter)
&& self.can_commit()
{
try_or_popup!(
@@ -348,12 +348,16 @@ impl Component for CommitComponent {
"commit error:",
self.commit()
);
- } else if e == self.key_config.keys.commit_amend
- && self.can_amend()
+ } else if key_match(
+ e,
+ self.key_config.keys.commit_amend,
+ ) && self.can_amend()
{
self.amend()?;
- } else if e == self.key_config.keys.open_commit_editor
- {
+ } else if key_match(
+ e,
+ self.key_config.keys.open_commit_editor,
+ ) {
self.queue.push(
InternalEvent::OpenExternalEditor(None),
);
diff --git a/src/components/commit_details/compare_details.rs b/src/components/commit_details/compare_details.rs
index 1e045e9b..c993b8d1 100644
--- a/src/components/commit_details/compare_details.rs
+++ b/src/components/commit_details/compare_details.rs
@@ -161,7 +161,7 @@ impl Component for CompareDetailsComponent {
CommandBlocking::PassingOn
}
- fn event(&mut self, _event: Event) -> Result<EventState> {
+ fn event(&mut self, _event: &Event) -> Result<EventState> {
Ok(EventState::NotConsumed)
}
diff --git a/src/components/commit_details/details.rs b/src/components/commit_details/details.rs
index 0b0e99c3..83430a28 100644
--- a/src/components/commit_details/details.rs
+++ b/src/components/commit_details/details.rs
@@ -6,7 +6,7 @@ use crate::{
CommandBlocking, CommandInfo, Component, DrawableComponent,
EventState, ScrollType,
},
- keys::SharedKeyConfig,
+ keys::{key_match, SharedKeyConfig},
strings::{self, order},
ui::style::SharedTheme,
};
@@ -357,24 +357,31 @@ impl Component for DetailsComponent {
CommandBlocking::PassingOn
}
- fn event(&mut self, event: Event) -> Result<EventState> {
+ fn event(&mut self, event: &Event) -> Result<EventState> {
if self.focused {
if let Event::Key(e) = event {
- return Ok(if e == self.key_config.keys.move_up {
- self.move_scroll_top(ScrollType::Up).into()
- } else if e == self.key_config.keys.move_down {
- self.move_scroll_top(ScrollType::Down).into()
- } else if e == self.key_config.keys.home
- || e == self.key_config.keys.shift_up
- {
- self.move_scroll_top(ScrollType::Home).into()
- } else if e == self.key_config.keys.end
- || e == self.key_config.keys.shift_down
- {
- self.move_scroll_top(ScrollType::End).into()
- } else {
- EventState::NotConsumed
- });
+ return Ok(
+ if key_match(e, self.key_config.keys.move_up) {
+ self.move_scroll_top(ScrollType::Up).into()
+ } else if key_match(
+ e,
+ self.key_config.keys.move_down,
+ ) {
+ self.move_scroll_top(ScrollType::Down).into()
+ } else if key_match(e, self.key_config.keys.home)
+ || key_match(e, self.key_config.keys.shift_up)
+ {
+ self.move_scroll_top(ScrollType::Home).into()
+ } else if key_match(e, self.key_config.keys.end)
+ || key_match(
+ e,
+ self.key_config.keys.shift_down,
+ ) {
+ self.move_scroll_top(ScrollType::End).into()
+ } else {
+ EventState::NotConsumed
+ },
+ );
}
}
diff --git a/src/components/commit_details/mod.rs b/src/components/commit_details/mod.rs
index 7cf356b2..6c57bd38 100644
--- a/src/components/commit_details/mod.rs
+++ b/src/components/commit_details/mod.rs
@@ -7,7 +7,10 @@ use super::{
Component, DrawableComponent, EventState, StatusTreeComponent,
};
use crate::{
- accessors, keys::SharedKeyConfig, queue::Queue, strings,
+ accessors,
+ keys::{key_match, SharedKeyConfig},
+ queue::Queue,
+ strings,
ui::style::SharedTheme,
};
use anyhow::Result;
@@ -215,7 +218,7 @@ impl Component for CommitDetailsComponent {
CommandBlocking::PassingOn
}
- fn event(&mut self, ev: Event) -> Result<EventState> {
+ fn event(&mut self, ev: &Event) -> Result<EventState> {
if event_pump(ev, self.components_mut().as_mut_slice())?
.is_consumed()
{
@@ -228,14 +231,18 @@ impl Component for CommitDetailsComponent {
if self.focused() {
if let Event::Key(e) = ev {
- return if e == self.key_config.keys.focus_below
- && self.details_focused()
+ return if key_match(
+ e,
+ self.key_config.keys.focus_below,
+ ) && self.details_focused()
{
self.set_details_focus(false);
self.file_tree.focus(true);
Ok(EventState::Consumed)
- } else if e == self.key_config.keys.focus_above
- && self.file_tree.focused()
+ } else if key_match(
+ e,
+ self.key_config.keys.focus_above,
+ ) && self.file_tree.focused()
&& !self.is_compare()
{
self.file_tree.focus(false);
diff --git a/src/components/commitlist.rs b/src/components/commitlist.rs
index 7ef6cc0e..ed7a6961 100644
--- a/src/components/commitlist.rs
+++ b/src/components/commitlist.rs
@@ -4,7 +4,7 @@ use crate::{
utils::string_width_align, CommandBlocking, CommandInfo,
Component, DrawableComponent, EventState, ScrollType,
},
- keys::SharedKeyConfig,
+ keys::{key_match, SharedKeyConfig},
strings::{self, symbol},
ui::style::{SharedTheme, Theme},
ui::{calc_scroll_top, draw_scrollbar},
@@ -426,26 +426,33 @@ impl DrawableComponent for CommitList {
}
impl Component for CommitList {
- fn event(&mut self, ev: Event) -> Result<EventState> {