hecto/src/filetype.rs

53 lines
1.0 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: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: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:28:41 -04:00
}