summaryrefslogtreecommitdiffstats
path: root/src/config
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2019-04-22 20:52:17 -0400
committerJiayi Zhao <jeff.no.zhao@gmail.com>2019-04-22 20:52:17 -0400
commit4e81c3c76cd8c04aa2cf912c09817ca75dd27183 (patch)
tree6bf6d732cacf1cf9b0920a822187edb1c1e971fa /src/config
parent043a118903e4f7981c4e6c1193406de798c1d9e6 (diff)
code cleanup and implement std::default::Default
Diffstat (limited to 'src/config')
-rw-r--r--src/config/config.rs27
-rw-r--r--src/config/keymap.rs22
-rw-r--r--src/config/mimetype.rs24
-rw-r--r--src/config/theme.rs14
4 files changed, 34 insertions, 53 deletions
diff --git a/src/config/config.rs b/src/config/config.rs
index eecefb3..4de38a6 100644
--- a/src/config/config.rs
+++ b/src/config/config.rs
@@ -22,19 +22,6 @@ pub struct JoshutoRawConfig {
column_ratio: Option<[usize; 3]>,
}
-impl JoshutoRawConfig {
- #[allow(dead_code)]
- pub fn new() -> Self {
- JoshutoRawConfig {
- scroll_offset: None,
- tilde_in_titlebar: None,
- sort_method: None,
- sort_option: None,
- column_ratio: None,
- }
- }
-}
-
impl Flattenable<JoshutoConfig> for JoshutoRawConfig {
fn flatten(self) -> JoshutoConfig {
let column_ratio = match self.column_ratio {
@@ -99,7 +86,14 @@ pub struct JoshutoConfig {
}
impl JoshutoConfig {
- pub fn new() -> Self {
+ pub fn get_config() -> JoshutoConfig {
+ parse_config_file::<JoshutoRawConfig, JoshutoConfig>(CONFIG_FILE)
+ .unwrap_or_else(JoshutoConfig::default)
+ }
+}
+
+impl std::default::Default for JoshutoConfig {
+ fn default() -> Self {
let sort_option = sort::SortOption {
show_hidden: false,
directories_first: true,
@@ -115,9 +109,4 @@ impl JoshutoConfig {
column_ratio: (1, 3, 4),
}
}
-
- pub fn get_config() -> JoshutoConfig {
- parse_config_file::<JoshutoRawConfig, JoshutoConfig>(CONFIG_FILE)
- .unwrap_or_else(JoshutoConfig::new)
- }
}
diff --git a/src/config/keymap.rs b/src/config/keymap.rs
index 4b44b2d..9fb2e7d 100644
--- a/src/config/keymap.rs
+++ b/src/config/keymap.rs
@@ -32,12 +32,8 @@ impl Flattenable<JoshutoKeymap> for JoshutoRawKeymap {
if let Some(maps) = self.mapcommand {
for mapcommand in maps {
match commands::from_args(mapcommand.command.as_str(), mapcommand.args.as_ref()) {
- Some(command) => {
- insert_keycommand(&mut keymaps, command, &mapcommand.keys[..]);
- }
- None => {
- eprintln!("Unknown command: {}", mapcommand.command);
- }
+ Some(command) => insert_keycommand(&mut keymaps, command, &mapcommand.keys[..]),
+ None => eprintln!("Unknown command: {}", mapcommand.command),
}
}
}
@@ -51,14 +47,16 @@ pub struct JoshutoKeymap {
}
impl JoshutoKeymap {
- pub fn new() -> Self {
- let keymaps = HashMap::new();
- JoshutoKeymap { keymaps }
- }
-
pub fn get_config() -> JoshutoKeymap {
parse_config_file::<JoshutoRawKeymap, JoshutoKeymap>(KEYMAP_FILE)
- .unwrap_or_else(JoshutoKeymap::new)
+ .unwrap_or_else(JoshutoKeymap::default)
+ }
+}
+
+impl std::default::Default for JoshutoKeymap {
+ fn default() -> Self {
+ let keymaps = HashMap::new();
+ JoshutoKeymap { keymaps }
}
}
diff --git a/src/config/mimetype.rs b/src/config/mimetype.rs
index 8c730c0..bdcf765 100644
--- a/src/config/mimetype.rs
+++ b/src/config/mimetype.rs
@@ -42,16 +42,6 @@ pub struct JoshutoRawMimetype {
extension: Option<HashMap<String, Vec<JoshutoMimetypeEntry>>>,
}
-impl JoshutoRawMimetype {
- #[allow(dead_code)]
- pub fn new() -> Self {
- JoshutoRawMimetype {
- mimetype: None,
- extension: None,
- }
- }
-}
-
impl Flattenable<JoshutoMimetype> for JoshutoRawMimetype {
fn flatten(self) -> JoshutoMimetype {
let mimetype = self.mimetype.unwrap_or_default();
@@ -71,15 +61,17 @@ pub struct JoshutoMimetype {
}
impl JoshutoMimetype {
- pub fn new() -> Self {
+ pub fn get_config() -> JoshutoMimetype {
+ parse_config_file::<JoshutoRawMimetype, JoshutoMimetype>(MIMETYPE_FILE)
+ .unwrap_or_else(JoshutoMimetype::default)
+ }
+}
+
+impl std::default::Default for JoshutoMimetype {
+ fn default() -> Self {
JoshutoMimetype {
mimetype: HashMap::new(),
extension: HashMap::new(),
}
}
-
- pub fn get_config() -> JoshutoMimetype {
- parse_config_file::<JoshutoRawMimetype, JoshutoMimetype>(MIMETYPE_FILE)
- .unwrap_or_else(JoshutoMimetype::new)
- }
}
diff --git a/src/config/theme.rs b/src/config/theme.rs
index 31ccbdc..5de537c 100644
--- a/src/config/theme.rs
+++ b/src/config/theme.rs
@@ -153,7 +153,14 @@ pub struct JoshutoTheme {
}
impl JoshutoTheme {
- pub fn new() -> Self {
+ pub fn get_config() -> JoshutoTheme {
+ parse_config_file::<JoshutoRawTheme, JoshutoTheme>(crate::THEME_FILE)
+ .unwrap_or_else(JoshutoTheme::default)
+ }
+}
+
+impl std::default::Default for JoshutoTheme {
+ fn default() -> Self {
let mut colorpair: Vec<JoshutoColorPair> = Vec::with_capacity(10);
colorpair.push(JoshutoColorPair::new(2, 2, -1));
colorpair.push(JoshutoColorPair::new(3, 3, -1));
@@ -220,9 +227,4 @@ impl JoshutoTheme {
ext: HashMap::new(),
}
}
-
- pub fn get_config() -> JoshutoTheme {
- parse_config_file::<JoshutoRawTheme, JoshutoTheme>(crate::THEME_FILE)
- .unwrap_or_else(JoshutoTheme::new)
- }
}