Fix examples

pull/3/head
Florian Dehau 8 years ago
parent 224eb2d8e0
commit 662e2dd102

@ -8,7 +8,7 @@ watch:
watchman-make -p 'src/**/*.rs' -t build -p 'test/**/*.rs' -t test
watch-test:
watchman-make -p 'src/**/*.rs' 'tests/**/*.rs' -t test
watchman-make -p 'src/**/*.rs' 'tests/**/*.rs' 'examples/**/*.rs' -t test
watch-doc:
watchman-make -p 'src/**/*.rs' -t doc

@ -8,7 +8,7 @@ use termion::input::TermRead;
use tui::{Terminal, TermionBackend};
use tui::widgets::{Widget, Block, border};
use tui::layout::{Group, Direction, Size};
use tui::style::Color;
use tui::style::{Style, Color};
fn main() {
let mut terminal = Terminal::new(TermionBackend::new().unwrap()).unwrap();
@ -36,31 +36,33 @@ fn draw(t: &mut Terminal<TermionBackend>) {
.render(t, &size, |t, chunks| {
Block::default()
.title("Top")
.title_color(Color::Magenta)
.background_color(Color::White)
.border_color(Color::Magenta)
.title_style(Style::default().fg(Color::Magenta))
.border_style(Style::default().fg(Color::Magenta))
.borders(border::BOTTOM)
.render(t, &chunks[0]);
Group::default()
.direction(Direction::Horizontal)
.sizes(&[Size::Fixed(7), Size::Min(0), Size::Fixed(7)])
.render(t, &chunks[1], |t, chunks| {
Block::default().title("Left").title_color(Color::Yellow).render(t, &chunks[0]);
Block::default()
.title("Left")
.title_style(Style::default().fg(Color::Yellow))
.render(t, &chunks[0]);
Block::default()
.title("Middle")
.title_color(Color::Cyan)
.border_color(Color::Cyan)
.title_style(Style::default().fg(Color::Cyan))
.border_style(Style::default().fg(Color::Cyan))
.borders(border::LEFT | border::RIGHT)
.render(t, &chunks[1]);
Block::default()
.title("Right")
.title_color(Color::Green)
.title_style(Style::default().fg(Color::Green))
.render(t, &chunks[2]);
});
Block::default()
.title("Bottom")
.title_color(Color::Red)
.border_color(Color::Red)
.title_style(Style::default().fg(Color::Green))
.border_style(Style::default().fg(Color::Green))
.borders(border::TOP)
.render(t, &chunks[2]);
});

@ -4,7 +4,7 @@ use tui::{Terminal, TermionBackend};
use tui::widgets::Widget;
use tui::buffer::Buffer;
use tui::layout::Rect;
use tui::style::Color;
use tui::style::Style;
struct Label<'a> {
text: &'a str,
@ -18,11 +18,7 @@ impl<'a> Default for Label<'a> {
impl<'a> Widget for Label<'a> {
fn draw(&self, area: &Rect, buf: &mut Buffer) {
buf.set_string(area.left(),
area.top(),
self.text,
Color::Reset,
Color::Reset);
buf.set_string(area.left(), area.top(), self.text, &Style::default());
}
}

@ -469,7 +469,12 @@ fn draw_main(t: &mut Terminal<TermionBackend>, app: &App, area: &Rect) {
});
if app.show_chart {
Chart::default()
.block(Block::default().title("Chart").borders(border::ALL))
.block(Block::default()
.title("Chart")
.title_style(Style::default()
.fg(Color::Cyan)
.modifier(Modifier::Bold))
.borders(border::ALL))
.x_axis(Axis::default()
.title("X Axis")
.style(Style::default().fg(Color::Gray))

@ -75,18 +75,20 @@ impl Default for Cell {
/// # extern crate tui;
/// use tui::buffer::{Buffer, Cell};
/// use tui::layout::Rect;
/// use tui::style::{Color, Style};
/// use tui::style::{Color, Style, Modifier};
///
/// # fn main() {
/// let mut buf = Buffer::empty(Rect{x: 0, y: 0, width: 10, height: 5});
/// buf.get_mut(0, 2).set_symbol("x");
/// assert_eq!(buf.get(0, 2).symbol, "x");
/// buf.set_string(3, 0, "string", Color::Red, Color::White);
/// buf.set_string(3, 0, "string", &Style::default().fg(Color::Red).bg(Color::White));
/// assert_eq!(buf.get(5, 0), &Cell{
/// symbol: String::from("r"),
/// fg: Color::Red,
/// bg: Color::White,
/// style: Style::Reset});
/// style: Style {
/// fg: Color::Red,
/// bg: Color::White,
/// modifier: Modifier::Reset
/// }});
/// buf.get_mut(5, 0).set_char('x');
/// assert_eq!(buf.get(5, 0).symbol, "x");
/// # }

@ -15,16 +15,15 @@ use symbols::bar;
/// ```
/// # extern crate tui;
/// # use tui::widgets::{Block, border, BarChart};
/// # use tui::style::Color;
/// # use tui::style::{Style, Color, Modifier};
/// # fn main() {
/// BarChart::default()
/// .block(Block::default().title("BarChart").borders(border::ALL))
/// .bar_width(3)
/// .bar_gap(1)
/// .bar_color(Color::Yellow)
/// .value_color(Color::Red)
/// .label_color(Color::White)
/// .background_color(Color::Black)
/// .style(Style::default().fg(Color::Yellow).bg(Color::Red))
/// .value_style(Style::default().fg(Color::Red).modifier(Modifier::Bold))
/// .label_style(Style::default().fg(Color::White))
/// .data(&[("B0", 0), ("B1", 2), ("B2", 4), ("B3", 3)])
/// .max(4);
/// # }

@ -12,14 +12,14 @@ use symbols::line;
/// ```
/// # extern crate tui;
/// # use tui::widgets::{Block, border};
/// # use tui::style::Color;
/// # use tui::style::{Style, Color};
/// # fn main() {
/// Block::default()
/// .title("Block")
/// .title_color(Color::Red)
/// .title_style(Style::default().fg(Color::Red))
/// .borders(border::LEFT | border::RIGHT)
/// .border_color(Color::White)
/// .background_color(Color::Black);
/// .border_style(Style::default().fg(Color::White))
/// .style(Style::default().bg(Color::Black));
/// # }
/// ```
#[derive(Clone, Copy)]

@ -159,29 +159,31 @@ impl Default for ChartLayout {
/// ```
/// # extern crate tui;
/// # use tui::widgets::{Block, border, Chart, Axis, Dataset, Marker};
/// # use tui::style::Color;
/// # use tui::style::{Style, Color};
/// # fn main() {
/// Chart::default()
/// .block(Block::default().title("Chart"))
/// .x_axis(Axis::default()
/// .title("X Axis")
/// .color(Color::Gray)
/// .title_style(Style::default().fg(Color::Red))
/// .style(Style::default().fg(Color::Gray))
/// .bounds([0.0, 10.0])
/// .labels(&["0.0", "5.0", "10.0"]))
/// .y_axis(Axis::default()
/// .title("Y Axis")
/// .color(Color::Gray)
/// .title_style(Style::default().fg(Color::Red))
/// .style(Style::default().fg(Color::Gray))
/// .bounds([0.0, 10.0])
/// .labels(&["0.0", "5.0", "10.0"]))
/// .datasets(&[Dataset::default()
/// .name("data1")
/// .marker(Marker::Dot)
/// .color(Color::Cyan)
/// .style(Style::default().fg(Color::Cyan))
/// .data(&[(0.0, 5.0), (1.0, 6.0), (1.5, 6.434)]),
/// Dataset::default()
/// .name("data2")
/// .marker(Marker::Braille)
/// .color(Color::Magenta)
/// .style(Style::default().fg(Color::Magenta))
/// .data(&[(4.0, 5.0), (5.0, 8.0), (7.66, 13.5)])]);
/// # }
pub struct Chart<'a> {

@ -12,12 +12,11 @@ use layout::Rect;
/// ```
/// # extern crate tui;
/// # use tui::widgets::{Widget, Gauge, Block, border};
/// # use tui::style::{Style, Color, ;
/// # use tui::style::{Style, Color, Modifier};
/// # fn main() {
/// Gauge::default()
/// .block(Block::default().borders(border::ALL).title("Progress"))
/// .style(Style::default().fg(Color::White).bg(Color::Black).modifier(Modifier::Italic))
/// .background_color(Color::Black)
/// .percent(20);
/// # }
/// ```

@ -14,14 +14,14 @@ use style::Style;
/// ```
/// # extern crate tui;
/// # use tui::widgets::{Block, border, List};
/// # use tui::style::Color;
/// # use tui::style::{Style, Color, Modifier};
/// # fn main() {
/// List::default()
/// .block(Block::default().title("List").borders(border::ALL))
/// .items(&["Item 1", "Item 2", "Item 3"])
/// .select(1)
/// .color(Color::White)
/// .highlight_color(Color::Yellow)
/// .style(Style::default().fg(Color::White))
/// .highlight_style(Style::default().modifier(Modifier::Italic))
/// .highlight_symbol(">>");
/// # }
/// ```

@ -14,12 +14,11 @@ use style::{Style, Color, Modifier};
/// ```
/// # extern crate tui;
/// # use tui::widgets::{Block, border, Paragraph};
/// # use tui::style::Color;
/// # use tui::style::{Style, Color};
/// # fn main() {
/// Paragraph::default()
/// .block(Block::default().title("Paragraph").borders(border::ALL))
/// .color(Color::White)
/// .background_color(Color::Black)
/// .style(Style::default().fg(Color::White).bg(Color::Black))
/// .wrap(true)
/// .text("First line\nSecond line\n{red Colored text}.");
/// # }

@ -13,14 +13,13 @@ use symbols::bar;
/// ```
/// # extern crate tui;
/// # use tui::widgets::{Block, border, Sparkline};
/// # use tui::style::Color;
/// # use tui::style::{Style, Color};
/// # fn main() {
/// Sparkline::default()
/// .block(Block::default().title("Sparkline").borders(border::ALL))
/// .data(&[0, 2, 3, 4, 1, 4, 10])
/// .max(5)
/// .color(Color::Yellow)
/// .background_color(Color::Red);
/// .style(Style::default().fg(Color::Red).bg(Color::White));
/// # }
/// ```
pub struct Sparkline<'a> {

@ -14,19 +14,18 @@ use style::Style;
///
/// ```
/// # use tui::widgets::{Block, border, Table};
/// # use tui::style::Color;
/// # use tui::style::{Style, Color};
/// # fn main() {
/// Table::default()
/// .block(Block::default().title("Table"))
/// .header(&["Col1", "Col2", "Col3"])
/// .header_color(Color::Yellow)
/// .header_style(Style::default().fg(Color::Yellow))
/// .widths(&[5, 5, 10])
/// .style(Style::default().fg(Color::White))
/// .column_spacing(1)
/// .rows(vec![["Row11", "Row12", "Row13"].as_ref(),
/// ["Row21", "Row22", "Row23"].as_ref(),
/// ["Row31", "Row32", "Row33"].as_ref()])
/// .color(Color::White)
/// .background_color(Color::Black);
/// ["Row31", "Row32", "Row33"].as_ref()]);
/// # }
/// ```
pub struct Table<'a> {
@ -97,6 +96,12 @@ impl<'a> Table<'a> {
self
}
pub fn style(&mut self, style: Style) -> &mut Table<'a> {
self.style = style;
self
}
pub fn column_spacing(&mut self, spacing: u16) -> &mut Table<'a> {
self.column_spacing = spacing;
self

@ -13,14 +13,13 @@ use symbols::line;
/// ```
/// # extern crate tui;
/// # use tui::widgets::{Block, border, Tabs};
/// # use tui::style::Color;
/// # use tui::style::{Style, Color};
/// # fn main() {
/// Tabs::default()
/// .block(Block::default().title("Tabs").borders(border::ALL))
/// .titles(&["Tab1", "Tab2", "Tab3", "Tab4"])
/// .color(Color::White)
/// .highlight_color(Color::Yellow)
/// .background_color(Color::Black);
/// .style(Style::default().fg(Color::White))
/// .highlight_style(Style::default().fg(Color::Yellow));
/// # }
/// ```
pub struct Tabs<'a> {

Loading…
Cancel
Save