-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tmux): Execute and Run with tmux (#258)
* initial commit [not-working] * working runner * close properly * add stop functionality * implement show * reintroduce removed function after merge the terminal executor/runner seems to have been changed since the last time I rebased so I reintroduced the necessary functions to make my vimux implementation work. --------- Co-authored-by: amirt-ms <[email protected]>
- Loading branch information
Showing
4 changed files
with
78 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
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,74 @@ | ||
local terminal = require("cmake-tools.terminal") | ||
local osys = require("cmake-tools.osys") | ||
local utils = require("cmake-tools.utils") | ||
---@class vimux : terminal | ||
local _vimux = { | ||
id = nil, | ||
} | ||
|
||
function _vimux.show(opts) | ||
vim.fn.VimuxInspectRunner() | ||
end | ||
|
||
function _vimux.close(opts) | ||
vim.fn.VimuxCloseRunner() | ||
end | ||
|
||
function _vimux.run(cmd, env_script, env, args, cwd, opts, on_exit, on_output) | ||
local full_cmd = _vimux.prepare_cmd_for_run(cmd, env, args, cwd) | ||
vim.fn.VimuxRunCommand(full_cmd) | ||
terminal.handle_exit(opts, on_exit, opts.close_on_exit) | ||
end | ||
|
||
function _vimux.has_active_job(opts) | ||
return false | ||
end | ||
|
||
function _vimux.stop(opts) | ||
vim.fn.VimuxSendKeys("C-c") | ||
end | ||
|
||
---Check if the executor is installed and can be used | ||
---@return string|boolean | ||
function _vimux.is_installed() | ||
if not vim.fn.exists(":VimuxRunCommand") then | ||
return "Vimux plugin is missing, please install it" | ||
end | ||
return true | ||
end | ||
|
||
function _vimux.prepare_cmd_for_run(cmd, env, args, cwd) | ||
local full_cmd = "" | ||
|
||
-- Launch form executable's build directory by default | ||
full_cmd = "cd " .. utils.transform_path(cwd) .. " &&" | ||
|
||
if osys.iswin32 then | ||
for k, v in pairs(env) do | ||
full_cmd = full_cmd .. " set " .. k .. "=" .. v .. "&&" | ||
end | ||
else | ||
for k, v in pairs(env) do | ||
full_cmd = full_cmd .. " " .. k .. "=" .. v .. "" | ||
end | ||
end | ||
|
||
full_cmd = full_cmd .. " " .. utils.transform_path(cmd) | ||
|
||
if osys.islinux or osys.iswsl or osys.ismac then | ||
full_cmd = " " .. full_cmd -- adding a space in front of the command prevents bash from recording the command in the history (if configured) | ||
end | ||
|
||
-- Add args to the cmd | ||
for _, arg in ipairs(args) do | ||
full_cmd = full_cmd .. " " .. arg | ||
end | ||
|
||
if osys.iswin32 then -- wrap in sub process to prevent env vars from being persited | ||
full_cmd = 'cmd /C "' .. full_cmd .. '"' | ||
end | ||
|
||
return full_cmd | ||
end | ||
|
||
return _vimux |