Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lua/focus/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ local autocmd = require('focus.modules.autocmd')
local split = require('focus.modules.split')
local functions = require('focus.modules.functions')
local resizer = require('focus.modules.resizer')
local utils = require('focus.modules.utils')

local H = {}
local Focus = {}
Expand Down Expand Up @@ -177,19 +178,19 @@ end
H.default_config = Focus.config

H.setup_config = function(config)
vim.validate({ config = { config, 'table', true } })
utils.validate({ config = { config, 'table', true } })

config = vim.tbl_deep_extend('force', H.default_config, config or {})

vim.validate({
utils.validate({
enable = { config.enable, 'boolean' },
commands = { config.commands, 'boolean' },
autoresize = { config.autoresize, 'table', true },
split = { config.split, 'table', true },
ui = { config.split, 'table', true },
})

vim.validate({
utils.validate({
['autoresize.enable'] = { config.autoresize.enable, 'boolean' },
['autoresize.width'] = { config.autoresize.width, 'number' },
['autoresize.height'] = { config.autoresize.height, 'number' },
Expand Down Expand Up @@ -217,12 +218,12 @@ H.setup_config = function(config)
},
})

vim.validate({
utils.validate({
['split.bufnew'] = { config.split.bufnew, 'boolean' },
['split.tmux'] = { config.split.tmux, 'boolean' },
})

vim.validate({
utils.validate({
['ui.number'] = { config.ui.number, 'boolean' },
['ui.relativenumber'] = { config.ui.relativenumber, 'boolean' },
['ui.hybridnumber'] = { config.ui.hybridnumber, 'boolean' },
Expand All @@ -237,7 +238,7 @@ H.setup_config = function(config)
['ui.winhighlight'] = { config.ui.winhighlight, 'boolean' },
})

vim.validate({
utils.validate({
['ui.colorcolumn.enable'] = { config.ui.colorcolumn.enable, 'boolean' },
['ui.colorcolumn.list'] = { config.ui.colorcolumn.list, 'string' },
})
Expand Down
21 changes: 21 additions & 0 deletions lua/focus/modules/utils.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
local M = {}

function M.validate(T)
local max = vim.fn.has('nvim-0.11') == 1 and 3 or 4
for name, spec in pairs(T) do
while #spec > max do
table.remove(spec, #spec)
end

T[name] = spec
end

if vim.fn.has('nvim-0.11') == 1 then
for name, spec in pairs(T) do
table.insert(spec, 1, name)
vim.validate(unpack(spec))
end
return
end

vim.validate(T)
end

--RETURNS TABLE OF LOWER CASE STRINGS
--
function M.to_lower(list)
Expand Down