Apply rustfmt

This commit is contained in:
Alexandre Bury 2016-10-02 15:22:29 -07:00
parent 8fa704bcfa
commit 3b3f403f7a
36 changed files with 197 additions and 217 deletions

View File

@ -1,9 +1,9 @@
use backend;
use event::{Event, Key};
use theme::{BaseColor, Color, ColorStyle, Effect};
use utf8;
use ncurses;
use theme::{BaseColor, Color, ColorStyle, Effect};
use utf8;
pub struct NcursesBackend;

View File

@ -13,10 +13,10 @@
//! [global callback](../struct.Cursive.html#method.add_global_callback)
//! table is checked.
use std::rc::Rc;
use std::ops::Deref;
use Cursive;
use std::ops::Deref;
use std::rc::Rc;
/// Callback is a function that can be triggered by an event.
/// It has a mutable access to the cursive root.

View File

@ -104,22 +104,25 @@ mod utf8;
mod backend;
pub use xy::XY;
pub use with::With;
pub use printer::Printer;
use backend::{Backend, NcursesBackend};
use view::Finder;
use std::sync::mpsc;
use event::{Callback, Event, EventResult};
pub use printer::Printer;
use std::any::Any;
use std::collections::HashMap;
use std::path::Path;
use vec::Vec2;
use view::View;
use std::sync::mpsc;
use vec::Vec2;
use view::Finder;
use view::View;
pub use with::With;
pub use xy::XY;
use event::{Callback, Event, EventResult};
/// Identifies a screen in the cursive ROOT.
pub type ScreenId = usize;
@ -467,11 +470,7 @@ impl Cursive {
// Draw the currently active screen
// If the menubar is active, nothing else can be.
let offset = if self.menubar.autohide {
0
} else {
1
};
let offset = if self.menubar.autohide { 0 } else { 1 };
// Draw the menubar?
if self.menubar.visible() {
let printer = printer.sub_printer(Vec2::zero(),

View File

@ -12,10 +12,10 @@
//!
//! [menubar]: ../struct.Cursive.html#method.menubar
use With;
use Cursive;
use std::rc::Rc;
use With;
use event::Callback;
use std::rc::Rc;
/// Root of a menu tree.
#[derive(Default)]

View File

@ -1,14 +1,14 @@
//! Makes drawing on ncurses windows easier.
use B;
use backend::Backend;
use std::cmp::min;
use theme::{BorderStyle, ColorStyle, Effect, Theme};
use unicode_segmentation::UnicodeSegmentation;
use utils::prefix_length;
use backend::Backend;
use B;
use theme::{BorderStyle, ColorStyle, Effect, Theme};
use vec::Vec2;
/// Convenient interface to draw on a subset of the screen.

View File

@ -114,17 +114,17 @@
//! highlight_inactive = "#5555FF"
//! ```
use std::io;
use std::io::Read;
use std::fs::File;
use std::path::Path;
use backend::Backend;
use toml;
use B;
use backend::Backend;
use std::fs::File;
use std::io;
use std::io::Read;
use std::path::Path;
use toml;
/// Text effect
#[derive(Clone, Copy, Debug)]
pub enum Effect {

View File

@ -1,7 +1,8 @@
use unicode_width::UnicodeWidthStr;
use unicode_segmentation::UnicodeSegmentation;
use With;
use unicode_segmentation::UnicodeSegmentation;
use unicode_width::UnicodeWidthStr;
use utils::prefix_length;
/// Generates rows of text in constrained width.

View File

@ -1,7 +1,7 @@
//! Toolbox to make text layout easier.
use unicode_width::UnicodeWidthStr;
use unicode_segmentation::UnicodeSegmentation;
use unicode_width::UnicodeWidthStr;
mod lines_iterator;
mod reader;
@ -55,11 +55,7 @@ pub fn prefix_length<'a, I>(iter: I, width: usize, delimiter: &str) -> usize
// We counted delimiter once too many times,
// but only if the iterator was non empty.
if sum == 0 {
sum
} else {
sum - delimiter_len
}
if sum == 0 { sum } else { sum - delimiter_len }
}
/// Computes the length of a suffix that fits in the given `width`.

View File

@ -1,9 +1,10 @@
//! Points on the 2D character grid.
use XY;
use direction::Orientation;
use std::cmp::{Ordering, max, min};
use std::ops::{Add, Div, Mul, Sub};
use std::cmp::{Ordering, max, min};
/// Simple 2D size, in cells.
///

View File

@ -1,6 +1,6 @@
use vec::Vec2;
use view::{SizeConstraint, View};
use views::BoxView;
use vec::Vec2;
/// Makes a view wrappable in a [`BoxView`].
///

View File

@ -1,5 +1,5 @@
use views::IdView;
use view::View;
use views::IdView;
/// Makes a view wrappable in an [`IdView`].
///

View File

@ -50,12 +50,12 @@ mod identifiable;
mod boxable;
use std::any::Any;
use Printer;
use direction::Direction;
use event::{Event, EventResult};
use vec::Vec2;
use Printer;
pub use self::boxable::Boxable;
pub use self::identifiable::Identifiable;
pub use self::position::{Offset, Position};
@ -65,8 +65,8 @@ pub use self::size_cache::SizeCache;
pub use self::size_constraint::SizeConstraint;
pub use self::view_path::ViewPath;
pub use self::view_wrapper::ViewWrapper;
pub use self::identifiable::Identifiable;
pub use self::boxable::Boxable;
use std::any::Any;
use vec::Vec2;
/// Main trait defining a view behaviour.

View File

@ -1,5 +1,5 @@
use std::cmp::min;
use XY;
use std::cmp::min;
use vec::Vec2;
/// Location of the view on screen
@ -60,7 +60,8 @@ pub enum Offset {
impl Offset {
/// Computes a single-dimension offset requred to draw a view.
pub fn compute_offset(&self, size: usize, available: usize, parent: usize)
pub fn compute_offset(&self, size: usize, available: usize,
parent: usize)
-> usize {
if size > available {
0
@ -79,17 +80,17 @@ impl Offset {
#[cfg(test)]
mod tests {
use vec::Vec2;
use super::Position;
use vec::Vec2;
#[test]
fn test_center() {
let center = Position::center();
assert_eq!(Vec2::new(2, 1), center.compute_offset((1,1), (5,3), (0,0)));
assert_eq!(Vec2::new(2, 0), center.compute_offset((1,3), (5,3), (0,0)));
assert_eq!(Vec2::new(1, 1), center.compute_offset((3,1), (5,3), (0,0)));
assert_eq!(Vec2::new(0, 1), center.compute_offset((5,1), (5,3), (0,0)));
assert_eq!(Vec2::new(0, 0), center.compute_offset((5,3), (5,3), (0,0)));
assert_eq!(Vec2::new(0, 0), center.compute_offset((5,3), (3,1), (0,0)));
let c = Position::center();
assert_eq!(Vec2::new(2, 1), c.compute_offset((1, 1), (5, 3), (0, 0)));
assert_eq!(Vec2::new(2, 0), c.compute_offset((1, 3), (5, 3), (0, 0)));
assert_eq!(Vec2::new(1, 1), c.compute_offset((3, 1), (5, 3), (0, 0)));
assert_eq!(Vec2::new(0, 1), c.compute_offset((5, 1), (5, 3), (0, 0)));
assert_eq!(Vec2::new(0, 0), c.compute_offset((5, 3), (5, 3), (0, 0)));
assert_eq!(Vec2::new(0, 0), c.compute_offset((5, 3), (3, 1), (0, 0)));
}
}

View File

@ -1,8 +1,8 @@
use Printer;
use std::cmp::{max, min};
use theme::ColorStyle;
use vec::Vec2;
use Printer;
/// Provide scrolling functionalities to a view.
///

View File

@ -1,10 +1,10 @@
use std::any::Any;
use Printer;
use direction::Direction;
use event::{Event, EventResult};
use std::any::Any;
use vec::Vec2;
use view::{Selector, View};
use Printer;
use event::{Event, EventResult};
/// Generic wrapper around a view.
///

View File

@ -38,7 +38,8 @@ impl<T: View> BoxView<T> {
/// Creates a new `BoxView` with the given width and height requirements.
///
/// `None` values will use the wrapped view's preferences.
pub fn new(width: SizeConstraint, height: SizeConstraint, view: T) -> Self {
pub fn new(width: SizeConstraint, height: SizeConstraint, view: T)
-> Self {
BoxView {
size: (width, height).into(),
squishable: false,

View File

@ -1,10 +1,11 @@
use unicode_width::UnicodeWidthStr;
use {Cursive, Printer, With};
use align::HAlign;
use event::*;
use direction::Direction;
use event::*;
use theme::ColorStyle;
use unicode_width::UnicodeWidthStr;
use vec::Vec2;
use view::View;

View File

@ -1,13 +1,13 @@
use With;
use Cursive;
use Printer;
use vec::Vec2;
use theme::ColorStyle;
use view::View;
use event::{Event, EventResult, Key};
use With;
use direction::Direction;
use event::{Event, EventResult, Key};
use std::rc::Rc;
use theme::ColorStyle;
use vec::Vec2;
use view::View;
/// Checkable box.

View File

@ -1,18 +1,19 @@
use std::cmp::max;
use std::any::Any;
use Cursive;
use With;
use direction::Direction;
use align::*;
use event::*;
use theme::ColorStyle;
use view::{Selector, View};
use views::{Button, DummyView, SizedView, TextView};
use vec::{Vec2, Vec4};
use Printer;
use With;
use align::*;
use direction::Direction;
use event::*;
use std::any::Any;
use std::cmp::max;
use theme::ColorStyle;
use unicode_width::UnicodeWidthStr;
use vec::{Vec2, Vec4};
use view::{Selector, View};
use views::{Button, DummyView, SizedView, TextView};
#[derive(PartialEq)]
enum Focus {

View File

@ -1,15 +1,16 @@
use unicode_segmentation::UnicodeSegmentation;
use unicode_width::UnicodeWidthStr;
use std::rc::Rc;
use {Cursive, Printer, With};
use direction::Direction;
use event::{Callback, Event, EventResult, Key};
use std::rc::Rc;
use theme::{ColorStyle, Effect};
use unicode_segmentation::UnicodeSegmentation;
use unicode_width::UnicodeWidthStr;
use utils::simple_suffix_length;
use vec::Vec2;
use view::View;
use event::{Callback, Event, EventResult, Key};
use utils::simple_suffix_length;
/// Input box where the user can enter and edit text.
@ -289,11 +290,7 @@ impl View for EditView {
let display_bytes = content.graphemes(true)
.scan(0, |w, g| {
*w += g.width();
if *w > self.last_length {
None
} else {
Some(g)
}
if *w > self.last_length { None } else { Some(g) }
})
.map(|g| g.len())
.fold(0, |a, b| a + b);

View File

@ -1,7 +1,8 @@
use std::collections::HashMap;
use Cursive;
use event::{Callback, Event, EventResult};
use std::collections::HashMap;
use view::{View, ViewWrapper};
/// A simple wrapper view that catches some ignored event from its child.

View File

@ -1,14 +1,14 @@
use XY;
use With;
use direction;
use view::View;
use view::{Selector, SizeCache};
use vec::Vec2;
use Printer;
use With;
use XY;
use direction;
use event::{Event, EventResult, Key};
use std::any::Any;
use std::cmp::min;
use vec::Vec2;
use view::{Selector, SizeCache};
use view::View;
/// Arranges its children linearly according to its orientation.
pub struct LinearLayout {
@ -120,11 +120,7 @@ impl LinearLayout {
match source {
direction::Relative::Front => {
let start = if from_focus {
self.focus
} else {
0
};
let start = if from_focus { self.focus } else { 0 };
Box::new(self.children.iter_mut().enumerate().skip(start))
}
@ -263,11 +259,7 @@ impl View for LinearLayout {
let mut overweight: Vec<(usize, usize)> = sizes.iter()
.map(|v| self.orientation.get(v))
.zip(min_sizes.iter().map(|v| self.orientation.get(v)))
.map(|(a, b)| if a > b {
a - b
} else {
0
})
.map(|(a, b)| if a > b { a - b } else { 0 })
.enumerate()
.collect();
// println_stderr!("Overweight: {:?}", overweight);

View File

@ -1,13 +1,13 @@
use Printer;
use With;
use vec::Vec2;
use view::View;
use view::Selector;
use direction;
use view::ScrollBase;
use event::{Event, EventResult, Key};
use std::any::Any;
use vec::Vec2;
use view::ScrollBase;
use view::Selector;
use view::View;
enum Child {
Row(String, Box<View>),
@ -84,11 +84,7 @@ impl ListView {
match source {
direction::Relative::Front => {
let start = if from_focus {
self.focus
} else {
0
};
let start = if from_focus { self.focus } else { 0 };
Box::new(self.children.iter_mut().enumerate().skip(start))
}

View File

@ -1,17 +1,18 @@
use std::rc::Rc;
use std::cmp::min;
use unicode_width::UnicodeWidthStr;
use Cursive;
use With;
use menu::{MenuItem, MenuTree};
use Printer;
use With;
use align::Align;
use event::{Callback, Event, EventResult, Key};
use menu::{MenuItem, MenuTree};
use std::cmp::min;
use std::rc::Rc;
use unicode_width::UnicodeWidthStr;
use vec::Vec2;
use view::{Position, ScrollBase, View};
use views::KeyEventView;
use align::Align;
use vec::Vec2;
use event::{Callback, Event, EventResult, Key};
/// Popup that shows a list of items.
pub struct MenuPopup {
@ -205,11 +206,7 @@ impl View for MenuPopup {
let scrolling = req.y < h;
let w = if scrolling {
w + 1
} else {
w
};
let w = if scrolling { w + 1 } else { w };
Vec2::new(w, h)
}

View File

@ -1,17 +1,17 @@
use Cursive;
use view::{Position, View};
use vec::Vec2;
use direction;
use menu::MenuTree;
use backend::Backend;
use views::{KeyEventView, MenuPopup};
use theme::ColorStyle;
use Printer;
use backend::Backend;
use direction;
use event::*;
use menu::MenuTree;
use std::rc::Rc;
use theme::ColorStyle;
use unicode_width::UnicodeWidthStr;
use vec::Vec2;
use view::{Position, View};
use views::{KeyEventView, MenuPopup};
/// Current state of the menubar
#[derive(PartialEq, Debug)]
@ -169,11 +169,7 @@ impl View for Menubar {
.iter()
.map(|&(ref title, _)| title.width() + 2)
.fold(0, |a, b| a + b),
if self.autohide {
1
} else {
0
});
if self.autohide { 1 } else { 0 });
// Since the closure will be called multiple times,
// we also need a new Rc on every call.
return EventResult::with_cb(move |s| {

View File

@ -58,25 +58,25 @@ mod text_area;
mod text_view;
mod tracked_view;
pub use self::id_view::IdView;
pub use self::box_view::BoxView;
pub use self::button::Button;
pub use self::checkbox::Checkbox;
pub use self::dialog::Dialog;
pub use self::dummy::DummyView;
pub use self::edit_view::EditView;
pub use self::id_view::IdView;
pub use self::key_event_view::KeyEventView;
pub use self::linear_layout::LinearLayout;
pub use self::list_view::ListView;
pub use self::menubar::Menubar;
pub use self::menu_popup::MenuPopup;
pub use self::menubar::Menubar;
pub use self::panel::Panel;
pub use self::progress_bar::{Counter, ProgressBar};
pub use self::radio::{RadioGroup, RadioButton};
pub use self::select_view::SelectView;
pub use self::slider_view::SliderView;
pub use self::shadow_view::ShadowView;
pub use self::sized_view::SizedView;
pub use self::slider_view::SliderView;
pub use self::stack_view::StackView;
pub use self::text_area::TextArea;
pub use self::text_view::TextView;

View File

@ -1,11 +1,12 @@
use std::sync::Arc;
use std::thread;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::cmp;
use {Cursive, Printer};
use align::HAlign;
use std::cmp;
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::thread;
use theme::{ColorStyle, Effect};
use view::View;

View File

@ -1,12 +1,12 @@
use {Printer, With};
use vec::Vec2;
use view::View;
use theme::ColorStyle;
use event::{Event, EventResult, Key};
use direction::Direction;
use event::{Event, EventResult, Key};
use std::cell::RefCell;
use std::rc::Rc;
use theme::ColorStyle;
use vec::Vec2;
use view::View;
struct SharedState<T> {
selection: usize,
@ -98,7 +98,8 @@ pub struct RadioButton<T> {
impl<T> RadioButton<T> {
impl_enabled!(self.enabled);
fn new(state: Rc<RefCell<SharedState<T>>>, id: usize, label: String) -> Self {
fn new(state: Rc<RefCell<SharedState<T>>>, id: usize, label: String)
-> Self {
RadioButton {
state: state,
id: id,

View File

@ -1,21 +1,22 @@
use std::cmp::min;
use std::rc::Rc;
use std::cell::Cell;
use std::borrow::Borrow;
use Cursive;
use With;
use menu::MenuTree;
use direction::Direction;
use view::{Position, ScrollBase, View};
use views::MenuPopup;
use align::{Align, HAlign, VAlign};
use event::{Callback, Event, EventResult, Key};
use theme::ColorStyle;
use vec::Vec2;
use Printer;
use With;
use align::{Align, HAlign, VAlign};
use direction::Direction;
use event::{Callback, Event, EventResult, Key};
use menu::MenuTree;
use std::borrow::Borrow;
use std::cell::Cell;
use std::cmp::min;
use std::rc::Rc;
use theme::ColorStyle;
use unicode_width::UnicodeWidthStr;
use vec::Vec2;
use view::{Position, ScrollBase, View};
use views::MenuPopup;
/// View to select an item among a list.
///
@ -394,11 +395,7 @@ impl<T: 'static> View for SelectView<T> {
let scrolling = req.y < h;
// Add 2 spaces for the scrollbar if we need
let w = if scrolling {
w + 2
} else {
w
};
let w = if scrolling { w + 2 } else { w };
Vec2::new(w, h)
}

View File

@ -1,7 +1,7 @@
use view::{View, ViewWrapper};
use Printer;
use vec::Vec2;
use theme::ColorStyle;
use vec::Vec2;
use view::{View, ViewWrapper};
/// Wrapper view that adds a shadow.
///

View File

@ -1,5 +1,5 @@
use view::View;
use vec::Vec2;
use view::View;
use view::ViewWrapper;
/// Wrapper around a view that remembers its size.

View File

@ -1,12 +1,12 @@
use std::rc::Rc;
use {Cursive, Printer};
use With;
use {Cursive, Printer};
use theme::ColorStyle;
use direction::{Direction, Orientation};
use event::{Callback, Event, EventResult, Key};
use std::rc::Rc;
use theme::ColorStyle;
use vec::Vec2;
use view::View;
use direction::{Direction, Orientation};
/// A horizontal or vertical slider.
pub struct SliderView {

View File

@ -1,13 +1,13 @@
use std::any::Any;
use Printer;
use backend::Backend;
use direction::Direction;
use backend::Backend;
use event::{Event, EventResult};
use std::any::Any;
use theme::ColorStyle;
use vec::Vec2;
use view::{Offset, Position, Selector, View};
use views::ShadowView;
use event::{Event, EventResult};
use Printer;
use theme::ColorStyle;
/// Simple stack of views.
/// Only the top-most view is active and can receive input.

View File

@ -1,14 +1,15 @@
use unicode_segmentation::UnicodeSegmentation;
use unicode_width::UnicodeWidthStr;
use odds::vec::VecExt;
use {Printer, With, XY};
use direction::Direction;
use vec::Vec2;
use event::{Event, EventResult, Key};
use utils::{LinesIterator, Row, prefix_length};
use view::{ScrollBase, SizeCache, View};
use odds::vec::VecExt;
use theme::{ColorStyle, Effect};
use unicode_segmentation::UnicodeSegmentation;
use unicode_width::UnicodeWidthStr;
use utils::{LinesIterator, Row, prefix_length};
use vec::Vec2;
use view::{ScrollBase, SizeCache, View};
/// Multi-lines text editor.
///

View File

@ -1,17 +1,17 @@
use XY;
use With;
use direction::Direction;
use vec::Vec2;
use view::{SizeCache, View};
use Printer;
use With;
use XY;
use align::*;
use direction::Direction;
use event::*;
use view::ScrollBase;
use utils::{LinesIterator, Row};
use unicode_width::UnicodeWidthStr;
use utils::{LinesIterator, Row};
use vec::Vec2;
use view::{SizeCache, View};
use view::ScrollBase;
/// A simple view showing a fixed text
pub struct TextView {

View File

@ -1,9 +1,9 @@
use Printer;
use std::cell::Cell;
use vec::Vec2;
use view::{View, ViewWrapper};
use views::IdView;
use Printer;
use vec::Vec2;
/// Wrapper around a view that remembers its position.
pub struct TrackedView<T: View> {