Skip to content

Commit

Permalink
Pull out draw code into closure
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thiel committed Jun 3, 2019
1 parent 598a6b0 commit 4ec1d37
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/interactive/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,11 @@ pub struct Traversal {
}

impl Traversal {
pub fn from_walk<B>(
terminal: &mut Terminal<B>,
pub fn from_walk(
options: WalkOptions,
input: Vec<PathBuf>,
) -> Result<Traversal, Error>
where
B: Backend,
{
mut update: impl FnMut(&Traversal) -> Result<(), Error>,
) -> Result<Traversal, Error> {
fn set_size_or_panic(
tree: &mut Tree,
parent_node_idx: TreeIndex,
Expand Down Expand Up @@ -158,14 +155,7 @@ impl Traversal {
last_seen_eid = eid;
last_checked = now;

terminal.draw(|mut f| {
let full_screen = f.size();
super::widgets::Entries {
tree: &t.tree,
root: t.root_index,
}
.render(&mut f, full_screen)
})?;
update(&t)?;
}
}
}
Expand Down Expand Up @@ -213,7 +203,17 @@ impl TerminalApp {
B: Backend,
{
Ok(TerminalApp {
traversal: Traversal::from_walk(terminal, options, input)?,
traversal: Traversal::from_walk(options, input, |t| {
terminal.draw(|mut f| {
let full_screen = f.size();
super::widgets::Entries {
tree: &t.tree,
root: t.root_index,
}
.render(&mut f, full_screen)
})?;
Ok(())
})?,
})
}
}

0 comments on commit 4ec1d37

Please sign in to comment.