diff options
| author | Zeng <76579810+Bekaboo@users.noreply.github.com> | 2023-01-15 12:18:45 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-15 19:18:45 +0100 |
| commit | 6eb540dc055cdf32ebeae020c51c7d792d7247bc (patch) | |
| tree | 07f56b676e43cf0a42181a6e635078b5d2486789 | |
| parent | fix(vala-lanaguager-server): update meson build commands (#896) (diff) | |
| download | mason-6eb540dc055cdf32ebeae020c51c7d792d7247bc.tar mason-6eb540dc055cdf32ebeae020c51c7d792d7247bc.tar.gz mason-6eb540dc055cdf32ebeae020c51c7d792d7247bc.tar.bz2 mason-6eb540dc055cdf32ebeae020c51c7d792d7247bc.tar.lz mason-6eb540dc055cdf32ebeae020c51c7d792d7247bc.tar.xz mason-6eb540dc055cdf32ebeae020c51c7d792d7247bc.tar.zst mason-6eb540dc055cdf32ebeae020c51c7d792d7247bc.zip | |
feat(ui): customizable window height and width (#906)
| -rw-r--r-- | README.md | 8 | ||||
| -rw-r--r-- | doc/mason.txt | 2 | ||||
| -rw-r--r-- | lua/mason-core/ui/display.lua | 26 | ||||
| -rw-r--r-- | lua/mason/settings.lua | 10 |
4 files changed, 37 insertions, 9 deletions
@@ -139,6 +139,8 @@ Example: ```lua require("mason").setup({ ui = { + height = 0.8, + width = 60, icons = { package_installed = "✓", package_pending = "➜", @@ -206,6 +208,12 @@ local DEFAULT_SETTINGS = { -- The border to use for the UI window. Accepts same border values as |nvim_open_win()|. border = "none", + -- Width of the window, accepts integer (fixed width) or float (percentage of screen width). + width = 0.8, + + -- Height of the window, accepts integer (fixed height) or float (percentage of screen height). + height = 0.8, + icons = { -- The list icon to use for installed packages. package_installed = "◍", diff --git a/doc/mason.txt b/doc/mason.txt index 604b16ac..5db2a0ac 100644 --- a/doc/mason.txt +++ b/doc/mason.txt @@ -218,6 +218,8 @@ Example: >lua require("mason").setup({ ui = { + height = 0.8, -- 0.8 * (vim.o.lines - vim.o.cmdheight) + width = 60, -- 60 columns icons = { package_installed = "✓", package_pending = "➜", diff --git a/lua/mason-core/ui/display.lua b/lua/mason-core/ui/display.lua index 85e73523..bc685cda 100644 --- a/lua/mason-core/ui/display.lua +++ b/lua/mason-core/ui/display.lua @@ -1,5 +1,6 @@ local log = require "mason-core.log" local state = require "mason-core.ui.state" +local settings = require "mason.settings" local M = {} @@ -167,22 +168,29 @@ M._render_node = render_node ---@alias WindowOpts { effects?: table<string, fun()>, winhighlight?: string[], border?: string|table } +---@param size integer | float +---@param viewport integer +local function calc_size(size, viewport) + if size <= 1 then + return math.ceil(size * viewport) + end + return math.min(size, viewport) +end + ---@param opts WindowOpts ---@param sizes_only boolean Whether to only return properties that control the window size. local function create_popup_window_opts(opts, sizes_only) + local lines = vim.o.lines - vim.o.cmdheight local columns = vim.o.columns - local top_offset = 1 - local bottom_offset = 1 + vim.o.cmdheight - if vim.o.laststatus == 0 then - bottom_offset = math.max(bottom_offset - 1, 1) - end - local height = vim.o.lines - bottom_offset - top_offset - local width = math.floor(columns * 0.8) + local height = calc_size(settings.current.ui.height, lines) + local width = calc_size(settings.current.ui.width, columns) + local row = math.floor((lines - height) / 2) + local col = math.floor((columns - width) / 2) local popup_layout = { height = height, width = width, - row = top_offset, - col = math.floor((columns - width) / 2), + row = row, + col = col, relative = "editor", style = "minimal", zindex = 45, diff --git a/lua/mason/settings.lua b/lua/mason/settings.lua index 9bdc0f9c..09726a5c 100644 --- a/lua/mason/settings.lua +++ b/lua/mason/settings.lua @@ -58,6 +58,16 @@ local DEFAULT_SETTINGS = { -- The border to use for the UI window. Accepts same border values as |nvim_open_win()|. border = "none", + -- Width of the window. Accepts: + -- - Integer greater than 1 for fixed width. + -- - Float in the range of 0-1 for a percentage of screen width. + width = 0.8, + + -- Height of the window. Accepts: + -- - Integer greater than 1 for fixed height. + -- - Float in the range of 0-1 for a percentage of screen height. + height = 0.9, + icons = { -- The list icon to use for installed packages. package_installed = "◍", |
