2023-07-16 09:11:59 +00:00
|
|
|
use ratatui::{
|
|
|
|
prelude::*,
|
|
|
|
widgets::{canvas::*, *},
|
|
|
|
};
|
2016-10-09 17:46:53 +00:00
|
|
|
|
2023-06-12 05:07:15 +00:00
|
|
|
use crate::app::App;
|
|
|
|
|
2023-09-26 05:30:36 +00:00
|
|
|
pub fn draw(f: &mut Frame, app: &mut App) {
|
2024-01-05 15:45:14 +00:00
|
|
|
let chunks = Layout::vertical([Constraint::Length(3), Constraint::Min(0)]).split(f.size());
|
2024-01-11 01:16:44 +00:00
|
|
|
let tabs = app
|
2020-05-10 13:44:30 +00:00
|
|
|
.tabs
|
|
|
|
.titles
|
|
|
|
.iter()
|
2023-07-16 09:11:59 +00:00
|
|
|
.map(|t| text::Line::from(Span::styled(*t, Style::default().fg(Color::Green))))
|
2024-01-11 01:16:44 +00:00
|
|
|
.collect::<Tabs>()
|
2019-12-15 20:38:18 +00:00
|
|
|
.block(Block::default().borders(Borders::ALL).title(app.title))
|
2020-07-11 17:08:28 +00:00
|
|
|
.highlight_style(Style::default().fg(Color::Yellow))
|
2019-12-15 20:38:18 +00:00
|
|
|
.select(app.tabs.index);
|
|
|
|
f.render_widget(tabs, chunks[0]);
|
|
|
|
match app.tabs.index {
|
|
|
|
0 => draw_first_tab(f, app, chunks[1]),
|
|
|
|
1 => draw_second_tab(f, app, chunks[1]),
|
2021-01-01 14:29:04 +00:00
|
|
|
2 => draw_third_tab(f, app, chunks[1]),
|
2019-12-15 20:38:18 +00:00
|
|
|
_ => {}
|
|
|
|
};
|
2016-10-09 17:46:53 +00:00
|
|
|
}
|
|
|
|
|
2023-09-26 05:30:36 +00:00
|
|
|
fn draw_first_tab(f: &mut Frame, app: &mut App, area: Rect) {
|
2024-01-05 15:45:14 +00:00
|
|
|
let chunks = Layout::vertical([
|
|
|
|
Constraint::Length(9),
|
|
|
|
Constraint::Min(8),
|
|
|
|
Constraint::Length(7),
|
|
|
|
])
|
|
|
|
.split(area);
|
2018-08-12 22:27:56 +00:00
|
|
|
draw_gauges(f, app, chunks[0]);
|
|
|
|
draw_charts(f, app, chunks[1]);
|
|
|
|
draw_text(f, chunks[2]);
|
2017-05-21 09:13:24 +00:00
|
|
|
}
|
|
|
|
|
2023-09-26 05:30:36 +00:00
|
|
|
fn draw_gauges(f: &mut Frame, app: &mut App, area: Rect) {
|
2024-01-05 15:45:14 +00:00
|
|
|
let chunks = Layout::vertical([
|
|
|
|
Constraint::Length(2),
|
|
|
|
Constraint::Length(3),
|
|
|
|
Constraint::Length(1),
|
|
|
|
])
|
|
|
|
.margin(1)
|
|
|
|
.split(area);
|
2019-12-15 20:38:18 +00:00
|
|
|
let block = Block::default().borders(Borders::ALL).title("Graphs");
|
|
|
|
f.render_widget(block, area);
|
|
|
|
|
2020-04-13 23:04:07 +00:00
|
|
|
let label = format!("{:.2}%", app.progress * 100.0);
|
2019-12-15 20:38:18 +00:00
|
|
|
let gauge = Gauge::default()
|
2018-08-12 17:44:52 +00:00
|
|
|
.block(Block::default().title("Gauge:"))
|
2020-07-11 17:08:28 +00:00
|
|
|
.gauge_style(
|
2018-08-12 17:44:52 +00:00
|
|
|
Style::default()
|
|
|
|
.fg(Color::Magenta)
|
|
|
|
.bg(Color::Black)
|
2020-07-11 17:08:28 +00:00
|
|
|
.add_modifier(Modifier::ITALIC | Modifier::BOLD),
|
2018-12-07 15:17:33 +00:00
|
|
|
)
|
2023-06-11 14:23:23 +00:00
|
|
|
.use_unicode(app.enhanced_graphics)
|
2020-05-10 13:44:30 +00:00
|
|
|
.label(label)
|
2020-04-13 23:04:07 +00:00
|
|
|
.ratio(app.progress);
|
2019-12-15 20:38:18 +00:00
|
|
|
f.render_widget(gauge, chunks[0]);
|
|
|
|
|
|
|
|
let sparkline = Sparkline::default()
|
2018-08-12 17:44:52 +00:00
|
|
|
.block(Block::default().title("Sparkline:"))
|
|
|
|
.style(Style::default().fg(Color::Green))
|
2020-04-13 23:04:07 +00:00
|
|
|
.data(&app.sparkline.points)
|
|
|
|
.bar_set(if app.enhanced_graphics {
|
|
|
|
symbols::bar::NINE_LEVELS
|
|
|
|
} else {
|
|
|
|
symbols::bar::THREE_LEVELS
|
|
|
|
});
|
2019-12-15 20:38:18 +00:00
|
|
|
f.render_widget(sparkline, chunks[1]);
|
2020-09-27 22:28:26 +00:00
|
|
|
|
|
|
|
let line_gauge = LineGauge::default()
|
|
|
|
.block(Block::default().title("LineGauge:"))
|
|
|
|
.gauge_style(Style::default().fg(Color::Magenta))
|
|
|
|
.line_set(if app.enhanced_graphics {
|
|
|
|
symbols::line::THICK
|
|
|
|
} else {
|
|
|
|
symbols::line::NORMAL
|
|
|
|
})
|
|
|
|
.ratio(app.progress);
|
|
|
|
f.render_widget(line_gauge, chunks[2]);
|
2017-05-21 09:13:24 +00:00
|
|
|
}
|
|
|
|
|
2023-09-26 05:30:36 +00:00
|
|
|
fn draw_charts(f: &mut Frame, app: &mut App, area: Rect) {
|
2018-08-12 17:44:52 +00:00
|
|
|
let constraints = if app.show_chart {
|
|
|
|
vec![Constraint::Percentage(50), Constraint::Percentage(50)]
|
2017-05-21 09:13:24 +00:00
|
|
|
} else {
|
2018-08-12 17:44:52 +00:00
|
|
|
vec![Constraint::Percentage(100)]
|
2017-05-21 09:13:24 +00:00
|
|
|
};
|
2024-01-05 15:45:14 +00:00
|
|
|
let chunks = Layout::horizontal(constraints).split(area);
|
2018-08-12 17:44:52 +00:00
|
|
|
{
|
2024-01-05 15:45:14 +00:00
|
|
|
let chunks = Layout::vertical([Constraint::Percentage(50), Constraint::Percentage(50)])
|
2018-08-12 22:27:56 +00:00
|
|
|
.split(chunks[0]);
|
2018-08-12 17:44:52 +00:00
|
|
|
{
|
2024-01-05 15:45:14 +00:00
|
|
|
let chunks =
|
|
|
|
Layout::horizontal([Constraint::Percentage(50), Constraint::Percentage(50)])
|
|
|
|
.split(chunks[0]);
|
2019-12-15 20:38:18 +00:00
|
|
|
|
|
|
|
// Draw tasks
|
2020-05-10 13:44:30 +00:00
|
|
|
let tasks: Vec<ListItem> = app
|
|
|
|
.tasks
|
|
|
|
.items
|
|
|
|
.iter()
|
2023-07-16 09:11:59 +00:00
|
|
|
.map(|i| ListItem::new(vec![text::Line::from(Span::raw(*i))]))
|
2020-05-10 13:44:30 +00:00
|
|
|
.collect();
|
2019-12-15 20:38:18 +00:00
|
|
|
let tasks = List::new(tasks)
|
2018-08-12 17:44:52 +00:00
|
|
|
.block(Block::default().borders(Borders::ALL).title("List"))
|
2020-07-11 17:08:28 +00:00
|
|
|
.highlight_style(Style::default().add_modifier(Modifier::BOLD))
|
2020-04-14 16:02:48 +00:00
|
|
|
.highlight_symbol("> ");
|
2019-12-15 20:38:18 +00:00
|
|
|
f.render_stateful_widget(tasks, chunks[0], &mut app.tasks.state);
|
|
|
|
|
|
|
|
// Draw logs
|
2020-07-11 17:08:28 +00:00
|
|
|
let info_style = Style::default().fg(Color::Blue);
|
|
|
|
let warning_style = Style::default().fg(Color::Yellow);
|
|
|
|
let error_style = Style::default().fg(Color::Magenta);
|
|
|
|
let critical_style = Style::default().fg(Color::Red);
|
2020-05-10 13:44:30 +00:00
|
|
|
let logs: Vec<ListItem> = app
|
|
|
|
.logs
|
|
|
|
.items
|
|
|
|
.iter()
|
|
|
|
.map(|&(evt, level)| {
|
|
|
|
let s = match level {
|
2018-09-07 20:24:52 +00:00
|
|
|
"ERROR" => error_style,
|
|
|
|
"CRITICAL" => critical_style,
|
|
|
|
"WARNING" => warning_style,
|
|
|
|
_ => info_style,
|
2020-05-10 13:44:30 +00:00
|
|
|
};
|
2023-07-16 09:11:59 +00:00
|
|
|
let content = vec![text::Line::from(vec![
|
2023-05-22 03:46:02 +00:00
|
|
|
Span::styled(format!("{level:<9}"), s),
|
2020-05-10 13:44:30 +00:00
|
|
|
Span::raw(evt),
|
|
|
|
])];
|
|
|
|
ListItem::new(content)
|
|
|
|
})
|
|
|
|
.collect();
|
2019-12-15 20:38:18 +00:00
|
|
|
let logs = List::new(logs).block(Block::default().borders(Borders::ALL).title("List"));
|
|
|
|
f.render_stateful_widget(logs, chunks[1], &mut app.logs.state);
|
2018-08-12 17:44:52 +00:00
|
|
|
}
|
2019-12-15 20:38:18 +00:00
|
|
|
|
|
|
|
let barchart = BarChart::default()
|
2018-08-12 17:44:52 +00:00
|
|
|
.block(Block::default().borders(Borders::ALL).title("Bar chart"))
|
2019-02-10 21:35:44 +00:00
|
|
|
.data(&app.barchart)
|
2018-08-12 17:44:52 +00:00
|
|
|
.bar_width(3)
|
|
|
|
.bar_gap(2)
|
2020-04-13 23:04:07 +00:00
|
|
|
.bar_set(if app.enhanced_graphics {
|
|
|
|
symbols::bar::NINE_LEVELS
|
|
|
|
} else {
|
|
|
|
symbols::bar::THREE_LEVELS
|
|
|
|
})
|
2018-08-12 17:44:52 +00:00
|
|
|
.value_style(
|
|
|
|
Style::default()
|
|
|
|
.fg(Color::Black)
|
|
|
|
.bg(Color::Green)
|
2020-07-11 17:08:28 +00:00
|
|
|
.add_modifier(Modifier::ITALIC),
|
2018-12-07 15:17:33 +00:00
|
|
|
)
|
|
|
|
.label_style(Style::default().fg(Color::Yellow))
|
2020-07-11 17:08:28 +00:00
|
|
|
.bar_style(Style::default().fg(Color::Green));
|
2019-12-15 20:38:18 +00:00
|
|
|
f.render_widget(barchart, chunks[1]);
|
2018-08-12 17:44:52 +00:00
|
|
|
}
|
|
|
|
if app.show_chart {
|
2020-05-10 13:44:30 +00:00
|
|
|
let x_labels = vec![
|
|
|
|
Span::styled(
|
|
|
|
format!("{}", app.signals.window[0]),
|
2020-07-11 17:08:28 +00:00
|
|
|
Style::default().add_modifier(Modifier::BOLD),
|
2020-05-10 13:44:30 +00:00
|
|
|
),
|
|
|
|
Span::raw(format!(
|
|
|
|
"{}",
|
|
|
|
(app.signals.window[0] + app.signals.window[1]) / 2.0
|
|
|
|
)),
|
|
|
|
Span::styled(
|
|
|
|
format!("{}", app.signals.window[1]),
|
2020-07-11 17:08:28 +00:00
|
|
|
Style::default().add_modifier(Modifier::BOLD),
|
2020-05-10 13:44:30 +00:00
|
|
|
),
|
2019-12-15 20:38:18 +00:00
|
|
|
];
|
2020-05-10 13:44:30 +00:00
|
|
|
let datasets = vec![
|
2019-12-15 20:38:18 +00:00
|
|
|
Dataset::default()
|
|
|
|
.name("data2")
|
2020-04-13 23:04:07 +00:00
|
|
|
.marker(symbols::Marker::Dot)
|
2019-12-15 20:38:18 +00:00
|
|
|
.style(Style::default().fg(Color::Cyan))
|
|
|
|
.data(&app.signals.sin1.points),
|
|
|
|
Dataset::default()
|
|
|
|
.name("data3")
|
2020-04-13 23:04:07 +00:00
|
|
|
.marker(if app.enhanced_graphics {
|
|
|
|
symbols::Marker::Braille
|
|
|
|
} else {
|
|
|
|
symbols::Marker::Dot
|
|
|
|
})
|
2019-12-15 20:38:18 +00:00
|
|
|
.style(Style::default().fg(Color::Yellow))
|
|
|
|
.data(&app.signals.sin2.points),
|
|
|
|
];
|
2020-05-10 13:44:30 +00:00
|
|
|
let chart = Chart::new(datasets)
|
2018-08-12 17:44:52 +00:00
|
|
|
.block(
|
|
|
|
Block::default()
|
2020-05-10 13:44:30 +00:00
|
|
|
.title(Span::styled(
|
|
|
|
"Chart",
|
2020-07-11 17:08:28 +00:00
|
|
|
Style::default()
|
2020-05-10 13:44:30 +00:00
|
|
|
.fg(Color::Cyan)
|
2020-07-11 17:08:28 +00:00
|
|
|
.add_modifier(Modifier::BOLD),
|
2020-05-10 13:44:30 +00:00
|
|
|
))
|
2018-08-12 17:44:52 +00:00
|
|
|
.borders(Borders::ALL),
|
2018-12-07 15:17:33 +00:00
|
|
|
)
|
|
|
|
.x_axis(
|
2018-08-12 17:44:52 +00:00
|
|
|
Axis::default()
|
|
|
|
.title("X Axis")
|
|
|
|
.style(Style::default().fg(Color::Gray))
|
2019-02-10 21:35:44 +00:00
|
|
|
.bounds(app.signals.window)
|
2020-05-10 13:44:30 +00:00
|
|
|
.labels(x_labels),
|
2018-12-07 15:17:33 +00:00
|
|
|
)
|
|
|
|
.y_axis(
|
2018-08-12 17:44:52 +00:00
|
|
|
Axis::default()
|
|
|
|
.title("Y Axis")
|
|
|
|
.style(Style::default().fg(Color::Gray))
|
|
|
|
.bounds([-20.0, 20.0])
|
2020-05-10 13:44:30 +00:00
|
|
|
.labels(vec![
|
2020-07-11 17:08:28 +00:00
|
|
|
Span::styled("-20", Style::default().add_modifier(Modifier::BOLD)),
|
2020-05-10 13:44:30 +00:00
|
|
|
Span::raw("0"),
|
2020-07-11 17:08:28 +00:00
|
|
|
Span::styled("20", Style::default().add_modifier(Modifier::BOLD)),
|
2020-05-10 13:44:30 +00:00
|
|
|
]),
|
|
|
|
);
|
2019-12-15 20:38:18 +00:00
|
|
|
f.render_widget(chart, chunks[1]);
|
2018-08-12 17:44:52 +00:00
|
|
|
}
|
2016-10-09 17:46:53 +00:00
|
|
|
}
|
2016-11-07 14:57:46 +00:00
|
|
|
|
2023-09-26 05:30:36 +00:00
|
|
|
fn draw_text(f: &mut Frame, area: Rect) {
|
2020-05-10 13:44:30 +00:00
|
|
|
let text = vec![
|
2023-07-16 09:11:59 +00:00
|
|
|
text::Line::from("This is a paragraph with several lines. You can change style your text the way you want"),
|
|
|
|
text::Line::from(""),
|
|
|
|
text::Line::from(vec![
|
2020-05-10 13:44:30 +00:00
|
|
|
Span::from("For example: "),
|
2020-07-11 17:08:28 +00:00
|
|
|
Span::styled("under", Style::default().fg(Color::Red)),
|
2020-05-10 13:44:30 +00:00
|
|
|
Span::raw(" "),
|
2020-07-11 17:08:28 +00:00
|
|
|
Span::styled("the", Style::default().fg(Color::Green)),
|
2020-05-10 13:44:30 +00:00
|
|
|
Span::raw(" "),
|
2020-07-11 17:08:28 +00:00
|
|
|
Span::styled("rainbow", Style::default().fg(Color::Blue)),
|
2020-05-10 13:44:30 +00:00
|
|
|
Span::raw("."),
|
|
|
|
]),
|
2023-07-16 09:11:59 +00:00
|
|
|
text::Line::from(vec![
|
2020-05-10 13:44:30 +00:00
|
|
|
Span::raw("Oh and if you didn't "),
|
2020-07-11 17:08:28 +00:00
|
|
|
Span::styled("notice", Style::default().add_modifier(Modifier::ITALIC)),
|
2020-05-10 13:44:30 +00:00
|
|
|
Span::raw(" you can "),
|
2020-07-11 17:08:28 +00:00
|
|
|
Span::styled("automatically", Style::default().add_modifier(Modifier::BOLD)),
|
2020-05-10 13:44:30 +00:00
|
|
|
Span::raw(" "),
|
2020-07-11 17:08:28 +00:00
|
|
|
Span::styled("wrap", Style::default().add_modifier(Modifier::REVERSED)),
|
2020-05-10 13:44:30 +00:00
|
|
|
Span::raw(" your "),
|
2020-07-11 17:08:28 +00:00
|
|
|
Span::styled("text", Style::default().add_modifier(Modifier::UNDERLINED)),
|
2020-05-10 13:44:30 +00:00
|
|
|
Span::raw(".")
|
|
|
|
]),
|
2023-07-16 09:11:59 +00:00
|
|
|
text::Line::from(
|
2020-05-10 13:44:30 +00:00
|
|
|
"One more thing is that it should display unicode characters: 10€"
|
|
|
|
),
|
2018-08-12 20:13:32 +00:00
|
|
|
];
|
2020-05-10 13:44:30 +00:00
|
|
|
let block = Block::default().borders(Borders::ALL).title(Span::styled(
|
|
|
|
"Footer",
|
2020-07-11 17:08:28 +00:00
|
|
|
Style::default()
|
2020-05-10 13:44:30 +00:00
|
|
|
.fg(Color::Magenta)
|
2020-07-11 17:08:28 +00:00
|
|
|
.add_modifier(Modifier::BOLD),
|
2020-05-10 13:44:30 +00:00
|
|
|
));
|
|
|
|
let paragraph = Paragraph::new(text).block(block).wrap(Wrap { trim: true });
|
2019-12-15 20:38:18 +00:00
|
|
|
f.render_widget(paragraph, area);
|
2017-05-21 09:13:24 +00:00
|
|
|
}
|
|
|
|
|
2023-09-26 05:30:36 +00:00
|
|
|
fn draw_second_tab(f: &mut Frame, app: &mut App, area: Rect) {
|
2024-01-05 15:45:14 +00:00
|
|
|
let chunks =
|
|
|
|
Layout::horizontal([Constraint::Percentage(30), Constraint::Percentage(70)]).split(area);
|
2018-08-12 17:44:52 +00:00
|
|
|
let up_style = Style::default().fg(Color::Green);
|
2019-03-10 16:43:56 +00:00
|
|
|
let failure_style = Style::default()
|
|
|
|
.fg(Color::Red)
|
2020-07-11 17:08:28 +00:00
|
|
|
.add_modifier(Modifier::RAPID_BLINK | Modifier::CROSSED_OUT);
|
2018-09-23 18:59:51 +00:00
|
|
|
let rows = app.servers.iter().map(|s| {
|
|
|
|
let style = if s.status == "Up" {
|
|
|
|
up_style
|
|
|
|
} else {
|
|
|
|
failure_style
|
|
|
|
};
|
2020-11-15 21:47:00 +00:00
|
|
|
Row::new(vec![s.name, s.location, s.status]).style(style)
|
2018-09-23 18:59:51 +00:00
|
|
|
});
|
2023-12-04 23:22:52 +00:00
|
|
|
let table = Table::new(
|
|
|
|
rows,
|
|
|
|
[
|
2019-07-10 10:39:10 +00:00
|
|
|
Constraint::Length(15),
|
|
|
|
Constraint::Length(15),
|
|
|
|
Constraint::Length(10),
|
2023-12-04 23:22:52 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
.header(
|
|
|
|
Row::new(vec!["Server", "Location", "Status"])
|
|
|
|
.style(Style::default().fg(Color::Yellow))
|
|
|
|
.bottom_margin(1),
|
|
|
|
)
|
|
|
|
.block(Block::default().title("Servers").borders(Borders::ALL));
|
2019-12-15 20:38:18 +00:00
|
|
|
f.render_widget(table, chunks[0]);
|
2016-11-07 14:57:46 +00:00
|
|
|
|
2019-12-15 20:38:18 +00:00
|
|
|
let map = Canvas::default()
|
2018-08-12 17:44:52 +00:00
|
|
|
.block(Block::default().title("World").borders(Borders::ALL))
|
|
|
|
.paint(|ctx| {
|
|
|
|
ctx.draw(&Map {
|
|
|
|
color: Color::White,
|
|
|
|
resolution: MapResolution::High,
|
|
|
|
});
|
|
|
|
ctx.layer();
|
2019-01-14 20:14:57 +00:00
|
|
|
ctx.draw(&Rectangle {
|
2020-03-03 08:27:28 +00:00
|
|
|
x: 0.0,
|
|
|
|
y: 30.0,
|
|
|
|
width: 10.0,
|
|
|
|
height: 10.0,
|
2019-01-14 20:14:57 +00:00
|
|
|
color: Color::Yellow,
|
|
|
|
});
|
2023-05-09 17:56:35 +00:00
|
|
|
ctx.draw(&Circle {
|
|
|
|
x: app.servers[2].coords.1,
|
|
|
|
y: app.servers[2].coords.0,
|
|
|
|
radius: 10.0,
|
|
|
|
color: Color::Green,
|
|
|
|
});
|
2018-08-12 17:44:52 +00:00
|
|
|
for (i, s1) in app.servers.iter().enumerate() {
|
|
|
|
for s2 in &app.servers[i + 1..] {
|
2023-07-16 09:11:59 +00:00
|
|
|
ctx.draw(&canvas::Line {
|
2018-08-12 17:44:52 +00:00
|
|
|
x1: s1.coords.1,
|
|
|
|
y1: s1.coords.0,
|
|
|
|
y2: s2.coords.0,
|
|
|
|
x2: s2.coords.1,
|
|
|
|
color: Color::Yellow,
|
2017-09-10 21:03:27 +00:00
|
|
|
});
|
2018-08-12 17:44:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for server in &app.servers {
|
|
|
|
let color = if server.status == "Up" {
|
|
|
|
Color::Green
|
|
|
|
} else {
|
|
|
|
Color::Red
|
|
|
|
};
|
2021-10-17 16:44:00 +00:00
|
|
|
ctx.print(
|
|
|
|
server.coords.1,
|
|
|
|
server.coords.0,
|
|
|
|
Span::styled("X", Style::default().fg(color)),
|
|
|
|
);
|
2018-08-12 17:44:52 +00:00
|
|
|
}
|
2018-12-07 15:17:33 +00:00
|
|
|
})
|
2020-04-13 23:04:07 +00:00
|
|
|
.marker(if app.enhanced_graphics {
|
|
|
|
symbols::Marker::Braille
|
|
|
|
} else {
|
|
|
|
symbols::Marker::Dot
|
|
|
|
})
|
2018-12-07 15:17:33 +00:00
|
|
|
.x_bounds([-180.0, 180.0])
|
2019-12-15 20:38:18 +00:00
|
|
|
.y_bounds([-90.0, 90.0]);
|
|
|
|
f.render_widget(map, chunks[1]);
|
2016-11-07 14:57:46 +00:00
|
|
|
}
|
2021-01-01 14:29:04 +00:00
|
|
|
|
2023-09-26 05:30:36 +00:00
|
|
|
fn draw_third_tab(f: &mut Frame, _app: &mut App, area: Rect) {
|
2024-01-05 15:45:14 +00:00
|
|
|
let chunks = Layout::horizontal([Constraint::Ratio(1, 2), Constraint::Ratio(1, 2)]).split(area);
|
2021-01-01 14:29:04 +00:00
|
|
|
let colors = [
|
|
|
|
Color::Reset,
|
|
|
|
Color::Black,
|
|
|
|
Color::Red,
|
|
|
|
Color::Green,
|
|
|
|
Color::Yellow,
|
|
|
|
Color::Blue,
|
|
|
|
Color::Magenta,
|
|
|
|
Color::Cyan,
|
|
|
|
Color::Gray,
|
|
|
|
Color::DarkGray,
|
|
|
|
Color::LightRed,
|
|
|
|
Color::LightGreen,
|
|
|
|
Color::LightYellow,
|
|
|
|
Color::LightBlue,
|
|
|
|
Color::LightMagenta,
|
|
|
|
Color::LightCyan,
|
|
|
|
Color::White,
|
|
|
|
];
|
|
|
|
let items: Vec<Row> = colors
|
|
|
|
.iter()
|
|
|
|
.map(|c| {
|
|
|
|
let cells = vec![
|
2023-05-22 03:46:02 +00:00
|
|
|
Cell::from(Span::raw(format!("{c:?}: "))),
|
2021-01-01 14:29:04 +00:00
|
|
|
Cell::from(Span::styled("Foreground", Style::default().fg(*c))),
|
|
|
|
Cell::from(Span::styled("Background", Style::default().bg(*c))),
|
|
|
|
];
|
|
|
|
Row::new(cells)
|
|
|
|
})
|
|
|
|
.collect();
|
2023-12-04 23:22:52 +00:00
|
|
|
let table = Table::new(
|
|
|
|
items,
|
|
|
|
[
|
2021-01-01 14:29:04 +00:00
|
|
|
Constraint::Ratio(1, 3),
|
|
|
|
Constraint::Ratio(1, 3),
|
|
|
|
Constraint::Ratio(1, 3),
|
2023-12-04 23:22:52 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
.block(Block::default().title("Colors").borders(Borders::ALL));
|
2021-01-01 14:29:04 +00:00
|
|
|
f.render_widget(table, chunks[0]);
|
|
|
|
}
|