mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Support setting individual bg colors for parent, current and preview panes
This commit is contained in:
parent
4fd1598e0f
commit
367f124855
7 changed files with 235 additions and 86 deletions
|
|
@ -20,6 +20,9 @@ light = ""
|
||||||
|
|
||||||
[app]
|
[app]
|
||||||
overall = {}
|
overall = {}
|
||||||
|
parent = {}
|
||||||
|
current = {}
|
||||||
|
preview = {}
|
||||||
|
|
||||||
# : }}}
|
# : }}}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,9 @@ light = ""
|
||||||
|
|
||||||
[app]
|
[app]
|
||||||
overall = {}
|
overall = {}
|
||||||
|
parent = {}
|
||||||
|
current = {}
|
||||||
|
preview = {}
|
||||||
|
|
||||||
# : }}}
|
# : }}}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,12 @@ pub struct Theme {
|
||||||
#[derive(Deserialize, DeserializeOver2)]
|
#[derive(Deserialize, DeserializeOver2)]
|
||||||
pub struct App {
|
pub struct App {
|
||||||
pub overall: Style,
|
pub overall: Style,
|
||||||
|
#[serde(default)]
|
||||||
|
pub parent: Style,
|
||||||
|
#[serde(default)]
|
||||||
|
pub current: Style,
|
||||||
|
#[serde(default)]
|
||||||
|
pub preview: Style,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, DeserializeOver2)]
|
#[derive(Deserialize, DeserializeOver2)]
|
||||||
|
|
@ -247,5 +253,19 @@ impl Theme {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
pub fn bg_color(&self) -> String { self.overall.bg.map(|c| c.to_string()).unwrap_or_default() }
|
pub fn bg_color(&self) -> String {
|
||||||
|
self.overall.bg.map(|c| c.to_string()).unwrap_or_default()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parent_bg(&self) -> String {
|
||||||
|
self.parent.bg.map(|c| c.to_string()).unwrap_or_default()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn current_bg(&self) -> String {
|
||||||
|
self.current.bg.map(|c| c.to_string()).unwrap_or_default()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn preview_bg(&self) -> String {
|
||||||
|
self.preview.bg.map(|c| c.to_string()).unwrap_or_default()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,37 @@
|
||||||
use ratatui::{buffer::Buffer, layout::Rect, style::Color};
|
use ratatui::{buffer::Buffer, layout::Rect, style::Color};
|
||||||
|
|
||||||
|
/// Apply background color to a pane, skipping borders on all sides
|
||||||
|
#[inline]
|
||||||
|
pub fn apply_pane_bg_with_borders(buf: &mut Buffer, pane: Rect, bg_color: Color) {
|
||||||
|
let start_y = pane.top() + 1;
|
||||||
|
let end_y = if pane.bottom() > 0 { pane.bottom() - 1 } else { pane.bottom() };
|
||||||
|
let start_x = pane.left() + 1;
|
||||||
|
let end_x = if pane.right() > 0 { pane.right() - 1 } else { pane.right() };
|
||||||
|
|
||||||
|
if start_y < end_y && start_x < end_x {
|
||||||
|
for y in start_y..end_y {
|
||||||
|
for x in start_x..end_x {
|
||||||
|
buf[(x, y)].set_bg(bg_color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Apply background color to a pane, skipping only top/bottom borders
|
||||||
|
#[inline]
|
||||||
|
pub fn apply_pane_bg_no_vertical_borders(buf: &mut Buffer, pane: Rect, bg_color: Color) {
|
||||||
|
let start_y = pane.top() + 1;
|
||||||
|
let end_y = if pane.bottom() > 0 { pane.bottom() - 1 } else { pane.bottom() };
|
||||||
|
|
||||||
|
if start_y < end_y {
|
||||||
|
for y in start_y..end_y {
|
||||||
|
for x in pane.left()..pane.right() {
|
||||||
|
buf[(x, y)].set_bg(bg_color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Apply background color to entire area, excluding header and status bar
|
/// Apply background color to entire area, excluding header and status bar
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn apply_overall_bg(buf: &mut Buffer, area: Rect, bg_color: Color) {
|
pub fn apply_overall_bg(buf: &mut Buffer, area: Rect, bg_color: Color) {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,12 @@
|
||||||
use mlua::{ObjectLike, Table};
|
use mlua::{ObjectLike, Table};
|
||||||
use ratatui::{buffer::Buffer, layout::Rect, widgets::Widget};
|
use ratatui::{
|
||||||
|
buffer::Buffer,
|
||||||
|
layout::{Constraint, Direction, Layout, Rect},
|
||||||
|
widgets::Widget,
|
||||||
|
};
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
use yazi_binding::elements::render_once;
|
use yazi_binding::elements::render_once;
|
||||||
use yazi_config::THEME;
|
use yazi_config::{THEME, YAZI};
|
||||||
use yazi_core::Core;
|
use yazi_core::Core;
|
||||||
use yazi_plugin::LUA;
|
use yazi_plugin::LUA;
|
||||||
|
|
||||||
|
|
@ -13,7 +17,9 @@ pub(super) struct Root<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Root<'a> {
|
impl<'a> Root<'a> {
|
||||||
pub(super) fn new(core: &'a Core) -> Self { Self { core } }
|
pub(super) fn new(core: &'a Core) -> Self {
|
||||||
|
Self { core }
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) fn reflow(area: Rect) -> mlua::Result<Table> {
|
pub(super) fn reflow(area: Rect) -> mlua::Result<Table> {
|
||||||
let area = yazi_binding::elements::Rect::from(area);
|
let area = yazi_binding::elements::Rect::from(area);
|
||||||
|
|
@ -70,9 +76,57 @@ impl Widget for Root<'_> {
|
||||||
which::Which::new(self.core).render(area, buf);
|
which::Which::new(self.core).render(area, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate the Tab area (excluding Header, Tabs, and Status)
|
||||||
|
// This matches the Root layout in root.lua
|
||||||
|
let tabs_height = if self.core.mgr.tabs.len() > 1 { 1 } else { 0 };
|
||||||
|
let root_chunks = Layout::default()
|
||||||
|
.direction(Direction::Vertical)
|
||||||
|
.constraints([
|
||||||
|
Constraint::Length(1), // Header
|
||||||
|
Constraint::Length(tabs_height), // Tabs
|
||||||
|
Constraint::Fill(1), // Tab content (the 3 panes)
|
||||||
|
Constraint::Length(1), // Status
|
||||||
|
])
|
||||||
|
.split(area);
|
||||||
|
let tab_area = root_chunks[2];
|
||||||
|
|
||||||
|
// Apply per-pane backgrounds first, then app-wide background
|
||||||
|
// Calculate pane areas using the manager ratio within the tab area
|
||||||
|
let ratio = YAZI.mgr.ratio.get();
|
||||||
|
let chunks = Layout::default()
|
||||||
|
.direction(Direction::Horizontal)
|
||||||
|
.constraints([
|
||||||
|
Constraint::Ratio(ratio.parent as u32, ratio.all as u32),
|
||||||
|
Constraint::Ratio(ratio.current as u32, ratio.all as u32),
|
||||||
|
Constraint::Ratio(ratio.preview as u32, ratio.all as u32),
|
||||||
|
])
|
||||||
|
.split(tab_area);
|
||||||
|
|
||||||
|
// Apply pane backgrounds (if configured)
|
||||||
|
// Skip borders: top/bottom rows and left/right edges where borders are drawn
|
||||||
|
let parent_bg = THEME.app.parent_bg();
|
||||||
|
if !parent_bg.is_empty() {
|
||||||
|
if let Ok(bg_color) = parent_bg.parse::<ratatui::style::Color>() {
|
||||||
|
apply_pane_bg_with_borders(buf, chunks[0], bg_color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let current_bg = THEME.app.current_bg();
|
||||||
|
if !current_bg.is_empty() {
|
||||||
|
if let Ok(bg_color) = current_bg.parse::<ratatui::style::Color>() {
|
||||||
|
apply_pane_bg_no_vertical_borders(buf, chunks[1], bg_color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let preview_bg = THEME.app.preview_bg();
|
||||||
|
if !preview_bg.is_empty() {
|
||||||
|
if let Ok(bg_color) = preview_bg.parse::<ratatui::style::Color>() {
|
||||||
|
apply_pane_bg_with_borders(buf, chunks[2], bg_color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Fill background on all cells to create an opaque background (like fzf does).
|
// Fill background on all cells to create an opaque background (like fzf does).
|
||||||
// This is done AFTER all rendering so text/foreground colors are already set.
|
// This is done AFTER all rendering so text/foreground colors are already set.
|
||||||
// The background is skipped on the header (top row) and status bar (bottom row).
|
|
||||||
let bg_color_str = THEME.app.bg_color();
|
let bg_color_str = THEME.app.bg_color();
|
||||||
if !bg_color_str.is_empty() {
|
if !bg_color_str.is_empty() {
|
||||||
if let Ok(bg_color) = bg_color_str.parse::<ratatui::style::Color>() {
|
if let Ok(bg_color) = bg_color_str.parse::<ratatui::style::Color>() {
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,8 @@ impl Term {
|
||||||
Print("\x1b[?12$p"), // Request cursor blink status (DECRQM query for DECSET 12)
|
Print("\x1b[?12$p"), // Request cursor blink status (DECRQM query for DECSET 12)
|
||||||
Print("\x1b[?u"), // Request keyboard enhancement flags (CSI u)
|
Print("\x1b[?u"), // Request keyboard enhancement flags (CSI u)
|
||||||
Print("\x1b[0c"), // Request device attributes
|
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),
|
yazi_term::If(TMUX.get(), EnterAlternateScreen),
|
||||||
yazi_term::SetBackground(true, THEME.app.bg_color()), // Set app background
|
yazi_term::SetBackground(true, THEME.app.bg_color()), // Set app background
|
||||||
EnableBracketedPaste,
|
EnableBracketedPaste,
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,9 @@ pub fn compose() -> Composer<ComposerGet, ComposerSet> {
|
||||||
.into_lua(lua)
|
.into_lua(lua)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> { Ok(value) }
|
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> {
|
||||||
|
Ok(value)
|
||||||
|
}
|
||||||
|
|
||||||
Composer::new(get, set)
|
Composer::new(get, set)
|
||||||
}
|
}
|
||||||
|
|
@ -35,11 +37,16 @@ fn app() -> Composer<ComposerGet, ComposerSet> {
|
||||||
let a = &THEME.app;
|
let a = &THEME.app;
|
||||||
match key {
|
match key {
|
||||||
b"overall" => Style::from(a.overall).into_lua(lua),
|
b"overall" => Style::from(a.overall).into_lua(lua),
|
||||||
|
b"parent" => Style::from(a.parent).into_lua(lua),
|
||||||
|
b"current" => Style::from(a.current).into_lua(lua),
|
||||||
|
b"preview" => Style::from(a.preview).into_lua(lua),
|
||||||
_ => Ok(Value::Nil),
|
_ => Ok(Value::Nil),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> { Ok(value) }
|
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> {
|
||||||
|
Ok(value)
|
||||||
|
}
|
||||||
|
|
||||||
Composer::new(get, set)
|
Composer::new(get, set)
|
||||||
}
|
}
|
||||||
|
|
@ -87,7 +94,9 @@ fn mgr() -> Composer<ComposerGet, ComposerSet> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> { Ok(value) }
|
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> {
|
||||||
|
Ok(value)
|
||||||
|
}
|
||||||
|
|
||||||
Composer::new(get, set)
|
Composer::new(get, set)
|
||||||
}
|
}
|
||||||
|
|
@ -116,7 +125,9 @@ fn tabs() -> Composer<ComposerGet, ComposerSet> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> { Ok(value) }
|
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> {
|
||||||
|
Ok(value)
|
||||||
|
}
|
||||||
|
|
||||||
Composer::new(get, set)
|
Composer::new(get, set)
|
||||||
}
|
}
|
||||||
|
|
@ -138,7 +149,9 @@ fn mode() -> Composer<ComposerGet, ComposerSet> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> { Ok(value) }
|
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> {
|
||||||
|
Ok(value)
|
||||||
|
}
|
||||||
|
|
||||||
Composer::new(get, set)
|
Composer::new(get, set)
|
||||||
}
|
}
|
||||||
|
|
@ -161,7 +174,9 @@ fn indicator() -> Composer<ComposerGet, ComposerSet> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> { Ok(value) }
|
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> {
|
||||||
|
Ok(value)
|
||||||
|
}
|
||||||
|
|
||||||
Composer::new(get, set)
|
Composer::new(get, set)
|
||||||
}
|
}
|
||||||
|
|
@ -198,7 +213,9 @@ fn status() -> Composer<ComposerGet, ComposerSet> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> { Ok(value) }
|
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> {
|
||||||
|
Ok(value)
|
||||||
|
}
|
||||||
|
|
||||||
Composer::new(get, set)
|
Composer::new(get, set)
|
||||||
}
|
}
|
||||||
|
|
@ -220,7 +237,9 @@ fn which() -> Composer<ComposerGet, ComposerSet> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> { Ok(value) }
|
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> {
|
||||||
|
Ok(value)
|
||||||
|
}
|
||||||
|
|
||||||
Composer::new(get, set)
|
Composer::new(get, set)
|
||||||
}
|
}
|
||||||
|
|
@ -247,7 +266,9 @@ fn confirm() -> Composer<ComposerGet, ComposerSet> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> { Ok(value) }
|
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> {
|
||||||
|
Ok(value)
|
||||||
|
}
|
||||||
|
|
||||||
Composer::new(get, set)
|
Composer::new(get, set)
|
||||||
}
|
}
|
||||||
|
|
@ -266,7 +287,9 @@ fn spot() -> Composer<ComposerGet, ComposerSet> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> { Ok(value) }
|
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> {
|
||||||
|
Ok(value)
|
||||||
|
}
|
||||||
|
|
||||||
Composer::new(get, set)
|
Composer::new(get, set)
|
||||||
}
|
}
|
||||||
|
|
@ -287,7 +310,9 @@ fn notify() -> Composer<ComposerGet, ComposerSet> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> { Ok(value) }
|
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> {
|
||||||
|
Ok(value)
|
||||||
|
}
|
||||||
|
|
||||||
Composer::new(get, set)
|
Composer::new(get, set)
|
||||||
}
|
}
|
||||||
|
|
@ -304,7 +329,9 @@ fn pick() -> Composer<ComposerGet, ComposerSet> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> { Ok(value) }
|
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> {
|
||||||
|
Ok(value)
|
||||||
|
}
|
||||||
|
|
||||||
Composer::new(get, set)
|
Composer::new(get, set)
|
||||||
}
|
}
|
||||||
|
|
@ -322,7 +349,9 @@ fn input() -> Composer<ComposerGet, ComposerSet> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> { Ok(value) }
|
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> {
|
||||||
|
Ok(value)
|
||||||
|
}
|
||||||
|
|
||||||
Composer::new(get, set)
|
Composer::new(get, set)
|
||||||
}
|
}
|
||||||
|
|
@ -343,7 +372,9 @@ fn cmp() -> Composer<ComposerGet, ComposerSet> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> { Ok(value) }
|
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> {
|
||||||
|
Ok(value)
|
||||||
|
}
|
||||||
|
|
||||||
Composer::new(get, set)
|
Composer::new(get, set)
|
||||||
}
|
}
|
||||||
|
|
@ -360,7 +391,9 @@ fn tasks() -> Composer<ComposerGet, ComposerSet> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> { Ok(value) }
|
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> {
|
||||||
|
Ok(value)
|
||||||
|
}
|
||||||
|
|
||||||
Composer::new(get, set)
|
Composer::new(get, set)
|
||||||
}
|
}
|
||||||
|
|
@ -380,7 +413,9 @@ fn help() -> Composer<ComposerGet, ComposerSet> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> { Ok(value) }
|
fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result<Value> {
|
||||||
|
Ok(value)
|
||||||
|
}
|
||||||
|
|
||||||
Composer::new(get, set)
|
Composer::new(get, set)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue