Feat: optimizations

This commit is contained in:
2026-03-07 11:38:49 +01:00
parent 20d72c9b21
commit 3104a61490
7 changed files with 35 additions and 53 deletions

View File

@@ -30,6 +30,7 @@ pub mod transform;
use ratatui::style::Color;
use std::cell::RefCell;
use std::rc::Rc;
/// Entry in the theme registry: id, display label, and palette constructor.
pub struct ThemeEntry {
@@ -66,17 +67,17 @@ pub const THEMES: &[ThemeEntry] = &[
];
thread_local! {
static CURRENT_THEME: RefCell<ThemeColors> = RefCell::new(build::build(&(THEMES[0].palette)()));
static CURRENT_THEME: RefCell<Rc<ThemeColors>> = RefCell::new(Rc::new(build::build(&(THEMES[0].palette)())));
}
/// Return the current thread-local theme.
pub fn get() -> ThemeColors {
CURRENT_THEME.with(|t| t.borrow().clone())
/// Return the current thread-local theme (cheap Rc clone, not a deep copy).
pub fn get() -> Rc<ThemeColors> {
CURRENT_THEME.with(|t| Rc::clone(&t.borrow()))
}
/// Set the current thread-local theme.
pub fn set(theme: ThemeColors) {
CURRENT_THEME.with(|t| *t.borrow_mut() = theme);
CURRENT_THEME.with(|t| *t.borrow_mut() = Rc::new(theme));
}
/// Complete set of resolved colors for all UI components.