summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2019-01-06 17:30:36 -0500
committerJiayi Zhao <jeff.no.zhao@gmail.com>2019-01-06 17:32:01 -0500
commitd10175338a7ab05b6bc786d4e0fc3723bad68a59 (patch)
tree7dece31fe47c827e5ab25e7bfb38ab85a01506b5
parentc5e78328ddcc23ebfe6c08cb444477ac3f489fdf (diff)
move configuration code into config/ folder
- change sort related configuration into its own []
-rw-r--r--config/joshuto.toml9
-rw-r--r--config/keymap.toml10
-rw-r--r--config/mimetype.toml3
-rw-r--r--src/joshuto.rs14
-rw-r--r--src/joshuto/command/file_operation.rs2
-rw-r--r--src/joshuto/command/open_file.rs2
-rw-r--r--src/joshuto/config.rs165
-rw-r--r--src/joshuto/config/config.rs173
-rw-r--r--src/joshuto/config/keymap.rs (renamed from src/joshuto/keymap.rs)0
-rw-r--r--src/joshuto/config/mimetype.rs (renamed from src/joshuto/mimetype.rs)0
-rw-r--r--src/joshuto/config/theme.rs (renamed from src/joshuto/theme.rs)0
-rw-r--r--src/joshuto/input.rs4
-rw-r--r--src/joshuto/sort.rs26
-rw-r--r--src/joshuto/ui.rs2
-rw-r--r--src/main.rs8
15 files changed, 229 insertions, 189 deletions
diff --git a/config/joshuto.toml b/config/joshuto.toml
index 9cd7c1a..7d0124c 100644
--- a/config/joshuto.toml
+++ b/config/joshuto.toml
@@ -1,12 +1,13 @@
# sort_type options: size, natural, basename, atime, ctime, mtime, type, random
## currently only supports: natural, mtime
sort_type = "natural"
-sort_case_sensitive = false
-sort_reverse = false
-sort_directories_first = true
-# show hidden files
+[sort_option]
show_hidden = false
+case_sensitive = false
+reverse = false
+directories_first = true
+
show_prerview = true
diff --git a/config/keymap.toml b/config/keymap.toml
index 4bc64da..6a0050e 100644
--- a/config/keymap.toml
+++ b/config/keymap.toml
@@ -106,6 +106,16 @@ command = "mkdir"
[[mapcommand]]
+keys = [ "g", "d" ]
+command = "cd"
+args = [ "~/Downloads" ]
+
+[[mapcommand]]
+keys = [ "g", "h" ]
+command = "cd"
+args = [ "~/" ]
+
+[[mapcommand]]
keys = [ "g", "r" ]
command = "cd"
args = [ "/" ]
diff --git a/config/mimetype.toml b/config/mimetype.toml
index c6eb19c..2a6e3e3 100644
--- a/config/mimetype.toml
+++ b/config/mimetype.toml
@@ -47,6 +47,9 @@
["nano"]
]
+"audio/flac" = [
+ [ "mpv" ]
+]
"audio/x-wav" = [
[ "mpv" ]
]
diff --git a/src/joshuto.rs b/src/joshuto.rs
index 73a9673..2bd2825 100644
--- a/src/joshuto.rs
+++ b/src/joshuto.rs
@@ -11,9 +11,7 @@ use std::thread;
use std::time;
pub mod config;
-pub mod keymap;
-pub mod mimetype;
-pub mod theme;
+
mod command;
mod history;
mod input;
@@ -37,13 +35,13 @@ pub struct JoshutoContext<'a> {
pub preview_list: Option<structs::JoshutoDirList>,
pub config_t: config::JoshutoConfig,
- pub mimetype_t: &'a mimetype::JoshutoMimetype,
+ pub mimetype_t: &'a config::JoshutoMimetype,
}
impl<'a> JoshutoContext<'a> {
pub fn new(config_t: &config::JoshutoConfig,
- mimetype_t: &'a mimetype::JoshutoMimetype) -> Self
+ mimetype_t: &'a config::JoshutoMimetype) -> Self
{
let curr_path: path::PathBuf = match env::current_dir() {
Ok(path) => { path },
@@ -199,7 +197,7 @@ fn recurse_get_keycommand<'a>(keymap: &'a HashMap<i32, CommandKeybind>)
ncurses::update_panels();
ncurses::doupdate();
- if ch == keymap::ESCAPE {
+ if ch == config::keymap::ESCAPE {
None
} else {
match keymap.get(&ch) {
@@ -232,8 +230,8 @@ pub fn resize_handler(context: &mut JoshutoContext)
}
pub fn run(config_t: config::JoshutoConfig,
- keymap_t: keymap::JoshutoKeymap,
- mimetype_t: mimetype::JoshutoMimetype)
+ keymap_t: config::JoshutoKeymap,
+ mimetype_t: config::JoshutoMimetype)
{
ui::init_ncurses();
diff --git a/src/joshuto/command/file_operation.rs b/src/joshuto/command/file_operation.rs
index 4cad0f0..e56788b 100644
--- a/src/joshuto/command/file_operation.rs
+++ b/src/joshuto/command/file_operation.rs
@@ -12,7 +12,7 @@ use std::thread;
use joshuto;
use joshuto::command;
use joshuto::input;
-use joshuto::keymap;
+use joshuto::config::keymap;
use joshuto::structs;
use joshuto::ui;
use joshuto::window;
diff --git a/src/joshuto/command/open_file.rs b/src/joshuto/command/open_file.rs
index 0489b89..26ef400 100644
--- a/src/joshuto/command/open_file.rs
+++ b/src/joshuto/command/open_file.rs
@@ -10,7 +10,7 @@ use std::path;
use joshuto;
use joshuto::command;
use joshuto::input;
-use joshuto::mimetype;
+use joshuto::config::mimetype;
use joshuto::structs;
use joshuto::ui;
use joshuto::unix;
diff --git a/src/joshuto/config.rs b/src/joshuto/config.rs
index 5545013..1ef10fb 100644
--- a/src/joshuto/config.rs
+++ b/src/joshuto/config.rs
@@ -1,156 +1,9 @@
-extern crate whoami;
-extern crate toml;
-extern crate xdg;
-
-use std::fs;
-use std::process;
-
-use joshuto;
-use joshuto::sort;
-
-#[derive(Debug, Deserialize)]
-pub struct JoshutoRawConfig {
- scroll_offset: Option<usize>,
- show_hidden: Option<bool>,
- sort_type: Option<String>,
- sort_directories_first: Option<bool>,
- sort_reverse: Option<bool>,
- sort_case_sensitive: Option<bool>,
- column_ratio: Option<[usize; 3]>,
-}
-
-impl JoshutoRawConfig {
- #[allow(dead_code)]
- pub fn new() -> Self
- {
- JoshutoRawConfig {
- scroll_offset: Some(8),
- show_hidden: Some(false),
- sort_type: Some(String::from("natural")),
- sort_directories_first: None,
- sort_reverse: None,
- sort_case_sensitive: None,
- column_ratio: Some([1, 3, 4]),
- }
- }
-
- pub fn flatten(self) -> JoshutoConfig
- {
- let username : String = whoami::username();
- let hostname : String = whoami::hostname();
-
- let column_ratio = match self.column_ratio {
- Some(s) => (s[0], s[1], s[2]),
- None => (1, 3, 4),
- };
-
- let scroll_offset: usize = self.scroll_offset.unwrap_or(6);
-
- let show_hidden: bool = self.show_hidden.unwrap_or(false);
- let sort_case_sensitive: bool = self.sort_case_sensitive.unwrap_or(false);
- let sort_reverse: bool = self.sort_reverse.unwrap_or(false);
- let sort_directories_first: bool = self.sort_directories_first.unwrap_or(true);
-
- let sort_struct = sort::SortStruct {
- show_hidden,
- sort_directories_first,
- sort_case_sensitive,
- sort_reverse,
- };
-
- let sort_type: sort::SortType = match self.sort_type {
- Some(s) => {
- match s.as_str() {
- "natural" => sort::SortType::SortNatural(sort_struct),
- "mtime" => sort::SortType::SortMtime(sort_struct),
- _ => sort::SortType::SortNatural(sort_struct),
- }
- }
- _ => sort::SortType::SortNatural(sort_struct),
- };
-
- JoshutoConfig {
- username,
- hostname,
- scroll_offset,
- sort_type,
- column_ratio,
- }
- }
-}
-
-#[derive(Debug, Clone)]
-pub struct JoshutoConfig {
- pub username: String,
- pub hostname: String,
- pub scroll_offset: usize,
- pub sort_type: joshuto::sort::SortType,
- pub column_ratio: (usize, usize, usize),
-}
-
-impl JoshutoConfig {
-
- pub fn new() -> Self
- {
- let sort_struct = sort::SortStruct {
- show_hidden: false,
- sort_directories_first: true,
- sort_case_sensitive: false,
- sort_reverse: false,
- };
- let sort_type = sort::SortType::SortNatural(sort_struct);
-
- let username : String = whoami::username();
- let hostname : String = whoami::hostname();
-
- JoshutoConfig {
- username,
- hostname,
- scroll_offset: 6,
- sort_type,
- column_ratio: (1, 3, 4),
- }
- }
-
- fn read_config() -> Option<JoshutoRawConfig>
- {
- match xdg::BaseDirectories::with_profile(::PROGRAM_NAME, "") {
- Ok(dirs) => {
- let config_path = dirs.find_config_file(::CONFIG_FILE)?;
- match fs::read_to_string(&config_path) {
- Ok(config_contents) => {
- match toml::from_str(&config_contents) {
- Ok(config) => {
- Some(config)
- },
- Err(e) => {
- eprintln!("{}", e);
- process::exit(1);
- },
- }
- },
- Err(e) => {
- eprintln!("{}", e);
- None
- },
- }
- },
- Err(e) => {
- eprintln!("{}", e);
- None
- },
- }
- }
-
- pub fn get_config() -> Self
- {
- match Self::read_config() {
- Some(config) => {
- config.flatten()
- }
- None => {
- JoshutoConfig::new()
- }
- }
- }
-}
+pub mod config;
+pub mod keymap;
+pub mod mimetype;
+pub mod theme;
+
+pub use self::config::JoshutoConfig;
+pub use self::keymap::JoshutoKeymap;
+pub use self::mimetype::JoshutoMimetype;
+pub use self::theme::JoshutoTheme;
diff --git a/src/joshuto/config/config.rs b/src/joshuto/config/config.rs
new file mode 100644
index 0000000..406d126
--- /dev/null
+++ b/src/joshuto/config/config.rs
@@ -0,0 +1,173 @@
+extern crate whoami;
+extern crate toml;
+extern crate xdg;
+
+use std::fs;
+use std::process;
+
+use joshuto;
+use joshuto::sort;
+
+#[derive(Clone, Debug, Deserialize)]
+pub struct SortRawOption {
+ pub show_hidden: Option<bool>,
+ pub directories_first: Option<bool>,
+ pub case_sensitive: Option<bool>,
+ pub reverse: Option<bool>,
+}
+
+#[derive(Clone, Debug, Deserialize)]
+pub struct JoshutoRawConfig {
+ scroll_offset: Option<usize>,
+ sort_type: Option<String>,
+ sort_option: Option<SortRawOption>,
+ column_ratio: Option<[usize; 3]>,
+}
+
+impl JoshutoRawConfig {
+ #[allow(dead_code)]
+ pub fn new() -> Self
+ {
+ JoshutoRawConfig {
+ scroll_offset: Some(8),
+ sort_type: Some(String::from("natural")),
+ sort_option: None,
+ column_ratio: Some([1, 3, 4]),
+ }
+ }
+
+ pub fn flatten(self) -> JoshutoConfig
+ {
+ let username : String = whoami::username();
+ let hostname : String = whoami::hostname();
+
+ let column_ratio = match self.column_ratio {
+ Some(s) => (s[0], s[1], s[2]),
+ None => (1, 3, 4),
+ };
+
+ let scroll_offset: usize = self.scroll_offset.unwrap_or(6);
+
+ let show_hidden: bool;
+ let case_sensitive: bool;
+ let reverse: bool;
+ let directories_first: bool;
+
+ match self.sort_option {
+ Some(s) => {
+ show_hidden = s.show_hidden.unwrap_or(false);
+ case_sensitive = s.case_sensitive.unwrap_or(false);
+ reverse = s.reverse.unwrap_or(false);
+ directories_first = s.directories_first.unwrap_or(true);
+ }
+ None => {
+ show_hidden = false;
+ case_sensitive = false;
+ reverse = false;
+ directories_first = true;
+ }
+ }
+
+ let sort_option = sort::SortOption {
+ show_hidden,
+ directories_first,
+ case_sensitive,
+ reverse,
+ };
+
+ let sort_type: sort::SortType = match self.sort_type {
+ Some(s) => {
+ match s.as_str() {
+ "natural" => sort::SortType::SortNatural(sort_option),
+ "mtime" => sort::SortType::SortMtime(sort_option),
+ _ => sort::SortType::SortNatural(sort_option),
+ }
+ }
+ _ => sort::SortType::SortNatural(sort_option),
+ };
+
+ JoshutoConfig {
+ username,
+ hostname,
+ scroll_offset,
+ sort_type,
+ column_ratio,
+ }
+ }
+}
+
+#[derive(Debug, Clone)]
+pub struct JoshutoConfig {
+ pub username: String,
+ pub hostname: String,
+ pub scroll_offset: usize,
+ pub sort_type: joshuto::sort::SortType,
+ pub column_ratio: (usize, usize, usize),
+}
+
+impl JoshutoConfig {
+
+ pub fn new() -> Self
+ {
+ let sort_option = sort::SortOption {
+ show_hidden: false,
+ directories_first: true,
+ case_sensitive: false,
+ reverse: false,
+ };
+ let sort_type = sort::SortType::SortNatural(sort_option);
+
+ let username : String = whoami::username();
+ let hostname : String = whoami::hostname();
+
+ JoshutoConfig {
+ username,
+ hostname,
+ scroll_offset: 6,
+ sort_type,
+ column_ratio: (1, 3, 4),
+ }
+ }
+
+ fn read_config() -> Option<JoshutoRawConfig>
+ {
+ match xdg::BaseDirectories::with_profile(::PROGRAM_NAME, "") {
+ Ok(dirs) => {
+ let config_path = dirs.find_config_file(::CONFIG_FILE)?;
+ match fs::read_to_string(&config_path) {
+ Ok(config_contents) => {
+ match toml::from_str(&config_contents) {
+ Ok(config) => {
+ Some(config)
+ },
+ Err(e) => {
+ eprintln!("{}", e);
+ process::exit(1);
+ },
+ }
+ },
+ Err(e) => {
+ eprintln!("{}", e);
+ None
+ },
+ }
+ },
+ Err(e) => {
+ eprintln!("{}", e);
+ None
+ },
+ }
+ }
+
+ pub fn get_config() -> Self
+ {
+ match Self::read_config() {
+ Some(config) => {
+ config.flatten()
+ }
+ None => {
+ JoshutoConfig::new()
+ }
+ }
+ }
+}
diff --git a/src/joshuto/keymap.rs b/src/joshuto/config/keymap.rs
index 96357da..96357da 100644
--- a/src/joshuto/keymap.rs
+++ b/src/joshuto/config/keymap.rs
diff --git a/src/joshuto/mimetype.rs b/src/joshuto/config/mimetype.rs
index 5520791..5520791 100644
--- a/src/joshuto/mimetype.rs
+++ b/src/joshuto/config/mimetype.rs
diff --git a/src/joshuto/theme.rs b/src/joshuto/config/theme.rs
index cf15d4a..cf15d4a 100644
--- a/src/joshuto/theme.rs
+++ b/src/joshuto/config/theme.rs
diff --git a/src/joshuto/input.rs b/src/joshuto/input.rs
index 4c35261..a132544 100644
--- a/src/joshuto/input.rs
+++ b/src/joshuto/input.rs
@@ -4,9 +4,9 @@ extern crate wcwidth;
use std::collections::HashMap;
use joshuto::command;
-use joshuto::keymap;
+use joshuto::config::keymap;
use joshuto::window;
-use joshuto::keymap::*;
+use joshuto::config::keymap::*;
pub fn get_str(win: &window::JoshutoPanel,
coord: (i32, i32)) -> Option<String>
diff --git a/src/joshuto/sort.rs b/src/joshuto/sort.rs
index 58dd226..8c2ece8 100644
--- a/src/joshuto/sort.rs
+++ b/src/joshuto/sort.rs
@@ -6,9 +6,17 @@ use std::time;
use joshuto::structs;
#[derive(Debug, Clone)]
+pub struct SortOption {
+ pub show_hidden: bool,
+ pub directories_first: bool,
+ pub case_sensitive: bool,
+ pub reverse: bool,
+}
+
+#[derive(Debug, Clone)]
pub enum SortType {
- SortNatural(SortStruct),
- SortMtime(SortStruct),
+ SortNatural(SortOption),
+ SortMtime(SortOption),
}
impl SortType {
@@ -16,16 +24,16 @@ impl SortType {
{
match *self {
SortType::SortNatural(ref ss) => {
- if ss.sort_directories_first && !ss.sort_case_sensitive && !ss.sort_reverse {
+ if ss.directories_first && !ss.case_sensitive && !ss.reverse {
SortNatural::dir_first_case_insensitive
- } else if ss.sort_directories_first && ss.sort_case_sensitive && !ss.sort_reverse {
+ } else if ss.directories_first && ss.case_sensitive && !ss.reverse {
SortNatural::dir_first
} else {
SortNatural::default_sort
}
}
SortType::SortMtime(ref ss) => {
- if ss.sort_directories_first && !ss.sort_reverse {
+ if ss.directories_first && !ss.reverse {
SortMtime::dir_first
} else {
SortMtime::default_sort
@@ -79,14 +87,6 @@ impl SortType {
}
}
-#[derive(Debug, Clone)]
-pub struct SortStruct {
- pub show_hidden: bool,
- pub sort_directories_first: bool,
- pub sort_case_sensitive: bool,
- pub sort_reverse: bool,
-}
-
fn filter_default(result : Result<fs::DirEntry, std::io::Error>) -> Option<structs::JoshutoDirEntry>
{
match result {
diff --git a/src/joshuto/ui.rs b/src/joshuto/ui.rs
index 679a2d5..d63bdf6 100644
--- a/src/joshuto/ui.rs
+++ b/src/joshuto/ui.rs
@@ -5,7 +5,7 @@ use std::fs;
use std::path;
use joshuto::structs;
-use joshuto::theme;
+use joshuto::config::theme;
use joshuto::unix;
use joshuto::window;
diff --git a/src/main.rs b/src/main.rs
index ef347c0..750fd3d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -29,12 +29,14 @@ fn main()
}
let config = joshuto::config::JoshutoConfig::get_config();
- let mimetype = joshuto::mimetype::JoshutoMimetype::get_config();
- let keymap = joshuto::keymap::JoshutoKeymap::get_config();
+// println!("{:#?}", config);
+
+ let mimetype = joshuto::config::JoshutoMimetype::get_config();
+ let keymap = joshuto::config::JoshutoKeymap::get_config();
// println!("{:#?}", keymap);
// println!("{:#?}", keymap.keymaps);
- let theme = joshuto::theme::JoshutoTheme::get_config();
+ let theme = joshuto::config::JoshutoTheme::get_config();
// println!("{:#?}", theme);
joshuto::run(config, keymap, mimetype);