commit 87448bd5eeb4541a1a2734f67fb9d056b20362d5
parent a34e63877d68be532498505494cd30a65bd05295
Author: Daniel Barlow <dan@telent.net>
Date: Tue, 20 Dec 2022 11:14:27 +0000
add visit-location command
though it does hardcode the URL, making it less than generally useful
Diffstat:
3 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/buffer.fnl b/buffer.fnl
@@ -31,5 +31,6 @@
(let [b (new-buffer name)]
(tset buffers name b)
b))
+ :current (fn [] (let [k (next buffers)] (. buffers k)))
:find (fn [self term] (. buffers term))
})
diff --git a/command.fnl b/command.fnl
@@ -1,15 +1,33 @@
(local { : Gtk } (require :lgi))
+(local { : view } (require :fennel))
(local commands {})
+(local Buffer (require :buffer))
+
+;; when a command is invoked from a binding, the binding may provide
+;; some or all of the parameter values. when there are missing params,
+;; or when invoked from the commander, `invoke` prompts for the
+;; missing params, offering default values which were specified by
+;; define-command
(fn define-command [name function params]
+ ;; required parameter names and default arguments
(let [v {:name name :function function :params params}]
(tset commands name v)))
(define-command "quit-browser" #(Gtk.main_quit) {})
+(define-command
+ "visit-location"
+ (fn [{:url url :buffer buffer}]
+ (buffer:visit url))
+ {:buffer (fn [] (Buffer.current))
+ :url #(do "http://www.example.com")
+ })
+
(fn prompt-missing-args [params explicit-args]
- explicit-args)
+ (collect [k v (pairs params)]
+ (values k (or (. explicit-args k) (v)))))
(fn invoke [s args]
(match (. commands s)
diff --git a/frame.fnl b/frame.fnl
@@ -44,9 +44,7 @@
:content contentwidget
:show-buffer (fn [self b]
(each [_ w (pairs (contentwidget:get_children))]
- (print "hide " w)
(w:hide))
- (print "show " (view b))
(contentwidget:pack_start b.webview true true 0)
(b.webview:show))
}]