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:
+21
-4
@@ -114,14 +114,31 @@ cpp = {
|
|||||||
["<leader>pr"] = "CppRun",
|
["<leader>pr"] = "CppRun",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## **Terminal Configuration**
|
## **Terminal Configuration**
|
||||||
```lua
|
```lua
|
||||||
-- In Neovim 0.11+, numbers don't work so they will be reimplemented later
|
|
||||||
terminal = {
|
terminal = {
|
||||||
preset = nil, -- also try : ("right", "corner")
|
-- floating or split
|
||||||
border = true
|
mode = "split",
|
||||||
|
win = {
|
||||||
|
-- type: "vertical" or "horizonal" -- Only for split windows
|
||||||
|
-- anchor: "bottom" or "right" or "center" or "corner"
|
||||||
|
-- "bottom" and "right" are only split anchors
|
||||||
|
-- "center" and "corner" are only floating anchors
|
||||||
|
type = "vertical", anchor = "right"
|
||||||
|
},
|
||||||
|
border = {
|
||||||
|
enabled = true,
|
||||||
|
-- type: border decoration, follows `winborder`
|
||||||
|
-- "bold": Bold line box.
|
||||||
|
-- "double": Double-line box.
|
||||||
|
-- "none": No border.
|
||||||
|
-- "rounded": Like "single", but with rounded corners ("╭" etc.).
|
||||||
|
-- "shadow": Drop shadow effect, by blending with the background.
|
||||||
|
-- "single": Single-line box.
|
||||||
|
-- "solid": Adds padding by a single whitespace cell.
|
||||||
|
type = "rounded"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -53,7 +53,10 @@ function M.setup(user_opts)
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
terminal = {
|
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 = {
|
border = {
|
||||||
enabled = true,
|
enabled = true,
|
||||||
type = "rounded",
|
type = "rounded",
|
||||||
|
|||||||
@@ -29,7 +29,9 @@ local presets = {
|
|||||||
---@param preset string
|
---@param preset string
|
||||||
---@return table|nil
|
---@return table|nil
|
||||||
function M.getPresets(preset)
|
function M.getPresets(preset)
|
||||||
|
if presets[preset] then
|
||||||
return presets[preset]
|
return presets[preset]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
+2
-2
@@ -4,10 +4,10 @@ local M = {}
|
|||||||
---@return table
|
---@return table
|
||||||
local function get_entries(path)
|
local function get_entries(path)
|
||||||
local result = {}
|
local result = {}
|
||||||
local handle = vim.loop.fs_scandir(path)
|
local handle = vim.uv.fs_scandir(path)
|
||||||
if not handle then return result end
|
if not handle then return result end
|
||||||
while true do
|
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
|
if not name then break end
|
||||||
-- Check if this is a project file
|
-- Check if this is a project file
|
||||||
local is_project = false
|
local is_project = false
|
||||||
|
|||||||
+32
-12
@@ -5,13 +5,6 @@ function M.setup(opts)
|
|||||||
M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("terminal"), opts or {})
|
M.opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get("terminal"), opts or {})
|
||||||
end
|
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
|
---@return string
|
||||||
function M.get_project_root()
|
function M.get_project_root()
|
||||||
local plugin_dir = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":h:h:h")
|
local plugin_dir = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":h:h:h")
|
||||||
@@ -50,9 +43,11 @@ function M.init_git(path, gitignore_lines)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@param cmd table
|
---@param cmd table
|
||||||
---@return integer, integer
|
---@return integer, integer?
|
||||||
function M.terminal(cmd)
|
function M.terminal(cmd)
|
||||||
local opts = require("Polydev.presets").getPresets(M.opts.preset)
|
if M.opts.mode == "floating" then
|
||||||
|
local opts = require("Polydev.presets").getPresets(M.opts.win.anchor)
|
||||||
|
|
||||||
local ui = vim.api.nvim_list_uis()[1]
|
local ui = vim.api.nvim_list_uis()[1]
|
||||||
local width
|
local width
|
||||||
local height
|
local height
|
||||||
@@ -71,7 +66,6 @@ function M.terminal(cmd)
|
|||||||
row = math.floor((ui.height - height) / 2)
|
row = math.floor((ui.height - height) / 2)
|
||||||
col = math.floor((ui.width - width) / 2)
|
col = math.floor((ui.width - width) / 2)
|
||||||
end
|
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, {
|
||||||
relative = "editor",
|
relative = "editor",
|
||||||
@@ -83,13 +77,39 @@ function M.terminal(cmd)
|
|||||||
border = M.opts.border.enabled and M.opts.border.type,
|
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("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("winhighlight", "Normal:PolydevNormal,FloatBorder:PolydevBorder", { win = win })
|
||||||
vim.api.nvim_set_option_value("cursorline", true, { win = win })
|
vim.api.nvim_set_option_value("cursorline", true, { win = win })
|
||||||
vim.api.nvim_set_option_value("scrolloff", 5, { win = win })
|
vim.api.nvim_set_option_value("scrolloff", 5, { win = win })
|
||||||
|
|
||||||
vim.fn.jobstart(table.concat(cmd, "/"), { term = true })
|
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 })
|
vim.api.nvim_buf_set_keymap(buf, "n", "<ESC>", "i<C-\\><C-n>:q<CR>", { noremap = true, silent = true })
|
||||||
return buf, win
|
return buf, win
|
||||||
|
end
|
||||||
|
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
|
||||||
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
Reference in New Issue
Block a user