summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhspetersson <jhspetersson@gmail.com>2024-04-08 16:45:01 +0200
committerjhspetersson <jhspetersson@gmail.com>2024-04-08 16:45:01 +0200
commit8b7c53ea2a0603bd416efc5ca6d2e6bbbb7ecc92 (patch)
tree72db2425a5575cb8951f238787081274d90e1ed4
parentf9a9e54d2c86e9a8694bb09748862e89d44ba20f (diff)
add IS_FONT field for ad hoc font file extensions detection
-rw-r--r--src/config.rs2
-rw-r--r--src/field.rs2
-rw-r--r--src/main.rs1
-rw-r--r--src/searcher.rs12
4 files changed, 17 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs
index 02c0b46..e9f173a 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -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")]
@@ -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,
diff --git a/src/field.rs b/src/field.rs
index 692eabf..8a2fcf6 100644
--- a/src/field.rs
+++ b/src/field.rs
@@ -84,6 +84,7 @@ pub enum Field {
IsImage,
IsSource,
IsVideo,
+ IsFont,
Sha1,
Sha256,
Sha512,
@@ -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),
diff --git a/src/main.rs b/src/main.rs
index 24022e4..63860d3 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -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
diff --git a/src/searcher.rs b/src/searcher.rs
index 3b2ba3d..b63aab6 100644
--- a/src/searcher.rs
+++ b/src/searcher.rs
@@ -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));
},
@@ -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)
+ }
}