REFACTOR: Cleaning up project and removing more deprecated code
This commit is contained in:
+50
-63
@@ -19,91 +19,78 @@ end
|
||||
---@return integer, integer?
|
||||
function M.terminal(cmd, opts)
|
||||
opts = opts or {}
|
||||
if opts.terminal.mode == "floating" then
|
||||
local buf, win
|
||||
if opts.mode.type == "float" then
|
||||
local ui = vim.api.nvim_list_uis()[1]
|
||||
local width, height, row, col
|
||||
|
||||
if opts.terminal ~= nil then
|
||||
local dim = {
|
||||
width = math.max(
|
||||
1,
|
||||
math.floor(ui.width * 0.9)
|
||||
- opts.terminal.left
|
||||
- opts.terminal.right
|
||||
)
|
||||
- opts.mode.win.float.padding.left
|
||||
- opts.mode.win.float.padding.right
|
||||
),
|
||||
height = math.max(
|
||||
1,
|
||||
math.floor(ui.height * 0.9)
|
||||
- opts.terminal.top
|
||||
- opts.terminal.bottom
|
||||
)
|
||||
row = math.floor((ui.height - height) / 2) + opts.terminal.top
|
||||
col = math.floor((ui.width - width) / 2) + opts.terminal.left
|
||||
end
|
||||
if opts.terminal == 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, {
|
||||
- opts.mode.win.float.padding.top
|
||||
- opts.mode.win.float.padding.bottom
|
||||
),
|
||||
}
|
||||
|
||||
local pos = {
|
||||
row = math.floor(
|
||||
(
|
||||
ui.height
|
||||
- (vim.o.laststatus == 3 and 1 or 0)
|
||||
- vim.o.cmdheight
|
||||
- dim.height
|
||||
) / 2
|
||||
),
|
||||
col = math.floor((ui.width - dim.width) / 2),
|
||||
}
|
||||
|
||||
buf = vim.api.nvim_create_buf(false, true)
|
||||
win = vim.api.nvim_open_win(buf, true, {
|
||||
relative = "editor",
|
||||
width = width,
|
||||
height = height,
|
||||
row = row,
|
||||
col = col,
|
||||
width = dim.width,
|
||||
height = dim.height,
|
||||
row = pos.row,
|
||||
col = pos.col,
|
||||
style = "minimal",
|
||||
border = opts.terminal.border.enabled and opts.terminal.border.type,
|
||||
border = opts.mode.win.float.border.enabled
|
||||
and opts.mode.win.float.border.type
|
||||
or nil,
|
||||
})
|
||||
vim.api.nvim_set_option_value(
|
||||
"winhighlight",
|
||||
"Normal:PolydevNormal,FloatBorder:PolydevBorder",
|
||||
{ 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.terminal.mode == "split" then
|
||||
if opts.terminal.win.type == "vertical" then
|
||||
if opts.terminal.win.anchor == "right" then
|
||||
if opts.mode.type == "split" then
|
||||
if opts.mode.win.split.type == "vertical" then
|
||||
if opts.mode.win.split.anchor == "right" then
|
||||
vim.cmd("set splitright")
|
||||
end
|
||||
vim.cmd(opts.mode.win.split.size .. " vsplit")
|
||||
end
|
||||
if opts.terminal.win.type == "horizontal" then
|
||||
if opts.terminal.win.anchor == "bottom" then
|
||||
if opts.mode.win.split.type == "horizontal" then
|
||||
if opts.mode.win.split.anchor == "bottom" then
|
||||
vim.cmd("set splitbelow")
|
||||
end
|
||||
vim.cmd(opts.mode.win.split.size .. " split")
|
||||
end
|
||||
|
||||
if opts.terminal.win.type == "vertical" then
|
||||
vim.cmd(opts.terminal.win.size .. " vsplit")
|
||||
end
|
||||
if opts.terminal.win.type == "horizontal" then
|
||||
vim.cmd(opts.terminal.win.size .. " split")
|
||||
end
|
||||
local buf = vim.api.nvim_create_buf(false, true)
|
||||
local win = vim.api.nvim_get_current_win()
|
||||
buf = vim.api.nvim_create_buf(false, true)
|
||||
win = vim.api.nvim_get_current_win()
|
||||
|
||||
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, win
|
||||
end
|
||||
return 0
|
||||
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
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user