From 87448bd5eeb4541a1a2734f67fb9d056b20362d5 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Tue, 20 Dec 2022 11:14:27 +0000 Subject: [PATCH] add visit-location command though it does hardcode the URL, making it less than generally useful --- buffer.fnl | 1 + command.fnl | 20 +++++++++++++++++++- frame.fnl | 2 -- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/buffer.fnl b/buffer.fnl index 3e026e4..39a4e6b 100644 --- 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 index 8a08e46..e52feea 100644 --- 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 index 82b081f..c8bf28c 100644 --- 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)) }]