Skip to content

Commit d6dad12

Browse files
sxyaziLemi0002
authored andcommitted
refactor: deprecate ui.Padding and ui.Rect:padding() (sxyazi#2574)
1 parent 29b1971 commit d6dad12

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

yazi-plugin/src/elements/pad.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ impl From<ratatui::widgets::Padding> for Pad {
1717

1818
impl Pad {
1919
pub fn compose(lua: &Lua, v4: bool) -> mlua::Result<Table> {
20+
if !v4 {
21+
crate::deprecate!(
22+
lua,
23+
"The `ui.Padding` has been deprecated, please use `ui.Pad` instead, in your {}"
24+
);
25+
}
26+
2027
let new = if v4 {
2128
lua.create_function(|_, (_, top, right, bottom, left): (Table, u16, u16, u16, u16)| {
2229
Ok(Self(ratatui::widgets::Padding::new(left, right, top, bottom)))

yazi-plugin/src/elements/rect.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ impl UserData for Rect {
7272
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
7373
methods.add_method("pad", |_, me, pad: Pad| Ok(me.pad(pad)));
7474
// TODO: deprecate this
75-
methods.add_method("padding", |_, me, pad: Pad| Ok(me.pad(pad)));
75+
methods.add_method("padding", |lua, me, pad: Pad| {
76+
crate::deprecate!(lua, "The `padding()` method of `ui.Rect` has been deprecated, please use `pad()` instead, in your {}");
77+
Ok(me.pad(pad))
78+
});
7679
methods.add_method("contains", |_, me, Rect(rect)| Ok(me.contains(rect.into())));
7780
}
7881
}

yazi-plugin/src/file/file.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ impl File {
4949

5050
impl FromLua for File {
5151
fn from_lua(value: Value, _: &Lua) -> mlua::Result<Self> {
52-
match value {
53-
Value::UserData(ud) => ud.take().map(Self::new),
54-
_ => Err("Expected a File".into_lua_err()),
55-
}
52+
Ok(match value {
53+
Value::UserData(ud) => Self::new(ud.take::<Self>()?.inner),
54+
_ => Err("Expected a File".into_lua_err())?,
55+
})
5656
}
5757
}
5858

0 commit comments

Comments
 (0)