-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new
cx.layer
API to determine the current UI layer (#2247)
- Loading branch information
Showing
33 changed files
with
199 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use std::ops::Deref; | ||
|
||
use mlua::{AnyUserData, IntoLua, MetaMethod, UserData, Value}; | ||
|
||
use super::Lives; | ||
|
||
pub(super) struct Ctx { | ||
inner: *const crate::Ctx, | ||
} | ||
|
||
impl Deref for Ctx { | ||
type Target = crate::Ctx; | ||
|
||
fn deref(&self) -> &Self::Target { unsafe { &*self.inner } } | ||
} | ||
|
||
impl Ctx { | ||
#[inline] | ||
pub(super) fn make(inner: &crate::Ctx) -> mlua::Result<AnyUserData> { | ||
Lives::scoped_userdata(Self { inner }) | ||
} | ||
} | ||
|
||
impl UserData for Ctx { | ||
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) { | ||
methods.add_meta_method(MetaMethod::Index, |lua, me, key: mlua::String| { | ||
match key.as_bytes().as_ref() { | ||
b"active" => super::Tab::make(me.active())?, | ||
b"tabs" => super::Tabs::make(&me.manager.tabs)?, | ||
b"tasks" => super::Tasks::make(&me.tasks)?, | ||
b"yanked" => super::Yanked::make(&me.manager.yanked)?, | ||
b"layer" => return yazi_plugin::bindings::Layer::from(me.layer()).into_lua(lua), | ||
_ => return Ok(Value::Nil), | ||
} | ||
.into_lua(lua) | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
#![allow(clippy::module_inception)] | ||
|
||
yazi_macro::mod_flat!( | ||
preference file files filter finder folder iter lives mode preview selected tab tabs | ||
tasks yanked | ||
); | ||
yazi_macro::mod_flat!(context file files filter finder folder iter lives mode preference preview selected tab tabs tasks yanked); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use mlua::{MetaMethod, UserData}; | ||
|
||
#[derive(Clone, Copy)] | ||
pub struct Layer(yazi_shared::Layer); | ||
|
||
impl From<yazi_shared::Layer> for Layer { | ||
fn from(event: yazi_shared::Layer) -> Self { Self(event) } | ||
} | ||
|
||
impl UserData for Layer { | ||
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) { | ||
methods.add_meta_method(MetaMethod::ToString, |_, me, ()| Ok(me.0.to_string())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#![allow(clippy::module_inception)] | ||
|
||
yazi_macro::mod_flat!(bindings cha chan icon image input mouse permit range window); | ||
yazi_macro::mod_flat!(bindings cha chan icon image input layer mouse permit range window); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use mlua::{IntoLua, Lua, MetaMethod, Table, Value}; | ||
|
||
pub struct Composer; | ||
|
||
impl Composer { | ||
pub fn make<F>(lua: &Lua, cap: usize, f: F) -> mlua::Result<Value> | ||
where | ||
F: Fn(&Lua, &[u8]) -> mlua::Result<Value> + 'static, | ||
{ | ||
let index = lua.create_function(move |lua, (ts, key): (Table, mlua::String)| { | ||
let v = f(lua, key.as_bytes().as_ref())?; | ||
ts.raw_set(key, v.clone())?; | ||
Ok(v) | ||
})?; | ||
|
||
let tbl = lua.create_table_with_capacity(0, cap)?; | ||
tbl.set_metatable(Some(lua.create_table_from([(MetaMethod::Index.name(), index)])?)); | ||
tbl.into_lua(lua) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.