diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-01-05 17:30:08 -0500 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-01-05 17:36:20 -0500 |
commit | 541d9cd6d9ad23d8c262f43a67befb21283b8ebc (patch) | |
tree | 187ddc25b8e5fef7fbd4cea12255201f65bcf3b5 | |
parent | 646d2e4fffd5aa73da0ee143054c1488fd409f8b (diff) |
optimize code
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/joshuto.rs | 3 | ||||
-rw-r--r-- | src/joshuto/command/cursor_move.rs | 2 | ||||
-rw-r--r-- | src/joshuto/command/file_operation.rs | 3 | ||||
-rw-r--r-- | src/joshuto/command/open_file.rs | 4 | ||||
-rw-r--r-- | src/joshuto/command/parent_directory.rs | 4 | ||||
-rw-r--r-- | src/joshuto/navigation.rs | 33 | ||||
-rw-r--r-- | src/joshuto/ui.rs | 9 |
8 files changed, 13 insertions, 47 deletions
@@ -16,7 +16,7 @@ serde = "1.0.82" serde_derive = "1.0.82" toml = "0.4.10" wcwidth = "1.0.1" -whoami = "0.2.4" +whoami = "0.3.0" xdg = "2.2.0" # clap = "*" diff --git a/src/joshuto.rs b/src/joshuto.rs index 1b5a77d..d33dbf4 100644 --- a/src/joshuto.rs +++ b/src/joshuto.rs @@ -323,9 +323,6 @@ pub fn run(config_t: config::JoshutoConfig, continue; } } - -// ncurses::printw(format!("{}", *keycommand).as_str()); - keycommand.execute(&mut tabs[index]); } } diff --git a/src/joshuto/command/cursor_move.rs b/src/joshuto/command/cursor_move.rs index 4f7c8c3..c4e4036 100644 --- a/src/joshuto/command/cursor_move.rs +++ b/src/joshuto/command/cursor_move.rs @@ -64,7 +64,7 @@ impl CursorMove { context.preview_list = Some(s); ui::redraw_view(&context.views.right_win, context.preview_list.as_ref()); }, - Err(e) => ui::wprint_err(&context.views.right_win, format!("{}", e).as_str()), + Err(e) => ui::wprint_err(&context.views.right_win, e.to_string().as_str()), } } else { ncurses::werase(context.views.right_win.win); diff --git a/src/joshuto/command/file_operation.rs b/src/joshuto/command/file_operation.rs index 5c36469..4cad0f0 100644 --- a/src/joshuto/command/file_operation.rs +++ b/src/joshuto/command/file_operation.rs @@ -325,8 +325,7 @@ impl command::Runnable for DeleteFiles { fn execute(&self, context: &mut joshuto::JoshutoContext) { - ui::wprint_msg(&context.views.bot_win, - format!("Delete selected files? (Y/n)").as_str()); + ui::wprint_msg(&context.views.bot_win, "Delete selected files? (Y/n)"); ncurses::doupdate(); let ch = ncurses::wgetch(context.views.bot_win.win); diff --git a/src/joshuto/command/open_file.rs b/src/joshuto/command/open_file.rs index 1f736c7..0489b89 100644 --- a/src/joshuto/command/open_file.rs +++ b/src/joshuto/command/open_file.rs @@ -113,7 +113,7 @@ impl command::Runnable for OpenFile { match path.strip_prefix(context.curr_path.as_path()) { Ok(s) => context.curr_path.push(s), Err(e) => { - ui::wprint_err(&context.views.bot_win, format!("{}", e).as_str()); + ui::wprint_err(&context.views.bot_win, e.to_string().as_str()); return; } } @@ -129,7 +129,7 @@ impl command::Runnable for OpenFile { Ok(s) => { Some(s) }, Err(e) => { ui::wprint_err(&context.views.right_win, - format!("{}", e).as_str()); + e.to_string().as_str()); None }, }; diff --git a/src/joshuto/command/parent_directory.rs b/src/joshuto/command/parent_directory.rs index ba986bc..9cbe2c8 100644 --- a/src/joshuto/command/parent_directory.rs +++ b/src/joshuto/command/parent_directory.rs @@ -54,7 +54,7 @@ impl command::Runnable for ParentDirectory { Some(s) }, Err(e) => { - ui::wprint_err(&context.views.left_win, format!("{}", e).as_str()); + ui::wprint_err(&context.views.left_win, e.to_string().as_str()); None }, }; @@ -72,7 +72,7 @@ impl command::Runnable for ParentDirectory { &context.config_t.username, &&context.config_t.hostname); }, Err(e) => { - ui::wprint_err(&context.views.bot_win, format!("{}", e).as_str()); + ui::wprint_err(&context.views.bot_win, e.to_string().as_str()); }, }; diff --git a/src/joshuto/navigation.rs b/src/joshuto/navigation.rs deleted file mode 100644 index 1dee12c..0000000 --- a/src/joshuto/navigation.rs +++ /dev/null @@ -1,33 +0,0 @@ -use std; -use std::path; - -use joshuto::structs; -use joshuto::sort; -use joshuto::history; - -pub fn set_dir_cursor_index(history: &mut history::DirHistory, - curr_view: &mut structs::JoshutoDirList, - preview_view: Option<structs::JoshutoDirList>, - sort_type: &sort::SortType, - new_index: i32) - -> Result<Option<structs::JoshutoDirList>, std::io::Error> -{ - let curr_index = curr_view.index as usize; - if let Some(s) = preview_view { - history.insert(s); - } - - curr_view.index = new_index; - let curr_index = curr_view.index as usize; - let new_path: path::PathBuf = curr_view.contents.as_ref() - .unwrap()[curr_index].entry.path(); - if new_path.is_dir() { - match history.pop_or_create(new_path.as_path(), sort_type) { - Ok(s) => Ok(Some(s)), - Err(e) => Err(e), - } - } else { - Ok(None) - } -} - diff --git a/src/joshuto/ui.rs b/src/joshuto/ui.rs index 5a4b16d..9ac76ed 100644 --- a/src/joshuto/ui.rs +++ b/src/joshuto/ui.rs @@ -99,10 +99,13 @@ pub fn wprint_path(win: &window::JoshutoPanel, username: &str, }; ncurses::wattron(win.win, ncurses::A_BOLD()); ncurses::wattron(win.win, ncurses::COLOR_PAIR(EXEC_COLOR)); - ncurses::mvwaddstr(win.win, 0, 0, - format!("{}@{} ", username, hostname).as_str()); + ncurses::mvwaddstr(win.win, 0, 0, username); + ncurses::waddstr(win.win, "@"); + ncurses::waddstr(win.win, hostname); ncurses::wattroff(win.win, ncurses::COLOR_PAIR(EXEC_COLOR)); + ncurses::waddstr(win.win, " "); + ncurses::wattron(win.win, ncurses::COLOR_PAIR(DIR_COLOR)); ncurses::waddstr(win.win, path_str); ncurses::waddstr(win.win, "/"); @@ -236,7 +239,7 @@ pub fn wprint_file_info(win: ncurses::WINDOW, file: &structs::JoshutoDirEntry) } }, Err(e) => { - ncurses::waddstr(win, format!("{:?}", e).as_str()); + ncurses::waddstr(win, e.to_string().as_str()); }, }; ncurses::wnoutrefresh(win); |