summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2018-07-14 12:53:35 -0400
committerJiayi Zhao <jeff.no.zhao@gmail.com>2018-07-14 12:53:35 -0400
commitdc21e9e65c8b9a1e2aa8c75a19fbb6561211fa00 (patch)
tree16010f6ab3c3e8e5866a8659e5a686231e4aae41
parentf78db0e501245e5835502e6e91272abf41c0fa2a (diff)
move most code to joshuto.rs
- add preliminary support for config file
-rw-r--r--.gitignore1
-rw-r--r--Cargo.lock64
-rw-r--r--Cargo.toml3
-rw-r--r--config/joshuto.toml4
-rw-r--r--src/joshuto.rs296
-rw-r--r--src/main.rs227
6 files changed, 392 insertions, 203 deletions
diff --git a/.gitignore b/.gitignore
index 53eaa21..a49f072 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
/target
+/test
**/*.rs.bk
diff --git a/Cargo.lock b/Cargo.lock
index cb45365..f472a46 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -8,6 +8,9 @@ name = "joshuto"
version = "0.1.0"
dependencies = [
"ncurses 5.93.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)",
+ "toml 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -30,8 +33,69 @@ name = "pkg-config"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
+[[package]]
+name = "proc-macro2"
+version = "0.4.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "quote"
+version = "0.6.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "proc-macro2 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "serde"
+version = "1.0.70"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "serde_derive"
+version = "1.0.70"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "proc-macro2 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syn 0.14.4 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "syn"
+version = "0.14.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "proc-macro2 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "toml"
+version = "0.4.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "unicode-xid"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
[metadata]
"checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb"
"checksum libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "b685088df2b950fccadf07a7187c8ef846a959c142338a48f9dc0b94517eb5f1"
"checksum ncurses 5.93.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0ecd01d431a5e9c1c733a1e3ab939b9b6c9c4ddc540c74caf3909664127785fa"
"checksum pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "110d5ee3593dbb73f56294327fe5668bcc997897097cbc76b51e7aed3f52452f"
+"checksum proc-macro2 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "effdb53b25cdad54f8f48843d67398f7ef2e14f12c1b4cb4effc549a6462a4d6"
+"checksum quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e44651a0dc4cdd99f71c83b561e221f714912d11af1a4dff0631f923d53af035"
+"checksum serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)" = "0c3adf19c07af6d186d91dae8927b83b0553d07ca56cbf7f2f32560455c91920"
+"checksum serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)" = "3525a779832b08693031b8ecfb0de81cd71cfd3812088fafe9a7496789572124"
+"checksum syn 0.14.4 (registry+https://github.com/rust-lang/crates.io-index)" = "2beff8ebc3658f07512a413866875adddd20f4fd47b2a4e6c9da65cd281baaea"
+"checksum toml 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a0263c6c02c4db6c8f7681f9fd35e90de799ebd4cfdeab77a38f4ff6b3d8c0d9"
+"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
diff --git a/Cargo.toml b/Cargo.toml
index 9e0918b..440c2d5 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -5,3 +5,6 @@ authors = ["Jiayi Zhao <jeff.no.zhao@gmail.com>"]
[dependencies]
ncurses = "5.93.0"
+serde = "1.0.70"
+serde_derive = "1.0.70"
+toml = "0.4"
diff --git a/config/joshuto.toml b/config/joshuto.toml
new file mode 100644
index 0000000..3ef7e3b
--- /dev/null
+++ b/config/joshuto.toml
@@ -0,0 +1,4 @@
+show_hidden = true
+# sort_method options: size, natural, basename, atime, ctime, mtime, type, random
+sort_method = "natural"
+
diff --git a/src/joshuto.rs b/src/joshuto.rs
index 245fda6..56758c8 100644
--- a/src/joshuto.rs
+++ b/src/joshuto.rs
@@ -1,8 +1,239 @@
extern crate ncurses;
-use std::fs;
-use std::cmp;
use std;
+use std::env;
+use std::fs;
+use std::path;
+use std::process;
+
+const QUIT: i32 = 'q' as i32;
+const ENTER: i32 = '\n' as i32;
+
+pub mod joshuto_sort {
+
+ use std::cmp;
+ use std::fs;
+ use std;
+
+ pub fn alpha_sort(file1 : &fs::DirEntry, file2 : &fs::DirEntry) -> cmp::Ordering
+ {
+ fn res_ordering(file1 : &fs::DirEntry, file2 : &fs::DirEntry) -> Result<cmp::Ordering, std::io::Error> {
+ let f1_type = file1.metadata()?;
+ let f2_type = file2.metadata()?;
+
+ if !f1_type.is_file() && f2_type.is_file() {
+ Ok(cmp::Ordering::Less)
+ } else if !f2_type.is_file() && f1_type.is_file() {
+ Ok(cmp::Ordering::Greater)
+ } else {
+ let f1_name : std::string::String =
+ file1.file_name().as_os_str().to_str().unwrap().to_lowercase();
+ let f2_name : std::string::String =
+ file2.file_name().as_os_str().to_str().unwrap().to_lowercase();
+ if f1_name <= f2_name {
+ Ok(cmp::Ordering::Less)
+ } else {
+ Ok(cmp::Ordering::Greater)
+ }
+ }
+ }
+ res_ordering(file1, file2).unwrap_or(cmp::Ordering::Less)
+ }
+}
+
+pub fn run()
+{
+ init_ncurses();
+
+ let mut term_rows : i32 = 0;
+ let mut term_cols : i32 = 0;
+ ncurses::getmaxyx(ncurses::stdscr(), &mut term_rows, &mut term_cols);
+
+ let mut index : usize = 0;
+ let mut pindex : usize = 0;
+ let mut cindex : usize = 0;
+
+ ncurses::refresh();
+
+ let mut top_win = ncurses::newwin(1, term_cols, 0, 0);
+ let mut mid_win = ncurses::newwin(term_rows - 2, term_cols / 7 * 3,
+ 1, term_cols / 7);
+ let mut left_win = ncurses::newwin(term_rows - 2, term_cols / 7, 1, 0);
+ let mut right_win = ncurses::newwin(term_rows - 2, term_cols / 7 * 3,
+ 1, term_cols / 7 * 4);
+
+ /* TODO: mutable in the future */
+ let sort_func : fn(file1 : &std::fs::DirEntry, file2 : &std::fs::DirEntry) -> std::cmp::Ordering
+ = joshuto_sort::alpha_sort;
+
+ let mut dir_contents : Vec<fs::DirEntry>; // = Vec::new();
+ match cwd_contents() {
+ Ok(s) => {
+ dir_contents = s;
+ dir_contents.sort_by(sort_func);
+ }
+ Err(_e) => {
+ process::exit(1);
+ }
+ }
+
+
+ win_print_curr_path(top_win);
+ win_print_parent_dir(left_win, pindex, (term_rows - 1) as usize);
+
+ win_contents_refresh_indexed(mid_win, &dir_contents, (term_rows - 1) as usize, index);
+
+ ncurses::refresh();
+
+ loop {
+ let ch = ncurses::getch();
+
+ match ch {
+ QUIT => {
+ break;
+ }
+ ncurses::KEY_RESIZE => {
+ ncurses::getmaxyx(ncurses::stdscr(), &mut term_rows, &mut term_cols);
+ top_win = ncurses::newwin(1, term_cols, 0, 0);
+ mid_win = ncurses::newwin(term_rows - 2, term_cols / 7 * 3,
+ term_cols / 7, 1);
+ left_win = ncurses::newwin(term_rows - 2, term_cols / 7, 0, 1);
+ right_win = ncurses::newwin(term_rows - 2, term_cols / 7 * 3,
+ term_cols / 7 * 4, 1);
+ ncurses::refresh();
+ }
+ ncurses::KEY_UP => {
+ if index > 0 {
+ index = index - 1;
+ win_print_select_file(right_win, &dir_contents[index], (term_rows - 1) as usize);
+ }
+ }
+ ncurses::KEY_DOWN => {
+ if index + 1 < dir_contents.len() {
+ index = index + 1;
+ win_print_select_file(right_win, &dir_contents[index], (term_rows - 1) as usize);
+ }
+ }
+ ncurses::KEY_LEFT => {
+ match env::current_dir() {
+ Ok(mut pathbuf) => {
+ if pathbuf.eq(&path::Path::new("/")) {
+ ncurses::wclear(left_win);
+ ncurses::wrefresh(left_win);
+ continue;
+ }
+ if pathbuf.pop() == false {
+ continue;
+ }
+ match env::set_current_dir(&pathbuf) {
+ Ok(_s) => {
+ match cwd_contents() {
+ Ok(s) => {
+ dir_contents = s;
+ dir_contents.sort_by(sort_func);
+ }
+ Err(_e) => {
+ process::exit(1);
+ }
+ }
+ index = pindex;
+ pindex = 0;
+
+ if pathbuf.eq(&path::Path::new("/")) {
+ ncurses::wclear(left_win);
+ ncurses::wrefresh(left_win);
+ } else {
+ win_print_curr_path(top_win);
+ win_print_parent_dir(left_win, pindex, (term_rows - 1) as usize);
+ }
+ },
+ Err(_e) => {
+ ncurses::printw("None");
+ },
+ };
+ }
+ Err(_e) => {
+ ncurses::printw("None");
+ }
+ };
+ }
+ ncurses::KEY_RIGHT => {
+ match dir_contents[index as usize].file_type() {
+ Ok(file_type) => {
+ if file_type.is_dir() {
+ let new_path : path::PathBuf = dir_contents[index as usize].path();
+ match env::set_current_dir(new_path) {
+ Ok(_s) => {
+ match cwd_contents() {
+ Ok(s) => {
+ dir_contents = s;
+ dir_contents.sort_by(sort_func);
+ }
+ Err(_e) => {
+ process::exit(1);
+ }
+ }
+ pindex = index;
+ index = 0;
+
+ win_print_curr_path(top_win);
+ win_print_parent_dir(left_win, pindex, (term_rows - 1) as usize);
+ },
+ Err(_e) => {
+ ncurses::printw("None");
+ },
+ };
+ }
+ },
+ Err(_e) => {
+ ncurses::printw("None");
+ },
+ };
+ }
+ ENTER => {
+ match dir_contents[index as usize].file_type() {
+ Ok(file_type) => {
+ if file_type.is_dir() {
+ let new_path : path::PathBuf = dir_contents[index as usize].path();
+ match env::set_current_dir(new_path) {
+ Ok(_s) => {
+ match cwd_contents() {
+ Ok(s) => {
+ dir_contents = s;
+ dir_contents.sort_by(sort_func);
+ }
+ Err(_e) => {
+ process::exit(1);
+ }
+ }
+ pindex = index;
+ index = 0;
+
+ win_print_curr_path(top_win);
+ win_print_parent_dir(left_win, pindex, (term_rows - 1) as usize);
+ },
+ Err(_e) => {
+ ncurses::printw("None");
+ },
+ };
+ }
+ },
+ Err(_e) => {
+ ncurses::printw("None");
+ },
+ };
+ }
+ _ => {
+ ncurses::wprintw(mid_win, format!("pressed: {}\n",
+ std::char::from_u32(ch as u32).expect("Invalid char")).as_ref());
+ }
+ };
+
+ win_contents_refresh_indexed(mid_win, &dir_contents,
+ (term_rows - 1) as usize, index);
+ }
+ ncurses::endwin();
+}
pub fn init_ncurses()
{
@@ -25,34 +256,8 @@ fn init_window(win_rows : i32, win_cols : i32, x : i32, y : i32) -> ncurses::WIN
ncurses::newwin(win_rows, win_cols, y, x)
}
-pub fn alpha_sort(file1 : &fs::DirEntry, file2 : &fs::DirEntry) -> cmp::Ordering
-{
- fn res_ordering(file1 : &fs::DirEntry, file2 : &fs::DirEntry) -> Result<cmp::Ordering, std::io::Error> {
- let f1_type = file1.metadata()?;
- let f2_type = file2.metadata()?;
-
- if !f1_type.is_file() && f2_type.is_file() {
- Ok(cmp::Ordering::Less)
- } else if !f2_type.is_file() && f1_type.is_file() {
- Ok(cmp::Ordering::Greater)
- } else {
- let f1_name : std::string::String =
- file1.file_name().as_os_str().to_str().unwrap().to_lowercase();
- let f2_name : std::string::String =
- file2.file_name().as_os_str().to_str().unwrap().to_lowercase();
- if f1_name <= f2_name {
- Ok(cmp::Ordering::Less)
- } else {
- Ok(cmp::Ordering::Greater)
- }
- }
- }
- res_ordering(file1, file2).unwrap_or(cmp::Ordering::Less)
-}
-
-pub fn win_print_dir_basic(win : ncurses::WINDOW,
+pub fn win_contents_refresh(win : ncurses::WINDOW,
dir_contents: &Vec<fs::DirEntry>, win_rows : usize) {
- let offset = 5;
let vec_len = dir_contents.len();
ncurses::wclear(win);
@@ -81,10 +286,10 @@ pub fn win_print_dir_basic(win : ncurses::WINDOW,
match dir_contents[i].file_name().into_string() {
Ok(file_name) => {
ncurses::wprintw(win, " ");
- ncurses::wprintw(win, file_name.as_str());
+ ncurses::wprintw(win, &file_name);
},
Err(_e) => {
- ncurses::wprintw(win, "Error");
+ ncurses::wprintw(win, "file_name Error");
},
};
@@ -96,7 +301,7 @@ pub fn win_print_dir_basic(win : ncurses::WINDOW,
}*/
},
Err(_e) => {
- ncurses::wprintw(win, "Error");
+ ncurses::wprintw(win, "metadata Error");
}
}
@@ -106,9 +311,9 @@ pub fn win_print_dir_basic(win : ncurses::WINDOW,
ncurses::wrefresh(win);
}
-pub fn win_print_dir(win : ncurses::WINDOW,
- dir_contents: &Vec<fs::DirEntry>,
- index : usize, win_rows : usize) {
+pub fn win_contents_refresh_indexed(win : ncurses::WINDOW,
+ dir_contents: &Vec<fs::DirEntry>,
+ win_rows : usize, index : usize) {
let offset = 5;
let vec_len = dir_contents.len();
@@ -147,7 +352,7 @@ pub fn win_print_dir(win : ncurses::WINDOW,
ncurses::wprintw(win, file_name.as_str());
},
Err(_e) => {
- ncurses::wprintw(win, "Error");
+ ncurses::wprintw(win, "file_name Error");
},
};
@@ -165,7 +370,7 @@ pub fn win_print_dir(win : ncurses::WINDOW,
},
Err(_e) => {
- ncurses::wprintw(win, "Error");
+ ncurses::wprintw(win, "metadata Error");
}
}
@@ -175,8 +380,15 @@ pub fn win_print_dir(win : ncurses::WINDOW,
ncurses::wrefresh(win);
}
+pub fn cwd_contents() -> Result<Vec<fs::DirEntry>, std::io::Error>
+{
+ let tmp_result : Result<Vec<fs::DirEntry>, _> = fs::read_dir(".").unwrap().collect();
+ // let dir_contents : Vec<fs::DirEntry> = tmp_result.unwrap();
+ tmp_result
+}
+
-pub fn win_print_curr_dir(win : ncurses::WINDOW)
+pub fn win_print_curr_path(win : ncurses::WINDOW)
{
use std::env;
@@ -191,8 +403,8 @@ pub fn win_print_parent_dir(win : ncurses::WINDOW, index : usize, length : usize
{
let tmp_result : Result<Vec<fs::DirEntry>, _> = fs::read_dir("..").unwrap().collect();
let mut tmp_pdir : Vec<fs::DirEntry> = tmp_result.unwrap();
- tmp_pdir.sort_by(alpha_sort);
- win_print_dir(win, &tmp_pdir, index, length);
+ tmp_pdir.sort_by(joshuto_sort::alpha_sort);
+ win_contents_refresh_indexed(win, &tmp_pdir, length, index);
}
pub fn win_print_select_file(win : ncurses::WINDOW, file : &fs::DirEntry, length : usize)
@@ -203,8 +415,8 @@ pub fn win_print_select_file(win : ncurses::WINDOW, file : &fs::DirEntry, length
if metadata.is_dir() {
let tmp_result : Result<Vec<fs::DirEntry>, _> = fs::read_dir(&file.path()).unwrap().collect();
let mut tmp_cdir : Vec<fs::DirEntry> = tmp_result.unwrap();
- tmp_cdir.sort_by(alpha_sort);
- win_print_dir_basic(win, &tmp_cdir, length);
+ tmp_cdir.sort_by(joshuto_sort::alpha_sort);
+ win_contents_refresh(win, &tmp_cdir, length);
}
}
Err(_e) => {
diff --git a/src/main.rs b/src/main.rs
index 8a25056..8278854 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,13 +1,27 @@
-extern crate ncurses;
+#[macro_use]
+extern crate serde_derive;
-mod joshuto;
+extern crate ncurses;
+extern crate toml;
+use std::env;
use std::fs;
use std::path;
-use std::env;
-const QUIT: i32 = 'q' as i32;
-const ENTER: i32 = '\n' as i32;
+mod joshuto;
+
+#[derive(Debug, Deserialize)]
+struct JoshutoConfig {
+ show_hidden: Option<bool>,
+ color_scheme: Option<String>,
+ sort_method: Option<String>,
+ keymaps: Option<JoshutoKeymaps>,
+}
+
+#[derive(Debug, Deserialize)]
+struct JoshutoKeymaps {
+ up : i32,
+}
/*
pub struct joshuto_win {
@@ -18,169 +32,60 @@ pub struct joshuto_win {
}
*/
-
-fn main()
+fn get_config_path() -> path::PathBuf
{
- let args: Vec<String> = env::args().collect();
-
- println!("{:?}", args);
-
- joshuto::init_ncurses();
-
- let mut term_rows : i32 = 0;
- let mut term_cols : i32 = 0;
- ncurses::getmaxyx(ncurses::stdscr(), &mut term_rows, &mut term_cols);
-
- let mut index : usize = 0;
- let mut pindex : usize = 0;
- let mut cindex : usize = 0;
-
- ncurses::refresh();
-
- let mut top_win = ncurses::newwin(1, term_cols, 0, 0);
- let mut mid_win = ncurses::newwin(term_rows - 2, term_cols / 7 * 3,
- 1, term_cols / 7);
- let mut left_win = ncurses::newwin(term_rows - 2, term_cols / 7, 1, 0);
- let mut right_win = ncurses::newwin(term_rows - 2, term_cols / 7 * 3,
- 1, term_cols / 7 * 4);
-
- let mut tmp_result : Result<Vec<fs::DirEntry>, _> = fs::read_dir(".").unwrap().collect();
- let mut dir_contents : Vec<fs::DirEntry> = tmp_result.unwrap();
- dir_contents.sort_by(joshuto::alpha_sort);
-
- joshuto::win_print_curr_dir(top_win);
- joshuto::win_print_parent_dir(left_win, pindex, (term_rows - 1) as usize);
+ let mut pathbuf : path::PathBuf;
+ match env::home_dir() {
+ Some(path) => {
+ pathbuf = path.to_path_buf();
+ pathbuf.push(".config/joshuto/joshuto.toml");
+ },
+ None => {
+ pathbuf = path::PathBuf::new();
+ pathbuf.push("/etc/joshuto/joshuto.toml");
+ },
+ };
+ pathbuf
+}
- joshuto::win_print_dir(mid_win, &dir_contents, index, (term_rows - 1) as usize);
+fn read_config(config_path : &path::PathBuf) -> JoshutoConfig
+{
+ // let mut config_file = fs::File::open(config_path).expect("No config found");
- ncurses::refresh();
+ let config_contents = fs::read_to_string(&config_path).unwrap();
- loop {
- let ch = ncurses::getch();
+/*
+ let mut config_contents = String::new();
+ config_file.read().read_to_string(&mut config_contents).expect("Error reading config file");
+*/
- match ch {
- QUIT => {
- break;
- }
- ncurses::KEY_RESIZE => {
- ncurses::getmaxyx(ncurses::stdscr(), &mut term_rows, &mut term_cols);
- top_win = ncurses::newwin(1, term_cols, 0, 0);
- mid_win = ncurses::newwin(term_rows - 2, term_cols / 7 * 3,
- term_cols / 7, 1);
- left_win = ncurses::newwin(term_rows - 2, term_cols / 7, 0, 1);
- right_win = ncurses::newwin(term_rows - 2, term_cols / 7 * 3,
- term_cols / 7 * 4, 1);
- ncurses::refresh();
- }
- ncurses::KEY_UP => {
- if index > 0 {
- index = index - 1;
- joshuto::win_print_select_file(right_win, &dir_contents[index], (term_rows - 1) as usize);
- }
- }
- ncurses::KEY_DOWN => {
- if index + 1 < dir_contents.len() {
- index = index + 1;
- joshuto::win_print_select_file(right_win, &dir_contents[index], (term_rows - 1) as usize);
- }
- }
- ncurses::KEY_LEFT => {
- match env::current_dir() {
- Ok(mut pathbuf) => {
- if pathbuf.eq(&path::Path::new("/")) {
- ncurses::wclear(left_win);
- ncurses::wrefresh(left_win);
- continue;
- }
- if pathbuf.pop() == false {
- continue;
- }
- match env::set_current_dir(&pathbuf) {
- Ok(_s) => {
- tmp_result = fs::read_dir(".").unwrap().collect();
- dir_contents = tmp_result.unwrap();
- dir_contents.sort_by(joshuto::alpha_sort);
- index = pindex;
- pindex = 0;
- if pathbuf.eq(&path::Path::new("/")) {
- ncurses::wclear(left_win);
- ncurses::wrefresh(left_win);
- } else {
- joshuto::win_print_curr_dir(top_win);
- joshuto::win_print_parent_dir(left_win, pindex, (term_rows - 1) as usize);
- }
- },
- Err(_e) => {
- ncurses::printw("None");
- },
- };
- }
- Err(e) => {
- println!("{}", e);
- }
- };
+ match toml::from_str(&config_contents) {
+ Ok(config) => {
+ config
+ },
+ Err(e) => {
+ println!("{}", e);
+ JoshutoConfig {
+ show_hidden: Some(false),
+ color_scheme: None,
+ sort_method: Some("Natural".to_string()),
+ keymaps: Some(JoshutoKeymaps {
+ up : 3,
+ }),
}
- ncurses::KEY_RIGHT => {
- match dir_contents[index as usize].file_type() {
- Ok(file_type) => {
- if file_type.is_dir() {
- let new_path : path::PathBuf = dir_contents[index as usize].path();
- match env::set_current_dir(new_path) {
- Ok(_s) => {
- tmp_result = fs::read_dir(".").unwrap().collect();
- dir_contents = tmp_result.unwrap();
- dir_contents.sort_by(joshuto::alpha_sort);
- pindex = index;
- index = 0;
+ }
+ }
+}
- joshuto::win_print_curr_dir(top_win);
- joshuto::win_print_parent_dir(left_win, pindex, (term_rows - 1) as usize);
- },
- Err(_e) => {
- ncurses::printw("None");
- },
- };
- }
- },
- Err(_e) => {
- ncurses::printw("None");
- },
- };
- }
- ENTER => {
- match dir_contents[index as usize].file_type() {
- Ok(file_type) => {
- if file_type.is_dir() {
- let new_path : path::PathBuf = dir_contents[index as usize].path();
- match env::set_current_dir(new_path) {
- Ok(_s) => {
- tmp_result = fs::read_dir(".").unwrap().collect();
- dir_contents = tmp_result.unwrap();
- dir_contents.sort_by(joshuto::alpha_sort);
- pindex = index;
- index = 0;
+fn main()
+{
+ let args: Vec<String> = env::args().collect();
+ println!("{:?}", args);
- joshuto::win_print_curr_dir(top_win);
- joshuto::win_print_parent_dir(left_win, pindex, (term_rows - 1) as usize);
- },
- Err(_e) => {
- ncurses::printw("None");
- },
- };
- }
- },
- Err(_e) => {
- ncurses::printw("None");
- },
- };
- }
- _ => {
- ncurses::wprintw(mid_win, format!("pressed: {}\n",
- std::char::from_u32(ch as u32).expect("Invalid char")).as_ref());
- }
- };
+ let config_path = get_config_path();
+ println!("{:?}", config_path);
+ let config = read_config(&config_path);
+ println!("{:#?}", config);
- joshuto::win_print_dir(mid_win, &dir_contents, index, (term_rows - 1) as usize);
- }
- ncurses::endwin();
+ joshuto::run();
}