ref(libmodal): make api func names more obvious

pull/14/head
Iron-E 2 years ago
parent cf1bca1f8f
commit a81c06464b
No known key found for this signature in database
GPG Key ID: 19B71B7B7B021D22

@ -126,7 +126,7 @@ function Mode:get_user_input()
end
-- echo the indicator.
utils.api.nvim_lecho(self.indicator)
utils.api.hi_echo(self.indicator)
-- capture input.
local user_input = vim.fn.getchar()
@ -174,7 +174,7 @@ function Mode:tear_down()
vim.g.libmodalActiveModeName = self.previous_mode_name
end
utils.api.nvim_redraw()
utils.api.redraw()
end
return

@ -50,7 +50,7 @@ end
--- @return boolean more_input
function Prompt:get_user_input()
-- clear previous `echo`s.
utils.api.nvim_redraw()
utils.api.redraw()
local continue_prompt -- will set to true `true` if looping this prompt again

@ -1,10 +1,24 @@
local globals = require 'libmodal/src/globals'
local Indicator = require 'libmodal/src/utils/Indicator'
--[[/* MODULE */]]
local api = {}
--- echo a list of `Indicator`s with their associated highlighting.
--- @param indicators libmodal.utils.Indicator|table<libmodal.utils.Indicator> the indicators to echo
function api.hi_echo(indicators)
if indicators.hl then -- wrap the single indicator in a table to form a list of indicators
indicators = {indicators}
end
api.redraw()
for _, indicator in ipairs(indicators) do
vim.api.nvim_command('echohl ' .. indicator.hl .. " | echon '" .. indicator.str .. "'")
end
vim.api.nvim_command 'echohl None'
end
--- send a character to exit a mode.
--- @param exit_char string the character used to exit the mode, or ESCAPE if none was provided.
function api.mode_exit(exit_char)
@ -18,38 +32,9 @@ function api.mode_exit(exit_char)
vim.api.nvim_feedkeys(exit_char, 'nt', false)
end
--- make vim ring the visual/audio bell, if it is enabled.
function api.nvim_bell()
vim.api.nvim_command('normal '..string.char(27)) -- escape char
end
--- run the `mode` command to refresh the screen.
function api.nvim_redraw()
function api.redraw()
vim.api.nvim_command 'mode'
end
--- echo a list of `Indicator`s with their associated highlighting.
--- @param indicators libmodal.utils.Indicator|table<libmodal.utils.Indicator> the indicators to echo
function api.nvim_lecho(indicators)
if indicators.hl then -- wrap the single indicator in a table to form a list of indicators
indicators = {indicators}
end
api.nvim_redraw()
for _, indicator in ipairs(indicators) do
vim.api.nvim_command('echohl ' .. indicator.hl .. " | echon '" .. indicator.str .. "'")
end
vim.api.nvim_command 'echohl None'
end
--- show an error.
--- @param title string a succint category of error
--- @param msg string a descriptive reason for the error
function api.nvim_show_err(title, msg)
api.nvim_lecho {Indicator.new('Title', tostring(title)..'\n'), Indicator.new('Error', tostring(msg))}
vim.fn.getchar()
end
return api

Loading…
Cancel
Save