Skip to content

Commit

Permalink
mild refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thiel committed May 4, 2020
1 parent 83804ad commit 5c1a04b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
8 changes: 5 additions & 3 deletions src/interactive/app/eventloop.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -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)
}
Expand Down
15 changes: 8 additions & 7 deletions src/interactive/app/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
}
Expand Down

0 comments on commit 5c1a04b

Please sign in to comment.