2021-07-07 18:25:14 +00:00
|
|
|
local libmodal = require 'libmodal'
|
2020-08-27 16:10:01 +00:00
|
|
|
|
2022-04-26 15:33:37 +00:00
|
|
|
-- recurse counter
|
2022-04-25 21:59:33 +00:00
|
|
|
local foo_mode_recurse = 1
|
2020-05-11 18:17:58 +00:00
|
|
|
|
2022-04-26 15:33:37 +00:00
|
|
|
-- function which is called whenever the user presses a button
|
2020-07-03 17:01:04 +00:00
|
|
|
function FooMode()
|
2022-04-26 15:33:37 +00:00
|
|
|
-- append to the input history, the latest button press
|
2021-07-07 18:25:14 +00:00
|
|
|
local userInput = string.char(vim.g[
|
2022-04-26 15:33:37 +00:00
|
|
|
-- the input is a character number
|
2022-04-25 21:59:33 +00:00
|
|
|
'foo' .. tostring(foo_mode_recurse) .. 'ModeInput'
|
2021-07-07 18:25:14 +00:00
|
|
|
])
|
2020-05-11 18:17:58 +00:00
|
|
|
|
2022-04-26 15:33:37 +00:00
|
|
|
-- if the user pressed 'z', then increase the counter and recurse
|
2020-05-13 22:22:25 +00:00
|
|
|
if userInput == 'z' then
|
2022-04-25 21:59:33 +00:00
|
|
|
foo_mode_recurse = foo_mode_recurse + 1
|
2020-07-03 17:01:04 +00:00
|
|
|
Enter()
|
2022-04-25 21:59:33 +00:00
|
|
|
foo_mode_recurse = foo_mode_recurse - 1
|
2020-05-11 18:17:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-26 15:33:37 +00:00
|
|
|
-- function to wrap around entering the mode so it can be recursively called
|
2020-07-03 17:01:04 +00:00
|
|
|
function Enter()
|
2022-04-25 21:59:33 +00:00
|
|
|
libmodal.mode.enter('FOO' .. foo_mode_recurse, FooMode)
|
2020-05-11 18:17:58 +00:00
|
|
|
end
|
|
|
|
|
2022-04-26 15:33:37 +00:00
|
|
|
-- initially call the function to begin the demo
|
2020-07-03 17:01:04 +00:00
|
|
|
Enter()
|