lua: add tostring impls for window, tab and pane objects

This commit is contained in:
Wez Furlong committed 2022-07-16 08:22:10 -07:00
1 parent 4e4371a312
commit ec65b64f30
5 files changed
+34

No files matched your search

Generated
+1
View File
@@ -2507,6 +2507,7 @@ version = "0.1.0"
dependencies = [
"anyhow",
"config",
"libc",
"log",
"luahelper",
"mux",
+1
View File
@@ -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" }
+17
View File
@@ -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<SplitPane>| 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()?;
+8
View File
@@ -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))
+7
View File
@@ -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()))