@@ -4,37 +4,40 @@ local M = {}
4
4
M .setup = function (opts )
5
5
M ._asyncrun_mapping = opts .mapping
6
6
M ._start_in_insert = opts .start_in_insert
7
+ M ._clear_env = opts .clear_env
8
+ M ._go_back = opts .go_back
7
9
end
8
10
9
11
function M .reset ()
10
12
if M ._asyncrun_term ~= nil then
11
13
if vim .g .asynctasks_term_reuse ~= 1 then
12
14
-- TODO: handle multiple terminals
13
15
error (" Terminal existed is not support . please set g.asynctasks_term_reuse = 1" )
14
- else
15
- vim .notify (" Delete existing terminal" , " info" )
16
16
end
17
17
M ._asyncrun_term :shutdown ()
18
+ M ._asyncrun_term = nil
18
19
end
19
-
20
- M ._asyncrun_term = nil
21
- M ._asyncrun_term_toggle = nil
22
20
end
23
21
24
22
function M .runner (opts )
25
23
M .reset ()
26
24
M ._asyncrun_term = terminal :new ({
27
25
cmd = opts .cmd ,
28
26
dir = opts .cwd ,
29
- close_on_exit = false ,
27
+ close_on_exit = ( opts . close == " 1 " ) and true or false ,
30
28
hidden = true ,
29
+ clear_env = M ._clear_env or false ,
31
30
on_open = function (term )
32
31
if M ._start_in_insert then
33
32
vim .cmd (" startinsert!" )
34
33
else
35
- vim .cmd (" stopinsert! " )
34
+ vim .cmd (" stopinsert" )
36
35
end
37
- end
36
+ end ,
37
+ on_exit = function (term , job_id , exit_code , event_name )
38
+ vim .g .asyncrun_code = exit_code
39
+ vim .cmd (" doautocmd User AsyncRunStop" )
40
+ end ,
38
41
})
39
42
40
43
function M ._asyncrun_term_toggle ()
@@ -43,11 +46,14 @@ function M.runner(opts)
43
46
44
47
if not opts .silent then
45
48
M ._asyncrun_term_toggle ()
49
+ if M ._go_back then
50
+ vim .cmd (" wincmd p" )
51
+ end
46
52
end
47
53
48
54
if M ._asyncrun_mapping then
49
55
vim .api .nvim_set_keymap (" n" , M ._asyncrun_mapping ,
50
- " <cmd>lua require('asyncrun_toggleterm ')._asyncrun_term_toggle()<CR>" , {
56
+ " <cmd>lua require('asyncrun.toggleterm2 ')._asyncrun_term_toggle()<CR>" , {
51
57
noremap = true ,
52
58
silent = true
53
59
})
0 commit comments