-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathtoggleterm2.lua
More file actions
63 lines (56 loc) · 1.67 KB
/
Copy pathtoggleterm2.lua
File metadata and controls
63 lines (56 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
local terminal = require("toggleterm.terminal").Terminal
local M = {}
M.setup = function(opts)
M._asyncrun_mapping = opts.mapping
M._start_in_insert = opts.start_in_insert
M._clear_env = opts.clear_env
M._go_back = opts.go_back
end
function M.reset()
if M._asyncrun_term ~= nil then
if vim.g.asynctasks_term_reuse ~= 1 then
-- TODO: handle multiple terminals
error("Terminal existed is not support . please set g.asynctasks_term_reuse = 1")
end
M._asyncrun_term:shutdown()
M._asyncrun_term = nil
end
end
function M.runner(opts)
M.reset()
M._asyncrun_term = terminal:new({
cmd = opts.cmd,
dir = opts.cwd,
close_on_exit = (opts.close == "1") and true or false,
hidden = true,
clear_env = M._clear_env or false,
on_open = function(term)
if M._start_in_insert then
vim.cmd("startinsert!")
else
vim.cmd("stopinsert")
end
end,
on_exit = function(term, job_id, exit_code, event_name)
vim.g.asyncrun_code = exit_code
vim.cmd("doautocmd User AsyncRunStop")
end,
})
function M._asyncrun_term_toggle()
M._asyncrun_term:toggle()
end
if not opts.silent then
M._asyncrun_term_toggle()
if M._go_back then
vim.cmd("wincmd p")
end
end
if M._asyncrun_mapping then
vim.api.nvim_set_keymap("n", M._asyncrun_mapping,
"<cmd>lua require('asyncrun.toggleterm2')._asyncrun_term_toggle()<CR>", {
noremap = true,
silent = true
})
end
end
return M