eazygit 0.5.1

A fast TUI for Git with staging, conflicts, rebase, and palette-first UX
Documentation
//! Theme-related action handlers.

use crate::app::{Action, reducer};
use crate::config;
use crate::errors::ApplicationError;
use super::super::HandlerContext;

/// Handle theme-related actions. Returns true if handled.
pub async fn handle(action: &Action, ctx: &mut HandlerContext<'_>) -> Result<bool, ApplicationError> {
    match action {
        Action::ApplyTheme(name) => {
            tracing::info!("Setting theme: {}", name);
            let mut theme = config::load_theme_by_name(name);
            theme.enable_transparency = ctx.app.state.theme.enable_transparency;
            ctx.app.state.theme = theme;
            if let Err(e) = config::persist_theme(name) {
                tracing::error!("Failed to persist theme: {}", e);
            }
            ctx.app.state = reducer(ctx.app.state.clone(), action.clone());
            Ok(true)
        }
        Action::ReloadTheme => {
            match config::load() {
                Ok(settings) => {
                    ctx.app.state.theme = settings.theme.clone();
                    ctx.app.state.theme_picker = false;
                    ctx.app.state = reducer(ctx.app.state.clone(), Action::HidePalette);
                }
                Err(e) => {
                    ctx.app.state = reducer(
                        ctx.app.state.clone(),
                        Action::SetStatusError(Some(format!("theme reload failed: {e}")))
                    );
                }
            }
            Ok(true)
        }
        _ => Ok(false),
    }
}