diff --git a/Cargo.lock b/Cargo.lock index 125b14e64..d922e70f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2507,6 +2507,7 @@ version = "0.1.0" dependencies = [ "anyhow", "config", + "libc", "log", "luahelper", "mux", diff --git a/lua-api-crates/mux/Cargo.toml b/lua-api-crates/mux/Cargo.toml index 80e4e7545..a90daa4b8 100644 --- a/lua-api-crates/mux/Cargo.toml +++ b/lua-api-crates/mux/Cargo.toml @@ -10,6 +10,7 @@ anyhow = "1.0" config = { path = "../../config" } wezterm-dynamic = { path = "../../wezterm-dynamic" } wezterm-term = { path = "../../term" } +libc = "0.2" log = "0.4" luahelper = { path = "../../luahelper" } portable-pty = { path = "../../pty" } diff --git a/lua-api-crates/mux/src/lib.rs b/lua-api-crates/mux/src/lib.rs index 1f52f7b89..c65620e1d 100644 --- a/lua-api-crates/mux/src/lib.rs +++ b/lua-api-crates/mux/src/lib.rs @@ -333,6 +333,13 @@ impl_lua_conversion_dynamic!(MuxTabInfo); impl UserData for MuxWindow { fn add_methods<'lua, M: UserDataMethods<'lua, Self>>(methods: &mut M) { + methods.add_meta_method(mlua::MetaMethod::ToString, |_, this, _: ()| { + Ok(format!( + "MuxWindow(mux_window_id:{}, pid:{})", + this.0, + unsafe { libc::getpid() } + )) + }); methods.add_method("window_id", |_, this, _: ()| Ok(this.0)); methods.add_async_method("gui_window", |lua, this, _: ()| async move { // Weakly bound to the gui module; mux cannot hard-depend @@ -407,6 +414,11 @@ impl MuxPane { impl UserData for MuxPane { fn add_methods<'lua, M: UserDataMethods<'lua, Self>>(methods: &mut M) { + methods.add_meta_method(mlua::MetaMethod::ToString, |_, this, _: ()| { + Ok(format!("MuxPane(pane_id:{}, pid:{})", this.0, unsafe { + libc::getpid() + })) + }); methods.add_method("pane_id", |_, this, _: ()| Ok(this.0)); methods.add_async_method("split", |_, this, args: Option| async move { let args = args.unwrap_or_default(); @@ -474,6 +486,11 @@ impl_lua_conversion_dynamic!(MuxPaneInfo); impl UserData for MuxTab { fn add_methods<'lua, M: UserDataMethods<'lua, Self>>(methods: &mut M) { + methods.add_meta_method(mlua::MetaMethod::ToString, |_, this, _: ()| { + Ok(format!("MuxTab(tab_id:{}, pid:{})", this.0, unsafe { + libc::getpid() + })) + }); methods.add_method("tab_id", |_, this, _: ()| Ok(this.0)); methods.add_method("window", |_, this, _: ()| { let mux = get_mux()?; diff --git a/wezterm-gui/src/scripting/guiwin.rs b/wezterm-gui/src/scripting/guiwin.rs index ae942c6dc..df0860336 100644 --- a/wezterm-gui/src/scripting/guiwin.rs +++ b/wezterm-gui/src/scripting/guiwin.rs @@ -35,6 +35,14 @@ impl GuiWin { impl UserData for GuiWin { fn add_methods<'lua, M: UserDataMethods<'lua, Self>>(methods: &mut M) { + methods.add_meta_method(mlua::MetaMethod::ToString, |_, this, _: ()| { + Ok(format!( + "GuiWin(mux_window_id:{}, pid:{})", + this.mux_window_id, + unsafe { libc::getpid() } + )) + }); + methods.add_method("window_id", |_, this, _: ()| Ok(this.mux_window_id)); methods.add_method("mux_window", |_, this, _: ()| { Ok(mux_lua::MuxWindow(this.mux_window_id)) diff --git a/wezterm-gui/src/scripting/pane.rs b/wezterm-gui/src/scripting/pane.rs index df3b76d56..218c422ed 100644 --- a/wezterm-gui/src/scripting/pane.rs +++ b/wezterm-gui/src/scripting/pane.rs @@ -30,6 +30,13 @@ impl PaneObject { impl UserData for PaneObject { fn add_methods<'lua, M: UserDataMethods<'lua, Self>>(methods: &mut M) { + methods.add_meta_method(mlua::MetaMethod::ToString, |_, this, _: ()| { + Ok(format!( + "GuiPane(pane_id:{}, pid:{})", + this.pane()?.pane_id(), + unsafe { libc::getpid() } + )) + }); methods.add_method("pane_id", |_, this, _: ()| Ok(this.pane()?.pane_id())); methods.add_method("mux_pane", |_, this, _: ()| { Ok(mux_lua::MuxPane(this.pane()?.pane_id()))