mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00: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
3 changed files with 28 additions and 11 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{ffi::OsStr, ops::Range};
|
use std::{ffi::OsStr, fmt::Display, ops::Range};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use regex::bytes::{Regex, RegexBuilder};
|
use regex::bytes::{Regex, RegexBuilder};
|
||||||
|
|
@ -9,10 +9,6 @@ pub struct Filter {
|
||||||
regex: Regex,
|
regex: Regex,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq for Filter {
|
|
||||||
fn eq(&self, other: &Self) -> bool { self.raw == other.raw }
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Filter {
|
impl Filter {
|
||||||
pub fn new(s: &str, case: FilterCase) -> Result<Self> {
|
pub fn new(s: &str, case: FilterCase) -> Result<Self> {
|
||||||
let regex = match case {
|
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)]
|
#[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, MetaMethod, UserDataMethods};
|
||||||
|
|
||||||
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_meta_method(MetaMethod::ToString, |_, me, ()| Ok(me.to_string()));
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,22 @@ Header = {
|
||||||
}
|
}
|
||||||
|
|
||||||
function Header:cwd(max)
|
function Header:cwd(max)
|
||||||
local cwd = cx.active.current.cwd
|
local s = ya.readable_path(tostring(cx.active.current.cwd)) .. self:flags()
|
||||||
local readable = ya.readable_path(tostring(cwd))
|
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
|
function Header:flags()
|
||||||
return ui.Span(ya.truncate(text, { max = max, rtl = true })):style(THEME.manager.cwd)
|
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
|
end
|
||||||
|
|
||||||
function Header:count()
|
function Header:count()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue