From f24517bc5a50a12ae9edebdaa24c9bc5e06debba Mon Sep 17 00:00:00 2001 From: Florian Dehau Date: Mon, 30 Oct 2017 22:28:37 +0100 Subject: [PATCH] [examples] Run cargo fmt --- examples/barchart.rs | 17 +++--- examples/block.rs | 18 +++--- examples/canvas.rs | 54 ++++++++--------- examples/chart.rs | 53 ++++++++--------- examples/demo.rs | 132 ++++++++++++++++++++---------------------- examples/gauge.rs | 31 +++++----- examples/list.rs | 43 ++++++-------- examples/paragraph.rs | 17 +++--- examples/rustbox.rs | 17 +++--- examples/sparkline.rs | 50 +++++++++------- examples/table.rs | 36 ++++++------ examples/tabs.rs | 9 ++- examples/util/mod.rs | 4 +- 13 files changed, 224 insertions(+), 257 deletions(-) diff --git a/examples/barchart.rs b/examples/barchart.rs index 55545a2..4ba29be 100644 --- a/examples/barchart.rs +++ b/examples/barchart.rs @@ -1,5 +1,5 @@ -extern crate tui; extern crate termion; +extern crate tui; use std::io; use std::thread; @@ -11,9 +11,9 @@ use termion::input::TermRead; use tui::Terminal; use tui::backend::MouseBackend; -use tui::widgets::{Widget, Block, border, BarChart}; -use tui::layout::{Group, Direction, Size, Rect}; -use tui::style::{Style, Color, Modifier}; +use tui::widgets::{border, BarChart, Block, Widget}; +use tui::layout::{Direction, Group, Rect, Size}; +use tui::style::{Color, Modifier, Style}; struct App<'a> { size: Rect, @@ -110,11 +110,9 @@ fn main() { let evt = rx.recv().unwrap(); match evt { - Event::Input(input) => { - if input == event::Key::Char('q') { - break; - } - } + Event::Input(input) => if input == event::Key::Char('q') { + break; + }, Event::Tick => { app.advance(); } @@ -126,7 +124,6 @@ fn main() { } fn draw(t: &mut Terminal, app: &App) { - Group::default() .direction(Direction::Vertical) .margin(2) diff --git a/examples/block.rs b/examples/block.rs index dd8885f..c14d59b 100644 --- a/examples/block.rs +++ b/examples/block.rs @@ -1,5 +1,5 @@ -extern crate tui; extern crate termion; +extern crate tui; use std::io; use termion::event; @@ -7,9 +7,9 @@ use termion::input::TermRead; use tui::Terminal; use tui::backend::MouseBackend; -use tui::widgets::{Widget, Block, border}; -use tui::layout::{Group, Direction, Size, Rect}; -use tui::style::{Style, Color, Modifier}; +use tui::widgets::{border, Block, Widget}; +use tui::layout::{Direction, Group, Rect, Size}; +use tui::style::{Color, Modifier, Style}; fn main() { let mut terminal = Terminal::new(MouseBackend::new().unwrap()).unwrap(); @@ -35,7 +35,6 @@ fn main() { } fn draw(t: &mut Terminal, size: &Rect) { - // Wrapping block for a group // Just draw the block and the group on the same area and build the group // with at least a margin of 1 @@ -56,9 +55,12 @@ fn draw(t: &mut Terminal, size: &Rect) { .render(t, &chunks[0]); Block::default() .title("Styled title") - .title_style(Style::default().fg(Color::White).bg(Color::Red).modifier( - Modifier::Bold, - )) + .title_style( + Style::default() + .fg(Color::White) + .bg(Color::Red) + .modifier(Modifier::Bold), + ) .render(t, &chunks[1]); }); Group::default() diff --git a/examples/canvas.rs b/examples/canvas.rs index 0dce5dd..1cf2a9f 100644 --- a/examples/canvas.rs +++ b/examples/canvas.rs @@ -1,5 +1,5 @@ -extern crate tui; extern crate termion; +extern crate tui; use std::io; use std::thread; @@ -11,9 +11,9 @@ use termion::input::TermRead; use tui::Terminal; use tui::backend::MouseBackend; -use tui::widgets::{Widget, Block, border}; -use tui::widgets::canvas::{Canvas, Map, MapResolution, Line}; -use tui::layout::{Group, Rect, Direction, Size}; +use tui::widgets::{border, Block, Widget}; +use tui::widgets::canvas::{Canvas, Line, Map, MapResolution}; +use tui::layout::{Direction, Group, Rect, Size}; use tui::style::Color; struct App { @@ -45,13 +45,11 @@ impl App { } fn advance(&mut self) { - if self.ball.left() < self.playground.left() || - self.ball.right() > self.playground.right() + if self.ball.left() < self.playground.left() || self.ball.right() > self.playground.right() { self.dir_x = !self.dir_x; } - if self.ball.top() < self.playground.top() || - self.ball.bottom() > self.playground.bottom() + if self.ball.top() < self.playground.top() || self.ball.bottom() > self.playground.bottom() { self.dir_y = !self.dir_y; } @@ -121,27 +119,25 @@ fn main() { let evt = rx.recv().unwrap(); match evt { - Event::Input(input) => { - match input { - event::Key::Char('q') => { - break; - } - event::Key::Down => { - app.y += 1.0; - } - event::Key::Up => { - app.y -= 1.0; - } - event::Key::Right => { - app.x += 1.0; - } - event::Key::Left => { - app.x -= 1.0; - } - - _ => {} + Event::Input(input) => match input { + event::Key::Char('q') => { + break; } - } + event::Key::Down => { + app.y += 1.0; + } + event::Key::Up => { + app.y -= 1.0; + } + event::Key::Right => { + app.x += 1.0; + } + event::Key::Left => { + app.x -= 1.0; + } + + _ => {} + }, Event::Tick => { app.advance(); } @@ -153,8 +149,6 @@ fn main() { } fn draw(t: &mut Terminal, app: &App) { - - Group::default() .direction(Direction::Horizontal) .sizes(&[Size::Percent(50), Size::Percent(50)]) diff --git a/examples/chart.rs b/examples/chart.rs index b44a638..123f92e 100644 --- a/examples/chart.rs +++ b/examples/chart.rs @@ -1,5 +1,5 @@ -extern crate tui; extern crate termion; +extern crate tui; mod util; use util::*; @@ -14,9 +14,9 @@ use termion::input::TermRead; use tui::Terminal; use tui::backend::MouseBackend; -use tui::widgets::{Widget, Block, border, Chart, Axis, Marker, Dataset}; +use tui::widgets::{border, Axis, Block, Chart, Dataset, Marker, Widget}; use tui::layout::Rect; -use tui::style::{Style, Color, Modifier}; +use tui::style::{Color, Modifier, Style}; struct App { size: Rect, @@ -108,11 +108,9 @@ fn main() { let evt = rx.recv().unwrap(); match evt { - Event::Input(input) => { - if input == event::Key::Char('q') { - break; - } - } + Event::Input(input) => if input == event::Key::Char('q') { + break; + }, Event::Tick => { app.advance(); } @@ -124,7 +122,6 @@ fn main() { } fn draw(t: &mut Terminal, app: &App) { - Chart::default() .block( Block::default() @@ -138,13 +135,11 @@ fn draw(t: &mut Terminal, app: &App) { .style(Style::default().fg(Color::Gray)) .labels_style(Style::default().modifier(Modifier::Italic)) .bounds(app.window) - .labels( - &[ - &format!("{}", app.window[0]), - &format!("{}", (app.window[0] + app.window[1]) / 2.0), - &format!("{}", app.window[1]), - ], - ), + .labels(&[ + &format!("{}", app.window[0]), + &format!("{}", (app.window[0] + app.window[1]) / 2.0), + &format!("{}", app.window[1]), + ]), ) .y_axis( Axis::default() @@ -154,20 +149,18 @@ fn draw(t: &mut Terminal, app: &App) { .bounds([-20.0, 20.0]) .labels(&["-20", "0", "20"]), ) - .datasets( - &[ - Dataset::default() - .name("data2") - .marker(Marker::Dot) - .style(Style::default().fg(Color::Cyan)) - .data(&app.data1), - Dataset::default() - .name("data3") - .marker(Marker::Braille) - .style(Style::default().fg(Color::Yellow)) - .data(&app.data2), - ], - ) + .datasets(&[ + Dataset::default() + .name("data2") + .marker(Marker::Dot) + .style(Style::default().fg(Color::Cyan)) + .data(&app.data1), + Dataset::default() + .name("data3") + .marker(Marker::Braille) + .style(Style::default().fg(Color::Yellow)) + .data(&app.data2), + ]) .render(t, &app.size); t.draw().unwrap(); diff --git a/examples/demo.rs b/examples/demo.rs index 1d5c314..79519ef 100644 --- a/examples/demo.rs +++ b/examples/demo.rs @@ -1,8 +1,8 @@ #[macro_use] extern crate log; -extern crate tui; extern crate termion; +extern crate tui; mod util; @@ -17,11 +17,11 @@ use termion::input::TermRead; use tui::Terminal; use tui::backend::MouseBackend; -use tui::widgets::{Widget, Block, SelectableList, List, Item, Gauge, Sparkline, Paragraph, border, - Chart, Axis, Dataset, BarChart, Marker, Tabs, Table, Row}; -use tui::widgets::canvas::{Canvas, Map, MapResolution, Line}; -use tui::layout::{Group, Direction, Size, Rect}; -use tui::style::{Style, Color, Modifier}; +use tui::widgets::{border, Axis, BarChart, Block, Chart, Dataset, Gauge, Item, List, Marker, + Paragraph, Row, SelectableList, Sparkline, Table, Tabs, Widget}; +use tui::widgets::canvas::{Canvas, Line, Map, MapResolution}; +use tui::layout::{Direction, Group, Rect, Size}; +use tui::style::{Color, Modifier, Style}; use util::*; @@ -57,8 +57,6 @@ enum Event { } fn main() { - - for argument in env::args() { if argument == "--log" { setup_log("demo.log"); @@ -236,33 +234,29 @@ fn main() { draw(&mut terminal, &app).unwrap(); let evt = rx.recv().unwrap(); match evt { - Event::Input(input) => { - match input { - event::Key::Char('q') => { - break; - } - event::Key::Up => { - if app.selected > 0 { - app.selected -= 1 - }; - } - event::Key::Down => { - if app.selected < app.items.len() - 1 { - app.selected += 1; - } - } - event::Key::Left => { - app.tabs.previous(); - } - event::Key::Right => { - app.tabs.next(); - } - event::Key::Char('t') => { - app.show_chart = !app.show_chart; - } - _ => {} + Event::Input(input) => match input { + event::Key::Char('q') => { + break; } - } + event::Key::Up => { + if app.selected > 0 { + app.selected -= 1 + }; + } + event::Key::Down => if app.selected < app.items.len() - 1 { + app.selected += 1; + }, + event::Key::Left => { + app.tabs.previous(); + } + event::Key::Right => { + app.tabs.next(); + } + event::Key::Char('t') => { + app.show_chart = !app.show_chart; + } + _ => {} + }, Event::Tick => { app.progress += 5; if app.progress > 100 { @@ -296,7 +290,6 @@ fn main() { } fn draw(t: &mut Terminal, app: &App) -> Result<(), io::Error> { - Group::default() .direction(Direction::Vertical) .sizes(&[Size::Fixed(3), Size::Min(0)]) @@ -334,7 +327,6 @@ fn draw_first_tab(t: &mut Terminal, app: &App, area: &Rect) { } fn draw_gauges(t: &mut Terminal, app: &App, area: &Rect) { - Block::default() .borders(border::ALL) .title("Graphs") @@ -438,13 +430,11 @@ fn draw_charts(t: &mut Terminal, app: &App, area: &Rect) { .style(Style::default().fg(Color::Gray)) .labels_style(Style::default().modifier(Modifier::Italic)) .bounds(app.window) - .labels( - &[ - &format!("{}", app.window[0]), - &format!("{}", (app.window[0] + app.window[1]) / 2.0), - &format!("{}", app.window[1]), - ], - ), + .labels(&[ + &format!("{}", app.window[0]), + &format!("{}", (app.window[0] + app.window[1]) / 2.0), + &format!("{}", app.window[1]), + ]), ) .y_axis( Axis::default() @@ -454,20 +444,18 @@ fn draw_charts(t: &mut Terminal, app: &App, area: &Rect) { .bounds([-20.0, 20.0]) .labels(&["-20", "0", "20"]), ) - .datasets( - &[ - Dataset::default() - .name("data2") - .marker(Marker::Dot) - .style(Style::default().fg(Color::Cyan)) - .data(&app.data2), - Dataset::default() - .name("data3") - .marker(Marker::Braille) - .style(Style::default().fg(Color::Yellow)) - .data(&app.data3), - ], - ) + .datasets(&[ + Dataset::default() + .name("data2") + .marker(Marker::Dot) + .style(Style::default().fg(Color::Cyan)) + .data(&app.data2), + Dataset::default() + .name("data3") + .marker(Marker::Braille) + .style(Style::default().fg(Color::Yellow)) + .data(&app.data3), + ]) .render(t, &chunks[1]); } }); @@ -475,20 +463,24 @@ fn draw_charts(t: &mut Terminal, app: &App, area: &Rect) { fn draw_text(t: &mut Terminal, area: &Rect) { Paragraph::default() - .block(Block::default() - .borders(border::ALL) - .title("Footer") - .title_style(Style::default().fg(Color::Magenta).modifier(Modifier::Bold))) + .block( + Block::default() + .borders(border::ALL) + .title("Footer") + .title_style(Style::default().fg(Color::Magenta).modifier(Modifier::Bold)), + ) .wrap(true) - .text("This is a paragraph with several lines.\nYou can change the color.\nUse \ - \\{fg=[color];bg=[color];mod=[modifier] [text]} to highlight the text with a color. \ - For example, {fg=red u}{fg=green n}{fg=yellow d}{fg=magenta e}{fg=cyan r} \ - {fg=gray t}{fg=light_gray h}{fg=light_red e} {fg=light_green r}{fg=light_yellow a} \ - {fg=light_magenta i}{fg=light_cyan n}{fg=white b}{fg=red o}{fg=green w}.\n\ - Oh, and if you didn't {mod=italic notice} you can {mod=bold automatically} \ - {mod=invert wrap} your {mod=underline text} =).\nOne more thing is that \ - it should display unicode characters properly: 日本国, ٩(-̮̮̃-̃)۶ ٩(●̮̮̃•̃)۶ ٩(͡๏̯͡๏)۶ \ - ٩(-̮̮̃•̃).") + .text( + "This is a paragraph with several lines.\nYou can change the color.\nUse \ + \\{fg=[color];bg=[color];mod=[modifier] [text]} to highlight the text with a color. \ + For example, {fg=red u}{fg=green n}{fg=yellow d}{fg=magenta e}{fg=cyan r} \ + {fg=gray t}{fg=light_gray h}{fg=light_red e} {fg=light_green r}{fg=light_yellow a} \ + {fg=light_magenta i}{fg=light_cyan n}{fg=white b}{fg=red o}{fg=green w}.\n\ + Oh, and if you didn't {mod=italic notice} you can {mod=bold automatically} \ + {mod=invert wrap} your {mod=underline text} =).\nOne more thing is that \ + it should display unicode characters properly: 日本国, ٩(-̮̮̃-̃)۶ ٩(●̮̮̃•̃)۶ ٩(͡๏̯͡๏)۶ \ + ٩(-̮̮̃•̃).", + ) .render(t, area); } diff --git a/examples/gauge.rs b/examples/gauge.rs index 545bc72..5c79140 100644 --- a/examples/gauge.rs +++ b/examples/gauge.rs @@ -1,5 +1,5 @@ -extern crate tui; extern crate termion; +extern crate tui; use std::io; use std::thread; @@ -11,9 +11,9 @@ use termion::input::TermRead; use tui::Terminal; use tui::backend::MouseBackend; -use tui::widgets::{Widget, Block, border, Gauge}; -use tui::layout::{Group, Direction, Size, Rect}; -use tui::style::{Style, Color, Modifier}; +use tui::widgets::{border, Block, Gauge, Widget}; +use tui::layout::{Direction, Group, Rect, Size}; +use tui::style::{Color, Modifier, Style}; struct App { size: Rect, @@ -105,11 +105,9 @@ fn main() { let evt = rx.recv().unwrap(); match evt { - Event::Input(input) => { - if input == event::Key::Char('q') { - break; - } - } + Event::Input(input) => if input == event::Key::Char('q') { + break; + }, Event::Tick => { app.advance(); } @@ -121,18 +119,15 @@ fn main() { } fn draw(t: &mut Terminal, app: &App) { - Group::default() .direction(Direction::Vertical) .margin(2) - .sizes( - &[ - Size::Percent(25), - Size::Percent(25), - Size::Percent(25), - Size::Percent(25), - ], - ) + .sizes(&[ + Size::Percent(25), + Size::Percent(25), + Size::Percent(25), + Size::Percent(25), + ]) .render(t, &app.size, |t, chunks| { Gauge::default() .block(Block::default().title("Gauge1").borders(border::ALL)) diff --git a/examples/list.rs b/examples/list.rs index 91c19f0..f19b747 100644 --- a/examples/list.rs +++ b/examples/list.rs @@ -1,5 +1,5 @@ -extern crate tui; extern crate termion; +extern crate tui; use std::io; use std::thread; @@ -11,9 +11,9 @@ use termion::input::TermRead; use tui::Terminal; use tui::backend::MouseBackend; -use tui::widgets::{Widget, Block, border, SelectableList, List, Item}; -use tui::layout::{Group, Direction, Size, Rect}; -use tui::style::{Style, Color, Modifier}; +use tui::widgets::{border, Block, Item, List, SelectableList, Widget}; +use tui::layout::{Direction, Group, Rect, Size}; +use tui::style::{Color, Modifier, Style}; struct App<'a> { size: Rect, @@ -149,27 +149,23 @@ fn main() { let evt = rx.recv().unwrap(); match evt { - Event::Input(input) => { - match input { - event::Key::Char('q') => { - break; - } - event::Key::Down => { - app.selected += 1; - if app.selected > app.items.len() - 1 { - app.selected = 0; - } - } - event::Key::Up => { - if app.selected > 0 { - app.selected -= 1; - } else { - app.selected = app.items.len() - 1; - } + Event::Input(input) => match input { + event::Key::Char('q') => { + break; + } + event::Key::Down => { + app.selected += 1; + if app.selected > app.items.len() - 1 { + app.selected = 0; } - _ => {} } - } + event::Key::Up => if app.selected > 0 { + app.selected -= 1; + } else { + app.selected = app.items.len() - 1; + }, + _ => {} + }, Event::Tick => { app.advance(); } @@ -181,7 +177,6 @@ fn main() { } fn draw(t: &mut Terminal, app: &App) { - Group::default() .direction(Direction::Horizontal) .sizes(&[Size::Percent(50), Size::Percent(50)]) diff --git a/examples/paragraph.rs b/examples/paragraph.rs index 3ffc509..812e107 100644 --- a/examples/paragraph.rs +++ b/examples/paragraph.rs @@ -1,5 +1,5 @@ -extern crate tui; extern crate termion; +extern crate tui; use std::io; use termion::event; @@ -7,9 +7,9 @@ use termion::input::TermRead; use tui::Terminal; use tui::backend::MouseBackend; -use tui::widgets::{Widget, Block, Paragraph}; -use tui::layout::{Group, Direction, Size, Rect}; -use tui::style::{Style, Color}; +use tui::widgets::{Block, Paragraph, Widget}; +use tui::layout::{Direction, Group, Rect, Size}; +use tui::style::{Color, Style}; fn main() { let mut terminal = Terminal::new(MouseBackend::new().unwrap()).unwrap(); @@ -37,7 +37,6 @@ fn main() { } fn draw(t: &mut Terminal, size: &Rect) { - Block::default() .style(Style::default().bg(Color::White)) .render(t, size); @@ -54,10 +53,10 @@ fn draw(t: &mut Terminal, size: &Rect) { Paragraph::default() .text( "This is a line\n{fg=red This is a line}\n{bg=red This is a \ - line}\n{mod=italic This is a line}\n{mod=bold This is a \ - line}\n{mod=crossed_out This is a line}\n{mod=invert This is a \ - line}\n{mod=underline This is a \ - line}\n{bg=green;fg=yellow;mod=italic This is a line}\n", + line}\n{mod=italic This is a line}\n{mod=bold This is a \ + line}\n{mod=crossed_out This is a line}\n{mod=invert This is a \ + line}\n{mod=underline This is a \ + line}\n{bg=green;fg=yellow;mod=italic This is a line}\n", ) .render(t, &chunks[0]); }); diff --git a/examples/rustbox.rs b/examples/rustbox.rs index a6ff30e..222428f 100644 --- a/examples/rustbox.rs +++ b/examples/rustbox.rs @@ -1,14 +1,14 @@ -extern crate tui; extern crate rustbox; +extern crate tui; use std::error::Error; use rustbox::Key; use tui::Terminal; use tui::backend::RustboxBackend; -use tui::widgets::{Widget, Block, border, Paragraph}; -use tui::layout::{Group, Direction, Size}; -use tui::style::{Style, Color, Modifier}; +use tui::widgets::{border, Block, Paragraph, Widget}; +use tui::layout::{Direction, Group, Size}; +use tui::style::{Color, Modifier, Style}; fn main() { let mut terminal = Terminal::new(RustboxBackend::new().unwrap()).unwrap(); @@ -17,11 +17,9 @@ fn main() { draw(&mut terminal); loop { match terminal.backend().rustbox().poll_event(false) { - Ok(rustbox::Event::KeyEvent(key)) => { - if key == Key::Char('q') { - break; - } - } + Ok(rustbox::Event::KeyEvent(key)) => if key == Key::Char('q') { + break; + }, Err(e) => panic!("{}", e.description()), _ => {} }; @@ -31,7 +29,6 @@ fn main() { } fn draw(t: &mut Terminal) { - let size = t.size().unwrap(); Group::default() diff --git a/examples/sparkline.rs b/examples/sparkline.rs index d4041a0..cf5ad13 100644 --- a/examples/sparkline.rs +++ b/examples/sparkline.rs @@ -1,5 +1,5 @@ -extern crate tui; extern crate termion; +extern crate tui; mod util; use util::*; @@ -14,9 +14,9 @@ use termion::input::TermRead; use tui::Terminal; use tui::backend::MouseBackend; -use tui::widgets::{Widget, Block, border, Sparkline}; -use tui::layout::{Group, Direction, Size, Rect}; -use tui::style::{Style, Color}; +use tui::widgets::{border, Block, Sparkline, Widget}; +use tui::layout::{Direction, Group, Rect, Size}; +use tui::style::{Color, Style}; struct App { size: Rect, @@ -105,11 +105,9 @@ fn main() { let evt = rx.recv().unwrap(); match evt { - Event::Input(input) => { - if input == event::Key::Char('q') { - break; - } - } + Event::Input(input) => if input == event::Key::Char('q') { + break; + }, Event::Tick => { app.advance(); } @@ -121,33 +119,41 @@ fn main() { } fn draw(t: &mut Terminal, app: &App) { - Group::default() .direction(Direction::Vertical) .margin(2) - .sizes( - &[Size::Fixed(3), Size::Fixed(3), Size::Fixed(7), Size::Min(0)], - ) + .sizes(&[ + Size::Fixed(3), + Size::Fixed(3), + Size::Fixed(7), + Size::Min(0), + ]) .render(t, &app.size, |t, chunks| { Sparkline::default() - .block(Block::default().title("Data1").borders( - border::LEFT | border::RIGHT, - )) + .block( + Block::default() + .title("Data1") + .borders(border::LEFT | border::RIGHT), + ) .data(&app.data1) .style(Style::default().fg(Color::Yellow)) .render(t, &chunks[0]); Sparkline::default() - .block(Block::default().title("Data2").borders( - border::LEFT | border::RIGHT, - )) + .block( + Block::default() + .title("Data2") + .borders(border::LEFT | border::RIGHT), + ) .data(&app.data2) .style(Style::default().bg(Color::Green)) .render(t, &chunks[1]); // Multiline Sparkline::default() - .block(Block::default().title("Data3").borders( - border::LEFT | border::RIGHT, - )) + .block( + Block::default() + .title("Data3") + .borders(border::LEFT | border::RIGHT), + ) .data(&app.data3) .style(Style::default().fg(Color::Red)) .render(t, &chunks[2]); diff --git a/examples/table.rs b/examples/table.rs index 5b900b5..993405c 100644 --- a/examples/table.rs +++ b/examples/table.rs @@ -1,5 +1,5 @@ -extern crate tui; extern crate termion; +extern crate tui; use std::io; @@ -8,9 +8,9 @@ use termion::input::TermRead; use tui::Terminal; use tui::backend::MouseBackend; -use tui::widgets::{Widget, Block, border, Table, Row}; -use tui::layout::{Group, Direction, Size, Rect}; -use tui::style::{Style, Color, Modifier}; +use tui::widgets::{border, Block, Row, Table, Widget}; +use tui::layout::{Direction, Group, Rect, Size}; +use tui::style::{Color, Modifier, Style}; struct App<'a> { size: Rect, @@ -70,13 +70,11 @@ fn main() { app.selected = 0; } } - event::Key::Up => { - if app.selected > 0 { - app.selected -= 1; - } else { - app.selected = app.items.len() - 1; - } - } + event::Key::Up => if app.selected > 0 { + app.selected -= 1; + } else { + app.selected = app.items.len() - 1; + }, _ => {} }; draw(&mut terminal, &app); @@ -87,7 +85,6 @@ fn main() { } fn draw(t: &mut Terminal, app: &App) { - Group::default() .direction(Direction::Horizontal) .sizes(&[Size::Percent(100)]) @@ -97,13 +94,14 @@ fn draw(t: &mut Terminal, app: &App) { let normal_style = Style::default().fg(Color::White); Table::new( ["Header1", "Header2", "Header3"].into_iter(), - app.items.iter().enumerate().map(|(i, item)| if i == - app.selected - { - Row::StyledData(item.into_iter(), &selected_style) - } else { - Row::StyledData(item.into_iter(), &normal_style) - }), + app.items + .iter() + .enumerate() + .map(|(i, item)| if i == app.selected { + Row::StyledData(item.into_iter(), &selected_style) + } else { + Row::StyledData(item.into_iter(), &normal_style) + }), ).block(Block::default().borders(border::ALL).title("Table")) .widths(&[10, 10, 10]) .render(t, &chunks[0]); diff --git a/examples/tabs.rs b/examples/tabs.rs index 967ff98..5ff98a0 100644 --- a/examples/tabs.rs +++ b/examples/tabs.rs @@ -1,5 +1,5 @@ -extern crate tui; extern crate termion; +extern crate tui; mod util; use util::*; @@ -10,9 +10,9 @@ use termion::input::TermRead; use tui::Terminal; use tui::backend::MouseBackend; -use tui::widgets::{Widget, Block, border, Tabs}; -use tui::layout::{Group, Direction, Size, Rect}; -use tui::style::{Style, Color}; +use tui::widgets::{border, Block, Tabs, Widget}; +use tui::layout::{Direction, Group, Rect, Size}; +use tui::style::{Color, Style}; struct App<'a> { size: Rect, @@ -64,7 +64,6 @@ fn main() { } fn draw(t: &mut Terminal, app: &mut App) { - Block::default() .style(Style::default().bg(Color::White)) .render(t, &app.size); diff --git a/examples/util/mod.rs b/examples/util/mod.rs index 1e3d5ee..1e862f1 100644 --- a/examples/util/mod.rs +++ b/examples/util/mod.rs @@ -1,8 +1,8 @@ #![allow(dead_code)] -extern crate rand; extern crate log4rs; extern crate log; +extern crate rand; use self::rand::distributions::{IndependentSample, Range}; @@ -15,7 +15,7 @@ pub fn setup_log(file_name: &str) { let log = FileAppender::builder() .encoder(Box::new(PatternEncoder::new( "{l} / {d(%H:%M:%S)} / \ - {M}:{L}{n}{m}{n}{n}", + {M}:{L}{n}{m}{n}{n}", ))) .build(file_name) .unwrap();