diff --git a/yazi-core/src/folder/filter.rs b/yazi-core/src/folder/filter.rs index 8d7ca45e..290b0067 100644 --- a/yazi-core/src/folder/filter.rs +++ b/yazi-core/src/folder/filter.rs @@ -1,4 +1,4 @@ -use std::{ffi::OsStr, ops::Range}; +use std::{ffi::OsStr, fmt::Display, ops::Range}; use anyhow::Result; use regex::bytes::{Regex, RegexBuilder}; @@ -9,10 +9,6 @@ pub struct Filter { regex: Regex, } -impl PartialEq for Filter { - fn eq(&self, other: &Self) -> bool { self.raw == other.raw } -} - impl Filter { pub fn new(s: &str, case: FilterCase) -> Result { let regex = match case { @@ -35,6 +31,14 @@ impl Filter { } } +impl PartialEq for Filter { + fn eq(&self, other: &Self) -> bool { self.raw == other.raw } +} + +impl Display for Filter { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(&self.raw) } +} + #[derive(Default, PartialEq, Eq)] pub enum FilterCase { Smart, diff --git a/yazi-fm/src/lives/filter.rs b/yazi-fm/src/lives/filter.rs index 1f7c66dc..79c9119c 100644 --- a/yazi-fm/src/lives/filter.rs +++ b/yazi-fm/src/lives/filter.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 Filter { } 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.to_string())); + }) } } diff --git a/yazi-plugin/preset/components/header.lua b/yazi-plugin/preset/components/header.lua index 2443a065..d973266d 100644 --- a/yazi-plugin/preset/components/header.lua +++ b/yazi-plugin/preset/components/header.lua @@ -3,11 +3,22 @@ Header = { } function Header:cwd(max) - local cwd = cx.active.current.cwd - local readable = ya.readable_path(tostring(cwd)) + local s = ya.readable_path(tostring(cx.active.current.cwd)) .. self:flags() + return ui.Span(ya.truncate(s, { max = max, rtl = true })):style(THEME.manager.cwd) +end - local text = cwd.is_search and string.format("%s (search: %s)", readable, cwd:frag()) or readable - return ui.Span(ya.truncate(text, { max = max, rtl = true })):style(THEME.manager.cwd) +function Header:flags() + local cwd = cx.active.current.cwd + local filter = cx.active.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)) + end end function Header:count()