From d8bbb115f619464a5e3ba21a2e34f7f5820575e1 Mon Sep 17 00:00:00 2001 From: Kevin Silvester Date: Wed, 30 Oct 2024 01:15:36 +0000 Subject: [PATCH] feat: add method for constructing background options + stop usage of global variable for setting image path --- config/appearance.lua | 23 +++++------------- config/general.lua | 2 +- utils/backdrops.lua | 54 +++++++++++++++++++++---------------------- 3 files changed, 33 insertions(+), 46 deletions(-) diff --git a/config/appearance.lua b/config/appearance.lua index 5b776e7..195c638 100644 --- a/config/appearance.lua +++ b/config/appearance.lua @@ -1,32 +1,20 @@ -local wezterm = require('wezterm') local gpu_adapters = require('utils.gpu_adapter') +local backdrops = require('utils.backdrops') local colors = require('colors.custom') return { - animation_fps = 60, - max_fps = 60, + animation_fps = 165, + max_fps = 165, front_end = 'WebGpu', webgpu_power_preference = 'HighPerformance', webgpu_preferred_adapter = gpu_adapters:pick_best(), + -- webgpu_preferred_adapter = gpu_adapters:pick_manual('Dx12', 'IntegratedGpu'), -- color scheme colors = colors, -- background - background = { - { - source = { File = wezterm.GLOBAL.background }, - horizontal_align = 'Center', - }, - { - source = { Color = colors.background }, - height = '120%', - width = '120%', - vertical_offset = '-10%', - horizontal_offset = '-10%', - opacity = 0.96, - }, - }, + background = backdrops:create_opts(), -- scrollbar enable_scroll_bar = true, @@ -46,6 +34,7 @@ return { top = 10, bottom = 7.5, }, + adjust_window_size_when_changing_font_size = false, window_close_confirmation = 'NeverPrompt', window_frame = { active_titlebar_bg = '#090909', diff --git a/config/general.lua b/config/general.lua index c482568..2c81047 100644 --- a/config/general.lua +++ b/config/general.lua @@ -5,7 +5,7 @@ return { exit_behavior_messaging = 'Verbose', status_update_interval = 1000, - scrollback_lines = 5000, + scrollback_lines = 20000, hyperlink_rules = { -- Matches: a URL in parens: (URL) diff --git a/utils/backdrops.lua b/utils/backdrops.lua index a3dc73b..d878919 100644 --- a/utils/backdrops.lua +++ b/utils/backdrops.lua @@ -1,5 +1,4 @@ local wezterm = require('wezterm') -local platform = require('utils.platform') local colors = require('colors.custom') -- Seeding random numbers before generating for use @@ -10,7 +9,6 @@ math.random() math.random() math.random() -local PATH_SEP = platform.is_win and '\\' or '/' local GLOB_PATTERN = '*.{jpg,jpeg,png,gif,bmp,ico,tiff,pnm,dds,tga}' ---@class BackDrops @@ -31,7 +29,6 @@ function BackDrops:init() focus_on = false, } local backdrops = setmetatable(inital, self) - wezterm.GLOBAL.background = nil return backdrops end @@ -44,9 +41,7 @@ end --- This throws a coroutine error if the function is invoked in outside of `wezterm.lua` in the - --- initial load of the Terminal config. function BackDrops:set_files() - self.files = - wezterm.glob(wezterm.config_dir .. PATH_SEP .. 'backdrops' .. PATH_SEP .. GLOB_PATTERN) - wezterm.GLOBAL.background = self.files[1] + self.files = wezterm.glob(wezterm.config_dir .. '/backdrops/' .. GLOB_PATTERN) return self end @@ -58,27 +53,33 @@ function BackDrops:set_focus(focus_color) return self end +---Create the `background` options with the current image +---@return table +function BackDrops:create_opts() + return { + { + source = { File = self.files[self.current_idx] }, + horizontal_align = 'Center', + }, + { + source = { Color = colors.background }, + height = '120%', + width = '120%', + vertical_offset = '-10%', + horizontal_offset = '-10%', + opacity = 0.96, + }, + } +end + ---Override the current window options for background ---@private ---@param window any WezTerm Window see: https://wezfurlong.org/wezterm/config/lua/window/index.html function BackDrops:_set_opt(window) - local opts = { - background = { - { - source = { File = wezterm.GLOBAL.background }, - horizontal_align = 'Center', - }, - { - source = { Color = colors.background }, - height = '120%', - width = '120%', - vertical_offset = '-10%', - horizontal_offset = '-10%', - opacity = 0.96, - }, - }, - } - window:set_config_overrides(opts) + window:set_config_overrides({ + background = self:create_opts(), + enable_tab_bar = window:effective_config().enable_tab_bar, + }) end ---Override the current window options for background with focus color @@ -96,6 +97,7 @@ function BackDrops:_set_focus_opt(window) opacity = 1, }, }, + enable_tab_bar = window:effective_config().enable_tab_bar, } window:set_config_overrides(opts) end @@ -113,12 +115,11 @@ function BackDrops:choices() return choices end ----Select a random file and redefine the global `wezterm.GLOBAL.background` variable +---Select a random background from the loaded `files` ---Pass in `Window` object to override the current window options ---@param window any? WezTerm `Window` see: https://wezfurlong.org/wezterm/config/lua/window/index.html function BackDrops:random(window) self.current_idx = math.random(#self.files) - wezterm.GLOBAL.background = self.files[self.current_idx] if window ~= nil then self:_set_opt(window) @@ -133,7 +134,6 @@ function BackDrops:cycle_forward(window) else self.current_idx = self.current_idx + 1 end - wezterm.GLOBAL.background = self.files[self.current_idx] self:_set_opt(window) end @@ -145,7 +145,6 @@ function BackDrops:cycle_back(window) else self.current_idx = self.current_idx - 1 end - wezterm.GLOBAL.background = self.files[self.current_idx] self:_set_opt(window) end @@ -159,7 +158,6 @@ function BackDrops:set_img(window, idx) end self.current_idx = idx - wezterm.GLOBAL.background = self.files[self.current_idx] self:_set_opt(window) end