mirror of
https://github.com/sxyazi/yazi.git
synced 2024-11-24 09:53:12 +03:00
feat: include file filter state in the header (#1182)
Co-authored-by: sxyazi <sxyazi@gmail.com>
This commit is contained in:
parent
f5a7aceac0
commit
505de05d66
@ -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<Self> {
|
||||
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,
|
||||
|
@ -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::<Self>(|_| {})
|
||||
lua.register_userdata_type::<Self>(|reg| {
|
||||
reg.add_meta_method(MetaMethod::ToString, |_, me, ()| Ok(me.to_string()));
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user