instead of using functions directly. This is so that the appropriate frame-relevant commander can be used to execure the command, but also makes the keymaps a little less opaque
58 lines
1.3 KiB
Fennel
58 lines
1.3 KiB
Fennel
(local { : view } (require :fennel))
|
|
(local { : Gdk } (require :lgi))
|
|
|
|
(local keymap (require :keymap))
|
|
|
|
|
|
(local Mod Gdk.ModifierType)
|
|
|
|
(local km {
|
|
"a" {
|
|
"a" ["command-1"]
|
|
"b" ["command-2" {:arg-1 "10" :arg-2 "11"}]
|
|
}
|
|
"b" {
|
|
"z" ["command-3"]
|
|
}
|
|
"c" ["command-4"]
|
|
})
|
|
|
|
(fn fake-key-event [c]
|
|
{:keyval (string.byte c)
|
|
:state {}
|
|
})
|
|
|
|
|
|
(let [s (keymap._.keychord->spec "q")]
|
|
(match s
|
|
{:keyval 113 :modmask 0} true
|
|
_ (assert false (view s))))
|
|
|
|
(let [s (keymap._.keychord->spec "C-a")]
|
|
(match s
|
|
{:keyval 97 :modmask 4} true
|
|
_ (assert false (view s))))
|
|
|
|
(let [s (keymap._.keychord->spec "C-M-Z")]
|
|
(match s
|
|
{:keyval 122 :modmask 13} true
|
|
_ (assert false (view s))))
|
|
|
|
|
|
(let [r (keymap.recogniser km)
|
|
(ok err)
|
|
(match (r:accept-event (fake-key-event "c"))
|
|
["command-4"] true
|
|
x (values false (view x))
|
|
nil (values false "???"))]
|
|
(assert ok err))
|
|
|
|
(let [r (keymap.recogniser km)
|
|
(ok err)
|
|
(match-try
|
|
(r:accept-event (fake-key-event "a"))
|
|
nil (r:accept-event (fake-key-event "b"))
|
|
["command-2" {:arg-1 "10" :arg-2 "11"}] true
|
|
(catch x (values false (view x))))]
|
|
(assert ok err))
|