summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2018-12-24 09:13:32 -0500
committerJiayi Zhao <jeff.no.zhao@gmail.com>2018-12-24 09:13:32 -0500
commit6f209921c25d1f9ff74ee6571c680b2d64fdd84a (patch)
treee282694a9b2ef192cc06486e18ed7d442a194e61
parent67f835a4a5c00e139d628e44c62349279c8698ff (diff)
fix status bars not updating properly
-rw-r--r--src/joshuto/mod.rs100
-rw-r--r--src/joshuto/navigation.rs12
-rw-r--r--src/joshuto/structs.rs39
-rw-r--r--src/joshuto/ui.rs8
4 files changed, 103 insertions, 56 deletions
diff --git a/src/joshuto/mod.rs b/src/joshuto/mod.rs
index cd283ac..a914a9a 100644
--- a/src/joshuto/mod.rs
+++ b/src/joshuto/mod.rs
@@ -69,6 +69,22 @@ fn redraw_views(joshuto_view : &structs::JoshutoView,
}
}
+fn redraw_status(joshuto_view : &structs::JoshutoView,
+ curr_view: Option<&structs::JoshutoDirList>, curr_path: &path::PathBuf,
+ username: &str, hostname: &str)
+{
+ if let Some(s) = curr_view.as_ref() {
+ let dirent = s.get_dir_entry(s.index);
+ if let Some(dirent) = dirent {
+ if let Ok(file_name) = dirent.entry.file_name().into_string() {
+ ui::wprint_path(&joshuto_view.top_win, username, hostname,
+ curr_path, file_name.as_str());
+ ui::wprint_file_info(joshuto_view.bot_win.win, &dirent.entry);
+ }
+ }
+ }
+}
+
fn refresh_handler(config_t: &config::JoshutoConfig,
joshuto_view : &mut structs::JoshutoView,
curr_path : &path::PathBuf,
@@ -79,19 +95,10 @@ fn refresh_handler(config_t: &config::JoshutoConfig,
joshuto_view.redraw_views();
ncurses::refresh();
- ui::wprint_path(&joshuto_view.top_win, &config_t.username,
- &config_t.hostname, curr_path);
-
redraw_views(joshuto_view, parent_view, curr_view, preview_view);
- let index = curr_view.unwrap().index;
- if index >= 0 {
- let index : usize = index as usize;
- let dirent : &structs::JoshutoDirEntry = &curr_view.unwrap().contents
- .as_ref().unwrap()[index];
-
- ui::wprint_file_info(joshuto_view.bot_win.win, &dirent.entry);
- }
+ redraw_status(joshuto_view, curr_view, curr_path,
+ &config_t.username, &config_t.hostname);
ncurses::doupdate();
}
@@ -107,7 +114,6 @@ pub fn run(mut config_t: config::JoshutoConfig,
process::exit(1);
},
};
- println!("pwd: {:?}", curr_path);
/* keep track of where we are in directories */
let mut history = history::History::new();
@@ -147,7 +153,6 @@ pub fn run(mut config_t: config::JoshutoConfig,
let index : usize = curr_view.as_ref().unwrap().index as usize;
let dirent : &structs::JoshutoDirEntry = &curr_view.as_ref().unwrap()
.contents.as_ref().unwrap()[index];
- ui::wprint_file_info(joshuto_view.bot_win.win, &dirent.entry);
let preview_path = dirent.entry.path();
if preview_path.is_dir() {
@@ -168,8 +173,9 @@ pub fn run(mut config_t: config::JoshutoConfig,
} else {
preview_view = None;
}
- ui::wprint_path(&joshuto_view.top_win, &config_t.username, &config_t.hostname,
- &curr_path);
+
+ redraw_status(&joshuto_view, curr_view.as_ref(), &curr_path,
+ &config_t.username, &config_t.hostname);
redraw_views(&joshuto_view,
parent_view.as_ref(),
@@ -204,7 +210,6 @@ pub fn run(mut config_t: config::JoshutoConfig,
continue;
}
}
- eprintln!("{:?}", *keycommand);
match *keycommand {
JoshutoCommand::Quit => break,
@@ -217,9 +222,7 @@ pub fn run(mut config_t: config::JoshutoConfig,
preview_view = match navigation::set_dir_cursor_index(&mut history,
curr_view.as_mut().unwrap(), preview_view, &config_t.sort_type,
curr_index - 1) {
- Ok(s) => {
- Some(s)
- },
+ Ok(s) => s,
Err(e) => {
ui::wprint_err(&joshuto_view.bot_win, format!("{}", e).as_str());
None
@@ -230,6 +233,10 @@ pub fn run(mut config_t: config::JoshutoConfig,
None.as_ref(),
curr_view.as_ref(),
preview_view.as_ref());
+
+ redraw_status(&joshuto_view, curr_view.as_ref(), &curr_path,
+ &config_t.username, &config_t.hostname);
+
ncurses::doupdate();
},
JoshutoCommand::MoveDown => {
@@ -244,7 +251,7 @@ pub fn run(mut config_t: config::JoshutoConfig,
preview_view = match navigation::set_dir_cursor_index(&mut history,
curr_view.as_mut().unwrap(), preview_view, &config_t.sort_type,
curr_index + 1) {
- Ok(s) => Some(s),
+ Ok(s) => s,
Err(e) => {
ui::wprint_err(&joshuto_view.bot_win, format!("{}", e).as_str());
None
@@ -255,6 +262,10 @@ pub fn run(mut config_t: config::JoshutoConfig,
None.as_ref(),
curr_view.as_ref(),
preview_view.as_ref());
+
+ redraw_status(&joshuto_view, curr_view.as_ref(), &curr_path,
+ &config_t.username, &config_t.hostname);
+
ncurses::doupdate();
},
JoshutoCommand::MovePageUp => {
@@ -273,7 +284,7 @@ pub fn run(mut config_t: config::JoshutoConfig,
preview_view = match navigation::set_dir_cursor_index(&mut history,
curr_view.as_mut().unwrap(), preview_view, &config_t.sort_type,
curr_index) {
- Ok(s) => Some(s),
+ Ok(s) => s,
Err(e) => {
ui::wprint_err(&joshuto_view.bot_win, format!("{}", e).as_str());
None
@@ -284,6 +295,10 @@ pub fn run(mut config_t: config::JoshutoConfig,
None.as_ref(),
curr_view.as_ref(),
preview_view.as_ref());
+
+ redraw_status(&joshuto_view, curr_view.as_ref(), &curr_path,
+ &config_t.username, &config_t.hostname);
+
ncurses::doupdate();
},
JoshutoCommand::MovePageDown => {
@@ -305,7 +320,7 @@ pub fn run(mut config_t: config::JoshutoConfig,
preview_view = match navigation::set_dir_cursor_index(&mut history,
curr_view.as_mut().unwrap(), preview_view, &config_t.sort_type,
curr_index) {
- Ok(s) => Some(s),
+ Ok(s) => s,
Err(e) => {
ui::wprint_err(&joshuto_view.bot_win, format!("{}", e).as_str());
None
@@ -316,6 +331,10 @@ pub fn run(mut config_t: config::JoshutoConfig,
None.as_ref(),
curr_view.as_ref(),
preview_view.as_ref());
+
+ redraw_status(&joshuto_view, curr_view.as_ref(), &curr_path,
+ &config_t.username, &config_t.hostname);
+
ncurses::doupdate();
},
JoshutoCommand::MoveHome => {
@@ -326,7 +345,7 @@ pub fn run(mut config_t: config::JoshutoConfig,
preview_view = match navigation::set_dir_cursor_index(&mut history,
curr_view.as_mut().unwrap(), preview_view, &config_t.sort_type, 0) {
- Ok(s) => Some(s),
+ Ok(s) => s,
Err(e) => {
ui::wprint_err(&joshuto_view.bot_win, format!("{}", e).as_str());
None
@@ -337,6 +356,10 @@ pub fn run(mut config_t: config::JoshutoConfig,
None.as_ref(),
curr_view.as_ref(),
preview_view.as_ref());
+
+ redraw_status(&joshuto_view, curr_view.as_ref(), &curr_path,
+ &config_t.username, &config_t.hostname);
+
ncurses::doupdate();
},
JoshutoCommand::MoveEnd => {
@@ -350,7 +373,7 @@ pub fn run(mut config_t: config::JoshutoConfig,
preview_view = match navigation::set_dir_cursor_index(&mut history,
curr_view.as_mut().unwrap(), preview_view, &config_t.sort_type,
(dir_len - 1) as i32) {
- Ok(s) => Some(s),
+ Ok(s) => s,
Err(e) => {
ui::wprint_err(&joshuto_view.bot_win, format!("{}", e).as_str());
None
@@ -361,6 +384,10 @@ pub fn run(mut config_t: config::JoshutoConfig,
None.as_ref(),
curr_view.as_ref(),
preview_view.as_ref());
+
+ redraw_status(&joshuto_view, curr_view.as_ref(), &curr_path,
+ &config_t.username, &config_t.hostname);
+
ncurses::doupdate();
},
JoshutoCommand::ParentDirectory => {
@@ -413,9 +440,8 @@ pub fn run(mut config_t: config::JoshutoConfig,
let dirent : &structs::JoshutoDirEntry = &curr_view.as_ref().unwrap()
.contents.as_ref().unwrap()[index];
- ui::wprint_path(&joshuto_view.top_win, &config_t.username,
- &config_t.hostname, &curr_path);
- ui::wprint_file_info(joshuto_view.bot_win.win, &dirent.entry);
+ redraw_status(&joshuto_view, curr_view.as_ref(), &curr_path,
+ &config_t.username, &config_t.hostname);
ncurses::doupdate();
},
@@ -450,11 +476,6 @@ pub fn run(mut config_t: config::JoshutoConfig,
format!("{}", e).as_str());
}
}
- } else {
- let dirent : &structs::JoshutoDirEntry = &curr_view.as_ref().unwrap()
- .contents.as_ref()
- .unwrap()[index];
- ui::wprint_file_info(joshuto_view.bot_win.win, &dirent.entry);
}
ncurses::doupdate();
},
@@ -504,8 +525,8 @@ pub fn run(mut config_t: config::JoshutoConfig,
}
}
- ui::wprint_path(&joshuto_view.top_win, &config_t.username, &config_t.hostname,
- &curr_path);
+ redraw_status(&joshuto_view, curr_view.as_ref(), &curr_path,
+ &config_t.username, &config_t.hostname);
if curr_view.as_ref().unwrap().contents.as_ref().unwrap().len() == 0 {
redraw_views(&joshuto_view,
@@ -530,7 +551,6 @@ pub fn run(mut config_t: config::JoshutoConfig,
None
},
};
- ui::wprint_file_info(joshuto_view.bot_win.win, &dirent.entry);
} else {
ncurses::werase(joshuto_view.right_win.win);
ui::wprint_err(&joshuto_view.right_win, "Not a directory");
@@ -541,6 +561,10 @@ pub fn run(mut config_t: config::JoshutoConfig,
curr_view.as_ref(),
preview_view.as_ref());
+ redraw_status(&joshuto_view, curr_view.as_ref(), &curr_path,
+ &config_t.username, &config_t.hostname);
+
+
ncurses::doupdate();
}
Err(e) => {
@@ -579,15 +603,13 @@ pub fn run(mut config_t: config::JoshutoConfig,
let dirent : &structs::JoshutoDirEntry = &curr_view.as_ref().unwrap()
.contents.as_ref().unwrap()[index];
- ui::wprint_path(&joshuto_view.top_win, &config_t.username,
- &config_t.hostname, &dirent.entry.path());
+ redraw_status(&joshuto_view, curr_view.as_ref(), &curr_path,
+ &config_t.username, &config_t.hostname);
s.update(dirent.entry.path().as_path(), &config_t.sort_type);
ui::display_contents(&joshuto_view.right_win, &s);
ncurses::wnoutrefresh(joshuto_view.right_win.win);
-
- ui::wprint_file_info(joshuto_view.bot_win.win, &dirent.entry);
}
}
ncurses::doupdate();
diff --git a/src/joshuto/navigation.rs b/src/joshuto/navigation.rs
index 506cb49..6bace13 100644
--- a/src/joshuto/navigation.rs
+++ b/src/joshuto/navigation.rs
@@ -10,7 +10,7 @@ pub fn set_dir_cursor_index(history : &mut history::History,
preview_view: Option<structs::JoshutoDirList>,
sort_type: &sort::SortType,
new_index: i32)
- -> Result<structs::JoshutoDirList, std::io::Error>
+ -> Result<Option<structs::JoshutoDirList>, std::io::Error>
{
let curr_index = curr_view.index as usize;
match preview_view {
@@ -26,7 +26,13 @@ pub fn set_dir_cursor_index(history : &mut history::History,
let curr_index = curr_view.index as usize;
let new_path: path::PathBuf = curr_view.contents.as_ref()
.unwrap()[curr_index].entry.path();
-
- history.pop_or_create(new_path.as_path(), sort_type)
+ 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/structs.rs b/src/joshuto/structs.rs
index 98c44e5..3c1201c 100644
--- a/src/joshuto/structs.rs
+++ b/src/joshuto/structs.rs
@@ -17,11 +17,11 @@ pub struct JoshutoDirEntry {
#[derive(Debug)]
pub struct JoshutoDirList {
- pub index : i32,
- pub need_update : bool,
- pub modified : time::SystemTime,
- pub contents : Option<Vec<JoshutoDirEntry>>,
- pub selection : Vec<fs::DirEntry>,
+ pub index: i32,
+ pub need_update: bool,
+ pub modified: time::SystemTime,
+ pub contents: Option<Vec<JoshutoDirEntry>>,
+ pub selection: Vec<fs::DirEntry>,
}
impl JoshutoDirList {
@@ -49,11 +49,6 @@ impl JoshutoDirList {
})
}
- pub fn display_contents(&self, win: &JoshutoWindow)
- {
- ui::display_contents(win, self);
- }
-
pub fn update(&mut self, path : &path::Path, sort_type: &sort::SortType)
{
let sort_func = sort_type.compare_func();
@@ -63,7 +58,8 @@ impl JoshutoDirList {
if let Ok(mut dir_contents) = JoshutoDirList::read_dir_list(path, sort_type) {
dir_contents.sort_by(&sort_func);
self.contents = Some(dir_contents);
- if self.index as usize >= self.contents.as_ref().unwrap().len() {
+ if self.index >= 0 &&
+ self.index as usize >= self.contents.as_ref().unwrap().len() {
if self.contents.as_ref().unwrap().len() > 0 {
self.index = (self.contents.as_ref().unwrap().len() - 1) as i32;
}
@@ -78,6 +74,27 @@ impl JoshutoDirList {
}
}
+ pub fn get_dir_entry(&self, index: i32) -> Option<&JoshutoDirEntry>
+ {
+ match self.contents {
+ Some(ref s) => {
+ if index >= 0 && (index as usize) < s.len() {
+ Some(&s[index as usize])
+ } else {
+ None
+ }
+ },
+ None => {
+ None
+ }
+ }
+ }
+
+ pub fn display_contents(&self, win: &JoshutoWindow)
+ {
+ ui::display_contents(win, self);
+ }
+
fn read_dir_list(path : &path::Path, sort_type: &sort::SortType)
-> Result<Vec<JoshutoDirEntry>, std::io::Error>
{
diff --git a/src/joshuto/ui.rs b/src/joshuto/ui.rs
index 354898c..c209882 100644
--- a/src/joshuto/ui.rs
+++ b/src/joshuto/ui.rs
@@ -68,11 +68,11 @@ pub fn wprint_err(win : &structs::JoshutoWindow, err_msg : &str)
ncurses::wnoutrefresh(win.win);
}
-pub fn wprint_path(win : &structs::JoshutoWindow, username : &str,
- hostname : &str, path : &path::PathBuf)
+pub fn wprint_path(win: &structs::JoshutoWindow, username: &str,
+ hostname: &str, path: &path::PathBuf, file_name: &str)
{
ncurses::werase(win.win);
- let path_str : &str = match path.to_str() {
+ let path_str: &str = match path.to_str() {
Some(s) => s,
None => "Error",
};
@@ -84,6 +84,8 @@ pub fn wprint_path(win : &structs::JoshutoWindow, username : &str,
ncurses::waddstr(win.win, path_str);
ncurses::wattroff(win.win, ncurses::A_BOLD());
+ ncurses::waddstr(win.win, "/");
+ ncurses::waddstr(win.win, file_name);
ncurses::wnoutrefresh(win.win);
}