summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2019-05-29 23:06:38 -0400
committerJiayi Zhao <jeff.no.zhao@gmail.com>2019-05-29 23:07:27 -0400
commit5980d762dba38b003dbe54506cdd58ee85f97c8c (patch)
tree28e07e112586b73e1de426f7ae34c8c2afc68fdb /src
parent5d8525a9cc8a61e8e66a92f66132ad11ce112ff7 (diff)
move hostname and username out of Context and into a static global
Diffstat (limited to 'src')
-rw-r--r--src/commands/change_directory.rs7
-rw-r--r--src/commands/cursor_move.rs7
-rw-r--r--src/commands/delete_files.rs36
-rw-r--r--src/commands/open_file.rs33
-rw-r--r--src/commands/parent_directory.rs7
-rw-r--r--src/commands/reload_dir.rs21
-rw-r--r--src/commands/tab_switch.rs7
-rw-r--r--src/context.rs7
-rw-r--r--src/history.rs30
-rw-r--r--src/main.rs3
-rw-r--r--src/run.rs28
-rw-r--r--src/tab.rs31
12 files changed, 65 insertions, 152 deletions
diff --git a/src/commands/change_directory.rs b/src/commands/change_directory.rs
index 4dfe942..5109935 100644
--- a/src/commands/change_directory.rs
+++ b/src/commands/change_directory.rs
@@ -44,12 +44,7 @@ impl ChangeDirectory {
.history
.insert(new_curr_list.path.clone(), new_curr_list);
- curr_tab.refresh(
- view,
- &context.config_t,
- &context.username,
- &context.hostname,
- );
+ curr_tab.refresh(view, &context.config_t);
Ok(())
}
}
diff --git a/src/commands/cursor_move.rs b/src/commands/cursor_move.rs
index c17b59d..e07cbf8 100644
--- a/src/commands/cursor_move.rs
+++ b/src/commands/cursor_move.rs
@@ -29,12 +29,7 @@ pub fn cursor_move(mut new_index: usize, context: &mut JoshutoContext, view: &Jo
}
curr_tab.refresh_curr(&view.mid_win);
- curr_tab.refresh_path_status(
- &view.top_win,
- &context.username,
- &context.hostname,
- context.config_t.tilde_in_titlebar,
- );
+ curr_tab.refresh_path_status(&view.top_win, context.config_t.tilde_in_titlebar);
curr_tab.refresh_file_status(&view.bot_win);
curr_tab.refresh_preview(&view.right_win, &context.config_t);
ncurses::doupdate();
diff --git a/src/commands/delete_files.rs b/src/commands/delete_files.rs
index 615f12d..a742499 100644
--- a/src/commands/delete_files.rs
+++ b/src/commands/delete_files.rs
@@ -56,31 +56,23 @@ impl DeleteFiles {
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,
- );
+
+ if let Some(s) = curr_tab.curr_list.index {
+ curr_tab.curr_list.pagestate.update_page_state(
+ s,
+ view.mid_win.rows,
+ curr_tab.curr_list.contents.len(),
+ context.config_t.scroll_offset,
+ );
+ }
+ curr_tab.refresh_curr(&view.mid_win);
+ curr_tab.refresh_parent(&view.left_win, &context.config_t);
+ curr_tab.refresh_preview(&view.right_win, &context.config_t);
}
- } else {
- curr_tab.refresh_file_status(&view.bot_win);
- curr_tab.refresh_path_status(
- &view.top_win,
- &context.username,
- &context.hostname,
- context.config_t.tilde_in_titlebar,
- );
}
- } else {
- curr_tab.refresh_file_status(&view.bot_win);
- curr_tab.refresh_path_status(
- &view.top_win,
- &context.username,
- &context.hostname,
- context.config_t.tilde_in_titlebar,
- );
}
+ curr_tab.refresh_file_status(&view.bot_win);
+ curr_tab.refresh_path_status(&view.top_win, context.config_t.tilde_in_titlebar);
ncurses::doupdate();
Ok(())
}
diff --git a/src/commands/open_file.rs b/src/commands/open_file.rs
index 0b60c02..3e17978 100644
--- a/src/commands/open_file.rs
+++ b/src/commands/open_file.rs
@@ -34,25 +34,6 @@ impl OpenFile {
mimetype_options.extend(ext_entries);
}
}
- /*
- match tree_magic::from_filepath(&path) {
- None => {},
- Some(mimetype) => {
- /* mime subtype have second priority */
- if let Some(s) = MIMETYPE_T.mimetype.get(&mimetype) {
- mimetype_options.extend(s.iter());
- }
-
- /* generic mime type have last priority */
- if let Some(s) = mimetype.find('/') {
- let mimetype_type = &mimetype[..s];
- if let Some(s) = MIMETYPE_T.mimetype.get(mimetype_type) {
- mimetype_options.extend(s.iter());
- }
- }
- }
- }
- */
mimetype_options
}
@@ -74,12 +55,7 @@ impl OpenFile {
.curr_list
.update_contents(&context.config_t.sort_option)?;
}
- curr_tab.refresh(
- view,
- &context.config_t,
- &context.username,
- &context.hostname,
- );
+ curr_tab.refresh(view, &context.config_t);
} else {
let paths: Option<Vec<PathBuf>> = context.tabs[context.curr_tab_index]
.curr_list
@@ -97,12 +73,7 @@ impl OpenFile {
.curr_list
.update_contents(&context.config_t.sort_option)?;
}
- curr_tab.refresh(
- view,
- &context.config_t,
- &context.username,
- &context.hostname,
- );
+ curr_tab.refresh(view, &context.config_t);
}
ncurses::doupdate();
Ok(())
diff --git a/src/commands/parent_directory.rs b/src/commands/parent_directory.rs
index 83ada54..50de924 100644
--- a/src/commands/parent_directory.rs
+++ b/src/commands/parent_directory.rs
@@ -34,12 +34,7 @@ impl ParentDirectory {
.history
.insert(new_curr_list.path.clone(), new_curr_list);
- curr_tab.refresh(
- view,
- &context.config_t,
- &context.username,
- &context.hostname,
- );
+ curr_tab.refresh(view, &context.config_t);
ncurses::doupdate();
Ok(())
}
diff --git a/src/commands/reload_dir.rs b/src/commands/reload_dir.rs
index 8891688..fc0dd78 100644
--- a/src/commands/reload_dir.rs
+++ b/src/commands/reload_dir.rs
@@ -16,13 +16,20 @@ impl ReloadDirList {
pub fn reload(context: &mut JoshutoContext, view: &JoshutoView) -> Result<(), std::io::Error> {
let curr_tab = &mut context.tabs[context.curr_tab_index];
- curr_tab.reload_contents(&context.config_t.sort_option)?;
- curr_tab.refresh(
- view,
- &context.config_t,
- &context.username,
- &context.hostname,
- );
+ let dir_len = curr_tab.curr_list.contents.len();
+ match curr_tab.curr_list.index {
+ None => {}
+ Some(s) => {
+ curr_tab.curr_list.pagestate.update_page_state(
+ s,
+ view.mid_win.rows,
+ dir_len,
+ context.config_t.scroll_offset,
+ );
+ curr_tab.reload_contents(&context.config_t.sort_option)?;
+ curr_tab.refresh(view, &context.config_t);
+ }
+ }
Ok(())
}
}
diff --git a/src/commands/tab_switch.rs b/src/commands/tab_switch.rs
index 2a45d99..e7bc4a3 100644
--- a/src/commands/tab_switch.rs
+++ b/src/commands/tab_switch.rs
@@ -34,12 +34,7 @@ impl TabSwitch {
.curr_list
.update_contents(&context.config_t.sort_option)?;
}
- curr_tab.refresh(
- view,
- &context.config_t,
- &context.username,
- &context.hostname,
- );
+ curr_tab.refresh(view, &context.config_t);
}
ui::redraw_tab_view(&view.tab_win, &context);
ncurses::doupdate();
diff --git a/src/context.rs b/src/context.rs
index d121277..89ec586 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -3,8 +3,6 @@ use crate::config;
use crate::tab::JoshutoTab;
pub struct JoshutoContext {
- pub username: String,
- pub hostname: String,
pub threads: Vec<FileOperationThread>,
pub curr_tab_index: usize,
pub tabs: Vec<JoshutoTab>,
@@ -15,12 +13,7 @@ pub struct JoshutoContext {
impl JoshutoContext {
pub fn new(config_t: config::JoshutoConfig) -> Self {
- let username: String = whoami::username();
- let hostname: String = whoami::hostname();
-
JoshutoContext {
- username,
- hostname,
threads: Vec::new(),
curr_tab_index: 0,
tabs: Vec::new(),
diff --git a/src/history.rs b/src/history.rs
index 7c6076f..0f604c3 100644
--- a/src/history.rs
+++ b/src/history.rs
@@ -26,24 +26,26 @@ impl DirectoryHistory for JoshutoHistory {
let mut ancestors = pathbuf.ancestors();
match ancestors.next() {
None => {}
- Some(mut ancestor) => for curr in ancestors {
- match JoshutoDirList::new(curr.to_path_buf().clone(), sort_option) {
- Ok(mut s) => {
- let index = s.contents.iter().enumerate().find_map(|(i, dir)| {
- if dir.path == ancestor {
- Some(i)
- } else {
- None
+ Some(mut ancestor) => {
+ for curr in ancestors {
+ match JoshutoDirList::new(curr.to_path_buf().clone(), sort_option) {
+ Ok(mut s) => {
+ let index = s.contents.iter().enumerate().find_map(|(i, dir)| {
+ if dir.path == ancestor {
+ Some(i)
+ } else {
+ None
+ }
+ });
+ if let Some(i) = index {
+ s.index = Some(i);
}
- });
- if let Some(i) = index {
- s.index = Some(i);
+ self.insert(curr.to_path_buf(), s);
}
- self.insert(curr.to_path_buf(), s);
+ Err(e) => eprintln!("populate_to_root: {}", e),
}
- Err(e) => eprintln!("populate_to_root: {}", e),
+ ancestor = curr;
}
- ancestor = curr;
}
}
}
diff --git a/src/main.rs b/src/main.rs
index 4c96326..0fce913 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -47,6 +47,9 @@ lazy_static! {
static ref MIMETYPE_T: JoshutoMimetype = JoshutoMimetype::get_config();
static ref PREVIEW_T: JoshutoPreview = JoshutoPreview::get_config();
static ref HOME_DIR: Option<PathBuf> = dirs::home_dir();
+
+ static ref USERNAME: String = whoami::username();
+ static ref HOSTNAME: String = whoami::hostname();
}
#[derive(StructOpt, Debug)]
diff --git a/src/run.rs b/src/run.rs
index 2757230..ef8a499 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -66,24 +66,14 @@ fn join_thread(
let dirty_tab = &mut context.tabs[tab_src];
dirty_tab.reload_contents(&context.config_t.sort_option)?;
if tab_src == context.curr_tab_index {
- dirty_tab.refresh(
- view,
- &context.config_t,
- &context.username,
- &context.hostname,
- );
+ dirty_tab.refresh(view, &context.config_t);
}
}
if tab_dest != tab_src && tab_dest < context.tabs.len() {
let dirty_tab = &mut context.tabs[tab_dest];
dirty_tab.reload_contents(&context.config_t.sort_option)?;
if tab_dest == context.curr_tab_index {
- dirty_tab.refresh(
- view,
- &context.config_t,
- &context.username,
- &context.hostname,
- );
+ dirty_tab.refresh(view, &context.config_t);
}
}
}
@@ -117,12 +107,7 @@ fn process_threads(context: &mut JoshutoContext, view: &JoshutoView) -> Result<(
fn resize_handler(context: &mut JoshutoContext, view: &JoshutoView) {
ui::redraw_tab_view(&view.tab_win, &context);
let curr_tab = &mut context.tabs[context.curr_tab_index];
- curr_tab.refresh(
- view,
- &context.config_t,
- &context.username,
- &context.hostname,
- );
+ curr_tab.refresh(view, &context.config_t);
ncurses::doupdate();
}
@@ -133,12 +118,7 @@ fn init_context(context: &mut JoshutoContext, view: &JoshutoView) {
context.tabs.push(tab);
context.curr_tab_index = context.tabs.len() - 1;
let curr_tab = &mut context.tabs[context.curr_tab_index];
- curr_tab.refresh(
- view,
- &context.config_t,
- &context.username,
- &context.hostname,
- );
+ curr_tab.refresh(view, &context.config_t);
ui::redraw_tab_view(&view.tab_win, &context);
ncurses::doupdate();
}
diff --git a/src/tab.rs b/src/tab.rs
index 8baec31..5e9440e 100644
--- a/src/tab.rs
+++ b/src/tab.rs
@@ -9,6 +9,8 @@ use crate::structs::JoshutoDirList;
use crate::ui;
use crate::window::{JoshutoPanel, JoshutoView};
+use crate::{HOSTNAME, USERNAME};
+
use crate::THEME_T;
pub struct JoshutoTab {
@@ -73,22 +75,11 @@ impl JoshutoTab {
Ok(())
}
- pub fn refresh(
- &mut self,
- views: &JoshutoView,
- config_t: &config::JoshutoConfig,
- username: &str,
- hostname: &str,
- ) {
+ pub fn refresh(&mut self, views: &JoshutoView, config_t: &config::JoshutoConfig) {
self.refresh_curr(&views.mid_win);
self.refresh_parent(&views.left_win, config_t);
self.refresh_preview(&views.right_win, config_t);
- self.refresh_path_status(
- &views.top_win,
- username,
- hostname,
- config_t.tilde_in_titlebar,
- );
+ self.refresh_path_status(&views.top_win, config_t.tilde_in_titlebar);
self.refresh_file_status(&views.bot_win);
}
@@ -126,26 +117,20 @@ impl JoshutoTab {
win.queue_for_refresh();
}
- pub fn refresh_path_status(
- &self,
- win: &JoshutoPanel,
- username: &str,
- hostname: &str,
- tilde_in_titlebar: bool,
- ) {
+ pub fn refresh_path_status(&self, win: &JoshutoPanel, tilde_in_titlebar: bool) {
let path_str: &str = self.curr_path.to_str().unwrap();
ncurses::werase(win.win);
ncurses::wattron(win.win, ncurses::A_BOLD());
- ncurses::mvwaddstr(win.win, 0, 0, username);
+ ncurses::mvwaddstr(win.win, 0, 0, (*USERNAME).as_str());
ncurses::waddstr(win.win, "@");
- ncurses::waddstr(win.win, hostname);
+ ncurses::waddstr(win.win, (*HOSTNAME).as_str());
ncurses::waddstr(win.win, " ");
ncurses::wattron(win.win, ncurses::COLOR_PAIR(THEME_T.directory.colorpair));
if tilde_in_titlebar {
- let path_str = &path_str.replace(&format!("/home/{}", username), "~");
+ let path_str = &path_str.replace(&format!("/home/{}", (*USERNAME).as_str()), "~");
ncurses::waddstr(win.win, path_str);
} else {
ncurses::waddstr(win.win, path_str);