mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-22 20:53:19 +00:00
Fix rustfmt and clippy errors
This commit is contained in:
parent
29db3dd722
commit
b2bb24b9d2
24 changed files with 458 additions and 393 deletions
|
@ -85,11 +85,9 @@ fn main() {
|
|||
});
|
||||
|
||||
// Tick
|
||||
thread::spawn(move || {
|
||||
loop {
|
||||
thread::spawn(move || loop {
|
||||
clock_tx.send(Event::Tick).unwrap();
|
||||
thread::sleep(time::Duration::from_millis(500));
|
||||
}
|
||||
});
|
||||
|
||||
// App
|
||||
|
|
|
@ -39,14 +39,12 @@ fn draw(t: &mut Terminal<TermionBackend>, size: &Rect) {
|
|||
// Wrapping block for a group
|
||||
// Just draw the block and the group on the same area and build the group
|
||||
// with at least a margin of 1
|
||||
Block::default()
|
||||
.borders(border::ALL)
|
||||
.render(t, &size);
|
||||
Block::default().borders(border::ALL).render(t, size);
|
||||
Group::default()
|
||||
.direction(Direction::Vertical)
|
||||
.margin(4)
|
||||
.sizes(&[Size::Percent(50), Size::Percent(50)])
|
||||
.render(t, &size, |t, chunks| {
|
||||
.render(t, size, |t, chunks| {
|
||||
Group::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.sizes(&[Size::Percent(50), Size::Percent(50)])
|
||||
|
|
|
@ -96,11 +96,9 @@ fn main() {
|
|||
});
|
||||
|
||||
// Tick
|
||||
thread::spawn(move || {
|
||||
loop {
|
||||
thread::spawn(move || loop {
|
||||
clock_tx.send(Event::Tick).unwrap();
|
||||
thread::sleep(time::Duration::from_millis(500));
|
||||
}
|
||||
});
|
||||
|
||||
// App
|
||||
|
@ -160,9 +158,7 @@ fn draw(t: &mut Terminal<TermionBackend>, app: &App) {
|
|||
.sizes(&[Size::Percent(50), Size::Percent(50)])
|
||||
.render(t, &app.size, |t, chunks| {
|
||||
Canvas::default()
|
||||
.block(Block::default()
|
||||
.borders(border::ALL)
|
||||
.title("World"))
|
||||
.block(Block::default().borders(border::ALL).title("World"))
|
||||
.paint(|ctx| {
|
||||
ctx.draw(&Map {
|
||||
color: Color::White,
|
||||
|
@ -174,9 +170,7 @@ fn draw(t: &mut Terminal<TermionBackend>, app: &App) {
|
|||
.y_bounds([-90.0, 90.0])
|
||||
.render(t, &chunks[0]);
|
||||
Canvas::default()
|
||||
.block(Block::default()
|
||||
.borders(border::ALL)
|
||||
.title("List"))
|
||||
.block(Block::default().borders(border::ALL).title("List"))
|
||||
.paint(|ctx| {
|
||||
ctx.draw(&Line {
|
||||
x1: app.ball.left() as f64,
|
||||
|
|
|
@ -85,11 +85,9 @@ fn main() {
|
|||
});
|
||||
|
||||
// Tick
|
||||
thread::spawn(move || {
|
||||
loop {
|
||||
thread::spawn(move || loop {
|
||||
clock_tx.send(Event::Tick).unwrap();
|
||||
thread::sleep(time::Duration::from_millis(500));
|
||||
}
|
||||
});
|
||||
|
||||
// App
|
||||
|
@ -130,9 +128,7 @@ fn draw(t: &mut Terminal<TermionBackend>, app: &App) {
|
|||
Chart::default()
|
||||
.block(Block::default()
|
||||
.title("Chart")
|
||||
.title_style(Style::default()
|
||||
.fg(Color::Cyan)
|
||||
.modifier(Modifier::Bold))
|
||||
.title_style(Style::default().fg(Color::Cyan).modifier(Modifier::Bold))
|
||||
.borders(border::ALL))
|
||||
.x_axis(Axis::default()
|
||||
.title("X Axis")
|
||||
|
|
|
@ -297,18 +297,29 @@ fn draw_first_tab(t: &mut Terminal<TermionBackend>, app: &App, area: &Rect) {
|
|||
.direction(Direction::Vertical)
|
||||
.sizes(&[Size::Fixed(7), Size::Min(7), Size::Fixed(7)])
|
||||
.render(t, area, |t, chunks| {
|
||||
draw_gauges(t, app, &chunks[0]);
|
||||
draw_charts(t, app, &chunks[1]);
|
||||
draw_text(t, &chunks[2]);
|
||||
});
|
||||
}
|
||||
|
||||
fn draw_gauges(t: &mut Terminal<TermionBackend>, app: &App, area: &Rect) {
|
||||
|
||||
Block::default()
|
||||
.borders(border::ALL)
|
||||
.title("Graphs")
|
||||
.render(t, &chunks[0]);
|
||||
.render(t, area);
|
||||
Group::default()
|
||||
.direction(Direction::Vertical)
|
||||
.margin(1)
|
||||
.sizes(&[Size::Fixed(2), Size::Fixed(3)])
|
||||
.render(t, &chunks[0], |t, chunks| {
|
||||
.render(t, area, |t, chunks| {
|
||||
Gauge::default()
|
||||
.block(Block::default().title("Gauge:"))
|
||||
.style(Style::default().fg(Color::Magenta).bg(Color::Black).modifier(Modifier::Italic))
|
||||
.style(Style::default()
|
||||
.fg(Color::Magenta)
|
||||
.bg(Color::Black)
|
||||
.modifier(Modifier::Italic))
|
||||
.label(&format!("{} / 100", app.progress))
|
||||
.percent(app.progress)
|
||||
.render(t, &chunks[0]);
|
||||
|
@ -318,6 +329,9 @@ fn draw_first_tab(t: &mut Terminal<TermionBackend>, app: &App, area: &Rect) {
|
|||
.data(&app.data)
|
||||
.render(t, &chunks[1]);
|
||||
});
|
||||
}
|
||||
|
||||
fn draw_charts(t: &mut Terminal<TermionBackend>, app: &App, area: &Rect) {
|
||||
let sizes = if app.show_chart {
|
||||
vec![Size::Percent(50), Size::Percent(50)]
|
||||
} else {
|
||||
|
@ -326,7 +340,7 @@ fn draw_first_tab(t: &mut Terminal<TermionBackend>, app: &App, area: &Rect) {
|
|||
Group::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.sizes(&sizes)
|
||||
.render(t, &chunks[1], |t, chunks| {
|
||||
.render(t, area, |t, chunks| {
|
||||
Group::default()
|
||||
.direction(Direction::Vertical)
|
||||
.sizes(&[Size::Percent(50), Size::Percent(50)])
|
||||
|
@ -336,12 +350,12 @@ fn draw_first_tab(t: &mut Terminal<TermionBackend>, app: &App, area: &Rect) {
|
|||
.sizes(&[Size::Percent(50), Size::Percent(50)])
|
||||
.render(t, &chunks[0], |t, chunks| {
|
||||
SelectableList::default()
|
||||
.block(Block::default()
|
||||
.borders(border::ALL)
|
||||
.title("List"))
|
||||
.block(Block::default().borders(border::ALL).title("List"))
|
||||
.items(&app.items)
|
||||
.select(app.selected)
|
||||
.highlight_style(Style::default().fg(Color::Yellow).modifier(Modifier::Bold))
|
||||
.highlight_style(Style::default()
|
||||
.fg(Color::Yellow)
|
||||
.modifier(Modifier::Bold))
|
||||
.highlight_symbol(">")
|
||||
.render(t, &chunks[0]);
|
||||
let info_style = Style::default().fg(Color::White);
|
||||
|
@ -349,25 +363,30 @@ fn draw_first_tab(t: &mut Terminal<TermionBackend>, app: &App, area: &Rect) {
|
|||
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 {
|
||||
.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,
|
||||
})).collect::<Vec<(String, &Style)>>())
|
||||
})
|
||||
})
|
||||
.collect::<Vec<(String, &Style)>>())
|
||||
.render(t, &chunks[1]);
|
||||
});
|
||||
BarChart::default()
|
||||
.block(Block::default()
|
||||
.borders(border::ALL)
|
||||
.title("Bar chart"))
|
||||
.block(Block::default().borders(border::ALL).title("Bar chart"))
|
||||
.data(&app.data4)
|
||||
.bar_width(3)
|
||||
.bar_gap(2)
|
||||
.value_style(Style::default().fg(Color::Black).bg(Color::Green).modifier(Modifier::Italic))
|
||||
.value_style(Style::default()
|
||||
.fg(Color::Black)
|
||||
.bg(Color::Green)
|
||||
.modifier(Modifier::Italic))
|
||||
.label_style(Style::default().fg(Color::Yellow))
|
||||
.style(Style::default().fg(Color::Green))
|
||||
.render(t, &chunks[1]);
|
||||
|
@ -386,7 +405,8 @@ fn draw_first_tab(t: &mut Terminal<TermionBackend>, app: &App, area: &Rect) {
|
|||
.labels_style(Style::default().modifier(Modifier::Italic))
|
||||
.bounds(app.window)
|
||||
.labels(&[&format!("{}", app.window[0]),
|
||||
&format!("{}", (app.window[0] + app.window[1]) / 2.0),
|
||||
&format!("{}",
|
||||
(app.window[0] + app.window[1]) / 2.0),
|
||||
&format!("{}", app.window[1])]))
|
||||
.y_axis(Axis::default()
|
||||
.title("Y Axis")
|
||||
|
@ -407,6 +427,9 @@ fn draw_first_tab(t: &mut Terminal<TermionBackend>, app: &App, area: &Rect) {
|
|||
.render(t, &chunks[1]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn draw_text(t: &mut Terminal<TermionBackend>, area: &Rect) {
|
||||
Paragraph::default()
|
||||
.block(Block::default()
|
||||
.borders(border::ALL)
|
||||
|
@ -414,14 +437,15 @@ fn draw_first_tab(t: &mut Terminal<TermionBackend>, app: &App, area: &Rect) {
|
|||
.title_style(Style::default().fg(Color::Magenta).modifier(Modifier::Bold)))
|
||||
.wrap(true)
|
||||
.text("This is a paragraph with several lines.\nYou can change the color.\nUse \
|
||||
\\{fg=[color];bg=[color];mod=[modifier] [text]} to highlight the text with a color. For example, {fg=red \
|
||||
u}{fg=green n}{fg=yellow d}{fg=magenta e}{fg=cyan r} {fg=gray t}{fg=light_gray h}{fg=light_red \
|
||||
e} {fg=light_green r}{fg=light_yellow a}{fg=light_magenta i}{fg=light_cyan n}{fg=white \
|
||||
b}{fg=red o}{fg=green w}.\nOh, and if you didn't {mod=italic notice} you can {mod=bold automatically} \
|
||||
{mod=invert wrap} your {mod=underline text} =).\nOne more thing is that it should display unicode \
|
||||
characters properly: 日本国, ٩(-̮̮̃-̃)۶ ٩(●̮̮̃•̃)۶ ٩(͡๏̯͡๏)۶ ٩(-̮̮̃•̃).")
|
||||
.render(t, &chunks[2]);
|
||||
});
|
||||
\\{fg=[color];bg=[color];mod=[modifier] [text]} to highlight the text with a color. \
|
||||
For example, {fg=red u}{fg=green n}{fg=yellow d}{fg=magenta e}{fg=cyan r} \
|
||||
{fg=gray t}{fg=light_gray h}{fg=light_red e} {fg=light_green r}{fg=light_yellow a} \
|
||||
{fg=light_magenta i}{fg=light_cyan n}{fg=white b}{fg=red o}{fg=green w}.\n\
|
||||
Oh, and if you didn't {mod=italic notice} you can {mod=bold automatically} \
|
||||
{mod=invert wrap} your {mod=underline text} =).\nOne more thing is that \
|
||||
it should display unicode characters properly: 日本国, ٩(-̮̮̃-̃)۶ ٩(●̮̮̃•̃)۶ ٩(͡๏̯͡๏)۶ \
|
||||
٩(-̮̮̃•̃).")
|
||||
.render(t, area);
|
||||
}
|
||||
|
||||
fn draw_second_tab(t: &mut Terminal<TermionBackend>, app: &App, area: &Rect) {
|
||||
|
@ -432,9 +456,7 @@ fn draw_second_tab(t: &mut Terminal<TermionBackend>, app: &App, area: &Rect) {
|
|||
let up_style = Style::default().fg(Color::Green);
|
||||
let failure_style = Style::default().fg(Color::Red);
|
||||
Table::default()
|
||||
.block(Block::default()
|
||||
.title("Servers")
|
||||
.borders(border::ALL))
|
||||
.block(Block::default().title("Servers").borders(border::ALL))
|
||||
.header(&["Server", "Location", "Status"])
|
||||
.header_style(Style::default().fg(Color::Yellow))
|
||||
.widths(&[15, 15, 10])
|
||||
|
|
|
@ -82,11 +82,9 @@ fn main() {
|
|||
});
|
||||
|
||||
// Tick
|
||||
thread::spawn(move || {
|
||||
loop {
|
||||
thread::spawn(move || loop {
|
||||
clock_tx.send(Event::Tick).unwrap();
|
||||
thread::sleep(time::Duration::from_millis(500));
|
||||
}
|
||||
});
|
||||
|
||||
// App
|
||||
|
@ -127,7 +125,10 @@ fn draw(t: &mut Terminal<TermionBackend>, app: &App) {
|
|||
Group::default()
|
||||
.direction(Direction::Vertical)
|
||||
.margin(2)
|
||||
.sizes(&[Size::Percent(25), Size::Percent(25), Size::Percent(25), Size::Percent(25)])
|
||||
.sizes(&[Size::Percent(25),
|
||||
Size::Percent(25),
|
||||
Size::Percent(25),
|
||||
Size::Percent(25)])
|
||||
.render(t, &app.size, |t, chunks| {
|
||||
Gauge::default()
|
||||
.block(Block::default().title("Gauge1").borders(border::ALL))
|
||||
|
|
|
@ -102,11 +102,9 @@ fn main() {
|
|||
});
|
||||
|
||||
// Tick
|
||||
thread::spawn(move || {
|
||||
loop {
|
||||
thread::spawn(move || loop {
|
||||
clock_tx.send(Event::Tick).unwrap();
|
||||
thread::sleep(time::Duration::from_millis(500));
|
||||
}
|
||||
});
|
||||
|
||||
// App
|
||||
|
@ -165,18 +163,14 @@ fn draw(t: &mut Terminal<TermionBackend>, app: &App) {
|
|||
.sizes(&[Size::Percent(50), Size::Percent(50)])
|
||||
.render(t, &app.size, |t, chunks| {
|
||||
SelectableList::default()
|
||||
.block(Block::default()
|
||||
.borders(border::ALL)
|
||||
.title("List"))
|
||||
.block(Block::default().borders(border::ALL).title("List"))
|
||||
.items(&app.items)
|
||||
.select(app.selected)
|
||||
.highlight_style(Style::default().fg(Color::Yellow).modifier(Modifier::Bold))
|
||||
.highlight_symbol(">")
|
||||
.render(t, &chunks[0]);
|
||||
List::default()
|
||||
.block(Block::default()
|
||||
.borders(border::ALL)
|
||||
.title("List"))
|
||||
.block(Block::default().borders(border::ALL).title("List"))
|
||||
.items(&app.events
|
||||
.iter()
|
||||
.map(|&(evt, level)| {
|
||||
|
|
|
@ -40,13 +40,13 @@ fn draw(t: &mut Terminal<TermionBackend>, size: &Rect) {
|
|||
|
||||
Block::default()
|
||||
.style(Style::default().bg(Color::White))
|
||||
.render(t, &size);
|
||||
.render(t, size);
|
||||
|
||||
Group::default()
|
||||
.direction(Direction::Vertical)
|
||||
.margin(5)
|
||||
.sizes(&[Size::Percent(100)])
|
||||
.render(t, &size, |t, chunks| {
|
||||
.render(t, size, |t, chunks| {
|
||||
Group::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.sizes(&[Size::Percent(100)])
|
||||
|
|
|
@ -41,7 +41,9 @@ fn draw(t: &mut Terminal<RustboxBackend>) {
|
|||
Paragraph::default()
|
||||
.block(Block::default()
|
||||
.title("Rustbox backend")
|
||||
.title_style(Style::default().fg(Color::Yellow).modifier(Modifier::Bold))
|
||||
.title_style(Style::default()
|
||||
.fg(Color::Yellow)
|
||||
.modifier(Modifier::Bold))
|
||||
.borders(border::ALL)
|
||||
.border_style(Style::default().fg(Color::Magenta)))
|
||||
.text("It {yellow works}!")
|
||||
|
|
|
@ -82,11 +82,9 @@ fn main() {
|
|||
});
|
||||
|
||||
// Tick
|
||||
thread::spawn(move || {
|
||||
loop {
|
||||
thread::spawn(move || loop {
|
||||
clock_tx.send(Event::Tick).unwrap();
|
||||
thread::sleep(time::Duration::from_millis(500));
|
||||
}
|
||||
});
|
||||
|
||||
// App
|
||||
|
@ -130,18 +128,24 @@ fn draw(t: &mut Terminal<TermionBackend>, app: &App) {
|
|||
.sizes(&[Size::Fixed(3), Size::Fixed(3), Size::Fixed(7), Size::Min(0)])
|
||||
.render(t, &app.size, |t, chunks| {
|
||||
Sparkline::default()
|
||||
.block(Block::default().title("Data1").borders(border::LEFT | border::RIGHT))
|
||||
.block(Block::default()
|
||||
.title("Data1")
|
||||
.borders(border::LEFT | border::RIGHT))
|
||||
.data(&app.data1)
|
||||
.style(Style::default().fg(Color::Yellow))
|
||||
.render(t, &chunks[0]);
|
||||
Sparkline::default()
|
||||
.block(Block::default().title("Data2").borders(border::LEFT | border::RIGHT))
|
||||
.block(Block::default()
|
||||
.title("Data2")
|
||||
.borders(border::LEFT | border::RIGHT))
|
||||
.data(&app.data2)
|
||||
.style(Style::default().bg(Color::Green))
|
||||
.render(t, &chunks[1]);
|
||||
// Multiline
|
||||
Sparkline::default()
|
||||
.block(Block::default().title("Data3").borders(border::LEFT | border::RIGHT))
|
||||
.block(Block::default()
|
||||
.title("Data3")
|
||||
.borders(border::LEFT | border::RIGHT))
|
||||
.data(&app.data3)
|
||||
.style(Style::default().fg(Color::Red))
|
||||
.render(t, &chunks[2]);
|
||||
|
|
|
@ -93,9 +93,7 @@ fn draw(t: &mut Terminal<TermionBackend>, app: &App) {
|
|||
let selected_style = Style::default().fg(Color::Yellow).modifier(Modifier::Bold);
|
||||
let normal_style = Style::default().fg(Color::White);
|
||||
Table::default()
|
||||
.block(Block::default()
|
||||
.borders(border::ALL)
|
||||
.title("Table"))
|
||||
.block(Block::default().borders(border::ALL).title("Table"))
|
||||
.header(&["Header1", "Header2", "Header3"])
|
||||
.widths(&[10, 10, 10])
|
||||
.rows(&app.items
|
||||
|
|
|
@ -83,16 +83,28 @@ fn draw(t: &mut Terminal<TermionBackend>, app: &mut App) {
|
|||
.render(t, &chunks[0]);
|
||||
match app.tabs.selection {
|
||||
0 => {
|
||||
Block::default().title("Inner 0").borders(border::ALL).render(t, &chunks[1]);
|
||||
Block::default()
|
||||
.title("Inner 0")
|
||||
.borders(border::ALL)
|
||||
.render(t, &chunks[1]);
|
||||
}
|
||||
1 => {
|
||||
Block::default().title("Inner 1").borders(border::ALL).render(t, &chunks[1]);
|
||||
Block::default()
|
||||
.title("Inner 1")
|
||||
.borders(border::ALL)
|
||||
.render(t, &chunks[1]);
|
||||
}
|
||||
2 => {
|
||||
Block::default().title("Inner 2").borders(border::ALL).render(t, &chunks[1]);
|
||||
Block::default()
|
||||
.title("Inner 2")
|
||||
.borders(border::ALL)
|
||||
.render(t, &chunks[1]);
|
||||
}
|
||||
3 => {
|
||||
Block::default().title("Inner 3").borders(border::ALL).render(t, &chunks[1]);
|
||||
Block::default()
|
||||
.title("Inner 3")
|
||||
.borders(border::ALL)
|
||||
.render(t, &chunks[1]);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,8 @@ impl Backend for RustboxBackend {
|
|||
let mut inst = 0;
|
||||
for (x, y, cell) in content {
|
||||
inst += 1;
|
||||
self.rustbox.print(x as usize,
|
||||
self.rustbox
|
||||
.print(x as usize,
|
||||
y as usize,
|
||||
cell.style.modifier.into(),
|
||||
cell.style.fg.into(),
|
||||
|
@ -54,12 +55,12 @@ impl Backend for RustboxBackend {
|
|||
Ok(())
|
||||
}
|
||||
fn size(&self) -> Result<Rect, io::Error> {
|
||||
Ok((Rect {
|
||||
Ok(Rect {
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: self.rustbox.width() as u16,
|
||||
height: self.rustbox.height() as u16,
|
||||
}))
|
||||
})
|
||||
}
|
||||
fn flush(&mut self) -> Result<(), io::Error> {
|
||||
self.rustbox.present();
|
||||
|
@ -68,7 +69,7 @@ impl Backend for RustboxBackend {
|
|||
}
|
||||
|
||||
fn rgb_to_byte(r: u8, g: u8, b: u8) -> u16 {
|
||||
((((r & 255 & 0xC0) + ((g & 255 & 0xE0) >> 2) + ((b & 0xE0) >> 5))) & 0xFF) as u16
|
||||
(((r & 255 & 0xC0) + ((g & 255 & 0xE0) >> 2) + ((b & 0xE0) >> 5)) & 0xFF) as u16
|
||||
}
|
||||
|
||||
impl Into<rustbox::Color> for Color {
|
||||
|
|
|
@ -109,23 +109,33 @@ impl Backend for TermionBackend {
|
|||
}
|
||||
|
||||
macro_rules! termion_fg {
|
||||
($color:ident) => (format!("{}", termion::color::Fg(termion::color::$color)));
|
||||
($color:ident) => (
|
||||
format!("{}", termion::color::Fg(termion::color::$color))
|
||||
);
|
||||
}
|
||||
|
||||
macro_rules! termion_fg_rgb {
|
||||
($r:expr, $g:expr, $b:expr) => (format!("{}", termion::color::Fg(termion::color::Rgb($r, $g, $b))));
|
||||
($r:expr, $g:expr, $b:expr) => (
|
||||
format!("{}", termion::color::Fg(termion::color::Rgb($r, $g, $b)))
|
||||
);
|
||||
}
|
||||
|
||||
macro_rules! termion_bg {
|
||||
($color:ident) => (format!("{}", termion::color::Bg(termion::color::$color)));
|
||||
($color:ident) => (
|
||||
format!("{}", termion::color::Bg(termion::color::$color))
|
||||
);
|
||||
}
|
||||
|
||||
macro_rules! termion_bg_rgb {
|
||||
($r:expr, $g:expr, $b:expr) => (format!("{}", termion::color::Bg(termion::color::Rgb($r, $g, $b))));
|
||||
($r:expr, $g:expr, $b:expr) => (
|
||||
format!("{}", termion::color::Bg(termion::color::Rgb($r, $g, $b)))
|
||||
);
|
||||
}
|
||||
|
||||
macro_rules! termion_modifier {
|
||||
($style:ident) => (format!("{}", termion::style::$style));
|
||||
($style:ident) => (
|
||||
format!("{}", termion::style::$style)
|
||||
);
|
||||
}
|
||||
|
||||
impl Color {
|
||||
|
|
|
@ -139,7 +139,10 @@ pub enum Size {
|
|||
pub fn split(area: &Rect, dir: &Direction, margin: u16, sizes: &[Size]) -> Vec<Rect> {
|
||||
let mut solver = Solver::new();
|
||||
let mut vars: HashMap<Variable, (usize, usize)> = HashMap::new();
|
||||
let elements = sizes.iter().map(|_| Element::new()).collect::<Vec<Element>>();
|
||||
let elements = sizes
|
||||
.iter()
|
||||
.map(|_| Element::new())
|
||||
.collect::<Vec<Element>>();
|
||||
let mut results = sizes.iter().map(|_| Rect::default()).collect::<Vec<Rect>>();
|
||||
let dest_area = area.inner(margin);
|
||||
for (i, e) in elements.iter().enumerate() {
|
||||
|
@ -157,14 +160,22 @@ pub fn split(area: &Rect, dir: &Direction, margin: u16, sizes: &[Size]) -> Vec<R
|
|||
}
|
||||
if let Some(first) = elements.first() {
|
||||
constraints.push(match *dir {
|
||||
Direction::Horizontal => first.left() | EQ(REQUIRED) | dest_area.left() as f64,
|
||||
Direction::Vertical => first.top() | EQ(REQUIRED) | dest_area.top() as f64,
|
||||
Direction::Horizontal => {
|
||||
first.left() | EQ(REQUIRED) | dest_area.left() as f64
|
||||
}
|
||||
Direction::Vertical => {
|
||||
first.top() | EQ(REQUIRED) | dest_area.top() as f64
|
||||
}
|
||||
});
|
||||
}
|
||||
if let Some(last) = elements.last() {
|
||||
constraints.push(match *dir {
|
||||
Direction::Horizontal => last.right() | EQ(REQUIRED) | dest_area.right() as f64,
|
||||
Direction::Vertical => last.bottom() | EQ(REQUIRED) | dest_area.bottom() as f64,
|
||||
Direction::Horizontal => {
|
||||
last.right() | EQ(REQUIRED) | dest_area.right() as f64
|
||||
}
|
||||
Direction::Vertical => {
|
||||
last.bottom() | EQ(REQUIRED) | dest_area.bottom() as f64
|
||||
}
|
||||
});
|
||||
}
|
||||
match *dir {
|
||||
|
@ -178,7 +189,8 @@ pub fn split(area: &Rect, dir: &Direction, margin: u16, sizes: &[Size]) -> Vec<R
|
|||
constraints.push(match *size {
|
||||
Size::Fixed(v) => elements[i].width | EQ(WEAK) | v as f64,
|
||||
Size::Percent(v) => {
|
||||
elements[i].width | EQ(WEAK) | ((v * dest_area.width) as f64 / 100.0)
|
||||
elements[i].width | EQ(WEAK) |
|
||||
((v * dest_area.width) as f64 / 100.0)
|
||||
}
|
||||
Size::Min(v) => elements[i].width | GE(WEAK) | v as f64,
|
||||
Size::Max(v) => elements[i].width | LE(WEAK) | v as f64,
|
||||
|
@ -195,7 +207,8 @@ pub fn split(area: &Rect, dir: &Direction, margin: u16, sizes: &[Size]) -> Vec<R
|
|||
constraints.push(match *size {
|
||||
Size::Fixed(v) => elements[i].height | EQ(WEAK) | v as f64,
|
||||
Size::Percent(v) => {
|
||||
elements[i].height | EQ(WEAK) | ((v * dest_area.height) as f64 / 100.0)
|
||||
elements[i].height | EQ(WEAK) |
|
||||
((v * dest_area.height) as f64 / 100.0)
|
||||
}
|
||||
Size::Min(v) => elements[i].height | GE(WEAK) | v as f64,
|
||||
Size::Max(v) => elements[i].height | LE(WEAK) | v as f64,
|
||||
|
|
|
@ -123,7 +123,7 @@ impl<B> Terminal<B>
|
|||
self.layout_cache.insert(key, value);
|
||||
}
|
||||
|
||||
for (_, e) in &mut self.layout_cache {
|
||||
for e in self.layout_cache.values_mut() {
|
||||
e.hot = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -123,7 +123,8 @@ impl<'a> Widget for BarChart<'a> {
|
|||
|
||||
self.background(&chart_area, buf, self.style.bg);
|
||||
|
||||
let max = self.max.unwrap_or(self.data.iter().fold(0, |acc, &(_, v)| max(v, acc)));
|
||||
let max = self.max
|
||||
.unwrap_or_else(|| self.data.iter().fold(0, |acc, &(_, v)| max(v, acc)));
|
||||
let max_index = min((chart_area.width / (self.bar_width + self.bar_gap)) as usize,
|
||||
self.data.len());
|
||||
let mut data = self.data
|
||||
|
@ -146,8 +147,7 @@ impl<'a> Widget for BarChart<'a> {
|
|||
};
|
||||
|
||||
for x in 0..self.bar_width {
|
||||
buf.get_mut(chart_area.left() + i as u16 * (self.bar_width + self.bar_gap) +
|
||||
x,
|
||||
buf.get_mut(chart_area.left() + i as u16 * (self.bar_width + self.bar_gap) + x,
|
||||
chart_area.top() + j)
|
||||
.set_symbol(symbol)
|
||||
.set_style(self.style);
|
||||
|
|
|
@ -12,8 +12,10 @@ use buffer::Buffer;
|
|||
use widgets::{Block, Widget};
|
||||
use layout::Rect;
|
||||
|
||||
pub const DOTS: [[u16; 2]; 4] =
|
||||
[[0x0001, 0x0008], [0x0002, 0x0010], [0x0004, 0x0020], [0x0040, 0x0080]];
|
||||
pub const DOTS: [[u16; 2]; 4] = [[0x0001, 0x0008],
|
||||
[0x0002, 0x0010],
|
||||
[0x0004, 0x0020],
|
||||
[0x0040, 0x0080]];
|
||||
pub const BRAILLE_OFFSET: u16 = 0x2800;
|
||||
pub const BRAILLE_BLANK: char = '⠀';
|
||||
|
||||
|
@ -90,7 +92,8 @@ impl<'a> Context<'a> {
|
|||
let right = self.x_bounds[1];
|
||||
let bottom = self.y_bounds[0];
|
||||
let top = self.y_bounds[1];
|
||||
for (x, y) in shape.points()
|
||||
for (x, y) in shape
|
||||
.points()
|
||||
.filter(|&(x, y)| !(x < left || x > right || y < bottom || y > top)) {
|
||||
let dy = ((top - y) * (self.height - 1) as f64 * 4.0 / (top - bottom)) as usize;
|
||||
let dx = ((x - left) * (self.width - 1) as f64 * 2.0 / (right - left)) as usize;
|
||||
|
@ -109,7 +112,8 @@ impl<'a> Context<'a> {
|
|||
|
||||
/// Print a string on the canvas at the given position
|
||||
pub fn print(&mut self, x: f64, y: f64, text: &'a str, color: Color) {
|
||||
self.labels.push(Label {
|
||||
self.labels
|
||||
.push(Label {
|
||||
x: x,
|
||||
y: y,
|
||||
text: text,
|
||||
|
@ -248,7 +252,8 @@ impl<'a, F> Widget for Canvas<'a, F>
|
|||
|
||||
// Retreive painted points for each layer
|
||||
for layer in ctx.layers {
|
||||
for (i, (ch, color)) in layer.string
|
||||
for (i, (ch, color)) in layer
|
||||
.string
|
||||
.chars()
|
||||
.zip(layer.colors.into_iter())
|
||||
.enumerate() {
|
||||
|
@ -264,8 +269,11 @@ impl<'a, F> Widget for Canvas<'a, F>
|
|||
|
||||
// Finally draw the labels
|
||||
let style = Style::default().bg(self.background_color);
|
||||
for label in ctx.labels.iter().filter(|l| {
|
||||
!(l.x < self.x_bounds[0] || l.x > self.x_bounds[1] || l.y < self.y_bounds[0] ||
|
||||
for label in ctx.labels
|
||||
.iter()
|
||||
.filter(|l| {
|
||||
!(l.x < self.x_bounds[0] || l.x > self.x_bounds[1] ||
|
||||
l.y < self.y_bounds[0] ||
|
||||
l.y > self.y_bounds[1])
|
||||
}) {
|
||||
let dy = ((self.y_bounds[1] - label.y) * (canvas_area.height - 1) as f64 /
|
||||
|
|
|
@ -389,17 +389,20 @@ impl<'a> Widget for Chart<'a> {
|
|||
for dataset in self.datasets {
|
||||
match dataset.marker {
|
||||
Marker::Dot => {
|
||||
for &(x, y) in dataset.data.iter().filter(|&&(x, y)| {
|
||||
for &(x, y) in dataset
|
||||
.data
|
||||
.iter()
|
||||
.filter(|&&(x, y)| {
|
||||
!(x < self.x_axis.bounds[0] || x > self.x_axis.bounds[1] ||
|
||||
y < self.y_axis.bounds[0] ||
|
||||
y > self.y_axis.bounds[1])
|
||||
}) {
|
||||
let dy = ((self.y_axis.bounds[1] - y) * (graph_area.height - 1) as f64 /
|
||||
(self.y_axis.bounds[1] -
|
||||
self.y_axis.bounds[0])) as u16;
|
||||
(self.y_axis.bounds[1] - self.y_axis.bounds[0])) as
|
||||
u16;
|
||||
let dx = ((x - self.x_axis.bounds[0]) * (graph_area.width - 1) as f64 /
|
||||
(self.x_axis.bounds[1] -
|
||||
self.x_axis.bounds[0])) as u16;
|
||||
(self.x_axis.bounds[1] - self.x_axis.bounds[0])) as
|
||||
u16;
|
||||
|
||||
buf.get_mut(graph_area.left() + dx, graph_area.top() + dy)
|
||||
.set_symbol(symbols::DOT)
|
||||
|
|
|
@ -98,7 +98,9 @@ impl<'a> Widget for Gauge<'a> {
|
|||
|
||||
// Fix colors
|
||||
for x in gauge_area.left()..end {
|
||||
buf.get_mut(x, y).set_fg(self.style.bg).set_bg(self.style.fg);
|
||||
buf.get_mut(x, y)
|
||||
.set_fg(self.style.bg)
|
||||
.set_bg(self.style.fg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,8 +34,10 @@ impl<'a> List<'a> {
|
|||
pub fn items<I>(&'a mut self, items: &'a [(I, &'a Style)]) -> &mut List<'a>
|
||||
where I: AsRef<str> + 'a
|
||||
{
|
||||
self.items =
|
||||
items.iter().map(|&(ref i, s)| (i.as_ref(), s)).collect::<Vec<(&'a str, &'a Style)>>();
|
||||
self.items = items
|
||||
.iter()
|
||||
.map(|&(ref i, s)| (i.as_ref(), s))
|
||||
.collect::<Vec<(&'a str, &'a Style)>>();
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -62,7 +64,7 @@ impl<'a> Widget for List<'a> {
|
|||
self.background(&list_area, buf, self.style.bg);
|
||||
|
||||
let max_index = min(self.items.len(), list_area.height as usize);
|
||||
for (i, &(ref item, style)) in self.items.iter().enumerate().take(max_index) {
|
||||
for (i, &(item, style)) in self.items.iter().enumerate().take(max_index) {
|
||||
buf.set_stringn(list_area.left(),
|
||||
list_area.top() + i as u16,
|
||||
item.as_ref(),
|
||||
|
@ -169,7 +171,9 @@ impl<'a> Widget for SelectableList<'a> {
|
|||
None => (0, &self.style),
|
||||
};
|
||||
let highlight_symbol = self.highlight_symbol.unwrap_or("");
|
||||
let blank_symbol = iter::repeat(" ").take(highlight_symbol.width()).collect::<String>();
|
||||
let blank_symbol = iter::repeat(" ")
|
||||
.take(highlight_symbol.width())
|
||||
.collect::<String>();
|
||||
// Make sure the list show the selected item
|
||||
let offset = if selected >= list_height {
|
||||
selected - list_height + 1
|
||||
|
|
|
@ -193,15 +193,13 @@ impl<'a, T> Iterator for Parser<'a, T>
|
|||
if self.escaping {
|
||||
self.escaping = false;
|
||||
Some((s, self.style))
|
||||
} else {
|
||||
if self.mark {
|
||||
} else if self.mark {
|
||||
Some((s, self.style))
|
||||
} else {
|
||||
self.style = self.base_style;
|
||||
self.mark = true;
|
||||
self.next()
|
||||
}
|
||||
}
|
||||
} else if s == "}" && self.mark {
|
||||
self.reset();
|
||||
self.next()
|
||||
|
|
|
@ -88,7 +88,11 @@ impl<'a> Table<'a> {
|
|||
{
|
||||
self.rows = rows.iter()
|
||||
.map(|&(ref r, style)| {
|
||||
(r.as_ref().iter().map(|i| i.as_ref()).collect::<Vec<&'a str>>(), style)
|
||||
(r.as_ref()
|
||||
.iter()
|
||||
.map(|i| i.as_ref())
|
||||
.collect::<Vec<&'a str>>(),
|
||||
style)
|
||||
})
|
||||
.collect::<Vec<(Vec<&'a str>, &'a Style)>>();
|
||||
self
|
||||
|
|
|
@ -92,7 +92,10 @@ impl<'a> Widget for Tabs<'a> {
|
|||
self.background(&tabs_area, buf, self.style.bg);
|
||||
|
||||
let mut x = tabs_area.left();
|
||||
for (title, style) in self.titles.iter().enumerate().map(|(i, t)| if i == self.selected {
|
||||
for (title, style) in self.titles
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, t)| if i == self.selected {
|
||||
(t, &self.highlight_style)
|
||||
} else {
|
||||
(t, &self.style)
|
||||
|
|
Loading…
Reference in a new issue