-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathevents.lua
More file actions
70 lines (58 loc) · 2.29 KB
/
events.lua
File metadata and controls
70 lines (58 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
local wezterm = require("wezterm")
local mux = wezterm.mux
wezterm.on("gui-startup", function()
local _, _, window = mux.spawn_window({})
window:gui_window():maximize()
end)
-- Font size readjustment function based on window resize
function readjust_font_size(window, pane)
local window_dims = window:get_dimensions()
local pane_dims = pane:get_dimensions()
local config_overrides = {}
local initial_font_size = 13 -- Set to your desired font size
config_overrides.font_size = initial_font_size
local max_iterations = 5
local iteration_count = 0
local tolerance = 3
-- Calculate the initial difference between window and pane heights
local current_diff = window_dims.pixel_height - pane_dims.pixel_height
local min_diff = math.abs(current_diff)
local best_font_size = initial_font_size
-- Loop to adjust font size until the difference is within tolerance or max iterations reached
while current_diff > tolerance and iteration_count < max_iterations do
wezterm.log_info(
string.format(
"Win Height: %d, Pane Height: %d, Height Diff: %d, Curr Font Size: %.2f, Cells: %d, Cell Height: %.2f",
window_dims.pixel_height,
pane_dims.pixel_height,
window_dims.pixel_height - pane_dims.pixel_height,
config_overrides.font_size,
pane_dims.viewport_rows,
pane_dims.pixel_height / pane_dims.viewport_rows
)
)
-- Increment the font size slightly
config_overrides.font_size = config_overrides.font_size + 0.5
window:set_config_overrides(config_overrides)
-- Update dimensions after changing font size
window_dims = window:get_dimensions()
pane_dims = pane:get_dimensions()
current_diff = window_dims.pixel_height - pane_dims.pixel_height
-- Check if the current difference is the smallest seen so far
local abs_diff = math.abs(current_diff)
if abs_diff < min_diff then
min_diff = abs_diff
best_font_size = config_overrides.font_size
end
iteration_count = iteration_count + 1
end
-- If no acceptable difference was found, set the font size to the best one encountered
if current_diff > tolerance then
config_overrides.font_size = best_font_size
window:set_config_overrides(config_overrides)
end
end
-- Uncomment if you still want font resizing on window resizing
wezterm.on("window-resized", function(window, pane)
readjust_font_size(window, pane)
end)