summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Zhao <jeff.no.zhao@gmail.com>2021-01-31 15:06:15 -0500
committerJeff Zhao <jeff.no.zhao@gmail.com>2021-01-31 15:06:15 -0500
commit6268cbbeca71e77ca2c0999f41c313926cb98531 (patch)
tree1efbb95b906b1216568205d5a0b0fdaa45a3a9cf
parent9af4f6eee5ef8f5a50dba981be3cbd05add95e73 (diff)
code cleanup
-rw-r--r--src/commands/file_ops.rs16
-rw-r--r--src/config/keymap.rs4
-rw-r--r--src/run.rs2
-rw-r--r--src/ui/tui_backend.rs10
-rw-r--r--src/util/to_string.rs2
5 files changed, 20 insertions, 14 deletions
diff --git a/src/commands/file_ops.rs b/src/commands/file_ops.rs
index 71012f9..19b13b6 100644
--- a/src/commands/file_ops.rs
+++ b/src/commands/file_ops.rs
@@ -47,21 +47,25 @@ pub fn paste(context: &mut JoshutoContext, options: IOWorkerOptions) -> JoshutoR
#[cfg(feature = "clipboard")]
pub fn copy_filename(context: &mut JoshutoContext) -> JoshutoResult<()> {
- if let Some(entry) = context
+ let entry_file_name = match context
.tab_context_ref()
.curr_tab_ref()
.curr_list_ref()
.and_then(|c| c.curr_entry_ref())
{
- let ret = match cli_clipboard::set_contents(entry.file_name().to_string()) {
+ Some(entry) => Some(entry.file_name().to_string()),
+ None => None,
+ };
+ if let Some(content) = entry_file_name {
+ let ret = match cli_clipboard::set_contents(content.clone()) {
+ Ok(_) => {
+ context.push_msg(format!("Copied '{}' to clipboard", content.as_str()));
+ Ok(())
+ }
Err(e) => Err(JoshutoError::new(
JoshutoErrorKind::ClipboardError,
format!("{:?}", e),
)),
- s => {
- context.push_msg(format!("Copied '{}' to clipboard", entry.file_name()));
- Ok(())
- }
};
return ret;
}
diff --git a/src/config/keymap.rs b/src/config/keymap.rs
index 80f0a6f..1e37358 100644
--- a/src/config/keymap.rs
+++ b/src/config/keymap.rs
@@ -2,7 +2,9 @@ use std::collections::{hash_map::Entry, HashMap};
use serde_derive::Deserialize;
-use termion::event::{Event, Key, MouseEvent};
+#[cfg(feature = "mouse")]
+use termion::event::MouseEvent;
+use termion::event::{Event, Key};
use super::{parse_to_config_file, ConfigStructure, Flattenable};
use crate::commands::{CommandKeybind, KeyCommand};
diff --git a/src/run.rs b/src/run.rs
index ad74ff1..e011973 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -1,7 +1,7 @@
use termion::event::Event;
use crate::commands::{CommandKeybind, JoshutoRunnable, KeyCommand};
-use crate::config::{JoshutoCommandMapping, JoshutoConfig};
+use crate::config::JoshutoCommandMapping;
use crate::context::JoshutoContext;
use crate::tab::JoshutoTab;
use crate::ui;
diff --git a/src/ui/tui_backend.rs b/src/ui/tui_backend.rs
index 9745226..7d98207 100644
--- a/src/ui/tui_backend.rs
+++ b/src/ui/tui_backend.rs
@@ -1,12 +1,14 @@
use std::io::stdout;
use std::io::Write;
-use termion::input::MouseTerminal;
use termion::raw::{IntoRawMode, RawTerminal};
use termion::screen::AlternateScreen;
use tui::backend::TermionBackend;
use tui::widgets::Widget;
+#[cfg(feature = "mouse")]
+use termion::input::MouseTerminal;
+
trait New {
fn new() -> std::io::Result<Self>
where
@@ -19,8 +21,7 @@ type Screen = MouseTerminal<AlternateScreen<RawTerminal<std::io::Stdout>>>;
impl New for Screen {
fn new() -> std::io::Result<Self> {
let stdout = std::io::stdout().into_raw_mode()?;
-
- let mut alt_screen = MouseTerminal::from(AlternateScreen::from(stdout));
+ let alt_screen = MouseTerminal::from(AlternateScreen::from(stdout));
return Ok(alt_screen);
}
}
@@ -30,8 +31,7 @@ type Screen = AlternateScreen<RawTerminal<std::io::Stdout>>;
impl New for Screen {
fn new() -> std::io::Result<Self> {
let stdout = std::io::stdout().into_raw_mode()?;
-
- let mut alt_screen = AlternateScreen::from(stdout);
+ let alt_screen = AlternateScreen::from(stdout);
return Ok(alt_screen);
}
}
diff --git a/src/util/to_string.rs b/src/util/to_string.rs
index 22d1f02..eefb075 100644
--- a/src/util/to_string.rs
+++ b/src/util/to_string.rs
@@ -1,4 +1,4 @@
-use termion::event::{Event, Key, MouseButton, MouseEvent};
+use termion::event::{Event, Key, MouseEvent};
pub trait ToString {
fn to_string(&self) -> String;