summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2018-12-24 09:13:56 -0500
committerJiayi Zhao <jeff.no.zhao@gmail.com>2018-12-24 09:13:56 -0500
commit1b28e151e6798d301dc42ebc2e31c4aba4c9a116 (patch)
tree82fac4a931606e6796ac131ecda98e9d266ecf8b
parent1c33427bb0f44f53048bfac15bc3d2bd1ff0857e (diff)
parent6f209921c25d1f9ff74ee6571c680b2d64fdd84a (diff)
Merge branch 'dev'
-rw-r--r--config/mimetype.toml3
-rw-r--r--src/joshuto/keymap.rs2
-rw-r--r--src/joshuto/keymapll.rs9
-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
-rw-r--r--src/main.rs6
8 files changed, 116 insertions, 63 deletions
diff --git a/config/mimetype.toml b/config/mimetype.toml
index ecac788..d204b65 100644
--- a/config/mimetype.toml
+++ b/config/mimetype.toml
@@ -20,3 +20,6 @@
"text/x-csrc" = [
["nano"]
]
+"video/mp4" = [
+ ["mpv"]
+]
diff --git a/src/joshuto/keymap.rs b/src/joshuto/keymap.rs
index f847011..f8309e3 100644
--- a/src/joshuto/keymap.rs
+++ b/src/joshuto/keymap.rs
@@ -75,7 +75,6 @@ impl JoshutoRawKeymap {
{
match keys.next() {
Some(s) => {
- print!("{:?}+", key);
let mut new_map: HashMap<i32, JoshutoCommand>;
let key_i32 = key.clone() as i32;
@@ -103,7 +102,6 @@ impl JoshutoRawKeymap {
map.insert(key as i32, JoshutoCommand::CompositeKeybind(new_map));
}
None => {
- println!("{:?} -> {:?}", key, keycommand);
map.insert(key as i32, keycommand);
}
}
diff --git a/src/joshuto/keymapll.rs b/src/joshuto/keymapll.rs
index cd5f58f..e4aa82c 100644
--- a/src/joshuto/keymapll.rs
+++ b/src/joshuto/keymapll.rs
@@ -50,7 +50,7 @@ pub enum Keycode {
STAB = ncurses::KEY_STAB as isize,
CTAB = ncurses::KEY_CTAB as isize,
CATAB = ncurses::KEY_CATAB as isize,
- ENTER = ncurses::KEY_ENTER as isize,
+// ENTER = ncurses::KEY_ENTER as isize,
PRINT = ncurses::KEY_PRINT as isize, /* print key */
LL = ncurses::KEY_LL as isize,
A1 = ncurses::KEY_A1 as isize,
@@ -119,6 +119,8 @@ pub enum Keycode {
EVENT = ncurses::KEY_EVENT as isize,
MAX = ncurses::KEY_MAX as isize,
+ NEWLINE = 0xA,
+
ZERO = 0x30,
ONE = 0x31,
TWO = 0x32,
@@ -257,6 +259,7 @@ impl Keycode {
"CTRL" => Some(Keycode::CTRL),
"SHIFT" => Some(Keycode::SHIFT),
"ALT" => Some(Keycode::ALT),
+
"CODE_YES" => Some(Keycode::CODE_YES),
"BREAK" => Some(Keycode::BREAK),
"SRESET" => Some(Keycode::SRESET),
@@ -298,7 +301,9 @@ impl Keycode {
"STAB" => Some(Keycode::STAB),
"CTAB" => Some(Keycode::CTAB),
"CATAB" => Some(Keycode::CATAB),
- "ENTER" => Some(Keycode::ENTER),
+ "ENTER" => Some(Keycode::NEWLINE),
+
+// "ENTER" => Some(Keycode::ENTER),
"PRINT" => Some(Keycode::PRINT),
"LL" => Some(Keycode::LL),
"A1" => Some(Keycode::A1),
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);
}
diff --git a/src/main.rs b/src/main.rs
index 7937925..92ad80f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -19,13 +19,13 @@ fn main()
println!("args: {:?}", args);
let config = joshuto::config::JoshutoConfig::get_config();
- println!("config:\n{:#?}", config);
+// println!("config:\n{:#?}", config);
let keymap = joshuto::keymap::JoshutoKeymap::get_config();
- println!("keymap:\n{:#?}", keymap);
+// println!("keymap:\n{:#?}", keymap);
let mimetype = joshuto::mimetype::JoshutoMimetype::get_config();
- println!("mimetype:\n{:#?}", mimetype);
+// println!("mimetype:\n{:#?}", mimetype);
joshuto::run(config, keymap, mimetype);
}