use keymap to choose command to invoke
This commit is contained in:
parent
a489df34ab
commit
25d31e0262
2
Procfile
2
Procfile
@ -1,2 +1,2 @@
|
||||
repl: fennel
|
||||
test: find . | entr sh test/run.sh
|
||||
test: find . -type d | entr -d sh test/run.sh
|
@ -1,7 +1,7 @@
|
||||
(local { : Gtk : Gdk : WebKit2 : cairo } (require :lgi))
|
||||
(local { : view } (require :fennel))
|
||||
|
||||
(fn new-buffer [name]
|
||||
(fn new-buffer [name keymap]
|
||||
(let [props {}
|
||||
widget (WebKit2.WebView {
|
||||
;; :on_decide_policy
|
||||
|
26
frame.fnl
26
frame.fnl
@ -1,12 +1,29 @@
|
||||
(local { : Gtk : Gdk : WebKit2 : cairo } (require :lgi))
|
||||
(local { : view } (require :fennel))
|
||||
(local Command (require :command))
|
||||
(local keymap (require :keymap))
|
||||
|
||||
(var frames [])
|
||||
|
||||
(fn new-frame []
|
||||
(let [hpad 2
|
||||
vpad 2
|
||||
recogniser (keymap.recogniser
|
||||
{
|
||||
"g" #(Command.invoke-interactively
|
||||
"visit-location"
|
||||
{:buffer "main"})
|
||||
"q" #(Command.invoke-interactively
|
||||
"quit-browser"
|
||||
{})
|
||||
"c" {
|
||||
"x"
|
||||
#(Command.invoke-interactively
|
||||
"quit-browser"
|
||||
{})
|
||||
}
|
||||
|
||||
})
|
||||
window (Gtk.Window {
|
||||
:title "Dunlin"
|
||||
:default_width 800
|
||||
@ -36,11 +53,10 @@
|
||||
|
||||
(tset window :on_key_release_event
|
||||
(fn [window event]
|
||||
(when (and (not (Command.active?))
|
||||
(= event.keyval (string.byte "g")))
|
||||
(Command.invoke-interactively
|
||||
"visit-location"
|
||||
{:buffer "main"}))
|
||||
(when (not (Command.active?))
|
||||
(match (recogniser:accept (string.char event.keyval))
|
||||
c (c)
|
||||
(nil prompt) (print "prompted" prompt)))
|
||||
(when (and event.state.MOD1_MASK
|
||||
(= event.keyval (string.byte "x")))
|
||||
(Command.activate))))
|
||||
|
19
keymap.fnl
Normal file
19
keymap.fnl
Normal file
@ -0,0 +1,19 @@
|
||||
|
||||
|
||||
(fn recogniser [keymap]
|
||||
(var m keymap)
|
||||
{
|
||||
:accept
|
||||
(fn [_ c]
|
||||
(let [v (. m c)]
|
||||
(match (type v)
|
||||
"table" (do
|
||||
(set m v)
|
||||
(values nil (.. c " ")))
|
||||
"function" (do
|
||||
(set m keymap)
|
||||
v))))
|
||||
})
|
||||
|
||||
|
||||
{ : recogniser }
|
20
test/keymap.fnl
Normal file
20
test/keymap.fnl
Normal file
@ -0,0 +1,20 @@
|
||||
(local { : view } (require :fennel))
|
||||
|
||||
(local keymap (require :keymap))
|
||||
|
||||
(local km
|
||||
{"a"
|
||||
{"a" #1
|
||||
"b" #2}
|
||||
"b"
|
||||
{"z" #3}
|
||||
"c" #4
|
||||
})
|
||||
|
||||
(let [r (keymap.recogniser km)
|
||||
(ok err)
|
||||
(match (r:accept "c")
|
||||
(where f (= (f) 4)) true
|
||||
x (values false (x)))]
|
||||
|
||||
(assert ok err))
|
Loading…
Reference in New Issue
Block a user