diff options
author | Joe Wilm <joe@jwilm.com> | 2016-11-19 16:16:20 -0800 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2016-11-19 21:34:11 -0800 |
commit | 66dbd29cd194a4c84f796f32827429895c2a3bba (patch) | |
tree | 5f5322cdae53d4fc295fe85f519192e9d38aab03 /font | |
parent | d97996e19de6856c23c51d05ec10f10db41e309d (diff) | |
download | alacritty-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 'font')
-rw-r--r-- | font/src/darwin/mod.rs | 21 | ||||
-rw-r--r-- | font/src/ft/mod.rs | 17 |
2 files changed, 27 insertions, 11 deletions
diff --git a/font/src/darwin/mod.rs b/font/src/darwin/mod.rs index 4db8dad1..1b295801 100644 --- a/font/src/darwin/mod.rs +++ b/font/src/darwin/mod.rs @@ -75,6 +75,7 @@ pub struct Descriptor { /// Given a fontdesc, can rasterize fonts. pub struct Rasterizer { fonts: HashMap<FontKey, Font>, + keys: HashMap<(FontDesc, Size), FontKey>, device_pixel_ratio: f32, } @@ -83,6 +84,7 @@ impl Rasterizer { println!("device_pixel_ratio: {}", device_pixel_ratio); Rasterizer { fonts: HashMap::new(), + keys: HashMap::new(), device_pixel_ratio: device_pixel_ratio, } } @@ -100,12 +102,19 @@ impl Rasterizer { } pub fn load_font(&mut self, desc: &FontDesc, size: Size) -> Option<FontKey> { - self.get_font(desc, size) - .map(|font| { - let key = FontKey::next(); - self.fonts.insert(key, font); - - key + self.keys + .get(&(desc.to_owned(), size)) + .map(|k| *k) + .or_else(|| { + self.get_font(desc, size) + .map(|font| { + let key = FontKey::next(); + + self.fonts.insert(key, font); + self.keys.insert((desc.clone(), size), key); + + key + }) }) } diff --git a/font/src/ft/mod.rs b/font/src/ft/mod.rs index 55829e12..fa4325a0 100644 --- a/font/src/ft/mod.rs +++ b/font/src/ft/mod.rs @@ -29,6 +29,7 @@ pub struct Rasterizer { faces: HashMap<FontKey, Face<'static>>, library: Library, system_fonts: HashMap<String, Family>, + keys: HashMap<FontDesc, FontKey>, dpi_x: u32, dpi_y: u32, dpr: f32, @@ -51,6 +52,7 @@ impl Rasterizer { Rasterizer { system_fonts: get_font_families(), faces: HashMap::new(), + keys: HashMap::new(), library: library, dpi_x: dpi_x as u32, dpi_y: dpi_y as u32, @@ -77,11 +79,16 @@ impl Rasterizer { } pub fn load_font(&mut self, desc: &FontDesc, _size: Size) -> Option<FontKey> { - self.get_face(desc) - .map(|face| { - let key = FontKey::next(); - self.faces.insert(key, face); - key + self.keys + .get(&desc.to_owned()) + .map(|k| *k) + .or_else(|| { + self.get_face(desc) + .map(|face| { + let key = FontKey::next(); + self.faces.insert(key, face); + key + }) }) } |