aboutsummaryrefslogtreecommitdiffstats
path: root/lua/mason-core/ui/display.lua
diff options
context:
space:
mode:
authorZeng <76579810+Bekaboo@users.noreply.github.com>2023-01-15 12:18:45 -0600
committerGitHub <noreply@github.com>2023-01-15 19:18:45 +0100
commit6eb540dc055cdf32ebeae020c51c7d792d7247bc (patch)
tree07f56b676e43cf0a42181a6e635078b5d2486789 /lua/mason-core/ui/display.lua
parentfix(vala-lanaguager-server): update meson build commands (#896) (diff)
downloadmason-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)
Diffstat (limited to 'lua/mason-core/ui/display.lua')
-rw-r--r--lua/mason-core/ui/display.lua26
1 files changed, 17 insertions, 9 deletions
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,