summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2019-05-05 20:11:36 -0400
committerJiayi Zhao <jeff.no.zhao@gmail.com>2019-05-05 20:11:36 -0400
commit4c194de5c7e940e1eaf71c0fb4b455ba6547c880 (patch)
tree331eb9908c67fe9a2f6d6e98e3b2d4f0901326bc
parent6b013bb91969d7e269aa5a08da729a8370a31900 (diff)
use readline() instead of readline_with_initial with possible
-rw-r--r--src/commands/delete_files.rs32
-rw-r--r--src/commands/open_file.rs2
-rw-r--r--src/commands/rename_file.rs8
-rw-r--r--src/commands/search.rs2
-rw-r--r--src/commands/set_mode.rs2
-rw-r--r--src/config/keymap.rs51
-rw-r--r--src/history.rs3
7 files changed, 26 insertions, 74 deletions
diff --git a/src/commands/delete_files.rs b/src/commands/delete_files.rs
index 283a1d3..615f12d 100644
--- a/src/commands/delete_files.rs
+++ b/src/commands/delete_files.rs
@@ -41,24 +41,28 @@ impl DeleteFiles {
ncurses::doupdate();
let curr_tab = &mut context.tabs[context.curr_tab_index];
- let ch = ncurses::getch();
+ let mut ch = ncurses::getch();
if ch == 'y' as i32 || ch == keymap::ENTER as i32 {
- ui::wprint_msg(&view.bot_win, "Are you sure? (Y/n)");
- ncurses::doupdate();
- let ch = ncurses::getch();
- if ch == 'y' as i32 || ch == keymap::ENTER as i32 {
- if let Some(paths) = curr_tab.curr_list.get_selected_paths() {
+ if let Some(paths) = curr_tab.curr_list.get_selected_paths() {
+ if paths.len() > 1 {
+ ui::wprint_msg(&view.bot_win, "Are you sure? (y/N)");
+ ncurses::doupdate();
+ ch = ncurses::getch();
+ } else {
+ ch = 'y' as i32;
+ }
+ if ch == 'y' as i32 {
Self::remove_files(paths)?;
ui::wprint_msg(&view.bot_win, "Deleted files");
- }
- curr_tab.reload_contents(&context.config_t.sort_option)?;
- curr_tab.refresh(
- &view,
- &context.config_t,
- &context.username,
- &context.hostname,
- );
+ curr_tab.reload_contents(&context.config_t.sort_option)?;
+ curr_tab.refresh(
+ &view,
+ &context.config_t,
+ &context.username,
+ &context.hostname,
+ );
+ }
} else {
curr_tab.refresh_file_status(&view.bot_win);
curr_tab.refresh_path_status(
diff --git a/src/commands/open_file.rs b/src/commands/open_file.rs
index ffcdbac..b606330 100644
--- a/src/commands/open_file.rs
+++ b/src/commands/open_file.rs
@@ -206,7 +206,7 @@ impl OpenFileWith {
(term_rows as usize - 1, 0),
PROMPT.to_string(),
);
- user_input = textfield.readline_with_initial("", "");
+ user_input = textfield.readline();
}
ncurses::doupdate();
diff --git a/src/commands/rename_file.rs b/src/commands/rename_file.rs
index 478a375..b4fa83c 100644
--- a/src/commands/rename_file.rs
+++ b/src/commands/rename_file.rs
@@ -47,13 +47,13 @@ impl RenameFile {
match self.method {
RenameFileMethod::Append => {
if let Some(ext) = start_str.rfind('.') {
- textfield.readline_with_initial(&start_str[0..ext], &start_str[ext..])
+ textfield.readline_with_initial((&start_str[0..ext], &start_str[ext..]))
} else {
- textfield.readline_with_initial(&start_str, "")
+ textfield.readline_with_initial((&start_str, ""))
}
}
- RenameFileMethod::Prepend => textfield.readline_with_initial("", &start_str),
- RenameFileMethod::Overwrite => textfield.readline_with_initial("", ""),
+ RenameFileMethod::Prepend => textfield.readline_with_initial(("", &start_str)),
+ RenameFileMethod::Overwrite => textfield.readline(),
}
};
diff --git a/src/commands/search.rs b/src/commands/search.rs
index 9dc45d3..96db9b9 100644
--- a/src/commands/search.rs
+++ b/src/commands/search.rs
@@ -86,7 +86,7 @@ impl JoshutoRunnable for Search {
PROMPT.to_string(),
);
- textfield.readline_with_initial("", "")
+ textfield.readline()
};
ncurses::doupdate();
diff --git a/src/commands/set_mode.rs b/src/commands/set_mode.rs
index 7b18b86..eb55a99 100644
--- a/src/commands/set_mode.rs
+++ b/src/commands/set_mode.rs
@@ -45,7 +45,7 @@ impl SetMode {
PROMPT.to_string(),
);
- user_input = textfield.readline_with_initial(&start_str, "");
+ user_input = textfield.readline_with_initial((&start_str, ""));
}
ncurses::doupdate();
diff --git a/src/config/keymap.rs b/src/config/keymap.rs
index 1dc84c0..9b3c6a9 100644
--- a/src/config/keymap.rs
+++ b/src/config/keymap.rs
@@ -87,54 +87,3 @@ fn insert_keycommand(
},
}
}
-
-pub fn key_to_i32(keycode: &str) -> Option<i32> {
- if keycode.len() == 1 {
- for ch in keycode.chars() {
- if ch.is_ascii() {
- return Some(ch as i32);
- }
- }
- None
- } else {
- match keycode {
- "Tab" => Some(TAB),
- "ShiftTab" => Some(ncurses::KEY_BTAB),
- "Space" => Some(' ' as i32),
- "Backspace" => Some(BACKSPACE),
- "Delete" => Some(ncurses::KEY_DC),
- "Enter" => Some(ENTER),
- "Escape" => Some(ESCAPE),
-
- "F0" => Some(ncurses::KEY_F0),
- "F1" => Some(ncurses::KEY_F1),
- "F2" => Some(ncurses::KEY_F2),
- "F3" => Some(ncurses::KEY_F3),
- "F4" => Some(ncurses::KEY_F4),
- "F5" => Some(ncurses::KEY_F5),
- "F6" => Some(ncurses::KEY_F6),
- "F7" => Some(ncurses::KEY_F7),
- "F8" => Some(ncurses::KEY_F8),
- "F9" => Some(ncurses::KEY_F9),
- "F10" => Some(ncurses::KEY_F10),
- "F11" => Some(ncurses::KEY_F11),
- "F12" => Some(ncurses::KEY_F12),
- "F13" => Some(ncurses::KEY_F13),
- "F14" => Some(ncurses::KEY_F14),
- "F15" => Some(ncurses::KEY_F15),
-
- "Insert" => Some(ncurses::KEY_IC), /* insert-character key */
- "PageUp" => Some(ncurses::KEY_PPAGE), /* next-page key */
- "PageDown" => Some(ncurses::KEY_NPAGE), /* previous-page key */
- "PrintScreen" => Some(ncurses::KEY_PRINT), /* print key */
-
- "Up" => Some(ncurses::KEY_UP),
- "Down" => Some(ncurses::KEY_DOWN),
- "Left" => Some(ncurses::KEY_LEFT),
- "Right" => Some(ncurses::KEY_RIGHT),
- "Home" => Some(ncurses::KEY_HOME),
- "End" => Some(ncurses::KEY_END),
- _ => None,
- }
- }
-}
diff --git a/src/history.rs b/src/history.rs
index 9d85322..b5e04ae 100644
--- a/src/history.rs
+++ b/src/history.rs
@@ -72,8 +72,7 @@ impl DirectoryHistory for HashMap<PathBuf, JoshutoDirList> {
sort_option: &sort::SortOption,
) -> Result<&mut JoshutoDirList, std::io::Error> {
match self.entry(path.to_path_buf().clone()) {
- Entry::Occupied(mut entry) => {
- let dir_entry = entry.get_mut();
+ Entry::Occupied(entry) => {
/*
if dir_entry.need_update() {
dir_entry.update_contents(&sort_option)?;