diff --git a/examples/block.rs b/examples/block.rs index 22d4e50..15150e5 100644 --- a/examples/block.rs +++ b/examples/block.rs @@ -30,14 +30,14 @@ fn draw(t: &mut Terminal) { .direction(Direction::Vertical) .alignment(Alignment::Left) .chunks(&[Size::Fixed(7), Size::Min(5), Size::Fixed(3)]) - .render(&Terminal::size().unwrap(), |chunks| { - t.render(chunks[0], Block::default().title("Block")); + .render(t, &Terminal::size().unwrap(), |t, chunks| { + Block::default().title("Block").render(&chunks[0], t); Group::default() .direction(Direction::Vertical) .alignment(Alignment::Left) .chunks(&[Size::Fixed(7), Size::Min(5), Size::Fixed(3)]) - .render(&chunks[1], |chunks| { - t.render(chunks[0], Block::default().title("Block")); + .render(t, &chunks[1], |t, chunks| { + Block::default().title("Block").render(&chunks[0], t); }); }); } diff --git a/examples/prototype.rs b/examples/prototype.rs index 36b0b0d..b775be7 100644 --- a/examples/prototype.rs +++ b/examples/prototype.rs @@ -9,7 +9,6 @@ use std::thread; use std::time; use std::sync::mpsc; use std::io::stdin; -use std::cmp::min; use rand::distributions::{IndependentSample, Range}; @@ -19,7 +18,7 @@ use termion::input::TermRead; use log::LogLevelFilter; use log4rs::append::file::FileAppender; use log4rs::encode::pattern::PatternEncoder; -use log4rs::config::{Appender, Config, Logger, Root}; +use log4rs::config::{Appender, Config, Root}; use tui::Terminal; use tui::widgets::{Widget, Block, List, Gauge, Sparkline, Text, border, Chart, Axis, Dataset}; @@ -75,7 +74,6 @@ impl Iterator for SinSignal { struct App { name: String, - fetching: bool, items: Vec, selected: usize, show_chart: bool, @@ -104,7 +102,7 @@ fn main() { .build(Root::builder().appender("log").build(LogLevelFilter::Debug)) .unwrap(); - let handle = log4rs::init_config(config).unwrap(); + log4rs::init_config(config).unwrap(); info!("Start"); let mut rand_signal = RandomSignal::new(Range::new(0, 100)); @@ -113,7 +111,6 @@ fn main() { let mut app = App { name: String::from("Test app"), - fetching: false, items: ["1", "2", "3"].into_iter().map(|e| String::from(*e)).collect(), selected: 0, show_chart: true, @@ -203,11 +200,19 @@ fn main() { fn draw(t: &mut Terminal, app: &App) { + let size = Terminal::size().unwrap(); + + Block::default() + .borders(border::ALL) + .title(&app.name) + .render(&size, t); + Group::default() .direction(Direction::Vertical) .alignment(Alignment::Left) + .margin(1) .chunks(&[Size::Fixed(7), Size::Min(5), Size::Fixed(3)]) - .render(t, &Terminal::size().unwrap(), |t, chunks| { + .render(t, &size, |t, chunks| { Block::default().borders(border::ALL).title("Graphs").render(&chunks[0], t); Group::default() .direction(Direction::Vertical) diff --git a/src/layout.rs b/src/layout.rs index 89b051f..a0a48bd 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -5,7 +5,6 @@ use cassowary::{Solver, Variable, Constraint}; use cassowary::WeightedRelation::*; use cassowary::strength::{WEAK, REQUIRED}; -use buffer::Buffer; use terminal::Terminal; use util::hash; diff --git a/src/terminal.rs b/src/terminal.rs index a53edc3..caa48f4 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -6,7 +6,6 @@ use termion; use termion::raw::{IntoRawMode, RawTerminal}; use buffer::Buffer; -use widgets::Widget; use layout::Rect; pub struct Terminal { @@ -55,7 +54,7 @@ impl Terminal { cell.symbol)) } } - write!(self.stdout, "{}", string); + write!(self.stdout, "{}", string).unwrap(); self.stdout.flush().unwrap(); } pub fn clear(&mut self) { diff --git a/src/widgets/block.rs b/src/widgets/block.rs index 4426b7d..c88ca46 100644 --- a/src/widgets/block.rs +++ b/src/widgets/block.rs @@ -95,7 +95,7 @@ impl<'a> Widget<'a> for Block<'a> { // Sides if self.borders.intersects(border::LEFT) { for y in 0..area.height { - let c = buf.update_cell(0, y, |c| { + buf.update_cell(0, y, |c| { c.symbol = line::VERTICAL; c.fg = self.border_fg; c.bg = self.border_bg; @@ -104,7 +104,7 @@ impl<'a> Widget<'a> for Block<'a> { } if self.borders.intersects(border::TOP) { for x in 0..area.width { - let c = buf.update_cell(x, 0, |c| { + buf.update_cell(x, 0, |c| { c.symbol = line::HORIZONTAL; c.fg = self.border_fg; c.bg = self.border_bg; @@ -151,7 +151,7 @@ impl<'a> Widget<'a> for Block<'a> { } else { 0 }; - buf.set_string(margin_x, 0, &title, self.title_fg, self.title_bg); + buf.set_string(margin_x, 0, title, self.title_fg, self.title_bg); } buf } diff --git a/src/widgets/chart.rs b/src/widgets/chart.rs index eb4137d..ea91036 100644 --- a/src/widgets/chart.rs +++ b/src/widgets/chart.rs @@ -6,7 +6,6 @@ use widgets::{Widget, Block}; use buffer::Buffer; use layout::Rect; use style::Color; -use util::hash; use symbols; pub struct Axis<'a> { diff --git a/src/widgets/gauge.rs b/src/widgets/gauge.rs index df169c8..365e01e 100644 --- a/src/widgets/gauge.rs +++ b/src/widgets/gauge.rs @@ -2,7 +2,6 @@ use widgets::{Widget, Block}; use buffer::Buffer; use style::Color; use layout::Rect; -use util::hash; /// Progress bar widget /// diff --git a/src/widgets/list.rs b/src/widgets/list.rs index bd9f70d..55af651 100644 --- a/src/widgets/list.rs +++ b/src/widgets/list.rs @@ -1,11 +1,9 @@ use std::cmp::min; -use std::hash::{Hash, Hasher}; use buffer::Buffer; use widgets::{Widget, Block}; use layout::Rect; use style::Color; -use util::hash; pub struct List<'a> { block: Option>, diff --git a/src/widgets/mod.rs b/src/widgets/mod.rs index 7dacdfe..acd90c6 100644 --- a/src/widgets/mod.rs +++ b/src/widgets/mod.rs @@ -12,12 +12,8 @@ pub use self::gauge::Gauge; pub use self::sparkline::Sparkline; pub use self::chart::{Chart, Axis, Dataset}; -use std::hash::Hash; - -use util::hash; -use buffer::{Buffer, Cell}; +use buffer::Buffer; use layout::Rect; -use style::Color; use terminal::Terminal; pub mod border { diff --git a/src/widgets/sparkline.rs b/src/widgets/sparkline.rs index e6ea2e6..da05f21 100644 --- a/src/widgets/sparkline.rs +++ b/src/widgets/sparkline.rs @@ -77,7 +77,7 @@ impl<'a> Widget<'a> for Sparkline<'a> { for j in (0..spark_area.height).rev() { for (i, d) in data.iter_mut().take(max_index).enumerate() { buf.update_cell(margin_x + i as u16, margin_y + j, |c| { - c.symbol = &match *d { + c.symbol = match *d { 0 => " ", 1 => bar::ONE_EIGHTH, 2 => bar::ONE_QUATER, diff --git a/src/widgets/text.rs b/src/widgets/text.rs index 3f9085b..aa90afa 100644 --- a/src/widgets/text.rs +++ b/src/widgets/text.rs @@ -62,9 +62,8 @@ impl<'a> Widget<'a> for Text<'a> { let margin_x = text_area.x - area.x; let margin_y = text_area.y - area.y; let height = min(lines.len(), text_area.height as usize); - let width = text_area.width as usize; for line in lines.iter_mut().take(height) { - buf.set_string(margin_x, margin_y, &line, self.fg, self.bg); + buf.set_string(margin_x, margin_y, line, self.fg, self.bg); } for &(x, y, width, fg, bg) in self.colors { for i in 0..width {