From 06b02e4665b53e948aa80e5148f3dd6cb74603d6 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Thu, 28 Feb 2019 16:04:14 -0800 Subject: [PATCH] Remove "extern crate" and rustfmt --- examples/edit.rs | 10 ++- examples/linear.rs | 3 +- examples/menubar.rs | 104 +++++++++++++----------- examples/mutation.rs | 3 +- examples/radio.rs | 61 +++++++------- examples/refcell_view.rs | 3 +- examples/scroll.rs | 3 +- examples/slider.rs | 3 +- examples/text_area.rs | 12 ++- examples/theme.rs | 3 +- examples/theme_manual.rs | 3 +- src/backend/curses/mod.rs | 1 + src/backend/curses/n.rs | 2 + src/backend/curses/pan.rs | 1 + src/backend/termion.rs | 2 +- src/event.rs | 4 +- src/lib.rs | 25 ------ src/logger.rs | 1 + src/menu.rs | 2 +- src/printer.rs | 16 ++-- src/rect.rs | 2 +- src/theme/effect.rs | 29 +++---- src/theme/palette.rs | 7 +- src/theme/style.rs | 2 +- src/utils/lines/simple/mod.rs | 3 +- src/utils/lines/spans/chunk_iterator.rs | 5 +- src/utils/lines/spans/lines_iterator.rs | 5 +- src/utils/reader.rs | 2 +- src/view/any.rs | 2 +- src/view/finder.rs | 10 ++- src/view/margins.rs | 2 +- src/view/position.rs | 2 +- src/view/scroll.rs | 2 +- src/view/view.rs | 2 +- src/view/view_wrapper.rs | 5 +- src/views/box_view.rs | 2 - src/views/button.rs | 2 +- src/views/checkbox.rs | 2 +- src/views/debug_view.rs | 2 +- src/views/dialog.rs | 10 ++- src/views/edit_view.rs | 9 +- src/views/hideable_view.rs | 3 +- src/views/id_view.rs | 2 +- src/views/linear_layout.rs | 11 ++- src/views/list_view.rs | 5 +- src/views/menu_popup.rs | 32 ++++---- src/views/menubar.rs | 18 ++-- src/views/on_event_view.rs | 2 +- src/views/panel.rs | 9 +- src/views/progress_bar.rs | 4 +- src/views/radio.rs | 8 +- src/views/scroll_view.rs | 30 ++++--- src/views/select_view.rs | 12 +-- src/views/slider_view.rs | 14 ++-- src/views/stack_view.rs | 12 ++- src/views/text_area.rs | 7 +- src/views/tracked_view.rs | 2 +- src/views/view_box.rs | 2 +- 58 files changed, 284 insertions(+), 258 deletions(-) diff --git a/examples/edit.rs b/examples/edit.rs index a8ac3c2..3f5c8b8 100644 --- a/examples/edit.rs +++ b/examples/edit.rs @@ -29,10 +29,12 @@ fn main() { .button("Ok", |s| { // This will run the given closure, *ONLY* if a view with the // correct type and the given ID is found. - let name = s.call_on_id("name", |view: &mut EditView| { - // We can return content from the closure! - view.get_content() - }).unwrap(); + let name = s + .call_on_id("name", |view: &mut EditView| { + // We can return content from the closure! + view.get_content() + }) + .unwrap(); // Run the next step show_popup(s, &name); diff --git a/examples/linear.rs b/examples/linear.rs index 97aa9cc..5929501 100644 --- a/examples/linear.rs +++ b/examples/linear.rs @@ -29,7 +29,8 @@ fn main() { .child(TextView::new(text).scrollable()) .child(TextView::new(text).scrollable()) .fixed_width(30), - ).button("Quit", |s| s.quit()) + ) + .button("Quit", |s| s.quit()) .h_align(HAlign::Center), ); diff --git a/examples/menubar.rs b/examples/menubar.rs index 1482de5..da38cfd 100644 --- a/examples/menubar.rs +++ b/examples/menubar.rs @@ -19,53 +19,65 @@ fn main() { // The menubar is a list of (label, menu tree) pairs. siv.menubar() // We add a new "File" tree - .add_subtree("File", - MenuTree::new() - // Trees are made of leaves, with are directly actionable... - .leaf("New", move |s| { - // Here we use the counter to add an entry - // in the list of "Recent" items. - let i = counter.fetch_add(1, Ordering::Relaxed); - let filename = format!("New {}", i); - s.menubar().find_subtree("File").unwrap() - .find_subtree("Recent").unwrap() - .insert_leaf(0, filename, |_| ()); + .add_subtree( + "File", + MenuTree::new() + // Trees are made of leaves, with are directly actionable... + .leaf("New", move |s| { + // Here we use the counter to add an entry + // in the list of "Recent" items. + let i = counter.fetch_add(1, Ordering::Relaxed); + let filename = format!("New {}", i); + s.menubar() + .find_subtree("File") + .unwrap() + .find_subtree("Recent") + .unwrap() + .insert_leaf(0, filename, |_| ()); - s.add_layer(Dialog::info("New file!")); - }) - // ... and of sub-trees, which open up when selected. - .subtree("Recent", - // The `.with()` method can help when running loops - // within builder patterns. - MenuTree::new().with(|tree| { - for i in 1..100 { - // We don't actually do anything here, - // but you could! - tree.add_leaf(format!("Item {}", i), |_| ()) - } - })) - // Delimiter are simple lines between items, - // and cannot be selected. - .delimiter() - .with(|tree| { - for i in 1..10 { - tree.add_leaf(format!("Option {}", i), |_| ()); - } - })) - .add_subtree("Help", - MenuTree::new() - .subtree("Help", - MenuTree::new() - .leaf("General", |s| { - s.add_layer(Dialog::info("Help message!")) - }) - .leaf("Online", |s| { - let text = "Google it yourself!\n\ - Kids, these days..."; - s.add_layer(Dialog::info(text)) - })) - .leaf("About", - |s| s.add_layer(Dialog::info("Cursive v0.0.0")))) + s.add_layer(Dialog::info("New file!")); + }) + // ... and of sub-trees, which open up when selected. + .subtree( + "Recent", + // The `.with()` method can help when running loops + // within builder patterns. + MenuTree::new().with(|tree| { + for i in 1..100 { + // We don't actually do anything here, + // but you could! + tree.add_leaf(format!("Item {}", i), |_| ()) + } + }), + ) + // Delimiter are simple lines between items, + // and cannot be selected. + .delimiter() + .with(|tree| { + for i in 1..10 { + tree.add_leaf(format!("Option {}", i), |_| ()); + } + }), + ) + .add_subtree( + "Help", + MenuTree::new() + .subtree( + "Help", + MenuTree::new() + .leaf("General", |s| { + s.add_layer(Dialog::info("Help message!")) + }) + .leaf("Online", |s| { + let text = "Google it yourself!\n\ + Kids, these days..."; + s.add_layer(Dialog::info(text)) + }), + ) + .leaf("About", |s| { + s.add_layer(Dialog::info("Cursive v0.0.0")) + }), + ) .add_delimiter() .add_leaf("Quit", |s| s.quit()); diff --git a/examples/mutation.rs b/examples/mutation.rs index 849a38d..32cf39b 100644 --- a/examples/mutation.rs +++ b/examples/mutation.rs @@ -39,7 +39,8 @@ fn show_popup(siv: &mut Cursive) { let content = reverse(view.get_content().source()); view.set_content(content); }); - }).dismiss_button("Ok"), + }) + .dismiss_button("Ok"), ); } diff --git a/examples/radio.rs b/examples/radio.rs index ef3b060..5435900 100644 --- a/examples/radio.rs +++ b/examples/radio.rs @@ -14,35 +14,40 @@ fn main() { siv.add_layer( Dialog::new() - .title("Make your selection") - // We'll have two columns side-by-side - .content(LinearLayout::horizontal() - .child(LinearLayout::vertical() - // The color group uses the label itself as stored value - // By default, the first item is selected. - .child(color_group.button_str("Red")) - .child(color_group.button_str("Green")) - .child(color_group.button_str("Blue"))) - // A DummyView is used as a spacer - .child(DummyView) - .child(LinearLayout::vertical() - // For the size, we store a number separately - .child(size_group.button(5, "Small")) - // The initial selection can also be overriden - .child(size_group.button(15, "Medium").selected()) - // The large size is out of stock, sorry! - .child(size_group.button(25, "Large").disabled()))) - .button("Ok", move |s| { - // We retrieve the stored value for both group. - let color = color_group.selection(); - let size = size_group.selection(); + .title("Make your selection") + // We'll have two columns side-by-side + .content( + LinearLayout::horizontal() + .child( + LinearLayout::vertical() + // The color group uses the label itself as stored value + // By default, the first item is selected. + .child(color_group.button_str("Red")) + .child(color_group.button_str("Green")) + .child(color_group.button_str("Blue")), + ) + // A DummyView is used as a spacer + .child(DummyView) + .child( + LinearLayout::vertical() + // For the size, we store a number separately + .child(size_group.button(5, "Small")) + // The initial selection can also be overriden + .child(size_group.button(15, "Medium").selected()) + // The large size is out of stock, sorry! + .child(size_group.button(25, "Large").disabled()), + ), + ) + .button("Ok", move |s| { + // We retrieve the stored value for both group. + let color = color_group.selection(); + let size = size_group.selection(); - s.pop_layer(); - // And we simply print the result. - let text = format!("Color: {}\nSize: {}cm", color, size); - s.add_layer(Dialog::text(text) - .button("Ok", |s| s.quit())); - }), + s.pop_layer(); + // And we simply print the result. + let text = format!("Color: {}\nSize: {}cm", color, size); + s.add_layer(Dialog::text(text).button("Ok", |s| s.quit())); + }), ); siv.run(); diff --git a/examples/refcell_view.rs b/examples/refcell_view.rs index e20c159..827e781 100644 --- a/examples/refcell_view.rs +++ b/examples/refcell_view.rs @@ -18,7 +18,8 @@ fn main() { .child(EditView::new().on_edit(on_edit).with_id("2")) .child(TextView::new("match").with_id("match")) .fixed_width(10), - ).button("Quit", Cursive::quit), + ) + .button("Quit", Cursive::quit), ); siv.run(); diff --git a/examples/scroll.rs b/examples/scroll.rs index 1772e93..4a2c5a5 100644 --- a/examples/scroll.rs +++ b/examples/scroll.rs @@ -16,7 +16,8 @@ fn main() { .child(Button::new("Bar", |s| s.add_layer(Dialog::info("Uh")))) .scrollable() .scroll_x(true), - ).fixed_size((60, 30)), + ) + .fixed_size((60, 30)), ); siv.add_global_callback('q', |s| s.quit()); diff --git a/examples/slider.rs b/examples/slider.rs index 6887991..1ad4f4f 100644 --- a/examples/slider.rs +++ b/examples/slider.rs @@ -31,7 +31,8 @@ fn main() { .button("Ok", Cursive::quit), ); }), - ).title("[ 7 ]") + ) + .title("[ 7 ]") .with_id("dialog"), ); diff --git a/examples/text_area.rs b/examples/text_area.rs index e68567d..ea162c2 100644 --- a/examples/text_area.rs +++ b/examples/text_area.rs @@ -33,14 +33,18 @@ fn main() { .on_submit(find) .with_id("edit") .min_width(10), - ).button("Ok", |s| { + ) + .button("Ok", |s| { let text = s .call_on_id("edit", |view: &mut EditView| { view.get_content() - }).unwrap(); + }) + .unwrap(); find(s, &text); - }).dismiss_button("Cancel"), - ).on_event(Event::Key(Key::Esc), |s| { + }) + .dismiss_button("Cancel"), + ) + .on_event(Event::Key(Key::Esc), |s| { s.pop_layer(); }), ) diff --git a/examples/theme.rs b/examples/theme.rs index 7115507..2793b3c 100644 --- a/examples/theme.rs +++ b/examples/theme.rs @@ -15,7 +15,8 @@ fn main() { Dialog::around(TextView::new( "This application uses a \ custom theme!", - )).title("Themed dialog") + )) + .title("Themed dialog") .button("Quit", |s| s.quit()), ); diff --git a/examples/theme_manual.rs b/examples/theme_manual.rs index ae79470..80e99a1 100644 --- a/examples/theme_manual.rs +++ b/examples/theme_manual.rs @@ -29,7 +29,8 @@ fn main() { }; s.set_theme(theme); - }).button("Quit", Cursive::quit), + }) + .button("Quit", Cursive::quit), ); siv.run(); diff --git a/src/backend/curses/mod.rs b/src/backend/curses/mod.rs index 76d82f4..3a22bd7 100644 --- a/src/backend/curses/mod.rs +++ b/src/backend/curses/mod.rs @@ -7,6 +7,7 @@ use std::collections::HashMap; use crate::event::{Event, Key}; use crate::theme::{BaseColor, Color, ColorPair}; +use maplit::hashmap; #[cfg(feature = "ncurses-backend")] pub mod n; diff --git a/src/backend/curses/n.rs b/src/backend/curses/n.rs index c1608ce..c90bdd8 100644 --- a/src/backend/curses/n.rs +++ b/src/backend/curses/n.rs @@ -1,4 +1,6 @@ //! Ncurses-specific backend. +use log::{debug, warn}; +use maplit::hashmap; use ncurses; use std::cell::{Cell, RefCell}; diff --git a/src/backend/curses/pan.rs b/src/backend/curses/pan.rs index 9b2bfab..4e416f7 100644 --- a/src/backend/curses/pan.rs +++ b/src/backend/curses/pan.rs @@ -1,4 +1,5 @@ //! Pancuses-specific backend. +use log::{debug, warn}; use pancurses; use std::cell::{Cell, RefCell}; diff --git a/src/backend/termion.rs b/src/backend/termion.rs index 2a90fe1..cfff8cf 100644 --- a/src/backend/termion.rs +++ b/src/backend/termion.rs @@ -14,7 +14,7 @@ use self::termion::input::{MouseTerminal, TermRead}; use self::termion::raw::{IntoRawMode, RawTerminal}; use self::termion::screen::AlternateScreen; use self::termion::style as tstyle; -use crossbeam_channel::{self, Receiver}; +use crossbeam_channel::{self, select, Receiver}; use crate::backend; use crate::event::{Event, Key, MouseButton, MouseEvent}; diff --git a/src/event.rs b/src/event.rs index 0010670..a9ebe16 100644 --- a/src/event.rs +++ b/src/event.rs @@ -13,12 +13,12 @@ //! [global callback](../struct.Cursive.html#method.add_global_callback) //! table is checked. +use crate::vec::Vec2; +use crate::Cursive; use std::any::Any; use std::cell::RefCell; use std::ops::Deref; use std::rc::Rc; -use crate::vec::Vec2; -use crate::Cursive; /// Callback is a function that can be triggered by an event. /// It has a mutable access to the cursive root. diff --git a/src/lib.rs b/src/lib.rs index 8fe3bc8..c0a43a4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,34 +61,9 @@ //! 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 crossbeam_channel; -#[macro_use] -extern crate lazy_static; - -#[cfg(any(feature = "ncurses", feature = "pancurses"))] -#[macro_use] -extern crate maplit; - // We use chan_signal to detect SIGWINCH. // It's not how windows work, so no need to use that. - - - - - - - - - - macro_rules! new_default( ($c:ty) => { impl Default for $c { diff --git a/src/logger.rs b/src/logger.rs index 4e9e1d3..ed3be5a 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -1,5 +1,6 @@ //! Logging utilities +use lazy_static::lazy_static; use std::collections::VecDeque; use std::sync::Mutex; diff --git a/src/menu.rs b/src/menu.rs index 0f07fac..d80306d 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -13,9 +13,9 @@ //! [menubar]: ../struct.Cursive.html#method.menubar use crate::event::Callback; -use std::rc::Rc; use crate::Cursive; use crate::With; +use std::rc::Rc; /// Root of a menu tree. #[derive(Default, Clone)] diff --git a/src/printer.rs b/src/printer.rs index 7211000..fdef623 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -2,14 +2,16 @@ use crate::backend::Backend; use crate::direction::Orientation; -use enumset::EnumSet; -use std::cmp::min; -use crate::theme::{BorderStyle, ColorStyle, Effect, PaletteColor, Style, Theme}; -use unicode_segmentation::UnicodeSegmentation; -use unicode_width::UnicodeWidthStr; +use crate::theme::{ + BorderStyle, ColorStyle, Effect, PaletteColor, Style, Theme, +}; use crate::utils::lines::simple::{prefix, suffix}; use crate::vec::Vec2; use crate::with::With; +use enumset::EnumSet; +use std::cmp::min; +use unicode_segmentation::UnicodeSegmentation; +use unicode_width::UnicodeWidthStr; /// Convenient interface to draw on a subset of the screen. /// @@ -428,7 +430,9 @@ impl<'a, 'b> Printer<'a, 'b> { /// * If the printer currently has the focus, /// uses `ColorStyle::highlight()`. /// * Otherwise, uses `ColorStyle::highlight_inactive()`. - pub fn with_selection)>(&self, selection: bool, f: F) { + pub fn with_selection)>( + &self, selection: bool, f: F, + ) { self.with_color( if selection { if self.focused { diff --git a/src/rect.rs b/src/rect.rs index f3b35e9..429558e 100644 --- a/src/rect.rs +++ b/src/rect.rs @@ -1,6 +1,6 @@ //! Rectangles on the 2D character grid. -use std::ops::Add; use crate::vec::Vec2; +use std::ops::Add; /// A non-empty rectangle on the 2D grid. #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/src/theme/effect.rs b/src/theme/effect.rs index 196448e..2348407 100644 --- a/src/theme/effect.rs +++ b/src/theme/effect.rs @@ -1,15 +1,16 @@ -enum_set_type! { - /// Text effect - pub enum Effect { - /// No effect - Simple, - /// Reverses foreground and background colors - Reverse, - /// Prints foreground in bold - Bold, - /// Prints foreground in italic - Italic, - /// Prints foreground with underline - Underline, - } +use enumset::EnumSetType; + +/// Text effect +#[derive(EnumSetType, Debug)] +pub enum Effect { + /// No effect + Simple, + /// Reverses foreground and background colors + Reverse, + /// Prints foreground in bold + Bold, + /// Prints foreground in italic + Italic, + /// Prints foreground with underline + Underline, } diff --git a/src/theme/palette.rs b/src/theme/palette.rs index 89fe54a..7017656 100644 --- a/src/theme/palette.rs +++ b/src/theme/palette.rs @@ -1,5 +1,6 @@ use super::Color; -use enum_map::EnumMap; +use enum_map::{enum_map, Enum, EnumMap}; +use log::warn; use toml; use std::collections::HashMap; @@ -150,7 +151,7 @@ impl Default for Palette { use crate::theme::Color::*; Palette { - basic: enum_map!{ + basic: enum_map! { Background => Dark(Blue), Shadow => Dark(Black), View => Dark(White), @@ -198,7 +199,7 @@ fn iterate_toml<'a>( } other => { // Other - error? - debug!( + warn!( "Found unexpected value in theme: {} = {:?}", key, other ); diff --git a/src/theme/style.rs b/src/theme/style.rs index af5e87c..b03ad5e 100644 --- a/src/theme/style.rs +++ b/src/theme/style.rs @@ -1,5 +1,5 @@ use super::{Color, ColorStyle, ColorType, Effect, PaletteColor}; -use enumset::EnumSet; +use enumset::{enum_set, EnumSet}; /// Combine a color and an effect. /// diff --git a/src/utils/lines/simple/mod.rs b/src/utils/lines/simple/mod.rs index fed1aa4..32eb7e1 100644 --- a/src/utils/lines/simple/mod.rs +++ b/src/utils/lines/simple/mod.rs @@ -72,7 +72,8 @@ where current_width += delimiter_width; true } - }).map(|token| token.len() + delimiter_len) + }) + .map(|token| token.len() + delimiter_len) .sum(); // We counted delimiter once too many times, diff --git a/src/utils/lines/spans/chunk_iterator.rs b/src/utils/lines/spans/chunk_iterator.rs index 7ad0d2f..b87df7d 100644 --- a/src/utils/lines/spans/chunk_iterator.rs +++ b/src/utils/lines/spans/chunk_iterator.rs @@ -1,8 +1,8 @@ use super::chunk::Chunk; use super::segment::Segment; +use crate::utils::span::SpannedText; use std::rc::Rc; use unicode_width::UnicodeWidthStr; -use crate::utils::span::SpannedText; use xi_unicode::LineBreakLeafIter; /// Iterator that returns non-breakable chunks of text. @@ -123,7 +123,8 @@ where while let Some(true) = self.source.spans().get(self.current_span).map(|span| { span.as_ref().resolve(self.source.source()).is_empty() - }) { + }) + { self.current_span += 1; } diff --git a/src/utils/lines/spans/lines_iterator.rs b/src/utils/lines/spans/lines_iterator.rs index 8d75db1..fa6b653 100644 --- a/src/utils/lines/spans/lines_iterator.rs +++ b/src/utils/lines/spans/lines_iterator.rs @@ -4,11 +4,11 @@ use super::prefix::prefix; use super::row::Row; use super::segment::Segment; use super::segment_merge_iterator::SegmentMergeIterator; +use crate::utils::span::SpannedText; use std::iter::Peekable; use std::rc::Rc; use unicode_segmentation::UnicodeSegmentation; use unicode_width::UnicodeWidthStr; -use crate::utils::span::SpannedText; /// Generates rows of text in constrainted width. /// @@ -168,7 +168,8 @@ where .into_iter() .flat_map(|chunk| chunk.segments) //.filter(|segment| segment.start != segment.end), - ).collect(); + ) + .collect(); // TODO: merge consecutive segments of the same span diff --git a/src/utils/reader.rs b/src/utils/reader.rs index e7e8d00..16b4660 100644 --- a/src/utils/reader.rs +++ b/src/utils/reader.rs @@ -1,5 +1,5 @@ -use std::io::{self, Read}; use crate::utils::Counter; +use std::io::{self, Read}; /// Wrapper around a `Read` that reports the progress made. /// diff --git a/src/view/any.rs b/src/view/any.rs index a5e56fc..fb5c342 100644 --- a/src/view/any.rs +++ b/src/view/any.rs @@ -1,5 +1,5 @@ -use std::any::Any; use crate::view::View; +use std::any::Any; /// A view that can be downcasted to its concrete type. /// diff --git a/src/view/finder.rs b/src/view/finder.rs index 7ba7c61..f5c0c81 100644 --- a/src/view/finder.rs +++ b/src/view/finder.rs @@ -1,6 +1,6 @@ -use std::any::Any; use crate::view::{View, ViewPath, ViewWrapper}; use crate::views::{IdView, ViewRef}; +use std::any::Any; /// Provides `call_on` to views. /// @@ -16,7 +16,9 @@ pub trait Finder { /// /// If the view is not found, or if it is not of the asked type, /// it returns `None`. - fn call_on(&mut self, sel: &Selector<'_>, callback: F) -> Option + fn call_on( + &mut self, sel: &Selector<'_>, callback: F, + ) -> Option where V: View + Any, F: FnOnce(&mut V) -> R; @@ -42,7 +44,9 @@ pub trait Finder { } impl Finder for T { - fn call_on(&mut self, sel: &Selector<'_>, callback: F) -> Option + fn call_on( + &mut self, sel: &Selector<'_>, callback: F, + ) -> Option where V: View + Any, F: FnOnce(&mut V) -> R, diff --git a/src/view/margins.rs b/src/view/margins.rs index 8c0e774..878c2cf 100644 --- a/src/view/margins.rs +++ b/src/view/margins.rs @@ -1,5 +1,5 @@ -use std::ops::{Add, Div, Mul, Sub}; use crate::vec::Vec2; +use std::ops::{Add, Div, Mul, Sub}; /// Four values representing each direction. #[derive(Clone, Copy)] diff --git a/src/view/position.rs b/src/view/position.rs index c03db47..20c631d 100644 --- a/src/view/position.rs +++ b/src/view/position.rs @@ -1,6 +1,6 @@ -use std::cmp::min; use crate::vec::Vec2; use crate::XY; +use std::cmp::min; /// Location of the view on screen pub type Position = XY; diff --git a/src/view/scroll.rs b/src/view/scroll.rs index e5e508f..d183db4 100644 --- a/src/view/scroll.rs +++ b/src/view/scroll.rs @@ -1,8 +1,8 @@ use crate::div::div_up; -use std::cmp::{max, min}; use crate::theme::ColorStyle; use crate::vec::Vec2; use crate::Printer; +use std::cmp::{max, min}; /// Provide scrolling functionalities to a view. /// diff --git a/src/view/view.rs b/src/view/view.rs index 5c81a63..bb41753 100644 --- a/src/view/view.rs +++ b/src/view/view.rs @@ -1,10 +1,10 @@ use crate::direction::Direction; use crate::event::{AnyCb, Event, EventResult}; use crate::rect::Rect; -use std::any::Any; use crate::vec::Vec2; use crate::view::{AnyView, Selector}; use crate::Printer; +use std::any::Any; /// Main trait defining a view behaviour. /// diff --git a/src/view/view_wrapper.rs b/src/view/view_wrapper.rs index b59dfc7..e23b38c 100644 --- a/src/view/view_wrapper.rs +++ b/src/view/view_wrapper.rs @@ -1,10 +1,10 @@ use crate::direction::Direction; use crate::event::{AnyCb, Event, EventResult}; use crate::rect::Rect; -use std::any::Any; use crate::vec::Vec2; use crate::view::{Selector, View}; use crate::Printer; +use std::any::Any; /// Generic wrapper around a view. /// @@ -125,7 +125,8 @@ impl View for T { } fn call_on_any<'a>( - &mut self, selector: &Selector<'_>, callback: Box, + &mut self, selector: &Selector<'_>, + callback: Box, ) { self.wrap_call_on_any(selector, callback) } diff --git a/src/views/box_view.rs b/src/views/box_view.rs index 7dd96f9..ee32544 100644 --- a/src/views/box_view.rs +++ b/src/views/box_view.rs @@ -220,8 +220,6 @@ impl ViewWrapper for BoxView { .size .zip_map(child_size.zip(req), SizeConstraint::result); - debug!("{:?}", result); - if !self.squishable { result } else { diff --git a/src/views/button.rs b/src/views/button.rs index d87fd05..4ca34df 100644 --- a/src/views/button.rs +++ b/src/views/button.rs @@ -3,10 +3,10 @@ use crate::direction::Direction; use crate::event::*; use crate::rect::Rect; use crate::theme::ColorStyle; -use unicode_width::UnicodeWidthStr; use crate::vec::Vec2; use crate::view::View; use crate::{Cursive, Printer, With}; +use unicode_width::UnicodeWidthStr; /// Simple text label with a callback when is pressed. /// diff --git a/src/views/checkbox.rs b/src/views/checkbox.rs index 1dfc158..9e90c6a 100644 --- a/src/views/checkbox.rs +++ b/src/views/checkbox.rs @@ -1,12 +1,12 @@ use crate::direction::Direction; use crate::event::{Event, EventResult, Key, MouseButton, MouseEvent}; -use std::rc::Rc; use crate::theme::ColorStyle; use crate::vec::Vec2; use crate::view::View; use crate::Cursive; use crate::Printer; use crate::With; +use std::rc::Rc; /// Checkable box. pub struct Checkbox { diff --git a/src/views/debug_view.rs b/src/views/debug_view.rs index 56c83c6..24791d9 100644 --- a/src/views/debug_view.rs +++ b/src/views/debug_view.rs @@ -4,7 +4,7 @@ use crate::vec::Vec2; use crate::view::View; use crate::Printer; -use unicode_width::UnicodeWidthStr; +use unicode_width::UnicodeWidthStr as _; /// View used for debugging, showing logs. pub struct DebugView { diff --git a/src/views/dialog.rs b/src/views/dialog.rs index d9125b0..6e0aa3d 100644 --- a/src/views/dialog.rs +++ b/src/views/dialog.rs @@ -2,16 +2,16 @@ use crate::align::*; use crate::direction::{Absolute, Direction, Relative}; use crate::event::{AnyCb, Event, EventResult, Key}; use crate::rect::Rect; -use std::cell::Cell; -use std::cmp::max; use crate::theme::ColorStyle; -use unicode_width::UnicodeWidthStr; use crate::vec::Vec2; use crate::view::{Margins, Selector, View}; use crate::views::{Button, DummyView, SizedView, TextView, ViewBox}; use crate::Cursive; use crate::Printer; use crate::With; +use std::cell::Cell; +use std::cmp::max; +use unicode_width::UnicodeWidthStr; /// Identifies currently focused element in [`Dialog`]. /// @@ -653,7 +653,9 @@ impl View for Dialog { } } - fn call_on_any<'a>(&mut self, selector: &Selector<'_>, callback: AnyCb<'a>) { + fn call_on_any<'a>( + &mut self, selector: &Selector<'_>, callback: AnyCb<'a>, + ) { self.content.call_on_any(selector, callback); } diff --git a/src/views/edit_view.rs b/src/views/edit_view.rs index c212c84..a7d8308 100644 --- a/src/views/edit_view.rs +++ b/src/views/edit_view.rs @@ -1,15 +1,15 @@ use crate::direction::Direction; use crate::event::{Callback, Event, EventResult, Key, MouseEvent}; use crate::rect::Rect; -use std::cell::RefCell; -use std::rc::Rc; use crate::theme::{ColorStyle, Effect}; -use unicode_segmentation::UnicodeSegmentation; -use unicode_width::{UnicodeWidthChar, UnicodeWidthStr}; use crate::utils::lines::simple::{simple_prefix, simple_suffix}; use crate::vec::Vec2; use crate::view::View; use crate::{Cursive, Printer, With}; +use std::cell::RefCell; +use std::rc::Rc; +use unicode_segmentation::UnicodeSegmentation; +use unicode_width::{UnicodeWidthChar, UnicodeWidthStr}; /// Closure type for callbacks when the content is modified. /// @@ -597,7 +597,6 @@ impl View for EditView { fn layout(&mut self, size: Vec2) { self.last_length = size.x; - debug!("Promised: {}", size.x); } fn take_focus(&mut self, _: Direction) -> bool { diff --git a/src/views/hideable_view.rs b/src/views/hideable_view.rs index 480f4ec..c19ba90 100644 --- a/src/views/hideable_view.rs +++ b/src/views/hideable_view.rs @@ -91,7 +91,8 @@ impl ViewWrapper for HideableView { } fn wrap_call_on_any<'a>( - &mut self, selector: &Selector<'_>, callback: Box, + &mut self, selector: &Selector<'_>, + callback: Box, ) { // We always run callbacks, even when invisible. self.view.call_on_any(selector, callback) diff --git a/src/views/id_view.rs b/src/views/id_view.rs index 2f99aca..39cd201 100644 --- a/src/views/id_view.rs +++ b/src/views/id_view.rs @@ -1,9 +1,9 @@ +use crate::view::{Selector, View, ViewWrapper}; use owning_ref::{OwningHandle, RcRef}; use std::any::Any; use std::cell::{RefCell, RefMut}; use std::ops::DerefMut; use std::rc::Rc; -use crate::view::{Selector, View, ViewWrapper}; /// Wrapper around a view to provide interior mutability. pub struct IdView { diff --git a/src/views/linear_layout.rs b/src/views/linear_layout.rs index 3f9d81f..ea49924 100644 --- a/src/views/linear_layout.rs +++ b/src/views/linear_layout.rs @@ -1,13 +1,14 @@ use crate::direction; use crate::event::{AnyCb, Event, EventResult, Key}; use crate::rect::Rect; -use std::cmp::min; -use std::ops::Deref; use crate::vec::Vec2; use crate::view::{Selector, SizeCache, View}; use crate::Printer; use crate::With; use crate::XY; +use log::debug; +use std::cmp::min; +use std::ops::Deref; /// Arranges its children linearly according to its orientation. pub struct LinearLayout { @@ -305,7 +306,8 @@ impl LinearLayout { self.orientation, // TODO: get actual width (not super important) usize::max_value(), - ).enumerate() + ) + .enumerate() { // Get the child size: // this will give us the allowed window for a click. @@ -341,7 +343,8 @@ impl View for LinearLayout { self.children.iter(), self.orientation, *printer.size.get(self.orientation), - ).enumerate() + ) + .enumerate() { // debug!("Printer size: {:?}", printer.size); // debug!("Child size: {:?}", item.child.size); diff --git a/src/views/list_view.rs b/src/views/list_view.rs index 9eb9bbb..ddbe85c 100644 --- a/src/views/list_view.rs +++ b/src/views/list_view.rs @@ -1,13 +1,14 @@ use crate::direction; use crate::event::{AnyCb, Callback, Event, EventResult, Key}; use crate::rect::Rect; -use std::rc::Rc; -use unicode_width::UnicodeWidthStr; use crate::vec::Vec2; use crate::view::{Selector, View}; use crate::Cursive; use crate::Printer; use crate::With; +use log::debug; +use std::rc::Rc; +use unicode_width::UnicodeWidthStr; /// Represents a child from a [`ListView`]. /// diff --git a/src/views/menu_popup.rs b/src/views/menu_popup.rs index b34d1db..63527d4 100644 --- a/src/views/menu_popup.rs +++ b/src/views/menu_popup.rs @@ -1,16 +1,18 @@ use crate::align::Align; -use crate::event::{Callback, Event, EventResult, Key, MouseButton, MouseEvent}; +use crate::event::{ + Callback, Event, EventResult, Key, MouseButton, MouseEvent, +}; use crate::menu::{MenuItem, MenuTree}; use crate::rect::Rect; -use std::cmp::min; -use std::rc::Rc; -use unicode_width::UnicodeWidthStr; use crate::vec::Vec2; use crate::view::{Position, ScrollBase, View}; use crate::views::OnEventView; use crate::Cursive; use crate::Printer; use crate::With; +use std::cmp::min; +use std::rc::Rc; +use unicode_width::UnicodeWidthStr; /// Popup that shows a list of items. pub struct MenuPopup { @@ -162,7 +164,8 @@ impl MenuPopup { action_cb.clone()(s); } }, - )).on_event(Key::Left, |s| { + )) + .on_event(Key::Left, |s| { s.pop_layer(); }), ); @@ -297,18 +300,14 @@ impl View for MenuPopup { Event::Mouse { event: MouseEvent::WheelUp, .. - } - if self.scrollbase.can_scroll_up() => - { + } if self.scrollbase.can_scroll_up() => { fix_scroll = false; self.scrollbase.scroll_up(1); } Event::Mouse { event: MouseEvent::WheelDown, .. - } - if self.scrollbase.can_scroll_down() => - { + } if self.scrollbase.can_scroll_down() => { fix_scroll = false; self.scrollbase.scroll_down(1); } @@ -316,12 +315,13 @@ impl View for MenuPopup { event: MouseEvent::Press(MouseButton::Left), position, offset, - } - if self.scrollbase.scrollable() && position + } if self.scrollbase.scrollable() + && position .checked_sub(offset + (0, 1)) .map(|position| { self.scrollbase.start_drag(position, self.last_size.x) - }).unwrap_or(false) => + }) + .unwrap_or(false) => { fix_scroll = false; } @@ -339,9 +339,7 @@ impl View for MenuPopup { event: MouseEvent::Press(_), position, offset, - } - if position.fits_in_rect(offset, self.last_size) => - { + } if position.fits_in_rect(offset, self.last_size) => { // eprintln!("Position: {:?} / {:?}", position, offset); // eprintln!("Last size: {:?}", self.last_size); let inner_size = self.last_size.saturating_sub((2, 2)); diff --git a/src/views/menubar.rs b/src/views/menubar.rs index acdfa32..f6514cb 100644 --- a/src/views/menubar.rs +++ b/src/views/menubar.rs @@ -2,14 +2,14 @@ use crate::direction; use crate::event::*; use crate::menu::{MenuItem, MenuTree}; use crate::rect::Rect; -use std::rc::Rc; use crate::theme::ColorStyle; -use unicode_width::UnicodeWidthStr; use crate::vec::Vec2; use crate::view::{Position, View}; use crate::views::{MenuPopup, OnEventView}; use crate::Cursive; use crate::Printer; +use std::rc::Rc; +use unicode_width::UnicodeWidthStr; /// Current state of the menubar #[derive(PartialEq, Debug)] @@ -236,7 +236,8 @@ fn show_child(s: &mut Cursive, offset: Vec2, menu: Rc) { MenuPopup::new(menu) .on_dismiss(|s| s.select_menubar()) .on_action(|s| s.menubar().state = State::Inactive), - ).on_event(Key::Right, |s| { + ) + .on_event(Key::Right, |s| { s.pop_layer(); s.select_menubar(); // Act as if we sent "Right" then "Down" @@ -246,7 +247,8 @@ fn show_child(s: &mut Cursive, offset: Vec2, menu: Rc) { { cb(s); } - }).on_event(Key::Left, |s| { + }) + .on_event(Key::Left, |s| { s.pop_layer(); s.select_menubar(); // Act as if we sent "Left" then "Down" @@ -319,9 +321,7 @@ impl View for Menubar { event: MouseEvent::Press(btn), position, offset, - } - if position.fits(offset) && position.y == offset.y => - { + } if position.fits(offset) && position.y == offset.y => { if let Some(child) = position .checked_sub(offset) .and_then(|pos| self.child_at(pos.x)) @@ -338,9 +338,7 @@ impl View for Menubar { event: MouseEvent::Release(btn), position, offset, - } - if position.fits(offset) && position.y == offset.y => - { + } if position.fits(offset) && position.y == offset.y => { if let Some(child) = position .checked_sub(offset) .and_then(|pos| self.child_at(pos.x)) diff --git a/src/views/on_event_view.rs b/src/views/on_event_view.rs index ecae07e..fd9420d 100644 --- a/src/views/on_event_view.rs +++ b/src/views/on_event_view.rs @@ -1,8 +1,8 @@ use crate::event::{Callback, Event, EventResult, EventTrigger}; -use std::rc::Rc; use crate::view::{View, ViewWrapper}; use crate::Cursive; use crate::With; +use std::rc::Rc; /// A wrapper view that can react to events. /// diff --git a/src/views/panel.rs b/src/views/panel.rs index 1a4683c..2bb0c05 100644 --- a/src/views/panel.rs +++ b/src/views/panel.rs @@ -2,11 +2,11 @@ use crate::align::*; use crate::event::{Event, EventResult}; use crate::rect::Rect; use crate::theme::ColorStyle; -use unicode_width::UnicodeWidthStr; use crate::vec::Vec2; use crate::view::{View, ViewWrapper}; use crate::Printer; use crate::With; +use unicode_width::UnicodeWidthStr; /// Draws a border around a wrapped view. #[derive(Debug)] @@ -69,9 +69,10 @@ impl Panel { return; } let spacing = 3; //minimum distance to borders - let x = spacing + self - .title_position - .get_offset(len, printer.size.x - 2 * spacing); + let x = spacing + + self + .title_position + .get_offset(len, printer.size.x - 2 * spacing); printer.with_high_border(false, |printer| { printer.print((x - 2, 0), "┤ "); printer.print((x + len, 0), " ├"); diff --git a/src/views/progress_bar.rs b/src/views/progress_bar.rs index a4d3141..b90c9f2 100644 --- a/src/views/progress_bar.rs +++ b/src/views/progress_bar.rs @@ -1,10 +1,10 @@ use crate::align::HAlign; -use std::cmp; -use std::thread; use crate::theme::{ColorStyle, ColorType, Effect}; use crate::utils::Counter; use crate::view::View; use crate::{Printer, With}; +use std::cmp; +use std::thread; // pub type CbPromise = Option>; diff --git a/src/views/radio.rs b/src/views/radio.rs index 1545cee..a0fc8ea 100644 --- a/src/views/radio.rs +++ b/src/views/radio.rs @@ -1,12 +1,12 @@ use crate::direction::Direction; use crate::event::{Event, EventResult, Key, MouseButton, MouseEvent}; -use std::cell::RefCell; -use std::rc::Rc; use crate::theme::ColorStyle; use crate::vec::Vec2; use crate::view::View; use crate::Cursive; use crate::{Printer, With}; +use std::cell::RefCell; +use std::rc::Rc; struct SharedState { selection: usize, @@ -207,9 +207,7 @@ impl View for RadioButton { fn on_event(&mut self, event: Event) -> EventResult { match event { - Event::Key(Key::Enter) | Event::Char(' ') => { - self.select() - } + Event::Key(Key::Enter) | Event::Char(' ') => self.select(), Event::Mouse { event: MouseEvent::Release(MouseButton::Left), position, diff --git a/src/views/scroll_view.rs b/src/views/scroll_view.rs index 0267775..c5c8204 100644 --- a/src/views/scroll_view.rs +++ b/src/views/scroll_view.rs @@ -343,10 +343,13 @@ where /// Returns `(inner_size, desired_size)` fn sizes(&mut self, constraint: Vec2, strict: bool) -> (Vec2, Vec2) { // First: try the cache - if !self.inner.needs_relayout() && self - .size_cache - .map(|cache| cache.zip_map(constraint, SizeCache::accept).both()) - .unwrap_or(false) + if !self.inner.needs_relayout() + && self + .size_cache + .map(|cache| { + cache.zip_map(constraint, SizeCache::accept).both() + }) + .unwrap_or(false) { // eprintln!("Cache: {:?}; constraint: {:?}", self.size_cache, constraint); @@ -534,18 +537,15 @@ where Event::Mouse { event: MouseEvent::WheelUp, .. - } - if self.enabled.y && self.offset.y > 0 => - { + } if self.enabled.y && self.offset.y > 0 => { self.offset.y = self.offset.y.saturating_sub(3); } Event::Mouse { event: MouseEvent::WheelDown, .. - } - if self.enabled.y - && (self.offset.y + self.available_size().y - < self.inner_size.y) => + } if self.enabled.y + && (self.offset.y + self.available_size().y + < self.inner_size.y) => { self.offset.y = min( self.inner_size @@ -558,8 +558,8 @@ where event: MouseEvent::Press(MouseButton::Left), position, offset, - } - if self.show_scrollbars && position + } if self.show_scrollbars + && position .checked_sub(offset) .map(|position| self.start_drag(position)) .unwrap_or(false) => @@ -570,9 +570,7 @@ where event: MouseEvent::Hold(MouseButton::Left), position, offset, - } - if self.show_scrollbars => - { + } if self.show_scrollbars => { let position = position.saturating_sub(offset); self.drag(position); } diff --git a/src/views/select_view.rs b/src/views/select_view.rs index 7aef377..0ead1f9 100644 --- a/src/views/select_view.rs +++ b/src/views/select_view.rs @@ -1,12 +1,10 @@ use crate::align::{Align, HAlign, VAlign}; use crate::direction::Direction; -use crate::event::{Callback, Event, EventResult, Key, MouseButton, MouseEvent}; +use crate::event::{ + Callback, Event, EventResult, Key, MouseButton, MouseEvent, +}; use crate::menu::MenuTree; use crate::rect::Rect; -use std::borrow::Borrow; -use std::cell::Cell; -use std::cmp::min; -use std::rc::Rc; use crate::theme::ColorStyle; use crate::utils::markup::StyledString; use crate::vec::Vec2; @@ -15,6 +13,10 @@ use crate::views::MenuPopup; use crate::Cursive; use crate::Printer; use crate::With; +use std::borrow::Borrow; +use std::cell::Cell; +use std::cmp::min; +use std::rc::Rc; /// View to select an item among a list. /// diff --git a/src/views/slider_view.rs b/src/views/slider_view.rs index 1eb4fe2..f030fd2 100644 --- a/src/views/slider_view.rs +++ b/src/views/slider_view.rs @@ -1,11 +1,13 @@ use crate::direction::{Direction, Orientation}; -use crate::event::{Callback, Event, EventResult, Key, MouseButton, MouseEvent}; -use std::rc::Rc; +use crate::event::{ + Callback, Event, EventResult, Key, MouseButton, MouseEvent, +}; use crate::theme::ColorStyle; use crate::vec::Vec2; use crate::view::View; use crate::With; use crate::{Cursive, Printer}; +use std::rc::Rc; /// A horizontal or vertical slider. pub struct SliderView { @@ -169,9 +171,7 @@ impl View for SliderView { event: MouseEvent::Hold(MouseButton::Left), position, offset, - } - if self.dragging => - { + } if self.dragging => { let position = position.saturating_sub(offset); let position = self.orientation.get(&position); let position = ::std::cmp::min( @@ -185,9 +185,7 @@ impl View for SliderView { event: MouseEvent::Press(MouseButton::Left), position, offset, - } - if position.fits_in_rect(offset, self.req_size()) => - { + } if position.fits_in_rect(offset, self.req_size()) => { if let Some(position) = position.checked_sub(offset) { self.dragging = true; self.value = self.orientation.get(&position); diff --git a/src/views/stack_view.rs b/src/views/stack_view.rs index a8ef758..1ce7f97 100644 --- a/src/views/stack_view.rs +++ b/src/views/stack_view.rs @@ -1,13 +1,15 @@ use crate::direction::Direction; use crate::event::{AnyCb, Event, EventResult}; -use std::cell; -use std::ops::Deref; use crate::theme::ColorStyle; use crate::vec::Vec2; -use crate::view::{IntoBoxedView, Offset, Position, Selector, View, ViewWrapper}; +use crate::view::{ + IntoBoxedView, Offset, Position, Selector, View, ViewWrapper, +}; use crate::views::{CircularFocus, Layer, ShadowView, ViewBox}; use crate::Printer; use crate::With; +use std::cell; +use std::ops::Deref; /// Simple stack of views. /// Only the top-most view is active and can receive input. @@ -166,7 +168,9 @@ impl View for ChildWrapper { } } - fn call_on_any<'a>(&mut self, selector: &Selector<'_>, callback: AnyCb<'a>) { + fn call_on_any<'a>( + &mut self, selector: &Selector<'_>, callback: AnyCb<'a>, + ) { match *self { ChildWrapper::Shadow(ref mut v) => { v.call_on_any(selector, callback) diff --git a/src/views/text_area.rs b/src/views/text_area.rs index 4092c87..d1b27dc 100644 --- a/src/views/text_area.rs +++ b/src/views/text_area.rs @@ -1,14 +1,15 @@ use crate::direction::Direction; use crate::event::{Event, EventResult, Key, MouseButton, MouseEvent}; use crate::rect::Rect; -use std::cmp::min; use crate::theme::{ColorStyle, Effect}; -use unicode_segmentation::UnicodeSegmentation; -use unicode_width::UnicodeWidthStr; use crate::utils::lines::simple::{prefix, simple_prefix, LinesIterator, Row}; use crate::vec::Vec2; use crate::view::{ScrollBase, SizeCache, View}; use crate::{Printer, With, XY}; +use log::debug; +use std::cmp::min; +use unicode_segmentation::UnicodeSegmentation; +use unicode_width::UnicodeWidthStr; /// Multi-lines text editor. /// diff --git a/src/views/tracked_view.rs b/src/views/tracked_view.rs index 5edefed..9c02ccb 100644 --- a/src/views/tracked_view.rs +++ b/src/views/tracked_view.rs @@ -1,8 +1,8 @@ -use std::cell::Cell; use crate::vec::Vec2; use crate::view::{View, ViewWrapper}; use crate::views::IdView; use crate::Printer; +use std::cell::Cell; /// Wrapper around a view that remembers its position. pub struct TrackedView { diff --git a/src/views/view_box.rs b/src/views/view_box.rs index 202aa4d..7af45fc 100644 --- a/src/views/view_box.rs +++ b/src/views/view_box.rs @@ -1,5 +1,5 @@ -use std::ops::{Deref, DerefMut}; use crate::view::{IntoBoxedView, View, ViewWrapper}; +use std::ops::{Deref, DerefMut}; /// A boxed `View`. ///