From 8ce8831ef573e3a341ab08f5acd9bf658ba9afb7 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Sun, 1 Sep 2024 10:51:03 +0800 Subject: [PATCH] Refactor --- yazi-plugin/preset/components/entity.lua | 17 ++++++++++------- yazi-plugin/preset/components/linemode.lua | 16 +++++++--------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/yazi-plugin/preset/components/entity.lua b/yazi-plugin/preset/components/entity.lua index a0a6dfc6..0cf2e951 100644 --- a/yazi-plugin/preset/components/entity.lua +++ b/yazi-plugin/preset/components/entity.lua @@ -1,24 +1,27 @@ Entity = { _inc = 1000, _children = { - { "icon", id = 1, order = 1000 }, - { "prefix", id = 2, order = 2000 }, - { "highlights", id = 3, order = 3000 }, - { "found", id = 4, order = 4000 }, - { "symlink", id = 5, order = 5000 }, + { "space", id = 1, order = 1000 }, + { "icon", id = 2, order = 2000 }, + { "prefix", id = 3, order = 3000 }, + { "highlights", id = 4, order = 4000 }, + { "found", id = 5, order = 5000 }, + { "symlink", id = 6, order = 6000 }, }, } function Entity:new(file) return setmetatable({ _file = file }, { __index = self }) end +function Entity:space() return ui.Line(" ") end + function Entity:icon() local icon = self._file:icon() if not icon then return ui.Line("") elseif self._file:is_hovered() then - return ui.Line(" " .. icon.text .. " ") + return ui.Line(icon.text .. " ") else - return ui.Line(" " .. icon.text .. " "):style(icon.style) + return ui.Line(icon.text .. " "):style(icon.style) end end diff --git a/yazi-plugin/preset/components/linemode.lua b/yazi-plugin/preset/components/linemode.lua index 79a0c83e..6aa1a09b 100644 --- a/yazi-plugin/preset/components/linemode.lua +++ b/yazi-plugin/preset/components/linemode.lua @@ -2,22 +2,23 @@ Linemode = { _inc = 1000, _children = { { "solo", id = 1, order = 1000 }, + { "space", id = 2, order = 2000 }, }, } function Linemode:new(file) return setmetatable({ _file = file }, { __index = self }) end +function Linemode:space() return ui.Line(" ") end + function Linemode:solo() local mode = cx.active.conf.linemode if mode == "none" or mode == "solo" then return ui.Line("") + elseif self[mode] then + return ui.Line { ui.Span(" "), self[mode](self) } + else + return ui.Line(" " .. mode) end - - if not self[mode] then - return ui.Line(mode) - end - - return ui.Line { self[mode](self) } end function Linemode:size() @@ -59,9 +60,6 @@ function Linemode:render() local lines = {} for _, c in ipairs(self._children) do lines[#lines + 1] = (type(c[1]) == "string" and self[c[1]] or c[1])(self) - if lines[#lines] and lines[#lines]:width() > 0 then - lines[#lines + 1] = ui.Line { ui.Span(" ") } - end end return ui.Line(lines) end