mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-22 20:53:19 +00:00
Refactor demo example
This commit is contained in:
parent
89a173fe9b
commit
41eac2aa4e
2 changed files with 12 additions and 16 deletions
|
@ -17,7 +17,7 @@ use termion::input::TermRead;
|
||||||
|
|
||||||
use tui::Terminal;
|
use tui::Terminal;
|
||||||
use tui::backend::MouseBackend;
|
use tui::backend::MouseBackend;
|
||||||
use tui::widgets::{Widget, Block, SelectableList, List, Gauge, Sparkline, Paragraph, border,
|
use tui::widgets::{Widget, Block, SelectableList, List, Item, Gauge, Sparkline, Paragraph, border,
|
||||||
Chart, Axis, Dataset, BarChart, Marker, Tabs, Table};
|
Chart, Axis, Dataset, BarChart, Marker, Tabs, Table};
|
||||||
use tui::widgets::canvas::{Canvas, Map, MapResolution, Line};
|
use tui::widgets::canvas::{Canvas, Map, MapResolution, Line};
|
||||||
use tui::layout::{Group, Direction, Size, Rect};
|
use tui::layout::{Group, Direction, Size, Rect};
|
||||||
|
@ -363,21 +363,18 @@ fn draw_charts(t: &mut Terminal<MouseBackend>, app: &App, area: &Rect) {
|
||||||
let warning_style = Style::default().fg(Color::Yellow);
|
let warning_style = Style::default().fg(Color::Yellow);
|
||||||
let error_style = Style::default().fg(Color::Magenta);
|
let error_style = Style::default().fg(Color::Magenta);
|
||||||
let critical_style = Style::default().fg(Color::Red);
|
let critical_style = Style::default().fg(Color::Red);
|
||||||
List::default()
|
List::new(app.events
|
||||||
.block(Block::default().borders(border::ALL).title("List"))
|
.iter()
|
||||||
.items(&app.events
|
.map(|&(evt, level)| {
|
||||||
.iter()
|
Item::StyledData(format!("{}: {}", level, evt), match level {
|
||||||
.map(|&(evt, level)| {
|
"ERROR" => &error_style,
|
||||||
(format!("{}: {}", level, evt),
|
"CRITICAL" => &critical_style,
|
||||||
match level {
|
"WARNING" => &warning_style,
|
||||||
"ERROR" => &error_style,
|
_ => &info_style,
|
||||||
"CRITICAL" => &critical_style,
|
|
||||||
"WARNING" => &warning_style,
|
|
||||||
_ => &info_style,
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<(String, &Style)>>())
|
}))
|
||||||
.render(t, &chunks[1]);
|
.block(Block::default().borders(border::ALL).title("List"))
|
||||||
|
.render(t, &chunks[1]);
|
||||||
});
|
});
|
||||||
BarChart::default()
|
BarChart::default()
|
||||||
.block(Block::default().borders(border::ALL).title("Bar chart"))
|
.block(Block::default().borders(border::ALL).title("Bar chart"))
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
use std::cmp::min;
|
|
||||||
use std::iter::Iterator;
|
use std::iter::Iterator;
|
||||||
|
|
||||||
use unicode_width::UnicodeWidthStr;
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
Loading…
Reference in a new issue