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.
37 lines
1.1 KiB
Lua
37 lines
1.1 KiB
Lua
2 years ago
|
local globals = require 'libmodal.globals'
|
||
4 years ago
|
|
||
2 years ago
|
--- @class libmodal.utils.api
|
||
3 years ago
|
local api = {}
|
||
|
|
||
2 years ago
|
--- send a character to exit a mode.
|
||
2 years ago
|
--- @param exit_char? number|string the character used to exit the mode, or ESCAPE if none was provided.
|
||
2 years ago
|
--- @return nil
|
||
4 years ago
|
function api.mode_exit(exit_char)
|
||
2 years ago
|
-- if there was no provided `exit_char`, or it is a character code.
|
||
2 years ago
|
if type(exit_char) == 'number' then
|
||
2 years ago
|
-- translate the character code or default to escape.
|
||
2 years ago
|
--- @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)
|
||
4 years ago
|
end
|
||
|
|
||
2 years ago
|
-- exit the prompt by sending an escape key.
|
||
3 years ago
|
vim.api.nvim_feedkeys(exit_char, 'nt', false)
|
||
4 years ago
|
end
|
||
|
|
||
2 years ago
|
--- run the `mode` command to refresh the screen.
|
||
2 years ago
|
--- @return nil
|
||
2 years ago
|
function api.redraw()
|
||
3 years ago
|
vim.api.nvim_command 'mode'
|
||
4 years ago
|
end
|
||
|
|
||
2 years ago
|
--- @param termcodes string
|
||
|
--- @return string replaced
|
||
|
function api.replace_termcodes(termcodes)
|
||
|
return vim.api.nvim_replace_termcodes(termcodes, true, true, true)
|
||
|
end
|
||
|
|
||
4 years ago
|
return api
|