Skip to content

Commit

Permalink
first step towards support aync/channel based input events
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Mar 29, 2020
1 parent 7689016 commit e811eff
Showing 1 changed file with 70 additions and 50 deletions.
120 changes: 70 additions & 50 deletions src/interactive/app/eventloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ impl AppState {
draw_window(window, props, terminal)
}

pub fn process_events<B>(
pub fn process_event<B>(
&mut self,
window: &mut MainWindow,
traversal: &mut Traversal,
display: &mut DisplayOptions,
terminal: &mut Terminal<B>,
keys: impl Iterator<Item = Result<Key, io::Error>>,
key: Key,
) -> Result<ProcessingResult, Error>
where
B: Backend,
Expand All @@ -77,61 +77,81 @@ impl AppState {
use FocussedPane::*;

self.reset_message();
self.draw(window, traversal, display.clone(), terminal)?;
for key in keys.filter_map(Result::ok) {
self.reset_message();
match key {
Char('?') => self.toggle_help_pane(window),
Char('\t') => {
self.cycle_focus(window);
}
Ctrl('c') => {
match key {
Char('?') => self.toggle_help_pane(window),
Char('\t') => {
self.cycle_focus(window);
}
Ctrl('c') => {
return Ok(ProcessingResult::ExitRequested(WalkResult {
num_errors: traversal.io_errors,
}))
}
Char('q') | Esc => match self.focussed {
Main => {
return Ok(ProcessingResult::ExitRequested(WalkResult {
num_errors: traversal.io_errors,
}))
}
Char('q') | Esc => match self.focussed {
Main => {
return Ok(ProcessingResult::ExitRequested(WalkResult {
num_errors: traversal.io_errors,
}))
}
Mark => self.focussed = Main,
Help => {
self.focussed = Main;
window.help_pane = None
}
},
_ => {}
}
Mark => self.focussed = Main,
Help => {
self.focussed = Main;
window.help_pane = None
}
},
_ => {}
}

match self.focussed {
FocussedPane::Mark => {
self.dispatch_to_mark_pane(key, window, traversal, display.clone(), terminal)
match self.focussed {
FocussedPane::Mark => {
self.dispatch_to_mark_pane(key, window, traversal, display.clone(), terminal)
}
FocussedPane::Help => {
window.help_pane.as_mut().expect("help pane").key(key);
}
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('u') | Char('h') | Backspace | Left => {
self.exit_node_with_traversal(traversal)
}
FocussedPane::Help => {
window.help_pane.as_mut().expect("help pane").key(key);
Char('o') | Char('l') | Char('\n') | Right => {
self.enter_node_with_traversal(traversal)
}
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('u') | Char('h') | Backspace | Left => {
self.exit_node_with_traversal(traversal)
}
Char('o') | Char('l') | Char('\n') | Right => {
self.enter_node_with_traversal(traversal)
}
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(traversal),
Char('g') => display.byte_vis.cycle(),
_ => {}
},
};
self.draw(window, traversal, display.clone(), terminal)?;
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(traversal),
Char('g') => display.byte_vis.cycle(),
_ => {}
},
};
self.draw(window, traversal, display.clone(), terminal)?;
Ok(ProcessingResult::Finished(WalkResult {
num_errors: traversal.io_errors,
}))
}
pub fn process_events<B>(
&mut self,
window: &mut MainWindow,
traversal: &mut Traversal,
display: &mut DisplayOptions,
terminal: &mut Terminal<B>,
keys: impl Iterator<Item = Result<Key, io::Error>>,
) -> Result<ProcessingResult, Error>
where
B: Backend,
{
self.reset_message();
self.draw(window, traversal, display.clone(), terminal)?;
for key in keys.filter_map(Result::ok) {
if let r @ ProcessingResult::ExitRequested(_) =
self.process_event(window, traversal, display, terminal, key)?
{
return Ok(r);
}
}
Ok(ProcessingResult::Finished(WalkResult {
num_errors: traversal.io_errors,
Expand Down

0 comments on commit e811eff

Please sign in to comment.