From a7c01303ac7318a8dbf314e869dcf3c2ee3599e2 Mon Sep 17 00:00:00 2001 From: Zane Weissman Date: Thu, 6 Nov 2025 09:53:14 -0500 Subject: [PATCH] [app] section in theme, OSC 11 and OSC 111 for setting and resetting background, updates to default dark and light themes --- yazi-config/preset/theme-dark.toml | 8 ++++++++ yazi-config/preset/theme-light.toml | 8 ++++++++ yazi-config/src/theme/theme.rs | 6 ++++++ yazi-fm/src/term.rs | 7 ++++++- yazi-plugin/src/theme/theme.rs | 15 +++++++++++++++ 5 files changed, 43 insertions(+), 1 deletion(-) diff --git a/yazi-config/preset/theme-dark.toml b/yazi-config/preset/theme-dark.toml index 1fcf2dc7..b522b26f 100644 --- a/yazi-config/preset/theme-dark.toml +++ b/yazi-config/preset/theme-dark.toml @@ -16,6 +16,14 @@ light = "" # : }}} +# : App {{{ + +[app] +background = "" + +# : }}} + + # : Manager {{{ [mgr] diff --git a/yazi-config/preset/theme-light.toml b/yazi-config/preset/theme-light.toml index 88e9a6f9..26a09880 100644 --- a/yazi-config/preset/theme-light.toml +++ b/yazi-config/preset/theme-light.toml @@ -16,6 +16,14 @@ light = "" # : }}} +# : App {{{ + +[app] +background = "" + +# : }}} + + # : Manager {{{ [mgr] diff --git a/yazi-config/src/theme/theme.rs b/yazi-config/src/theme/theme.rs index b3a8369f..d1be70d4 100644 --- a/yazi-config/src/theme/theme.rs +++ b/yazi-config/src/theme/theme.rs @@ -12,6 +12,7 @@ use crate::Style; #[derive(Deserialize, DeserializeOver1)] pub struct Theme { pub flavor: Flavor, + pub app: App, pub mgr: Mgr, pub tabs: Tabs, pub mode: Mode, @@ -33,6 +34,11 @@ pub struct Theme { pub icon: Icon, } +#[derive(Deserialize, DeserializeOver2)] +pub struct App { + pub background: String, +} + #[derive(Deserialize, DeserializeOver2)] pub struct Mgr { pub cwd: Style, diff --git a/yazi-fm/src/term.rs b/yazi-fm/src/term.rs index d6426d0b..84f93df9 100644 --- a/yazi-fm/src/term.rs +++ b/yazi-fm/src/term.rs @@ -4,7 +4,7 @@ use anyhow::Result; use crossterm::{event::{DisableBracketedPaste, DisableMouseCapture, EnableBracketedPaste, EnableMouseCapture, KeyboardEnhancementFlags, PopKeyboardEnhancementFlags, PushKeyboardEnhancementFlags}, execute, queue, style::Print, terminal::{EnterAlternateScreen, LeaveAlternateScreen, SetTitle, disable_raw_mode, enable_raw_mode}}; use ratatui::{CompletedFrame, Frame, Terminal, backend::CrosstermBackend, buffer::Buffer, layout::Rect}; use yazi_adapter::{Emulator, Mux, TMUX}; -use yazi_config::YAZI; +use yazi_config::{YAZI,THEME}; use yazi_shared::SyncCell; use yazi_term::tty::{TTY, TtyWriter}; @@ -23,6 +23,7 @@ impl Term { last_area: Default::default(), last_buffer: Default::default(), }; + let background = &THEME.app.background; enable_raw_mode()?; static FIRST: SyncCell = SyncCell::new(false); @@ -37,6 +38,8 @@ impl Term { Print("\x1b[?12$p"), // Request cursor blink status (DECRQM query for DECSET 12) Print("\x1b[?u"), // Request keyboard enhancement flags (CSI u) Print("\x1b[0c"), // Request device attributes + // Set terminal background color + yazi_term::If(!background.is_empty(), Print(format!("\x1b]11;{}\x1b\\", background))), yazi_term::If(TMUX.get(), EnterAlternateScreen), EnableBracketedPaste, yazi_term::If(!YAZI.mgr.mouse_events.get().is_empty(), EnableMouseCapture), @@ -100,6 +103,8 @@ impl Term { execute!( TTY.writer(), yazi_term::If(!YAZI.mgr.mouse_events.get().is_empty(), DisableMouseCapture), + // Restore default terminal background + yazi_term::If(!THEME.app.background.is_empty(), Print("\x1b]111\x1b\\")), yazi_term::RestoreCursor, DisableBracketedPaste, LeaveAlternateScreen, diff --git a/yazi-plugin/src/theme/theme.rs b/yazi-plugin/src/theme/theme.rs index 5b8f6d81..df730835 100644 --- a/yazi-plugin/src/theme/theme.rs +++ b/yazi-plugin/src/theme/theme.rs @@ -5,6 +5,7 @@ use yazi_config::THEME; pub fn compose() -> Composer { fn get(lua: &Lua, key: &[u8]) -> mlua::Result { match key { + b"app" => app(), b"mgr" => mgr(), b"tabs" => tabs(), b"mode" => mode(), @@ -28,6 +29,20 @@ pub fn compose() -> Composer { Composer::new(get, set) } +fn app() -> Composer { + fn get(lua: &Lua, key: &[u8]) -> mlua::Result { + let a = &THEME.app; + match key { + b"background" => lua.create_string(&a.background)?.into_lua(lua), + _ => Ok(Value::Nil), + } + } + + fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result { Ok(value) } + + Composer::new(get, set) +} + fn mgr() -> Composer { fn get(lua: &Lua, key: &[u8]) -> mlua::Result { let m = &THEME.mgr;