updated formatting

This commit is contained in:
Rishabh Dwivedi 2021-08-30 04:01:03 +05:30
parent 323027715f
commit 730dc0c0d2
3 changed files with 35 additions and 34 deletions

View File

@ -22,7 +22,6 @@ local function close_menu(force_save)
Harpoon_cmd_bufh = nil Harpoon_cmd_bufh = nil
end end
local function create_window() local function create_window()
log.trace("_create_window()") log.trace("_create_window()")
local config = harpoon.get_menu_config() local config = harpoon.get_menu_config()
@ -55,19 +54,19 @@ local function create_window()
end end
local function is_white_space(str) local function is_white_space(str)
local white_space_chars = { local white_space_chars = {
[" "] = true, [" "] = true,
["\t"] = true, ["\t"] = true,
["\r"] = true, ["\r"] = true,
["\f"] = true, ["\f"] = true,
["\v"] = true ["\v"] = true,
} }
for i = 1, string.len(str) do for i = 1, string.len(str) do
if white_space_chars[string.sub(str, i, i)] == nil then if white_space_chars[string.sub(str, i, i)] == nil then
return false return false
end
end end
end return true
return true
end end
local function get_menu_items() local function get_menu_items()
@ -76,9 +75,9 @@ local function get_menu_items()
local indices = {} local indices = {}
for _, line in pairs(lines) do for _, line in pairs(lines) do
if not is_white_space(line) then if not is_white_space(line) then
table.insert(indices, line) table.insert(indices, line)
end end
end end
return indices return indices
@ -86,7 +85,10 @@ end
M.toggle_quick_menu = function() M.toggle_quick_menu = function()
log.trace("toggle_quick_menu()") log.trace("toggle_quick_menu()")
if Harpoon_cmd_win_id ~= nil and vim.api.nvim_win_is_valid(Harpoon_cmd_win_id) then if
Harpoon_cmd_win_id ~= nil
and vim.api.nvim_win_is_valid(Harpoon_cmd_win_id)
then
close_menu() close_menu()
return return
end end

View File

@ -58,10 +58,9 @@ local function get_first_empty_slot()
return idx return idx
end end
end end
return M.get_length() + 1; return M.get_length() + 1
end end
M.gotoTerminal = function(idx) M.gotoTerminal = function(idx)
log.trace("gotoTerminal(): Terminal:", idx) log.trace("gotoTerminal(): Terminal:", idx)
local term_handle = find_terminal(idx) local term_handle = find_terminal(idx)
@ -112,7 +111,7 @@ end
M.add_cmd = function(cmd) M.add_cmd = function(cmd)
log.trace("add_cmd()") log.trace("add_cmd()")
local found_idx = get_first_empty_slot(); local found_idx = get_first_empty_slot()
harpoon.get_term_config().cmds[found_idx] = cmd harpoon.get_term_config().cmds[found_idx] = cmd
M.emit_changed() M.emit_changed()
end end
@ -128,14 +127,14 @@ M.rm_cmd = function(idx)
end end
M.set_cmd_list = function(new_list) M.set_cmd_list = function(new_list)
log.trace("set_cmd_list(): New list:", new_list) log.trace("set_cmd_list(): New list:", new_list)
for k in pairs(harpoon.get_term_config().cmds) do for k in pairs(harpoon.get_term_config().cmds) do
harpoon.get_term_config().cmds[k] = nil harpoon.get_term_config().cmds[k] = nil
end end
for k, v in pairs(new_list) do for k, v in pairs(new_list) do
harpoon.get_term_config().cmds[k] = v harpoon.get_term_config().cmds[k] = v
end end
M.emit_changed() M.emit_changed()
end end
return M return M

View File

@ -3,7 +3,7 @@ local term = require("harpoon.term")
local function assert_table_equals(tbl1, tbl2) local function assert_table_equals(tbl1, tbl2)
if #tbl1 ~= #tbl2 then if #tbl1 ~= #tbl2 then
assert(false, ""..#tbl1.." != "..#tbl2) assert(false, "" .. #tbl1 .. " != " .. #tbl2)
end end
for i = 1, #tbl1 do for i = 1, #tbl1 do
if tbl1[i] ~= tbl2[i] then if tbl1[i] ~= tbl2[i] then
@ -21,7 +21,7 @@ describe("basic functionalities", function()
cmds = {} cmds = {}
harpoon.get_term_config = function() harpoon.get_term_config = function()
return { return {
cmds = cmds cmds = cmds,
} }
end end
term.emit_changed = function() term.emit_changed = function()
@ -32,7 +32,7 @@ describe("basic functionalities", function()
it("add_cmd for empty", function() it("add_cmd for empty", function()
term.add_cmd("cmake ..") term.add_cmd("cmake ..")
local expected_result = { local expected_result = {
"cmake .." "cmake ..",
} }
assert_table_equals(harpoon.get_term_config().cmds, expected_result) assert_table_equals(harpoon.get_term_config().cmds, expected_result)
assert.equals(emitted, true) assert.equals(emitted, true)
@ -131,10 +131,10 @@ describe("basic functionalities", function()
term.add_cmd("cmake ..") term.add_cmd("cmake ..")
term.add_cmd("make") term.add_cmd("make")
term.add_cmd("ninja") term.add_cmd("ninja")
term.set_cmd_list({"make uninstall", "make install",}) term.set_cmd_list({ "make uninstall", "make install" })
local expected_result = { local expected_result = {
"make uninstall", "make uninstall",
"make install", "make install",
} }
assert_table_equals(expected_result, harpoon.get_term_config().cmds) assert_table_equals(expected_result, harpoon.get_term_config().cmds)
end) end)