This commit is contained in:
Alexandre Bury 2018-01-22 11:55:56 -08:00
parent 98aff39904
commit 3674c118cb
28 changed files with 145 additions and 67 deletions

View File

@ -1,3 +1,4 @@
unstable_features = true
max_width = 79
reorder_imports = true
fn_args_density = "Compressed"

View File

@ -22,7 +22,10 @@ pub struct Concrete {
impl Concrete {
fn blt_keycode_to_ev(
&mut self, kc: KeyCode, shift: bool, ctrl: bool
&mut self,
kc: KeyCode,
shift: bool,
ctrl: bool,
) -> Event {
match kc {
KeyCode::F1

View File

@ -24,7 +24,9 @@ pub struct Concrete {
impl Concrete {
/// Save a new color pair.
fn insert_color(
&self, pairs: &mut HashMap<ColorPair, i16>, pair: ColorPair
&self,
pairs: &mut HashMap<ColorPair, i16>,
pair: ColorPair,
) -> i16 {
let n = 1 + pairs.len() as i16;
let target = if ncurses::COLOR_PAIRS() > i32::from(n) {
@ -89,10 +91,12 @@ impl Concrete {
| ncurses::BUTTON_CTRL)
as mmask_t;
let make_event = |event| Event::Mouse {
offset: Vec2::zero(),
position: Vec2::new(mevent.x as usize, mevent.y as usize),
event: event,
let make_event = |event| {
Event::Mouse {
offset: Vec2::zero(),
position: Vec2::new(mevent.x as usize, mevent.y as usize),
event: event,
}
};
if mevent.bstate == ncurses::REPORT_MOUSE_POSITION as mmask_t {

View File

@ -22,7 +22,9 @@ pub struct Concrete {
impl Concrete {
/// Save a new color pair.
fn insert_color(
&self, pairs: &mut HashMap<ColorPair, i32>, pair: ColorPair
&self,
pairs: &mut HashMap<ColorPair, i32>,
pair: ColorPair,
) -> i32 {
let n = 1 + pairs.len() as i32;
@ -80,10 +82,12 @@ impl Concrete {
mevent.bstate &= !(pancurses::BUTTON_SHIFT | pancurses::BUTTON_ALT
| pancurses::BUTTON_CTRL) as mmask_t;
let make_event = |event| Event::Mouse {
offset: Vec2::zero(),
position: Vec2::new(mevent.x as usize, mevent.y as usize),
event: event,
let make_event = |event| {
Event::Mouse {
offset: Vec2::zero(),
position: Vec2::new(mevent.x as usize, mevent.y as usize),
event: event,
}
};
if mevent.bstate == pancurses::REPORT_MOUSE_POSITION as mmask_t {
@ -414,13 +418,15 @@ impl backend::Backend for Concrete {
pancurses::Input::KeySuspend => Event::Refresh,
pancurses::Input::KeyUndo => Event::Refresh,
pancurses::Input::KeyResize => {
// Let pancurses adjust their structures when the window is resized.
// Do it for Windows only, as 'resize_term' is not implemented for Unix
// Let pancurses adjust their structures when the
// window is resized.
// Do it for Windows only, as 'resize_term' is not
// implemented for Unix
if cfg!(target_os = "windows") {
pancurses::resize_term(0, 0);
}
Event::WindowResize
},
}
pancurses::Input::KeyEvent => Event::Refresh,
// TODO: mouse support
pancurses::Input::KeyMouse => self.parse_mouse_event(),

View File

@ -59,14 +59,14 @@
//! Or you can use gdb as usual.
#![deny(missing_docs)]
#[macro_use]
extern crate enum_map;
#[macro_use]
extern crate enumset;
#[macro_use]
extern crate log;
#[macro_use]
extern crate maplit;
#[macro_use]
extern crate enum_map;
extern crate num;
extern crate owning_ref;

View File

@ -5,7 +5,7 @@ use enumset::EnumSet;
use std::cell::Cell;
use std::cmp::min;
use std::rc::Rc;
use theme::{BorderStyle, ColorStyle, Effect, Style, Theme, PaletteColor};
use theme::{BorderStyle, ColorStyle, Effect, PaletteColor, Style, Theme};
use unicode_segmentation::UnicodeSegmentation;
use utils::lines::simple::prefix;
use vec::Vec2;
@ -33,7 +33,9 @@ impl<'a> Printer<'a> {
/// But nobody needs to know that.
#[doc(hidden)]
pub fn new<T: Into<Vec2>>(
size: T, theme: &'a Theme, backend: &'a backend::Concrete
size: T,
theme: &'a Theme,
backend: &'a backend::Concrete,
) -> Self {
Printer {
offset: Vec2::zero(),
@ -51,7 +53,8 @@ impl<'a> Printer<'a> {
///
/// Users rarely need to call this directly.
pub fn clear(&self) {
self.backend.clear(self.theme.palette[PaletteColor::Background]);
self.backend
.clear(self.theme.palette[PaletteColor::Background]);
}
/// Returns `true` if nothing has been printed yet.
@ -131,7 +134,8 @@ impl<'a> Printer<'a> {
where
F: FnOnce(&Printer),
{
self.backend.with_color(c.resolve(&self.theme.palette), || f(self));
self.backend
.with_color(c.resolve(&self.theme.palette), || f(self));
}
/// Call the given closure with a styled printer,
@ -200,7 +204,10 @@ impl<'a> Printer<'a> {
/// printer.print_box((0,0), (6,4), false);
/// ```
pub fn print_box<T: Into<Vec2>, S: Into<Vec2>>(
&self, start: T, size: S, invert: bool
&self,
start: T,
size: S,
invert: bool,
) {
self.new.set(false);
@ -297,7 +304,10 @@ impl<'a> Printer<'a> {
/// Returns a printer on a subset of this one's area.
pub fn sub_printer<S: Into<Vec2>, T: Into<Vec2>>(
&'a self, offset: S, size: T, focused: bool
&'a self,
offset: S,
size: T,
focused: bool,
) -> Printer<'a> {
let size = size.into();
let offset = offset.into().or_min(self.size);

View File

@ -67,7 +67,8 @@
//! Since some pairs are frequently used, `ColorStyle` defines some methods to
//! create these usual values:
//!
//! * **`ColorStyle::background()`**: style used to print the application background.
//! * **`ColorStyle::background()`**: style used to print the application
//! background.
//! * Its *background* color is `Background`.
//! * Its *foreground* color is unimportant as no characters are ever
//! printed in the background.
@ -86,7 +87,8 @@
//! * **`ColorStyle::title_primary()`**: style used to print titles.
//! * Its *background* color is `View`.
//! * Its *foreground* color is `TitlePrimary`.
//! * **`ColorStyle::title_secondary()`**: style used to print secondary titles.
//! * **`ColorStyle::title_secondary()`**: style used to print secondary
//! titles.
//! * Its *background* color is `View`.
//! * Its *foreground* color is `TitleSecondary`.
//! * **`ColorStyle::highlight()`**: style used to print selected items.
@ -167,7 +169,7 @@ pub use self::color::{BaseColor, Color};
pub use self::color_pair::ColorPair;
pub use self::color_style::{ColorStyle, ColorType};
pub use self::effect::Effect;
pub use self::palette::{Palette, PaletteColor, default_palette};
pub use self::palette::{default_palette, Palette, PaletteColor};
pub use self::style::Style;
use std::fs::File;
use std::io;

View File

@ -1,4 +1,4 @@
use super::{ColorStyle, Effect, Color, PaletteColor, ColorType};
use super::{Color, ColorStyle, ColorType, Effect, PaletteColor};
use enumset::EnumSet;
/// Combine a color and an effect.
@ -51,7 +51,10 @@ impl Style {
}
/// Returns a combination of `self` and `other`.
pub fn add<S>(self, other: S) -> Self where S: Into<Style> {
pub fn add<S>(self, other: S) -> Self
where
S: Into<Style>,
{
Self::merge(&[self, other.into()])
}
}

View File

@ -3,7 +3,9 @@ use std::iter::Peekable;
/// Concatenates chunks as long as they fit in the given width.
pub fn prefix<'a, I>(
tokens: &mut Peekable<I>, width: usize, offset: &mut ChunkPart
tokens: &mut Peekable<I>,
width: usize,
offset: &mut ChunkPart,
) -> Vec<Chunk<'a>>
where
I: Iterator<Item = Chunk<'a>>,

View File

@ -13,7 +13,8 @@ pub struct Row {
impl Row {
/// Resolve the row indices into string slices and attributes.
pub fn resolve<'a, T>(
&self, source: &'a SpannedString<T>
&self,
source: &'a SpannedString<T>,
) -> Vec<Span<'a, T>> {
self.segments
.iter()

View File

@ -6,7 +6,7 @@ extern crate pulldown_cmark;
use self::pulldown_cmark::{Event, Tag};
use theme::{Effect, Style};
use utils::markup::{StyledString, StyledIndexedSpan};
use utils::markup::{StyledIndexedSpan, StyledString};
use utils::span::IndexedCow;
/// Parses the given string as markdown text.
@ -139,7 +139,8 @@ Attention
====
I *really* love __Cursive__!";
let spans = parse_spans(input);
let spans: Vec<_> = spans.iter().map(|span| span.resolve(input)).collect();
let spans: Vec<_> =
spans.iter().map(|span| span.resolve(input)).collect();
// println!("{:?}", spans);
assert_eq!(

View File

@ -7,7 +7,7 @@ pub mod markdown;
use theme::Style;
use utils::span::{SpannedString, IndexedSpan, Span};
use utils::span::{IndexedSpan, Span, SpannedString};
/// A parsed string with markup style.
///

View File

@ -284,7 +284,7 @@ impl From<((i32, i32), (i32, i32))> for Vec4 {
}
impl From<((usize, usize), (usize, usize))> for Vec4 {
fn from(
((left, right), (top, bottom)): ((usize, usize), (usize, usize))
((left, right), (top, bottom)): ((usize, usize), (usize, usize)),
) -> Vec4 {
(left, right, top, bottom).into()
}

View File

@ -8,7 +8,9 @@ use views::BoxView;
pub trait Boxable: View + Sized {
/// Wraps `self` in a `BoxView` with the given size constraints.
fn boxed(
self, width: SizeConstraint, height: SizeConstraint
self,
width: SizeConstraint,
height: SizeConstraint,
) -> BoxView<Self> {
BoxView::new(width, height, self)
}

View File

@ -73,12 +73,16 @@ pub trait AnyView: View {
fn as_any_mut(&mut self) -> &mut Any;
}
impl <T: View> AnyView for T {
impl<T: View> AnyView for T {
/// Downcast self to a `Any`.
fn as_any(&self) -> &Any { self }
fn as_any(&self) -> &Any {
self
}
/// Downcast self to a mutable `Any`.
fn as_any_mut(&mut self) -> &mut Any { self }
fn as_any_mut(&mut self) -> &mut Any {
self
}
}
/// Main trait defining a view behaviour.

View File

@ -30,7 +30,10 @@ impl Position {
/// child with its top-left corner at the returned coordinates will
/// position him appropriately.
pub fn compute_offset<S, A, P>(
&self, size: S, available: A, parent: P
&self,
size: S,
available: A,
parent: P,
) -> Vec2
where
S: Into<Vec2>,
@ -65,7 +68,10 @@ 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
&self,
size: usize,
available: usize,
parent: usize,
) -> usize {
if size > available {
0

View File

@ -39,7 +39,9 @@ impl<T: View> BoxView<T> {
///
/// `None` values will use the wrapped view's preferences.
pub fn new(
width: SizeConstraint, height: SizeConstraint, view: T
width: SizeConstraint,
height: SizeConstraint,
view: T,
) -> Self {
BoxView {
size: (width, height).into(),

View File

@ -32,7 +32,8 @@ impl Checkbox {
/// Sets a callback to be used when the state changes.
pub fn set_on_change<F: 'static + Fn(&mut Cursive, bool)>(
&mut self, on_change: F
&mut self,
on_change: F,
) {
self.on_change = Some(Rc::new(on_change));
}
@ -41,7 +42,8 @@ impl Checkbox {
///
/// Chainable variant.
pub fn on_change<F: 'static + Fn(&mut Cursive, bool)>(
self, on_change: F
self,
on_change: F,
) -> Self {
self.with(|s| s.set_on_change(on_change))
}

View File

@ -218,7 +218,7 @@ impl Dialog {
/// Returns an iterator on this buttons for this dialog.
pub fn buttons_mut<'a>(
&'a mut self
&'a mut self,
) -> Box<'a + Iterator<Item = &'a mut Button>> {
Box::new(self.buttons.iter_mut().map(|b| &mut b.button.view))
}
@ -248,7 +248,9 @@ impl Dialog {
// An event is received while a button is in focus
fn on_event_button(
&mut self, event: Event, button_id: usize
&mut self,
event: Event,
button_id: usize,
) -> EventResult {
let result = {
let button = &mut self.buttons[button_id];
@ -531,7 +533,9 @@ impl View for Dialog {
}
fn call_on_any<'a>(
&mut self, selector: &Selector, callback: Box<FnMut(&mut Any) + 'a>
&mut self,
selector: &Selector,
callback: Box<FnMut(&mut Any) + 'a>,
) {
self.content.call_on_any(selector, callback);
}

View File

@ -513,7 +513,8 @@ impl View for EditView {
.next()
.expect(&format!(
"Found no char at cursor {} in {}",
self.cursor, &self.content
self.cursor,
&self.content
));
if self.secret {
make_small_stars(selected.width())

View File

@ -77,7 +77,9 @@ impl<T: View + 'static> ViewWrapper for IdView<T> {
// Some for<'b> weirdness here to please the borrow checker gods...
fn wrap_call_on_any<'a>(
&mut self, selector: &Selector, mut callback: BoxedCallback<'a>
&mut self,
selector: &Selector,
mut callback: BoxedCallback<'a>,
) {
match selector {
&Selector::Id(id) if id == self.id => callback(self),

View File

@ -7,7 +7,7 @@ use std::any::Any;
use std::cmp::min;
use std::ops::Deref;
use vec::Vec2;
use view::{AnyView, View, Selector, SizeCache};
use view::{AnyView, Selector, SizeCache, View};
/// Arranges its children linearly according to its orientation.
pub struct LinearLayout {
@ -57,7 +57,9 @@ struct ChildItem<T> {
impl<T> ChildIterator<T> {
fn new(
inner: T, orientation: direction::Orientation, available: usize
inner: T,
orientation: direction::Orientation,
available: usize,
) -> Self {
ChildIterator {
inner,
@ -197,7 +199,9 @@ impl LinearLayout {
/// Returns a cyclic mutable iterator starting with the child in focus
fn iter_mut<'a>(
&'a mut self, from_focus: bool, source: direction::Relative
&'a mut self,
from_focus: bool,
source: direction::Relative,
) -> Box<Iterator<Item = (usize, &mut Child)> + 'a> {
match source {
direction::Relative::Front => {
@ -286,7 +290,8 @@ impl LinearLayout {
}
fn try_focus(
(i, child): (usize, &mut Child), source: direction::Direction
(i, child): (usize, &mut Child),
source: direction::Direction,
) -> Option<usize> {
if child.view.take_focus(source) {
Some(i)
@ -369,7 +374,8 @@ impl View for LinearLayout {
// Ok, so maybe it didn't. Budget cuts, everyone.
// Let's pretend we have almost no space in this direction.
// budget_req is the dummy requirements, in an extreme budget situation.
// budget_req is the dummy requirements, in an extreme budget
// situation.
let budget_req = req.with_axis(self.orientation, 1);
debug!("Budget req: {:?}", budget_req);
@ -547,7 +553,8 @@ impl View for LinearLayout {
}
fn call_on_any<'a>(
&mut self, selector: &Selector,
&mut self,
selector: &Selector,
mut callback: Box<FnMut(&mut Any) + 'a>,
) {
for child in &mut self.children {

View File

@ -106,7 +106,10 @@ impl Menubar {
/// Insert a new item at the given position.
pub fn insert_subtree<S>(
&mut self, i: usize, title: S, menu: MenuTree
&mut self,
i: usize,
title: S,
menu: MenuTree,
) -> &mut Self
where
S: Into<String>,

View File

@ -123,7 +123,8 @@ impl ProgressBar {
///
/// Chainable variant.
pub fn with_task<F: FnOnce(Counter) + Send + 'static>(
mut self, task: F
mut self,
task: F,
) -> Self {
self.start(task);
self
@ -143,7 +144,8 @@ impl ProgressBar {
/// }
/// ```
pub fn with_label<F: Fn(usize, (usize, usize)) -> String + 'static>(
mut self, label_maker: F
mut self,
label_maker: F,
) -> Self {
self.label_maker = Box::new(label_maker);
self

View File

@ -52,7 +52,9 @@ impl<T> RadioGroup<T> {
///
/// The button will display `label` next to it, and will embed `value`.
pub fn button<S: Into<String>>(
&mut self, value: T, label: S
&mut self,
value: T,
label: S,
) -> RadioButton<T> {
let count = self.state.borrow().values.len();
self.state.borrow_mut().values.push(Rc::new(value));
@ -75,7 +77,8 @@ impl<T> RadioGroup<T> {
impl RadioGroup<String> {
/// Adds a button, using the label itself as value.
pub fn button_str<S: Into<String>>(
&mut self, text: S
&mut self,
text: S,
) -> RadioButton<String> {
let text = text.into();
self.button(text.clone(), text)
@ -104,7 +107,9 @@ impl<T> RadioButton<T> {
impl_enabled!(self.enabled);
fn new(
state: Rc<RefCell<SharedState<T>>>, id: usize, label: String
state: Rc<RefCell<SharedState<T>>>,
id: usize,
label: String,
) -> Self {
RadioButton {
state: state,

View File

@ -570,7 +570,6 @@ impl SelectView<String> {
}
impl<T: 'static> View for SelectView<T> {
fn draw(&self, printer: &Printer) {
self.last_offset.set(printer.offset);
@ -610,9 +609,10 @@ impl<T: 'static> View for SelectView<T> {
self.scrollbase.draw(printer, |printer, i| {
printer.with_selection(i == self.focus(), |printer| {
if i != self.focus() && !self.enabled {
printer.with_color(ColorStyle::secondary(), |printer| {
self.draw_item(printer, i)
});
printer
.with_color(ColorStyle::secondary(), |printer| {
self.draw_item(printer, i)
});
} else {
self.draw_item(printer, i);
}

View File

@ -33,7 +33,10 @@ pub enum LayerPosition {
impl Placement {
pub fn compute_offset<S, A, P>(
&self, size: S, available: A, parent: P
&self,
size: S,
available: A,
parent: P,
) -> Vec2
where
S: Into<Vec2>,
@ -107,7 +110,9 @@ impl<T: View> View for ChildWrapper<T> {
}
fn call_on_any<'a>(
&mut self, selector: &Selector, callback: Box<FnMut(&mut Any) + 'a>
&mut self,
selector: &Selector,
callback: Box<FnMut(&mut Any) + 'a>,
) {
match *self {
ChildWrapper::Shadow(ref mut v) => {
@ -391,7 +396,8 @@ impl View for StackView {
}
fn call_on_any<'a>(
&mut self, selector: &Selector,
&mut self,
selector: &Selector,
mut callback: Box<FnMut(&mut Any) + 'a>,
) {
for layer in &mut self.layers {

View File

@ -76,7 +76,6 @@ impl Deref for TextContentRef {
fn deref(&self) -> &StyledString {
&self.handle.content
}
}
impl TextContent {