summaryrefslogtreecommitdiff
path: root/lua/functions.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/functions.lua')
-rw-r--r--lua/functions.lua21
1 files changed, 11 insertions, 10 deletions
diff --git a/lua/functions.lua b/lua/functions.lua
index 12eca3a..1f088a8 100644
--- a/lua/functions.lua
+++ b/lua/functions.lua
@@ -12,6 +12,14 @@ function table.filter(list, predicate)
return filtered_list
end
+local function set_terminal_height(height)
+ if not vim.api.nvim_win_is_valid(vim.g.term_win) then
+ return
+ end
+
+ vim.api.nvim_win_set_height(vim.g.term_win, height)
+end
+
function _G.check_back_space()
local col = vim.api.nvim_win_get_cursor(0)[2]
@@ -32,14 +40,13 @@ function _G.show_documentation()
end
end
-function _G.toggle_terminal(height)
+function _G.toggle_terminal()
if vim.fn.win_gotoid(vim.g.term_win) == 1 then
- vim.g.is_term_open = 0
vim.cmd("quit!")
else
vim.cmd("botright new")
- vim.cmd("resize " .. height)
+ vim.api.nvim_win_set_height(vim.fn.win_getid(), vim.g.terminal_height)
if not pcall(function() vim.cmd("buffer " .. vim.g.term_buf) end) then
vim.fn.termopen(vim.env.SHELL, {detach=0})
@@ -54,7 +61,6 @@ function _G.toggle_terminal(height)
vim.cmd("startinsert!")
vim.g.term_win = vim.fn.win_getid()
- vim.g.is_term_open = 1
if vim.fn.exists("g:NERDTree") and vim.api.nvim_eval("g:NERDTree.IsOpen()") then
vim.cmd("NERDTreeFocus")
@@ -114,11 +120,6 @@ function _G.close_current_buffer()
vim.api.nvim_buf_delete(current_buf_nr, { force = true })
- -- Resize terminal
- if vim.g.is_term_open == 1 then
- vim.cmd("wincmd j")
- vim.cmd("resize " .. vim.g.terminal_height)
- vim.cmd("wincmd k")
- end
+ set_terminal_height(vim.g.terminal_height)
end