aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthelearnerofcode <thelearnerofcode@users.noreply.github.com>2017-11-11 11:23:49 -0500
committerJoe Wilm <jwilm@users.noreply.github.com>2017-11-11 08:23:49 -0800
commitbdb360ed1d25fa42b3743723321be298e500519f (patch)
tree25f23fb6d215e50a4268307a43026e70cf63c136
parentf68558e9dcce97e0d4d842a2d5b62e31e4124210 (diff)
downloadalacritty-bdb360ed1d25fa42b3743723321be298e500519f.tar.gz
alacritty-bdb360ed1d25fa42b3743723321be298e500519f.zip
Support integer font size in config (#886)
Fixes #882
-rw-r--r--src/config.rs24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/config.rs b/src/config.rs
index 768b5579..4cde0f0a 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -1260,28 +1260,28 @@ impl Default for Delta {
}
}
-trait DeserializeFromF32 : Sized {
- fn deserialize_from_f32<'a, D>(D) -> ::std::result::Result<Self, D::Error>
+trait DeserializeSize : Sized {
+ fn deserialize<'a, D>(D) -> ::std::result::Result<Self, D::Error>
where D: serde::de::Deserializer<'a>;
}
-impl DeserializeFromF32 for Size {
- fn deserialize_from_f32<'a, D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
+impl DeserializeSize for Size {
+ fn deserialize<'a, D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where D: serde::de::Deserializer<'a>
{
use std::marker::PhantomData;
- struct FloatVisitor<__D> {
+ struct NumVisitor<__D> {
_marker: PhantomData<__D>,
}
- impl<'a, __D> Visitor<'a> for FloatVisitor<__D>
+ impl<'a, __D> Visitor<'a> for NumVisitor<__D>
where __D: serde::de::Deserializer<'a>
{
type Value = f64;
fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result {
- f.write_str("f64")
+ f.write_str("f64 or u64")
}
fn visit_f64<E>(self, value: f64) -> ::std::result::Result<Self::Value, E>
@@ -1289,10 +1289,16 @@ impl DeserializeFromF32 for Size {
{
Ok(value)
}
+
+ fn visit_u64<E>(self, value: u64) -> ::std::result::Result<Self::Value, E>
+ where E: ::serde::de::Error
+ {
+ Ok(value as f64)
+ }
}
deserializer
- .deserialize_f64(FloatVisitor::<D>{ _marker: PhantomData })
+ .deserialize_any(NumVisitor::<D>{ _marker: PhantomData })
.map(|v| Size::new(v as _))
}
}
@@ -1315,7 +1321,7 @@ pub struct Font {
pub bold: FontDescription,
// Font size in points
- #[serde(deserialize_with="DeserializeFromF32::deserialize_from_f32")]
+ #[serde(deserialize_with="DeserializeSize::deserialize")]
pub size: Size,
/// Extra spacing per character