mirror of
https://github.com/sxyazi/yazi.git
synced 2024-12-25 09:46:37 +03:00
feat: suggest keywords in the header if a finder is active (#1847)
This commit is contained in:
parent
4dd24f779c
commit
e3507205fb
@ -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::<Self>(|_| {})
|
||||
lua.register_userdata_type::<Self>(|reg| {
|
||||
reg.add_meta_method(MetaMethod::ToString, |_, me, ()| Ok(me.filter.to_string()));
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -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 cwd = self._current.cwd
|
||||
local filter = self._current.files.filter
|
||||
local finder = self._tab.finder
|
||||
|
||||
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 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
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user