This commit is contained in:
sxyazi 2026-03-12 16:11:32 +08:00
parent 6ca1c6315a
commit 93604362d7
No known key found for this signature in database
4 changed files with 12 additions and 6 deletions

View file

@ -31,7 +31,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/):
- New `ind-which-activate` DDS event to change the which component behavior ([#3608])
- New `hey` DDS event fires when static messages are restored from persistence ([#3725])
- New `cx.which` API to access the which component state ([#3617])
- New experimental `ya.co()` API that creates a coroutine ([#1234])
- New experimental `ya.co()` API that creates a coroutine ([#3757])
### Changed
@ -1681,3 +1681,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/):
[#3733]: https://github.com/sxyazi/yazi/pull/3733
[#3744]: https://github.com/sxyazi/yazi/pull/3744
[#3748]: https://github.com/sxyazi/yazi/pull/3748
[#3757]: https://github.com/sxyazi/yazi/pull/3757

View file

@ -50,7 +50,7 @@ function M:seek(job)
end
function M:spot(job)
local i = 0
local i, url = 0, job.file.url
for rows in self:spot_base(job) do
i, rows[#rows + 1] = i + 1, ui.Row {}
ya.spot_table(
@ -64,6 +64,9 @@ function M:spot(job)
:widths { ui.Constraint.Length(14), ui.Constraint.Fill(1) }
)
end
if self.size then
ya.emit("update_files", { op = fs.op("size", { url = url.parent, sizes = { [url.urn] = self.size } }) })
end
end
function M:spot_base(job)
@ -74,6 +77,7 @@ function M:spot_base(job)
}
end
self.size = nil
return ya.co(function()
yield("0B (?)")
@ -94,6 +98,7 @@ function M:spot_base(job)
end
end
self.size = size
yield(ya.readable_size(size))
end)
end

View file

@ -45,7 +45,7 @@ function M:spot_base(_, selected)
while it do
local next, now = it:recv(), ya.time()
if not next then
self.sizes[url] = it.cha.is_dir and size
self.sizes[url] = it.cha.is_dir and size or nil
break
elseif now >= last + 0.1 then
last, size, sum = now, size + next, sum + next

View file

@ -15,15 +15,15 @@ impl Utils {
pub(super) fn co(lua: &Lua) -> mlua::Result<Function> {
lua.create_function(|lua, f: Function| {
let thread = lua.create_thread(f)?;
lua.create_async_function(move |lua, args: MultiValue| {
lua.create_async_function(move |lua, mut args: MultiValue| {
let thread = thread.clone();
async move {
loop {
let values: MultiValue = thread.resume(&args)?;
let values: MultiValue = thread.resume(args)?;
if let Some(Value::LightUserData(ud)) = values.get(0)
&& *ud == Lua::poll_pending()
{
lua.yield_with::<()>(values).await?;
args = lua.yield_with(values).await?;
} else {
return Ok(values);
}