Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: suggest keywords in the header if a finder is active #1847

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions yazi-fm/src/lives/finder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::ops::Deref;

use mlua::{AnyUserData, Lua};
use mlua::{AnyUserData, Lua, MetaMethod, UserDataMethods};

use super::SCOPE;

Expand All @@ -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()));
})
}
}
29 changes: 17 additions & 12 deletions yazi-plugin/preset/components/header.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function Header:new(area, tab)
return setmetatable({
_area = area,
_tab = tab,
_current = tab.current,
}, { __index = self })
end

Expand All @@ -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()
Expand All @@ -65,7 +70,7 @@ function Header:count()

return ui.Line {
ui.Span(string.format(" %d ", count)):style(style),
ui.Span(" "),
" ",
}
end

Expand Down
15 changes: 8 additions & 7 deletions yazi-plugin/preset/components/status.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function Status:new(area, tab)
return setmetatable({
_area = area,
_tab = tab,
_current = tab.current,
}, { __index = self })
end

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down