|
43 | 43 | --- their UI plugins' exclusion lists as a fallback. |
44 | 44 | M.FORM_FILETYPE = "input-form" |
45 | 45 |
|
| 46 | +--- Character sets for the built-in border styles accepted by `nvim_open_win`. |
| 47 | +--- Order is clockwise from top-left: TL, T, TR, R, BR, B, BL, L. |
| 48 | +local BORDER_CHARS = { |
| 49 | + rounded = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, |
| 50 | + single = { "┌", "─", "┐", "│", "┘", "─", "└", "│" }, |
| 51 | + double = { "╔", "═", "╗", "║", "╝", "═", "╚", "║" }, |
| 52 | + solid = { " ", " ", " ", " ", " ", " ", " ", " " }, |
| 53 | +} |
| 54 | + |
| 55 | +-- T-junction connectors used to replace the top corners when stitching two |
| 56 | +-- boxes together (the bottom of box A and the top of box B share a row). |
| 57 | +local MERGE_CONNECTORS = { |
| 58 | + rounded = { left = "├", right = "┤" }, |
| 59 | + single = { left = "├", right = "┤" }, |
| 60 | + double = { left = "╠", right = "╣" }, |
| 61 | + solid = { left = " ", right = " " }, |
| 62 | +} |
| 63 | + |
| 64 | +--- Build an 8-element border array whose top row is a T-junction stitching |
| 65 | +--- into the bottom of a parent box above it. Accepts either one of the |
| 66 | +--- built-in border style names or an existing 8-element border array. |
| 67 | +--- |
| 68 | +--- Returns `nil` for unrecognised / non-mergeable borders (e.g. `"none"`, |
| 69 | +--- `"shadow"`) so the caller can fall back to an unmerged layout. |
| 70 | +---@param border string|table |
| 71 | +---@return table|nil |
| 72 | +function M.merged_top_border(border) |
| 73 | + local chars, connectors |
| 74 | + if type(border) == "string" then |
| 75 | + chars = BORDER_CHARS[border] |
| 76 | + connectors = MERGE_CONNECTORS[border] |
| 77 | + elseif type(border) == "table" and #border == 8 then |
| 78 | + chars = vim.deepcopy(border) |
| 79 | + -- Best-effort fallback for custom arrays: use the straight T's. |
| 80 | + connectors = { left = "├", right = "┤" } |
| 81 | + end |
| 82 | + if not chars or not connectors then |
| 83 | + return nil |
| 84 | + end |
| 85 | + return { |
| 86 | + connectors.left, |
| 87 | + chars[2], |
| 88 | + connectors.right, |
| 89 | + chars[4], |
| 90 | + chars[5], |
| 91 | + chars[6], |
| 92 | + chars[7], |
| 93 | + chars[8], |
| 94 | + } |
| 95 | +end |
| 96 | + |
46 | 97 | local _excluded_registered = false |
47 | 98 |
|
48 | 99 | -- Append `ft` to a list-shaped config field if missing. |
|
0 commit comments