local wezterm = require("wezterm") local state = require("plugins.sessionizer.src.state") local ui = require("plugins.sessionizer.src.ui") local workspaces = require("plugins.sessionizer.src.workspaces") local M = {} function M.apply_to_config(config, user_config) local opts = user_config or {} state.apply_to_config(opts) if opts.key and opts.mods then config.keys = config.keys or {} table.insert(config.keys, { key = opts.key, mods = opts.mods, action = ui.make_switcher(), }) end if opts.add_to_launch_menu then config.launch_menu = config.launch_menu or {} local dirs = workspaces.cached_dirs() if #dirs ~= 0 then for _, dir in ipairs(dirs) do table.insert(config.launch_menu, { label = "Workspace: " .. wezterm.basename(dir.id or dir), cwd = dir.id or dir, args = { "nvim" }, }) end end end -- Optional warmup to reduce latency on first invocation if opts.warmup ~= false then local delay_ms = tonumber(opts.warmup_delay_ms or 0) or 0 if delay_ms > 0 then wezterm.time.call_after(delay_ms / 1000, function() workspaces.refresh_async() end) else workspaces.refresh_async() end end end return M