-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshowkey.lua
64 lines (55 loc) · 1.46 KB
/
showkey.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
local vim = require("modalisa.lib.vim")
local dump = vim.inspect
local akeygrabber = require("awful.keygrabber")
local M = {}
local grabber
function M.start(args)
local stop_key = args.stop_key or "Escape"
local mod_map = args.mod_map or {
Shift = "S",
Mod1 = "A",
Mod4 = "M",
Control = "C",
}
local opts = args.opts or {}
-- force visibilty and no timeout
opts.echo = opts.echo or {}
opts.echo.enabled = true
opts.echo.timeout = 0
local ignore_mods = args.ignore_mods or { "Lock2", "Mod2" }
grabber = akeygrabber({
start_callback = function()
awesome.emit_signal("modalisa::echo", { showkey = string.format("press %s to exit", stop_key) }, opts)
end,
stop_callback = function()
awesome.emit_signal("modalisa::echo::hide")
end,
stop_key = stop_key,
keypressed_callback = function(_, modifiers, key)
local filtered_modifiers = {}
for _, m in ipairs(modifiers) do
local ignore = vim.tbl_contains(ignore_mods, m)
if not ignore then
table.insert(filtered_modifiers, m)
end
end
modifiers = filtered_modifiers
print("mods: ", dump(modifiers), "key: ", key)
local k = ""
for _, m in pairs(modifiers) do
k = string.format("%s%s-", k, mod_map[m])
end
k = string.format("%s%s", k, key)
if string.len(k) > 1 then
k = string.format("<%s>", k)
end
awesome.emit_signal("modalisa::echo", { showkey = k }, opts)
end,
}):start()
end
function M.stop()
if grabber then
grabber:stop()
end
end
return M