diff --git a/yazi-fm/src/lives/finder.rs b/yazi-fm/src/lives/finder.rs index 1907064dd..a2e14a1a0 100644 --- a/yazi-fm/src/lives/finder.rs +++ b/yazi-fm/src/lives/finder.rs @@ -1,6 +1,6 @@ use std::ops::Deref; -use mlua::{AnyUserData, Lua}; +use mlua::{AnyUserData, Lua, MetaMethod, UserDataMethods}; use super::SCOPE; @@ -21,6 +21,8 @@ impl Finder { } pub(super) fn register(lua: &Lua) -> mlua::Result<()> { - lua.register_userdata_type::(|_| {}) + lua.register_userdata_type::(|reg| { + reg.add_meta_method(MetaMethod::ToString, |_, me, ()| Ok(me.filter.to_string())); + }) } } diff --git a/yazi-plugin/preset/components/header.lua b/yazi-plugin/preset/components/header.lua index a5e94ec55..2cf3289ff 100644 --- a/yazi-plugin/preset/components/header.lua +++ b/yazi-plugin/preset/components/header.lua @@ -17,6 +17,7 @@ function Header:new(area, tab) return setmetatable({ _area = area, _tab = tab, + _current = tab.current, }, { __index = self }) end @@ -26,22 +27,26 @@ function Header:cwd() return ui.Span("") end - local s = ya.readable_path(tostring(self._tab.current.cwd)) .. self:flags() + local s = ya.readable_path(tostring(self._current.cwd)) .. self:flags() return ui.Span(ya.truncate(s, { max = max, rtl = true })):style(THEME.manager.cwd) end function Header:flags() - local cwd = self._tab.current.cwd - local filter = self._tab.current.files.filter - - local s = cwd.is_search and string.format(" (search: %s", cwd:frag()) or "" - if not filter then - return s == "" and s or s .. ")" - elseif s == "" then - return string.format(" (filter: %s)", tostring(filter)) - else - return string.format("%s, filter: %s)", s, tostring(filter)) + local cwd = self._current.cwd + local filter = self._current.files.filter + local finder = self._tab.finder + + local t = {} + if cwd.is_search then + t[#t + 1] = string.format("search: %s", cwd:frag()) + end + if filter then + t[#t + 1] = string.format("filter: %s", filter) + end + if finder then + t[#t + 1] = string.format("find: %s", finder) end + return #t == 0 and "" or " (" .. table.concat(t, ", ") .. ")" end function Header:count() @@ -65,7 +70,7 @@ function Header:count() return ui.Line { ui.Span(string.format(" %d ", count)):style(style), - ui.Span(" "), + " ", } end diff --git a/yazi-plugin/preset/components/status.lua b/yazi-plugin/preset/components/status.lua index cede2de74..5fe7b5e04 100644 --- a/yazi-plugin/preset/components/status.lua +++ b/yazi-plugin/preset/components/status.lua @@ -20,6 +20,7 @@ function Status:new(area, tab) return setmetatable({ _area = area, _tab = tab, + _current = tab.current, }, { __index = self }) end @@ -45,7 +46,7 @@ function Status:mode() end function Status:size() - local h = self._tab.current.hovered + local h = self._current.hovered if not h then return ui.Line {} end @@ -58,7 +59,7 @@ function Status:size() end function Status:name() - local h = self._tab.current.hovered + local h = self._current.hovered if not h then return ui.Line {} end @@ -67,7 +68,7 @@ function Status:name() end function Status:permissions() - local h = self._tab.current.hovered + local h = self._current.hovered if not h then return ui.Line {} end @@ -97,8 +98,8 @@ end function Status:percentage() local percent = 0 - local cursor = self._tab.current.cursor - local length = #self._tab.current.files + local cursor = self._current.cursor + local length = #self._current.files if cursor ~= 0 and length ~= 0 then percent = math.floor((cursor + 1) * 100 / length) end @@ -119,8 +120,8 @@ function Status:percentage() end function Status:position() - local cursor = self._tab.current.cursor - local length = #self._tab.current.files + local cursor = self._current.cursor + local length = #self._current.files local style = self:style() return ui.Line {