wez / wezterm

A GPU-accelerated cross-platform terminal emulator and multiplexer written by @wez and implemented in Rust
https://wezfurlong.org/wezterm/
Other
17.75k stars 794 forks source link

Center window contents #1124

Open valpackett opened 3 years ago

valpackett commented 3 years ago

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

Unlike #291 I just want to be able to center the content in the window to avoid ugly asymmetrical padding on the bottom and right sides of the window. Or even align it to be horizontally centered but vertically always sticking to the bottom edge.

(BTW even if/when there would be snap-to-character-grid resizing, there would still be fullscreen/maximized mode…)

Describe the solution you'd like

It is sort of possible to achieve with scripting…

wezterm.on("window-resized", function(window, pane)
  local window_dims = window:get_dimensions();
  local overrides = window:get_config_overrides() or {}
  local new_padding = {
    left = math.floor((window_dims.pixel_width % 19) / 2),
    right = 0,
    top = math.floor((window_dims.pixel_height % 43) / 2),
    bottom = 0
  };
  overrides.window_padding = new_padding
  window:set_config_overrides(overrides)
end);

…but only with hardcoded cell size. So, I guess there should be a Lua call for getting character grid cell dimensions!

Describe alternatives you've considered

Or make this just a built-in mode (flag) to avoid having stuff in configs.

bvtthead commented 1 year ago

I would also like this feature.

On st I used the anysize patch to center the content of the terminal window on my tiling wm.

Currently I am using:

local center_content = function(window, pane)
    local win_dim = window:get_dimensions()
    local tab_dim = pane:tab():get_size()
    local overrides = window:get_config_overrides() or {}
    local padding_left = (win_dim.pixel_width - tab_dim.pixel_width) / 2
    local padding_top = (win_dim.pixel_height - tab_dim.pixel_height) / 2
    local new_padding = {
        left = padding_left,
        right = 0,
        top = padding_top,
        bottom = 0,
    }
    if overrides.window_padding and new_padding.left == overrides.window_padding.left then
        return
    end
    overrides.window_padding = new_padding
    window:set_config_overrides(overrides)
end

wezterm.on('window-resized', center_content)
wezterm.on('window-config-reloaded', center_content)
karimlevallois commented 9 months ago

This is interesting. How would a use the above in my 3 pane setup (below) to add padding to my top right (terminal) split? Currently it's a bit far to the left and looks a bit out of place against my centred Neovim main pane and auto-sized Bottom right split

-- Startup using 3 panes, lvim, wezterm and btm
wezterm.on("gui-startup", function(cmd)
    local tab, pane, window = mux.spawn_window(cmd or {
        args = { "/opt/homebrew/bin/fish", "-c", "/Users/Karim/.local/bin/lvim" },
    })
    window:gui_window():toggle_fullscreen()
    -- Create a right side pane
    local right_pane = pane:split { direction = "Right", size = 0.4 }
    -- Split right pane into two, with new pane on bottom
    local bottom_pane = right_pane:split { direction = "Bottom", size = 0.9, args = { "/opt/homebrew/bin/btm" } }
    -- Activate primary left pane
    pane:activate()
end)
Screenshot 2024-01-27 at 08 32 36
bartdorsey commented 9 months ago

I really would like an option to "center" the terminal inside whatever padding you had set. Right now all the excess padding goes to the right and bottom. The idea way for this to work is you set your padding and then any extra padding is divided equally between opposite sides.

wez commented 9 months ago

FWIW, if you enable https://wezfurlong.org/wezterm/config/lua/config/use_resize_increments.html you will be less likely to have any excess padding. This works best under X11 and macOS, but has no effect on Windows.

janbuchar commented 9 months ago

FWIW, if you enable https://wezfurlong.org/wezterm/config/lua/config/use_resize_increments.html you will be less likely to have any excess padding. This works best under X11 and macOS, but has no effect on Windows.

Thank you for this! Unfortunately, I usually work in a fullscreen terminal window, so this is not a 100% solution for me.

ArchWand commented 5 months ago

I would like to note that on MacOS use_resize_increments interacts a bit weirdly with Raycast's "Maximize". It would appear that Raycast sets the window as large as possible, but this ends up being scaled back to some increment that fits an exact number of cells, which often leaves a small strip of the background peeking through along the bottom. This looks like intended behavior, but is annoying nonetheless.