Skip to content

Commit

Permalink
Prepare for handling mutable application state
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thiel committed Jun 3, 2019
1 parent e8cb9dc commit e48898b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
14 changes: 12 additions & 2 deletions src/interactive/app.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::widgets::{DisplayState, MainWindow};
use crate::{interactive::Traversal, ByteFormat, WalkOptions, WalkResult};
use failure::Error;
use std::{io, path::PathBuf};
Expand Down Expand Up @@ -31,9 +32,14 @@ impl TerminalApp {
let Self { traversal, display } = self;
terminal.draw(|mut f| {
let full_screen = f.size();
super::widgets::MainWindow {
let root = traversal.root_index;
MainWindow {
traversal,
display: *display,
state: DisplayState {
root,
selected: None,
},
}
.render(&mut f, full_screen)
})?;
Expand Down Expand Up @@ -77,9 +83,13 @@ impl TerminalApp {
traversal: Traversal::from_walk(options, input, move |traversal| {
terminal.draw(|mut f| {
let full_screen = f.size();
super::widgets::MainWindow {
MainWindow {
traversal,
display: display_options,
state: DisplayState {
root: traversal.root_index,
selected: None,
},
}
.render(&mut f, full_screen)
})?;
Expand Down
14 changes: 10 additions & 4 deletions src/interactive/widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ pub struct Entries<'a> {
pub display: DisplayOptions,
}

pub struct DisplayState {
pub root: TreeIndex,
pub selected: Option<TreeIndex>,
}

pub struct MainWindow<'a> {
pub traversal: &'a Traversal,
pub display: DisplayOptions,
pub state: DisplayState,
}

pub struct Footer {
Expand Down Expand Up @@ -59,22 +65,22 @@ impl<'a> Widget for MainWindow<'a> {
traversal:
Traversal {
tree,
root_index,
entries_traversed,
total_bytes,
..
},
display,
} = *self;
state,
} = self;
let regions = Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Max(256), Constraint::Length(1)].as_ref())
.split(area);
let (entries, footer) = (regions[0], regions[1]);
Entries {
tree: &tree,
root: *root_index,
display: display,
root: state.root,
display: *display,
}
.draw(entries, buf);

Expand Down

0 comments on commit e48898b

Please sign in to comment.