From 8ef28ec6786fe4770ee302f7323f87775109a0c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20misaki=20masa?= Date: Fri, 27 Jun 2025 23:03:16 +0800 Subject: [PATCH] refactor: deprecate `ui.Rect.default` (#2927) --- yazi-plugin/src/elements/rect.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/yazi-plugin/src/elements/rect.rs b/yazi-plugin/src/elements/rect.rs index e5b52d4e..9853568a 100644 --- a/yazi-plugin/src/elements/rect.rs +++ b/yazi-plugin/src/elements/rect.rs @@ -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) }