mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
[app] section in theme, OSC 11 and OSC 111 for setting and resetting background, updates to default dark and light themes
This commit is contained in:
parent
4b56e73235
commit
a7c01303ac
5 changed files with 43 additions and 1 deletions
|
|
@ -16,6 +16,14 @@ light = ""
|
|||
# : }}}
|
||||
|
||||
|
||||
# : App {{{
|
||||
|
||||
[app]
|
||||
background = ""
|
||||
|
||||
# : }}}
|
||||
|
||||
|
||||
# : Manager {{{
|
||||
|
||||
[mgr]
|
||||
|
|
|
|||
|
|
@ -16,6 +16,14 @@ light = ""
|
|||
# : }}}
|
||||
|
||||
|
||||
# : App {{{
|
||||
|
||||
[app]
|
||||
background = ""
|
||||
|
||||
# : }}}
|
||||
|
||||
|
||||
# : Manager {{{
|
||||
|
||||
[mgr]
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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<bool> = 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,
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ use yazi_config::THEME;
|
|||
pub fn compose() -> Composer<ComposerGet, ComposerSet> {
|
||||
fn get(lua: &Lua, key: &[u8]) -> mlua::Result<Value> {
|
||||
match key {
|
||||
b"app" => app(),
|
||||
b"mgr" => mgr(),
|
||||
b"tabs" => tabs(),
|
||||
b"mode" => mode(),
|
||||
|
|
@ -28,6 +29,20 @@ pub fn compose() -> Composer<ComposerGet, ComposerSet> {
|
|||
Composer::new(get, set)
|
||||
}
|
||||
|
||||
fn app() -> Composer<ComposerGet, ComposerSet> {
|
||||
fn get(lua: &Lua, key: &[u8]) -> mlua::Result<Value> {
|
||||
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<Value> { Ok(value) }
|
||||
|
||||
Composer::new(get, set)
|
||||
}
|
||||
|
||||
fn mgr() -> Composer<ComposerGet, ComposerSet> {
|
||||
fn get(lua: &Lua, key: &[u8]) -> mlua::Result<Value> {
|
||||
let m = &THEME.mgr;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue