Skip to content

Commit

Permalink
Explicitly declare an init-window
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thiel committed Jun 3, 2019
1 parent 7f4fb35 commit b919c50
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
20 changes: 10 additions & 10 deletions src/interactive/app.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use crate::{WalkOptions, WalkResult};
use failure::Error;
use petgraph::{prelude::NodeIndex, Directed, Direction, Graph};
use std::time::{Duration, Instant};
use std::{ffi::OsString, io, path::PathBuf};
use std::{
ffi::OsString,
io,
path::PathBuf,
time::{Duration, Instant},
};
use termion::input::{Keys, TermReadEventsAndRaw};
use tui::widgets::Widget;
use tui::{backend::Backend, Terminal};
Expand Down Expand Up @@ -191,11 +195,11 @@ impl TerminalApp {
B: Backend,
R: io::Read + TermReadEventsAndRaw,
{
use termion::event::Key::Ctrl;
use termion::event::Key::{Char, Ctrl};

for key in keys.filter_map(Result::ok) {
match key {
Ctrl('c') => break,
Ctrl('c') | Char('\n') => break,
_ => dbg!(&key),
};
}
Expand All @@ -213,14 +217,10 @@ impl TerminalApp {
B: Backend,
{
Ok(TerminalApp {
traversal: Traversal::from_walk(options, input, |t| {
traversal: Traversal::from_walk(options, input, |traversal| {
terminal.draw(|mut f| {
let full_screen = f.size();
super::widgets::Entries {
tree: &t.tree,
root: t.root_index,
}
.render(&mut f, full_screen)
super::widgets::InitWindow { traversal }.render(&mut f, full_screen)
})?;
Ok(())
})?,
Expand Down
29 changes: 25 additions & 4 deletions src/interactive/widgets.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
use super::{Tree, TreeIndex};
use super::{Traversal, Tree, TreeIndex};
use petgraph::Direction;
use tui::buffer::Buffer;
use tui::layout::{Corner, Rect};
use tui::widgets::{Block, Borders, List, Text, Widget};
use tui::{
buffer::Buffer,
layout::{Corner, Rect},
widgets::{Block, Borders, List, Text, Widget},
};

pub struct Entries<'a> {
pub tree: &'a Tree,
pub root: TreeIndex,
}

pub struct InitWindow<'a> {
pub traversal: &'a Traversal,
}

impl<'a> Widget for InitWindow<'a> {
fn draw(&mut self, area: Rect, buf: &mut Buffer) {
let Self {
traversal: Traversal {
tree, root_index, ..
},
} = self;
Entries {
tree: tree,
root: *root_index,
}
.draw(area, buf);
}
}

impl<'a> Widget for Entries<'a> {
fn draw(&mut self, area: Rect, buf: &mut Buffer) {
let Self { tree, root } = self;
Expand Down

0 comments on commit b919c50

Please sign in to comment.