summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2019-02-08 13:47:21 -0500
committerJiayi Zhao <jeff.no.zhao@gmail.com>2019-02-08 13:47:21 -0500
commit63472555d504580c606fed9a63ad16a1020b0c84 (patch)
treea57a020b43c2138f25f1a4be390b08b32d7fd750
parent475923c0b1f331937b7499869403f07764ccb8b2 (diff)
add cut for non-linux platforms
-rw-r--r--src/joshuto.rs2
-rw-r--r--src/joshuto/command/file_operations.rs82
-rw-r--r--src/joshuto/window.rs3
3 files changed, 60 insertions, 27 deletions
diff --git a/src/joshuto.rs b/src/joshuto.rs
index 33f2a0f..914594b 100644
--- a/src/joshuto.rs
+++ b/src/joshuto.rs
@@ -162,6 +162,7 @@ fn resize_handler(context: &mut JoshutoContext) {
ncurses::doupdate();
}
+#[allow(unreachable_code)]
pub fn run(config_t: config::JoshutoConfig, keymap_t: config::JoshutoKeymap) {
ui::init_ncurses();
@@ -208,6 +209,5 @@ pub fn run(config_t: config::JoshutoConfig, keymap_t: config::JoshutoKeymap) {
keycommand.execute(&mut context);
}
}
- #[allow(unreachable_code)]
ncurses::endwin();
}
diff --git a/src/joshuto/command/file_operations.rs b/src/joshuto/command/file_operations.rs
index 7821850..73cf903 100644
--- a/src/joshuto/command/file_operations.rs
+++ b/src/joshuto/command/file_operations.rs
@@ -156,14 +156,15 @@ impl PasteFiles {
{
let paths = selected_files.lock().unwrap();
if paths.len() == 0 {
- return Err(std::io::Error::new(std::io::ErrorKind::Other, "oh no!"));
+ return Err(std::io::Error::new(std::io::ErrorKind::Other, "no files selected"));
}
path_ino = paths[0].metadata()?.st_dev();
}
let (tx, rx) = sync::mpsc::channel();
+ let handle;
if dest_ino == path_ino {
- let handle = thread::spawn(move || {
+ handle = thread::spawn(move || {
let mut paths = selected_files.lock().unwrap();
let mut progress_info = ProgressInfo {
bytes_finished: 1,
@@ -173,15 +174,15 @@ impl PasteFiles {
for path in (*paths).iter() {
let mut file_name = path.file_name().unwrap().to_os_string();
+ if options.skip_exist && destination.exists() {
+ continue;
+ }
+
while path::Path::new(&file_name).exists() {
file_name.push("_0");
}
destination.push(file_name);
- if options.skip_exist && destination.exists() {
- continue;
- }
-
std::fs::rename(&path, &destination).unwrap();
destination.pop();
@@ -191,16 +192,9 @@ impl PasteFiles {
paths.clear();
0
});
- let thread = FileOperationThread {
- tab_src: tab_src_index,
- tab_dest,
- handle,
- recv: rx,
- };
- Ok(thread)
} else {
- let handle = thread::spawn(move || {
- let files = selected_files.lock().unwrap();
+ handle = thread::spawn(move || {
+ let mut paths = selected_files.lock().unwrap();
let handle = |process_info: fs_extra::TransitProcess| {
let progress_info = ProgressInfo {
@@ -211,18 +205,60 @@ impl PasteFiles {
fs_extra::dir::TransitProcessResult::ContinueOrAbort
};
- fs_extra::move_items_with_progress(&files, &destination, &options, handle).unwrap();
+ fs_extra::move_items_with_progress(&paths, &destination, &options, handle).unwrap();
+ paths.clear();
0
});
+ }
+ let thread = FileOperationThread {
+ tab_src: tab_src_index,
+ tab_dest,
+ handle,
+ recv: rx,
+ };
+ Ok(thread)
+ }
- let thread = FileOperationThread {
- tab_src: tab_src_index,
- tab_dest,
- handle,
- recv: rx,
- };
- Ok(thread)
+ #[cfg(not(target_os = "linux"))]
+ fn cut(&self, context: &mut JoshutoContext) -> Result<FileOperationThread, std::io::Error> {
+ let tab_dest = context.curr_tab_index;
+ let tab_src_index: usize;
+ {
+ tab_src_index = *tab_src.lock().unwrap();
}
+ let mut destination = context.tabs[tab_dest].curr_path.clone();
+ let options = self.options.clone();
+
+ {
+ let paths = selected_files.lock().unwrap();
+ if paths.len() == 0 {
+ return Err(std::io::Error::new(std::io::ErrorKind::Other, "no files selected"));
+ }
+ }
+
+ let handle = thread::spawn(move || {
+ let mut paths = selected_files.lock().unwrap();
+
+ let handle = |process_info: fs_extra::TransitProcess| {
+ let progress_info = ProgressInfo {
+ bytes_finished: process_info.copied_bytes,
+ total_bytes: process_info.total_bytes,
+ };
+ tx.send(progress_info).unwrap();
+ fs_extra::dir::TransitProcessResult::ContinueOrAbort
+ };
+
+ fs_extra::move_items_with_progress(&paths, &destination, &options, handle).unwrap();
+ paths.clear();
+ 0
+ });
+ let thread = FileOperationThread {
+ tab_src: tab_src_index,
+ tab_dest,
+ handle,
+ recv: rx,
+ };
+ Ok(thread)
}
fn copy(&self, context: &mut JoshutoContext) -> Result<FileOperationThread, std::io::Error> {
diff --git a/src/joshuto/window.rs b/src/joshuto/window.rs
index 859f8eb..e9c3608 100644
--- a/src/joshuto/window.rs
+++ b/src/joshuto/window.rs
@@ -105,9 +105,6 @@ impl JoshutoPanel {
pub fn move_to_top(&self) {
ncurses::top_panel(self.panel);
}
- pub fn move_to_bottom(&self) {
- ncurses::bottom_panel(self.panel);
- }
pub fn queue_for_refresh(&self) {
ncurses::wnoutrefresh(self.win);
}