58 lines
911 B
Lua
58 lines
911 B
Lua
local bind = {}
|
|
|
|
bind.leader = "SUPER"
|
|
|
|
local function merge(...)
|
|
local out = {}
|
|
|
|
for _, t in ipairs({ ... }) do
|
|
if t ~= nil then
|
|
for k, v in pairs(t) do
|
|
out[k] = v
|
|
end
|
|
end
|
|
end
|
|
|
|
return out
|
|
end
|
|
|
|
function bind.with_leader(keys)
|
|
if keys == nil or keys == "" then
|
|
return bind.leader
|
|
end
|
|
|
|
return bind.leader .. " + " .. keys
|
|
end
|
|
|
|
function bind.key(keys, dispatcher, desc, opts)
|
|
local flags = merge(opts)
|
|
|
|
if desc ~= nil then
|
|
flags.description = desc
|
|
end
|
|
|
|
return hl.bind(keys, dispatcher, flags)
|
|
end
|
|
|
|
function bind.set(table)
|
|
local keys = table.keys
|
|
local dispatcher = table.dispatcher
|
|
local desc = ""
|
|
local opts = {}
|
|
if table.desc ~= nil and table.desc ~= "" then
|
|
desc = table.desc
|
|
end
|
|
if table.opts ~= nil then
|
|
opts = table.opts
|
|
end
|
|
bind.key(keys, dispatcher, desc, opts)
|
|
end
|
|
|
|
function bind.map(table)
|
|
for _, item in pairs(table) do
|
|
bind.set(item)
|
|
end
|
|
end
|
|
|
|
return bind
|