rework: removed max preset and made it default as nil instead

This commit is contained in:
DarthMooMancer
2025-05-14 22:20:35 -04:00
parent eb3e75fe67
commit 9105add777
4 changed files with 37 additions and 19 deletions
+2 -2
View File
@@ -121,7 +121,7 @@ cpp = {
```lua ```lua
-- In Neovim 0.11+, numbers don't work so they will be reimplemented later -- In Neovim 0.11+, numbers don't work so they will be reimplemented later
terminal = { terminal = {
preset = "max", -- "max", "right", "corner" preset = nil, -- also try : ("right", "corner")
border = true, border = true
} }
``` ```
+1 -1
View File
@@ -8,7 +8,7 @@ M.defaults = {
} }
}, },
terminal = { terminal = {
preset = "max", preset = nil,
border = true, border = true,
} }
} }
+18 -12
View File
@@ -1,12 +1,17 @@
local M = {} 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 = { local presets = {
max = {
left_padding = 0,
right_padding = 0,
top_padding = 0,
bottom_padding = 0
},
right = { right = {
left_padding = 100, left_padding = 100,
right_padding = 0, right_padding = 0,
@@ -21,16 +26,17 @@ local presets = {
} }
} }
---@param preset string
---@return table|nil
function M.getPresets(preset) function M.getPresets(preset)
if preset == "max" then if presets[preset] ~= nil then
return presets.max return presets[preset]
elseif preset == "right" then elseif presets[preset] == nil then
return presets.right return nil
elseif preset == "corner" then
return presets.corner
else else
print("Preset option: " .. preset .. " does not exist") print("Preset option: " .. preset .. " does not exist")
end end
return {}
end end
return M return M
+16 -4
View File
@@ -54,11 +54,23 @@ end
function M.terminal(cmd) function M.terminal(cmd)
local opts = require("Polydev.presets").getPresets(M.opts.preset) local opts = require("Polydev.presets").getPresets(M.opts.preset)
local ui = vim.api.nvim_list_uis()[1] 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) if opts ~= nil then
local height = math.max(1, math.floor(ui.height * 0.9) - opts.top_padding - opts.bottom_padding) width = math.max(1, math.floor(ui.width * 0.9) - opts.left_padding - opts.right_padding)
local row = math.floor((ui.height - height) / 2) + opts.top_padding height = math.max(1, math.floor(ui.height * 0.9) - opts.top_padding - opts.bottom_padding)
local col = math.floor((ui.width - width) / 2) + opts.left_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 buf = vim.api.nvim_create_buf(false, true)
local win = vim.api.nvim_open_win(buf, true, { local win = vim.api.nvim_open_win(buf, true, {