summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Thiel <sthiel@thoughtworks.com>2020-05-04 11:21:57 +0800
committerSebastian Thiel <sthiel@thoughtworks.com>2020-05-04 11:21:57 +0800
commit5c1a04bb108eefdb6e10294fef0681cf92ecbaad (patch)
treeb1b1f6f66b57269ec5878d2234ce0d5279ee396a
parent83804adf605c2d1264b0fcafcdbf5f77023570ab (diff)
mild refactor
-rw-r--r--src/interactive/app/eventloop.rs8
-rw-r--r--src/interactive/app/handlers.rs15
2 files changed, 13 insertions, 10 deletions
diff --git a/src/interactive/app/eventloop.rs b/src/interactive/app/eventloop.rs
index c26d536..baf5c03 100644
--- a/src/interactive/app/eventloop.rs
+++ b/src/interactive/app/eventloop.rs
@@ -1,7 +1,7 @@
use crate::interactive::{
sorted_entries,
widgets::{MainWindow, MainWindowProps},
- ByteVisualization, CursorDirection, DisplayOptions, EntryDataBundle, SortMode,
+ ByteVisualization, CursorDirection, CursorMode, DisplayOptions, EntryDataBundle, SortMode,
};
use dua::{
traverse::{Traversal, TreeIndex},
@@ -113,8 +113,10 @@ impl AppState {
}
FocussedPane::Main => match key {
Char('O') => self.open_that(traversal),
- Char(' ') => self.mark_entry(false, window, traversal),
- Char('d') => self.mark_entry(true, window, traversal),
+ Char(' ') => self.mark_entry(CursorMode::Toggle, window, traversal),
+ Char('d') => {
+ self.mark_entry(CursorMode::ToggleAndAdvanceDown, window, traversal)
+ }
Char('u') | Char('h') | Backspace | Left => {
self.exit_node_with_traversal(traversal)
}
diff --git a/src/interactive/app/handlers.rs b/src/interactive/app/handlers.rs
index 89041d7..d2a5e38 100644
--- a/src/interactive/app/handlers.rs
+++ b/src/interactive/app/handlers.rs
@@ -14,6 +14,12 @@ use termion::event::Key;
use tui::backend::Backend;
use tui_react::Terminal;
+#[derive(Copy, Clone)]
+pub enum CursorMode {
+ Toggle,
+ ToggleAndAdvanceDown,
+}
+
pub enum CursorDirection {
PageDown,
Down,
@@ -291,12 +297,7 @@ impl AppState {
.map(|w| w.size);
}
- pub fn mark_entry(
- &mut self,
- advance_cursor: bool,
- window: &mut MainWindow,
- traversal: &Traversal,
- ) {
+ pub fn mark_entry(&mut self, mode: CursorMode, window: &mut MainWindow, traversal: &Traversal) {
if let Some(index) = self.selected {
let is_dir = self
.entries
@@ -310,7 +311,7 @@ impl AppState {
window.mark_pane = MarkPane::default().toggle_index(index, &traversal.tree, is_dir)
}
};
- if advance_cursor {
+ if let CursorMode::ToggleAndAdvanceDown = mode {
self.change_entry_selection(CursorDirection::Down)
}
}