Run cargo fmt

This commit is contained in:
Florian Dehau 2017-09-11 07:58:37 +02:00
parent 295fc77df2
commit 71545a0aa8
26 changed files with 6932 additions and 6824 deletions

View file

@ -24,7 +24,8 @@ impl<'a> App<'a> {
fn new() -> App<'a> {
App {
size: Rect::default(),
data: vec![("B1", 9),
data: vec![
("B1", 9),
("B2", 12),
("B3", 5),
("B4", 8),
@ -47,7 +48,8 @@ impl<'a> App<'a> {
("B21", 11),
("B22", 9),
("B23", 3),
("B24", 5)],
("B24", 5),
],
}
}

View file

@ -56,10 +56,9 @@ fn draw(t: &mut Terminal<MouseBackend>, size: &Rect) {
.render(t, &chunks[0]);
Block::default()
.title("Styled title")
.title_style(Style::default()
.fg(Color::White)
.bg(Color::Red)
.modifier(Modifier::Bold))
.title_style(Style::default().fg(Color::White).bg(Color::Red).modifier(
Modifier::Bold,
))
.render(t, &chunks[1]);
});
Group::default()

View file

@ -46,11 +46,13 @@ impl App {
fn advance(&mut self) {
if self.ball.left() < self.playground.left() ||
self.ball.right() > self.playground.right() {
self.ball.right() > self.playground.right()
{
self.dir_x = !self.dir_x;
}
if self.ball.top() < self.playground.top() ||
self.ball.bottom() > self.playground.bottom() {
self.ball.bottom() > self.playground.bottom()
{
self.dir_y = !self.dir_y;
}

View file

@ -126,25 +126,37 @@ fn main() {
fn draw(t: &mut Terminal<MouseBackend>, app: &App) {
Chart::default()
.block(Block::default()
.block(
Block::default()
.title("Chart")
.title_style(Style::default().fg(Color::Cyan).modifier(Modifier::Bold))
.borders(border::ALL))
.x_axis(Axis::default()
.borders(border::ALL),
)
.x_axis(
Axis::default()
.title("X Axis")
.style(Style::default().fg(Color::Gray))
.labels_style(Style::default().modifier(Modifier::Italic))
.bounds(app.window)
.labels(&[&format!("{}", app.window[0]),
.labels(
&[
&format!("{}", app.window[0]),
&format!("{}", (app.window[0] + app.window[1]) / 2.0),
&format!("{}", app.window[1])]))
.y_axis(Axis::default()
&format!("{}", app.window[1]),
],
),
)
.y_axis(
Axis::default()
.title("Y Axis")
.style(Style::default().fg(Color::Gray))
.labels_style(Style::default().modifier(Modifier::Italic))
.bounds([-20.0, 20.0])
.labels(&["-20", "0", "20"]))
.datasets(&[Dataset::default()
.labels(&["-20", "0", "20"]),
)
.datasets(
&[
Dataset::default()
.name("data2")
.marker(Marker::Dot)
.style(Style::default().fg(Color::Cyan))
@ -153,7 +165,9 @@ fn draw(t: &mut Terminal<MouseBackend>, app: &App) {
.name("data3")
.marker(Marker::Braille)
.style(Style::default().fg(Color::Yellow))
.data(&app.data2)])
.data(&app.data2),
],
)
.render(t, &app.size);
t.draw().unwrap();

View file

@ -125,10 +125,14 @@ fn draw(t: &mut Terminal<MouseBackend>, app: &App) {
Group::default()
.direction(Direction::Vertical)
.margin(2)
.sizes(&[Size::Percent(25),
.sizes(
&[
Size::Percent(25),
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))

View file

@ -30,12 +30,35 @@ impl<'a> App<'a> {
fn new() -> App<'a> {
App {
size: Rect::default(),
items: vec!["Item1", "Item2", "Item3", "Item4", "Item5", "Item6", "Item7", "Item8",
"Item9", "Item10", "Item11", "Item12", "Item13", "Item14", "Item15",
"Item16", "Item17", "Item18", "Item19", "Item20", "Item21", "Item22",
"Item23", "Item24"],
items: vec![
"Item1",
"Item2",
"Item3",
"Item4",
"Item5",
"Item6",
"Item7",
"Item8",
"Item9",
"Item10",
"Item11",
"Item12",
"Item13",
"Item14",
"Item15",
"Item16",
"Item17",
"Item18",
"Item19",
"Item20",
"Item21",
"Item22",
"Item23",
"Item24",
],
selected: 0,
events: vec![("Event1", "INFO"),
events: vec![
("Event1", "INFO"),
("Event2", "INFO"),
("Event3", "CRITICAL"),
("Event4", "ERROR"),
@ -60,7 +83,8 @@ impl<'a> App<'a> {
("Event23", "INFO"),
("Event24", "WARNING"),
("Event25", "INFO"),
("Event26", "INFO")],
("Event26", "INFO"),
],
info_style: Style::default().fg(Color::White),
warning_style: Style::default().fg(Color::Yellow),
error_style: Style::default().fg(Color::Magenta),
@ -170,15 +194,16 @@ fn draw(t: &mut Terminal<MouseBackend>, app: &App) {
.highlight_symbol(">")
.render(t, &chunks[0]);
{
let events = app.events
.iter()
.map(|&(evt, level)| {
Item::StyledData(format!("{}: {}", level, evt), match level {
let events = app.events.iter().map(|&(evt, level)| {
Item::StyledData(
format!("{}: {}", level, evt),
match level {
"ERROR" => &app.error_style,
"CRITICAL" => &app.critical_style,
"WARNING" => &app.warning_style,
_ => &app.info_style,
})
},
)
});
List::new(events)
.block(Block::default().borders(border::ALL).title("List"))

View file

@ -52,11 +52,13 @@ fn draw(t: &mut Terminal<MouseBackend>, size: &Rect) {
.sizes(&[Size::Percent(100)])
.render(t, &chunks[0], |t, chunks| {
Paragraph::default()
.text("This is a line\n{fg=red This is a line}\n{bg=red This is a \
.text(
"This is a line\n{fg=red This is a line}\n{bg=red This is a \
line}\n{mod=italic This is a line}\n{mod=bold This is a \
line}\n{mod=crossed_out This is a line}\n{mod=invert This is a \
line}\n{mod=underline This is a \
line}\n{bg=green;fg=yellow;mod=italic This is a line}\n")
line}\n{bg=green;fg=yellow;mod=italic This is a line}\n",
)
.render(t, &chunks[0]);
});
});

View file

@ -39,13 +39,13 @@ fn draw(t: &mut Terminal<RustboxBackend>) {
.sizes(&[Size::Percent(100)])
.render(t, &size, |t, chunks| {
Paragraph::default()
.block(Block::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)))
.border_style(Style::default().fg(Color::Magenta)),
)
.text("It {yellow works}!")
.render(t, &chunks[0]);
});

View file

@ -125,27 +125,29 @@ fn draw(t: &mut Terminal<MouseBackend>, app: &App) {
Group::default()
.direction(Direction::Vertical)
.margin(2)
.sizes(&[Size::Fixed(3), Size::Fixed(3), Size::Fixed(7), Size::Min(0)])
.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]);

View file

@ -13,8 +13,10 @@ use self::log4rs::config::{Appender, Config, Root};
pub fn setup_log(file_name: &str) {
let log = FileAppender::builder()
.encoder(Box::new(PatternEncoder::new("{l} / {d(%H:%M:%S)} / \
{M}:{L}{n}{m}{n}{n}")))
.encoder(Box::new(PatternEncoder::new(
"{l} / {d(%H:%M:%S)} / \
{M}:{L}{n}{m}{n}{n}",
)))
.build(file_name)
.unwrap();

View file

@ -15,7 +15,8 @@ pub use self::termion::{TermionBackend, MouseBackend, RawBackend};
pub trait Backend {
fn draw<'a, I>(&mut self, content: I) -> Result<(), io::Error>
where I: Iterator<Item = (u16, u16, &'a Cell)>;
where
I: Iterator<Item = (u16, u16, &'a Cell)>;
fn hide_cursor(&mut self) -> Result<(), io::Error>;
fn show_cursor(&mut self) -> Result<(), io::Error>;
fn clear(&mut self) -> Result<(), io::Error>;

View file

@ -28,18 +28,20 @@ impl RustboxBackend {
impl Backend for RustboxBackend {
fn draw<'a, I>(&mut self, content: I) -> Result<(), io::Error>
where I: Iterator<Item = (u16, u16, &'a Cell)>
where
I: Iterator<Item = (u16, u16, &'a Cell)>,
{
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(),
cell.style.bg.into(),
&cell.symbol);
&cell.symbol,
);
}
debug!("{} instructions outputed", inst);
Ok(())

View file

@ -11,7 +11,8 @@ use layout::Rect;
use style::{Style, Color, Modifier};
pub struct TermionBackend<W>
where W: Write
where
W: Write,
{
stdout: W,
}
@ -36,7 +37,8 @@ impl MouseBackend {
}
impl<W> Backend for TermionBackend<W>
where W: Write
where
W: Write,
{
/// Clears the entire screen and move the cursor to the top left of the screen
fn clear(&mut self) -> Result<(), io::Error> {
@ -61,7 +63,8 @@ impl<W> Backend for TermionBackend<W>
}
fn draw<'a, I>(&mut self, content: I) -> Result<(), io::Error>
where I: Iterator<Item = (u16, u16, &'a Cell)>
where
I: Iterator<Item = (u16, u16, &'a Cell)>,
{
let mut string = String::with_capacity(content.size_hint().0 * 3);
let mut style = Style::default();
@ -98,12 +101,14 @@ impl<W> Backend for TermionBackend<W>
inst += 1;
}
debug!("{} instructions outputed.", inst);
write!(self.stdout,
write!(
self.stdout,
"{}{}{}{}",
string,
Color::Reset.termion_fg(),
Color::Reset.termion_bg(),
Modifier::Reset.termion_modifier())?;
Modifier::Reset.termion_modifier()
)?;
Ok(())
}

View file

@ -155,22 +155,29 @@ impl Buffer {
/// Returns the index in the Vec<Cell> for the given (x, y)
pub fn index_of(&self, x: u16, y: u16) -> usize {
debug_assert!(x >= self.area.left() && x < self.area.right() && y >= self.area.top() &&
debug_assert!(
x >= self.area.left() && x < self.area.right() && y >= self.area.top() &&
y < self.area.bottom(),
"Trying to access position outside the buffer: x={}, y={}, area={:?}",
x,
y,
self.area);
self.area
);
((y - self.area.y) * self.area.width + (x - self.area.x)) as usize
}
/// Returns the coordinates of a cell given its index
pub fn pos_of(&self, i: usize) -> (u16, u16) {
debug_assert!(i >= self.content.len(),
debug_assert!(
i >= self.content.len(),
"Trying to get the coords of a cell outside the buffer: i={} len={}",
i,
self.content.len());
(self.area.x + i as u16 % self.area.width, self.area.y + i as u16 / self.area.width)
self.content.len()
);
(
self.area.x + i as u16 % self.area.width,
self.area.y + i as u16 / self.area.width,
)
}
/// Print a string, starting at the position (x, y)

View file

@ -160,22 +160,14 @@ 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 {
@ -189,8 +181,7 @@ 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,
@ -207,8 +198,7 @@ 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,
@ -332,8 +322,9 @@ impl Group {
self
}
pub fn render<F, B>(&self, t: &mut Terminal<B>, area: &Rect, mut f: F)
where B: Backend,
F: FnMut(&mut Terminal<B>, &[Rect])
where
B: Backend,
F: FnMut(&mut Terminal<B>, &[Rect]),
{
let chunks = t.compute_layout(self, area);
f(t, &chunks);

View file

@ -15,7 +15,8 @@ pub struct LayoutEntry {
/// Interface to the terminal backed by Termion
pub struct Terminal<B>
where B: Backend
where
B: Backend,
{
backend: B,
/// Cache to prevent the layout to be computed at each draw call
@ -28,7 +29,8 @@ pub struct Terminal<B>
}
impl<B> Terminal<B>
where B: Backend
where
B: Backend,
{
/// Wrapper around Termion initialization. Each buffer is initialized with a blank string and
/// default colors for the foreground and the background
@ -58,9 +60,11 @@ impl<B> Terminal<B>
.entry((group.clone(), *area))
.or_insert_with(|| {
let chunks = split(area, &group.direction, group.margin, &group.sizes);
debug!("New layout computed:\n* Group = {:?}\n* Chunks = {:?}",
debug!(
"New layout computed:\n* Group = {:?}\n* Chunks = {:?}",
group,
chunks);
chunks
);
LayoutEntry {
chunks: chunks,
hot: true,
@ -92,7 +96,8 @@ impl<B> Terminal<B>
/// Calls the draw method of a given widget on the current buffer
pub fn render<W>(&mut self, widget: &mut W, area: &Rect)
where W: Widget
where
W: Widget,
{
widget.draw(area, &mut self.buffers[self.current]);
}

View file

@ -123,10 +123,13 @@ impl<'a> Widget for BarChart<'a> {
self.background(&chart_area, buf, self.style.bg);
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 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
.iter()
.take(max_index)
@ -147,9 +150,10 @@ 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,
chart_area.top() + j)
.set_symbol(symbol)
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);
}
@ -167,18 +171,22 @@ impl<'a> Widget for BarChart<'a> {
let value_label = &self.values[i];
let width = value_label.width() as u16;
if width < self.bar_width {
buf.set_string(chart_area.left() + i as u16 * (self.bar_width + self.bar_gap) +
buf.set_string(
chart_area.left() + i as u16 * (self.bar_width + self.bar_gap) +
(self.bar_width - width) / 2,
chart_area.bottom() - 2,
value_label,
&self.value_style);
&self.value_style,
);
}
}
buf.set_stringn(chart_area.left() + i as u16 * (self.bar_width + self.bar_gap),
buf.set_stringn(
chart_area.left() + i as u16 * (self.bar_width + self.bar_gap),
chart_area.bottom() - 1,
label,
self.bar_width as usize,
&self.label_style);
&self.label_style,
);
}
}
}

View file

@ -125,17 +125,17 @@ impl<'a> Widget for Block<'a> {
if self.borders.intersects(border::RIGHT) {
let x = area.right() - 1;
for y in area.top()..area.bottom() {
buf.get_mut(x, y)
.set_symbol(line::VERTICAL)
.set_style(self.border_style);
buf.get_mut(x, y).set_symbol(line::VERTICAL).set_style(
self.border_style,
);
}
}
if self.borders.intersects(border::BOTTOM) {
let y = area.bottom() - 1;
for x in area.left()..area.right() {
buf.get_mut(x, y)
.set_symbol(line::HORIZONTAL)
.set_style(self.border_style);
buf.get_mut(x, y).set_symbol(line::HORIZONTAL).set_style(
self.border_style,
);
}
}
@ -174,11 +174,13 @@ impl<'a> Widget for Block<'a> {
0
};
let width = area.width - lx - rx;
buf.set_stringn(area.left() + lx,
buf.set_stringn(
area.left() + lx,
area.top(),
title,
width as usize,
&self.title_style);
&self.title_style,
);
}
}
}

View file

@ -25,8 +25,10 @@ impl Iterator for LineIterator {
type Item = (f64, f64);
fn next(&mut self) -> Option<Self::Item> {
if self.current < self.end {
let pos = (self.x + (self.current * self.dx) / self.end * self.dir_x,
self.y + (self.current * self.dy) / self.end * self.dir_y);
let pos = (
self.x + (self.current * self.dx) / self.end * self.dir_x,
self.y + (self.current * self.dy) / self.end * self.dir_y,
);
self.current += 1.0;
Some(pos)
} else {

View file

@ -12,10 +12,12 @@ use buffer::Buffer;
use widgets::{Block, Widget};
use layout::Rect;
pub const DOTS: [[u16; 2]; 4] = [[0x0001, 0x0008],
pub const DOTS: [[u16; 2]; 4] = [
[0x0001, 0x0008],
[0x0002, 0x0010],
[0x0004, 0x0020],
[0x0040, 0x0080]];
[0x0040, 0x0080],
];
pub const BRAILLE_OFFSET: u16 = 0x2800;
pub const BRAILLE_BLANK: char = '';
@ -85,16 +87,18 @@ pub struct Context<'a> {
impl<'a> Context<'a> {
/// Draw any object that may implement the Shape trait
pub fn draw<'b, S>(&mut self, shape: &'b S)
where S: Shape<'b>
where
S: Shape<'b>,
{
self.dirty = true;
let left = self.x_bounds[0];
let right = self.x_bounds[1];
let bottom = self.y_bounds[0];
let top = self.y_bounds[1];
for (x, y) in shape
.points()
.filter(|&(x, y)| !(x < left || x > right || y < bottom || y > top)) {
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;
let index = dy / 4 * self.width as usize + dx / 2;
@ -112,8 +116,7 @@ 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,
@ -167,7 +170,8 @@ impl<'a> Context<'a> {
/// # }
/// ```
pub struct Canvas<'a, F>
where F: Fn(&mut Context)
where
F: Fn(&mut Context),
{
block: Option<Block<'a>>,
x_bounds: [f64; 2],
@ -177,7 +181,8 @@ pub struct Canvas<'a, F>
}
impl<'a, F> Default for Canvas<'a, F>
where F: Fn(&mut Context)
where
F: Fn(&mut Context),
{
fn default() -> Canvas<'a, F> {
Canvas {
@ -191,7 +196,8 @@ impl<'a, F> Default for Canvas<'a, F>
}
impl<'a, F> Canvas<'a, F>
where F: Fn(&mut Context)
where
F: Fn(&mut Context),
{
pub fn block(&mut self, block: Block<'a>) -> &mut Canvas<'a, F> {
self.block = Some(block);
@ -219,7 +225,8 @@ impl<'a, F> Canvas<'a, F>
}
impl<'a, F> Widget for Canvas<'a, F>
where F: Fn(&mut Context)
where
F: Fn(&mut Context),
{
fn draw(&mut self, area: &Rect, buf: &mut Buffer) {
let canvas_area = match self.block {
@ -256,7 +263,8 @@ impl<'a, F> Widget for Canvas<'a, F>
.string
.chars()
.zip(layer.colors.into_iter())
.enumerate() {
.enumerate()
{
if ch != BRAILLE_BLANK {
let (x, y) = (i % width, i / width);
buf.get_mut(x as u16 + canvas_area.left(), y as u16 + canvas_area.top())
@ -269,21 +277,23 @@ 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 /
(self.y_bounds[1] - self.y_bounds[0])) as u16;
(self.y_bounds[1] - self.y_bounds[0])) as
u16;
let dx = ((label.x - self.x_bounds[0]) * (canvas_area.width - 1) as f64 /
(self.x_bounds[1] - self.x_bounds[0])) as u16;
buf.set_string(dx + canvas_area.left(),
(self.x_bounds[1] - self.x_bounds[0])) as
u16;
buf.set_string(
dx + canvas_area.left(),
dy + canvas_area.top(),
label.text,
&style.fg(label.color));
&style.fg(label.color),
);
}
}
}

View file

@ -1,6 +1,6 @@
/// Source: http://www.gnuplotting.org/plotting-the-world-revisited/
pub static WORLD_HIGH_RESOLUTION: [(f64, f64); 5125] =
[(-163.71289567772871, -78.595667413241543),
pub static WORLD_HIGH_RESOLUTION: [(f64, f64); 5125] = [
(-163.71289567772871, -78.595667413241543),
(-163.105800951163786, -78.223338718578589),
(-161.245113491846439, -78.380176690584435),
(-160.24620805564453, -78.693645928866943),
@ -5254,9 +5254,11 @@ pub static WORLD_HIGH_RESOLUTION: [(f64, f64); 5125] =
(173.22408328683531, -84.413710219254398),
(175.985671828513034, -84.158997084487751),
(178.277211542063895, -84.472517999202552),
(180.0, -84.71338)];
(180.0, -84.71338),
];
pub static WORLD_LOW_RESOLUTION: [(f64, f64); 1166] = [(-92.32, 48.24),
pub static WORLD_LOW_RESOLUTION: [(f64, f64); 1166] = [
(-92.32, 48.24),
(-88.13, 48.92),
(-83.11, 46.27),
(-81.66, 44.76),
@ -6421,4 +6423,5 @@ pub static WORLD_LOW_RESOLUTION: [(f64, f64); 1166] = [(-92.32, 48.24),
(-161.20, -79.93),
(-163.62, -78.74),
(66.82, 66.82),
(66.82, 66.82)];
(66.82, 66.82),
];

View file

@ -293,11 +293,14 @@ impl<'a> Chart<'a> {
let legend_width = inner_width + 2;
let legend_height = self.datasets.len() as u16 + 2;
if legend_width < layout.graph_area.width / 3 &&
legend_height < layout.graph_area.height / 3 {
layout.legend_area = Some(Rect::new(layout.graph_area.right() - legend_width,
legend_height < layout.graph_area.height / 3
{
layout.legend_area = Some(Rect::new(
layout.graph_area.right() - legend_width,
layout.graph_area.top(),
legend_width,
legend_height));
legend_height,
));
}
}
layout
@ -338,12 +341,13 @@ impl<'a> Widget for Chart<'a> {
let labels_len = labels.len() as u16;
if total_width < graph_area.width && labels_len > 1 {
for (i, label) in labels.iter().enumerate() {
buf.set_string(graph_area.left() +
i as u16 * (graph_area.width - 1) / (labels_len - 1) -
buf.set_string(
graph_area.left() + i as u16 * (graph_area.width - 1) / (labels_len - 1) -
label.width() as u16,
y,
label,
&self.x_axis.labels_style);
&self.x_axis.labels_style,
);
}
}
}
@ -354,10 +358,12 @@ impl<'a> Widget for Chart<'a> {
for (i, label) in labels.iter().enumerate() {
let dy = i as u16 * (graph_area.height - 1) / (labels_len - 1);
if dy < graph_area.bottom() {
buf.set_string(x,
buf.set_string(
x,
graph_area.bottom() - 1 - dy,
label,
&self.y_axis.labels_style);
&self.y_axis.labels_style,
);
}
}
}
@ -389,14 +395,12 @@ 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;
@ -427,14 +431,17 @@ impl<'a> Widget for Chart<'a> {
}
if let Some(legend_area) = layout.legend_area {
Block::default()
.borders(border::ALL)
.draw(&legend_area, buf);
Block::default().borders(border::ALL).draw(
&legend_area,
buf,
);
for (i, dataset) in self.datasets.iter().enumerate() {
buf.set_string(legend_area.x + 1,
buf.set_string(
legend_area.x + 1,
legend_area.y + 1 + i as u16,
dataset.name,
&dataset.style);
&dataset.style,
);
}
}
}

View file

@ -98,9 +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,
);
}
}
}

View file

@ -15,7 +15,8 @@ pub enum Item<'i, D: 'i> {
}
pub struct List<'b, 'i, L, D: 'i>
where L: Iterator<Item = Item<'i, D>>
where
L: Iterator<Item = Item<'i, D>>,
{
block: Option<Block<'b>>,
items: L,
@ -23,7 +24,8 @@ pub struct List<'b, 'i, L, D: 'i>
}
impl<'b, 'i, L, D> Default for List<'b, 'i, L, D>
where L: Iterator<Item = Item<'i, D>> + Default
where
L: Iterator<Item = Item<'i, D>> + Default,
{
fn default() -> List<'b, 'i, L, D> {
List {
@ -35,7 +37,8 @@ impl<'b, 'i, L, D> Default for List<'b, 'i, L, D>
}
impl<'b, 'i, L, D> List<'b, 'i, L, D>
where L: Iterator<Item = Item<'i, D>>
where
L: Iterator<Item = Item<'i, D>>,
{
pub fn new(items: L) -> List<'b, 'i, L, D> {
List {
@ -51,7 +54,8 @@ impl<'b, 'i, L, D> List<'b, 'i, L, D>
}
pub fn items<I>(&'b mut self, items: I) -> &mut List<'b, 'i, L, D>
where I: IntoIterator<Item = Item<'i, D>, IntoIter = L>
where
I: IntoIterator<Item = Item<'i, D>, IntoIter = L>,
{
self.items = items.into_iter();
self
@ -64,8 +68,9 @@ impl<'b, 'i, L, D> List<'b, 'i, L, D>
}
impl<'b, 'i, L, D> Widget for List<'b, 'i, L, D>
where L: Iterator<Item = Item<'i, D>>,
D: Display
where
L: Iterator<Item = Item<'i, D>>,
D: Display,
{
fn draw(&mut self, area: &Rect, buf: &mut Buffer) {
let list_area = match self.block {
@ -82,24 +87,28 @@ impl<'b, 'i, L, D> Widget for List<'b, 'i, L, D>
self.background(&list_area, buf, self.style.bg);
for (i, item) in self.items
.by_ref()
.enumerate()
.take(list_area.height as usize) {
for (i, item) in self.items.by_ref().enumerate().take(
list_area.height as usize,
)
{
match item {
Item::Data(ref v) => {
buf.set_stringn(list_area.left(),
buf.set_stringn(
list_area.left(),
list_area.top() + i as u16,
&format!("{}", v),
list_area.width as usize,
&Style::default());
&Style::default(),
);
}
Item::StyledData(ref v, ref s) => {
buf.set_stringn(list_area.left(),
buf.set_stringn(
list_area.left(),
list_area.top() + i as u16,
&format!("{}", v),
list_area.width as usize,
s);
s,
);
}
};
}
@ -160,7 +169,8 @@ impl<'b> SelectableList<'b> {
}
pub fn items<I>(&'b mut self, items: &'b [I]) -> &mut SelectableList<'b>
where I: AsRef<str> + 'b
where
I: AsRef<str> + 'b,
{
self.items = items.iter().map(|i| i.as_ref()).collect::<Vec<&str>>();
self

View file

@ -84,7 +84,8 @@ impl<'a> Paragraph<'a> {
}
struct Parser<'a, T>
where T: Iterator<Item = &'a str>
where
T: Iterator<Item = &'a str>,
{
text: T,
mark: bool,
@ -96,7 +97,8 @@ struct Parser<'a, T>
}
impl<'a, T> Parser<'a, T>
where T: Iterator<Item = &'a str>
where
T: Iterator<Item = &'a str>,
{
fn new(text: T, base_style: Style) -> Parser<'a, T> {
Parser {
@ -176,7 +178,8 @@ impl<'a, T> Parser<'a, T>
}
impl<'a, T> Iterator for Parser<'a, T>
where T: Iterator<Item = &'a str>
where
T: Iterator<Item = &'a str>,
{
type Item = (&'a str, Style);
fn next(&mut self) -> Option<Self::Item> {

View file

@ -92,14 +92,14 @@ 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)
}) {
})
{
x += 1;
if x > tabs_area.right() {
break;