define-command parameters now specify a 'completer' function
This commit is contained in:
parent
0ea9ba1b92
commit
28080a1387
29
command.fnl
29
command.fnl
@ -5,19 +5,11 @@
|
||||
|
||||
(local Buffer (require :buffer))
|
||||
|
||||
(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]
|
||||
(fn define-command [name ordered-params function]
|
||||
;; required parameter names and default arguments
|
||||
(let [param-names (icollect [_ name val (by-pairs ordered-params)]
|
||||
name)
|
||||
params (collect [_ name val (by-pairs ordered-params)]
|
||||
(values name val))
|
||||
(let [param-names (icollect [_ [name] (pairs ordered-params)] name)
|
||||
params (collect [_ [name completer default] (pairs ordered-params)]
|
||||
(values name {: completer : default}))
|
||||
v {: name
|
||||
: function
|
||||
: param-names
|
||||
@ -26,15 +18,16 @@
|
||||
|
||||
(define-command
|
||||
"quit-browser"
|
||||
#(Gtk.main_quit) [])
|
||||
[]
|
||||
#(Gtk.main_quit))
|
||||
|
||||
(define-command
|
||||
"visit-location"
|
||||
[[:buffer #[$1] (fn [f] f.buffer.name)]
|
||||
[:url #[$1] #(do "http://www.example.com")]
|
||||
]
|
||||
(fn [{:url url :buffer buffer}]
|
||||
(let [b (Buffer.find buffer)] (: b :visit url)))
|
||||
[:buffer (fn [f] f.buffer.name)
|
||||
:url #(do "http://www.example.com")
|
||||
])
|
||||
(let [b (Buffer.find buffer)] (: b :visit url))))
|
||||
|
||||
(fn find-command [name]
|
||||
(. commands name))
|
||||
@ -102,7 +95,7 @@
|
||||
:active s.active
|
||||
:error s.error
|
||||
:prompt (if s.active (or s.this-param "Command?" "") "")
|
||||
:default (and param (param self.frame))
|
||||
:default (and param (param.default self.frame))
|
||||
}))
|
||||
|
||||
(fn update-widget-state [{ : entry : prompt} result]
|
||||
|
@ -5,12 +5,16 @@
|
||||
(var happened false)
|
||||
(fn before [] (set happened false))
|
||||
|
||||
(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 #[$1] #(do "3")]
|
||||
[:b #[$1] #(do "2")]]
|
||||
(fn [{: a : b }] (set happened (* (tonumber a) (tonumber b)))))
|
||||
|
||||
(before)
|
||||
(let [commander (Command.commander)
|
||||
|
Loading…
Reference in New Issue
Block a user