1
0
Fork 0
mirror of https://github.com/pnx/dotfiles synced 2026-06-16 11:24:55 +02:00

nvim: hacking with and height of telescope windows.

This commit is contained in:
Henrik Hautakoski 2025-01-18 17:27:12 +01:00
parent 35438bea75
commit a7538c250d
2 changed files with 54 additions and 5 deletions

View file

@ -37,14 +37,13 @@ return {
cycle_layout_list = { "horizontal", "vertical" },
layout_config = {
vertical = {
width = 0.5,
height = 0.6,
width = utils.width(0.5, { min = 80, max = 100, padding = 10}),
height = utils.height(0.6, { min = 15, max = 50, padding = 2}),
},
horizontal = {
width = 0.95,
height = 0.95,
width = utils.width(0.95, { min = 80, max = 180, padding = 10 }),
height = utils.height(0.95, { min = 15, max = 34, padding = 2 }),
preview_width = 0.5,
preview_cutoff = 200,
}
}
},

View file

@ -154,4 +154,54 @@ function M.buffer_view(opts)
end
end
---@param value integer
---@param screen integer
---@param min integer
---@param max integer
---@param padding integer
---@return integer
local function calculate_size(value, screen, min, max, padding)
if (min > 0) then
if (screen < (min + padding)) then
return math.max(screen - padding, 0)
end
value = math.max(value, min)
end
if (max > 0) then value = math.min(value, max) end
return value
end
---@class size_opts
---@field max integer?
---@field min integer?
---@field padding integer?
---@param percentage number
---@param opts size_opts
---@return function
function M.width(percentage, opts)
return function(_, screen_width)
local padding = opts.padding or 0
local max = opts.max or -1
local min = opts.min or -1
local width = math.floor(percentage * screen_width)
return calculate_size(width, screen_width, min, max, padding)
end
end
---@param percentage number
---@param opts size_opts
---@return function
function M.height(percentage, opts)
return function(_, _, screen_height)
local padding = opts.padding or 0
local max = opts.max or -1
local min = opts.min or -1
local height = math.floor(percentage * screen_height)
return calculate_size(height, screen_height, min, max, padding)
end
end
return M