-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dustin Blackman
committed
Nov 23, 2023
1 parent
50e573b
commit 145abb6
Showing
8 changed files
with
124 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,41 @@ | ||
use once_cell::sync::Lazy; | ||
use ratatui::style::Color; | ||
use syntect::parsing::SyntaxReference; | ||
use syntect::parsing::SyntaxSet; | ||
|
||
pub static SYNTAX_SET: Lazy<SyntaxSet> = Lazy::new(Syntaxes::load); | ||
|
||
pub struct Syntaxes {} | ||
|
||
impl Syntaxes { | ||
pub fn load() -> SyntaxSet { | ||
fn load() -> SyntaxSet { | ||
let payload = include_bytes!("../../../.cache/syntaxes/syntaxes.bin"); | ||
let syntax_set: SyntaxSet = bincode::deserialize_from(&payload[..]).unwrap(); | ||
return syntax_set; | ||
} | ||
|
||
pub fn get(name: &str) -> &SyntaxReference { | ||
if let Some(syntax) = SYNTAX_SET.find_syntax_by_extension(name) { | ||
return syntax; | ||
} | ||
|
||
if let Some(syntax) = SYNTAX_SET.find_syntax_by_name(name) { | ||
return syntax; | ||
} | ||
|
||
if let Some(syntax) = SYNTAX_SET.find_syntax_by_token(name) { | ||
return syntax; | ||
} | ||
|
||
return SYNTAX_SET.find_syntax_plain_text(); | ||
} | ||
|
||
pub fn translate_colour(syntect_color: syntect::highlighting::Color) -> Option<Color> { | ||
match syntect_color { | ||
syntect::highlighting::Color { r, g, b, a } if a > 0 => { | ||
return Some(Color::Rgb(r, g, b)) | ||
} | ||
_ => return None, | ||
} | ||
} | ||
} |
Oops, something went wrong.