aboutsummaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2016-11-19 16:16:20 -0800
committerJoe Wilm <joe@jwilm.com>2016-11-19 21:34:11 -0800
commit66dbd29cd194a4c84f796f32827429895c2a3bba (patch)
tree5f5322cdae53d4fc295fe85f519192e9d38aab03 /src/config.rs
parentd97996e19de6856c23c51d05ec10f10db41e309d (diff)
downloadalacritty-66dbd29cd194a4c84f796f32827429895c2a3bba.tar.gz
alacritty-66dbd29cd194a4c84f796f32827429895c2a3bba.zip
Add support for recording/running ref tests
Ref tests use a recording of the terminal protocol and a serialization of the grid state to check that the parsing and action handling systems produce the correct result. Ref tests may be recorded by running alacritty with `--ref-test` and closing the terminal by using the window "X" button. At that point, the recording is fully written to disk, and a serialization of important state is recorded. Those files should be moved to an appropriate folder in the `tests/ref/` tree, and the `ref_test!` macro invocation should be updated accordingly. A couple of changes were necessary to make this work: * Ref tests shouldn't create a pty; the pty was refactored out of the `Term` type. * Repeatable lines/cols were needed; on startup, the terminal is resized * by default to 80x24 though that may be changed by passing `--dimensions w h`. * Calculating window size based on desired rows/columns and font metrics required making load_font callable multiple times. * Refactor types into library crate so they may be imported in an integration test. * A whole bunch of types needed symmetric serialization and deserialization. Mostly this was just adding derives, but the custom deserialization of Rgb had to change to a deserialize_with function. This initially adds one ref test as a sanity check, and more will be added in subsequent commits. This initial ref tests just starts the terminal and runs `ll`.
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs54
1 files changed, 28 insertions, 26 deletions
diff --git a/src/config.rs b/src/config.rs
index b315fb86..704c4237 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -463,7 +463,9 @@ pub struct Colors {
#[derive(Debug, Deserialize)]
pub struct PrimaryColors {
+ #[serde(deserialize_with = "rgb_from_hex")]
background: Rgb,
+ #[serde(deserialize_with = "rgb_from_hex")]
foreground: Rgb,
}
@@ -501,45 +503,45 @@ impl Default for Colors {
/// The normal or bright colors section of config
#[derive(Debug, Deserialize)]
pub struct AnsiColors {
+ #[serde(deserialize_with = "rgb_from_hex")]
black: Rgb,
+ #[serde(deserialize_with = "rgb_from_hex")]
red: Rgb,
+ #[serde(deserialize_with = "rgb_from_hex")]
green: Rgb,
+ #[serde(deserialize_with = "rgb_from_hex")]
yellow: Rgb,
+ #[serde(deserialize_with = "rgb_from_hex")]
blue: Rgb,
+ #[serde(deserialize_with = "rgb_from_hex")]
magenta: Rgb,
+ #[serde(deserialize_with = "rgb_from_hex")]
cyan: Rgb,
+ #[serde(deserialize_with = "rgb_from_hex")]
white: Rgb,
}
-impl serde::de::Deserialize for Rgb {
- fn deserialize<D>(deserializer: &mut D) -> ::std::result::Result<Self, D::Error>
- where D: serde::de::Deserializer
- {
- use std::marker::PhantomData;
-
- struct StringVisitor<__D> {
- _marker: PhantomData<__D>,
- }
-
- impl<__D> ::serde::de::Visitor for StringVisitor<__D>
- where __D: ::serde::de::Deserializer
+/// Deserialize an Rgb from a hex string
+///
+/// This is *not* the deserialize impl for Rgb since we want a symmetric
+/// serialize/deserialize impl for ref tests.
+fn rgb_from_hex<D>(deserializer: &mut D) -> ::std::result::Result<Rgb, D::Error>
+ where D: de::Deserializer
+{
+ struct RgbVisitor;
+
+ impl ::serde::de::Visitor for RgbVisitor {
+ type Value = Rgb;
+
+ fn visit_str<E>(&mut self, value: &str) -> ::std::result::Result<Rgb, E>
+ where E: ::serde::de::Error
{
- type Value = String;
-
- fn visit_str<E>(&mut self, value: &str) -> ::std::result::Result<Self::Value, E>
- where E: ::serde::de::Error
- {
- Ok(value.to_owned())
- }
+ Rgb::from_str(&value[..])
+ .map_err(|_| E::custom("failed to parse rgb; expect 0xrrggbb"))
}
-
- deserializer
- .deserialize_f64(StringVisitor::<D>{ _marker: PhantomData })
- .and_then(|v| {
- Rgb::from_str(&v[..])
- .map_err(|_| D::Error::custom("failed to parse rgb; expect 0xrrggbb"))
- })
}
+
+ deserializer.deserialize_str(RgbVisitor)
}
impl Rgb {