mirror of
https://github.com/zellij-org/zellij.git
synced 2024-12-27 11:16:20 +03:00
Improve handling of empty valid yaml
files (#716)
Improves the way empty valid `yaml` files are handled. When deserializing a `config` or `layout` file, that is an empty valid `yaml` file, eg: ``` --- ``` We now assume the default configuration is desired.
This commit is contained in:
parent
b42ce60348
commit
2771b247ac
@ -99,17 +99,22 @@ impl TryFrom<&CliArgs> for Config {
|
|||||||
impl Config {
|
impl Config {
|
||||||
/// Uses defaults, but lets config override them.
|
/// Uses defaults, but lets config override them.
|
||||||
pub fn from_yaml(yaml_config: &str) -> ConfigResult {
|
pub fn from_yaml(yaml_config: &str) -> ConfigResult {
|
||||||
let config_from_yaml: ConfigFromYaml = serde_yaml::from_str(yaml_config)?;
|
let config_from_yaml: Option<ConfigFromYaml> = serde_yaml::from_str(yaml_config)?;
|
||||||
let keybinds = Keybinds::get_default_keybinds_with_config(config_from_yaml.keybinds);
|
|
||||||
let options = Options::from_yaml(config_from_yaml.options);
|
|
||||||
let themes = config_from_yaml.themes;
|
|
||||||
|
|
||||||
|
match config_from_yaml {
|
||||||
|
None => Ok(Config::default()),
|
||||||
|
Some(config) => {
|
||||||
|
let keybinds = Keybinds::get_default_keybinds_with_config(config.keybinds);
|
||||||
|
let options = Options::from_yaml(config.options);
|
||||||
|
let themes = config.themes;
|
||||||
Ok(Config {
|
Ok(Config {
|
||||||
keybinds,
|
keybinds,
|
||||||
options,
|
options,
|
||||||
themes,
|
themes,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Deserializes from given path.
|
/// Deserializes from given path.
|
||||||
pub fn new(path: &Path) -> ConfigResult {
|
pub fn new(path: &Path) -> ConfigResult {
|
||||||
|
@ -103,9 +103,12 @@ impl LayoutFromYaml {
|
|||||||
|
|
||||||
let mut layout = String::new();
|
let mut layout = String::new();
|
||||||
layout_file.read_to_string(&mut layout)?;
|
layout_file.read_to_string(&mut layout)?;
|
||||||
let layout: LayoutFromYaml = serde_yaml::from_str(&layout)?;
|
let layout: Option<LayoutFromYaml> = serde_yaml::from_str(&layout)?;
|
||||||
|
|
||||||
Ok(layout)
|
match layout {
|
||||||
|
Some(layout) => Ok(layout),
|
||||||
|
None => Ok(LayoutFromYaml::default()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// It wants to use Path here, but that doesn't compile.
|
// It wants to use Path here, but that doesn't compile.
|
||||||
|
Loading…
Reference in New Issue
Block a user