Skip to content

Commit

Permalink
Merge pull request #467 from gjtorikian/caseinsensitive-search
Browse files Browse the repository at this point in the history
Allow case insensitive search for `.tmtheme` paths
  • Loading branch information
Enselic committed Jul 22, 2023
2 parents f4ee0e9 + b8a85d6 commit e10d03f
Showing 1 changed file with 35 additions and 23 deletions.
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!();
}
}

0 comments on commit e10d03f

Please sign in to comment.