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:
Chris Schade 2024-06-22 09:52:09 +02:00
parent f5a7aceac0
commit ed8b30b81d
3 changed files with 15 additions and 4 deletions

View file

@ -1,4 +1,4 @@
use std::{ffi::OsStr, ops::Range};
use std::{ffi::OsStr, fmt::{Display, Error}, ops::Range};
use anyhow::Result;
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)]
pub enum FilterCase {
Smart,

View file

@ -1,6 +1,6 @@
use std::ops::Deref;
use mlua::{AnyUserData, Lua};
use mlua::{AnyUserData, Lua, UserDataFields};
use super::SCOPE;
@ -21,6 +21,8 @@ impl Filter {
}
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()));
})
}
}

View file

@ -5,8 +5,13 @@ Header = {
function Header:cwd(max)
local cwd = cx.active.current.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)
end