Skip to content

Commit 88ebb7d

Browse files
amirt01amirt-ms
andauthored
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]>
1 parent f36f0a6 commit 88ebb7d

4 files changed

Lines changed: 78 additions & 0 deletions

File tree

lua/cmake-tools/const.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ local const = {
5858
require("overseer").open({ enter = false, direction = "right" })
5959
end, -- a function that gets overseer.Task when it is created, before calling `task:start`
6060
},
61+
vimux = {},
6162
terminal = {
6263
name = "Executor Terminal",
6364
prefix_name = "[CMakeTools]: ", -- This must be included and must be unique, otherwise the terminals will not work. Do not use a simple spacebar " ", or any generic name
@@ -105,6 +106,7 @@ local const = {
105106
}, -- options to pass into the `overseer.new_task` command
106107
on_new_task = function(task) end, -- a function that gets overseer.Task when it is created, before calling `task:start`
107108
},
109+
vimux = {},
108110
terminal = {
109111
name = "Runner Terminal",
110112
prefix_name = "[CMakeTools]: ", -- This must be included and must be unique, otherwise the terminals will not work. Do not use a simple spacebar " ", or any generic name

lua/cmake-tools/executors/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ return {
33
terminal = require("cmake-tools.terminal"),
44
overseer = require("cmake-tools.overseer"),
55
toggleterm = require("cmake-tools.toggleterm"),
6+
vimux = require("cmake-tools.vimux"),
67
}

lua/cmake-tools/runners/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ return {
33
terminal = require("cmake-tools.terminal"),
44
overseer = require("cmake-tools.overseer"),
55
toggleterm = require("cmake-tools.toggleterm"),
6+
vimux = require("cmake-tools.vimux"),
67
}

lua/cmake-tools/vimux.lua

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
local terminal = require("cmake-tools.terminal")
2+
local osys = require("cmake-tools.osys")
3+
local utils = require("cmake-tools.utils")
4+
---@class vimux : terminal
5+
local _vimux = {
6+
id = nil,
7+
}
8+
9+
function _vimux.show(opts)
10+
vim.fn.VimuxInspectRunner()
11+
end
12+
13+
function _vimux.close(opts)
14+
vim.fn.VimuxCloseRunner()
15+
end
16+
17+
function _vimux.run(cmd, env_script, env, args, cwd, opts, on_exit, on_output)
18+
local full_cmd = _vimux.prepare_cmd_for_run(cmd, env, args, cwd)
19+
vim.fn.VimuxRunCommand(full_cmd)
20+
terminal.handle_exit(opts, on_exit, opts.close_on_exit)
21+
end
22+
23+
function _vimux.has_active_job(opts)
24+
return false
25+
end
26+
27+
function _vimux.stop(opts)
28+
vim.fn.VimuxSendKeys("C-c")
29+
end
30+
31+
---Check if the executor is installed and can be used
32+
---@return string|boolean
33+
function _vimux.is_installed()
34+
if not vim.fn.exists(":VimuxRunCommand") then
35+
return "Vimux plugin is missing, please install it"
36+
end
37+
return true
38+
end
39+
40+
function _vimux.prepare_cmd_for_run(cmd, env, args, cwd)
41+
local full_cmd = ""
42+
43+
-- Launch form executable's build directory by default
44+
full_cmd = "cd " .. utils.transform_path(cwd) .. " &&"
45+
46+
if osys.iswin32 then
47+
for k, v in pairs(env) do
48+
full_cmd = full_cmd .. " set " .. k .. "=" .. v .. "&&"
49+
end
50+
else
51+
for k, v in pairs(env) do
52+
full_cmd = full_cmd .. " " .. k .. "=" .. v .. ""
53+
end
54+
end
55+
56+
full_cmd = full_cmd .. " " .. utils.transform_path(cmd)
57+
58+
if osys.islinux or osys.iswsl or osys.ismac then
59+
full_cmd = " " .. full_cmd -- adding a space in front of the command prevents bash from recording the command in the history (if configured)
60+
end
61+
62+
-- Add args to the cmd
63+
for _, arg in ipairs(args) do
64+
full_cmd = full_cmd .. " " .. arg
65+
end
66+
67+
if osys.iswin32 then -- wrap in sub process to prevent env vars from being persited
68+
full_cmd = 'cmd /C "' .. full_cmd .. '"'
69+
end
70+
71+
return full_cmd
72+
end
73+
74+
return _vimux

0 commit comments

Comments
 (0)