1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-11 13:51:01 -05:00

Provide correct default for scroll_history

When implementing fallback to the default value with an u32 you will get
0 as the default value.

However the default scrollback value is 10_000. A custom deserializer
has been implemented which automatically falls back to the correct
default value.
This commit is contained in:
Christian Duerr 2018-03-09 17:57:24 +01:00 committed by Joe Wilm
parent dd60ea563d
commit 04086186a0

View file

@ -398,7 +398,7 @@ pub struct Config {
tabspaces: usize, tabspaces: usize,
/// How much scrolling history to keep /// How much scrolling history to keep
#[serde(default="default_scroll_history", deserialize_with="failure_default")] #[serde(default="default_scroll_history", deserialize_with="deserialize_scroll_history")]
scroll_history: u32, scroll_history: u32,
} }
@ -406,6 +406,18 @@ fn default_scroll_history() -> u32 {
10_000 10_000
} }
fn deserialize_scroll_history<'a, D>(deserializer: D) -> ::std::result::Result<u32, D::Error>
where D: de::Deserializer<'a>
{
match u32::deserialize(deserializer) {
Ok(lines) => Ok(lines),
Err(err) => {
eprintln!("problem with config: {}; Using default value", err);
Ok(default_scroll_history())
},
}
}
fn failure_default_vec<'a, D, T>(deserializer: D) -> ::std::result::Result<Vec<T>, D::Error> fn failure_default_vec<'a, D, T>(deserializer: D) -> ::std::result::Result<Vec<T>, D::Error>
where D: de::Deserializer<'a>, where D: de::Deserializer<'a>,
T: Deserialize<'a> T: Deserialize<'a>