mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Show 'filter' in header when applied (see #1181)
Header now shows filter when it is applied, as it did with search.
This commit is contained in:
parent
f5a7aceac0
commit
ed8b30b81d
3 changed files with 15 additions and 4 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{ffi::OsStr, ops::Range};
|
use std::{ffi::OsStr, fmt::{Display, Error}, ops::Range};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use regex::bytes::{Regex, RegexBuilder};
|
use regex::bytes::{Regex, RegexBuilder};
|
||||||
|
|
@ -35,6 +35,10 @@ impl Filter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Display for Filter {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), Error> { f.write_str(&self.raw) }
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Default, PartialEq, Eq)]
|
#[derive(Default, PartialEq, Eq)]
|
||||||
pub enum FilterCase {
|
pub enum FilterCase {
|
||||||
Smart,
|
Smart,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
use mlua::{AnyUserData, Lua};
|
use mlua::{AnyUserData, Lua, UserDataFields};
|
||||||
|
|
||||||
use super::SCOPE;
|
use super::SCOPE;
|
||||||
|
|
||||||
|
|
@ -21,6 +21,8 @@ impl Filter {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn register(lua: &Lua) -> mlua::Result<()> {
|
pub(super) fn register(lua: &Lua) -> mlua::Result<()> {
|
||||||
lua.register_userdata_type::<Self>(|_| {})
|
lua.register_userdata_type::<Self>(|reg| {
|
||||||
|
reg.add_field_method_get("to_string", |_, me| Ok(me.to_string()));
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,13 @@ Header = {
|
||||||
function Header:cwd(max)
|
function Header:cwd(max)
|
||||||
local cwd = cx.active.current.cwd
|
local cwd = cx.active.current.cwd
|
||||||
local readable = ya.readable_path(tostring(cwd))
|
local readable = ya.readable_path(tostring(cwd))
|
||||||
|
local files = cx.active.current.files
|
||||||
|
|
||||||
|
local search = cwd.is_search and string.format(" (search: %s)", cwd:frag()) or ""
|
||||||
|
local filter = files.filter and string.format(" (filter: %s)", files.filter.to_string) or ""
|
||||||
|
|
||||||
|
local text = string.format("%s%s%s", readable, search, filter)
|
||||||
|
|
||||||
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)
|
return ui.Span(ya.truncate(text, { max = max, rtl = true })):style(THEME.manager.cwd)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue