feat(utils): added ability to have floating or split windows and anchors of where each are

fix(ui): also changed deprecated features to use newer features by
neovim
This commit is contained in:
DarthMooMancer
2025-05-17 18:33:55 -04:00
parent eea8def35c
commit e6c3353b51
5 changed files with 93 additions and 51 deletions
+4 -1
View File
@@ -53,7 +53,10 @@ function M.setup(user_opts)
},
},
terminal = {
preset = nil,
mode = "split", -- floating or split
win = {
type = "vertical", anchor = "right" -- type: "vertical" or "horizonal" -- anchor: "below" or "right" or "center" or "corner"
},
border = {
enabled = true,
type = "rounded",
+3 -1
View File
@@ -29,7 +29,9 @@ local presets = {
---@param preset string
---@return table|nil
function M.getPresets(preset)
return presets[preset]
if presets[preset] then
return presets[preset]
end
end
return M
+2 -2
View File
@@ -4,10 +4,10 @@ local M = {}
---@return table
local function get_entries(path)
local result = {}
local handle = vim.loop.fs_scandir(path)
local handle = vim.uv.fs_scandir(path)
if not handle then return result end
while true do
local name, type = vim.loop.fs_scandir_next(handle)
local name, type = vim.uv.fs_scandir_next(handle)
if not name then break end
-- Check if this is a project file
local is_project = false
+63 -43
View File
@@ -5,13 +5,6 @@ function M.setup(opts)
M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("terminal"), opts or {})
end
---@param path string
---@return boolean|nil
function M.is_dir(path)
local stat = vim.loop.fs_stat(path)
return stat and stat.type == "directory"
end
---@return string
function M.get_project_root()
local plugin_dir = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":h:h:h")
@@ -50,46 +43,73 @@ function M.init_git(path, gitignore_lines)
end
---@param cmd table
---@return integer, integer
---@return integer, integer?
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
if M.opts.mode == "floating" then
local opts = require("Polydev.presets").getPresets(M.opts.win.anchor)
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
local ui = vim.api.nvim_list_uis()[1]
local width
local height
local row
local col
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, {
relative = "editor",
width = width,
height = height,
row = row,
col = col,
style = "minimal",
border = M.opts.border.enabled and M.opts.border.type,
})
vim.api.nvim_set_option_value("winblend", vim.o.pumblend, { win = win })
vim.api.nvim_set_option_value("winhighlight", "Normal:PolydevNormal,FloatBorder:PolydevBorder", { win = win })
vim.api.nvim_set_option_value("cursorline", true, { win = win })
vim.api.nvim_set_option_value("scrolloff", 5, { win = win })
vim.fn.jobstart(table.concat(cmd, "/"), { term = true })
vim.api.nvim_buf_set_keymap(buf, "n", "<ESC>", "i<C-\\><C-n>:q<CR>", { noremap = true, silent = true })
return buf, win
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)
if M.opts.mode == "split" then
if M.opts.win.type == "vertical" then
if M.opts.win.anchor == "right" then
vim.cmd("set splitright")
end
end
if M.opts.win.type == "horizontal" then
if M.opts.anchor == "bottom" then
vim.cmd("set splitbelow")
end
end
if M.opts.win.type == "vertical" then
vim.cmd("vsplit")
end
if M.opts.win.type == "horizontal" then
vim.cmd("split")
end
local buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_win_set_buf(0, buf)
vim.fn.jobstart(table.concat(cmd, "/"), { term = true })
vim.api.nvim_buf_set_keymap(buf, "n", "<ESC>", "i<C-\\><C-n>:q<CR>", { noremap = true, silent = true })
return buf
end
local buf = vim.api.nvim_create_buf(false, true)
local win = vim.api.nvim_open_win(buf, true, {
relative = "editor",
width = width,
height = height,
row = row,
col = col,
style = "minimal",
border = M.opts.border.enabled and M.opts.border.type,
})
vim.api.nvim_set_option_value("winblend", vim.o.pumblend, { win = win })
vim.api.nvim_set_option_value("winhighlight", "Normal:Pmenu,FloatBorder:Pmenu", { win = win })
vim.api.nvim_set_option_value("cursorline", true, { win = win })
vim.api.nvim_set_option_value("scrolloff", 5, { win = win })
vim.fn.jobstart(table.concat(cmd, "/"), { term = true })
vim.api.nvim_buf_set_keymap(buf, "n", "<ESC>", "i<C-\\><C-n>:q<CR>", { noremap = true, silent = true })
return buf, win
return 0
end
return M