Compare commits
1 Commits
4b78434ea4
...
2ceb5ad757
Author | SHA1 | Date | |
---|---|---|---|
2ceb5ad757 |
25
command.fnl
25
command.fnl
@ -47,7 +47,6 @@
|
|||||||
#$1.buffer.name]
|
#$1.buffer.name]
|
||||||
[:url
|
[:url
|
||||||
(fn [term]
|
(fn [term]
|
||||||
(let [from-history
|
|
||||||
(if (> (# term) 2)
|
(if (> (# term) 2)
|
||||||
(icollect [v (_G.history:find-distinct term)]
|
(icollect [v (_G.history:find-distinct term)]
|
||||||
(let [label (.. v.url " " (or v.title ""))]
|
(let [label (.. v.url " " (or v.title ""))]
|
||||||
@ -55,8 +54,7 @@
|
|||||||
:widget (Gtk.Button { : label })
|
:widget (Gtk.Button { : label })
|
||||||
:value v.url
|
:value v.url
|
||||||
})))
|
})))
|
||||||
[])]
|
[]))
|
||||||
(lume.unique (lume.concat from-history [(completion {:text term})]))))
|
|
||||||
#($1.buffer:location)]
|
#($1.buffer:location)]
|
||||||
]
|
]
|
||||||
(fn [{:url url :buffer buffer}]
|
(fn [{:url url :buffer buffer}]
|
||||||
@ -69,7 +67,6 @@
|
|||||||
#$1.buffer.name]]
|
#$1.buffer.name]]
|
||||||
(fn [{: buffer}] (buffer:back)))
|
(fn [{: buffer}] (buffer:back)))
|
||||||
|
|
||||||
|
|
||||||
(fn find-command [name]
|
(fn find-command [name]
|
||||||
(. commands name))
|
(. commands name))
|
||||||
|
|
||||||
@ -171,8 +168,8 @@
|
|||||||
|
|
||||||
{:command nil}
|
{:command nil}
|
||||||
(set-completions
|
(set-completions
|
||||||
(icollect [k _ (pairs commands)]
|
(collect [k _ (pairs commands)]
|
||||||
(if (= (k:find str 1 true) 1) (completion { :text k})))))))
|
(if (= (k:find str 1 true) 1) (values k k)))))))
|
||||||
|
|
||||||
(fn activate [{: state : entry : prompt &as self}]
|
(fn activate [{: state : entry : prompt &as self}]
|
||||||
(tset state :active true)
|
(tset state :active true)
|
||||||
@ -208,8 +205,12 @@
|
|||||||
(fn new-commander [frame]
|
(fn new-commander [frame]
|
||||||
(let [entry (Gtk.Entry {:sensitive false })
|
(let [entry (Gtk.Entry {:sensitive false })
|
||||||
prompt (Gtk.Label { :label ""})
|
prompt (Gtk.Label { :label ""})
|
||||||
box (Gtk.Box { :orientation Gtk.Orientation.VERTICAL })
|
box (Gtk.Box {
|
||||||
hbox (Gtk.Box { :orientation Gtk.Orientation.HORIZONTAL })
|
:orientation Gtk.Orientation.VERTICAL
|
||||||
|
})
|
||||||
|
hbox (Gtk.Box {
|
||||||
|
:orientation Gtk.Orientation.HORIZONTAL
|
||||||
|
})
|
||||||
completions (Gtk.FlowBox)
|
completions (Gtk.FlowBox)
|
||||||
self {
|
self {
|
||||||
:state default-state
|
:state default-state
|
||||||
@ -229,9 +230,13 @@
|
|||||||
(hbox:pack_start entry true true 5)
|
(hbox:pack_start entry true true 5)
|
||||||
(box:pack_start hbox true false 0)
|
(box:pack_start hbox true false 0)
|
||||||
(box:pack_start completions true true 0)
|
(box:pack_start completions true true 0)
|
||||||
(tset entry :on_changed #(self:on-input $1.text))
|
(tset entry :on_changed
|
||||||
|
(fn [event]
|
||||||
|
(self:on-input event.text)))
|
||||||
(tset entry :on_activate
|
(tset entry :on_activate
|
||||||
#(update-widget-state self (self:on-input-finished $1.text)))
|
(fn [event]
|
||||||
|
(let [result (self:on-input-finished event.text)]
|
||||||
|
(update-widget-state self result))))
|
||||||
self))
|
self))
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,8 +6,6 @@
|
|||||||
(local Frame (require :frame))
|
(local Frame (require :frame))
|
||||||
(local Buffer (require :buffer))
|
(local Buffer (require :buffer))
|
||||||
|
|
||||||
(local search (require :search))
|
|
||||||
|
|
||||||
;;; when we decide how to do an init file/rc file, this will go in it
|
;;; when we decide how to do an init file/rc file, this will go in it
|
||||||
|
|
||||||
(local my-keymap {
|
(local my-keymap {
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
(s:nrows)))
|
(s:nrows)))
|
||||||
|
|
||||||
(fn find-distinct [self term]
|
(fn find-distinct [self term]
|
||||||
|
(print :self self :term term)
|
||||||
(let [s (self.db:prepare "select distinct v.url,pt.title from visits v left join page_titles pt on v.url = pt.url where instr(v.url, ?) >0")]
|
(let [s (self.db:prepare "select distinct v.url,pt.title from visits v left join page_titles pt on v.url = pt.url where instr(v.url, ?) >0")]
|
||||||
(assert (= 0 (s:bind_values term)))
|
(assert (= 0 (s:bind_values term)))
|
||||||
(s:nrows)))
|
(s:nrows)))
|
||||||
|
@ -65,7 +65,6 @@ focus from entry to step through the completions then RET activates
|
|||||||
* [done] display unbound key error
|
* [done] display unbound key error
|
||||||
* [done] back binding
|
* [done] back binding
|
||||||
* [done] save url history, use it in completions
|
* [done] save url history, use it in completions
|
||||||
* [done] autocomplete command name
|
|
||||||
|
|
||||||
* custom rendering for completions (e.g. buffer thumbnails)
|
* custom rendering for completions (e.g. buffer thumbnails)
|
||||||
* less ugly default completions rendering
|
* less ugly default completions rendering
|
||||||
@ -75,6 +74,7 @@ focus from entry to step through the completions then RET activates
|
|||||||
* bind event to echo-area click, ideally dependent on what's being shown
|
* bind event to echo-area click, ideally dependent on what's being shown
|
||||||
in there
|
in there
|
||||||
* in general, can we bind commands to widget events?
|
* in general, can we bind commands to widget events?
|
||||||
|
* autocomplete command name
|
||||||
* command to create new buffer
|
* command to create new buffer
|
||||||
* keyboard navigation of completions
|
* keyboard navigation of completions
|
||||||
|
|
||||||
|
52
search.fnl
52
search.fnl
@ -1,52 +0,0 @@
|
|||||||
(local { : Gtk } (require :lgi))
|
|
||||||
(local { : view } (require :fennel))
|
|
||||||
(local lume (require :lume))
|
|
||||||
|
|
||||||
(local {: define-command : completion } (require :command))
|
|
||||||
(local Buffer (require :buffer))
|
|
||||||
|
|
||||||
(fn url-escape [s]
|
|
||||||
(string.gsub s
|
|
||||||
"([^A-Za-z0-9_])"
|
|
||||||
#(string.format "%%%02x" (string.byte $1))))
|
|
||||||
|
|
||||||
(local searchers
|
|
||||||
{:ddg
|
|
||||||
{:name "Duck Duck Go"
|
|
||||||
:function (fn [term]
|
|
||||||
(.. "https://duckduckgo.com/?q=" (url-escape term)))
|
|
||||||
}
|
|
||||||
:google
|
|
||||||
{:name "Google"
|
|
||||||
:function (fn [term]
|
|
||||||
(.. "https://www.google.com/search?q=" (url-escape term)))
|
|
||||||
}
|
|
||||||
:luai
|
|
||||||
{:name "Lua interactive reference manual"
|
|
||||||
:function (fn [term]
|
|
||||||
(.. "https://pgl.yoyo.org/luai/i/" (url-escape term)))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
(fn completions [term]
|
|
||||||
(icollect [keyword {: name : function} (pairs searchers)]
|
|
||||||
(if (string.match keyword term)
|
|
||||||
(completion {
|
|
||||||
:text keyword
|
|
||||||
:value keyword
|
|
||||||
:widget (Gtk.Button { :label name })
|
|
||||||
}))))
|
|
||||||
|
|
||||||
|
|
||||||
(define-command
|
|
||||||
"search"
|
|
||||||
[[:term
|
|
||||||
#[(completion {:text $1})]
|
|
||||||
#""]
|
|
||||||
[:buffer
|
|
||||||
#(lume.map (Buffer.match $1) #(completion { :text $1.name :value $1 }))
|
|
||||||
#$1.buffer.name]
|
|
||||||
[:engine completions #:ddg]]
|
|
||||||
(fn [{: term : engine : buffer}]
|
|
||||||
(buffer:visit ((. (. searchers engine) :function) term))))
|
|
@ -1,8 +0,0 @@
|
|||||||
(local Buffer (require :buffer))
|
|
||||||
|
|
||||||
(let [_ (Buffer.new "first")
|
|
||||||
_ (Buffer.new "second")
|
|
||||||
_ (Buffer.new "third")
|
|
||||||
_ (Buffer.new "through")
|
|
||||||
_ (Buffer.new "throughput")]
|
|
||||||
(assert (= (# (Buffer.match "")) 5)))
|
|
Loading…
Reference in New Issue
Block a user