From fd007ab0235f3e7dd5816870d852263ee6972b73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20=C2=B7=20Misaki=20Masa?= Date: Sat, 5 Apr 2025 11:16:56 +0800 Subject: [PATCH] refactor: deprecate `ui.Padding` and `ui.Rect:padding()` (#2574) --- yazi-plugin/src/elements/pad.rs | 7 +++++++ yazi-plugin/src/elements/rect.rs | 5 ++++- yazi-plugin/src/file/file.rs | 8 ++++---- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/yazi-plugin/src/elements/pad.rs b/yazi-plugin/src/elements/pad.rs index 141ccaf7..94d97e41 100644 --- a/yazi-plugin/src/elements/pad.rs +++ b/yazi-plugin/src/elements/pad.rs @@ -17,6 +17,13 @@ impl From for Pad { impl Pad { pub fn compose(lua: &Lua, v4: bool) -> mlua::Result { + if !v4 { + crate::deprecate!( + lua, + "The `ui.Padding` has been deprecated, please use `ui.Pad` instead, in your {}" + ); + } + let new = if v4 { lua.create_function(|_, (_, top, right, bottom, left): (Table, u16, u16, u16, u16)| { Ok(Self(ratatui::widgets::Padding::new(left, right, top, bottom))) diff --git a/yazi-plugin/src/elements/rect.rs b/yazi-plugin/src/elements/rect.rs index d0d16db0..78b9690d 100644 --- a/yazi-plugin/src/elements/rect.rs +++ b/yazi-plugin/src/elements/rect.rs @@ -72,7 +72,10 @@ impl UserData for Rect { fn add_methods>(methods: &mut M) { methods.add_method("pad", |_, me, pad: Pad| Ok(me.pad(pad))); // TODO: deprecate this - methods.add_method("padding", |_, me, pad: Pad| Ok(me.pad(pad))); + methods.add_method("padding", |lua, me, pad: Pad| { + crate::deprecate!(lua, "The `padding()` method of `ui.Rect` has been deprecated, please use `pad()` instead, in your {}"); + Ok(me.pad(pad)) + }); methods.add_method("contains", |_, me, Rect(rect)| Ok(me.contains(rect.into()))); } } diff --git a/yazi-plugin/src/file/file.rs b/yazi-plugin/src/file/file.rs index 667e94c8..e23db4b6 100644 --- a/yazi-plugin/src/file/file.rs +++ b/yazi-plugin/src/file/file.rs @@ -49,10 +49,10 @@ impl File { impl FromLua for File { fn from_lua(value: Value, _: &Lua) -> mlua::Result { - match value { - Value::UserData(ud) => ud.take().map(Self::new), - _ => Err("Expected a File".into_lua_err()), - } + Ok(match value { + Value::UserData(ud) => Self::new(ud.take::()?.inner), + _ => Err("Expected a File".into_lua_err())?, + }) } }