-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
120 lines (94 loc) · 2.19 KB
/
init.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
local M = {}
---@diagnostic disable-next-line: unused-local
local dump = require("modalisa.lib.vim").inspect
local root_tree = require("modalisa.root")
local modal = require("modalisa.modal")
local config = require("modalisa.config")
function M.showkey(...)
modal.showkey(...)
end
-- run key sequence on root
function M.run(...)
return modal.run(...)
end
-- run inline tree
function M.run_tree(...)
return modal.run_tree(...)
end
function M.stop()
modal.stop()
end
function M.fake_input(...)
return modal.fake_input(...)
end
-- add key to root
function M.add_key(...)
return root_tree.add(...)
end
-- remove key from root
function M.remove_key(...)
return root_tree.remove(...)
end
-- get key from root
function M.get_tree(...)
return root_tree.get(...)
end
-- add keys to root
function M.add_keys(...)
return root_tree.add_keys(...)
end
-- config set var
function M.set(k, v)
config[k] = v
end
-- config get var
function M.get(k)
return config[k]
end
-- get complete config
function M.get_config(...)
return config.get_config(...)
end
-- get complete config
function M.get_default_config(...)
return config.get_default_config(...)
end
local mt = {
__call = function(_, opts)
return M.setup(opts)
end,
}
local once
function M.setup(opts)
assert(once == nil, "modalisa is already setup")
once = true
config.setup(opts)
opts = config.get_config() or {}
require("modalisa.root").setup(opts)
require("modalisa.modal").setup(opts)
-- NOTE: all UI modules are only invoked by signals making them completely
-- optional, so that users are able to implement their own, if configuration
-- options do not suit them.
if not opts.disable_hints then
require("modalisa.ui.hints").setup(opts)
end
if not opts.disable_label then
require("modalisa.ui.label").setup(opts)
end
if not opts.disable_echo then
require("modalisa.ui.echo").setup(opts)
end
if not opts.disable_prompt then
require("modalisa.ui.prompt").setup(opts)
end
-- default keys
if opts.include_default_keys then
require("modalisa.keys").setup(opts)
end
-- user defined keys
if pcall(require, "modalisa_keys") then
require("modalisa_keys").setup(opts)
end
return setmetatable(M, mt)
end
return setmetatable(M, mt)