perf(Mode): remove `InputBytes` class

pull/20/head
Iron-E 1 year ago
parent 69beec5e8e
commit 34b94a246d
No known key found for this signature in database
GPG Key ID: 83A6AEB40395D40D

@ -13,23 +13,16 @@ local utils = require 'libmodal/src/utils'
--- @field private help? libmodal.utils.Help --- @field private help? libmodal.utils.Help
--- @field private indicator libmodal.utils.Indicator --- @field private indicator libmodal.utils.Indicator
--- @field private input libmodal.utils.Vars --- @field private input libmodal.utils.Vars
--- @field private input_bytes? number[]
--- @field private instruction fun()|{[string]: fun()|string} --- @field private instruction fun()|{[string]: fun()|string}
--- @field private mappings libmodal.collections.ParseTable --- @field private mappings libmodal.collections.ParseTable
--- @field private name string --- @field private name string
--- @field private popups libmodal.collections.Stack --- @field private popups libmodal.collections.Stack
--- @field private show_name fun()
--- @field private supress_exit boolean --- @field private supress_exit boolean
--- @field private timeouts_enabled boolean --- @field private timeouts_enabled boolean
local Mode = utils.classes.new() local Mode = utils.classes.new()
local InputBytes = utils.classes.new(
{
clear = function(self)
for i, _ in ipairs(self) do
self[i] = nil
end
end
})
local HELP = '?' local HELP = '?'
local TIMEOUT = local TIMEOUT =
{ {
@ -70,7 +63,7 @@ function Mode:check_input_for_mapping()
self.help:show() self.help:show()
end end
self.input_bytes:clear() self.input_bytes = {}
elseif command_type == globals.TYPE_TBL and globals.is_true(self.timeouts_enabled) then -- the command was a table, meaning that it MIGHT match. elseif command_type == globals.TYPE_TBL and globals.is_true(self.timeouts_enabled) then -- the command was a table, meaning that it MIGHT match.
self.flush_input_timer:start( -- start the timer self.flush_input_timer:start( -- start the timer
TIMEOUT.LEN, 0, vim.schedule_wrap(function() TIMEOUT.LEN, 0, vim.schedule_wrap(function()
@ -81,14 +74,14 @@ function Mode:check_input_for_mapping()
self.execute_instruction(cmd[ParseTable.CR]) self.execute_instruction(cmd[ParseTable.CR])
end end
-- clear input -- clear input
self.input_bytes:clear() self.input_bytes = {}
self.popups:peek():refresh(self.input_bytes) self.popups:peek():refresh(self.input_bytes)
end) end)
) )
else -- the command was an actual vim command. else -- the command was an actual vim command.
--- @diagnostic disable-next-line:param-type-mismatch already checked `cmd` != `table` --- @diagnostic disable-next-line:param-type-mismatch already checked `cmd` != `table`
self.execute_instruction(cmd) self.execute_instruction(cmd)
self.input_bytes:clear() self.input_bytes = {}
end end
self.popups:peek():refresh(self.input_bytes) self.popups:peek():refresh(self.input_bytes)
@ -137,7 +130,7 @@ function Mode:get_user_input()
end end
-- echo the indicator. -- echo the indicator.
self:show_name() self.show_name()
-- capture input. -- capture input.
local user_input = vim.fn.getchar() local user_input = vim.fn.getchar()
@ -188,13 +181,11 @@ function Mode:tear_down()
utils.api.redraw() utils.api.redraw()
end end
return --- create a new mode.
{ --- @param name string the name of the mode.
--- create a new mode. --- @param instruction fun()|string|table a Lua function, keymap dictionary, Vimscript command.
--- @param name string the name of the mode. --- @return libmodal.Mode
--- @param instruction fun()|string|table a Lua function, keymap dictionary, Vimscript command. function Mode.new(name, instruction, supress_exit)
--- @return libmodal.Mode
new = function(name, instruction, supress_exit)
name = vim.trim(name) name = vim.trim(name)
-- inherit the metatable. -- inherit the metatable.
@ -230,7 +221,7 @@ return
self.help = utils.Help.new(self.instruction, 'KEY MAP') self.help = utils.Help.new(self.instruction, 'KEY MAP')
end end
self.input_bytes = setmetatable({}, InputBytes) self.input_bytes = {}
-- build the parse tree. -- build the parse tree.
--- @diagnostic disable-next-line:param-type-mismatch already checked `self.instruction` != `table` --- @diagnostic disable-next-line:param-type-mismatch already checked `self.instruction` != `table`
@ -247,5 +238,6 @@ return
end end
return self return self
end end
}
return Mode

Loading…
Cancel
Save