Skip to content

Commit

Permalink
remove now unused method
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Mar 29, 2020
1 parent 758ea32 commit 1ceb264
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 164 deletions.
75 changes: 8 additions & 67 deletions src/interactive/app/eventloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,80 +154,21 @@ pub struct TerminalApp {
}

impl TerminalApp {
pub fn draw<B>(&mut self, terminal: &mut Terminal<B>) -> 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<B>(
&mut self,
mut terminal: Terminal<B>,
terminal: Terminal<B>,
keys: impl Iterator<Item = Result<Key, io::Error>>,
) -> Result<WalkResult, Error>
where
B: Backend,
{
use termion::event::Key::*;
use FocussedPane::*;
fn exit_now<B: Backend>(terminal: Terminal<B>) -> ! {
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<B>(
Expand Down
98 changes: 1 addition & 97 deletions src/interactive/app/handlers.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -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<usize, usize> {
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<B>(&mut self, key: Key, terminal: &mut Terminal<B>)
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,
Expand Down

0 comments on commit 1ceb264

Please sign in to comment.