From d831ccbb67e0deb049bb5f48b811529d98b71d51 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Wed, 9 Mar 2022 23:30:23 +0000 Subject: [PATCH] add DWIMminess to url bar text entry - prepend https:// to things that might be partial URLs - perform searches for things that are not URLs (e.g. contain spaces) - use different search engines for things that start with @foo e.g. @ebay, @ddg, @lua --- just/just.fnl | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/just/just.fnl b/just/just.fnl index cadccaa..4d7241f 100644 --- a/just/just.fnl +++ b/just/just.fnl @@ -40,6 +40,30 @@ progress, trough { name (or size Gtk.IconSize.LARGE_TOOLBAR))) +(fn urlencode [url] + (-> url + (: :gsub "([^%w ])" (fn [c] (string.format "%%%02X" (string.byte c)))) + (: :gsub " " "+"))) + +(print (urlencode "hello world o'hare & feirneds")) + +(local default-search-provider "ddg") + +(fn search-term-to-uri [provider text] + (match provider + "ebay" (.. "https://www.ebay.co.uk/sch/i.html?_nkw=" (urlencode text)) + "lua" (.. "https://pgl.yoyo.org/luai/i/" (urlencode text)) + "ddg" (.. "https://duckduckgo.com/?q=" (urlencode text)))) + +(fn to-uri [text] + (if (text:find " ") + (let [(_ _ provider term) (text:find "^@(%g+) *(.*)")] + (if provider + (search-term-to-uri provider term) + (search-term-to-uri default-search-provider text))) + (text:find "^http") text + (.. "https://" text))) + (local Navbar { @@ -48,7 +72,7 @@ progress, trough { (let [url (Gtk.Entry { ;; :completion (Gtk.EntryCompletion {:model completions :text_column 0 }) :on_activate - #(webview:visit $1.text) + #(webview:visit (to-uri $1.text)) }) stop (doto (Gtk.Button { :on_clicked #(webview:stop-loading)