Merge pull request #86 from jonathf/master

custom terminal creation command
This commit is contained in:
ThePrimeagen 2021-06-10 10:26:44 -06:00 committed by GitHub
commit 65d1b43428
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,11 +4,14 @@ local log = require("harpoon.dev").log
local M = {} local M = {}
local terminals = {} local terminals = {}
local function create_terminal() local function create_terminal(create_with)
log.trace("_create_terminal()") if not create_with then
create_with = ":terminal"
end
log.trace("_create_terminal(): Init:", create_with)
local current_id = vim.fn.bufnr() local current_id = vim.fn.bufnr()
vim.cmd(":terminal") vim.cmd(create_with)
local buf_id = vim.fn.bufnr() local buf_id = vim.fn.bufnr()
local term_id = vim.b.terminal_job_id local term_id = vim.b.terminal_job_id
@ -27,11 +30,14 @@ local function create_terminal()
return buf_id, term_id return buf_id, term_id
end end
local function find_terminal(idx) local function find_terminal(args)
log.trace("_find_terminal(): Terminal:", idx) log.trace("_find_terminal(): Terminal:", args)
local term_handle = terminals[idx] if type(args) == "number" then
args = { idx = args }
end
local term_handle = terminals[args.idx]
if not term_handle or not vim.api.nvim_buf_is_valid(term_handle.buf_id) 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() local buf_id, term_id = create_terminal(args.create_with)
if buf_id == nil then if buf_id == nil then
return return
end end
@ -40,7 +46,7 @@ local function find_terminal(idx)
buf_id = buf_id, buf_id = buf_id,
term_id = term_id, term_id = term_id,
} }
terminals[idx] = term_handle terminals[args.idx] = term_handle
end end
return term_handle return term_handle
end end