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

View File

@ -2,9 +2,6 @@ local wezterm = require("wezterm")
local base = require("config/base")
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 alt_keymod = base.alt_keymod
local module = {}

View File

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