diff --git a/lua/libmodal/src/Mode.lua b/lua/libmodal/src/Mode.lua index 4a69104..67d5ae6 100644 --- a/lua/libmodal/src/Mode.lua +++ b/lua/libmodal/src/Mode.lua @@ -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 diff --git a/lua/libmodal/src/Prompt.lua b/lua/libmodal/src/Prompt.lua index 272589f..2013295 100644 --- a/lua/libmodal/src/Prompt.lua +++ b/lua/libmodal/src/Prompt.lua @@ -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 diff --git a/lua/libmodal/src/utils/api.lua b/lua/libmodal/src/utils/api.lua index 7581ca1..e14e3d9 100644 --- a/lua/libmodal/src/utils/api.lua +++ b/lua/libmodal/src/utils/api.lua @@ -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 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 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