Skip to content

Commit 4d658a8

Browse files
committed
feat(basics)!: add options.win_border='auto' and make it default
1 parent 58cb8f4 commit 4d658a8

File tree

5 files changed

+59
-11
lines changed

5 files changed

+59
-11
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ There are following change types:
4747

4848
- Add `gen_spec.user_prompt` that acts the same as `?` built-in textobject. It can be used for using this textobject under another identifier.
4949

50+
## mini.basics
51+
52+
### Refine
53+
54+
- Change default value of `options.win_border` to be `'auto'`.
55+
56+
### Expand
57+
58+
- Update `options.win_border` to allow value `'auto'` which infers target 'fillchars' values from 'winborder' option.
59+
5060
## mini.completion
5161

5262
### Evolve

doc/mini-basics.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ Defaults ~
8383
extra_ui = false,
8484

8585
-- Presets for window borders ('single', 'double', ...)
86-
win_borders = 'default',
86+
-- Default 'auto' infers from 'winborder' option
87+
win_borders = 'auto',
8788
},
8889

8990
-- Mappings. Set field to `false` to disable.
@@ -191,6 +192,7 @@ The `config.options.win_borders` updates |'fillchars'| to have a consistent set
191192
of characters for window border (`vert`, `horiz`, `msgsep`, etc.).
192193

193194
Available values:
195+
- `'auto'` - infer from |'winborder'|. On Neovim<0.11 do nothing.
194196
- `'bold'` - bold lines.
195197
- `'dot'` - dot in every cell.
196198
- `'double'` - double line.

lua/mini/basics.lua

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ end
162162
--- of characters for window border (`vert`, `horiz`, `msgsep`, etc.).
163163
---
164164
--- Available values:
165+
--- - `'auto'` - infer from |'winborder'|. On Neovim<0.11 do nothing.
165166
--- - `'bold'` - bold lines.
166167
--- - `'dot'` - dot in every cell.
167168
--- - `'double'` - double line.
@@ -322,7 +323,8 @@ MiniBasics.config = {
322323
extra_ui = false,
323324

324325
-- Presets for window borders ('single', 'double', ...)
325-
win_borders = 'default',
326+
-- Default 'auto' infers from 'winborder' option
327+
win_borders = 'auto',
326328
},
327329

328330
-- Mappings. Set field to `false` to disable.
@@ -492,10 +494,13 @@ H.apply_options = function(config)
492494
end
493495

494496
-- Use some common window borders presets
495-
local border_chars = H.win_borders_fillchars[config.options.win_borders]
496-
if border_chars ~= nil then
497-
vim.opt.fillchars:append(border_chars)
497+
local win_borders = config.options.win_borders
498+
if win_borders == 'auto' and vim.fn.has('nvim-0.11') == 1 then
499+
local option_value = vim.o.winborder
500+
win_borders = H.winborder_map[option_value] or option_value
498501
end
502+
local border_chars = H.win_borders_fillchars[win_borders]
503+
if border_chars ~= nil then vim.opt.fillchars:append(border_chars) end
499504
end
500505

501506
H.vim_o = setmetatable({}, {
@@ -524,6 +529,7 @@ H.win_borders_fillchars = {
524529
single = 'vert:│,horiz:─,horizdown:┬,horizup:┴,verthoriz:┼,vertleft:┤,vertright:├,msgsep:─',
525530
solid = 'vert: ,horiz: ,horizdown: ,horizup: ,verthoriz: ,vertleft: ,vertright: ,msgsep: ',
526531
}
532+
H.winborder_map = { none = 'solid', rounded = 'single', shadow = 'solid' }
527533

528534
-- Mappings -------------------------------------------------------------------
529535
--stylua: ignore

readmes/mini-basics.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ Here are code snippets for some common installation methods (use only one):
128128
extra_ui = false,
129129

130130
-- Presets for window borders ('single', 'double', ...)
131-
win_borders = 'default',
131+
-- Default 'auto' infers from 'winborder' option
132+
win_borders = 'auto',
132133
},
133134

134135
-- Mappings. Set field to `false` to disable.

tests/test_basics.lua

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ T['setup()']['creates `config` field'] = function()
4444
-- Check default values
4545
expect_config('options.basic', true)
4646
expect_config('options.extra_ui', false)
47-
expect_config('options.win_borders', 'default')
47+
expect_config('options.win_borders', 'auto')
4848
expect_config('mappings.basic', true)
4949
expect_config('mappings.option_toggle_prefix', [[\]])
5050
expect_config('mappings.windows', false)
@@ -215,12 +215,41 @@ T['Options']['respect `config.options.extra_ui`'] = function()
215215
end
216216

217217
T['Options']['respect `config.options.win_borders`'] = function()
218-
eq(child.o.fillchars, '')
218+
local validate = function(opt_value, ref_fillchars)
219+
child.o.fillchars = ''
220+
load_module({ options = { basic = false, win_borders = opt_value } })
221+
eq(child.o.fillchars, ref_fillchars)
222+
end
223+
224+
validate(nil, '')
225+
validate('double', 'horiz:═,horizdown:╦,horizup:╩,msgsep:═,vert:║,verthoriz:╬,vertleft:╣,vertright:╠')
226+
-- - Should not respect 'winborder' style names directly
227+
validate('none', '')
228+
229+
if child.fn.has('nvim-0.11') == 0 then return end
230+
231+
-- With default 'auto' should infer from 'winborder' option
232+
local validate_winborder = function(winborder_value, ref_fillchars)
233+
child.o.winborder = winborder_value
234+
validate(nil, ref_fillchars)
235+
validate('auto', ref_fillchars)
236+
end
237+
238+
validate_winborder('', '')
239+
240+
local single_fcs = 'horiz:─,horizdown:┬,horizup:┴,msgsep:─,vert:│,verthoriz:┼,vertleft:┤,vertright:├'
241+
validate_winborder('single', single_fcs)
242+
validate_winborder('rounded', single_fcs)
243+
244+
local solid_fcs = 'horiz: ,horizdown: ,horizup: ,msgsep: ,vert: ,verthoriz: ,vertleft: ,vertright: '
245+
validate_winborder('solid', solid_fcs)
246+
validate_winborder('none', solid_fcs)
247+
validate_winborder('shadow', solid_fcs)
219248

220-
load_module({ options = { basic = false, win_borders = 'double' } })
249+
if child.fn.has('nvim-0.12') == 0 then return end
221250

222-
local ref_value = 'horiz:═,horizdown:╦,horizup:╩,msgsep:═,vert:║,verthoriz:╬,vertleft:╣,vertright:╠'
223-
eq(child.o.fillchars, ref_value)
251+
-- With custom list 'winborder' should do nothing
252+
validate_winborder('+,-,+,|,+,-,+,|', '')
224253
end
225254

226255
T['Mappings'] = new_set()

0 commit comments

Comments
 (0)