-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #257 from qujihan/master
增加新的runner
- Loading branch information
Showing
4 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function! asyncrun#runner#toggleterm2#run(opts) | ||
lua require("asyncrun_toggleterm").runner(vim.fn.eval("a:opts")) | ||
endfunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
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 | ||
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") | ||
else | ||
vim.notify("Delete existing terminal", "info") | ||
end | ||
M._asyncrun_term:shutdown() | ||
end | ||
|
||
M._asyncrun_term = nil | ||
M._asyncrun_term_toggle = nil | ||
end | ||
|
||
function M.runner(opts) | ||
M.reset() | ||
M._asyncrun_term = terminal:new({ | ||
cmd = opts.cmd, | ||
dir = opts.cwd, | ||
close_on_exit = false, | ||
hidden = true, | ||
on_open = function(term) | ||
if M._start_in_insert then | ||
vim.cmd("startinsert!") | ||
else | ||
vim.cmd("stopinsert!") | ||
end | ||
end | ||
}) | ||
|
||
function M._asyncrun_term_toggle() | ||
M._asyncrun_term:toggle() | ||
end | ||
|
||
if not opts.silent then | ||
M._asyncrun_term_toggle() | ||
end | ||
|
||
if M._asyncrun_mapping then | ||
vim.api.nvim_set_keymap("n", M._asyncrun_mapping, | ||
"<cmd>lua require('asyncrun_toggleterm')._asyncrun_term_toggle()<CR>", { | ||
noremap = true, | ||
silent = true | ||
}) | ||
end | ||
end | ||
|
||
return M |