Updating terminal to be simplifed and easier to manage
added a few features like border, relative numbers and scrolloff. Hope it works
This commit is contained in:
+40
-4
@@ -12,6 +12,7 @@ M.config = {
|
|||||||
terminal = {
|
terminal = {
|
||||||
width_pad = 10,
|
width_pad = 10,
|
||||||
height_pad = 10,
|
height_pad = 10,
|
||||||
|
border = true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,27 +32,62 @@ function M.setup(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Open floating terminal
|
-- Open floating terminal
|
||||||
local function open_float_terminal(cmd)
|
function M.open_float_terminal(cmd)
|
||||||
local ui = vim.api.nvim_list_uis()[1]
|
local ui = vim.api.nvim_list_uis()[1]
|
||||||
local width, height = math.floor(ui.width * 0.9), math.floor(ui.height * 0.9)
|
local width, height = math.floor(ui.width * 0.9), math.floor(ui.height * 0.9)
|
||||||
local row, col = math.floor(ui.height * 0.05), math.floor(ui.width * 0.05)
|
local row, col = math.floor(ui.height * 0.05), math.floor(ui.width * 0.05)
|
||||||
|
|
||||||
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", width = width - M.config.terminal.width_pad, height = height - M.config.terminal.height_pad,
|
relative = "editor",
|
||||||
row = row + 5, col = col + 5, style = "minimal", border = "rounded"
|
width = width - M.config.terminal.width_pad,
|
||||||
|
height = height - M.config.terminal.height_pad,
|
||||||
|
row = row,
|
||||||
|
col = col,
|
||||||
|
style = "minimal",
|
||||||
|
border = M.config.terminal.border and "rounded" or "none",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Enable scrolling, relative line numbers, and prevent closing on click
|
||||||
vim.api.nvim_win_set_option(win, "winblend", vim.o.pumblend)
|
vim.api.nvim_win_set_option(win, "winblend", vim.o.pumblend)
|
||||||
vim.api.nvim_win_set_option(win, "winhighlight", "Normal:Pmenu,FloatBorder:Pmenu")
|
vim.api.nvim_win_set_option(win, "winhighlight", "Normal:Pmenu,FloatBorder:Pmenu")
|
||||||
|
vim.api.nvim_win_set_option(win, "number", true)
|
||||||
|
vim.api.nvim_win_set_option(win, "relativenumber", true)
|
||||||
|
vim.api.nvim_win_set_option(win, "scrolloff", 5)
|
||||||
|
vim.api.nvim_win_set_option(win, "cursorline", true)
|
||||||
|
|
||||||
vim.fn.termopen(cmd)
|
vim.fn.termopen(cmd)
|
||||||
vim.cmd("startinsert")
|
vim.cmd("startinsert")
|
||||||
|
|
||||||
vim.api.nvim_buf_set_keymap(buf, "t", "<Esc>", "<C-\\><C-n>:q<CR>", { noremap = true, silent = true })
|
-- Keymaps: ESC to exit Terminal mode, <C-q> to close the floating terminal
|
||||||
|
vim.api.nvim_buf_set_keymap(buf, "t", "<Esc>", "<C-\\><C-n>", { noremap = true, silent = true })
|
||||||
|
vim.api.nvim_buf_set_keymap(buf, "t", "<C-q>", "<C-\\><C-n>:q<CR>", { noremap = true, silent = true })
|
||||||
|
|
||||||
return buf, win
|
return buf, win
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- -- Open floating terminal
|
||||||
|
-- local function open_float_terminal(cmd)
|
||||||
|
-- local ui = vim.api.nvim_list_uis()[1]
|
||||||
|
-- local width, height = math.floor(ui.width * 0.9), math.floor(ui.height * 0.9)
|
||||||
|
-- local row, col = math.floor(ui.height * 0.05), math.floor(ui.width * 0.05)
|
||||||
|
--
|
||||||
|
-- local buf = vim.api.nvim_create_buf(false, true)
|
||||||
|
-- local win = vim.api.nvim_open_win(buf, true, {
|
||||||
|
-- relative = "editor", width = width - M.config.terminal.width_pad, height = height - M.config.terminal.height_pad,
|
||||||
|
-- row = row + 5, col = col + 5, style = "minimal", border = "rounded"
|
||||||
|
-- })
|
||||||
|
--
|
||||||
|
-- vim.api.nvim_win_set_option(win, "winblend", vim.o.pumblend)
|
||||||
|
-- vim.api.nvim_win_set_option(win, "winhighlight", "Normal:Pmenu,FloatBorder:Pmenu")
|
||||||
|
--
|
||||||
|
-- vim.fn.termopen(cmd)
|
||||||
|
-- vim.cmd("startinsert")
|
||||||
|
--
|
||||||
|
-- vim.api.nvim_buf_set_keymap(buf, "t", "<Esc>", "<C-\\><C-n>:q<CR>", { noremap = true, silent = true })
|
||||||
|
-- return buf, win
|
||||||
|
-- end
|
||||||
|
|
||||||
-- Create a new Java project
|
-- Create a new Java project
|
||||||
function M.create_project()
|
function M.create_project()
|
||||||
-- Use vim.ui.input for better handling of input
|
-- Use vim.ui.input for better handling of input
|
||||||
|
|||||||
Reference in New Issue
Block a user