Skip to content

Commit

Permalink
add IS_FONT field for ad hoc font file extensions detection
Browse files Browse the repository at this point in the history
  • Loading branch information
jhspetersson committed Apr 8, 2024
1 parent f9a9e54 commit 8b7c53e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub struct Config {
pub is_image : Vec<String>,
pub is_source : Vec<String>,
pub is_video : Vec<String>,
pub is_font : Vec<String>,
pub default_file_size_format : Option<String>,
pub check_for_updates: Option<bool>,
#[serde(skip_serializing, default = "get_false")]
Expand Down Expand Up @@ -150,6 +151,7 @@ impl Config {
is_image : vec_of_strings![".bmp", ".exr", ".gif", ".heic", ".jpeg", ".jpg", ".jxl", ".png", ".psb", ".psd", ".svg", ".tga", ".tiff", ".webp"],
is_source : vec_of_strings![".asm", ".bas", ".c", ".cc", ".ceylon", ".clj", ".coffee", ".cpp", ".cs", ".d", ".dart", ".elm", ".erl", ".go", ".gradle", ".groovy", ".h", ".hh", ".hpp", ".java", ".jl", ".js", ".jsp", ".jsx", ".kt", ".kts", ".lua", ".nim", ".pas", ".php", ".pl", ".pm", ".py", ".rb", ".rs", ".scala", ".sol", ".swift", ".tcl", ".ts", ".tsx", ".vala", ".vb", ".zig"],
is_video : vec_of_strings![".3gp", ".avi", ".flv", ".m4p", ".m4v", ".mkv", ".mov", ".mp4", ".mpeg", ".mpg", ".webm", ".wmv"],
is_font : vec_of_strings![".eot", ".fon", ".otc", ".otf", ".ttc", ".ttf", ".woff", ".woff2"],
default_file_size_format : Some(String::new()),
check_for_updates : Some(false),
debug : false,
Expand Down
2 changes: 2 additions & 0 deletions src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ pub enum Field {
IsImage,
IsSource,
IsVideo,
IsFont,
Sha1,
Sha256,
Sha512,
Expand Down Expand Up @@ -174,6 +175,7 @@ impl FromStr for Field {
"is_image" => Ok(Field::IsImage),
"is_source" => Ok(Field::IsSource),
"is_video" => Ok(Field::IsVideo),
"is_font" => Ok(Field::IsFont),
"sha1" => Ok(Field::Sha1),
"sha2_256" | "sha256" => Ok(Field::Sha256),
"sha2_512" | "sha512" => Ok(Field::Sha512),
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ Column Options:
is_image Returns a boolean signifying whether the file is an image
is_source Returns a boolean signifying whether the file is source code
is_video Returns a boolean signifying whether the file is a video file
is_font Returns a boolean signifying whether the file is a font file
sha1 Returns SHA-1 digest of a file
sha2_256 | sha256 Returns SHA2-256 digest of a file
Expand Down
12 changes: 12 additions & 0 deletions src/searcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,14 @@ impl <'a> Searcher<'a> {

return Variant::from_bool(is_video);
},
Field::IsFont => {
let is_font = match file_info {
Some(file_info) => self.is_font(&file_info.name),
None => self.is_font(&entry.file_name().to_string_lossy())
};

return Variant::from_bool(is_font);
},
Field::Sha1 => {
return Variant::from_string(&crate::util::get_sha1_file_hash(&entry));
},
Expand Down Expand Up @@ -1805,4 +1813,8 @@ impl <'a> Searcher<'a> {
fn is_video(&self, file_name: &str) -> bool {
has_extension(file_name, &self.config.is_video)
}

fn is_font(&self, file_name: &str) -> bool {
has_extension(file_name, &self.config.is_font)
}
}

0 comments on commit 8b7c53e

Please sign in to comment.