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

Allow case insensitive search for .tmtheme paths #467

Merged
merged 3 commits into from
Jul 22, 2023
Merged
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
58 changes: 35 additions & 23 deletions src/highlighting/theme_set.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::theme::Theme;
use super::super::LoadingError;
#[cfg(feature = "plist-load")]
use super::settings::*;
use super::super::LoadingError;
use super::theme::Theme;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use std::path::{Path, PathBuf};
use serde::{Deserialize, Serialize};

#[derive(Debug, Default, Serialize, Deserialize)]
pub struct ThemeSet {
Expand All @@ -26,7 +26,12 @@ impl ThemeSet {
let mut themes = Vec::new();
for entry in crate::utils::walk_dir(folder) {
let entry = entry.map_err(LoadingError::WalkDir)?;
if entry.path().extension().map_or(false, |e| e == "tmTheme") {
if entry.path().is_file()
&& entry
.path()
.extension()
.map_or(false, |e| e.eq_ignore_ascii_case("tmTheme"))
{
themes.push(entry.path().to_owned());
}
}
Expand All @@ -43,7 +48,9 @@ impl ThemeSet {

/// Loads a theme given a readable stream
#[cfg(feature = "plist-load")]
pub fn load_from_reader<R: std::io::BufRead + std::io::Seek>(r: &mut R) -> Result<Theme, LoadingError> {
pub fn load_from_reader<R: std::io::BufRead + std::io::Seek>(
r: &mut R,
) -> Result<Theme, LoadingError> {
Ok(Theme::parse_settings(read_plist(r)?)?)
}

Expand All @@ -61,19 +68,20 @@ impl ThemeSet {
let paths = Self::discover_theme_paths(folder)?;
for p in &paths {
let theme = Self::get_theme(p)?;
let basename =
p.file_stem().and_then(|x| x.to_str()).ok_or(LoadingError::BadPath)?;
let basename = p
.file_stem()
.and_then(|x| x.to_str())
.ok_or(LoadingError::BadPath)?;
self.themes.insert(basename.to_owned(), theme);
}

Ok(())
}
}


#[cfg(test)]
mod tests {
use crate::highlighting::{ThemeSet, Color};
use crate::highlighting::{Color, ThemeSet};
#[cfg(feature = "plist-load")]
#[test]
fn can_parse_common_themes() {
Expand All @@ -85,20 +93,24 @@ mod tests {

let theme = ThemeSet::get_theme("testdata/spacegray/base16-ocean.dark.tmTheme").unwrap();
assert_eq!(theme.name.unwrap(), "Base16 Ocean Dark");
assert_eq!(theme.settings.selection.unwrap(),
Color {
r: 0x4f,
g: 0x5b,
b: 0x66,
a: 0xff,
});
assert_eq!(theme.scopes[0].style.foreground.unwrap(),
Color {
r: 0xc0,
g: 0xc5,
b: 0xce,
a: 0xFF,
});
assert_eq!(
theme.settings.selection.unwrap(),
Color {
r: 0x4f,
g: 0x5b,
b: 0x66,
a: 0xff,
}
);
assert_eq!(
theme.scopes[0].style.foreground.unwrap(),
Color {
r: 0xc0,
g: 0xc5,
b: 0xce,
a: 0xFF,
}
);
// unreachable!();
}
}