Compare commits

...

5 Commits

Author SHA1 Message Date
862780878c clean up the spew file a bit 2023-01-01 00:15:26 +00:00
64d4dfe2ff hook up progress-bar, uri display
the road to callback hell is plagued with good intentions:
I am not unwilling to revisit this code if it gets any more gnarly
2023-01-01 00:11:01 +00:00
39735be891 unnest conditionals in keymap recogniser 2022-12-31 23:49:41 +00:00
ec391a9e57 delete unused params 2022-12-31 23:24:38 +00:00
7065b89c92 visit-location defaults to current 2022-12-31 17:33:20 +00:00
5 changed files with 95 additions and 61 deletions

View File

@ -1,7 +1,8 @@
(local { : Gtk : Gdk : WebKit2 : cairo } (require :lgi)) (local { : Gtk : Gdk : WebKit2 : cairo } (require :lgi))
(local { : view } (require :fennel)) (local { : view } (require :fennel))
(fn new-buffer [name keymap] (fn new-buffer [name]
(var property-change-listener nil)
(let [props {} (let [props {}
widget (WebKit2.WebView { widget (WebKit2.WebView {
;; :on_decide_policy ;; :on_decide_policy
@ -19,12 +20,18 @@
(when (not (= pspec.name :parent)) (when (not (= pspec.name :parent))
(let [val (. self pspec.name)] (let [val (. self pspec.name)]
(tset props pspec.name val) (tset props pspec.name val)
;(listeners:notify pspec.name val) (when property-change-listener
))) (property-change-listener
pspec.name val)))
))
})] })]
{:webview widget {:webview widget
:name name :name name
:visit (fn [self u] (widget:load_uri u)) :subscribe-property-changes
(fn [self cb]
(set property-change-listener cb))
:location #(widget:get_uri)
:visit (fn [_ u] (widget:load_uri u))
:properties props})) :properties props}))
(let [buffers {}] (let [buffers {}]

View File

@ -36,7 +36,7 @@
[[:buffer [[:buffer
Buffer.match Buffer.match
#($1.buffer.name)] #($1.buffer.name)]
[:url #(doto {} (tset $1 $1)) #(do "http://www.example.com")] [:url #{$1 $1} #($1.buffer:location)]
] ]
(fn [{:url url :buffer buffer}] (fn [{:url url :buffer buffer}]
(buffer:visit url))) (buffer:visit url)))
@ -183,6 +183,9 @@
:widget box :widget box
: prompt : prompt
: frame : frame
:set-inactive-text (fn [self text]
(when (not self.state.active)
(tset entry :text text)))
:completions-widget completions :completions-widget completions
}] }]
(hbox:pack_start prompt false false 15) (hbox:pack_start prompt false false 15)

View File

@ -30,7 +30,14 @@
contentwidget (Gtk.Box { contentwidget (Gtk.Box {
:orientation Gtk.Orientation.VERTICAL :orientation Gtk.Orientation.VERTICAL
}) })
] update-prop (fn [name value]
(match name
:estimated-load-progress
(tset progress-bar :fraction value)
:uri
(commander:set-inactive-text value)
n
(comment (print "prop change" n value))))]
(tset window :on_key_release_event (tset window :on_key_release_event
(fn [window event] (fn [window event]
@ -58,6 +65,11 @@
(w:hide)) (w:hide))
(tset self :buffer b) (tset self :buffer b)
(contentwidget:pack_start b.webview true true 0) (contentwidget:pack_start b.webview true true 0)
(b:subscribe-property-changes
(fn [name val]
(if (= b self.buffer)
(update-prop name val)
(print "ignore props from background" b))))
(b.webview:show)) (b.webview:show))
}] }]
(lume.extend self f) (lume.extend self f)

View File

