wezterm: modularize events in apply config step

This commit is contained in:
Gabriel Arazas 2025-01-28 17:15:08 +08:00
parent 04e1a9d0b2
commit 0ee4d7df89
3 changed files with 41 additions and 34 deletions

View File

@ -3,43 +3,51 @@ local wezterm = require("wezterm")
local io = require("io") local io = require("io")
local os = require("os") local os = require("os")
wezterm.on("update-right-status", function(window, _) function module.apply_to_config(config)
local key = window:active_key_table() wezterm.on("update-right-status", function(window, _)
if key then local key = window:active_key_table()
key = "TABLE: " .. key if key then
end key = "TABLE: " .. key
window:set_right_status(key or "") end
end) window:set_right_status(key or "")
end)
wezterm.on("view-last-output-in-new-pane", function(_, pane) wezterm.on("view-last-output-in-new-pane", function(_, pane)
local zones = pane:get_semantic_zones("Output") local zones = pane:get_semantic_zones("Output")
local last_zone = zones[#zones - 1] local last_zone = zones[#zones - 1]
if not last_zone then if not last_zone then
return nil return nil
end end
local output = pane:get_text_from_semantic_zone(last_zone) local output = pane:get_text_from_semantic_zone(last_zone)
local tmpname = os.tmpname() local tmpname = os.tmpname()
local f = io.open(tmpname, "w+") local f = io.open(tmpname, "w+")
if f ~= nil then if f ~= nil then
f:write(output) f:write(output)
f:flush() f:flush()
f:close() f:close()
end end
pane:split({ pane:split({
args = { os.getenv("PAGER") or "less", tmpname }, args = { os.getenv("PAGER") or "less", tmpname },
direction = "Bottom", direction = "Bottom",
domain = { DomainName = "local" }, domain = { DomainName = "local" },
}) })
-- Without this, it would quickly close all of the process immediately. -- Without this, it would quickly close all of the process immediately.
wezterm.sleep_ms(1000) wezterm.sleep_ms(1000)
-- While it isn't required, it is nice to clean it up. -- While it isn't required, it is nice to clean it up.
os.remove(tmpname) os.remove(tmpname)
end) end)
-- Maximize the terminal on startup.
wezterm.on('gui-startup', function(cmd)
local tab, pane, window = wezterm.mux.spawn_window(cmd or {})
window:gui_window():maximize()
end)
end
return module return module

View File

@ -2,9 +2,6 @@ local wezterm = require("wezterm")
local base = require("config/base") local base = require("config/base")
local act = wezterm.action local act = wezterm.action
-- Take note this is required to import the events in this module.
local _ = require("config/events")
local keymod = base.keymod local keymod = base.keymod
local alt_keymod = base.alt_keymod local alt_keymod = base.alt_keymod
local module = {} local module = {}

View File

@ -1,6 +1,8 @@
local config = require("wezterm").config_builder() local config = require("wezterm").config_builder()
config:set_strict_mode(true) config:set_strict_mode(true)
require("config/events").apply_to_config(config)
require("config/base").apply_to_config(config) require("config/base").apply_to_config(config)
require("config/keys").apply_to_config(config) require("config/keys").apply_to_config(config)
require("config/appearance").apply_to_config(config) require("config/appearance").apply_to_config(config)