2 2 local format
= require 'bugabinga.cmdline.format' 3 3 local position
= require 'bugabinga.cmdline.position' 4 4 local cursor
= require 'bugabinga.cmdline.cursor' 5 5 local highlight
= require 'bugabinga.cmdline.highlight' 6 -local table = require 'std.table' 8 7 local ns
= vim.api.nvim_create_namespace
'bugabinga.cmdline' 9 8 local hl_ns
= vim.api.nvim_create_namespace
'bugabinga.cmdline.hl' 17 -local ICON_HIGHLIGHT_MAP
= {
18 - search_down =
'CmdlineIconSearch',
19 - search_up =
'CmdlineIconSearch',
20 - shell =
'CmdlineIconShell',
21 - help =
'CmdlineIconHelp',
22 - lua =
'CmdlineIconLua',
23 - input =
'CmdlineIconInput',
24 - cmdline =
'CmdlineIconCmdline',
27 -local function get_winhighlight(type)
28 - local hl
= format.border_highlight_map[
type]
or format.border_highlight_map.cmdline
29 - return string.
format(
'Normal:NormalFloat,FloatBorder:%s,FloatBorderCorner:%s', hl.border, hl.corner)
32 18 local function get_buf()
33 19 if vim.api.nvim_buf_is_valid(state.buffer)
then 34 20 return state.buffer
58 44 vim.wo[state.window].cursorline
= false 59 45 vim.wo[state.window].winbar
= '' 60 46 vim.wo[state.window].foldenable
= false 61 - vim.wo[state.window].winhighlight
= get_winhighlight(fmt.type)
47 + vim.wo[state.window].winhighlight
= format.winhighlight(fmt.type,
'NormalFloat')
62 48 return state.window
53 +local function apply_icon(buf, fmt)
54 + vim.api.nvim_buf_clear_namespace(buf, ns,
0,
-1)
55 + local icon_hl
= format.icon_highlight(fmt.type)
56 + vim.api.nvim_buf_set_extmark(buf, ns,
0,
0, {
57 + virt_text = { { fmt.icon, icon_hl } },
58 + virt_text_pos =
'overlay',
67 62 function M.
show(cmdline_state)
68 63 local text
= cmdline_state:text()
64 + local firstc
= cmdline_state.firstc
65 + local prompt
= cmdline_state.prompt
70 - local fmt
= format.detect(cmdline_state.firstc, text, cmdline_state.prompt)
67 + state.firstc
= firstc
68 + state.prompt
= prompt
69 + local fmt
= format.detect(firstc, text, prompt)
71 70 local fmt_changed
= not state.current_fmt
or fmt.type
~= state.current_fmt.type
72 71 state.current_fmt
= fmt
73 72 local display_text
= ' ' .. text
.. ' ' 95 94 vim.g.ui_cmdline_pos
= { anchor.screenpos.row, anchor.screenpos.col }
97 96 if fmt_changed
then 98 - vim.wo[win].winhighlight
= get_winhighlight(fmt.type)
97 + vim.wo[win].winhighlight
= format.winhighlight(fmt.type,
'NormalFloat')
100 99 vim.api.nvim_buf_set_lines(buf,
0,
-1,
false, { display_text })
101 - vim.api.nvim_buf_clear_namespace(buf, ns,
0,
-1)
102 - local icon_hl
= ICON_HIGHLIGHT_MAP[fmt.type]
or 'CmdlineIconCmdline' 103 - vim.api.nvim_buf_set_extmark(buf, ns,
0,
0, {
104 - virt_text = { { fmt.icon, icon_hl } },
105 - virt_text_pos =
'overlay',
100 + apply_icon(buf, fmt)
107 101 highlight.apply(buf, hl_ns, text, fmt.lang,
0,
2)
108 102 local cursor_byte
= cmdline_state:cursor_byte()
109 103 local cursor_col
= 2 + cursor_byte
123 117 state.window
= -1 124 118 state.current_fmt
= nil 126 122 position.set_cmdline_anchor(
nil)
127 123 vim.g.ui_cmdline_pos
= nil 131 127 if not vim.api.nvim_win_is_valid(state.window)
then 134 - local info
= vim.api.nvim_get_cmdline_info()
135 - local raw
= info.cmdline
and #info.cmdline
> 0 and table.
concat(info.cmdline,
'')
or '' 136 - local firstc
= info.firstc
and info.firstc
~= '' and info.firstc
or '' 137 - local content
= raw
138 - if firstc
~= '' and raw:find(
'^' .. firstc)
then 139 - content
= raw:sub(
#firstc
+ 1)
141 - if content
~= state.text
then 142 - state.text
= content
143 - local fmt
= format.detect(firstc, content, cmdline_state.prompt)
144 - if fmt.type
~= state.current_fmt.type
then 145 - state.current_fmt
= fmt
146 - vim.wo[state.window].winhighlight
= get_winhighlight(fmt.type)
147 - vim.api.nvim_buf_clear_namespace(state.buffer, ns,
0,
-1)
148 - local icon_hl
= ICON_HIGHLIGHT_MAP[fmt.type]
or 'CmdlineIconCmdline' 149 - vim.api.nvim_buf_set_extmark(state.buffer, ns,
0,
0, {
150 - virt_text = { { fmt.icon, icon_hl } },
151 - virt_text_pos =
'overlay',
155 130 local cursor_byte
= cmdline_state:cursor_byte()
156 131 local cursor_col
= 2 + cursor_byte
157 132 local anchor
= position.get_cmdline_anchor()
166 141 return state.current_fmt
and state.current_fmt.type
or 'cmdline' 144 +function M.
get_text()