feat: new app:theme action that hot-reload user themes/flavors (#3906)

This commit is contained in:
sxyazi 2026-04-21 23:34:56 +08:00
parent 369c47539c
commit 4a2e5addcd
No known key found for this signature in database
107 changed files with 799 additions and 405 deletions

View file

@ -12,6 +12,7 @@ yazi_macro::mod_flat!(
resize
resume
stop
theme
title
update_progress
);

View file

@ -0,0 +1,25 @@
use anyhow::Result;
use yazi_actor::Ctx;
use yazi_config::{THEME, build_flavor};
use yazi_emulator::EMULATOR;
use yazi_macro::{render, succ};
use yazi_parser::VoidForm;
use yazi_shared::data::Data;
use yazi_shim::serde::Overlay;
use crate::Actor;
pub struct Theme;
impl Actor for Theme {
type Form = VoidForm;
const NAME: &str = "theme";
fn act(_cx: &mut Ctx, _: Self::Form) -> Result<Data> {
THEME.overlay(build_flavor(EMULATOR.light, true)?);
yazi_plugin::theme::reset()?;
succ!(render!());
}
}

View file

@ -2,7 +2,7 @@ use std::{ops::Deref, ptr};
use mlua::{AnyUserData, IntoLua, UserData, UserDataFields, UserDataMethods, Value};
use yazi_binding::{Range, Style, cached_field};
use yazi_config::{Selectable, THEME};
use yazi_config::THEME;
use yazi_shared::{path::AsPath, url::UrlLike};
use super::Lives;
@ -111,7 +111,7 @@ impl UserData for File {
methods.add_method("style", |lua, me, ()| {
lua.named_registry_value::<AnyUserData>("cx")?.borrow_scoped(|core: &yazi_core::Core| {
let mime = core.mgr.mimetype.get(&me.url).unwrap_or_default();
THEME.filetype.iter().find(|&x| x.matches(me, mime)).map(|x| Style::from(x.style))
THEME.filetype.match_style(me, mime).map(Style::from)
})
});
methods.add_method("is_yanked", |lua, me, ()| {

View file

@ -5,7 +5,7 @@ use mlua::{AnyUserData, UserData};
use scopeguard::defer;
use tracing::error;
use yazi_plugin::LUA;
use yazi_shared::RoCell;
use yazi_shim::cell::RoCell;
use super::{Core, PtrCell};

View file

@ -38,7 +38,7 @@ impl UserData for Preference {
fn add_fields<F: UserDataFields<Self>>(fields: &mut F) {
// Display
cached_field!(fields, name, |lua, me| lua.create_string(&me.name));
cached_field!(fields, linemode, |lua, me| lua.create_string(&me.linemode));
cached_field!(fields, linemode, |lua, me| lua.create_string(&*me.linemode));
fields.add_field_method_get("show_hidden", |_, me| Ok(me.show_hidden));
// Sorting

View file

@ -15,8 +15,8 @@ impl Actor for Linemode {
fn act(cx: &mut Ctx, form: Self::Form) -> Result<Data> {
let tab = cx.tab_mut();
if form.new != tab.pref.linemode {
tab.pref.linemode = form.new.into_owned();
if form.new != *tab.pref.linemode {
tab.pref.linemode = form.new.into();
render!();
}