Add tests; fix bugs with Help and ParseTable

pull/7/head
Iron-E 4 years ago
parent 57fcf4b1c1
commit 2844351594
No known key found for this signature in database
GPG Key ID: 19B71B7B7B021D22

@ -1,11 +1,19 @@
-- Imports
local libmodal = require('libmodal')
-- A function which will split the window both horizontally and vertically.
local function _split_twice()
local cmd = vim.api.nvim_command
cmd('split')
cmd('vsplit')
end
-- Register key combos for splitting windows and then closing windows
local fooModeCombos = {
['zf'] = 'split',
['zfo'] = 'vsplit',
['zfc'] = 'q'
['zfc'] = 'q',
['zff'] = _split_twice
}
-- Enter the mode using the key combos.

@ -1,11 +1,17 @@
-- Import
local libmodal = require('libmodal')
-- A function, which when called, goes to the first tab.
local function _first()
vim.api.nvim_command('tabfirst')
end
-- Define commands through a dictionary.
local commands = {
['new'] = 'tabnew',
['close'] = 'tabclose',
['last'] = 'tablast'
['last'] = 'tablast',
['first'] = _first
}
-- Begin the prompt.

@ -51,18 +51,18 @@ classes = nil
-----------------------------------------------------------
--[[ SUMMARY:
* Execute some `proposedInstruction` according to a set of determined logic.
* Execute some `selection` according to a set of determined logic.
]]
--[[ REMARKS:
* Only provides logic for when `self._instruction` is a table of commands.
]]
--[[ PARAMS:
* `proposedInstruction` => The instruction that is desired to be executed.
* `selection` => The instruction that is desired to be executed.
]]
-----------------------------------------------------------
function _metaMode._executeInstruction(proposedInstruction)
if type(proposedInstruction) == globals.TYPE_FUNC then
proposedInstruction()
else
api.nvim_command(proposedInstruction)
end
function _metaMode._commandTableExecute(instruction)
if type(instruction) == globals.TYPE_FUNC then instruction()
else api.nvim_command(instruction) end
end
-----------------------------------------------
@ -102,7 +102,7 @@ function _metaMode:_checkInputForMapping()
_TIMEOUT:SEND()
-- if there is a command, execute it.
if cmd[ParseTable.CR] then
self._executeInstruction(cmd[ParseTable.CR])
self._commandTableExecute(cmd[ParseTable.CR])
end
-- clear input
inputBytes:clear()
@ -112,7 +112,7 @@ function _metaMode:_checkInputForMapping()
-- The command was an actual vim command.
else
self._executeInstruction(cmd)
self._commandTableExecute(cmd)
inputBytes:clear()
end

@ -106,7 +106,7 @@ local function _get(parseTable, splitKey)
else
return _get(val, splitKey)
end
elseif valType == globals.TYPE_STR and #splitKey < 1 then
elseif valType == globals.TYPE_STR or valType == globals.TYPE_FUNC and #splitKey < 1 then
return val
end
end
@ -129,9 +129,11 @@ local function _put(parseTable, splitKey, value)
if #splitKey > 0 then -- there are still characters left in the key.
if not parseTable[k] then parseTable[k] = {}
-- If there is a previous command mapping in place
elseif type(parseTable[k]) == globals.TYPE_STR then
-- Swap the mapping to a `CR`
parseTable[k] = {[ParseTable.CR] = parseTable[k]}
else local valueType = type(parseTable[k])
if valueType == globals.TYPE_STR or valueType == globals.TYPE_FUNC then
-- Swap the mapping to a `CR`
parseTable[k] = {[ParseTable.CR] = parseTable[k]}
end
end
-- run _update() again

@ -1,3 +1,11 @@
--[[
/*
* IMPORTS
*/
--]]
local vim = vim
local globals = require('libmodal/src/globals')
--[[
/*
* MODULE
@ -75,18 +83,21 @@ function Help.new(commandsOrMaps, title)
----------------------
local function tabAlign(tbl)
local toPrint = {}
for k, v in pairs(tbl) do
toPrint[#toPrint + 1] = k
local len = string.len(k)
local byte = string.byte(k)
for key, value in pairs(tbl) do
toPrint[#toPrint + 1] = key
local len = string.len(key)
local byte = string.byte(key)
-- account for ASCII chars that take up more space.
if byte <= 32 or byte == 127 then len = len + 1
end
if byte <= 32 or byte == 127 then len = len + 1 end
for _ = len, longestKeyLen do
toPrint[#toPrint + 1] = ' '
end
toPrint[#toPrint + 1] = table.concat(SEPARATOR_TEMPLATE, v)
toPrint[#toPrint + 1] = table.concat(
SEPARATOR_TEMPLATE,
(type(value) == globals.TYPE_STR) and value or '<lua function>'
)
end
return toPrint
end

Loading…
Cancel
Save