From 1ceb264ee9393b6adec68781100ee962ae8e3656 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 29 Mar 2020 16:29:25 +0800 Subject: [PATCH] remove now unused method --- src/interactive/app/eventloop.rs | 75 +++--------------------- src/interactive/app/handlers.rs | 98 +------------------------------- 2 files changed, 9 insertions(+), 164 deletions(-) diff --git a/src/interactive/app/eventloop.rs b/src/interactive/app/eventloop.rs index 7dbe9f3a..d69e9434 100644 --- a/src/interactive/app/eventloop.rs +++ b/src/interactive/app/eventloop.rs @@ -154,80 +154,21 @@ pub struct TerminalApp { } impl TerminalApp { - pub fn draw(&mut self, terminal: &mut Terminal) -> Result<(), Error> - where - B: Backend, - { - let props = MainWindowProps { - traversal: &self.traversal, - display: self.display, - state: &self.state, - }; - draw_window(&mut self.window, props, terminal) - } pub fn process_events( &mut self, - mut terminal: Terminal, + terminal: Terminal, keys: impl Iterator>, ) -> Result where B: Backend, { - use termion::event::Key::*; - use FocussedPane::*; - fn exit_now(terminal: Terminal) -> ! { - drop(terminal); - io::stdout().flush().ok(); - // Exit 'quickly' to avoid having to wait for all memory to be freed by us. - // Let the OS do it - we have nothing to lose, literally. - std::process::exit(0); - } - - self.draw(&mut terminal)?; - for key in keys.filter_map(Result::ok) { - self.reset_message(); - match key { - Char('?') => self.toggle_help_pane(), - Char('\t') => { - self.cycle_focus(); - } - Ctrl('c') => exit_now(terminal), - Char('q') | Esc => match self.state.focussed { - Main => exit_now(terminal), - Mark => self.state.focussed = Main, - Help => { - self.state.focussed = Main; - self.window.help_pane = None - } - }, - _ => {} - } - - match self.state.focussed { - FocussedPane::Mark => self.dispatch_to_mark_pane(key, &mut terminal), - FocussedPane::Help => { - self.window.help_pane.as_mut().expect("help pane").key(key); - } - FocussedPane::Main => match key { - Char('O') => self.open_that(), - Char(' ') => self.mark_entry(false), - Char('d') => self.mark_entry(true), - Char('u') | Char('h') | Backspace | Left => self.exit_node(), - Char('o') | Char('l') | Char('\n') | Right => self.enter_node(), - Ctrl('u') | PageUp => self.change_entry_selection(CursorDirection::PageUp), - Char('k') | Up => self.change_entry_selection(CursorDirection::Up), - Char('j') | Down => self.change_entry_selection(CursorDirection::Down), - Ctrl('d') | PageDown => self.change_entry_selection(CursorDirection::PageDown), - Char('s') => self.cycle_sorting(), - Char('g') => self.display.byte_vis.cycle(), - _ => {} - }, - }; - self.draw(&mut terminal)?; - } - Ok(WalkResult { - num_errors: self.traversal.io_errors, - }) + self.state.process_events( + &mut self.window, + &mut self.traversal, + self.display, + terminal, + keys, + ) } pub fn initialize( diff --git a/src/interactive/app/handlers.rs b/src/interactive/app/handlers.rs index 8c0df23c..e01b7107 100644 --- a/src/interactive/app/handlers.rs +++ b/src/interactive/app/handlers.rs @@ -1,6 +1,6 @@ use crate::interactive::widgets::MainWindow; use crate::interactive::{ - app::{FocussedPane::*, TerminalApp}, + app::FocussedPane::*, path_of, sorted_entries, widgets::MarkMode, widgets::{HelpPane, MarkPane}, @@ -312,102 +312,6 @@ impl AppState { } } -impl TerminalApp { - pub fn cycle_focus(&mut self) { - if let Some(p) = self.window.mark_pane.as_mut() { - p.set_focus(false) - }; - self.state.focussed = match ( - self.state.focussed, - &self.window.help_pane, - &mut self.window.mark_pane, - ) { - (Main, Some(_), _) => Help, - (Help, _, Some(ref mut pane)) => { - pane.set_focus(true); - Mark - } - (Help, _, None) => Main, - (Mark, _, _) => Main, - (Main, None, None) => Main, - (Main, None, Some(ref mut pane)) => { - pane.set_focus(true); - Mark - } - }; - } - - pub fn toggle_help_pane(&mut self) { - self.state.focussed = match self.state.focussed { - Main | Mark => { - self.window.help_pane = Some(HelpPane::default()); - Help - } - Help => { - self.window.help_pane = None; - Main - } - } - } - - pub fn reset_message(&mut self) { - self.state.reset_message() - } - - pub fn open_that(&self) { - self.state.open_that(&self.traversal) - } - - pub fn exit_node(&mut self) { - let entries = self.state.entries_for_exit_node(&self.traversal); - self.state.exit_node(entries); - } - - pub fn enter_node(&mut self) { - let new_entries = self.state.entries_for_enter_node(&self.traversal); - self.state.enter_node(new_entries) - } - - pub fn change_entry_selection(&mut self, direction: CursorDirection) { - self.state.change_entry_selection(direction) - } - - pub fn cycle_sorting(&mut self) { - self.state.cycle_sorting(&self.traversal) - } - - pub fn mark_entry(&mut self, advance_cursor: bool) { - self.state - .mark_entry(advance_cursor, &mut self.window, &self.traversal) - } - - fn set_root(&mut self, root: TreeIndex) { - self.state.set_root(root, &self.traversal); - } - - pub fn delete_entry(&mut self, index: TreeIndex) -> Result { - self.state.delete_entry(index, &mut self.traversal) - } - - fn recompute_sizes_recursively(&mut self, mut index: TreeIndex) { - self.state - .recompute_sizes_recursively(index, &mut self.traversal) - } - - pub fn dispatch_to_mark_pane(&mut self, key: Key, terminal: &mut Terminal) - where - B: Backend, - { - self.state.dispatch_to_mark_pane( - key, - &mut self.window, - &mut self.traversal, - self.display, - terminal, - ); - } -} - fn into_error_count(res: Result<(), io::Error>) -> usize { match res.map_err(io_err_to_usize) { Ok(_) => 0,