summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/joshuto/command/change_directory.rs2
-rw-r--r--src/joshuto/command/cursor_move.rs20
-rw-r--r--src/joshuto/command/file_operation.rs109
-rw-r--r--src/joshuto/command/open_file.rs74
-rw-r--r--src/joshuto/command/parent_directory.rs2
-rw-r--r--src/joshuto/command/quit.rs2
-rw-r--r--src/joshuto/command/show_hidden.rs2
7 files changed, 79 insertions, 132 deletions
diff --git a/src/joshuto/command/change_directory.rs b/src/joshuto/command/change_directory.rs
index c71256c..c05cfb8 100644
--- a/src/joshuto/command/change_directory.rs
+++ b/src/joshuto/command/change_directory.rs
@@ -22,7 +22,7 @@ impl ChangeDirectory {
path,
}
}
- pub fn command() -> &'static str { "ChangeDirectory" }
+ pub const fn command() -> &'static str { "change_directory" }
}
impl command::JoshutoCommand for ChangeDirectory {}
diff --git a/src/joshuto/command/cursor_move.rs b/src/joshuto/command/cursor_move.rs
index 764337c..56c2e5d 100644
--- a/src/joshuto/command/cursor_move.rs
+++ b/src/joshuto/command/cursor_move.rs
@@ -22,7 +22,7 @@ impl CursorMove {
movement,
}
}
- pub fn command() -> &'static str { "CursorMove" }
+ pub fn command() -> &'static str { "cursor_move" }
}
impl command::JoshutoCommand for CursorMove {}
@@ -84,7 +84,7 @@ pub struct CursorMovePageUp;
impl CursorMovePageUp {
pub fn new() -> Self { CursorMovePageUp }
- pub fn command() -> &'static str { "CursorMovePageUp" }
+ pub fn command() -> &'static str { "cursor_move_page_up" }
}
impl command::JoshutoCommand for CursorMovePageUp {}
@@ -149,7 +149,7 @@ pub struct CursorMovePageDown;
impl CursorMovePageDown {
pub fn new() -> Self { CursorMovePageDown }
- pub fn command() -> &'static str { "CursorMovePageDown" }
+ pub fn command() -> &'static str { "cursor_move_page_down" }
}
impl command::JoshutoCommand for CursorMovePageDown {}
@@ -213,11 +213,8 @@ impl command::Runnable for CursorMovePageDown {
pub struct CursorMoveHome;
impl CursorMoveHome {
- pub fn new() -> Self
- {
- CursorMoveHome
- }
- pub fn command() -> &'static str { "CursorMoveHome" }
+ pub fn new() -> Self { CursorMoveHome }
+ pub fn command() -> &'static str { "cursor_move_home" }
}
impl command::JoshutoCommand for CursorMoveHome {}
@@ -272,11 +269,8 @@ impl command::Runnable for CursorMoveHome {
pub struct CursorMoveEnd;
impl CursorMoveEnd {
- pub fn new() -> Self
- {
- CursorMoveEnd
- }
- pub fn command() -> &'static str { "CursorMoveHome" }
+ pub fn new() -> Self { CursorMoveEnd }
+ pub fn command() -> &'static str { "cursor_move_end" }
}
impl command::JoshutoCommand for CursorMoveEnd {}
diff --git a/src/joshuto/command/file_operation.rs b/src/joshuto/command/file_operation.rs
index 526bfcf..5a26668 100644
--- a/src/joshuto/command/file_operation.rs
+++ b/src/joshuto/command/file_operation.rs
@@ -63,7 +63,7 @@ pub struct CutFiles;
impl CutFiles {
pub fn new() -> Self { CutFiles }
- pub fn command() -> &'static str { "CutFiles" }
+ pub fn command() -> &'static str { "cut_files" }
}
impl command::JoshutoCommand for CutFiles {}
@@ -89,7 +89,7 @@ pub struct CopyFiles;
impl CopyFiles {
pub fn new() -> Self { CopyFiles }
- pub fn command() -> &'static str { "CopyFiles" }
+ pub fn command() -> &'static str { "copy_files" }
}
impl command::JoshutoCommand for CopyFiles {}
@@ -121,7 +121,7 @@ impl PasteFiles {
options,
}
}
- pub fn command() -> &'static str { "PasteFiles" }
+ pub fn command() -> &'static str { "paste_files" }
fn cut(&self, destination: &path::PathBuf, win: &window::JoshutoPanel) {
let mut destination = destination;
@@ -205,7 +205,7 @@ pub struct DeleteFiles;
impl DeleteFiles {
pub fn new() -> Self { DeleteFiles }
- pub fn command() -> &'static str { "DeleteFiles" }
+ pub fn command() -> &'static str { "delete_files" }
}
impl command::JoshutoCommand for DeleteFiles {}
@@ -255,57 +255,65 @@ impl command::Runnable for DeleteFiles {
}
#[derive(Debug)]
-pub struct RenameFile;
+pub enum RenameFileMethod {
+ Append,
+ Prepend,
+ Overwrite
+}
-impl RenameFile {
- pub fn new() -> Self { RenameFile }
- pub fn command() -> &'static str { "RenameFile" }
+#[derive(Debug)]
+pub struct RenameFile {
+ method: RenameFileMethod,
+}
- pub fn rename_file(path: &path::PathBuf, context: &mut joshuto::JoshutoContext)
+impl RenameFile {
+ pub fn new(method: RenameFileMethod) -> Self
{
- if let Some(file_name) = path.file_name() {
- let mut term_rows: i32 = 0;
- let mut term_cols: i32 = 0;
- ncurses::getmaxyx(ncurses::stdscr(), &mut term_rows, &mut term_cols);
+ RenameFile {
+ method,
+ }
+ }
+ pub fn command() -> &'static str { "rename_file" }
- let mut win = window::JoshutoPanel::new(1, term_cols, (term_rows as usize - 1, 0));
- ncurses::keypad(win.win, true);
+ pub fn rename_file(path: &path::PathBuf, context: &mut joshuto::JoshutoContext, user_input: String, start: i32)
+ {
+ let mut term_rows: i32 = 0;
+ let mut term_cols: i32 = 0;
+ ncurses::getmaxyx(ncurses::stdscr(), &mut term_rows, &mut term_cols);
- const PROMPT: &str = ":rename_file ";
- ncurses::wprintw(win.win, PROMPT);
+ let mut win = window::JoshutoPanel::new(1, term_cols, (term_rows as usize - 1, 0));
+ ncurses::keypad(win.win, true);
- win.move_to_top();
- ncurses::doupdate();
+ const PROMPT: &str = ":rename_file ";
+ ncurses::wprintw(win.win, PROMPT);
- ncurses::wmove(win.win, 0, PROMPT.len() as i32);
+ win.move_to_top();
+ ncurses::doupdate();
- match ui::get_str(&win, (0, PROMPT.len() as i32)) {
- Some(s) => {
- let mut new_path = path.parent().unwrap().to_path_buf();
- new_path.push(s);
- match fs::rename(&path, &new_path) {
- Ok(_) => {
- context.reload_dirlists();
+ if let Some(s) = ui::get_str_prefill_pos(&win, (0, PROMPT.len() as i32), user_input, start + PROMPT.len() as i32) {
+ let mut new_path = path.parent().unwrap().to_path_buf();
+ new_path.push(s);
+ match fs::rename(&path, &new_path) {
+ Ok(_) => {
+ context.reload_dirlists();
- ui::redraw_view(&context.views.left_win, context.parent_list.as_ref());
- ui::redraw_view(&context.views.mid_win, context.curr_list.as_ref());
- ui::redraw_view(&context.views.right_win, context.preview_list.as_ref());
+ ui::redraw_view(&context.views.left_win, context.parent_list.as_ref());
+ ui::redraw_view(&context.views.mid_win, context.curr_list.as_ref());
+ ui::redraw_view(&context.views.right_win, context.preview_list.as_ref());
- ui::redraw_status(&context.views, context.curr_list.as_ref(),
- &context.curr_path,
- &context.config_t.username, &context.config_t.hostname);
- },
- Err(e) => {
- ui::wprint_err(&context.views.bot_win, e.to_string().as_str());
- },
- }
+ ui::redraw_status(&context.views, context.curr_list.as_ref(),
+ &context.curr_path,
+ &context.config_t.username, &context.config_t.hostname);
+ },
+ Err(e) => {
+ ui::wprint_err(&context.views.bot_win, e.to_string().as_str());
},
- None => {},
}
- win.destroy();
- ncurses::update_panels();
- ncurses::doupdate();
}
+
+ win.destroy();
+ ncurses::update_panels();
+ ncurses::doupdate();
}
}
@@ -330,7 +338,22 @@ impl command::Runnable for RenameFile {
};
if let Some(path) = dirlist {
- Self::rename_file(&path, context);
+ if let Some(file_name) = path.file_name() {
+ if let Ok(user_input) = file_name.to_os_string().into_string() {
+ match self.method {
+ RenameFileMethod::Append => {
+ let start = user_input.len() as i32;
+ Self::rename_file(&path, context, user_input, start);
+ },
+ RenameFileMethod::Prepend => {
+ Self::rename_file(&path, context, user_input, 0);
+ },
+ RenameFileMethod::Overwrite => {
+ Self::rename_file(&path, context, String::new(), 0);
+ },
+ }
+ }
+ }
}
}
}
diff --git a/src/joshuto/command/open_file.rs b/src/joshuto/command/open_file.rs
index 260eb6e..25b180e 100644
--- a/src/joshuto/command/open_file.rs
+++ b/src/joshuto/command/open_file.rs
@@ -20,7 +20,7 @@ pub struct OpenFile;
impl OpenFile {
pub fn new() -> Self { OpenFile }
- pub fn command() -> &'static str { "OpenFile" }
+ pub fn command() -> &'static str { "open_file" }
}
impl command::JoshutoCommand for OpenFile {}
@@ -112,82 +112,12 @@ impl command::Runnable for OpenFile {
}
}
-/*
-fn open_with(mimetypes: &HashMap<String, Vec<Vec<String>>>,
- direntry: &fs::DirEntry)
-{
- let mut term_rows: i32 = 0;
- let mut term_cols: i32 = 0;
- ncurses::getmaxyx(ncurses::stdscr(), &mut term_rows, &mut term_cols);
-
- let pathbuf = direntry.path();
- let mimetype = unix::get_mime_type(pathbuf.as_path());
-
- let mut empty_vec: Vec<Vec<String>> = Vec::new();
- let mimetype_options: &Vec<Vec<String>>;
- match mimetypes.get(&mimetype) {
- Some(s) => {
- mimetype_options = s;
- },
- None => {
- mimetype_options = &empty_vec;
- },
- }
-
- let option_size = mimetype_options.len();
- let mut win = window::JoshutoPanel::new(option_size as i32 + 2, term_cols,
- (term_rows as usize - option_size - 2, 0));
-
- let mut display_vec: Vec<String> = Vec::with_capacity(option_size);
- for (i, val) in mimetype_options.iter().enumerate() {
- display_vec.push(format!(" {}\t{}", i, val.join(" ")));
- }
- display_vec.sort();
-
- win.move_to_top();
- ui::display_options(&win, &display_vec);
- // ncurses::curs_set(ncurses::CURSOR_VISIBILITY::CURSOR_VISIBLE);
- ncurses::doupdate();
-
- ncurses::wmove(win.win, option_size as i32 + 1, 0);
- ncurses::wprintw(win.win, ":open_with ");
-
- let mut cur_ind = ":open_with ".len();
-
-
- win.destroy();
- // ncurses::curs_set(ncurses::CURSOR_VISIBILITY::CURSOR_INVISIBLE);
- ncurses::update_panels();
- ncurses::doupdate();
-
- match user_input.parse::<usize>() {
- Ok(s) => {
- if s < mimetype_options.len() {
- ncurses::savetty();
- ncurses::endwin();
- unix::open_with(pathbuf.as_path(), &mimetype_options[s]);
- ncurses::resetty();
- ncurses::refresh();
- }
- }
- Err(_) => {
- let args: Vec<String> = user_input.split_whitespace().map(|x| String::from(x)).collect();
- ncurses::savetty();
- ncurses::endwin();
- unix::open_with(pathbuf.as_path(), &args);
- ncurses::resetty();
- ncurses::refresh();
- }
- }
-}
-*/
-
#[derive(Debug)]
pub struct OpenFileWith;
impl OpenFileWith {
pub fn new() -> Self { OpenFileWith }
- pub fn command() -> &'static str { "OpenFileWith" }
+ pub fn command() -> &'static str { "open_file_with" }
pub fn open_with(pathbuf: path::PathBuf, mimetype_t: &mimetype::JoshutoMimetype)
{
diff --git a/src/joshuto/command/parent_directory.rs b/src/joshuto/command/parent_directory.rs
index becb42a..ba986bc 100644
--- a/src/joshuto/command/parent_directory.rs
+++ b/src/joshuto/command/parent_directory.rs
@@ -14,7 +14,7 @@ pub struct ParentDirectory;
impl ParentDirectory {
pub fn new() -> Self { ParentDirectory }
- pub fn command() -> &'static str { "ParentDirectory" }
+ pub fn command() -> &'static str { "parent_directory" }
}
impl command::JoshutoCommand for ParentDirectory {}
diff --git a/src/joshuto/command/quit.rs b/src/joshuto/command/quit.rs
index 9b2a2ae..8ad284c 100644
--- a/src/joshuto/command/quit.rs
+++ b/src/joshuto/command/quit.rs
@@ -11,7 +11,7 @@ pub struct Quit;
impl Quit {
pub fn new() -> Self { Quit }
- pub fn command() -> &'static str { "Quit" }
+ pub fn command() -> &'static str { "quit" }
}
impl command::JoshutoCommand for Quit {}
diff --git a/src/joshuto/command/show_hidden.rs b/src/joshuto/command/show_hidden.rs
index 273a316..0d93be9 100644
--- a/src/joshuto/command/show_hidden.rs
+++ b/src/joshuto/command/show_hidden.rs
@@ -15,7 +15,7 @@ pub struct ToggleHiddenFiles;
impl ToggleHiddenFiles {
pub fn new() -> Self { ToggleHiddenFiles }
- pub fn command() -> &'static str { "ToggleHiddenFiles" }
+ pub fn command() -> &'static str { "toggle_hidden" }
}
impl command::JoshutoCommand for ToggleHiddenFiles {}