mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Clippy
This commit is contained in:
@@ -45,10 +45,7 @@ impl AuthActivity {
|
||||
/// Update auth activity model based on msg
|
||||
/// The function exits when returns None
|
||||
pub(super) fn update(&mut self, msg: Option<(String, Msg)>) -> Option<(String, Msg)> {
|
||||
let ref_msg: Option<(&str, &Msg)> = match msg.as_ref() {
|
||||
None => None,
|
||||
Some((s, msg)) => Some((s, msg)),
|
||||
};
|
||||
let ref_msg: Option<(&str, &Msg)> = msg.as_ref().map(|(s, msg)| (s.as_str(), msg));
|
||||
// Match msg
|
||||
match ref_msg {
|
||||
None => None, // Exit after None
|
||||
|
||||
@@ -185,10 +185,7 @@ impl FileTransferActivity {
|
||||
}
|
||||
|
||||
pub(super) fn action_local_rename(&mut self, input: String) {
|
||||
let entry: Option<FsEntry> = match self.get_local_file_entry() {
|
||||
Some(f) => Some(f.clone()),
|
||||
None => None,
|
||||
};
|
||||
let entry: Option<FsEntry> = self.get_local_file_entry().cloned();
|
||||
if let Some(entry) = entry {
|
||||
let mut dst_path: PathBuf = PathBuf::from(input);
|
||||
// Check if path is relative
|
||||
@@ -265,10 +262,7 @@ impl FileTransferActivity {
|
||||
}
|
||||
|
||||
pub(super) fn action_local_delete(&mut self) {
|
||||
let entry: Option<FsEntry> = match self.get_local_file_entry() {
|
||||
Some(f) => Some(f.clone()),
|
||||
None => None,
|
||||
};
|
||||
let entry: Option<FsEntry> = self.get_local_file_entry().cloned();
|
||||
if let Some(entry) = entry {
|
||||
let full_path: PathBuf = entry.get_abs_path();
|
||||
// Delete file or directory and report status as popup
|
||||
@@ -528,10 +522,7 @@ impl FileTransferActivity {
|
||||
}
|
||||
|
||||
pub(super) fn action_find_transfer(&mut self, idx: usize, name: Option<String>) {
|
||||
let entry: Option<FsEntry> = match self.found.as_ref().unwrap().get(idx) {
|
||||
None => None,
|
||||
Some(e) => Some(e.clone()),
|
||||
};
|
||||
let entry: Option<FsEntry> = self.found.as_ref().unwrap().get(idx).cloned();
|
||||
if let Some(entry) = entry {
|
||||
// Download file
|
||||
match self.tab {
|
||||
@@ -548,10 +539,7 @@ impl FileTransferActivity {
|
||||
}
|
||||
|
||||
pub(super) fn action_find_delete(&mut self, idx: usize) {
|
||||
let entry: Option<FsEntry> = match self.found.as_ref().unwrap().get(idx) {
|
||||
None => None,
|
||||
Some(e) => Some(e.clone()),
|
||||
};
|
||||
let entry: Option<FsEntry> = self.found.as_ref().unwrap().get(idx).cloned();
|
||||
if let Some(entry) = entry {
|
||||
// Download file
|
||||
match self.tab {
|
||||
|
||||
@@ -57,10 +57,7 @@ impl FileTransferActivity {
|
||||
/// Update auth activity model based on msg
|
||||
/// The function exits when returns None
|
||||
pub(super) fn update(&mut self, msg: Option<(String, Msg)>) -> Option<(String, Msg)> {
|
||||
let ref_msg: Option<(&str, &Msg)> = match msg.as_ref() {
|
||||
None => None,
|
||||
Some((s, msg)) => Some((s, msg)),
|
||||
};
|
||||
let ref_msg: Option<(&str, &Msg)> = msg.as_ref().map(|(s, msg)| (s.as_str(), msg));
|
||||
// Match msg
|
||||
match ref_msg {
|
||||
None => None, // Exit after None
|
||||
@@ -132,10 +129,7 @@ impl FileTransferActivity {
|
||||
self.update_local_filelist()
|
||||
}
|
||||
(COMPONENT_EXPLORER_LOCAL, &MSG_KEY_CHAR_I) => {
|
||||
let file: Option<FsEntry> = match self.get_local_file_entry() {
|
||||
Some(f) => Some(f.clone()),
|
||||
None => None,
|
||||
};
|
||||
let file: Option<FsEntry> = self.get_local_file_entry().cloned();
|
||||
if let Some(file) = file {
|
||||
self.mount_file_info(&file);
|
||||
}
|
||||
@@ -251,10 +245,7 @@ impl FileTransferActivity {
|
||||
self.update_remote_filelist()
|
||||
}
|
||||
(COMPONENT_EXPLORER_REMOTE, &MSG_KEY_CHAR_I) => {
|
||||
let file: Option<FsEntry> = match self.get_remote_file_entry() {
|
||||
Some(f) => Some(f.clone()),
|
||||
None => None,
|
||||
};
|
||||
let file: Option<FsEntry> = self.get_remote_file_entry().cloned();
|
||||
if let Some(file) = file {
|
||||
self.mount_file_info(&file);
|
||||
}
|
||||
|
||||
@@ -68,10 +68,7 @@ impl SetupActivity {
|
||||
_ => None,
|
||||
};
|
||||
if let Some(idx) = idx {
|
||||
let key: Option<String> = match config_cli.iter_ssh_keys().nth(idx) {
|
||||
Some(k) => Some(k.clone()),
|
||||
None => None,
|
||||
};
|
||||
let key: Option<String> = config_cli.iter_ssh_keys().nth(idx).cloned();
|
||||
if let Some(key) = key {
|
||||
match config_cli.get_ssh_key(&key) {
|
||||
Ok(opt) => {
|
||||
|
||||
@@ -43,10 +43,7 @@ impl SetupActivity {
|
||||
/// Update auth activity model based on msg
|
||||
/// The function exits when returns None
|
||||
pub(super) fn update(&mut self, msg: Option<(String, Msg)>) -> Option<(String, Msg)> {
|
||||
let ref_msg: Option<(&str, &Msg)> = match msg.as_ref() {
|
||||
None => None,
|
||||
Some((s, msg)) => Some((s, msg)),
|
||||
};
|
||||
let ref_msg: Option<(&str, &Msg)> = msg.as_ref().map(|(s, msg)| (s.as_str(), msg));
|
||||
// Match msg
|
||||
match ref_msg {
|
||||
None => None,
|
||||
|
||||
@@ -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