Add checks for string arguments

pull/6/head
Iron-E 4 years ago
parent 075a3072bb
commit 0c3b58540e
No known key found for this signature in database
GPG Key ID: 19B71B7B7B021D22

@ -10,6 +10,7 @@ local ParseTable = require('libmodal/src/collections/ParseTable')
local utils = require('libmodal/src/utils')
local Vars = require('libmodal/src/Vars')
local vim = vim
local api = vim.api
--[[
@ -199,14 +200,21 @@ function _metaMode:_inputLoop()
-- Set the global input variable to the new input.
self.input:nvimSet(userInput)
-- Make sure that the user doesn't want to exit.
if not self.exit.supress
and userInput == globals.ESC_NR then return false
-- If the second argument was a dict, parse it.
elseif type(self._instruction) == globals.TYPE_TBL then
self:_checkInputForMapping()
else -- the second argument was a function; execute it.
self._instruction()
if not self.exit.supress and userInput == globals.ESC_NR then -- The user wants to exit.
return false -- As in, "I don't want to continue."
else -- The user wants to continue.
--[[ The instruction type is determined every cycle, because the user may be assuming a more direct control
over the instruction and it may change over the course of execution. ]]
local instructionType = type(self._instruction)
if instructionType == globals.TYPE_TBL then -- The second argument was a dict. Parse it.
self:_checkInputForMapping()
elseif instructionType == globals.TYPE_STR and vim.fn then -- It is the name of a VimL function. This only works in Neovim 0.5+.
vim.fn[self._instruction]()
else -- the second argument was a function; execute it.
self._instruction()
end
end
return true

@ -7,6 +7,7 @@
local globals = require('libmodal/src/globals')
local utils = require('libmodal/src/utils')
local vim = vim
local api = vim.api
--[[
@ -64,16 +65,18 @@ function _metaPrompt:_inputLoop()
local instruction = self._instruction
-- determine what to do with the input
if string.len(userInput) > 0 then -- the user actually entered something
if string.len(userInput) > 0 then -- The user actually entered something.
self.input:nvimSet(userInput)
if type(instruction) == globals.TYPE_TBL then -- the instruction is a command table.
if instruction[userInput] then -- there is a defined command for the input.
if type(instruction) == globals.TYPE_TBL then -- The instruction is a command table.
if instruction[userInput] then -- There is a defined command for the input.
api.nvim_command(instruction[userInput])
elseif userInput == _HELP then -- the user did not define a 'help' command, so use the default.
elseif userInput == _HELP then -- The user did not define a 'help' command, so use the default.
self._help:show()
else -- show an error.
utils.api.nvim_show_err(globals.DEFAULT_ERROR_TITLE, 'Unknown command')
end
elseif type(instruction) == globals.TYPE_STR and vim.fn then -- The instruction is a function. Works on Neovim 0.5+.
vim.fn[instruction]()
else -- attempt to call the instruction.
instruction()
end

Loading…
Cancel
Save