mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
19b484a744
commit
a35ccf49be
3 changed files with 21 additions and 18 deletions
15
yazi-plugin/src/bindings/calculator.rs
Normal file
15
yazi-plugin/src/bindings/calculator.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
use mlua::{IntoLuaMulti, UserData, UserDataMethods, Value};
|
||||
use yazi_binding::Error;
|
||||
|
||||
pub struct SizeCalculator(pub yazi_fs::SizeCalculator);
|
||||
|
||||
impl UserData for SizeCalculator {
|
||||
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
||||
methods.add_async_method_mut("recv", |lua, mut me, ()| async move {
|
||||
match me.0.next().await {
|
||||
Ok(value) => (value, Value::Nil).into_lua_multi(&lua),
|
||||
Err(e) => (Value::Nil, Error::Io(e)).into_lua_multi(&lua),
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
#![allow(clippy::module_inception)]
|
||||
|
||||
yazi_macro::mod_flat!(cha chan icon image input layer mouse permit range receiver);
|
||||
yazi_macro::mod_flat!(calculator cha chan icon image input layer mouse permit range receiver);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
use globset::GlobBuilder;
|
||||
use mlua::{ExternalError, ExternalResult, Function, IntoLua, IntoLuaMulti, Lua, Table, UserData, UserDataMethods, Value};
|
||||
use mlua::{ExternalError, ExternalResult, Function, IntoLua, IntoLuaMulti, Lua, Table, Value};
|
||||
use tokio::fs;
|
||||
use yazi_binding::{Error, Url, UrlRef};
|
||||
use yazi_fs::{SizeCalculator, mounts::PARTITIONS, remove_dir_clean};
|
||||
use yazi_fs::{mounts::PARTITIONS, remove_dir_clean};
|
||||
|
||||
use crate::{Composer, bindings::Cha, file::File};
|
||||
use crate::{Composer, bindings::{Cha, SizeCalculator}, file::File};
|
||||
|
||||
pub fn compose(lua: &Lua) -> mlua::Result<Value> {
|
||||
Composer::make(lua, 10, |lua, key| {
|
||||
|
|
@ -155,20 +155,8 @@ fn read_dir(lua: &Lua) -> mlua::Result<Function> {
|
|||
|
||||
fn calc_size(lua: &Lua) -> mlua::Result<Function> {
|
||||
lua.create_async_function(|lua, url: UrlRef| async move {
|
||||
struct Wrapper(SizeCalculator);
|
||||
impl UserData for Wrapper {
|
||||
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
||||
methods.add_async_method_mut("recv", |lua, mut me, ()| async move {
|
||||
match me.0.next().await {
|
||||
Ok(value) => (value, Value::Nil).into_lua_multi(&lua),
|
||||
Err(e) => (Value::Nil, Error::Io(e)).into_lua_multi(&lua),
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
match SizeCalculator::new(&*url).await {
|
||||
Ok(it) => Wrapper(it).into_lua_multi(&lua),
|
||||
match yazi_fs::SizeCalculator::new(&*url).await {
|
||||
Ok(it) => SizeCalculator(it).into_lua_multi(&lua),
|
||||
Err(e) => (Value::Nil, Error::Io(e)).into_lua_multi(&lua),
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue