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::{ use gtk::{
gdk::RGBA, gdk::RGBA,
pango::{Style, Underline}, pango::{Style, Underline},
@ -21,7 +22,8 @@ use syntect::{
Solarized (dark) Solarized (dark)
Solarized (light) 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 { pub struct Syntax {
syntax_set: SyntaxSet, syntax_set: SyntaxSet,
@ -85,8 +87,15 @@ impl Syntax {
let mut buffer = Vec::new(); let mut buffer = Vec::new();
// Apply syntect decorator // Apply syntect decorator
let ranges = HighlightLines::new(syntax_reference, &self.theme_set.themes[DEFAULT_THEME]) let ranges = HighlightLines::new(
.highlight_line(&source, &self.syntax_set)?; 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 // Build tags
for (style, entity) in ranges { for (style, entity) in ranges {