Compare commits

...

5 Commits

Author SHA1 Message Date
Daniel Barlow 862780878c clean up the spew file a bit 2023-01-01 00:15:26 +00:00
Daniel Barlow 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
Daniel Barlow 39735be891 unnest conditionals in keymap recogniser 2022-12-31 23:49:41 +00:00
Daniel Barlow ec391a9e57 delete unused params 2022-12-31 23:24:38 +00:00
Daniel Barlow 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 { : view } (require :fennel))
(fn new-buffer [name keymap]
(fn new-buffer [name]
(var property-change-listener nil)
(let [props {}
widget (WebKit2.WebView {
;; :on_decide_policy
@ -19,12 +20,18 @@
(when (not (= pspec.name :parent))
(let [val (. self pspec.name)]
(tset props pspec.name val)
;(listeners:notify pspec.name val)
)))
(when property-change-listener
(property-change-listener
pspec.name val)))
))
})]
{:webview widget
: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}))
(let [buffers {}]

View File

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

View File

@ -30,7 +30,14 @@
contentwidget (Gtk.Box {
: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
(fn [window event]
@ -58,6 +65,11 @@
(w:hide))
(tset self :buffer b)
(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))
}]
(lume.extend self f)

View File

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

View File

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