Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small cleanups #159

Merged
merged 3 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 3 additions & 41 deletions src/color.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::{fs::File, io::BufReader, path::PathBuf};

use crate::utils;

use anyhow::Context;
use serde::Deserialize;
use syntect::highlighting::{
Expand Down Expand Up @@ -31,7 +29,7 @@ pub fn native_color(c: u32, format: &TextureFormat) -> [f32; 4] {
}
}

#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq)]
pub struct Theme {
pub text_color: u32,
pub background_color: u32,
Expand Down Expand Up @@ -71,42 +69,6 @@ impl Theme {
}
}

// TODO(cosmic): replace with derive after syntect theme impls PartialEq
impl PartialEq for Theme {
fn eq(&self, other: &Self) -> bool {
let Self {
text_color: self_text_color,
background_color: self_background_color,
code_color: self_code_color,
quote_block_color: self_quote_block_color,
link_color: self_link_color,
select_color: self_select_color,
checkbox_color: self_checkbox_color,
code_highlighter: self_code_highlighter,
} = self;
let Self {
text_color: other_text_color,
background_color: other_background_color,
code_color: other_code_color,
quote_block_color: other_quote_block_color,
link_color: other_link_color,
select_color: other_select_color,
checkbox_color: other_checkbox_color,
code_highlighter: other_code_highlighter,
} = other;

self_text_color == other_text_color
&& self_background_color == other_background_color
&& self_code_color == other_code_color
&& self_quote_block_color == other_quote_block_color
&& self_link_color == other_link_color
&& self_select_color == other_select_color
&& self_checkbox_color == other_checkbox_color
&& utils::SyntectThemePartialEq(self_code_highlighter)
== utils::SyntectThemePartialEq(other_code_highlighter)
}
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum SyntaxTheme {
Defaults(ThemeDefaults),
Expand Down Expand Up @@ -158,8 +120,8 @@ impl<'de> Deserialize<'de> for SyntaxTheme {
return Err(serde::de::Error::custom(
"Expects either a default theme name or a path to a custom theme. E.g.\n\
default: \"inspired-github\"\n\
custom: { path = \"/path/to/custom.tmTheme\" }"
))
custom: { path = \"/path/to/custom.tmTheme\" }",
));
};

match untagged {
Expand Down
16 changes: 15 additions & 1 deletion src/image/decode.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::utils::usize_in_mib;
use image::{
codecs::{jpeg::JpegDecoder, png::PngDecoder},
codecs::{
gif::GifDecoder, jpeg::JpegDecoder, png::PngDecoder, tiff::TiffDecoder, webp::WebPDecoder,
},
ColorType, GenericImageView, ImageDecoder, ImageFormat,
};
use lz4_flex::frame::{BlockSize, FrameDecoder, FrameEncoder, FrameInfo};
Expand Down Expand Up @@ -40,6 +42,18 @@ pub fn decode_and_compress(contents: &[u8]) -> anyhow::Result<(Vec<u8>, (u32, u3
let dec = JpegDecoder::new(io::Cursor::new(&contents))?;
stream_decode_and_compress(dec)
}
ImageFormat::Gif => {
let dec = GifDecoder::new(io::Cursor::new(&contents))?;
stream_decode_and_compress(dec)
}
ImageFormat::Tiff => {
let dec = TiffDecoder::new(io::Cursor::new(&contents))?;
stream_decode_and_compress(dec)
}
ImageFormat::WebP => {
let dec = WebPDecoder::new(io::Cursor::new(&contents))?;
stream_decode_and_compress(dec)
}
_ => None,
};

Expand Down
11 changes: 0 additions & 11 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,17 +226,6 @@ impl Cell {
}
}

// TODO(cosmic): Gonna send a PR upstream because the theme should impl `PartialEq`
pub struct SyntectThemePartialEq<'a>(pub &'a SyntectTheme);

impl PartialEq for SyntectThemePartialEq<'_> {
fn eq(&self, other: &Self) -> bool {
self.0.name == other.0.name
&& self.0.author == other.0.author
&& self.0.scopes.len() == other.0.scopes.len()
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion src/watcher/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Delays {
fn increase_delays(&mut self) {
self.delay *= 2;
self.short_timeout *= 2;
self.long_timeout += Duration::from_millis(1);
self.long_timeout += Duration::from_secs(1);
}

fn delay(&self) {
Expand Down