@ -44,17 +44,20 @@
(bor m (. Gdk.ModifierType k)))] (bor m (. Gdk.ModifierType k)))]
(spec->index {:keyval event.keyval : modmask}))) (spec->index {:keyval event.keyval : modmask})))
(fn designates-command? [tbl] (fn command? [tbl]
;; a keymap entry has a string as key, a command ;; a keymap entry has a string as key, a command
;; definition is a numerically-indexed array ;; definition is a numerically-indexed array
(if (. tbl 1) true)) (if (. tbl 1) true))
(fn keymap? [tbl]
(not (. tbl 1)))
(fn compile-keymap [input] (fn compile-keymap [input]
(collect [k v (pairs input)] (collect [k v (pairs input)]
(let [f (-> k keychord->spec spec->index)] (let [f (-> k keychord->spec spec->index)]
(if (designates-command? v) (if (keymap? v)
(values f v) (values f (compile-keymap v))
(values f (compile-keymap v)))))) (values f v)))))
(fn recogniser [source-keymap] (fn recogniser [source-keymap]
(let [keymap (compile-keymap source-keymap)] (let [keymap (compile-keymap source-keymap)]
@ -63,19 +66,21 @@
:accept-event :accept-event
(fn [_ e] (fn [_ e]
(when (not (modifier? e.keyval)) (when (not (modifier? e.keyval))
(let [c (event->index e) (let [c (event->index e)]
v (. m c)] (match (. m c)
(if v (where v (keymap? v))
(if (designates-command? v) (do
(do (set m v)
(set m keymap) (values nil (.. c " ")))
v)
(do (where v (command? v))
(set m v) (do
(values nil (.. c " ")))) (set m keymap)
(do v)
(set m keymap) _
(values nil (.. "No binding for " (view e) " "))))))) (do
(set m keymap)
(values nil (.. "No binding for " (view e) " ")))))))
})) }))

View File

@ -34,54 +34,61 @@ document element(?)
webview webview
lua's standard types lua's standard types
## next steps -----
* [done] change define-command so that the parameters are ordered a consideration we haven't touched on yet: in emacs, not all buffers
* display unbound key error are files - e.g. the buffer list, or the process list, or the magit
* ESC to cancel interactive command status buffer - there is a well-used affordance for elisp to put
* autocomplete command name semi-persistent interactable content onscreen - do we need such a
* parameters with non-string values (e.g. buffer) thing here or is it ok to say "just call gtk" to command authors
* show current url when command inactive
* [done] show prompts for parameter ----
* multiple buffers
- create buffer when input widget is active for a parameter, show the completions
- list buffers (where does the output go?) flowbox
- find and switch to buffer
while typing, use the typed input to get a completions list. each
completion is an acceptable value: convert to a gtk widget by calling
(to-label value) and add to flowbox.
how do we do the buffer list thing? if the value is a table
- generate html, or if :to-label key present, use it as-is
- use native widgets else Gtk.Label { :label value.value }
else (assume it's a string)
Gtk.Label { :label value }
native widgets seems neater on RET, check there is a completion value whose stringification
- how do we permit commands to insert widgets into the frame? matches the input string. Hide the flowbox
- how do we get rid of them?
we could have an "output overlay" inserted underneath the commander. to activate a rendered completion, the callback needs to perform the
could we use the same thing for completions? we haven't addressed same action as RET would on the chosen value
non-string parameters yet, really
M-x switch-to-buffer is there a role for TAB?
Buffer mai_
+------+ +---------+ - in the shell it activates completion or shows options: we don't need that if we're updating them automatically
| main | | mailing |
+------+ +---------+ - we could use it to cycle through the available completions: switch
focus from entry to step through the completions then RET activates
----- -----
so there are two things going on here # TODO
1) how to implement switch-to-buffer with appropriate autocomplete * [done] show loading progress
on the buffer name - perhaps involving showing buffer thumbnails etc * [done] show url when the commander is inactive
* [done] visit-location url defaults to current
2) in emacs, not all buffers are files - e.g. the buffer list, or the * custom rendering for completions (e.g. buffer thumbnails)
process list, or the magit status buffer - there is a well-used * buffer name is often going to be useless. find buffers
affordance for elisp to put semi-persistent interactable content by url/title
onscreen - do we need such a thing here or is it ok to say "just call still need some 1:1 mapping between the buffer object and
gtk" to command authors a text-representable form of same
* click in commander widget activates visit-location
are these the same problem or are they separate problems? do we have * display unbound key error
the second problem? What I will do is address the first one and * ESC to cancel interactive command
see if it's generalisable once I've done it. * autocomplete command name
* multiple buffers
- create buffer
- list buffers (do we need this if we have thumbnails?)