use environment-based theme

This commit is contained in:
yggverse 2024-12-03 16:39:22 +02:00
parent 9e7147838f
commit 09fcbfa725

View File

@ -1,3 +1,4 @@
use adw::StyleManager;
use gtk::{
gdk::RGBA,
pango::{Style, Underline},
@ -21,7 +22,8 @@ use syntect::{
Solarized (dark)
Solarized (light)
*/
pub const DEFAULT_THEME: &str = "Solarized (dark)";
pub const DEFAULT_THEME_DARK: &str = "base16-eighties.dark";
pub const DEFAULT_THEME_LIGHT: &str = "InspiredGitHub";
pub struct Syntax {
syntax_set: SyntaxSet,
@ -85,7 +87,14 @@ impl Syntax {
let mut buffer = Vec::new();
// Apply syntect decorator
let ranges = HighlightLines::new(syntax_reference, &self.theme_set.themes[DEFAULT_THEME])
let ranges = HighlightLines::new(
syntax_reference,
&self.theme_set.themes[if StyleManager::default().is_dark() {
DEFAULT_THEME_DARK
} else {
DEFAULT_THEME_LIGHT
}], // @TODO apply on env change
)
.highlight_line(&source, &self.syntax_set)?;
// Build tags