feat: size linemode supports showing the file count for directories (#1591)

This commit is contained in:
三咲雅 · Misaki Masa 2024-09-02 09:11:30 +08:00 committed by GitHub
parent 5f4779cc90
commit f2dca99e43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View File

@ -1,6 +1,7 @@
use std::ops::Deref;
use mlua::{AnyUserData, Lua, UserDataFields, UserDataMethods};
use yazi_plugin::url::UrlRef;
use super::{Config, Finder, Folder, Mode, Preview, Selected, SCOPE};
@ -41,6 +42,9 @@ impl Tab {
me.parent.as_ref().map(|f| Folder::make(None, f, me)).transpose()
});
reg.add_method("history", |_, me, url: UrlRef| {
me.history.get(&url).map(|f| Folder::make(None, f, me)).transpose()
});
reg.add_field_method_get("selected", |_, me| Selected::make(&me.selected));
reg.add_field_method_get("preview", |_, me| Preview::make(me));

View File

@ -24,7 +24,12 @@ end
function Linemode:size()
local size = self._file:size()
return ui.Line(size and ya.readable_size(size) or "")
if size then
return ui.Line(ya.readable_size(size))
else
local folder = cx.active:history(self._file.url)
return ui.Line(folder and tostring(#folder.files) or "")
end
end
function Linemode:ctime()