2016-10-09 17:46:53 +00:00
|
|
|
extern crate tui;
|
2016-10-11 17:54:35 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
|
|
|
extern crate log4rs;
|
2016-10-09 17:46:53 +00:00
|
|
|
extern crate termion;
|
2016-10-12 17:43:39 +00:00
|
|
|
extern crate rand;
|
2016-10-09 17:46:53 +00:00
|
|
|
|
|
|
|
use std::thread;
|
2016-10-12 14:12:42 +00:00
|
|
|
use std::time;
|
2016-10-09 17:46:53 +00:00
|
|
|
use std::sync::mpsc;
|
2016-10-12 17:43:39 +00:00
|
|
|
use std::io::stdin;
|
2016-10-14 17:44:52 +00:00
|
|
|
|
|
|
|
use rand::distributions::{IndependentSample, Range};
|
2016-10-09 17:46:53 +00:00
|
|
|
|
|
|
|
use termion::event;
|
|
|
|
use termion::input::TermRead;
|
|
|
|
|
2016-10-11 17:54:35 +00:00
|
|
|
use log::LogLevelFilter;
|
|
|
|
use log4rs::append::file::FileAppender;
|
|
|
|
use log4rs::encode::pattern::PatternEncoder;
|
2016-10-20 15:17:35 +00:00
|
|
|
use log4rs::config::{Appender, Config, Root};
|
2016-10-11 17:54:35 +00:00
|
|
|
|
2016-10-09 17:46:53 +00:00
|
|
|
use tui::Terminal;
|
2016-10-22 10:51:41 +00:00
|
|
|
use tui::widgets::{Widget, Block, List, Gauge, Sparkline, Text, border, Chart, Axis, Dataset,
|
2016-11-01 14:59:33 +00:00
|
|
|
BarChart, Marker, Tabs, Table};
|
|
|
|
use tui::widgets::canvas::{Canvas, Line, Map, MapResolution};
|
2016-10-26 12:32:45 +00:00
|
|
|
use tui::layout::{Group, Direction, Size, Rect};
|
2016-10-13 15:30:18 +00:00
|
|
|
use tui::style::Color;
|
2016-10-09 17:46:53 +00:00
|
|
|
|
2016-10-14 17:44:52 +00:00
|
|
|
#[derive(Clone)]
|
|
|
|
struct RandomSignal {
|
|
|
|
range: Range<u64>,
|
|
|
|
rng: rand::ThreadRng,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RandomSignal {
|
|
|
|
fn new(r: Range<u64>) -> RandomSignal {
|
|
|
|
RandomSignal {
|
|
|
|
range: r,
|
|
|
|
rng: rand::thread_rng(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Iterator for RandomSignal {
|
|
|
|
type Item = u64;
|
|
|
|
fn next(&mut self) -> Option<u64> {
|
|
|
|
Some(self.range.ind_sample(&mut self.rng))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
struct SinSignal {
|
|
|
|
x: f64,
|
2016-10-27 10:35:56 +00:00
|
|
|
interval: f64,
|
2016-10-14 17:44:52 +00:00
|
|
|
period: f64,
|
|
|
|
scale: f64,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SinSignal {
|
2016-10-27 10:35:56 +00:00
|
|
|
fn new(interval: f64, period: f64, scale: f64) -> SinSignal {
|
2016-10-14 17:44:52 +00:00
|
|
|
SinSignal {
|
|
|
|
x: 0.0,
|
2016-10-27 10:35:56 +00:00
|
|
|
interval: interval,
|
2016-10-14 17:44:52 +00:00
|
|
|
period: period,
|
|
|
|
scale: scale,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Iterator for SinSignal {
|
2016-10-20 10:01:09 +00:00
|
|
|
type Item = (f64, f64);
|
|
|
|
fn next(&mut self) -> Option<(f64, f64)> {
|
2016-10-27 10:35:56 +00:00
|
|
|
self.x += self.interval;
|
2016-10-20 10:01:09 +00:00
|
|
|
Some((self.x, ((self.x * 1.0 / self.period).sin() + 1.0) * self.scale))
|
2016-10-14 17:44:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-27 17:37:06 +00:00
|
|
|
struct MyTabs {
|
|
|
|
titles: [&'static str; 2],
|
|
|
|
selection: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MyTabs {
|
|
|
|
fn next(&mut self) {
|
|
|
|
self.selection = (self.selection + 1) % self.titles.len();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn previous(&mut self) {
|
|
|
|
if self.selection > 0 {
|
|
|
|
self.selection -= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-22 09:26:46 +00:00
|
|
|
struct App<'a> {
|
2016-10-26 12:32:45 +00:00
|
|
|
size: Rect,
|
2016-10-22 09:26:46 +00:00
|
|
|
items: Vec<&'a str>,
|
|
|
|
items2: Vec<&'a str>,
|
2016-10-11 17:54:35 +00:00
|
|
|
selected: usize,
|
2016-10-27 17:37:06 +00:00
|
|
|
tabs: MyTabs,
|
2016-10-14 17:44:52 +00:00
|
|
|
show_chart: bool,
|
2016-10-12 14:12:42 +00:00
|
|
|
progress: u16,
|
2016-10-12 17:43:39 +00:00
|
|
|
data: Vec<u64>,
|
2016-10-20 10:01:09 +00:00
|
|
|
data2: Vec<(f64, f64)>,
|
2016-10-20 14:26:34 +00:00
|
|
|
data3: Vec<(f64, f64)>,
|
2016-10-22 10:51:41 +00:00
|
|
|
data4: Vec<(&'a str, u64)>,
|
2016-10-21 17:02:19 +00:00
|
|
|
window: [f64; 2],
|
2016-10-14 17:44:52 +00:00
|
|
|
colors: [Color; 2],
|
|
|
|
color_index: usize,
|
2016-10-09 17:46:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum Event {
|
2016-10-11 17:54:35 +00:00
|
|
|
Input(event::Key),
|
2016-10-12 14:12:42 +00:00
|
|
|
Tick,
|
2016-10-09 17:46:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
2016-10-11 17:54:35 +00:00
|
|
|
let log = FileAppender::builder()
|
2016-10-12 14:12:42 +00:00
|
|
|
.encoder(Box::new(PatternEncoder::new("{l} / {d(%H:%M:%S)} / {M}:{L}{n}{m}{n}{n}")))
|
2016-10-11 17:54:35 +00:00
|
|
|
.build("prototype.log")
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let config = Config::builder()
|
|
|
|
.appender(Appender::builder().build("log", Box::new(log)))
|
2016-10-12 14:12:42 +00:00
|
|
|
.build(Root::builder().appender("log").build(LogLevelFilter::Debug))
|
2016-10-11 17:54:35 +00:00
|
|
|
.unwrap();
|
|
|
|
|
2016-10-20 15:17:35 +00:00
|
|
|
log4rs::init_config(config).unwrap();
|
2016-10-11 17:54:35 +00:00
|
|
|
info!("Start");
|
|
|
|
|
2016-10-14 17:44:52 +00:00
|
|
|
let mut rand_signal = RandomSignal::new(Range::new(0, 100));
|
2016-10-27 10:35:56 +00:00
|
|
|
let mut sin_signal = SinSignal::new(1.0, 4.0, 20.0);
|
|
|
|
let mut sin_signal2 = SinSignal::new(0.1, 2.0, 10.0);
|
2016-10-14 17:44:52 +00:00
|
|
|
|
2016-10-09 17:46:53 +00:00
|
|
|
let mut app = App {
|
2016-10-26 12:32:45 +00:00
|
|
|
size: Rect::default(),
|
2016-10-22 09:26:46 +00:00
|
|
|
items: vec!["Item1", "Item2", "Item3", "Item4", "Item5", "Item6", "Item7", "Item8",
|
|
|
|
"Item9", "Item10"],
|
|
|
|
items2: vec!["Event1", "Event2", "Event3", "Event4", "Event5", "Event6", "Event7",
|
|
|
|
"Event8", "Event9", "Event10", "Event11", "Event12", "Event13", "Event14",
|
2016-10-26 12:32:45 +00:00
|
|
|
"Event15", "Event16", "Event17", "Event18", "Event19"],
|
2016-10-11 17:54:35 +00:00
|
|
|
selected: 0,
|
2016-10-27 17:37:06 +00:00
|
|
|
tabs: MyTabs {
|
|
|
|
titles: ["Main", "Map"],
|
|
|
|
selection: 0,
|
|
|
|
},
|
2016-10-14 17:44:52 +00:00
|
|
|
show_chart: true,
|
2016-10-12 14:12:42 +00:00
|
|
|
progress: 0,
|
2016-10-21 17:02:19 +00:00
|
|
|
data: rand_signal.clone().take(200).collect(),
|
2016-11-01 21:54:16 +00:00
|
|
|
data2: sin_signal.clone().take(30).collect(),
|
2016-10-27 10:35:56 +00:00
|
|
|
data3: sin_signal2.clone().take(200).collect(),
|
2016-10-22 10:51:41 +00:00
|
|
|
data4: vec![("B1", 9),
|
|
|
|
("B2", 12),
|
|
|
|
("B3", 5),
|
|
|
|
("B4", 8),
|
|
|
|
("B5", 2),
|
|
|
|
("B6", 4),
|
|
|
|
("B7", 5),
|
|
|
|
("B8", 9),
|
|
|
|
("B9", 14),
|
|
|
|
("B10", 15),
|
|
|
|
("B11", 1),
|
2016-10-26 12:32:45 +00:00
|
|
|
("B12", 0),
|
|
|
|
("B13", 4),
|
|
|
|
("B14", 6),
|
|
|
|
("B15", 4)],
|
2016-10-21 17:02:19 +00:00
|
|
|
window: [0.0, 20.0],
|
2016-10-14 17:44:52 +00:00
|
|
|
colors: [Color::Magenta, Color::Red],
|
|
|
|
color_index: 0,
|
2016-10-09 17:46:53 +00:00
|
|
|
};
|
|
|
|
let (tx, rx) = mpsc::channel();
|
2016-10-12 14:12:42 +00:00
|
|
|
let input_tx = tx.clone();
|
2016-10-09 17:46:53 +00:00
|
|
|
|
2016-11-01 21:54:16 +00:00
|
|
|
for _ in 0..30 {
|
2016-10-21 17:02:19 +00:00
|
|
|
sin_signal.next();
|
2016-10-27 10:35:56 +00:00
|
|
|
}
|
|
|
|
for _ in 0..200 {
|
2016-10-21 17:02:19 +00:00
|
|
|
sin_signal2.next();
|
|
|
|
}
|
|
|
|
|
2016-10-09 17:46:53 +00:00
|
|
|
thread::spawn(move || {
|
|
|
|
let stdin = stdin();
|
|
|
|
for c in stdin.keys() {
|
|
|
|
let evt = c.unwrap();
|
2016-10-12 14:12:42 +00:00
|
|
|
input_tx.send(Event::Input(evt)).unwrap();
|
2016-10-11 17:54:35 +00:00
|
|
|
if evt == event::Key::Char('q') {
|
|
|
|
break;
|
2016-10-09 17:46:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2016-10-11 17:54:35 +00:00
|
|
|
|
2016-10-12 14:12:42 +00:00
|
|
|
thread::spawn(move || {
|
|
|
|
let tx = tx.clone();
|
|
|
|
loop {
|
|
|
|
tx.send(Event::Tick).unwrap();
|
2016-10-26 17:19:46 +00:00
|
|
|
thread::sleep(time::Duration::from_millis(1000));
|
2016-10-12 14:12:42 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-10-09 17:46:53 +00:00
|
|
|
let mut terminal = Terminal::new().unwrap();
|
|
|
|
terminal.clear();
|
|
|
|
terminal.hide_cursor();
|
2016-10-11 17:54:35 +00:00
|
|
|
|
2016-10-09 17:46:53 +00:00
|
|
|
loop {
|
2016-10-26 12:32:45 +00:00
|
|
|
let size = Terminal::size().unwrap();
|
|
|
|
if size != app.size {
|
|
|
|
terminal.resize(size);
|
|
|
|
app.size = size;
|
|
|
|
}
|
2016-10-09 17:46:53 +00:00
|
|
|
draw(&mut terminal, &app);
|
|
|
|
let evt = rx.recv().unwrap();
|
|
|
|
match evt {
|
2016-10-11 17:54:35 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2016-10-27 17:37:06 +00:00
|
|
|
event::Key::Left => {
|
|
|
|
app.tabs.previous();
|
|
|
|
}
|
|
|
|
event::Key::Right => {
|
|
|
|
app.tabs.next();
|
|
|
|
}
|
2016-10-12 09:36:39 +00:00
|
|
|
event::Key::Char('t') => {
|
2016-10-14 17:44:52 +00:00
|
|
|
app.show_chart = !app.show_chart;
|
2016-10-12 09:36:39 +00:00
|
|
|
}
|
2016-10-11 17:54:35 +00:00
|
|
|
_ => {}
|
|
|
|
}
|
2016-10-09 17:46:53 +00:00
|
|
|
}
|
2016-10-12 14:12:42 +00:00
|
|
|
Event::Tick => {
|
|
|
|
app.progress += 5;
|
|
|
|
if app.progress > 100 {
|
|
|
|
app.progress = 0;
|
|
|
|
}
|
2016-10-14 17:44:52 +00:00
|
|
|
app.data.insert(0, rand_signal.next().unwrap());
|
2016-10-12 17:43:39 +00:00
|
|
|
app.data.pop();
|
2016-10-14 17:44:52 +00:00
|
|
|
app.data2.remove(0);
|
2016-10-20 10:01:09 +00:00
|
|
|
app.data2.push(sin_signal.next().unwrap());
|
2016-10-27 10:35:56 +00:00
|
|
|
for _ in 0..10 {
|
|
|
|
app.data3.remove(0);
|
|
|
|
}
|
|
|
|
for _ in 0..10 {
|
|
|
|
app.data3.push(sin_signal2.next().unwrap());
|
|
|
|
}
|
2016-10-22 10:51:41 +00:00
|
|
|
let i = app.data4.pop().unwrap();
|
|
|
|
app.data4.insert(0, i);
|
2016-10-21 17:02:19 +00:00
|
|
|
app.window[0] += 1.0;
|
|
|
|
app.window[1] += 1.0;
|
2016-10-22 09:26:46 +00:00
|
|
|
let i = app.items2.pop().unwrap();
|
|
|
|
app.items2.insert(0, i);
|
2016-10-14 17:44:52 +00:00
|
|
|
app.color_index += 1;
|
|
|
|
if app.color_index >= app.colors.len() {
|
|
|
|
app.color_index = 0;
|
|
|
|
}
|
2016-10-12 14:12:42 +00:00
|
|
|
}
|
2016-10-09 17:46:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
terminal.show_cursor();
|
|
|
|
}
|
|
|
|
|
2016-10-15 22:38:20 +00:00
|
|
|
fn draw(t: &mut Terminal, app: &App) {
|
2016-10-09 17:46:53 +00:00
|
|
|
|
2016-10-27 17:37:06 +00:00
|
|
|
Group::default()
|
|
|
|
.direction(Direction::Vertical)
|
|
|
|
.sizes(&[Size::Fixed(3), Size::Min(0)])
|
|
|
|
.render(t, &app.size, |t, chunks| {
|
|
|
|
Tabs::default()
|
|
|
|
.block(Block::default().borders(border::ALL).title("Tabs"))
|
|
|
|
.titles(&app.tabs.titles)
|
|
|
|
.highlight_color(Color::Yellow)
|
|
|
|
.select(app.tabs.selection)
|
|
|
|
.render(&chunks[0], t);
|
|
|
|
match app.tabs.selection {
|
|
|
|
0 => {
|
|
|
|
draw_main(t, app, &chunks[1]);
|
|
|
|
}
|
2016-10-27 20:55:24 +00:00
|
|
|
1 => {
|
2016-11-01 14:59:33 +00:00
|
|
|
Group::default()
|
|
|
|
.direction(Direction::Vertical)
|
|
|
|
.sizes(&[Size::Percent(50), Size::Percent(50)])
|
|
|
|
.render(t, &chunks[1], |t, chunks| {
|
|
|
|
Table::default()
|
|
|
|
.block(Block::default().title("Servers").borders(border::ALL))
|
|
|
|
.titles(&["Server", "Location", "Status"])
|
|
|
|
.widths(&[20, 20, 20])
|
|
|
|
.rows(&[&["Europe#1", "Paris", "Up"],
|
|
|
|
&["Europe#2", "Berlin", "Up"]])
|
|
|
|
.render(&chunks[0], t);
|
|
|
|
Canvas::default()
|
|
|
|
.block(Block::default().title("World").borders(border::ALL))
|
|
|
|
.layers(&[&[Map::default().resolution(MapResolution::High)]])
|
2016-11-01 21:54:16 +00:00
|
|
|
.x_bounds([-180.0, 180.0])
|
2016-11-01 14:59:33 +00:00
|
|
|
.y_bounds([-90.0, 90.0])
|
|
|
|
.render(&chunks[1], t);
|
|
|
|
})
|
2016-10-27 20:55:24 +00:00
|
|
|
}
|
2016-10-27 17:37:06 +00:00
|
|
|
_ => {}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
t.finish();
|
|
|
|
}
|
2016-10-20 15:17:35 +00:00
|
|
|
|
2016-10-27 17:37:06 +00:00
|
|
|
fn draw_main(t: &mut Terminal, app: &App, area: &Rect) {
|
2016-10-15 22:38:20 +00:00
|
|
|
Group::default()
|
2016-10-09 17:46:53 +00:00
|
|
|
.direction(Direction::Vertical)
|
2016-10-23 12:14:43 +00:00
|
|
|
.sizes(&[Size::Fixed(7), Size::Min(7), Size::Fixed(7)])
|
2016-10-27 17:37:06 +00:00
|
|
|
.render(t, area, |t, chunks| {
|
|
|
|
Block::default()
|
|
|
|
.borders(border::ALL)
|
|
|
|
.title("Graphs")
|
|
|
|
.render(&chunks[0], t);
|
2016-10-15 22:38:20 +00:00
|
|
|
Group::default()
|
2016-10-12 14:12:42 +00:00
|
|
|
.direction(Direction::Vertical)
|
|
|
|
.margin(1)
|
2016-10-23 12:14:43 +00:00
|
|
|
.sizes(&[Size::Fixed(2), Size::Fixed(3)])
|
2016-10-20 14:26:34 +00:00
|
|
|
.render(t, &chunks[0], |t, chunks| {
|
2016-10-15 22:38:20 +00:00
|
|
|
Gauge::default()
|
2016-10-20 10:01:09 +00:00
|
|
|
.block(Block::default().title("Gauge:"))
|
2016-10-26 12:32:45 +00:00
|
|
|
.color(Color::Magenta)
|
2016-10-12 14:12:42 +00:00
|
|
|
.percent(app.progress)
|
2016-10-15 22:38:20 +00:00
|
|
|
.render(&chunks[0], t);
|
|
|
|
Sparkline::default()
|
2016-10-20 10:01:09 +00:00
|
|
|
.block(Block::default().title("Sparkline:"))
|
2016-10-23 12:14:43 +00:00
|
|
|
.color(Color::Green)
|
2016-10-12 17:43:39 +00:00
|
|
|
.data(&app.data)
|
2016-10-15 22:38:20 +00:00
|
|
|
.render(&chunks[1], t);
|
|
|
|
});
|
2016-10-14 17:44:52 +00:00
|
|
|
let sizes = if app.show_chart {
|
2016-10-23 12:14:43 +00:00
|
|
|
vec![Size::Percent(50), Size::Percent(50)]
|
2016-10-12 09:36:39 +00:00
|
|
|
} else {
|
2016-10-23 12:14:43 +00:00
|
|
|
vec![Size::Percent(100)]
|
2016-10-12 09:36:39 +00:00
|
|
|
};
|
2016-10-15 22:38:20 +00:00
|
|
|
Group::default()
|
2016-10-11 17:54:35 +00:00
|
|
|
.direction(Direction::Horizontal)
|
2016-10-23 12:14:43 +00:00
|
|
|
.sizes(&sizes)
|
2016-10-20 14:26:34 +00:00
|
|
|
.render(t, &chunks[1], |t, chunks| {
|
2016-10-22 09:26:46 +00:00
|
|
|
Group::default()
|
|
|
|
.direction(Direction::Vertical)
|
2016-10-23 12:14:43 +00:00
|
|
|
.sizes(&[Size::Percent(50), Size::Percent(50)])
|
2016-10-22 09:26:46 +00:00
|
|
|
.render(t, &chunks[0], |t, chunks| {
|
|
|
|
Group::default()
|
|
|
|
.direction(Direction::Horizontal)
|
2016-10-23 12:14:43 +00:00
|
|
|
.sizes(&[Size::Percent(50), Size::Percent(50)])
|
2016-10-22 09:26:46 +00:00
|
|
|
.render(t, &chunks[0], |t, chunks| {
|
|
|
|
List::default()
|
2016-10-27 17:37:06 +00:00
|
|
|
.block(Block::default()
|
|
|
|
.borders(border::ALL)
|
|
|
|
.title("List"))
|
2016-10-22 09:26:46 +00:00
|
|
|
.items(&app.items)
|
|
|
|
.select(app.selected)
|
2016-10-26 12:32:45 +00:00
|
|
|
.selection_color(Color::Yellow)
|
2016-10-22 09:26:46 +00:00
|
|
|
.selection_symbol(">")
|
|
|
|
.render(&chunks[0], t);
|
|
|
|
List::default()
|
2016-10-27 17:37:06 +00:00
|
|
|
.block(Block::default()
|
|
|
|
.borders(border::ALL)
|
|
|
|
.title("List"))
|
2016-10-22 09:26:46 +00:00
|
|
|
.items(&app.items2)
|
|
|
|
.render(&chunks[1], t);
|
2016-10-22 10:51:41 +00:00
|
|
|
});
|
|
|
|
BarChart::default()
|
2016-10-27 17:37:06 +00:00
|
|
|
.block(Block::default()
|
|
|
|
.borders(border::ALL)
|
|
|
|
.title("Bar chart"))
|
2016-10-22 10:51:41 +00:00
|
|
|
.data(&app.data4)
|
|
|
|
.bar_width(3)
|
|
|
|
.bar_gap(2)
|
2016-10-26 12:32:45 +00:00
|
|
|
.bar_color(Color::Green)
|
2016-10-22 10:51:41 +00:00
|
|
|
.value_color(Color::Black)
|
2016-10-26 12:32:45 +00:00
|
|
|
.label_color(Color::Yellow)
|
2016-10-22 10:51:41 +00:00
|
|
|
.render(&chunks[1], t);
|
2016-10-22 09:26:46 +00:00
|
|
|
});
|
2016-10-14 17:44:52 +00:00
|
|
|
if app.show_chart {
|
2016-10-15 22:38:20 +00:00
|
|
|
Chart::default()
|
2016-10-21 17:02:19 +00:00
|
|
|
.block(Block::default().title("Chart"))
|
|
|
|
.x_axis(Axis::default()
|
|
|
|
.title("X Axis")
|
|
|
|
.color(Color::Gray)
|
|
|
|
.bounds(app.window)
|
|
|
|
.labels(&[&format!("{}", app.window[0]),
|
|
|
|
&format!("{}", (app.window[0] + app.window[1]) / 2.0),
|
|
|
|
&format!("{}", app.window[1])]))
|
|
|
|
.y_axis(Axis::default()
|
|
|
|
.title("Y Axis")
|
|
|
|
.color(Color::Gray)
|
|
|
|
.bounds([0.0, 40.0])
|
|
|
|
.labels(&["0", "20", "40"]))
|
2016-10-27 10:35:56 +00:00
|
|
|
.datasets(&[Dataset::default()
|
|
|
|
.marker(Marker::Dot)
|
|
|
|
.color(Color::Cyan)
|
|
|
|
.data(&app.data2),
|
|
|
|
Dataset::default()
|
|
|
|
.marker(Marker::Braille)
|
|
|
|
.color(Color::Yellow)
|
|
|
|
.data(&app.data3)])
|
2016-10-15 22:38:20 +00:00
|
|
|
.render(&chunks[1], t);
|
2016-10-12 09:36:39 +00:00
|
|
|
}
|
2016-10-15 22:38:20 +00:00
|
|
|
});
|
|
|
|
Text::default()
|
2016-10-20 10:01:09 +00:00
|
|
|
.block(Block::default().borders(border::ALL).title("Footer"))
|
2016-10-22 17:25:17 +00:00
|
|
|
.wrap(true)
|
2016-10-14 17:44:52 +00:00
|
|
|
.fg(app.colors[app.color_index])
|
2016-10-27 17:37:06 +00:00
|
|
|
.text("This a paragraph with several lines.\nYou can change the \
|
|
|
|
color.\nUse \\{[color] [text]} to highlight the text with the \
|
|
|
|
color. For example, {red u}{green n}{yellow d}{magenta e}{cyan r} \
|
|
|
|
{gray t}{light_gray h}{light_red e} {light_green r}{light_yellow \
|
|
|
|
a}{light_magenta i}{light_cyan n}{white b}{red o}{green w}.\nOh, \
|
|
|
|
and if you didn't notice you can automatically wrap your text =).")
|
2016-10-15 22:38:20 +00:00
|
|
|
.render(&chunks[2], t);
|
2016-10-09 17:46:53 +00:00
|
|
|
});
|
|
|
|
}
|