hecto/src/filetype.rs

65 lines
1.3 KiB
Rust
Raw Normal View History

2021-03-16 10:28:41 -04:00
pub struct FileType {
name: String,
hl_opts: HighlightingOptions,
}
2021-03-16 10:38:26 -04:00
#[derive(Default, Copy, Clone)]
2021-03-16 10:28:41 -04:00
pub struct HighlightingOptions {
2021-03-16 10:38:26 -04:00
numbers: bool,
2021-03-16 10:45:19 -04:00
strings: bool,
2021-03-16 10:57:15 -04:00
characters: bool,
2021-03-16 11:02:27 -04:00
comments: bool,
2021-03-16 10:28:41 -04:00
}
impl Default for FileType {
fn default() -> Self {
Self {
name: String::from("No filetype"),
hl_opts: HighlightingOptions::default(),
}
}
}
impl FileType {
pub fn name(&self) -> String {
self.name.clone()
}
2021-03-16 10:38:26 -04:00
pub fn highlighting_options(&self) -> HighlightingOptions {
self.hl_opts
}
2021-03-16 10:28:41 -04:00
pub fn from(file_name: &str) -> Self {
if file_name.ends_with(".rs") {
return Self {
name: String::from("Rust"),
2021-03-16 10:45:19 -04:00
hl_opts: HighlightingOptions {
numbers: true,
strings: true,
2021-03-16 10:57:15 -04:00
characters: true,
2021-03-16 11:02:27 -04:00
comments: true,
2021-03-16 10:45:19 -04:00
},
2021-03-16 10:28:41 -04:00
};
}
Self::default()
}
2021-03-16 10:38:26 -04:00
}
impl HighlightingOptions {
pub fn numbers(self) -> bool {
self.numbers
}
2021-03-16 10:45:19 -04:00
pub fn strings(self) -> bool {
self.strings
}
2021-03-16 10:57:15 -04:00
pub fn characters(self) -> bool {
self.characters
}
2021-03-16 11:02:27 -04:00
pub fn comments(self) -> bool {
self.comments
}
2021-03-16 10:28:41 -04:00
}