mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-22 12:43:16 +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::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};
|
||||
use tui::widgets::canvas::{Canvas, Map, MapResolution, Line};
|
||||
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 error_style = Style::default().fg(Color::Magenta);
|
||||
let critical_style = Style::default().fg(Color::Red);
|
||||
List::default()
|
||||
.block(Block::default().borders(border::ALL).title("List"))
|
||||
.items(&app.events
|
||||
.iter()
|
||||
.map(|&(evt, level)| {
|
||||
(format!("{}: {}", level, evt),
|
||||
match level {
|
||||
"ERROR" => &error_style,
|
||||
"CRITICAL" => &critical_style,
|
||||
"WARNING" => &warning_style,
|
||||
_ => &info_style,
|
||||
})
|
||||
List::new(app.events
|
||||
.iter()
|
||||
.map(|&(evt, level)| {
|
||||
Item::StyledData(format!("{}: {}", level, evt), match level {
|
||||
"ERROR" => &error_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()
|
||||
.block(Block::default().borders(border::ALL).title("Bar chart"))
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use std::iter;
|
||||
use std::fmt::Display;
|
||||
use std::cmp::min;
|
||||
use std::iter::Iterator;
|
||||
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
|
|
Loading…
Reference in a new issue