mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Fix clippy lints
This commit is contained in:
parent
994a3cf545
commit
47d8d23198
@ -63,6 +63,8 @@ pub type ScreenId = usize;
|
|||||||
/// [`send_wrapper`]: https://crates.io/crates/send_wrapper
|
/// [`send_wrapper`]: https://crates.io/crates/send_wrapper
|
||||||
pub type CbSink = Sender<Box<dyn FnOnce(&mut Cursive) + Send>>;
|
pub type CbSink = Sender<Box<dyn FnOnce(&mut Cursive) + Send>>;
|
||||||
|
|
||||||
|
new_default!(Cursive);
|
||||||
|
|
||||||
impl Cursive {
|
impl Cursive {
|
||||||
/// Creates a new Cursive root, and initialize the back-end.
|
/// Creates a new Cursive root, and initialize the back-end.
|
||||||
///
|
///
|
||||||
|
@ -85,7 +85,7 @@ impl Orientation {
|
|||||||
///
|
///
|
||||||
/// * For an horizontal view, returns `(Sum(x), Max(y))`.
|
/// * For an horizontal view, returns `(Sum(x), Max(y))`.
|
||||||
/// * For a vertical view, returns `(Max(x), Sum(y))`.
|
/// * For a vertical view, returns `(Max(x), Sum(y))`.
|
||||||
pub fn stack<'a, T: Iterator<Item = Vec2>>(self, iter: T) -> Vec2 {
|
pub fn stack<T: Iterator<Item = Vec2>>(self, iter: T) -> Vec2 {
|
||||||
match self {
|
match self {
|
||||||
Orientation::Horizontal => {
|
Orientation::Horizontal => {
|
||||||
iter.fold(Vec2::zero(), |a, b| a.stack_horizontal(&b))
|
iter.fold(Vec2::zero(), |a, b| a.stack_horizontal(&b))
|
||||||
|
@ -101,12 +101,14 @@ impl EventTrigger {
|
|||||||
/// Only bare arrow keys without modifiers (Shift, Ctrl, Alt) will be accepted.
|
/// Only bare arrow keys without modifiers (Shift, Ctrl, Alt) will be accepted.
|
||||||
pub fn arrows() -> Self {
|
pub fn arrows() -> Self {
|
||||||
Self::from_fn_and_tag(
|
Self::from_fn_and_tag(
|
||||||
|e| match e {
|
|e| {
|
||||||
Event::Key(Key::Left)
|
matches!(
|
||||||
| Event::Key(Key::Down)
|
e,
|
||||||
| Event::Key(Key::Up)
|
Event::Key(Key::Left)
|
||||||
| Event::Key(Key::Right) => true,
|
| Event::Key(Key::Down)
|
||||||
_ => false,
|
| Event::Key(Key::Up)
|
||||||
|
| Event::Key(Key::Right)
|
||||||
|
)
|
||||||
},
|
},
|
||||||
"arrows",
|
"arrows",
|
||||||
)
|
)
|
||||||
@ -115,9 +117,9 @@ impl EventTrigger {
|
|||||||
/// Returns an `EventTrigger` that only accepts mouse events.
|
/// Returns an `EventTrigger` that only accepts mouse events.
|
||||||
pub fn mouse() -> Self {
|
pub fn mouse() -> Self {
|
||||||
Self::from_fn_and_tag(
|
Self::from_fn_and_tag(
|
||||||
|e| match e {
|
|e| {
|
||||||
Event::Mouse { .. } => true,
|
matches!(e,
|
||||||
_ => false,
|
Event::Mouse { .. })
|
||||||
},
|
},
|
||||||
"mouse",
|
"mouse",
|
||||||
)
|
)
|
||||||
@ -256,18 +258,12 @@ impl EventResult {
|
|||||||
|
|
||||||
/// Returns `true` if `self` is `EventResult::Consumed`.
|
/// Returns `true` if `self` is `EventResult::Consumed`.
|
||||||
pub fn is_consumed(&self) -> bool {
|
pub fn is_consumed(&self) -> bool {
|
||||||
match *self {
|
matches!(*self, EventResult::Consumed(_))
|
||||||
EventResult::Consumed(_) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if `self` contains a callback.
|
/// Returns `true` if `self` contains a callback.
|
||||||
pub fn has_callback(&self) -> bool {
|
pub fn has_callback(&self) -> bool {
|
||||||
match *self {
|
matches!(*self, EventResult::Consumed(Some(_)))
|
||||||
EventResult::Consumed(Some(_)) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Process this result if it is a callback.
|
/// Process this result if it is a callback.
|
||||||
@ -463,12 +459,10 @@ impl MouseEvent {
|
|||||||
/// It means you should be able to grab a scroll bar, and move the mouse
|
/// It means you should be able to grab a scroll bar, and move the mouse
|
||||||
/// away from the view, without actually changing the focus.
|
/// away from the view, without actually changing the focus.
|
||||||
pub fn grabs_focus(self) -> bool {
|
pub fn grabs_focus(self) -> bool {
|
||||||
match self {
|
matches!(self,
|
||||||
MouseEvent::Press(_)
|
MouseEvent::Press(_)
|
||||||
| MouseEvent::WheelUp
|
| MouseEvent::WheelUp
|
||||||
| MouseEvent::WheelDown => true,
|
| MouseEvent::WheelDown)
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,26 +51,17 @@ impl MenuItem {
|
|||||||
|
|
||||||
/// Returns `true` if `self` is a delimiter.
|
/// Returns `true` if `self` is a delimiter.
|
||||||
pub fn is_delimiter(&self) -> bool {
|
pub fn is_delimiter(&self) -> bool {
|
||||||
match *self {
|
matches!(*self, MenuItem::Delimiter)
|
||||||
MenuItem::Delimiter => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if `self` is a leaf node.
|
/// Returns `true` if `self` is a leaf node.
|
||||||
pub fn is_leaf(&self) -> bool {
|
pub fn is_leaf(&self) -> bool {
|
||||||
match *self {
|
matches!(*self, MenuItem::Leaf(_, _))
|
||||||
MenuItem::Leaf(_, _) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if `self` is a subtree.
|
/// Returns `true` if `self` is a subtree.
|
||||||
pub fn is_subtree(&self) -> bool {
|
pub fn is_subtree(&self) -> bool {
|
||||||
match *self {
|
matches!(*self, MenuItem::Subtree(_, _))
|
||||||
MenuItem::Subtree(_, _) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return a mutable reference to the subtree, if applicable.
|
/// Return a mutable reference to the subtree, if applicable.
|
||||||
|
@ -183,10 +183,10 @@ impl Color {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_special(value: &str) -> Option<Color> {
|
fn parse_special(value: &str) -> Option<Color> {
|
||||||
if value.starts_with('#') {
|
if let Some(value) = value.strip_prefix('#') {
|
||||||
parse_hex(&value[1..])
|
parse_hex(value)
|
||||||
} else if value.starts_with("0x") {
|
} else if let Some(value) = value.strip_prefix("0x") {
|
||||||
parse_hex(&value[2..])
|
parse_hex(value)
|
||||||
} else if value.len() == 6 {
|
} else if value.len() == 6 {
|
||||||
parse_hex(value)
|
parse_hex(value)
|
||||||
} else if value.len() == 3 {
|
} else if value.len() == 3 {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use enumset::EnumSetType;
|
use enumset::EnumSetType;
|
||||||
|
|
||||||
/// Text effect
|
/// Text effect
|
||||||
|
#[allow(clippy::derive_hash_xor_eq)] // We do derive it through EnumSetType
|
||||||
#[derive(EnumSetType, Debug, Hash)]
|
#[derive(EnumSetType, Debug, Hash)]
|
||||||
pub enum Effect {
|
pub enum Effect {
|
||||||
/// No effect
|
/// No effect
|
||||||
|
@ -71,6 +71,7 @@ pub type OnSubmit = dyn Fn(&mut Cursive, &str);
|
|||||||
/// ```
|
/// ```
|
||||||
pub struct EditView {
|
pub struct EditView {
|
||||||
/// Current content.
|
/// Current content.
|
||||||
|
#[allow(clippy::rc_buffer)] // Rc::make_mut is what we want here.
|
||||||
content: Rc<String>,
|
content: Rc<String>,
|
||||||
|
|
||||||
/// Cursor position in the content, in bytes.
|
/// Cursor position in the content, in bytes.
|
||||||
@ -357,6 +358,7 @@ impl EditView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the current text.
|
/// Get the current text.
|
||||||
|
#[allow(clippy::rc_buffer)]
|
||||||
pub fn get_content(&self) -> Rc<String> {
|
pub fn get_content(&self) -> Rc<String> {
|
||||||
Rc::clone(&self.content)
|
Rc::clone(&self.content)
|
||||||
}
|
}
|
||||||
|
@ -32,10 +32,7 @@ pub enum GraphemePart {
|
|||||||
impl GraphemePart {
|
impl GraphemePart {
|
||||||
/// Returns true iff GraphemePart is Continuation
|
/// Returns true iff GraphemePart is Continuation
|
||||||
pub fn is_continuation(&self) -> bool {
|
pub fn is_continuation(&self) -> bool {
|
||||||
match *self {
|
matches!(*self, GraphemePart::Continuation)
|
||||||
GraphemePart::Continuation => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns Some(String) if GraphemePart is Begin(String), else None.
|
/// Returns Some(String) if GraphemePart is Begin(String), else None.
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
use crate::{backend, backends, Cursive};
|
use crate::{backend, backends, Cursive};
|
||||||
|
|
||||||
|
type Initializer =
|
||||||
|
dyn FnMut()
|
||||||
|
-> Result<Box<dyn backend::Backend>, Box<dyn std::error::Error>>;
|
||||||
|
|
||||||
/// A runnable wrapper around `Cursive`, bundling the backend initializer.
|
/// A runnable wrapper around `Cursive`, bundling the backend initializer.
|
||||||
///
|
///
|
||||||
/// This struct embeds both `Cursive` and a backend-initializer
|
/// This struct embeds both `Cursive` and a backend-initializer
|
||||||
@ -12,12 +16,7 @@ use crate::{backend, backends, Cursive};
|
|||||||
/// regular `Cursive` object.
|
/// regular `Cursive` object.
|
||||||
pub struct CursiveRunnable {
|
pub struct CursiveRunnable {
|
||||||
siv: Cursive,
|
siv: Cursive,
|
||||||
backend_init: Box<
|
backend_init: Box<Initializer>,
|
||||||
dyn FnMut() -> Result<
|
|
||||||
Box<dyn backend::Backend>,
|
|
||||||
Box<dyn std::error::Error>,
|
|
||||||
>,
|
|
||||||
>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::ops::Deref for CursiveRunnable {
|
impl std::ops::Deref for CursiveRunnable {
|
||||||
|
Loading…
Reference in New Issue
Block a user