diff options
author | Jeff Zhao <jeff.no.zhao@gmail.com> | 2021-04-16 11:25:27 -0400 |
---|---|---|
committer | Jeff Zhao <jeff.no.zhao@gmail.com> | 2021-04-16 13:46:30 -0400 |
commit | a98af4f70d1b58ae7b2ece410c22d247240a2b1e (patch) | |
tree | ce110859292c798779d32fb9a8d4bd318b37cece | |
parent | ec6138539b8102dd44736199ce9f3f0ecba92b40 (diff) |
code cleanup
-rw-r--r-- | src/commands/bulk_rename.rs | 2 | ||||
-rw-r--r-- | src/commands/file_ops.rs | 8 | ||||
-rw-r--r-- | src/commands/key_command.rs | 24 | ||||
-rw-r--r-- | src/commands/open_file.rs | 4 | ||||
-rw-r--r-- | src/commands/quit.rs | 2 | ||||
-rw-r--r-- | src/config/keymap.rs | 4 | ||||
-rw-r--r-- | src/context/context.rs | 24 | ||||
-rw-r--r-- | src/error.rs | 74 | ||||
-rw-r--r-- | src/io/io_observer.rs | 10 | ||||
-rw-r--r-- | src/io/io_worker.rs | 42 | ||||
-rw-r--r-- | src/io/mod.rs | 6 | ||||
-rw-r--r-- | src/ui/tui_backend.rs | 2 | ||||
-rw-r--r-- | src/ui/views/tui_folder_view.rs | 12 | ||||
-rw-r--r-- | src/ui/widgets/tui_dirlist.rs | 2 | ||||
-rw-r--r-- | src/ui/widgets/tui_footer.rs | 2 | ||||
-rw-r--r-- | src/util/event.rs | 16 | ||||
-rw-r--r-- | src/util/input.rs | 10 | ||||
-rw-r--r-- | src/util/mod.rs | 1 | ||||
-rw-r--r-- | src/util/name_resolution.rs (renamed from src/io/name_resolution.rs) | 0 |
19 files changed, 121 insertions, 124 deletions
diff --git a/src/commands/bulk_rename.rs b/src/commands/bulk_rename.rs index 1b1ffb4..bd873e0 100644 --- a/src/commands/bulk_rename.rs +++ b/src/commands/bulk_rename.rs @@ -85,7 +85,7 @@ pub fn _bulk_rename(context: &mut JoshutoContext) -> JoshutoResult<()> { } if paths_renamed.len() < paths.len() { return Err(JoshutoError::new( - JoshutoErrorKind::IOInvalidInput, + JoshutoErrorKind::IoInvalidInput, "Insufficient inputs".to_string(), )); } diff --git a/src/commands/file_ops.rs b/src/commands/file_ops.rs index 8abc19b..92bb174 100644 --- a/src/commands/file_ops.rs +++ b/src/commands/file_ops.rs @@ -4,7 +4,7 @@ use crate::context::{JoshutoContext, LocalStateContext}; use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult}; use crate::io::FileOp; -use crate::io::{IOWorkerOptions, IOWorkerThread}; +use crate::io::{IoWorkerOptions, IoWorkerThread}; pub fn cut(context: &mut JoshutoContext) -> JoshutoResult<()> { if let Some(list) = context.tab_context_ref().curr_tab_ref().curr_list_ref() { @@ -32,16 +32,16 @@ pub fn copy(context: &mut JoshutoContext) -> JoshutoResult<()> { Ok(()) } -pub fn paste(context: &mut JoshutoContext, options: IOWorkerOptions) -> JoshutoResult<()> { +pub fn paste(context: &mut JoshutoContext, options: IoWorkerOptions) -> JoshutoResult<()> { match context.take_local_state() { Some(state) if !state.paths.is_empty() => { let dest = context.tab_context_ref().curr_tab_ref().pwd().to_path_buf(); - let worker_thread = IOWorkerThread::new(state.file_op, state.paths, dest, options); + let worker_thread = IoWorkerThread::new(state.file_op, state.paths, dest, options); context.add_worker(worker_thread); Ok(()) } _ => Err(JoshutoError::new( - JoshutoErrorKind::IOInvalidData, + JoshutoErrorKind::IoInvalidData, "no files selected".to_string(), )), } diff --git a/src/commands/key_command.rs b/src/commands/key_command.rs index 79ad1d9..3ae2cee 100644 --- a/src/commands/key_command.rs +++ b/src/commands/key_command.rs @@ -2,7 +2,7 @@ use std::path; use crate::context::JoshutoContext; use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult}; -use crate::io::IOWorkerOptions; +use crate::io::IoWorkerOptions; use crate::ui::TuiBackend; use crate::util::load_child::LoadChild; use crate::util::sort::SortType; @@ -21,7 +21,7 @@ pub enum KeyCommand { CutFiles, CopyFiles, - PasteFiles(IOWorkerOptions), + PasteFiles(IoWorkerOptions), CopyFileName, CursorMoveUp(usize), @@ -198,7 +198,7 @@ impl KeyCommand { "force_quit" => Ok(Self::ForceQuit), "mkdir" => match arg { "" => Err(JoshutoError::new( - JoshutoErrorKind::IOInvalidData, + JoshutoErrorKind::IoInvalidData, format!("{}: missing additional parameter", command), )), arg => Ok(Self::NewDirectory(path::PathBuf::from(arg))), @@ -208,14 +208,14 @@ impl KeyCommand { "open_file" => Ok(Self::OpenFile), "open_file_with" => Ok(Self::OpenFileWith), "paste_files" => { - let mut options = IOWorkerOptions::default(); + let mut options = IoWorkerOptions::default(); for arg in arg.split_whitespace() { match arg { "--overwrite" => options.overwrite = true, "--skip_exist" => options.skip_exist = true, _ => { return Err(JoshutoError::new( - JoshutoErrorKind::IOInvalidData, + JoshutoErrorKind::IoInvalidData, format!("{}: unknown option {}", command, arg), )); } @@ -227,7 +227,7 @@ impl KeyCommand { "reload_dir_list" => Ok(Self::ReloadDirList), "rename" => match arg { "" => Err(JoshutoError::new( - JoshutoErrorKind::IOInvalidData, + JoshutoErrorKind::IoInvalidData, format!("{}: Expected 1, got 0", command), )), arg => { @@ -239,7 +239,7 @@ impl KeyCommand { "rename_prepend" => Ok(Self::RenameFilePrepend), "search" => match arg { "" => Err(JoshutoError::new( - JoshutoErrorKind::IOInvalidData, + JoshutoErrorKind::IoInvalidData, format!("{}: Expected 1, got 0", command), )), arg => Ok(Self::Search(arg.to_string())), @@ -255,7 +255,7 @@ impl KeyCommand { "--all" => all = true, _ => { return Err(JoshutoError::new( - JoshutoErrorKind::IOInvalidData, + JoshutoErrorKind::IoInvalidData, format!("{}: unknown option {}", command, arg), )); } @@ -267,11 +267,11 @@ impl KeyCommand { "shell" => match shell_words::split(arg) { Ok(s) if !s.is_empty() => Ok(Self::ShellCommand(s)), Ok(_) => Err(JoshutoError::new( - JoshutoErrorKind::IOInvalidData, + JoshutoErrorKind::IoInvalidData, format!("sort: args {}", arg), )), Err(e) => Err(JoshutoError::new( - JoshutoErrorKind::IOInvalidData, + JoshutoErrorKind::IoInvalidData, format!("{}: {}", arg, e), )), }, @@ -281,7 +281,7 @@ impl KeyCommand { arg => match SortType::parse(arg) { Some(s) => Ok(Self::Sort(s)), None => Err(JoshutoError::new( - JoshutoErrorKind::IOInvalidData, + JoshutoErrorKind::IoInvalidData, format!("sort: Unknown option {}", arg), )), }, @@ -289,7 +289,7 @@ impl KeyCommand { "tab_switch" => match arg.parse::<i32>() { Ok(s) => Ok(Self::TabSwitch(s)), Err(e) => Err(JoshutoError::new( - JoshutoErrorKind::IOInvalidData, + JoshutoErrorKind::IoInvalidData, format!("{}: {}", command, e.to_string()), )), }, diff --git a/src/commands/open_file.rs b/src/commands/open_file.rs index 0f3105f..c815069 100644 --- a/src/commands/open_file.rs +++ b/src/commands/open_file.rs @@ -41,7 +41,7 @@ pub fn open(context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoRe }; if paths.is_empty() { return Err(JoshutoError::new( - JoshutoErrorKind::IONotFound, + JoshutoErrorKind::IoNotFound, String::from("No files selected"), )); } @@ -138,7 +138,7 @@ pub fn open_with(context: &mut JoshutoContext, backend: &mut TuiBackend) -> Josh }; if paths.is_empty() { return Err(JoshutoError::new( - JoshutoErrorKind::IONotFound, + JoshutoErrorKind::IoNotFound, String::from("No files selected"), )); } diff --git a/src/commands/quit.rs b/src/commands/quit.rs index 29b7c36..3ed1d76 100644 --- a/src/commands/quit.rs +++ b/src/commands/quit.rs @@ -4,7 +4,7 @@ use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult}; pub fn quit(context: &mut JoshutoContext) -> JoshutoResult<()> { if context.worker_is_busy() { Err(JoshutoError::new( - JoshutoErrorKind::IOOther, + JoshutoErrorKind::IoOther, String::from("operations running in background, use force_quit to quit"), )) } else { diff --git a/src/config/keymap.rs b/src/config/keymap.rs index 1e37358..96e48a5 100644 --- a/src/config/keymap.rs +++ b/src/config/keymap.rs @@ -8,7 +8,7 @@ use termion::event::{Event, Key}; use super::{parse_to_config_file, ConfigStructure, Flattenable}; use crate::commands::{CommandKeybind, KeyCommand}; -use crate::io::IOWorkerOptions; +use crate::io::IoWorkerOptions; use crate::util::key_mapping::str_to_event; use crate::KEYMAP_FILE; @@ -138,7 +138,7 @@ impl JoshutoCommandMapping { let keys = [Event::Key(Key::Char('y')), Event::Key(Key::Char('y'))]; insert_keycommand(&mut m, cmd, &keys)?; - let cmd = KeyCommand::PasteFiles(IOWorkerOptions::default()); + let cmd = KeyCommand::PasteFiles(IoWorkerOptions::default()); let keys = [Event::Key(Key::Char('p')), Event::Key(Key::Char('p'))]; insert_keycommand(&mut m, cmd, &keys)?; diff --git a/src/context/context.rs b/src/context/context.rs index 574b7af..5e5bb0e 100644 --- a/src/context/context.rs +++ b/src/context/context.rs @@ -5,7 +5,7 @@ use std::thread; use crate::config; use crate::context::{LocalStateContext, TabContext}; -use crate::io::{IOWorkerObserver, IOWorkerProgress, IOWorkerThread}; +use crate::io::{IoWorkerObserver, IoWorkerProgress, IoWorkerThread}; use crate::util::event::{Events, JoshutoEvent}; pub struct JoshutoContext { @@ -16,8 +16,8 @@ pub struct JoshutoContext { local_state: Option<LocalStateContext>, search_state: Option<String>, message_queue: VecDeque<String>, - worker_queue: VecDeque<IOWorkerThread>, - worker: Option<IOWorkerObserver>, + worker_queue: VecDeque<IoWorkerThread>, + worker: Option<IoWorkerObserver>, } impl JoshutoContext { @@ -88,7 +88,7 @@ impl JoshutoContext { } // worker related - pub fn add_worker(&mut self, thread: IOWorkerThread) { + pub fn add_worker(&mut self, thread: IoWorkerThread) { self.worker_queue.push_back(thread); } pub fn worker_is_busy(&self) -> bool { @@ -98,15 +98,15 @@ impl JoshutoContext { self.worker_queue.is_empty() } - pub fn worker_iter(&self) -> Iter<IOWorkerThread> { + pub fn worker_iter(&self) -> Iter<IoWorkerThread> { self.worker_queue.iter() } - pub fn worker_ref(&self) -> Option<&IOWorkerObserver> { + pub fn worker_ref(&self) -> Option<&IoWorkerObserver> { self.worker.as_ref() } - pub fn set_worker_progress(&mut self, res: IOWorkerProgress) { + pub fn set_worker_progress(&mut self, res: IoWorkerProgress) { if let Some(s) = self.worker.as_mut() { s.set_progress(res); } @@ -134,26 +134,26 @@ impl JoshutoContext { let worker_handle = thread::spawn(move || worker.start(wtx)); // relay worker info to event loop while let Ok(progress) = wrx.recv() { - let _ = tx.send(JoshutoEvent::IOWorkerProgress(progress)); + let _ = tx.send(JoshutoEvent::IoWorkerProgress(progress)); } let result = worker_handle.join(); match result { Ok(res) => { - let _ = tx.send(JoshutoEvent::IOWorkerResult(res)); + let _ = tx.send(JoshutoEvent::IoWorkerResult(res)); } Err(_) => { let err = std::io::Error::new(std::io::ErrorKind::Other, "Sending Error"); - let _ = tx.send(JoshutoEvent::IOWorkerResult(Err(err))); + let _ = tx.send(JoshutoEvent::IoWorkerResult(Err(err))); } } }); - let observer = IOWorkerObserver::new(handle, src, dest); + let observer = IoWorkerObserver::new(handle, src, dest); self.worker = Some(observer); } } - pub fn remove_job(&mut self) -> Option<IOWorkerObserver> { + pub fn remove_job(&mut self) -> Option<IoWorkerObserver> { self.worker.take() } } diff --git a/src/error.rs b/src/error.rs index bbdd116..68e5d6a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -2,26 +2,26 @@ use std::io::ErrorKind; #[derive(Copy, Clone, Debug)] pub enum JoshutoErrorKind { - IONotFound, - IOPermissionDenied, - IOConnectionRefused, - IOConnectionReset, - IOConnectionAborted, - IONotConnected, - IOAddrInUse, - IOAddrNotAvailable, - IOBrokenPipe, - IOAlreadyExists, - IOWouldBlock, - IOInvalidInput, + IoNotFound, + IoPermissionDenied, + IoConnectionRefused, + IoConnectionReset, + IoConnectionAborted, + IoNotConnected, + IoAddrInUse, + IoAddrNotAvailable, + IoBrokenPipe, + IoAlreadyExists, + IoWouldBlock, + IoInvalidInput, // also used for invalid arguments - IOInvalidData, - IOTimedOut, - IOWriteZero, - IOInterrupted, - IOOther, - IOUnexpectedEof, + IoInvalidData, + IoTimedOut, + IoWriteZero, + IoInterrupted, + IoOther, + IoUnexpectedEof, // environment variable not found EnvVarNotPresent, @@ -35,25 +35,25 @@ pub enum JoshutoErrorKind { impl std::convert::From<ErrorKind> for JoshutoErrorKind { fn from(err: ErrorKind) -> Self { match err { - ErrorKind::NotFound => JoshutoErrorKind::IONotFound, - ErrorKind::PermissionDenied => JoshutoErrorKind::IOPermissionDenied, - ErrorKind::ConnectionRefused => JoshutoErrorKind::IOConnectionRefused, - ErrorKind::ConnectionReset => JoshutoErrorKind::IOConnectionReset, - ErrorKind::ConnectionAborted => JoshutoErrorKind::IOConnectionAborted, - ErrorKind::NotConnected => JoshutoErrorKind::IONotConnected, - ErrorKind::AddrInUse => JoshutoErrorKind::IOAddrInUse, - ErrorKind::AddrNotAvailable => JoshutoErrorKind::IOAddrNotAvailable, - ErrorKind::BrokenPipe => JoshutoErrorKind::IOBrokenPipe, - ErrorKind::AlreadyExists => JoshutoErrorKind::IOAlreadyExists, - ErrorKind::WouldBlock => JoshutoErrorKind::IOWouldBlock, - ErrorKind::InvalidInput => JoshutoErrorKind::IOInvalidInput, - ErrorKind::InvalidData => JoshutoErrorKind::IOInvalidData, - ErrorKind::TimedOut => JoshutoErrorKind::IOTimedOut, - ErrorKind::WriteZero => JoshutoErrorKind::IOWriteZero, - ErrorKind::Interrupted => JoshutoErrorKind::IOInterrupted, - ErrorKind::UnexpectedEof => JoshutoErrorKind::IOUnexpectedEof, - ErrorKind::Other => JoshutoErrorKind::IOOther, - _ => JoshutoErrorKind::IOOther, + ErrorKind::NotFound => JoshutoErrorKind::IoNotFound, + ErrorKind::PermissionDenied => JoshutoErrorKind::IoPermissionDenied, + ErrorKind::ConnectionRefused => JoshutoErrorKind::IoConnectionRefused, + ErrorKind::ConnectionReset => JoshutoErrorKind::IoConnectionReset, + ErrorKind::ConnectionAborted => JoshutoErrorKind::IoConnectionAborted, + ErrorKind::NotConnected => JoshutoErrorKind::IoNotConnected, + ErrorKind::AddrInUse => JoshutoErrorKind::IoAddrInUse, + ErrorKind::AddrNotAvailable => JoshutoErrorKind::IoAddrNotAvailable, + ErrorKind::BrokenPipe => JoshutoErrorKind::IoBrokenPipe, + ErrorKind::AlreadyExists => JoshutoErrorKind::IoAlreadyExists, + ErrorKind::WouldBlock => JoshutoErrorKind::IoWouldBlock, + ErrorKind::InvalidInput => JoshutoErrorKind::IoInvalidInput, + ErrorKind::InvalidData => JoshutoErrorKind::IoInvalidData, + ErrorKind::TimedOut => JoshutoErrorKind::IoTimedOut, + ErrorKind::WriteZero => JoshutoErrorKind::IoWriteZero, + ErrorKind::Interrupted => JoshutoErrorKind::IoInterrupted, + ErrorKind::UnexpectedEof => JoshutoErrorKind::IoUnexpectedEof, + ErrorKind::Other => JoshutoErrorKind::IoOther, + _ => JoshutoErrorKind::IoOther, } } } diff --git a/src/io/io_observer.rs b/src/io/io_observer.rs index 532b6f5..eb7a829 100644 --- a/src/io/io_observer.rs +++ b/src/io/io_observer.rs @@ -1,19 +1,19 @@ use std::path; use std::thread; -use crate::io::{FileOp, IOWorkerProgress}; +use crate::io::{FileOp, IoWorkerProgress}; use crate::util::format; #[derive(Debug)] -pub struct IOWorkerObserver { +pub struct IoWorkerObserver { pub handle: thread::JoinHandle<()>, - pub progress: Option<IOWorkerProgress>, + pub progress: Option<IoWorkerProgress>, msg: String, src: path::PathBuf, dest: path::PathBuf, } -impl IOWorkerObserver { +impl IoWorkerObserver { pub fn new(handle: thread::JoinHandle<()>, src: path::PathBuf, dest: path::PathBuf) -> Self { Self { handle, @@ -27,7 +27,7 @@ impl IOWorkerObserver { pub fn join(self) -> bool { matches!(self.handle.join(), Ok(_)) } - pub fn set_progress(&mut self, progress: IOWorkerProgress) { + pub fn set_progress(&mut self, progress: IoWorkerProgress) { self.progress = Some(progress); } pub fn update_msg(&mut self) { diff --git a/src/io/io_worker.rs b/src/io/io_worker.rs index 97af52a..58cf1d1 100644 --- a/src/io/io_worker.rs +++ b/src/io/io_worker.rs @@ -2,7 +2,7 @@ use std::fs; use std::path; use std::sync::mpsc; -use super::rename_filename_conflict; +use crate::util::name_resolution::rename_filename_conflict; #[derive(Clone, Copy, Debug)] pub enum FileOp { @@ -11,12 +11,12 @@ pub enum FileOp { } #[derive(Clone, Debug)] -pub struct IOWorkerOptions { +pub struct IoWorkerOptions { pub overwrite: bool, pub skip_exist: bool, } -impl std::default::Default for IOWorkerOptions { +impl std::default::Default for IoWorkerOptions { fn default() -> Self { Self { overwrite: false, @@ -25,7 +25,7 @@ impl std::default::Default for IOWorkerOptions { } } -impl std::fmt::Display for IOWorkerOptions { +impl std::fmt::Display for IoWorkerOptions { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!( f, @@ -36,14 +36,14 @@ impl std::fmt::Display for IOWorkerOptions { } #[derive(Clone, Debug)] -pub struct IOWorkerProgress { +pub struct IoWorkerProgress { _kind: FileOp, _index: usize, _len: usize, _processed: u64, } -impl IOWorkerProgress { +impl IoWorkerProgress { pub fn new(_kind: FileOp, _index: usize, _len: usize, _processed: u64) -> Self { Self { _kind, @@ -79,19 +79,19 @@ impl IOWorkerProgress { } #[derive(Debug)] -pub struct IOWorkerThread { +pub struct IoWorkerThread { _kind: FileOp, - pub options: IOWorkerOptions, + pub options: IoWorkerOptions, pub paths: Vec<path::PathBuf>, pub dest: path::PathBuf, } -impl IOWorkerThread { +impl IoWorkerThread { pub fn new( _kind: FileOp, paths: Vec<path::PathBuf>, dest: path::PathBuf, - options: IOWorkerOptions, + options: IoWorkerOptions, ) -> Self { Self { _kind, @@ -105,15 +105,15 @@ impl IOWorkerThread { self._kind } - pub fn start(&self, tx: mpsc::Sender<IOWorkerProgress>) -> std::io::Result<IOWorkerProgress> { + pub fn start(&self, tx: mpsc::Sender<IoWorkerProgress>) -> std::io::Result<IoWorkerProgress> { match self.kind() { FileOp::Cut => self.paste_cut(tx), FileOp::Copy => self.paste_copy(tx), } } - fn paste_copy(&self, tx: mpsc::Sender<IOWorkerProgress>) -> std::io::Result<IOWorkerProgress> { - let mut progress = IOWorkerProgress::new(self.kind(), 0, self.paths.len(), 0); + fn paste_copy(&self, tx: mpsc::Sender<IoWorkerProgress>) -> std::io::Result<IoWorkerProgress> { + let mut progress = IoWorkerProgress::new(self.kind(), 0, self.paths.len(), 0); for (i, path) in self.paths.iter().enumerate() { progress.set_index(i); let _ = tx.send(progress.clone()); @@ -124,7 +124,7 @@ impl IOWorkerThread { &mut progress, )?; } - Ok(IOWorkerProgress::new( + Ok(IoWorkerProgress::new( self.kind(), self.paths.len(), self.paths.len(), @@ -132,8 +132,8 @@ impl IOWorkerThread { )) } - fn paste_cut(&self, tx: mpsc::Sender<IOWorkerProgress>) -> std::io::Result<IOWorkerProgress> { - let mut progress = IOWorkerProgress::new(self.kind(), 0, self.paths.len(), 0); + fn paste_cut(&self, tx: mpsc::Sender<IoWorkerProgress>) -> std::io::Result<IoWorkerProgress> { + let mut progress = IoWorkerProgress::new(self.kind(), 0, self.paths.len(), 0); for (i, path) in self.paths.iter().enumerate() { progress.set_index(i); let _ = tx.send(progress.clone()); @@ -144,7 +144,7 @@ impl IOWorkerThread { &mut progress, )?; } - Ok(IOWorkerProgress::new( + Ok(IoWorkerProgress::new( self.kind(), self.paths.len(), self.paths.len(), @@ -156,8 +156,8 @@ impl IOWorkerThread { pub fn recursive_copy( src: &path::Path, dest: &path::Path, - tx: mpsc::Sender<IOWorkerProgress>, - progress: &mut IOWorkerProgress, + tx: mpsc::Sender<IoWorkerProgress>, + progress: &mut IoWorkerProgress, ) -> std::io::Result<()> { let mut dest_buf = dest.to_path_buf(); if let Some(s) = src.file_name() { @@ -195,8 +195,8 @@ pub fn recursive_copy( pub fn recursive_cut( src: &path::Path, dest: &path::Path, - tx: mpsc::Sender<IOWorkerProgress>, - progress: &mut IOWorkerProgress, + tx: mpsc::Sender<IoWorkerProgress>, + progress: &mut IoWorkerProgress, ) -> std::io::Result<()> { let mut dest_buf = dest.to_path_buf(); if let Some(s) = src.file_name() { diff --git a/src/io/mod.rs b/src/io/mod.rs index f360d19..f577cc6 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -1,7 +1,5 @@ mod io_observer; mod io_worker; -mod name_resolution; -pub use io_observer::IOWorkerObserver; -pub use io_worker::{FileOp, IOWorkerOptions, IOWorkerProgress, IOWorkerThread}; -pub use name_resolution::rename_filename_conflict; +pub use io_observer::IoWorkerObserver; +pub use io_worker::{FileOp, IoWorkerOptions, IoWorkerProgress, IoWorkerThread}; diff --git a/src/ui/tui_backend.rs b/src/ui/tui_backend.rs index 7d98207..f04450d 100644 --- a/src/ui/tui_backend.rs +++ b/src/ui/tui_backend.rs @@ -32,7 +32,7 @@ impl New for Screen { fn new() -> std::io::Result<Self> { let stdout = std::io::stdout().into_raw_mode()?; let alt_screen = AlternateScreen::from(stdout); - return Ok(alt_screen); + Ok(alt_screen) } } diff --git a/src/ui/views/tui_folder_view.rs b/src/ui/views/tui_folder_view.rs index f34fa9f..65e4d6b 100644 --- a/src/ui/views/tui_folder_view.rs +++ b/src/ui/views/tui_folder_view.rs @@ -47,8 +47,8 @@ impl<'a> Widget for TuiFolderView<'a> { ..area }; let block = Block::default().borders(Borders::ALL); - let inner = block.inner(area.clone()); - block.render(area.clone(), buf); + let inner = block.inner(area); + block.render(area, buf); let layout_rect = Layout::default() .direction(Direction::Horizontal) @@ -56,12 +56,12 @@ impl<'a> Widget for TuiFolderView<'a> { .split(inner); let block = Block::default().borders(Borders::RIGHT); - let inner1 = block.inner(layout_rect[0].clone()); - block.render(layout_rect[0].clone(), buf); + let inner1 = block.inner(layout_rect[0]); + block.render(layout_rect[0], buf); let block = Block::default().borders(Borders::LEFT); - let inner3 = block.inner(layout_rect[2].clone()); - block.render(layout_rect[2].clone(), buf); + let inner3 = block.inner(layout_rect[2]); + block.render(layout_rect[2], buf); vec![inner1, layout_rect[1], inner3] } else { diff --git a/src/ui/widgets/tui_dirlist.rs b/src/ui/widgets/tui_dirlist.rs index 8d410dc..0d88354 100644 --- a/src/ui/widgets/tui_dirlist.rs +++ b/src/ui/widgets/tui_dirlist.rs @@ -29,7 +29,7 @@ impl<'a> Widget for TuiDirList<'a> { let x = area.left(); let y = area.top(); - if self.dirlist.contents.len() == 0 { + if self.dirlist.contents.is_empty() { let style = Style::default().bg(Color::Red).fg(Color::White); buf.set_stringn(x, y, "empty", area.width as usize, style); return; diff --git a/src/ui/widgets/tui_footer.rs b/src/ui/widgets/tui_footer.rs index 603d5a6..1597553 100644 --- a/src/ui/widgets/tui_footer.rs +++ b/src/ui/widgets/tui_footer.rs @@ -32,7 +32,7 @@ impl<'a> Widget for TuiFooter<'a> { #[cfg(unix)] let mimetype = match entry.metadata.mimetype.as_ref() { - Some(s) => s, + Some(s) => s.as_str(), None => "", }; diff --git a/src/util/event.rs b/src/util/event.rs index 4d79035..fc3e1b2 100644 --- a/src/util/event.rs +++ b/src/util/event.rs @@ -9,13 +9,13 @@ use signal_hook::iterator::SignalsInfo; use termion::event::Event; use termion::input::TermRead; -use crate::io::IOWorkerProgress; +use crate::io::IoWorkerProgress; #[derive(Debug)] pub enum JoshutoEvent { Termion(Event), - IOWorkerProgress(IOWorkerProgress), - IOWorkerResult(io::Result<IOWorkerProgress>), + IoWorkerProgress(IoWorkerProgress), + IoWorkerResult(io::Result<IoWorkerProgress>), Signal(i32), // Filesystem(notify::Result), } @@ -78,12 +78,10 @@ impl Events { } while input_rx.recv().is_ok() { - if let Some(event) = events.next() { - if let Ok(event) = event { - if let Err(e) = event_tx2.send(JoshutoEvent::Termion(event)) { - eprintln!("Input thread send err: {:#?}", e); - return; - } + if let Some(Ok(event)) = events.next() { + if let Err(e) = event_tx2.send(JoshutoEvent::Termion(event)) { + eprintln!("Input thread send err: {:#?}", e); + return; } } } diff --git a/src/util/input.rs b/src/util/input.rs index af9e326..b588320 100644 --- a/src/util/input.rs +++ b/src/util/input.rs @@ -5,7 +5,7 @@ use tui::layout::{Constraint, Direction, Layout}; use crate::commands::{cursor_move, parent_cursor_move, JoshutoRunnable, KeyCommand}; use crate::context::JoshutoContext; use crate::history::DirectoryHistory; -use crate::io::{FileOp, IOWorkerProgress}; +use crate::io::{FileOp, IoWorkerProgress}; use crate::ui; use crate::util::event::JoshutoEvent; use crate::util::format; @@ -102,21 +102,21 @@ pub fn process_mouse( pub fn process_noninteractive(event: JoshutoEvent, context: &mut JoshutoContext) { match event { - JoshutoEvent::IOWorkerProgress(res) => process_worker_progress(context, res), - JoshutoEvent::IOWorkerResult(res) => process_finished_worker(context, res), + JoshutoEvent::IoWorkerProgress(res) => process_worker_progress(context, res), + JoshutoEvent::IoWorkerResult(res) => process_finished_worker(context, res), JoshutoEvent::Signal(signal::SIGWINCH) => {} _ => {} } } -pub fn process_worker_progress(context: &mut JoshutoContext, res: IOWorkerProgress) { +pub fn process_worker_progress(context: &mut JoshutoContext, res: IoWorkerProgress) { context.set_worker_progress(res); context.update_worker_msg(); } pub fn process_finished_worker( context: &mut JoshutoContext, - res: std::io::Result<IOWorkerProgress>, + res: std::io::Result<IoWorkerProgress>, ) { let observer = context.remove_job().unwrap(); let options = context.config_ref().sort_option.clone(); diff --git a/src/util/mod.rs b/src/util/mod.rs index a85e78d..360dd04 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -6,6 +6,7 @@ pub mod format; pub mod input; pub mod key_mapping; pub mod load_child; +pub mod name_resolution; pub mod sort; pub mod to_string; pub mod unix; diff --git a/src/io/name_resolution.rs b/src/util/name_resolution.rs index a8e520b..a8e520b 100644 --- a/src/io/name_resolution.rs +++ b/src/util/name_resolution.rs |