From 5e48df5126a64c4753ce0034bc1a1667203de88b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20=C2=B7=20Misaki=20Masa?= Date: Tue, 26 Nov 2024 16:53:58 +0800 Subject: [PATCH] feat!: extend the available styles for `mode` by separating `mode` from the `separator` styles (#1953) --- README.md | 4 +- yazi-config/preset/theme+dark.toml | 5 ++- yazi-config/preset/theme+light.toml | 5 ++- .../preset/{theme.toml => theme-base.toml} | 41 ++++++++++++------- yazi-config/src/theme/theme.rs | 29 ++++++++----- yazi-macro/src/asset.rs | 4 +- yazi-plugin/preset/components/status.lua | 37 +++++++++-------- 7 files changed, 74 insertions(+), 51 deletions(-) rename yazi-config/preset/{theme.toml => theme-base.toml} (81%) diff --git a/README.md b/README.md index 01478be2b..42c33b514 100644 --- a/README.md +++ b/README.md @@ -18,12 +18,12 @@ Yazi (means "duck") is a terminal file manager written in Rust, based on non-blo - πŸ’ͺ **Powerful Async Task Scheduling and Management**: Provides real-time progress updates, task cancellation, and internal task priority assignment. - πŸ–ΌοΈ **Built-in Support for Multiple Image Protocols**: Also integrated with Überzug++ and Chafa, covering almost all terminals. - 🌟 **Built-in Code Highlighting and Image Decoding**: Combined with the pre-loading mechanism, greatly accelerates image and normal file loading. -- πŸ”Œ **Concurrent Plugin System**: UI plugins (rewriting most of the UI), functional plugins, custom previewer/preloader/fetcher; Just some pieces of Lua. +- πŸ”Œ **Concurrent Plugin System**: UI plugins (rewriting most of the UI), functional plugins, custom previewer/preloader/spotter/fetcher; Just some pieces of Lua. - πŸ“‘ **Data Distribution Service**: Built on a client-server architecture (no additional server process required), integrated with a Lua-based publish-subscribe model, achieving cross-instance communication and state persistence. - πŸ“¦ **Package Manager**: Install plugins and themes with one command, keeping them up to date, or pin them to a specific version. - 🧰 Integration with ripgrep, fd, fzf, zoxide - πŸ’« Vim-like input/pick/confirm/which/notify component, auto-completion for cd paths -- 🏷️ Multi-Tab Support, Cross-directory selection, Scrollable Preview (for videos, PDFs, archives, directories, code, etc.) +- 🏷️ Multi-Tab Support, Cross-directory selection, Scrollable Preview (for videos, PDFs, archives, code, directories, etc.) - πŸ”„ Bulk Renaming, Visual Mode, File Chooser - 🎨 Theme System, Mouse Support, Trash Bin, Custom Layouts, CSI u - ... and more! diff --git a/yazi-config/preset/theme+dark.toml b/yazi-config/preset/theme+dark.toml index 0cddb08ca..e57fe1d85 100644 --- a/yazi-config/preset/theme+dark.toml +++ b/yazi-config/preset/theme+dark.toml @@ -1,5 +1,6 @@ -# `theme+dark.toml` and `theme+light.toml` are additions to `theme.toml` and are considered part of it. -# If your terminal is in dark mode, `theme+dark.toml` will be applied *after* `theme.toml`; if it's in light mode, then `theme+light.toml` instead. +# If the user's terminal is in dark mode, Yazi will use the content from `theme-base.toml` + `theme+dark.toml` as the default theme; +# if it's in light mode, use `theme-base.toml` + `theme+light.toml` instead. +# Users can always override and adjust the default theme in their own `theme.toml` configuration file. "$schema" = "https://yazi-rs.github.io/schemas/theme.json" # vim:fileencoding=utf-8:foldmethod=marker diff --git a/yazi-config/preset/theme+light.toml b/yazi-config/preset/theme+light.toml index e2a09a688..9205532da 100644 --- a/yazi-config/preset/theme+light.toml +++ b/yazi-config/preset/theme+light.toml @@ -1,5 +1,6 @@ -# `theme+dark.toml` and `theme+light.toml` are additions to `theme.toml` and are considered part of it. -# If your terminal is in dark mode, `theme+dark.toml` will be applied *after* `theme.toml`; if it's in light mode, then `theme+light.toml` instead. +# If the user's terminal is in dark mode, Yazi will use the content from `theme-base.toml` + `theme+dark.toml` as the default theme; +# if it's in light mode, use `theme-base.toml` + `theme+light.toml` instead. +# Users can always override and adjust the default theme in their own `theme.toml` configuration file. "$schema" = "https://yazi-rs.github.io/schemas/theme.json" # vim:fileencoding=utf-8:foldmethod=marker diff --git a/yazi-config/preset/theme.toml b/yazi-config/preset/theme-base.toml similarity index 81% rename from yazi-config/preset/theme.toml rename to yazi-config/preset/theme-base.toml index c1160d13e..3c7bf625b 100644 --- a/yazi-config/preset/theme.toml +++ b/yazi-config/preset/theme-base.toml @@ -1,5 +1,6 @@ -# A TOML linter such as https://taplo.tamasfe.dev/ can use this schema to validate your config. -# If you encounter any issues, please make an issue at https://github.com/yazi-rs/schemas. +# If the user's terminal is in dark mode, Yazi will use the content from `theme-base.toml` + `theme+dark.toml` as the default theme; +# if it's in light mode, use `theme-base.toml` + `theme+light.toml` instead. +# Users can always override and adjust the default theme in their own `theme.toml` configuration file. "$schema" = "https://yazi-rs.github.io/schemas/theme.json" # vim:fileencoding=utf-8:foldmethod=marker @@ -51,17 +52,29 @@ syntect_theme = "" # : }}} -# : Status {{{ +# : Mode {{{ + +[mode] + +normal_main = { bg = "blue", bold = true } +normal_alt = { fg = "blue", bg = "gray" } + +# Select mode +select_main = { bg = "red", bold = true } +select_alt = { fg = "red", bg = "gray" } + +# Unset mode +unset_main = { bg = "red", bold = true } +unset_alt = { fg = "red", bg = "gray" } + +# : }}} + + +# : Status bar {{{ [status] separator_open = "ξ‚Ά" separator_close = "ξ‚΄" -separator_style = { fg = "gray", bg = "gray" } - -# Mode -mode_normal = { bg = "blue", bold = true } -mode_select = { bg = "red", bold = true } -mode_unset = { bg = "red", bold = true } # Progress progress_label = { bold = true } @@ -69,11 +82,11 @@ progress_normal = { fg = "blue", bg = "black" } progress_error = { fg = "red", bg = "black" } # Permissions -permissions_t = { fg = "green" } -permissions_r = { fg = "yellow" } -permissions_w = { fg = "red" } -permissions_x = { fg = "cyan" } -permissions_s = { fg = "darkgray" } +perm_sep = { fg = "darkgray" } +perm_type = { fg = "green" } +perm_read = { fg = "yellow" } +perm_write = { fg = "red" } +perm_exec = { fg = "cyan" } # : }}} diff --git a/yazi-config/src/theme/theme.rs b/yazi-config/src/theme/theme.rs index 6220dd6a3..c23e2ec86 100644 --- a/yazi-config/src/theme/theme.rs +++ b/yazi-config/src/theme/theme.rs @@ -11,6 +11,7 @@ use super::{Filetype, Flavor, Icons}; pub struct Theme { pub flavor: Flavor, pub manager: Manager, + mode: Mode, status: Status, pub input: Input, pub confirm: Confirm, @@ -77,16 +78,22 @@ pub struct Manager { pub syntect_theme: PathBuf, } +#[derive(Deserialize, Serialize)] +struct Mode { + pub normal_main: Style, + pub normal_alt: Style, + + pub select_main: Style, + pub select_alt: Style, + + pub unset_main: Style, + pub unset_alt: Style, +} + #[derive(Deserialize, Serialize)] struct Status { pub separator_open: String, pub separator_close: String, - pub separator_style: Style, - - // Mode - pub mode_normal: Style, - pub mode_select: Style, - pub mode_unset: Style, // Progress pub progress_label: Style, @@ -94,11 +101,11 @@ struct Status { pub progress_error: Style, // Permissions - pub permissions_t: Style, - pub permissions_r: Style, - pub permissions_w: Style, - pub permissions_x: Style, - pub permissions_s: Style, + pub perm_sep: Style, + pub perm_type: Style, + pub perm_read: Style, + pub perm_write: Style, + pub perm_exec: Style, } #[derive(Deserialize, Serialize)] diff --git a/yazi-macro/src/asset.rs b/yazi-macro/src/asset.rs index a46ccfa16..b08a60e2f 100644 --- a/yazi-macro/src/asset.rs +++ b/yazi-macro/src/asset.rs @@ -50,12 +50,12 @@ macro_rules! theme_preset { ".toml" )) .expect(concat!("Failed to read 'yazi-config/preset/theme+", $name, ".toml'")); - std::borrow::Cow::from(format!("{}\n{append}", &$crate::config_preset!("theme"))) + std::borrow::Cow::from(format!("{}\n{append}", &$crate::config_preset!("theme-base"))) } #[cfg(not(debug_assertions))] { std::borrow::Cow::from(concat!( - include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/preset/theme.toml")), + include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/preset/theme-base.toml")), "\n", include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/preset/theme+", $name, ".toml")) )) diff --git a/yazi-plugin/preset/components/status.lua b/yazi-plugin/preset/components/status.lua index 3fc880310..d4727bf08 100644 --- a/yazi-plugin/preset/components/status.lua +++ b/yazi-plugin/preset/components/status.lua @@ -25,12 +25,13 @@ function Status:new(area, tab) end function Status:style() + local m = THEME.mode if self._tab.mode.is_select then - return THEME.status.mode_select + return { main = m.select_main, alt = m.select_alt } elseif self._tab.mode.is_unset then - return THEME.status.mode_unset + return { main = m.unset_main, alt = m.unset_alt } else - return THEME.status.mode_normal + return { main = m.normal_main, alt = m.normal_alt } end end @@ -39,9 +40,9 @@ function Status:mode() local style = self:style() return ui.Line { - ui.Span(THEME.status.separator_open):fg(style.bg), - ui.Span(" " .. mode .. " "):style(style), - ui.Span(THEME.status.separator_close):fg(style.bg):bg(THEME.status.separator_style.fg), + ui.Span(THEME.status.separator_open):fg(style.main.bg), + ui.Span(" " .. mode .. " "):style(style.main), + ui.Span(THEME.status.separator_close):fg(style.main.bg):bg(style.alt.bg), } end @@ -53,8 +54,8 @@ function Status:size() local style = self:style() return ui.Line { - ui.Span(" " .. ya.readable_size(h:size() or h.cha.len) .. " "):fg(style.bg):bg(THEME.status.separator_style.bg), - ui.Span(THEME.status.separator_close):fg(THEME.status.separator_style.fg), + ui.Span(" " .. ya.readable_size(h:size() or h.cha.len) .. " "):style(style.alt), + ui.Span(THEME.status.separator_close):fg(style.alt.bg), } end @@ -81,15 +82,15 @@ function Status:perm() local spans = {} for i = 1, #perm do local c = perm:sub(i, i) - local style = THEME.status.permissions_t + local style = THEME.status.perm_type if c == "-" or c == "?" then - style = THEME.status.permissions_s + style = THEME.status.perm_sep elseif c == "r" then - style = THEME.status.permissions_r + style = THEME.status.perm_read elseif c == "w" then - style = THEME.status.permissions_w + style = THEME.status.perm_write elseif c == "x" or c == "s" or c == "S" or c == "t" or c == "T" then - style = THEME.status.permissions_x + style = THEME.status.perm_exec end spans[i] = ui.Span(c):style(style) end @@ -114,8 +115,8 @@ function Status:percent() local style = self:style() return ui.Line { - ui.Span(" " .. THEME.status.separator_open):fg(THEME.status.separator_style.fg), - ui.Span(percent):fg(style.bg):bg(THEME.status.separator_style.bg), + ui.Span(" " .. THEME.status.separator_open):fg(style.alt.bg), + ui.Span(percent):style(style.alt), } end @@ -125,9 +126,9 @@ function Status:position() local style = self:style() return ui.Line { - ui.Span(THEME.status.separator_open):fg(style.bg):bg(THEME.status.separator_style.fg), - ui.Span(string.format(" %2d/%-2d ", math.min(cursor + 1, length), length)):style(style), - ui.Span(THEME.status.separator_close):fg(style.bg), + ui.Span(THEME.status.separator_open):fg(style.main.bg):bg(style.alt.bg), + ui.Span(string.format(" %2d/%-2d ", math.min(cursor + 1, length), length)):style(style.main), + ui.Span(THEME.status.separator_close):fg(style.main.bg), } end