use std::path::Path;
use tree_sitter_highlight::HighlightConfiguration;
mod error;
mod renderer;
mod theme;
pub use error::Error;
pub use renderer::Renderer;
pub use theme::Theme;
#[cfg(feature = "themes")]
pub mod themes {
pub const AYU_DARK: &str = include_str!("themes/ayu_dark.toml");
pub const AYU_LIGHT: &str = include_str!("themes/ayu_light.toml");
pub const AYU_MIRAGE: &str = include_str!("themes/ayu_mirage.toml");
pub const CATPPUCCIN_FRAPPE: &str = include_str!("themes/catppuccin_frappe.toml");
pub const CATPPUCCIN_LATTE: &str = include_str!("themes/catppuccin_latte.toml");
pub const CATPPUCCIN_MACCHIATO: &str = include_str!("themes/catppuccin_macchiato.toml");
pub const CATPPUCCIN_MOCHA: &str = include_str!("themes/catppuccin_mocha.toml");
}
#[derive(Eq, Hash, PartialEq, Clone, Debug)]
pub enum Lang {
#[cfg(feature = "tree-sitter-c")]
C,
#[cfg(feature = "tree-sitter-commonlisp")]
CommonLisp,
#[cfg(feature = "tree-sitter-cpp")]
Cpp,
#[cfg(feature = "tree-sitter-cuda")]
Cuda,
#[cfg(feature = "tree-sitter-javascript")]
Js,
#[cfg(feature = "tree-sitter-python")]
Python,
#[cfg(feature = "tree-sitter-rust")]
Rust,
}
impl Lang {
pub fn from<T: AsRef<Path>>(path: T) -> Option<Self> {
path.as_ref()
.extension()
.and_then(|e| e.to_str())
.and_then(|e| match e {
#[cfg(feature = "tree-sitter-c")]
"c" => Some(Lang::C),
#[cfg(feature = "tree-sitter-commonlisp")]
"lisp" | "lsp" | "l" | "cl" => Some(Lang::CommonLisp),
#[cfg(feature = "tree-sitter-cpp")]
"cpp" | "cc" | "cxx" => Some(Lang::Cpp),
#[cfg(feature = "tree-sitter-cuda")]
"cu" => Some(Lang::Cuda),
#[cfg(feature = "tree-sitter-javascript")]
"js" => Some(Lang::Js),
#[cfg(feature = "tree-sitter-python")]
"py" => Some(Lang::Python),
#[cfg(feature = "tree-sitter-rust")]
"rs" => Some(Lang::Rust),
&_ => None,
})
}
fn config(&self) -> HighlightConfiguration {
match self {
#[cfg(feature = "tree-sitter-c")]
Lang::C => HighlightConfiguration::new(
tree_sitter_c::language(),
tree_sitter_c::HIGHLIGHT_QUERY,
"",
"",
)
.expect("loading tree-sitter-c"),
#[cfg(feature = "tree-sitter-commonlisp")]
Lang::CommonLisp => {
HighlightConfiguration::new(tree_sitter_commonlisp::language(), "", "", "")
.expect("loading tree-sitter-commonlisp")
}
#[cfg(feature = "tree-sitter-cpp")]
Lang::Cpp => HighlightConfiguration::new(
tree_sitter_cpp::language(),
tree_sitter_cpp::HIGHLIGHT_QUERY,
"",
"",
)
.expect("loading tree-sitter-cpp"),
#[cfg(feature = "tree-sitter-cuda")]
Lang::Cuda => HighlightConfiguration::new(tree_sitter_cuda::language(), "", "", "")
.expect("loading tree-sitter-cuda"),
#[cfg(feature = "tree-sitter-javascript")]
Lang::Js => HighlightConfiguration::new(
tree_sitter_javascript::language(),
tree_sitter_javascript::HIGHLIGHT_QUERY,
tree_sitter_javascript::INJECTION_QUERY,
tree_sitter_javascript::LOCALS_QUERY,
)
.expect("loading tree-sitter-javascript"),
#[cfg(feature = "tree-sitter-python")]
Lang::Python => HighlightConfiguration::new(
tree_sitter_python::language(),
tree_sitter_python::HIGHLIGHT_QUERY,
"",
"",
)
.expect("loading tree-sitter-cpp"),
#[cfg(feature = "tree-sitter-rust")]
Lang::Rust => HighlightConfiguration::new(
tree_sitter_rust::language(),
tree_sitter_rust::HIGHLIGHT_QUERY,
"",
"",
)
.expect("loading tree-sitter-rust"),
}
}
}