2021-07-07 18:25:14 +00:00
|
|
|
local libmodal = require 'libmodal'
|
2020-05-08 17:18:01 +00:00
|
|
|
|
2022-04-26 15:33:37 +00:00
|
|
|
-- keep track of the user's input history manually
|
2022-04-25 21:59:33 +00:00
|
|
|
local input_history = {}
|
2020-05-21 19:49:53 +00:00
|
|
|
|
2022-04-26 15:33:37 +00:00
|
|
|
-- clear the input history if it grows too long for our usage
|
2022-04-25 21:59:33 +00:00
|
|
|
function input_history:clear(index_to_check)
|
|
|
|
if #self >= index_to_check then
|
2020-05-21 19:49:53 +00:00
|
|
|
for i, _ in ipairs(self) do
|
|
|
|
self[i] = nil
|
|
|
|
end
|
2020-05-08 17:18:01 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-26 15:33:37 +00:00
|
|
|
-- this is the function that will be called whenever the user presses a button
|
2022-04-25 21:59:33 +00:00
|
|
|
local function foo_mode()
|
2022-04-26 15:33:37 +00:00
|
|
|
-- append to the input history, the latest button press
|
2023-03-12 23:26:38 +00:00
|
|
|
table.insert(input_history, string.char(
|
2022-04-26 15:33:37 +00:00
|
|
|
-- the input is a character number
|
2021-07-07 18:25:14 +00:00
|
|
|
vim.g.fooModeInput
|
2023-03-12 23:26:38 +00:00
|
|
|
))
|
2020-05-08 17:18:01 +00:00
|
|
|
|
2022-04-26 15:33:37 +00:00
|
|
|
-- custom logic to test for each character index to see if it matches the 'zfo' mapping
|
2020-05-08 17:18:01 +00:00
|
|
|
local index = 1
|
2022-04-25 21:59:33 +00:00
|
|
|
if input_history[1] == 'z' then
|
|
|
|
if input_history[2] == 'f' then
|
|
|
|
if input_history[3] == 'o' then
|
2021-07-07 18:25:14 +00:00
|
|
|
vim.api.nvim_command "echom 'It works!'"
|
2020-05-21 19:49:53 +00:00
|
|
|
else index = 3
|
|
|
|
end
|
|
|
|
else index = 2
|
|
|
|
end
|
2020-05-08 17:18:01 +00:00
|
|
|
end
|
|
|
|
|
2022-04-25 21:59:33 +00:00
|
|
|
input_history:clear(index)
|
2020-05-08 17:18:01 +00:00
|
|
|
end
|
|
|
|
|
2022-04-26 15:33:37 +00:00
|
|
|
-- enter the mode to begin the demo
|
2022-04-25 21:59:33 +00:00
|
|
|
libmodal.mode.enter('FOO', foo_mode)
|