commit ed504b9e1a0307a13e869cb3296f07ec072dae42 from: Omar Polo date: Mon Feb 07 16:21:11 2022 UTC reply-last-input: reply input requests on demand Telescope now remebers the last URL (per tab!) that replied with 1X (input request.) The new command reply-last-input allows to resend a query to that URL. It's particularly useful with capsules that make a heavy uses of 10 replies (search engines or similar, interactive pages, etc) because it both saves a network roundtrip and the user from looking for the "search" link all across the page ;-) idea from a conversation with thfr@, thanks! commit - 693188cbff678ee0934f5fe5da91365614864888 commit + ed504b9e1a0307a13e869cb3296f07ec072dae42 blob - 1aac903783e44a8036b0c1808fae51a11727d5d9 blob + b5c5d74d817371346a6e8417ac61ba82031627c7 --- cmd.c +++ cmd.c @@ -986,4 +986,18 @@ cmd_cache_info(struct buffer *buffer) message("pages: %zu, total: %s", npages, fmt); else message("pages: %zu, total: %zu", npages, tot); +} + +void +cmd_reply_last_input(struct buffer *buffer) +{ + GUARD_RECURSIVE_MINIBUFFER(); + + if (current_tab->last_input_url == NULL) { + message("there was no previous input request in this tab"); + return; + } + + message("%s", current_tab->last_input_url); + ui_require_input(current_tab, 0, ir_select_reply); } blob - 62dba1eb923cd3ef15581965e9c2db818ab99e8c blob + a4fd3fbd593dc70791e26dc9239884f3769cacbd --- cmd.h +++ cmd.h @@ -57,6 +57,7 @@ CMD(cmd_push_button, "Follow link at point or toggle CMD(cmd_push_button_new_tab, "Follow link at point in a new tab.n"); CMD(cmd_redraw, "Redraw the screen."); CMD(cmd_reload_page, "Reload the current page."); +CMD(cmd_reply_last_input, "Reply last input request."); 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."); blob - 047685c6e6d886f1213c4dae7d9a21764232ae15 blob + c4e4304a0600bfe0a8cf9f7acc9bd453ada08787 --- defaults.c +++ defaults.c @@ -450,6 +450,7 @@ load_default_keys(void) global_set_key("M-l", cmd_link_select); global_set_key("M-/", cmd_swiper); global_set_key("t", cmd_toc); + global_set_key("M-r", cmd_reply_last_input); /* === minibuffer map === */ minibuffer_set_key("ret", cmd_mini_complete_and_exit); blob - ce5a8b929512ff8d10fd521ba878f014fed97ef9 blob + 6f2e28cb6d6926f95e7b914d57a2dc0fab120741 --- minibuffer.c +++ minibuffer.c @@ -230,6 +230,24 @@ ir_select_gemini(void) /* a bit ugly but... */ memcpy(&uri, &tab->uri, sizeof(tab->uri)); + phos_uri_set_query(&uri, ministate.buf); + phos_serialize_uri(&uri, buf, sizeof(buf)); + load_url_in_tab(tab, buf, NULL, LU_MODE_NOCACHE); +} + +void +ir_select_reply(void) +{ + char buf[1025] = {0}; + struct phos_uri uri; + struct tab *tab = current_tab; + + exit_minibuffer(); + minibuffer_hist_save_entry(); + + /* a bit ugly but... */ + strlcpy(buf, tab->last_input_url, sizeof(buf)); + phos_parse_absolute_uri(buf, &uri); phos_uri_set_query(&uri, ministate.buf); phos_serialize_uri(&uri, buf, sizeof(buf)); load_url_in_tab(tab, buf, NULL, LU_MODE_NOCACHE); blob - 4388609c5677976c7328ef4a22e25c32e4e72c1f blob + 70795ac34c8058672ee0a2487c150076873f97b8 --- minibuffer.h +++ minibuffer.h @@ -75,6 +75,7 @@ void minibuffer_self_insert(void); void sensible_self_insert(void); void eecmd_select(void); void ir_select_gemini(void); +void ir_select_reply(void); void ir_select_gopher(void); void lu_select(void); void bp_select(void); blob - 473b28c04befb9e50c13079a38f6d0453493302c blob + 675bf515111430b8cf3f85838b48c092a0bafe3e --- telescope.c +++ telescope.c @@ -400,6 +400,11 @@ handle_imsg_got_meta(struct imsg *imsg, size_t datalen if (tab->code < 10) { /* internal errors */ load_page_from_str(tab, err_pages[tab->code]); } else if (tab->code < 20) { /* 1x */ + free(tab->last_input_url); + tab->last_input_url = strdup(tab->hist_cur->h); + if (tab->last_input_url == NULL) + die(); + load_page_from_str(tab, err_pages[tab->code]); ui_require_input(tab, tab->code == 11, ir_select_gemini); } else if (tab->code == 20) { blob - 06a9bd417000d3c81facb3e263499c6baefaa976 blob + 21778771969b58af00d8f60052518efdf7759955 --- telescope.h +++ telescope.h @@ -232,6 +232,7 @@ struct tab { struct histhead hist; struct hist *hist_cur; size_t hist_off; + char *last_input_url; int code; char meta[GEMINI_URL_LEN];