refactor: deprecate ui.Rect.default (#2927)

This commit is contained in:
三咲雅 misaki masa 2025-06-27 23:03:16 +08:00 committed by GitHub
parent e16c0da547
commit 8ef28ec678
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,6 +3,7 @@ use std::ops::Deref;
use mlua::{FromLua, IntoLua, Lua, MetaMethod, Table, UserData, Value};
use super::Pad;
use crate::deprecate;
#[derive(Clone, Copy, Debug, Default, FromLua)]
pub struct Rect(pub(super) ratatui::layout::Rect);
@ -34,9 +35,20 @@ impl Rect {
}))
})?;
let rect = lua.create_table_from([("default", Self(ratatui::layout::Rect::default()))])?;
let index = lua.create_function(move |lua, (_, key): (Table, mlua::String)| {
Ok(match key.as_bytes().as_ref() {
b"default" => {
deprecate!(lua, "`ui.Rect.default` is deprecated, use `ui.Rect{{}}` instead, in your {}\nSee #2927 for more details: https://github.com/sxyazi/yazi/pull/2927");
Some(Self(Default::default()))
}
_ => None,
})
})?;
rect.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
let rect = lua.create_table()?;
rect.set_metatable(Some(
lua.create_table_from([(MetaMethod::Call.name(), new), (MetaMethod::Index.name(), index)])?,
));
rect.into_lua(lua)
}