Merge pull request #16 from ThePrimeagen/term-bug

Term bug
This commit is contained in:
ThePrimeagen 2021-02-28 19:50:59 -07:00 committed by GitHub
commit eeef833d5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,31 +26,31 @@ function getCmd(idx)
return
end
M.gotoTerminal = function(idx)
function find_terminal(idx)
local term_handle = terminals[idx]
if not term_handle then
if not term_handle or not vim.api.nvim_buf_is_valid(term_handle.buf_id) then
local buf_id, term_id = create_terminal()
if buf_id == nil then
return
end
term_handle = {
buf_id = buf_id,
term_id = term_id
}
terminals[idx] = term_handle
end
return term_handle
end
M.gotoTerminal = function(idx)
local term_handle = find_terminal(idx)
vim.api.nvim_set_current_buf(term_handle.buf_id)
end
M.sendCommand = function(idx, cmd)
local term_handle = terminals[idx]
if not term_handle then
M.gotoTerminal(idx)
term_handle = terminals[idx]
end
local term_handle = find_terminal(idx)
if type(cmd) == "number" then
cmd = terminal_config.cmds[cmd]