You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.1 KiB
Lua
36 lines
1.1 KiB
Lua
--- @type libmodal.globals
|
|
local globals = require 'libmodal/src/globals'
|
|
|
|
--- @class libmodal.utils.api
|
|
local api = {}
|
|
|
|
--- send a character to exit a mode.
|
|
--- @param exit_char? number|string the character used to exit the mode, or ESCAPE if none was provided.
|
|
function api.mode_exit(exit_char)
|
|
-- if there was no provided `exit_char`, or it is a character code.
|
|
if type(exit_char) == globals.TYPE_NUM then
|
|
-- translate the character code or default to escape.
|
|
--- @diagnostic disable-next-line:param-type-mismatch we just checked `exit_char` == `number`
|
|
exit_char = string.char(exit_char)
|
|
elseif not exit_char then
|
|
-- translate the character code or default to escape.
|
|
exit_char = string.char(globals.ESC_NR)
|
|
end
|
|
|
|
-- exit the prompt by sending an escape key.
|
|
vim.api.nvim_feedkeys(exit_char, 'nt', false)
|
|
end
|
|
|
|
--- run the `mode` command to refresh the screen.
|
|
function api.redraw()
|
|
vim.api.nvim_command 'mode'
|
|
end
|
|
|
|
--- @param termcodes string
|
|
--- @return string replaced
|
|
function api.replace_termcodes(termcodes)
|
|
return vim.api.nvim_replace_termcodes(termcodes, true, true, true)
|
|
end
|
|
|
|
return api
|