mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Clippy
This commit is contained in:
@@ -35,23 +35,10 @@ use tui::{
|
||||
widgets::Paragraph,
|
||||
};
|
||||
|
||||
// -- state
|
||||
|
||||
struct OwnStates {
|
||||
focus: bool,
|
||||
}
|
||||
|
||||
impl Default for OwnStates {
|
||||
fn default() -> Self {
|
||||
OwnStates { focus: false }
|
||||
}
|
||||
}
|
||||
|
||||
// -- component
|
||||
|
||||
pub struct Text {
|
||||
props: Props,
|
||||
states: OwnStates,
|
||||
}
|
||||
|
||||
impl Text {
|
||||
@@ -59,10 +46,7 @@ impl Text {
|
||||
///
|
||||
/// Instantiate a new Text component
|
||||
pub fn new(props: Props) -> Self {
|
||||
Text {
|
||||
props,
|
||||
states: OwnStates::default(),
|
||||
}
|
||||
Text { props }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,16 +135,12 @@ impl Component for Text {
|
||||
/// ### blur
|
||||
///
|
||||
/// Blur component
|
||||
fn blur(&mut self) {
|
||||
self.states.focus = false;
|
||||
}
|
||||
fn blur(&mut self) {}
|
||||
|
||||
/// ### active
|
||||
///
|
||||
/// Active component
|
||||
fn active(&mut self) {
|
||||
self.states.focus = true;
|
||||
}
|
||||
fn active(&mut self) {}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -189,12 +169,6 @@ mod tests {
|
||||
))
|
||||
.build(),
|
||||
);
|
||||
// Focus
|
||||
assert_eq!(component.states.focus, false);
|
||||
component.active();
|
||||
assert_eq!(component.states.focus, true);
|
||||
component.blur();
|
||||
assert_eq!(component.states.focus, false);
|
||||
// Get value
|
||||
assert_eq!(component.get_value(), Payload::None);
|
||||
// Event
|
||||
|
||||
@@ -99,10 +99,7 @@ impl View {
|
||||
///
|
||||
/// Get component properties
|
||||
pub fn get_props(&self, id: &str) -> Option<PropsBuilder> {
|
||||
match self.components.get(id) {
|
||||
None => None,
|
||||
Some(cmp) => Some(cmp.get_props()),
|
||||
}
|
||||
self.components.get(id).map(|cmp| cmp.get_props())
|
||||
}
|
||||
|
||||
/// update
|
||||
@@ -110,10 +107,9 @@ impl View {
|
||||
/// Update component properties
|
||||
/// Returns `None` if component doesn't exist
|
||||
pub fn update(&mut self, id: &str, props: Props) -> Option<(String, Msg)> {
|
||||
match self.components.get_mut(id) {
|
||||
None => None,
|
||||
Some(cmp) => Some((id.to_string(), cmp.update(props))),
|
||||
}
|
||||
self.components
|
||||
.get_mut(id)
|
||||
.map(|cmp| (id.to_string(), cmp.update(props)))
|
||||
}
|
||||
|
||||
// -- state
|
||||
@@ -122,10 +118,7 @@ impl View {
|
||||
///
|
||||
/// Get component value
|
||||
pub fn get_value(&self, id: &str) -> Option<Payload> {
|
||||
match self.components.get(id) {
|
||||
None => None,
|
||||
Some(cmp) => Some(cmp.get_value()),
|
||||
}
|
||||
self.components.get(id).map(|cmp| cmp.get_value())
|
||||
}
|
||||
|
||||
// -- events
|
||||
@@ -137,10 +130,10 @@ impl View {
|
||||
pub fn on(&mut self, ev: InputEvent) -> Option<(String, Msg)> {
|
||||
match self.focus.as_ref() {
|
||||
None => None,
|
||||
Some(id) => match self.components.get_mut(id) {
|
||||
None => None,
|
||||
Some(cmp) => Some((id.to_string(), cmp.on(ev))),
|
||||
},
|
||||
Some(id) => self
|
||||
.components
|
||||
.get_mut(id)
|
||||
.map(|cmp| (id.to_string(), cmp.on(ev))),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user