From 8522e028f14c7634574a916d515f9bfad8ea8395 Mon Sep 17 00:00:00 2001 From: Karoline Pauls Date: Fri, 7 Dec 2018 15:17:33 +0000 Subject: [PATCH] Run `cargo fmt` with the new Rust stable toolchain (1.31.0) --- examples/barchart.rs | 8 +++++--- examples/block.rs | 11 +++++++---- examples/canvas.rs | 6 ++++-- examples/chart.rs | 20 +++++++++++++------- examples/crossterm.rs | 3 ++- examples/custom_widget.rs | 8 +++++--- examples/demo.rs | 37 ++++++++++++++++++++++++------------- examples/gauge.rs | 13 ++++++++----- examples/layout.rs | 13 ++++++++----- examples/paragraph.rs | 13 ++++++++----- examples/rustbox.rs | 11 +++++++---- examples/sparkline.rs | 22 ++++++++++++++-------- examples/table.rs | 12 +++++++----- src/layout.rs | 3 ++- src/widgets/barchart.rs | 3 ++- src/widgets/chart.rs | 39 +++++++++++++++++++++------------------ src/widgets/list.rs | 3 ++- tests/block.rs | 3 ++- tests/gauge.rs | 3 ++- 19 files changed, 143 insertions(+), 88 deletions(-) diff --git a/examples/barchart.rs b/examples/barchart.rs index a2496a9d..3a0c94d0 100644 --- a/examples/barchart.rs +++ b/examples/barchart.rs @@ -117,9 +117,11 @@ fn main() -> Result<(), failure::Error> { })?; match events.next()? { - Event::Input(input) => if input == Key::Char('q') { - break; - }, + Event::Input(input) => { + if input == Key::Char('q') { + break; + } + } Event::Tick => { app.update(); } diff --git a/examples/block.rs b/examples/block.rs index 17bd7cc4..3d88ccd2 100644 --- a/examples/block.rs +++ b/examples/block.rs @@ -60,7 +60,8 @@ fn main() -> Result<(), failure::Error> { .fg(Color::White) .bg(Color::Red) .modifier(Modifier::Bold), - ).render(&mut f, chunks[1]); + ) + .render(&mut f, chunks[1]); } { let chunks = Layout::default() @@ -80,9 +81,11 @@ fn main() -> Result<(), failure::Error> { })?; match events.next()? { - Event::Input(key) => if key == Key::Char('q') { - break; - }, + Event::Input(key) => { + if key == Key::Char('q') { + break; + } + } _ => {} } } diff --git a/examples/canvas.rs b/examples/canvas.rs index c443a1b5..0f5345f7 100644 --- a/examples/canvas.rs +++ b/examples/canvas.rs @@ -105,7 +105,8 @@ fn main() -> Result<(), failure::Error> { resolution: MapResolution::High, }); ctx.print(app.x, -app.y, "You are here", Color::Yellow); - }).x_bounds([-180.0, 180.0]) + }) + .x_bounds([-180.0, 180.0]) .y_bounds([-90.0, 90.0]) .render(&mut f, chunks[0]); Canvas::default() @@ -139,7 +140,8 @@ fn main() -> Result<(), failure::Error> { y2: f64::from(app.ball.top()), color: Color::Yellow, }); - }).x_bounds([10.0, 110.0]) + }) + .x_bounds([10.0, 110.0]) .y_bounds([10.0, 110.0]) .render(&mut f, chunks[1]); })?; diff --git a/examples/chart.rs b/examples/chart.rs index e70a868b..f63b1573 100644 --- a/examples/chart.rs +++ b/examples/chart.rs @@ -80,7 +80,8 @@ fn main() -> Result<(), failure::Error> { .title("Chart") .title_style(Style::default().fg(Color::Cyan).modifier(Modifier::Bold)) .borders(Borders::ALL), - ).x_axis( + ) + .x_axis( Axis::default() .title("X Axis") .style(Style::default().fg(Color::Gray)) @@ -91,14 +92,16 @@ fn main() -> Result<(), failure::Error> { &format!("{}", (app.window[0] + app.window[1]) / 2.0), &format!("{}", app.window[1]), ]), - ).y_axis( + ) + .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(&[ + ) + .datasets(&[ Dataset::default() .name("data2") .marker(Marker::Dot) @@ -109,13 +112,16 @@ fn main() -> Result<(), failure::Error> { .marker(Marker::Braille) .style(Style::default().fg(Color::Yellow)) .data(&app.data2), - ]).render(&mut f, size); + ]) + .render(&mut f, size); })?; match events.next()? { - Event::Input(input) => if input == Key::Char('q') { - break; - }, + Event::Input(input) => { + if input == Key::Char('q') { + break; + } + } Event::Tick => { app.update(); } diff --git a/examples/crossterm.rs b/examples/crossterm.rs index 66d72381..e62f6d25 100644 --- a/examples/crossterm.rs +++ b/examples/crossterm.rs @@ -27,7 +27,8 @@ fn main() -> Result<(), failure::Error> { .title_style(Style::default().fg(Color::Yellow).modifier(Modifier::Bold)) .borders(Borders::ALL) .border_style(Style::default().fg(Color::Magenta)), - ).render(&mut f, size); + ) + .render(&mut f, size); })?; let input = crossterm::input(); diff --git a/examples/custom_widget.rs b/examples/custom_widget.rs index 0c0a72fe..8ea1acbe 100644 --- a/examples/custom_widget.rs +++ b/examples/custom_widget.rs @@ -61,9 +61,11 @@ fn main() -> Result<(), failure::Error> { })?; match events.next()? { - Event::Input(key) => if key == Key::Char('q') { - break; - }, + Event::Input(key) => { + if key == Key::Char('q') { + break; + } + } _ => {} } } diff --git a/examples/demo.rs b/examples/demo.rs index 4d319c25..14a24ec3 100644 --- a/examples/demo.rs +++ b/examples/demo.rs @@ -199,9 +199,11 @@ fn main() -> Result<(), failure::Error> { app.selected -= 1 }; } - Key::Down => if app.selected < app.items.len() - 1 { - app.selected += 1; - }, + Key::Down => { + if app.selected < app.items.len() - 1 { + app.selected += 1; + } + } Key::Left => { app.tabs.previous(); } @@ -255,8 +257,9 @@ where Constraint::Min(7), Constraint::Length(7), ] - .as_ref(), - ).split(area); + .as_ref(), + ) + .split(area); draw_gauges(f, app, chunks[0]); draw_charts(f, app, chunks[1]); draw_text(f, chunks[2]); @@ -281,7 +284,8 @@ where .fg(Color::Magenta) .bg(Color::Black) .modifier(Modifier::Italic), - ).label(&format!("{} / 100", app.progress)) + ) + .label(&format!("{} / 100", app.progress)) .percent(app.progress) .render(f, chunks[0]); Sparkline::default() @@ -349,7 +353,8 @@ where .fg(Color::Black) .bg(Color::Green) .modifier(Modifier::Italic), - ).label_style(Style::default().fg(Color::Yellow)) + ) + .label_style(Style::default().fg(Color::Yellow)) .style(Style::default().fg(Color::Green)) .render(f, chunks[1]); } @@ -360,7 +365,8 @@ where .title("Chart") .title_style(Style::default().fg(Color::Cyan).modifier(Modifier::Bold)) .borders(Borders::ALL), - ).x_axis( + ) + .x_axis( Axis::default() .title("X Axis") .style(Style::default().fg(Color::Gray)) @@ -371,14 +377,16 @@ where &format!("{}", (app.window[0] + app.window[1]) / 2.0), &format!("{}", app.window[1]), ]), - ).y_axis( + ) + .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(&[ + ) + .datasets(&[ Dataset::default() .name("data2") .marker(Marker::Dot) @@ -389,7 +397,8 @@ where .marker(Marker::Braille) .style(Style::default().fg(Color::Yellow)) .data(&app.data3), - ]).render(f, chunks[1]); + ]) + .render(f, chunks[1]); } } @@ -420,7 +429,8 @@ where .borders(Borders::ALL) .title("Footer") .title_style(Style::default().fg(Color::Magenta).modifier(Modifier::Bold)), - ).wrap(true) + ) + .wrap(true) .render(f, area); } @@ -476,7 +486,8 @@ where }; ctx.print(server.coords.1, server.coords.0, "X", color); } - }).x_bounds([-180.0, 180.0]) + }) + .x_bounds([-180.0, 180.0]) .y_bounds([-90.0, 90.0]) .render(f, chunks[1]); } diff --git a/examples/gauge.rs b/examples/gauge.rs index cc2805db..4e7d3187 100644 --- a/examples/gauge.rs +++ b/examples/gauge.rs @@ -83,8 +83,9 @@ fn main() -> Result<(), failure::Error> { Constraint::Percentage(25), Constraint::Percentage(25), ] - .as_ref(), - ).split(size); + .as_ref(), + ) + .split(size); Gauge::default() .block(Block::default().title("Gauge1").borders(Borders::ALL)) @@ -111,9 +112,11 @@ fn main() -> Result<(), failure::Error> { })?; match events.next()? { - Event::Input(input) => if input == Key::Char('q') { - break; - }, + Event::Input(input) => { + if input == Key::Char('q') { + break; + } + } Event::Tick => { app.update(); } diff --git a/examples/layout.rs b/examples/layout.rs index c174df5f..899c80e1 100644 --- a/examples/layout.rs +++ b/examples/layout.rs @@ -45,8 +45,9 @@ fn main() -> Result<(), failure::Error> { Constraint::Percentage(80), Constraint::Percentage(10), ] - .as_ref(), - ).split(size); + .as_ref(), + ) + .split(size); Block::default() .title("Block") @@ -59,9 +60,11 @@ fn main() -> Result<(), failure::Error> { })?; match events.next()? { - Event::Input(input) => if let Key::Char('q') = input { - break; - }, + Event::Input(input) => { + if let Key::Char('q') = input { + break; + } + } _ => {} } } diff --git a/examples/paragraph.rs b/examples/paragraph.rs index 7b379aaf..a3d1a4eb 100644 --- a/examples/paragraph.rs +++ b/examples/paragraph.rs @@ -51,8 +51,9 @@ fn main() -> Result<(), failure::Error> { Constraint::Percentage(30), Constraint::Percentage(30), ] - .as_ref(), - ).split(size); + .as_ref(), + ) + .split(size); let text = [ Text::raw("This a line\n"), @@ -83,9 +84,11 @@ fn main() -> Result<(), failure::Error> { })?; match events.next()? { - Event::Input(key) => if key == Key::Char('q') { - break; - }, + Event::Input(key) => { + if key == Key::Char('q') { + break; + } + } _ => {} } } diff --git a/examples/rustbox.rs b/examples/rustbox.rs index 6d6e0640..8564d585 100644 --- a/examples/rustbox.rs +++ b/examples/rustbox.rs @@ -16,9 +16,11 @@ fn main() -> Result<(), failure::Error> { loop { draw(&mut terminal)?; match terminal.backend().rustbox().poll_event(false) { - Ok(rustbox::Event::KeyEvent(key)) => if key == Key::Char('q') { - break; - }, + Ok(rustbox::Event::KeyEvent(key)) => { + if key == Key::Char('q') { + break; + } + } Err(e) => panic!("{}", e.description()), _ => {} }; @@ -41,6 +43,7 @@ fn draw(t: &mut Terminal) -> Result<(), std::io::Error> { .title_style(Style::default().fg(Color::Yellow).modifier(Modifier::Bold)) .borders(Borders::ALL) .border_style(Style::default().fg(Color::Magenta)), - ).render(&mut f, size) + ) + .render(&mut f, size) }) } diff --git a/examples/sparkline.rs b/examples/sparkline.rs index 83f1a314..19504442 100644 --- a/examples/sparkline.rs +++ b/examples/sparkline.rs @@ -83,14 +83,16 @@ fn main() -> Result<(), failure::Error> { Constraint::Length(7), Constraint::Min(0), ] - .as_ref(), - ).split(size); + .as_ref(), + ) + .split(size); Sparkline::default() .block( Block::default() .title("Data1") .borders(Borders::LEFT | Borders::RIGHT), - ).data(&app.data1) + ) + .data(&app.data1) .style(Style::default().fg(Color::Yellow)) .render(&mut f, chunks[0]); Sparkline::default() @@ -98,7 +100,8 @@ fn main() -> Result<(), failure::Error> { Block::default() .title("Data2") .borders(Borders::LEFT | Borders::RIGHT), - ).data(&app.data2) + ) + .data(&app.data2) .style(Style::default().bg(Color::Green)) .render(&mut f, chunks[1]); // Multiline @@ -107,15 +110,18 @@ fn main() -> Result<(), failure::Error> { Block::default() .title("Data3") .borders(Borders::LEFT | Borders::RIGHT), - ).data(&app.data3) + ) + .data(&app.data3) .style(Style::default().fg(Color::Red)) .render(&mut f, chunks[2]); })?; match events.next()? { - Event::Input(input) => if input == Key::Char('q') { - break; - }, + Event::Input(input) => { + if input == Key::Char('q') { + break; + } + } Event::Tick => { app.update(); } diff --git a/examples/table.rs b/examples/table.rs index 2ee7f89b..e5bef95a 100644 --- a/examples/table.rs +++ b/examples/table.rs @@ -91,11 +91,13 @@ fn main() -> Result<(), failure::Error> { app.selected = 0; } } - Key::Up => if app.selected > 0 { - app.selected -= 1; - } else { - app.selected = app.items.len() - 1; - }, + Key::Up => { + if app.selected > 0 { + app.selected -= 1; + } else { + app.selected = app.items.len() - 1; + } + } _ => {} }, _ => {} diff --git a/src/layout.rs b/src/layout.rs index 0253e974..160e2b67 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -379,7 +379,8 @@ fn test_rect_size_truncation() { // but let's make sure the ratios don't diverge crazily. assert!( (f64::from(rect.width) / f64::from(rect.height) - - f64::from(width) / f64::from(height)).abs() + - f64::from(width) / f64::from(height)) + .abs() < 1.0 ) } diff --git a/src/widgets/barchart.rs b/src/widgets/barchart.rs index 98274f64..00909a2e 100644 --- a/src/widgets/barchart.rs +++ b/src/widgets/barchart.rs @@ -154,7 +154,8 @@ impl<'a> Widget for BarChart<'a> { buf.get_mut( chart_area.left() + i as u16 * (self.bar_width + self.bar_gap) + x, chart_area.top() + j, - ).set_symbol(symbol) + ) + .set_symbol(symbol) .set_style(self.style); } diff --git a/src/widgets/chart.rs b/src/widgets/chart.rs index c21384bb..4010fe82 100644 --- a/src/widgets/chart.rs +++ b/src/widgets/chart.rs @@ -428,24 +428,26 @@ where for dataset in self.datasets { match dataset.marker { - Marker::Dot => 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) * f64::from(graph_area.height - 1) - / (self.y_axis.bounds[1] - self.y_axis.bounds[0])) - as u16; - let dx = ((x - self.x_axis.bounds[0]) * f64::from(graph_area.width - 1) - / (self.x_axis.bounds[1] - self.x_axis.bounds[0])) - as u16; + Marker::Dot => { + 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) * f64::from(graph_area.height - 1) + / (self.y_axis.bounds[1] - self.y_axis.bounds[0])) + as u16; + let dx = ((x - self.x_axis.bounds[0]) * f64::from(graph_area.width - 1) + / (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) - .set_fg(dataset.style.fg) - .set_bg(dataset.style.bg); - }, + buf.get_mut(graph_area.left() + dx, graph_area.top() + dy) + .set_symbol(symbols::DOT) + .set_fg(dataset.style.fg) + .set_bg(dataset.style.bg); + } + } Marker::Braille => { Canvas::default() .background_color(self.style.bg) @@ -456,7 +458,8 @@ where coords: dataset.data, color: dataset.style.fg, }); - }).draw(graph_area, buf); + }) + .draw(graph_area, buf); } } } diff --git a/src/widgets/list.rs b/src/widgets/list.rs index 84428c49..d9c3955d 100644 --- a/src/widgets/list.rs +++ b/src/widgets/list.rs @@ -236,7 +236,8 @@ impl<'b> Widget for SelectableList<'b> { } else { Text::styled(item, self.style) } - }).skip(offset as usize); + }) + .skip(offset as usize); List::new(items) .block(self.block.unwrap_or_default()) .style(self.style) diff --git a/tests/block.rs b/tests/block.rs index a70c9e08..a1f7cdec 100644 --- a/tests/block.rs +++ b/tests/block.rs @@ -27,7 +27,8 @@ fn it_draws_a_block() { height: 8, }, ); - }).unwrap(); + }) + .unwrap(); let mut expected = Buffer::with_lines(vec![ "┌Title─┐ ", "│ │ ", diff --git a/tests/gauge.rs b/tests/gauge.rs index 073221c1..8d9d07ab 100644 --- a/tests/gauge.rs +++ b/tests/gauge.rs @@ -28,7 +28,8 @@ fn gauge_render() { .block(Block::default().title("Ratio").borders(Borders::ALL)) .ratio(0.2113139343131) .render(&mut f, chunks[1]); - }).unwrap(); + }) + .unwrap(); let expected = Buffer::with_lines(vec![ " ", " ",