This commit is contained in:
Alexandre Bury 2018-01-22 14:37:27 -08:00
parent 06086fdeb0
commit da8310b076
26 changed files with 65 additions and 140 deletions

View File

@ -1,13 +1,12 @@
extern crate cursive;
use cursive::Cursive;
use cursive::views::{Dialog, TextView};
use cursive::theme::Color;
use cursive::theme::BaseColor;
use cursive::theme::Style;
use cursive::theme::Color;
use cursive::theme::Effect;
use cursive::theme::Style;
use cursive::utils::markup::StyledString;
use cursive::views::{Dialog, TextView};
fn main() {
let mut siv = Cursive::new();

View File

@ -17,7 +17,6 @@ fn main() {
// We can quit by pressing `q`
siv.add_global_callback('q', Cursive::quit);
siv.add_layer(TextView::new(
"Hello World with default terminal background color!\n\
Press q to quit the application.",

View File

@ -22,10 +22,7 @@ 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,9 +24,7 @@ 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) {
@ -91,12 +89,10 @@ impl Concrete {
| ncurses::BUTTON_CTRL)
as mmask_t;
let make_event = |event| {
Event::Mouse {
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,9 +22,7 @@ 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;
@ -82,12 +80,10 @@ impl Concrete {
mevent.bstate &= !(pancurses::BUTTON_SHIFT | pancurses::BUTTON_ALT
| pancurses::BUTTON_CTRL) as mmask_t;
let make_event = |event| {
Event::Mouse {
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 {

View File

@ -175,8 +175,7 @@ impl Cursive {
///
/// `filename` must point to a valid toml file.
pub fn load_theme_file<P: AsRef<Path>>(
&mut self,
filename: P,
&mut self, filename: P
) -> Result<(), theme::Error> {
self.set_theme(try!(theme::load_theme_file(filename)));
Ok(())
@ -281,9 +280,7 @@ impl Cursive {
/// # }
/// ```
pub fn call_on<V, F, R>(
&mut self,
sel: &view::Selector,
callback: F,
&mut self, sel: &view::Selector, callback: F
) -> Option<R>
where
V: View + Any,

View File

@ -33,9 +33,7 @@ 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(),
@ -204,10 +202,7 @@ 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);
@ -304,10 +299,7 @@ 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

@ -3,9 +3,7 @@ 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,8 +13,7 @@ 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,6 @@
pub mod markdown;
use theme::Style;
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,9 +8,7 @@ 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

@ -94,7 +94,6 @@ pub trait View: Any {
EventResult::Ignored
}
/// Returns the minimum size the view requires with the given restrictions.
///
/// If the view is flexible (it has multiple size options), it can try

View File

@ -30,10 +30,7 @@ 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>,
@ -68,10 +65,7 @@ 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

@ -78,9 +78,7 @@ pub trait ViewWrapper: 'static {
/// Wraps the `find` method.
fn wrap_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.with_view_mut(|v| v.call_on_any(selector, callback));
}
@ -146,9 +144,7 @@ impl<T: ViewWrapper> View for 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>
) {
self.wrap_call_on_any(selector, callback)
}

View File

@ -39,9 +39,7 @@ 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,8 +32,7 @@ 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));
}
@ -42,8 +41,7 @@ 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

@ -108,7 +108,11 @@ impl Dialog {
/// ```
/// use cursive::views::{Dialog, TextView};
/// let dialog = Dialog::around(TextView::new("Hello!"));
/// let text_view: &TextView = dialog.get_content().as_any().downcast_ref::<TextView>().unwrap();
/// let text_view: &TextView = dialog
/// .get_content()
/// .as_any()
/// .downcast_ref::<TextView>()
/// .unwrap();
/// assert_eq!(text_view.get_content().source(), "Hello!");
/// ```
pub fn get_content(&self) -> &AnyView {
@ -235,7 +239,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))
}
@ -265,9 +269,7 @@ 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];
@ -550,9 +552,7 @@ 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

@ -436,11 +436,9 @@ fn make_small_stars(length: usize) -> &'static str {
impl View for EditView {
fn draw(&self, printer: &Printer) {
assert_eq!(
printer.size.x,
self.last_length,
printer.size.x, self.last_length,
"Was promised {}, received {}",
self.last_length,
printer.size.x
self.last_length, printer.size.x
);
let width = self.content.width();
@ -513,8 +511,7 @@ 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,9 +77,7 @@ 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

@ -57,9 +57,7 @@ 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,
@ -71,7 +69,8 @@ impl<T> ChildIterator<T> {
}
impl<'a, T: Deref<Target = Child>, I: Iterator<Item = T>> Iterator
for ChildIterator<I> {
for ChildIterator<I>
{
type Item = ChildItem<T>;
fn next(&mut self) -> Option<Self::Item> {
@ -199,9 +198,7 @@ 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 => {
@ -290,8 +287,7 @@ 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)
@ -553,8 +549,7 @@ 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

@ -148,9 +148,7 @@ impl ListView {
}
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 ListChild)> + 'a> {
match source {
direction::Relative::Front => {
@ -174,9 +172,7 @@ impl ListView {
}
fn move_focus(
&mut self,
n: usize,
source: direction::Direction,
&mut self, n: usize, source: direction::Direction
) -> EventResult {
let i = if let Some(i) = source
.relative(direction::Orientation::Vertical)
@ -250,8 +246,7 @@ impl ListView {
}
fn try_focus(
(i, child): (usize, &mut ListChild),
source: direction::Direction,
(i, child): (usize, &mut ListChild), source: direction::Direction
) -> Option<usize> {
match *child {
ListChild::Delimiter => None,
@ -454,8 +449,7 @@ impl View for ListView {
}
fn call_on_any<'a>(
&mut self,
selector: &Selector,
&mut self, selector: &Selector,
mut callback: Box<FnMut(&mut Any) + 'a>,
) {
for view in self.children.iter_mut().filter_map(ListChild::view) {

View File

@ -106,10 +106,7 @@ 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,8 +123,7 @@ 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
@ -144,8 +143,7 @@ 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,9 +52,7 @@ 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));
@ -77,8 +75,7 @@ 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)
@ -107,9 +104,7 @@ 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

@ -33,10 +33,7 @@ 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>,
@ -110,9 +107,7 @@ 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) => {
@ -294,7 +289,8 @@ struct StackPositionIterator<R: Deref<Target = Child>, I: Iterator<Item = R>> {
}
impl<R: Deref<Target = Child>, I: Iterator<Item = R>>
StackPositionIterator<R, I> {
StackPositionIterator<R, I>
{
/// Returns a new StackPositionIterator
pub fn new(inner: I, total_size: Vec2) -> Self {
let previous = Vec2::zero();
@ -307,7 +303,8 @@ impl<R: Deref<Target = Child>, I: Iterator<Item = R>>
}
impl<R: Deref<Target = Child>, I: Iterator<Item = R>> Iterator
for StackPositionIterator<R, I> {
for StackPositionIterator<R, I>
{
type Item = (R, Vec2);
fn next(&mut self) -> Option<(R, Vec2)> {
@ -396,8 +393,7 @@ 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 {