From 8f45cb8dfab9b4d832a78e11e21940c894f571df Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Wed, 6 Jul 2022 15:52:31 -0700 Subject: [PATCH] lua: add MuxWindow::gui_window() method This is the inverse of Window::mux_window(). --- lua-api-crates/mux/src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lua-api-crates/mux/src/lib.rs b/lua-api-crates/mux/src/lib.rs index 2d0dc7622..91987cc14 100644 --- a/lua-api-crates/mux/src/lib.rs +++ b/lua-api-crates/mux/src/lib.rs @@ -1,6 +1,6 @@ use config::keyassignment::SpawnTabDomain; -use config::lua::get_or_create_sub_module; use config::lua::mlua::{self, Lua, UserData, UserDataMethods, Value as LuaValue}; +use config::lua::{get_or_create_module, get_or_create_sub_module}; use luahelper::impl_lua_conversion_dynamic; use mux::domain::SplitSource; use mux::pane::{Pane, PaneId}; @@ -334,6 +334,15 @@ impl_lua_conversion_dynamic!(MuxTabInfo); impl UserData for MuxWindow { fn add_methods<'lua, M: UserDataMethods<'lua, Self>>(methods: &mut M) { methods.add_method("window_id", |_, this, _: ()| Ok(this.0)); + methods.add_method("gui_window", |lua, this, _: ()| { + // Weakly bound to the gui module; mux cannot hard-depend + // on wezterm-gui, but we can runtime resolve the appropriate module + let wezterm_mod = get_or_create_module(lua, "wezterm") + .map_err(|err| mlua::Error::external(format!("{err:#}")))?; + let gui: mlua::Table = wezterm_mod.get("gui")?; + let func: mlua::Function = gui.get("gui_window_for_mux_window")?; + func.call::<_, mlua::Value>(this.0) + }); methods.add_method("get_workspace", |_, this, _: ()| { let mux = get_mux()?; let window = this.resolve(&mux)?;