-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroot.lua
53 lines (44 loc) · 1.05 KB
/
root.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
local tree = require("modalisa.tree")
local config = require("modalisa.config")
local vim = require("modalisa.lib.vim")
local dump = vim.inspect
local M = {}
local root_tree
-- @param[opt=nil] seq
function M.add(key, seq)
root_tree:add(key, seq)
end
-- @param[opt=""] prefix
function M.add_keys(keys, prefix)
for k, v in pairs(keys) do
root_tree:add(v, k, prefix)
end
end
-- @param[opt=""] seq
function M.get(seq)
seq = seq or ""
return root_tree:get(seq)
end
function M.remove(seq)
return root_tree:remove(seq)
end
function M.setup(opts)
assert(root_tree == nil, "root is already setup")
root_tree = tree:new(opts, "modalisa")
awesome.connect_signal("modalisa::config::update", function(_, _)
-- when config has been updated, we have to merge all opts again
local new_opts = config.get_config()
root_tree:add_opts(new_opts)
end)
end
return setmetatable(M, {
__index = function(_, k)
return root_tree:get(k)
end,
__newindex = function(_, k, v)
return root_tree:add(v, k)
end,
__tostring = function(_)
return dump(root_tree)
end,
})