wezterm icon indicating copy to clipboard operation
wezterm copied to clipboard

Automatic Padding

Open gopyts opened this issue 1 year ago • 4 comments

Is your feature request related to a problem? Please describe.

I've noticed an issue with the padding when resizing the terminal window in Wezterm. Currently, the padding becomes unbalanced, with more space on the right and bottom, creating an uneven appearance.

Describe the solution you'd like

I propose the implementation of an option for automatic padding option. Something like:

config.window_padding = {
  automatic_adjustment = true,
}

When resizing the window, the automatic padding adjustment would distribute the additional padding equally on the left and right sides and on the top and bottom, ensuring a centered and balanced appearance of the content within the terminal window.

Describe alternatives you've considered

One way to reduce the padding imbalance is to change the terminal font size to reduce the gap. But, this compromises the user experience by forcing the user to change the font size of their preference and sometimes, it is difficult to find a size that reduces the right and bottom gap simultaneously.

Additional context

When Starting image

When the window is resized image

gopyts avatar Feb 17 '24 20:02 gopyts

I got something sort of along the lines of this by adding this to my .wezterm.lua.

function recompute_padding(window)
	local overrides = window:get_config_overrides() or {}
	local win_dims = window:get_dimensions()
	local pane_dims = window:active_pane():get_dimensions()

	local new_padding = {
		left = math.floor((win_dims.pixel_width - pane_dims.pixel_width)/2),
		top = math.floor((win_dims.pixel_height - pane_dims.pixel_height)/2) - 10,
	}
	overrides.window_padding = new_padding
	window:set_config_overrides(overrides)
end

wezterm.on("window-resized", function(window, pane)
	recompute_padding(window)
end)

wezterm.on("window-config-reloaded", function(window)
	recompute_padding(window)
end)

Still far from perfect. Part of the issue is that the :get_dimensions() for window is for the outer rectangle of the window and setting the right and bottom you risk going infinitely small. Something built into Wezterm would be better or if there were more helper methods.

ReallySnazzy avatar Feb 23 '24 23:02 ReallySnazzy

Probably a duplicate of #1124

ReallySnazzy avatar Feb 23 '24 23:02 ReallySnazzy

One way to solve the infinitely decreasing size issue is by resetting to the default padding each time:

local function minimize_padding(window, pane, cfg_padding)
  -- Reset padding
  local overrides = window:get_config_overrides() or {}
  overrides.window_padding = cfg_padding
  window:set_config_overrides(overrides)

  -- Center
  local vert_gap_size = window:get_dimensions().pixel_height - pane:get_dimensions().pixel_height
  local horz_gap_size = window:get_dimensions().pixel_width - pane:get_dimensions().pixel_width
  overrides.window_padding = {
    left = horz_gap_size * 1/2,
    right = horz_gap_size * 1/2,
    top = vert_gap_size * 1/2,
    bottom = vert_gap_size * 1/2,
  }
  window:set_config_overrides(overrides)
end

wezterm.on("window-resized", function(window, pane)
  minimize_padding(window, pane, config.window_padding)
end);

This has the flaw of requiring two adjustments, which can make the content appear jumpy while resizing.

ArchWand avatar Jun 12 '24 02:06 ArchWand

Both of the scripts above cannot handle tab bars and panes; the calculation gets completely messed up. Possible the only solution is to hardcode the padding based on the window size as follows:


function set_default (t, d)
  local mt = {__index = function () return d end}
  setmetatable(t, mt)
end

-- Choose padding based on window size
function compute_padding(window, cfg_padding)
  -- Get window size and corresponding padding
  local w = cfg_padding.w[window:get_dimensions().pixel_width]
  local h = cfg_padding.h[window:get_dimensions().pixel_height]

  -- Set padding
  local overrides = window:get_config_overrides() or {}
  overrides.window_padding = {
    left = w.left,
    right = w.right,
    top = h.top,
    bottom = h.bottom,
  }
  window:set_config_overrides(overrides)
end

-- [[ Config Start ]]

local padding_table = { w = {}, h = {} }
-- Fullscreen
padding_table.w[1920] = { left = 0, right = 0 }
padding_table.h[1080] = { top = 4, bottom = 5 }

-- Full
padding_table.w[1914] = { left = 2, right = 2 }
padding_table.h[1074] = { top = 1, bottom = 2 }

-- Half
padding_table.w[954] = { left = 2, right = 2 }
padding_table.h[534] = { top = 4, bottom = 5 }

set_default(padding_table.w, { left = 0, right = 0 })
set_default(padding_table.h, { top = 0, bottom = 0 })

-- [[ Config End ]]

wezterm.on("window-resized", function(window)
  util.compute_padding(window, padding_table)
end);

wezterm.on("window-config-reloaded", function(window)
  util.compute_padding(window, padding_table)
end);

ArchWand avatar Jun 14 '24 05:06 ArchWand

Duplicate of #1124 Closing this. Thx!

gopyts avatar Aug 16 '24 09:08 gopyts