diff options
author | Canop <cano.petrole@gmail.com> | 2020-10-07 18:38:07 +0200 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2020-10-07 18:38:07 +0200 |
commit | 4b6a90a86d62902bb2795b5b721635fdaa87faa5 (patch) | |
tree | d01a6d18389f42e02aebb8458c8a0ef5e682489f /src/conf/conf.rs | |
parent | 53e07a4ebb94ae613b552af1d6e3d0ff7ee5cdff (diff) |
change the syntax of `cols_order` in conf
Diffstat (limited to 'src/conf/conf.rs')
-rw-r--r-- | src/conf/conf.rs | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/conf/conf.rs b/src/conf/conf.rs index 8c34d2b..9a36b58 100644 --- a/src/conf/conf.rs +++ b/src/conf/conf.rs @@ -87,7 +87,12 @@ impl Conf { /// (i.e. this function is called before or after the terminal alternation) pub fn read_file(&mut self, filepath: &Path) -> Result<(), ConfError> { let data = fs::read_to_string(filepath)?; - let root: Value = data.parse::<Value>()?; + let root: toml::value::Table = match data.parse::<Value>()? { + Value::Table(tbl) => tbl, + _ => { + return Err(ConfError::Invalid {}); + } + }; // reading default flags if let Some(s) = string_field(&root, "default_flags") { // it's additive because another config file may have @@ -104,9 +109,15 @@ impl Conf { self.disable_mouse_capture = !mouse_capture; } // cols order - self.cols_order = string_field(&root, "cols_order") - .map(|s| Col::parse_cols(&s)) - .transpose()?; + if let Some(s) = string_field(&root, "cols_order") { + // old format, with each char being a col, for example + // `cols_order = "gbpdscn"` + self.cols_order = Some(Col::parse_cols_single_str(&s)?); + } else if let Some(arr) = string_array_field(&root, "cols_order") { + // new format, where each col is a string, for example + // `cols_order = ["branch", "size" ..., "name"]` + self.cols_order = Some(Col::parse_cols(&arr)?); + } // reading verbs if let Some(Value::Array(verbs_value)) = &root.get("verbs") { for verb_value in verbs_value.iter() { |