commit fd6c540b6faa6c802c92c9e209e2122ca3ddfa92 from: Omar Polo date: Mon Feb 12 15:51:59 2024 UTC add cmd_search to search using a search engine This adds a new command `search', bound by default to `s', that prompts for a query and loads and consult the ``oracle'' (the search engine) using default_search_engine (which will be made customizable.) It also temporarly supports only gemini URLs. Feature requested by -fab-, thanks! commit - 3c56c523c37b8b505cafdd3e5d62d3d72b76ae29 commit + fd6c540b6faa6c802c92c9e209e2122ca3ddfa92 blob - 16927d7f8b2759c895120017509f67f0dd66d505 blob + edc2fb6aa94afa69e4541ababd5321e1966c18f3 --- cmd.c +++ cmd.c @@ -1144,4 +1144,14 @@ cmd_unload_certificate(struct buffer *buffer) yornp("Unload only for the current session?", unload_certificate_cb, current_tab); +} + +void +cmd_search(struct buffer *buffer) +{ + GUARD_RECURSIVE_MINIBUFFER(); + + enter_minibuffer(sensible_self_insert, search_select, exit_minibuffer, NULL, + NULL, NULL, 0); + strlcpy(ministate.prompt, "Search: ", sizeof(ministate.prompt)); } blob - dbc815b0574735727d036b2b60f2e02553d254ba blob + d87f17e9ab329739684235c9be32f2c8f12db25b --- cmd.h +++ cmd.h @@ -74,6 +74,7 @@ CMD(cmd_scroll_down, "Scroll down by one visual page" CMD(cmd_scroll_line_down, "Scroll down by one line"); CMD(cmd_scroll_line_up, "Scroll up by one line."); CMD(cmd_scroll_up, "Scroll up by one visual page"); +CMD(cmd_search, "Search using the preferred search engine"); CMD(cmd_suspend_telescope, "Suspend the current Telescope session."); CMD(cmd_swiper, "Jump to a line using the minibuffer."); CMD(cmd_tab_close, "Close the current tab."); blob - 463a3c12612616a467e7c37ca3de6f45abf7c364 blob + 1f3988f96a0fc2d3b96579dbf4e6b4207f3fc159 --- defaults.c +++ defaults.c @@ -32,6 +32,7 @@ char *default_protocol = NULL; char *download_path = NULL; char *new_tab_url = NULL; +char *default_search_engine = NULL; int autosave = 20; int dont_wrap_pre = 0; @@ -459,6 +460,7 @@ load_default_keys(void) global_set_key("M-/", cmd_swiper); global_set_key("t", cmd_toc); global_set_key("M-r", cmd_reply_last_input); + global_set_key("s", cmd_search); /* === minibuffer map === */ minibuffer_set_key("ret", cmd_mini_complete_and_exit); @@ -504,6 +506,10 @@ config_init(void) { struct line_face *f; size_t i, len; + + default_search_engine = strdup("gemini://geminispace.info/search"); + if (default_search_engine == NULL) + err(1, "strdup"); len = sizeof(line_faces)/sizeof(line_faces[0]); for (i = 0; i < len; ++i) { blob - 2a9d1be7b0c7a7f2c3038fe66a2255b334104d45 blob + 4b9955c4393483c90c51626f32ed09eb2d1a34ad --- defaults.h +++ defaults.h @@ -18,6 +18,7 @@ #define DEFAULTS_H extern char *default_protocol; +extern char *default_search_engine; extern char *download_path; extern char *new_tab_url; blob - 553a43c65186449e2d6c1908d960d8037744cb71 blob + 6be5e852a512982ad158ea11e14c739ba3399cea --- minibuffer.c +++ minibuffer.c @@ -24,6 +24,7 @@ #include "certs.h" #include "cmd.h" +#include "defaults.h" #include "fs.h" #include "hist.h" #include "iri.h" @@ -449,6 +450,21 @@ uc_select(void) yornp("Remember for future sessions too?", save_cert_for_site_cb, current_tab); +} + +void +search_select(void) +{ + static struct iri iri; + static char buf[1025]; + + /* a bit ugly but... */ + iri_parse(NULL, default_search_engine, &iri); + iri_setquery(&iri, minibuffer_compl_text()); + iri_unparse(&iri, buf, sizeof(buf)); + + exit_minibuffer(); + load_url_in_tab(current_tab, buf, NULL, LU_MODE_NOCACHE); } static void blob - 693f6b6e018dab5defaa9c193f993d8496332733 blob + 88d01cf11bf190385a692572ceadad2f6c8eec88 --- minibuffer.h +++ minibuffer.h @@ -85,6 +85,7 @@ void ls_select(void); void swiper_select(void); void toc_select(void); void uc_select(void); +void search_select(void); void enter_minibuffer(void(*)(void), void(*)(void), void(*)(void), struct hist *, complfn *, void *, int); blob - b8b586f7862d1925bf758391117c735a539ebc7c blob + c94f5d082e90fd040a19fc74becfd104c5fbdfd7 --- telescope.1 +++ telescope.1 @@ -11,7 +11,7 @@ .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -.Dd $Mdocdate: February 8 2024$ +.Dd $Mdocdate: February 12 2024$ .Dt TELESCOPE 1 .Os .Sh NAME @@ -707,6 +707,8 @@ link-select swiper .It M-r reply-last-input +.It s +search .El .Ss Minibuffer-specific keys .Bl -tag -width xxxxxxxxxxxx -offset indent -compact @@ -898,6 +900,8 @@ Reload the current page. Reply the last input request. .It Ic root Go to the root directory. +.It Ic search +Search using the preferred search engine. .It Ic scroll-down Scroll down by one visual page. .It Ic scroll-line-down