Compare commits

...

5 Commits

Author SHA1 Message Date
Daniel Barlow 8d871b20b8 define command parameters as array not kv table
a command should be able to say in which order it wants to ask for
unsupplied parameter values
2022-12-23 19:48:17 +00:00
Daniel Barlow bdd4507692 we are amused 2022-12-23 19:45:58 +00:00
Daniel Barlow e639e4c73d remove duplicate handler for entry activation 2022-12-23 19:45:37 +00:00
Daniel Barlow 40a598dca8 add indefinite article 2022-12-23 16:29:42 +00:00
Daniel Barlow e1988e6703 remove `inspect` package: we're not using it 2022-12-23 16:29:12 +00:00
6 changed files with 48 additions and 61 deletions

View File

@ -5,22 +5,36 @@
(local Buffer (require :buffer))
(fn define-command [name function params]
(fn by-pairs [a]
(let [iter (fn [_ a]
(match a
[k v & rest] (values rest k v)
_ nil))]
(values iter a a)))
(fn define-command [name function ordered-params]
;; required parameter names and default arguments
(let [v {:name name :function function :params params}]
(let [param-names (icollect [_ name val (by-pairs ordered-params)]
name)
params (collect [_ name val (by-pairs ordered-params)]
(values name val))
v {: name
: function
: param-names
: params}]
(tset commands name v)))
(define-command
"quit-browser"
#(Gtk.main_quit) {})
#(Gtk.main_quit) [])
(define-command
"visit-location"
(fn [{:url url :buffer buffer}]
(let [b (Buffer.find buffer)] (: b :visit url)))
{:buffer (fn [] (. (Buffer.current) :name))
[:buffer (fn [] (. (Buffer.current) :name))
:url #(do "http://www.example.com")
})
])
(fn find-command [name]
(. commands name))
@ -38,7 +52,7 @@
(fn next-param [command params]
(accumulate [v nil
k _ (pairs command.params)
_ k (ipairs command.param-names)
&until v]
(if (. params k) nil k)))

View File

@ -20,7 +20,6 @@
}:
let pname = "dunlin";
lua = lua5_3.withPackages (ps: with ps; [
inspect
lgi
luafilesystem
luaposix
@ -33,7 +32,7 @@ in stdenv.mkDerivation rec {
fennel = fennel_;
version = "0.1";
src =./.;
src = lib.sources.cleanSource ./.;
GIO_EXTRA_MODULES = glib_networking_gio;

View File

@ -22,8 +22,9 @@ like:
* watch a local html file and reload when it changes
* find the open tab for my home Fediverse instance (or open one if
needed) and post a message/share a link to what I'm looking at
* search the {Lua reference, Ruby docs, GTK docs} for term instead of
wading through the SEO cesspool that is the internet in 2022
* search the {Lua reference, Ruby docs, GTK docs} for a given term
instead of wading through the SEO cesspool that is the internet in
2022
* search in previously "liked" pages for the thing I found three weeks
ago, instead of ... ditto
* find the tab that's playing music and pause the player (instead of

View File

@ -27,14 +27,6 @@
:orientation Gtk.Orientation.VERTICAL
})
]
(tset Command.widget :on_activate
(fn [event]
(let [result (Command.on-input event.text)]
(set Command.widget.placeholder_text
(or result.prompt ""))
(set Command.widget.sensitive result.active)
(set Command.widget.text
(or result.default result.error "")))))
(tset window :on_key_release_event
(fn [window event]

View File

@ -1,41 +1,10 @@
what if ... a web browser, but tabs were more like emacs buffers?
# Braindump
buffer attributes:
- url
- viewport (this is a departure from the emacs buffer)
This is a combination of a thinking-out-loud document and a TODO list.
It is not a document of record. You should not expect to derive value
from reading it
## commands
A command is a description of a function that may be invoked
interactively, and the parameters it expects.
```fennel
(define-command "visit-location"
visit-location
{:url Type.Url input-from-minibuffer})
;; hit "g" and then enter the location in the minibuffer
(bind-key "g" (command "visit-location"))
;; hit "h" to go straight to your home page
(bind-key "h" (command "visit-location")
{:url (Type.Url "https://home.example.com")})
;; left mouse click on minibuffer hit "h" to go straight to your home page
(bind-event Dunlin.minibuffer :button-1-click (command "visit-location"))
```
when it is run from the command prompt, each parameter is
prompted, with appropriate defaults.
when it is bound to a key chord/sequence, the binding may specify
where it gets its parameters from - otherise
visit-location
visit-location-in-new-buffer
run-command
back
switch-to-buffer
save-file
save-link
tl;dr what if ... a web browser, but tabs were more like emacs buffers?
## objects/data types
@ -47,6 +16,8 @@ buffer
add some kind of webview reuse so that invisible and old buffers
don't need to have a webview until needed.
I seem to be using "buffer" and "tab" mostly synonymously
frame
Frame.the-frame
frame.set-buffer (buffer)
@ -54,15 +25,25 @@ frame
frame.commander - text entry widget
frame.actions - container of toolbar buttons
in future we may be able to split a frame into multiple windows
which show different buffers
location (url)
document
document element(?)
webview
lua's standard types
## next steps
# getting started
gtk stuffz for frame/commander/initial buffer
command parser hooked to commander
visit-location command
* 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
* show prompts for parameter
* multiple buffers
- create buffer
- list buffers (where does the output go?)
- find and switch to buffer

View File

@ -5,12 +5,12 @@
(var happened false)
(fn before [] (set happened false) (Command.reset-state))
(Command.define-command "no-args-command" #(set happened true))
(Command.define-command "no-args-command" #(set happened true) [])
(Command.define-command
"multiply"
(fn [{: a : b }] (set happened (* (tonumber a) (tonumber b))))
{:a #(do "3") :b #(do "2")})
[:a #(do "3") :b #(do "2")])
(before)
(let [(ok err)