mirror of
https://github.com/wez/wezterm.git
synced 2024-12-28 07:55:03 +03:00
add gui-startup and mux-startup events
Using the newly exposed-to-lua mux apis, you may now run some lua code at GUI startup and/or mux startup, just prior to any default windows being created. If you happen to spawn any panes as a result of this, wezterm will skip creating the default program. ```lua local wezterm = require 'wezterm' local mux = wezterm.mux -- This produces a window split horizontally into three equal parts wezterm.on("gui-startup", function() wezterm.log_info("doing gui startup") local tab, pane, window = mux.spawn_window{} mux.split_pane(pane, {size=0.3}) mux.split_pane(pane, {size=0.5}) end) wezterm.on("mux-startup", function() wezterm.log_info("doing mux startup") local tab, pane, window = mux.spawn_window{} mux.split_pane(pane, {size=0.5, direction="Top"}) end) return { unix_domains = { {name="unix"} }, } ``` refs: #674 refs: #1949
This commit is contained in:
parent
824dc66610
commit
699bbce8e2
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -4833,6 +4833,7 @@ dependencies = [
|
||||
"env-bootstrap",
|
||||
"libc",
|
||||
"log",
|
||||
"mlua",
|
||||
"mux",
|
||||
"openssl",
|
||||
"portable-pty",
|
||||
|
@ -224,7 +224,8 @@ async fn async_run_with_domain_as_default(
|
||||
mux.add_domain(&domain);
|
||||
mux.set_default_domain(&domain);
|
||||
|
||||
spawn_tab_in_default_domain_if_mux_is_empty(cmd).await
|
||||
let is_connecting = true;
|
||||
spawn_tab_in_default_domain_if_mux_is_empty(cmd, is_connecting).await
|
||||
}
|
||||
|
||||
async fn async_run_mux_client(opts: ConnectCommand) -> anyhow::Result<()> {
|
||||
@ -273,10 +274,23 @@ fn run_mux_client(opts: ConnectCommand) -> anyhow::Result<()> {
|
||||
|
||||
async fn spawn_tab_in_default_domain_if_mux_is_empty(
|
||||
cmd: Option<CommandBuilder>,
|
||||
is_connecting: bool,
|
||||
) -> anyhow::Result<()> {
|
||||
let mux = Mux::get().unwrap();
|
||||
|
||||
let domain = mux.default_domain();
|
||||
|
||||
if !is_connecting {
|
||||
let have_panes_in_domain = mux
|
||||
.iter_panes()
|
||||
.iter()
|
||||
.any(|p| p.domain_id() == domain.domain_id());
|
||||
|
||||
if have_panes_in_domain {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
let window_id = mux.new_empty_window(None);
|
||||
|
||||
domain.attach(Some(*window_id)).await?;
|
||||
@ -381,7 +395,27 @@ async fn async_run_terminal_gui(
|
||||
if !opts.no_auto_connect {
|
||||
connect_to_auto_connect_domains().await?;
|
||||
}
|
||||
spawn_tab_in_default_domain_if_mux_is_empty(cmd).await
|
||||
|
||||
async fn trigger_gui_startup(lua: Option<Rc<mlua::Lua>>) -> anyhow::Result<()> {
|
||||
if let Some(lua) = lua {
|
||||
let args = lua.pack_multi(())?;
|
||||
config::lua::emit_event(&lua, ("gui-startup".to_string(), args))
|
||||
.await
|
||||
.map_err(|e| {
|
||||
log::error!("while processing gui-startup event: {:#}", e);
|
||||
e
|
||||
})?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
promise::spawn::spawn(config::with_lua_config_on_main_thread(move |lua| {
|
||||
trigger_gui_startup(lua)
|
||||
}))
|
||||
.await?;
|
||||
|
||||
let is_connecting = false;
|
||||
spawn_tab_in_default_domain_if_mux_is_empty(cmd, is_connecting).await
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -16,6 +16,7 @@ env-bootstrap = { path = "../env-bootstrap" }
|
||||
libc = "0.2"
|
||||
log = "0.4"
|
||||
mux = { path = "../mux" }
|
||||
mlua = "0.8.0-beta.4"
|
||||
openssl = "0.10"
|
||||
portable-pty = { path = "../pty", features = ["serde_support"]}
|
||||
promise = { path = "../promise" }
|
||||
|
@ -199,10 +199,34 @@ fn run() -> anyhow::Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
async fn trigger_mux_startup(lua: Option<Rc<mlua::Lua>>) -> anyhow::Result<()> {
|
||||
if let Some(lua) = lua {
|
||||
let args = lua.pack_multi(())?;
|
||||
config::lua::emit_event(&lua, ("mux-startup".to_string(), args))
|
||||
.await
|
||||
.map_err(|e| {
|
||||
log::error!("while processing mux-startup event: {:#}", e);
|
||||
e
|
||||
})?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn async_run(cmd: Option<CommandBuilder>) -> anyhow::Result<()> {
|
||||
let mux = Mux::get().unwrap();
|
||||
|
||||
let domain = mux.default_domain();
|
||||
|
||||
{
|
||||
config::with_lua_config_on_main_thread(move |lua| trigger_mux_startup(lua)).await?;
|
||||
}
|
||||
|
||||
let have_panes_in_domain = mux
|
||||
.iter_panes()
|
||||
.iter()
|
||||
.any(|p| p.domain_id() == domain.domain_id());
|
||||
|
||||
if !have_panes_in_domain {
|
||||
let window_id = mux.new_empty_window(None);
|
||||
domain.attach(Some(*window_id)).await?;
|
||||
|
||||
@ -211,6 +235,7 @@ async fn async_run(cmd: Option<CommandBuilder>) -> anyhow::Result<()> {
|
||||
.default_domain()
|
||||
.spawn(config.initial_size(0), cmd, None, *window_id)
|
||||
.await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user