Skip to content

Commit df7c522

Browse files
committed
feat(utils): Add a helper to handle validate table
1 parent 5895bca commit df7c522

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lua/dashboard/utils.lua

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,22 @@ local uv = vim.loop
22
local utils = {}
33

44
utils.is_win = uv.os_uname().version:match('Windows')
5+
local is_nvim_11_or_newer = vim.version().minor >= 11 -- check nvim minor ver
56

67
function utils.path_join(...)
78
local path_sep = utils.is_win and '\\' or '/'
89
return table.concat({ ... }, path_sep)
910
end
1011

12+
-- dynamically use correct validate form method
13+
local function validate_table(name, value)
14+
if is_nvim_11_or_newer then
15+
vim.validate(name, value, 'table')
16+
else
17+
vim.validate({ [name] = { value, 't' } })
18+
end
19+
end
20+
1121
function utils.element_align(tbl)
1222
local lens = {}
1323
vim.tbl_map(function(k)
@@ -26,7 +36,7 @@ function utils.element_align(tbl)
2636
end
2737

2838
function utils.get_max_len(contents)
29-
vim.validate('contents', contents, 'table')
39+
validate_table('contents', contents)
3040
local cells = {}
3141
for _, v in pairs(contents) do
3242
table.insert(cells, vim.api.nvim_strwidth(v))
@@ -37,7 +47,7 @@ end
3747

3848
-- draw the graphics into the screen center
3949
function utils.center_align(tbl)
40-
vim.validate('tbl', tbl, 'table')
50+
validate_table('tbl', tbl)
4151
local function fill_sizes(lines)
4252
local fills = {}
4353
for _, line in pairs(lines) do

0 commit comments

Comments
 (0)