diff --git a/README.md b/README.md index 0cc70e9a..5439e86e 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ require("cmake-tools").setup { direction = "float", -- 'vertical' | 'horizontal' | 'tab' | 'float' close_on_exit = false, -- whether close the terminal when exit auto_scroll = true, -- whether auto scroll to the bottom + singleton = true, -- single instance, autocloses the opened one, if present }, overseer = { new_task_opts = { @@ -114,6 +115,7 @@ require("cmake-tools").setup { direction = "float", -- 'vertical' | 'horizontal' | 'tab' | 'float' close_on_exit = false, -- whether close the terminal when exit auto_scroll = true, -- whether auto scroll to the bottom + singleton = true, -- single instance, autocloses the opened one, if present }, overseer = { new_task_opts = { diff --git a/lua/cmake-tools/const.lua b/lua/cmake-tools/const.lua index 52c1a119..29ad2ed2 100644 --- a/lua/cmake-tools/const.lua +++ b/lua/cmake-tools/const.lua @@ -35,6 +35,7 @@ local const = { direction = "float", -- 'vertical' | 'horizontal' | 'tab' | 'float' close_on_exit = false, -- whether close the terminal when exit auto_scroll = true, -- whether auto scroll to the bottom + singleton = true, -- single instance, autocloses the opened one, if present }, overseer = { new_task_opts = { @@ -77,6 +78,7 @@ local const = { direction = "float", -- 'vertical' | 'horizontal' | 'tab' | 'float' close_on_exit = false, -- whether close the terminal when exit auto_scroll = true, -- whether auto scroll to the bottom + singleton = true, -- single instance, autocloses the opened one, if present }, overseer = { new_task_opts = { diff --git a/lua/cmake-tools/toggleterm.lua b/lua/cmake-tools/toggleterm.lua index 27f90729..8255a873 100644 --- a/lua/cmake-tools/toggleterm.lua +++ b/lua/cmake-tools/toggleterm.lua @@ -24,6 +24,9 @@ end function _toggleterm.run(cmd, env_script, env, args, cwd, opts, on_exit, on_output) _toggleterm.cmd = cmd .. " " .. table.concat(args, " ") + if opts.singleton and _toggleterm.term then + _toggleterm.term:close() + end _toggleterm.term = _terminal.Terminal:new({ --[[ env = {}, -- key:value table with environmental variables passed to jobstart() ]] cmd = _toggleterm.cmd,