@@ -4,37 +4,40 @@ local M = {}
44M .setup = function (opts )
55M ._asyncrun_mapping = opts .mapping
66M ._start_in_insert = opts .start_in_insert
7+ M ._clear_env = opts .clear_env
8+ M ._go_back = opts .go_back
79end
810
911function M .reset ()
1012if M ._asyncrun_term ~= nil then
1113if vim .g .asynctasks_term_reuse ~= 1 then
1214-- TODO: handle multiple terminals
1315error (" Terminal existed is not support . please set g.asynctasks_term_reuse = 1" )
14- else
15- vim .notify (" Delete existing terminal" ," info" )
1616end
1717M ._asyncrun_term :shutdown ()
18+ M ._asyncrun_term = nil
1819end
19-
20- M ._asyncrun_term = nil
21- M ._asyncrun_term_toggle = nil
2220end
2321
2422function M .runner (opts )
2523M .reset ()
2624M ._asyncrun_term = terminal :new ({
2725cmd = opts .cmd ,
2826dir = opts .cwd ,
29- close_on_exit = false ,
27+ close_on_exit = ( opts . close == " 1 " ) and true or false ,
3028hidden = true ,
29+ clear_env = M ._clear_env or false ,
3130on_open = function (term )
3231if M ._start_in_insert then
3332vim .cmd (" startinsert!" )
3433else
35- vim .cmd (" stopinsert! " )
34+ vim .cmd (" stopinsert" )
3635end
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 ,
3841 })
3942
4043function M ._asyncrun_term_toggle ()
@@ -43,11 +46,14 @@ function M.runner(opts)
4346
4447if not opts .silent then
4548M ._asyncrun_term_toggle ()
49+ if M ._go_back then
50+ vim .cmd (" wincmd p" )
51+ end
4652end
4753
4854if M ._asyncrun_mapping then
4955vim .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>" , {
5157noremap = true ,
5258silent = true
5359 })