feat(tmux): added extra term cmd manipulation functions to tmux module

In the future, these should probably be refactored out into the utils
file beacuse they are the exact same functions as the one in the term
module.
This commit is contained in:
Pranav Rao 2021-10-22 09:07:44 -04:00
parent 45a888ee8a
commit 20590f1512

View File

@ -85,6 +85,16 @@ local function find_terminal(args)
return window_handle
end
local function get_first_empty_slot()
log.trace("_get_first_empty_slot()")
for idx, cmd in pairs(harpoon.get_term_config().cmds) do
if cmd == "" then
return idx
end
end
return M.get_length() + 1
end
M.gotoTerminal = function(idx)
log.trace("tmux: gotoTerminal(): Window:", idx)
local window_handle = find_terminal(idx)
@ -139,4 +149,51 @@ M.clear_all = function()
tmux_windows = {}
end
M.get_length = function()
log.trace("_get_length()")
return table.maxn(harpoon.get_term_config().cmds)
end
M.valid_index = function(idx)
if idx == nil or idx > M.get_length() or idx <= 0 then
return false
end
return true
end
M.emit_changed = function()
log.trace("_emit_changed()")
if harpoon.get_global_settings().save_on_change then
harpoon.save()
end
end
M.add_cmd = function(cmd)
log.trace("add_cmd()")
local found_idx = get_first_empty_slot()
harpoon.get_term_config().cmds[found_idx] = cmd
M.emit_changed()
end
M.rm_cmd = function(idx)
log.trace("rm_cmd()")
if not M.valid_index(idx) then
log.debug("rm_cmd(): no cmd exists for index", idx)
return
end
table.remove(harpoon.get_term_config().cmds, idx)
M.emit_changed()
end
M.set_cmd_list = function(new_list)
log.trace("set_cmd_list(): New list:", new_list)
for k in pairs(harpoon.get_term_config().cmds) do
harpoon.get_term_config().cmds[k] = nil
end
for k, v in pairs(new_list) do
harpoon.get_term_config().cmds[k] = v
end
M.emit_changed()
end
return M