From a144cd8e736b7389193465c64293166b0265cc33 Mon Sep 17 00:00:00 2001 From: PFiS1737 Date: Mon, 10 Feb 2025 17:15:00 +0800 Subject: [PATCH] feat(statusline): make 0% and 100% percent format configurable --- yazi-config/preset/theme-dark.toml | 2 +- yazi-config/preset/theme-light.toml | 2 +- yazi-config/src/theme/theme.rs | 2 +- yazi-plugin/preset/components/status.lua | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/yazi-config/preset/theme-dark.toml b/yazi-config/preset/theme-dark.toml index 60fad20d9..eed740ca8 100644 --- a/yazi-config/preset/theme-dark.toml +++ b/yazi-config/preset/theme-dark.toml @@ -80,7 +80,7 @@ separator_left = [ "", "" ] separator_right = [ "", "" ] # Format -format_percent = "%2d%%" +format_percent = [ "Top", "%2d%%", "Bot" ] format_position = "%2d/%-2d" format_mode = "%.3s" diff --git a/yazi-config/preset/theme-light.toml b/yazi-config/preset/theme-light.toml index 1267bc336..b5e3e462e 100644 --- a/yazi-config/preset/theme-light.toml +++ b/yazi-config/preset/theme-light.toml @@ -80,7 +80,7 @@ separator_left = [ "", "" ] separator_right = [ "", "" ] # Format -format_percent = "%2d%%" +format_percent = [ "Top", "%2d%%", "Bot" ] format_position = "%2d/%-2d" format_mode = "%.3s" diff --git a/yazi-config/src/theme/theme.rs b/yazi-config/src/theme/theme.rs index b8204b3f7..ed44d485c 100644 --- a/yazi-config/src/theme/theme.rs +++ b/yazi-config/src/theme/theme.rs @@ -97,7 +97,7 @@ struct Status { pub separator_right: (String, String), // Format - pub format_percent: String, + pub format_percent: (String, String, String), pub format_position: String, pub format_mode: String, diff --git a/yazi-plugin/preset/components/status.lua b/yazi-plugin/preset/components/status.lua index e3fe6f53a..e6c29abf4 100644 --- a/yazi-plugin/preset/components/status.lua +++ b/yazi-plugin/preset/components/status.lua @@ -106,17 +106,17 @@ function Status:percent() end if percent == 0 then - percent = " Top " + percent = string.format(THEME.status.format_percent[1], percent) elseif percent == 100 then - percent = " Bot " + percent = string.format(THEME.status.format_percent[3], percent) else - percent = string.format(" " .. THEME.status.format_percent .. " ", percent) + percent = string.format(THEME.status.format_percent[2], percent) end local style = self:style() return ui.Line { ui.Span(" " .. THEME.status.separator_right[1]):fg(style.alt.bg), - ui.Span(percent):style(style.alt), + ui.Span(" " .. percent .. " "):style(style.alt), } end