repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

feat(cmdline): sync popupmenu border with cmdline format via DRY highlight map

24c3917efa785926dc560b133fbd7294554c69a9

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Extract BORDER_HIGHLIGHT_MAP to format.lua as format.border_highlight_map,
shared by both render.lua and popupmenu.lua.

popupmenu.on_show now accepts format_type parameter and applies
format-aware border/corner highlights via winhighlight.

render.get_format_type() exported for popupmenu to query current format.

init.lua passes render.get_format_type() to popupmenu.on_show().

Changed files (4)

neovim/lua/bugabinga/cmdline/format.lua

Modified
2 2 local icon = require 'std.icon'
4 4 local HELP_PATTERNS = { '^h$', '^he$', '^hel$', '^help$', '^h%s', '^help%s' }
6 +local BORDER_HIGHLIGHT_MAP = {
7 + search_down = { border = 'CmdlineBorderSearch', corner = 'CmdlineBorderCornerSearch' },
8 + search_up = { border = 'CmdlineBorderSearch', corner = 'CmdlineBorderCornerSearch' },
9 + shell = { border = 'CmdlineBorderShell', corner = 'CmdlineBorderCornerShell' },
10 + help = { border = 'CmdlineBorderHelp', corner = 'CmdlineBorderCornerHelp' },
11 + lua = { border = 'CmdlineBorderLua', corner = 'CmdlineBorderCornerLua' },
12 + input = { border = 'CmdlineBorderInput', corner = 'CmdlineBorderCornerInput' },
13 + cmdline = { border = 'CmdlineBorderCmdline', corner = 'CmdlineBorderCornerCmdline' },
6 16 return {
7 17 detect = function(firstc, content, prompt)
8 18 if prompt and prompt ~= '' then
30 40 return { type = 'cmdline', icon = icon.command, lang = 'vim' }
31 41 end,
42 + border_highlight_map = BORDER_HIGHLIGHT_MAP,

neovim/lua/bugabinga/cmdline/init.lua

Modified
18 18 render.hide()
19 19 end,
20 20 popupmenu_show = function(items, selected, row, col, grid)
21 - popupmenu.on_show(items, selected, row, col, grid)
21 + popupmenu.on_show(items, selected, row, col, grid, render.get_format_type())
22 22 end,
23 23 popupmenu_select = function(selected)
24 24 popupmenu.on_select(selected)

neovim/lua/bugabinga/cmdline/popupmenu.lua

Modified
1 1 local icon = require 'std.icon'
2 +local table = require 'std.table'
2 3 local position = require 'bugabinga.cmdline.position'
4 +local format = require 'bugabinga.cmdline.format'
4 6 local ns = vim.api.nvim_create_namespace 'bugabinga.cmdline.popupmenu'
10 12 selected = -1,
11 13 grid = -1,
12 14 above = false,
15 + format_type = 'cmdline',
15 18 local function kind_icon(kind)
87 90 local function get_win(buf, anchor, width, height)
88 - if vim.api.nvim_win_is_valid(state.window) then
89 - return state.window
91 + local is_new = not vim.api.nvim_win_is_valid(state.window)
92 + if is_new then
93 + state.window = vim.api.nvim_open_win(buf, false, {
94 + relative = 'editor',
95 + width = width,
96 + height = height,
97 + row = anchor.row,
98 + col = anchor.col,
99 + style = 'minimal',
100 + border = vim.g.border_style,
101 + focusable = false,
102 + zindex = 201,
103 + })
91 - state.window = vim.api.nvim_open_win(buf, false, {
92 - relative = 'editor',
93 - width = width,
94 - height = height,
95 - row = anchor.row,
96 - col = anchor.col,
97 - style = 'minimal',
98 - border = vim.g.border_style,
99 - focusable = false,
100 - zindex = 201,
101 - })
102 105 vim.wo[state.window].cursorline = true
103 106 vim.wo[state.window].winbar = ''
104 107 vim.wo[state.window].foldenable = false
105 - vim.wo[state.window].winhighlight =
106 - 'Normal:Pmenu,CursorLine:PmenuSel,FloatBorder:FloatBorder'
108 + local hl = format.border_highlight_map[state.format_type] or format.border_highlight_map.cmdline
109 + vim.wo[state.window].winhighlight = string.format(
110 + 'Normal:Pmenu,CursorLine:PmenuSel,FloatBorder:%s,FloatBorderCorner:%s',
111 + hl.border, hl.corner
107 113 return state.window
110 116 local M = {}
112 -function M.on_show(items, selected, row, col, grid)
118 +function M.on_show(items, selected, row, col, grid, format_type)
113 119 if not items or #items == 0 then
114 120 M.on_hide()
115 121 return
117 123 state.items = items
118 124 state.selected = selected
119 125 state.grid = grid
126 + state.format_type = format_type or 'cmdline'
120 127 local width = math.min(max_width(items) + 2, vim.o.columns - 4)
121 - local height = math.min(#items, vim.o.pumheight)
128 + local pumheight = vim.o.pumheight
129 + local height = pumheight > 0 and math.min(#items, pumheight) or #items
122 130 local anchor = get_anchor(row, col, grid, height)
123 131 local buf = get_buf()
124 132 local win = get_win(buf, anchor, width, height)
176 184 state.selected = -1
177 185 state.grid = -1
178 186 state.above = false
187 + state.format_type = 'cmdline'
181 190 return M

neovim/lua/bugabinga/cmdline/render.lua

Modified
14 14 text = '',
17 -local BORDER_HIGHLIGHT_MAP = {
18 - search_down = { border = 'CmdlineBorderSearch', corner = 'CmdlineBorderCornerSearch' },
19 - search_up = { border = 'CmdlineBorderSearch', corner = 'CmdlineBorderCornerSearch' },
20 - shell = { border = 'CmdlineBorderShell', corner = 'CmdlineBorderCornerShell' },
21 - help = { border = 'CmdlineBorderHelp', corner = 'CmdlineBorderCornerHelp' },
22 - lua = { border = 'CmdlineBorderLua', corner = 'CmdlineBorderCornerLua' },
23 - input = { border = 'CmdlineBorderInput', corner = 'CmdlineBorderCornerInput' },
24 - cmdline = { border = 'CmdlineBorderCmdline', corner = 'CmdlineBorderCornerCmdline' },
27 17 local ICON_HIGHLIGHT_MAP = {
28 18 search_down = 'CmdlineIconSearch',
29 19 search_up = 'CmdlineIconSearch',
37 27 local function get_winhighlight(type)
38 - local hl = BORDER_HIGHLIGHT_MAP[type] or BORDER_HIGHLIGHT_MAP.cmdline
28 + local hl = format.border_highlight_map[type] or format.border_highlight_map.cmdline
39 29 return string.format('Normal:NormalFloat,FloatBorder:%s,FloatBorderCorner:%s', hl.border, hl.corner)
172 162 cursor.fix(state.window, cursor_col)
165 +function M.get_format_type()
166 + return state.current_fmt and state.current_fmt.type or 'cmdline'
167 +end
175 169 return M