From 9105add77780b9941a38ba247d0434c6d6c0eff3 Mon Sep 17 00:00:00 2001 From: DarthMooMancer <107283522+DarthMooMancer@users.noreply.github.com> Date: Wed, 14 May 2025 22:20:35 -0400 Subject: [PATCH] rework: removed max preset and made it default as nil instead --- docs/setup.md | 4 ++-- lua/Polydev/configs.lua | 2 +- lua/Polydev/presets.lua | 30 ++++++++++++++++++------------ lua/Polydev/utils.lua | 20 ++++++++++++++++---- 4 files changed, 37 insertions(+), 19 deletions(-) diff --git a/docs/setup.md b/docs/setup.md index 7660da9..7236d01 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -121,7 +121,7 @@ cpp = { ```lua -- In Neovim 0.11+, numbers don't work so they will be reimplemented later terminal = { - preset = "max", -- "max", "right", "corner" - border = true, + preset = nil, -- also try : ("right", "corner") + border = true } ``` diff --git a/lua/Polydev/configs.lua b/lua/Polydev/configs.lua index 1a61e5b..250b73f 100644 --- a/lua/Polydev/configs.lua +++ b/lua/Polydev/configs.lua @@ -8,7 +8,7 @@ M.defaults = { } }, terminal = { - preset = "max", + preset = nil, border = true, } } diff --git a/lua/Polydev/presets.lua b/lua/Polydev/presets.lua index ba93b84..e226962 100644 --- a/lua/Polydev/presets.lua +++ b/lua/Polydev/presets.lua @@ -1,12 +1,17 @@ local M = {} +---@class padding +---@field left_padding integer +---@field right_padding integer +---@field top_padding integer +---@field bottom_padding integer + +---@class preset_list +---@field right padding +---@field corner padding + +---@type preset_list local presets = { - max = { - left_padding = 0, - right_padding = 0, - top_padding = 0, - bottom_padding = 0 - }, right = { left_padding = 100, right_padding = 0, @@ -21,16 +26,17 @@ local presets = { } } +---@param preset string +---@return table|nil function M.getPresets(preset) - if preset == "max" then - return presets.max - elseif preset == "right" then - return presets.right - elseif preset == "corner" then - return presets.corner + if presets[preset] ~= nil then + return presets[preset] + elseif presets[preset] == nil then + return nil else print("Preset option: " .. preset .. " does not exist") end + return {} end return M diff --git a/lua/Polydev/utils.lua b/lua/Polydev/utils.lua index 62933d5..39c2bc8 100644 --- a/lua/Polydev/utils.lua +++ b/lua/Polydev/utils.lua @@ -54,11 +54,23 @@ end function M.terminal(cmd) local opts = require("Polydev.presets").getPresets(M.opts.preset) local ui = vim.api.nvim_list_uis()[1] + local width + local height + local row + local col - local width = math.max(1, math.floor(ui.width * 0.9) - opts.left_padding - opts.right_padding) - local height = math.max(1, math.floor(ui.height * 0.9) - opts.top_padding - opts.bottom_padding) - local row = math.floor((ui.height - height) / 2) + opts.top_padding - local col = math.floor((ui.width - width) / 2) + opts.left_padding + if opts ~= nil then + width = math.max(1, math.floor(ui.width * 0.9) - opts.left_padding - opts.right_padding) + height = math.max(1, math.floor(ui.height * 0.9) - opts.top_padding - opts.bottom_padding) + row = math.floor((ui.height - height) / 2) + opts.top_padding + col = math.floor((ui.width - width) / 2) + opts.left_padding + end + if opts == nil then + width = math.max(1, math.floor(ui.width * 0.9)) + height = math.max(1, math.floor(ui.height * 0.9)) + row = math.floor((ui.height - height) / 2) + col = math.floor((ui.width - width) / 2) + end local buf = vim.api.nvim_create_buf(false, true) local win = vim.api.nvim_open_win(buf, true, {