From 345dd935225c4043bcaab4135d2390673d79a605 Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 6 Dec 2024 07:12:32 +0100 Subject: [PATCH 1/2] feat: theme support for the spotter Allows changing the colors of https://github.com/sxyazi/yazi/pull/1802. Fixes #1986. --- yazi-config/preset/theme-dark.toml | 8 ++++++++ yazi-config/preset/theme-light.toml | 9 +++++++++ yazi-config/src/theme/theme.rs | 7 +++++++ yazi-plugin/src/utils/spot.rs | 6 +++--- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/yazi-config/preset/theme-dark.toml b/yazi-config/preset/theme-dark.toml index 1457cc2ae..953409597 100644 --- a/yazi-config/preset/theme-dark.toml +++ b/yazi-config/preset/theme-dark.toml @@ -128,6 +128,14 @@ btn_labels = [ " [Y]es ", " (N)o " ] # : }}} +# : Spot {{{ + +[spot] +border = { fg = "blue" } +title = { fg = "blue" } + +# : }}} + # : Completion {{{ [completion] diff --git a/yazi-config/preset/theme-light.toml b/yazi-config/preset/theme-light.toml index abe33d571..158802fd0 100644 --- a/yazi-config/preset/theme-light.toml +++ b/yazi-config/preset/theme-light.toml @@ -128,6 +128,15 @@ btn_labels = [ " [Y]es ", " (N)o " ] # : }}} +# : Spot {{{ + +[spot] +border = { fg = "blue" } +title = { fg = "blue" } + +# : }}} + + # : Completion {{{ [completion] diff --git a/yazi-config/src/theme/theme.rs b/yazi-config/src/theme/theme.rs index c23e2ec86..962f10dd0 100644 --- a/yazi-config/src/theme/theme.rs +++ b/yazi-config/src/theme/theme.rs @@ -15,6 +15,7 @@ pub struct Theme { status: Status, pub input: Input, pub confirm: Confirm, + pub spot: Spot, pub pick: Pick, pub completion: Completion, pub tasks: Tasks, @@ -127,6 +128,12 @@ pub struct Confirm { pub btn_labels: [String; 2], } +#[derive(Deserialize, Serialize)] +pub struct Spot { + pub border: Style, + pub title: Style, +} + #[derive(Deserialize, Serialize)] pub struct Pick { pub border: Style, diff --git a/yazi-plugin/src/utils/spot.rs b/yazi-plugin/src/utils/spot.rs index a08a55bdd..b0029dde1 100644 --- a/yazi-plugin/src/utils/spot.rs +++ b/yazi-plugin/src/utils/spot.rs @@ -1,5 +1,5 @@ use mlua::{AnyUserData, Function, Lua, Table}; -use ratatui::style::Stylize; +use yazi_config::THEME; use yazi_macro::emit; use yazi_shared::{Layer, event::Cmd}; @@ -70,10 +70,10 @@ impl Utils { area, position: ratatui::widgets::Borders::ALL, type_: ratatui::widgets::BorderType::Rounded, - style: ratatui::style::Style::default().blue(), + style: ratatui::style::Style::from(THEME.spot.border), titles: vec![( ratatui::widgets::block::Position::Top, - ratatui::text::Line::raw(lock.url.name().to_string_lossy().into_owned()).centered(), + ratatui::text::Line::raw(lock.url.name().to_string_lossy().into_owned()).centered().style(THEME.spot.title), )], }), Renderable::Table(table), From 3fa16c59fb7addce307febe291f84a158fc069fa Mon Sep 17 00:00:00 2001 From: sxyazi Date: Sat, 21 Dec 2024 00:14:48 +0800 Subject: [PATCH 2/2] Format --- yazi-config/preset/theme-dark.toml | 100 ++++++++++++++-------------- yazi-config/preset/theme-light.toml | 99 +++++++++++++-------------- yazi-config/src/theme/theme.rs | 66 +++++++++--------- yazi-plugin/src/utils/spot.rs | 6 +- 4 files changed, 138 insertions(+), 133 deletions(-) diff --git a/yazi-config/preset/theme-dark.toml b/yazi-config/preset/theme-dark.toml index 953409597..65f7ff73e 100644 --- a/yazi-config/preset/theme-dark.toml +++ b/yazi-config/preset/theme-dark.toml @@ -15,6 +15,7 @@ light = "" # : }}} + # : Manager {{{ [manager] @@ -93,28 +94,21 @@ perm_exec = { fg = "cyan" } # : }}} -# : Pick {{{ - -[pick] -border = { fg = "blue" } -active = { fg = "magenta", bold = true } -inactive = {} - -# : }}} - - -# : Input {{{ +# : Which {{{ -[input] -border = { fg = "blue" } -title = {} -value = {} -selected = { reversed = true } +[which] +cols = 3 +mask = { bg = "black" } +cand = { fg = "lightcyan" } +rest = { fg = "darkgray" } +desc = { fg = "lightmagenta" } +separator = "  " +separator_style = { fg = "darkgray" } # : }}} -# : Confirm {{{ +# : Confirmation {{{ [confirm] border = { fg = "blue" } @@ -128,7 +122,7 @@ btn_labels = [ " [Y]es ", " (N)o " ] # : }}} -# : Spot {{{ +# : Spotter {{{ [spot] border = { fg = "blue" } @@ -136,6 +130,43 @@ title = { fg = "blue" } # : }}} + +# : Notification {{{ + +[notify] +title_info = { fg = "green" } +title_warn = { fg = "yellow" } +title_error = { fg = "red" } + +# Icons +icon_info = "" +icon_warn = "" +icon_error = "" + +# : }}} + + +# : Picker {{{ + +[pick] +border = { fg = "blue" } +active = { fg = "magenta", bold = true } +inactive = {} + +# : }}} + + +# : Input {{{ + +[input] +border = { fg = "blue" } +title = {} +value = {} +selected = { reversed = true } + +# : }}} + + # : Completion {{{ [completion] @@ -151,7 +182,7 @@ icon_command = "" # : }}} -# : Tasks {{{ +# : Task manager {{{ [tasks] border = { fg = "blue" } @@ -161,21 +192,7 @@ hovered = { fg = "magenta", underline = true } # : }}} -# : Which {{{ - -[which] -cols = 3 -mask = { bg = "black" } -cand = { fg = "lightcyan" } -rest = { fg = "darkgray" } -desc = { fg = "lightmagenta" } -separator = "  " -separator_style = { fg = "darkgray" } - -# : }}} - - -# : Help {{{ +# : Help menu {{{ [help] on = { fg = "cyan" } @@ -187,21 +204,6 @@ footer = { fg = "black", bg = "white" } # : }}} -# : Notify {{{ - -[notify] -title_info = { fg = "green" } -title_warn = { fg = "yellow" } -title_error = { fg = "red" } - -# Icons -icon_info = "" -icon_warn = "" -icon_error = "" - -# : }}} - - # : File-specific styles {{{ [filetype] diff --git a/yazi-config/preset/theme-light.toml b/yazi-config/preset/theme-light.toml index 158802fd0..76cd827be 100644 --- a/yazi-config/preset/theme-light.toml +++ b/yazi-config/preset/theme-light.toml @@ -15,6 +15,7 @@ light = "" # : }}} + # : Manager {{{ [manager] @@ -93,28 +94,21 @@ perm_exec = { fg = "cyan" } # : }}} -# : Pick {{{ - -[pick] -border = { fg = "blue" } -active = { fg = "magenta", bold = true } -inactive = {} - -# : }}} - - -# : Input {{{ +# : Which {{{ -[input] -border = { fg = "blue" } -title = {} -value = {} -selected = { reversed = true } +[which] +cols = 3 +mask = { bg = "black" } +cand = { fg = "lightcyan" } +rest = { fg = "darkgray" } +desc = { fg = "lightmagenta" } +separator = "  " +separator_style = { fg = "darkgray" } # : }}} -# : Confirm {{{ +# : Confirmation {{{ [confirm] border = { fg = "blue" } @@ -128,7 +122,7 @@ btn_labels = [ " [Y]es ", " (N)o " ] # : }}} -# : Spot {{{ +# : Spotter {{{ [spot] border = { fg = "blue" } @@ -137,6 +131,42 @@ title = { fg = "blue" } # : }}} +# : Notification {{{ + +[notify] +title_info = { fg = "green" } +title_warn = { fg = "yellow" } +title_error = { fg = "red" } + +# Icons +icon_info = "" +icon_warn = "" +icon_error = "" + +# : }}} + + +# : Picker {{{ + +[pick] +border = { fg = "blue" } +active = { fg = "magenta", bold = true } +inactive = {} + +# : }}} + + +# : Input {{{ + +[input] +border = { fg = "blue" } +title = {} +value = {} +selected = { reversed = true } + +# : }}} + + # : Completion {{{ [completion] @@ -152,7 +182,7 @@ icon_command = "" # : }}} -# : Tasks {{{ +# : Task manager {{{ [tasks] border = { fg = "blue" } @@ -162,21 +192,7 @@ hovered = { fg = "magenta", underline = true } # : }}} -# : Which {{{ - -[which] -cols = 3 -mask = { bg = "black" } -cand = { fg = "lightcyan" } -rest = { fg = "darkgray" } -desc = { fg = "lightmagenta" } -separator = "  " -separator_style = { fg = "darkgray" } - -# : }}} - - -# : Help {{{ +# : Help menu {{{ [help] on = { fg = "cyan" } @@ -188,21 +204,6 @@ footer = { fg = "black", bg = "white" } # : }}} -# : Notify {{{ - -[notify] -title_info = { fg = "green" } -title_warn = { fg = "yellow" } -title_error = { fg = "red" } - -# Icons -icon_info = "" -icon_warn = "" -icon_error = "" - -# : }}} - - # : File-specific styles {{{ [filetype] diff --git a/yazi-config/src/theme/theme.rs b/yazi-config/src/theme/theme.rs index 962f10dd0..cb7ddfd33 100644 --- a/yazi-config/src/theme/theme.rs +++ b/yazi-config/src/theme/theme.rs @@ -13,15 +13,15 @@ pub struct Theme { pub manager: Manager, mode: Mode, status: Status, - pub input: Input, + pub which: Which, pub confirm: Confirm, pub spot: Spot, + pub notify: Notify, pub pick: Pick, + pub input: Input, pub completion: Completion, pub tasks: Tasks, - pub which: Which, pub help: Help, - pub notify: Notify, // File-specific styles #[serde(rename = "filetype", deserialize_with = "Filetype::deserialize", skip_serializing)] @@ -109,12 +109,17 @@ struct Status { pub perm_exec: Style, } -#[derive(Deserialize, Serialize)] -pub struct Input { - pub border: Style, - pub title: Style, - pub value: Style, - pub selected: Style, +#[derive(Deserialize, Serialize, Validate)] +pub struct Which { + #[validate(range(min = 1, max = 3, message = "Must be between 1 and 3"))] + pub cols: u8, + pub mask: Style, + pub cand: Style, + pub rest: Style, + pub desc: Style, + + pub separator: String, + pub separator_style: Style, } #[derive(Deserialize, Serialize)] @@ -134,6 +139,17 @@ pub struct Spot { pub title: Style, } +#[derive(Deserialize, Serialize)] +pub struct Notify { + pub title_info: Style, + pub title_warn: Style, + pub title_error: Style, + + pub icon_info: String, + pub icon_warn: String, + pub icon_error: String, +} + #[derive(Deserialize, Serialize)] pub struct Pick { pub border: Style, @@ -141,6 +157,14 @@ pub struct Pick { pub inactive: Style, } +#[derive(Deserialize, Serialize)] +pub struct Input { + pub border: Style, + pub title: Style, + pub value: Style, + pub selected: Style, +} + #[derive(Deserialize, Serialize)] pub struct Completion { pub border: Style, @@ -159,19 +183,6 @@ pub struct Tasks { pub hovered: Style, } -#[derive(Deserialize, Serialize, Validate)] -pub struct Which { - #[validate(range(min = 1, max = 3, message = "Must be between 1 and 3"))] - pub cols: u8, - pub mask: Style, - pub cand: Style, - pub rest: Style, - pub desc: Style, - - pub separator: String, - pub separator_style: Style, -} - #[derive(Deserialize, Serialize)] pub struct Help { pub on: Style, @@ -181,14 +192,3 @@ pub struct Help { pub hovered: Style, pub footer: Style, } - -#[derive(Deserialize, Serialize)] -pub struct Notify { - pub title_info: Style, - pub title_warn: Style, - pub title_error: Style, - - pub icon_info: String, - pub icon_warn: String, - pub icon_error: String, -} diff --git a/yazi-plugin/src/utils/spot.rs b/yazi-plugin/src/utils/spot.rs index b0029dde1..0ee8ece65 100644 --- a/yazi-plugin/src/utils/spot.rs +++ b/yazi-plugin/src/utils/spot.rs @@ -70,10 +70,12 @@ impl Utils { area, position: ratatui::widgets::Borders::ALL, type_: ratatui::widgets::BorderType::Rounded, - style: ratatui::style::Style::from(THEME.spot.border), + style: THEME.spot.border.into(), titles: vec![( ratatui::widgets::block::Position::Top, - ratatui::text::Line::raw(lock.url.name().to_string_lossy().into_owned()).centered().style(THEME.spot.title), + ratatui::text::Line::raw(lock.url.name().to_string_lossy().into_owned()) + .centered() + .style(THEME.spot.title), )], }), Renderable::Table(table),