2 a36bb43a 2024-01-15 op * Copyright (c) 2021, 2024 Omar Polo <op@omarpolo.com>
4 2b2d2872 2021-06-20 op * Permission to use, copy, modify, and distribute this software for any
5 2b2d2872 2021-06-20 op * purpose with or without fee is hereby granted, provided that the above
6 2b2d2872 2021-06-20 op * copyright notice and this permission notice appear in all copies.
8 2b2d2872 2021-06-20 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 2b2d2872 2021-06-20 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 2b2d2872 2021-06-20 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 2b2d2872 2021-06-20 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 2b2d2872 2021-06-20 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 2b2d2872 2021-06-20 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 2b2d2872 2021-06-20 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 786e6deb 2021-07-21 op #include "compat.h"
19 61251035 2021-06-26 op #include <limits.h>
20 2b2d2872 2021-06-20 op #include <stdlib.h>
21 61251035 2021-06-26 op #include <string.h>
23 4fdc9933 2024-02-05 op #include "certs.h"
24 d252d87c 2024-02-05 op #include "cmd.h"
25 b1e1e41a 2021-07-14 op #include "compl.h"
26 e5a2797f 2021-07-13 op #include "defaults.h"
27 65c49665 2024-01-23 op #include "hist.h"
28 f7db6d13 2024-02-06 op #include "keymap.h"
29 eeebca22 2022-01-11 op #include "mcache.h"
30 450a89f7 2021-07-12 op #include "minibuffer.h"
31 1fce2e75 2021-08-14 op #include "session.h"
32 2b2d2872 2021-06-20 op #include "telescope.h"
33 d1a0f2a3 2021-07-12 op #include "ui.h"
34 5caf7d67 2021-07-12 op #include "utf8.h"
35 c8c572e4 2022-02-08 op #include "utils.h"
37 ca231710 2021-07-15 op #define GUARD_RECURSIVE_MINIBUFFER() \
39 ca231710 2021-07-15 op if (in_minibuffer) { \
40 ca231710 2021-07-15 op message("enable-recursive-minibuffers " \
41 ca231710 2021-07-15 op "is not yet available."); \
46 5a3c3ede 2021-07-19 op #define GUARD_READ_ONLY() \
48 5a3c3ede 2021-07-19 op if (!in_minibuffer) { \
49 5a3c3ede 2021-07-19 op message("text is read-only"); \
54 c4c82003 2021-07-01 op /* return 1 if moved, 0 otherwise */
55 c4c82003 2021-07-01 op static inline int
56 c4c82003 2021-07-01 op forward_line(struct buffer *buffer, int n)
58 c4c82003 2021-07-01 op struct vline *vl;
61 c4c82003 2021-07-01 op if (buffer->current_line == NULL)
63 963c680c 2021-07-05 op vl = buffer->current_line;
66 c4c82003 2021-07-01 op while (n != 0) {
68 963c680c 2021-07-05 op vl = TAILQ_NEXT(vl, vlines);
69 c4c82003 2021-07-01 op if (vl == NULL)
71 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
73 c4c82003 2021-07-01 op buffer->current_line = vl;
76 963c680c 2021-07-05 op vl = TAILQ_PREV(vl, vhead, vlines);
77 c4c82003 2021-07-01 op if (vl == NULL)
79 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
81 6e6c6afb 2021-07-14 op if (buffer->current_line == buffer->top_line) {
82 6e6c6afb 2021-07-14 op buffer->line_off--;
83 c4c82003 2021-07-01 op buffer->top_line = vl;
85 c4c82003 2021-07-01 op buffer->current_line = vl;
96 c4c82003 2021-07-01 op cmd_previous_line(struct buffer *buffer)
98 c4c82003 2021-07-01 op forward_line(buffer, -1);
102 c4c82003 2021-07-01 op cmd_next_line(struct buffer *buffer)
104 c4c82003 2021-07-01 op forward_line(buffer, +1);
108 2b2d2872 2021-06-20 op cmd_backward_char(struct buffer *buffer)
110 2b2d2872 2021-06-20 op if (buffer->cpoff != 0)
111 2b2d2872 2021-06-20 op buffer->cpoff--;
115 2b2d2872 2021-06-20 op cmd_forward_char(struct buffer *buffer)
117 aed6fae9 2021-07-19 op if (buffer->current_line == NULL)
119 bd4a08a7 2022-11-07 op if (buffer->current_line->cplen > buffer->cpoff)
120 bd4a08a7 2022-11-07 op buffer->cpoff++;
124 2b2d2872 2021-06-20 op cmd_backward_paragraph(struct buffer *buffer)
127 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
128 2b2d2872 2021-06-20 op message("No previous paragraph");
131 bd4a08a7 2022-11-07 op } while (buffer->current_line->len != 0 ||
132 2b2d2872 2021-06-20 op buffer->current_line->parent->type != LINE_TEXT);
136 2b2d2872 2021-06-20 op cmd_forward_paragraph(struct buffer *buffer)
139 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)) {
140 2b2d2872 2021-06-20 op message("No next paragraph");
143 bd4a08a7 2022-11-07 op } while (buffer->current_line->len != 0 ||
144 2b2d2872 2021-06-20 op buffer->current_line->parent->type != LINE_TEXT);
148 2b2d2872 2021-06-20 op cmd_move_beginning_of_line(struct buffer *buffer)
150 2b2d2872 2021-06-20 op buffer->cpoff = 0;
154 2b2d2872 2021-06-20 op cmd_move_end_of_line(struct buffer *buffer)
156 2b2d2872 2021-06-20 op struct vline *vl;
158 2b2d2872 2021-06-20 op vl = buffer->current_line;
159 bd4a08a7 2022-11-07 op if (vl == NULL)
161 bd4a08a7 2022-11-07 op buffer->cpoff = vl->cplen;
165 2b2d2872 2021-06-20 op cmd_redraw(struct buffer *buffer)
167 95a8c791 2021-08-26 op ui_schedule_redraw();
171 2b2d2872 2021-06-20 op cmd_scroll_line_up(struct buffer *buffer)
173 e39920a9 2021-07-07 op struct vline *vl;
176 028fff57 2021-07-30 op if (buffer->top_line == NULL)
179 028fff57 2021-07-30 op if ((vl = TAILQ_PREV(buffer->top_line, vhead, vlines))
183 028fff57 2021-07-30 op buffer->top_line = vl;
185 028fff57 2021-07-30 op if (vl->parent->flags & L_HIDDEN)
191 41b1ed04 2021-07-21 op buffer->line_off--;
193 028fff57 2021-07-30 op forward_line(buffer, -1);
197 2b2d2872 2021-06-20 op cmd_scroll_line_down(struct buffer *buffer)
199 c4c82003 2021-07-01 op if (!forward_line(buffer, +1))
203 028fff57 2021-07-30 op if (buffer->top_line == NULL)
206 028fff57 2021-07-30 op buffer->top_line = TAILQ_NEXT(buffer->top_line, vlines);
207 028fff57 2021-07-30 op if (buffer->top_line->parent->flags & L_HIDDEN)
212 2b2d2872 2021-06-20 op buffer->line_off++;
216 2b2d2872 2021-06-20 op cmd_scroll_up(struct buffer *buffer)
218 64923c4b 2021-07-15 op struct vline *vl;
221 b471d670 2021-07-24 op if (buffer->top_line == NULL)
224 64923c4b 2021-07-15 op for (i = 0; i < body_lines; ++i) {
225 64923c4b 2021-07-15 op vl = TAILQ_PREV(buffer->top_line, vhead, vlines);
226 64923c4b 2021-07-15 op if (vl == NULL)
228 eab11449 2021-07-19 op buffer->line_off--;
229 64923c4b 2021-07-15 op buffer->top_line = vl;
230 64923c4b 2021-07-15 op forward_line(buffer, -1);
235 2b2d2872 2021-06-20 op cmd_scroll_down(struct buffer *buffer)
239 b471d670 2021-07-24 op if (buffer->top_line == NULL)
242 64923c4b 2021-07-15 op for (i = 0; i < body_lines; ++i) {
243 64923c4b 2021-07-15 op if (!forward_line(buffer, +1))
246 64923c4b 2021-07-15 op buffer->top_line = TAILQ_NEXT(buffer->top_line,
248 eab11449 2021-07-19 op buffer->line_off++;
253 2b2d2872 2021-06-20 op cmd_beginning_of_buffer(struct buffer *buffer)
255 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_FIRST(&buffer->head);
256 c4c82003 2021-07-01 op buffer->cpoff = 0;
257 94ec38e8 2021-06-29 op buffer->top_line = buffer->current_line;
258 2b2d2872 2021-06-20 op buffer->line_off = 0;
262 2b2d2872 2021-06-20 op cmd_end_of_buffer(struct buffer *buffer)
264 2b2d2872 2021-06-20 op buffer->current_line = TAILQ_LAST(&buffer->head, vhead);
266 52b1043c 2021-07-19 op if (buffer->current_line == NULL)
269 f04d2fc5 2021-07-18 op /* deal with invisible lines */
270 f04d2fc5 2021-07-18 op if (buffer->current_line->parent->flags & L_HIDDEN)
271 f04d2fc5 2021-07-18 op forward_line(buffer, -1);
273 f04d2fc5 2021-07-18 op cmd_move_end_of_line(buffer);
277 5b3e45c1 2021-01-02 op kill_telescope_cb(int r, struct tab *tab)
280 5b3e45c1 2021-01-02 op save_session();
281 5b3e45c1 2021-01-02 op event_loopbreak();
286 2b2d2872 2021-06-20 op cmd_kill_telescope(struct buffer *buffer)
288 5b3e45c1 2021-01-02 op yornp("really quit?", kill_telescope_cb, NULL);
292 2b2d2872 2021-06-20 op cmd_push_button(struct buffer *buffer)
294 2b2d2872 2021-06-20 op struct vline *vl;
295 963c680c 2021-07-05 op struct line *l;
297 2b2d2872 2021-06-20 op vl = buffer->current_line;
299 a87cfde9 2021-07-19 op if (vl == NULL)
302 963c680c 2021-07-05 op switch (vl->parent->type) {
303 963c680c 2021-07-05 op case LINE_LINK:
304 ed21a9a1 2022-01-11 op load_url_in_tab(current_tab, vl->parent->alt, NULL,
305 ed21a9a1 2022-01-11 op LU_MODE_NOCACHE);
307 963c680c 2021-07-05 op case LINE_PRE_START:
308 963c680c 2021-07-05 op l = TAILQ_NEXT(vl->parent, lines);
309 963c680c 2021-07-05 op for (; l != NULL; l = TAILQ_NEXT(l, lines)) {
310 963c680c 2021-07-05 op if (l->type == LINE_PRE_END)
312 963c680c 2021-07-05 op l->flags ^= L_HIDDEN;
313 6e6c6afb 2021-07-14 op if (l->flags & L_HIDDEN)
314 6e6c6afb 2021-07-14 op buffer->line_max--;
316 6e6c6afb 2021-07-14 op buffer->line_max++;
325 2b2d2872 2021-06-20 op cmd_push_button_new_tab(struct buffer *buffer)
327 2b2d2872 2021-06-20 op struct vline *vl;
329 2b2d2872 2021-06-20 op vl = buffer->current_line;
330 a87cfde9 2021-07-19 op if (vl == NULL || vl->parent->type != LINE_LINK)
333 65c49665 2024-01-23 op new_tab(vl->parent->alt, hist_cur(current_tab->hist), current_tab);
337 2b2d2872 2021-06-20 op cmd_previous_button(struct buffer *buffer)
339 5d0feb4b 2021-06-23 op struct excursion place;
341 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
344 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
345 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
346 2b2d2872 2021-06-20 op message("No previous link");
349 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
353 2b2d2872 2021-06-20 op cmd_next_button(struct buffer *buffer)
355 5d0feb4b 2021-06-23 op struct excursion place;
357 5d0feb4b 2021-06-23 op save_excursion(&place, buffer);
360 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)){
361 5d0feb4b 2021-06-23 op restore_excursion(&place, buffer);
362 2b2d2872 2021-06-20 op message("No next link");
365 2b2d2872 2021-06-20 op } while (buffer->current_line->parent->type != LINE_LINK);
368 1c412d48 2021-06-25 op static inline int
369 1c412d48 2021-06-25 op is_heading(const struct line *l)
371 1c412d48 2021-06-25 op return l->type == LINE_TITLE_1 ||
372 1c412d48 2021-06-25 op l->type == LINE_TITLE_2 ||
373 1c412d48 2021-06-25 op l->type == LINE_TITLE_3;
377 1c412d48 2021-06-25 op cmd_previous_heading(struct buffer *buffer)
379 1c412d48 2021-06-25 op struct excursion place;
381 1c412d48 2021-06-25 op save_excursion(&place, buffer);
384 c4c82003 2021-07-01 op if (!forward_line(buffer, -1)) {
385 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
386 1c412d48 2021-06-25 op message("No previous heading");
389 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
393 1c412d48 2021-06-25 op cmd_next_heading(struct buffer *buffer)
395 1c412d48 2021-06-25 op struct excursion place;
397 1c412d48 2021-06-25 op save_excursion(&place, buffer);
400 c4c82003 2021-07-01 op if (!forward_line(buffer, +1)) {
401 1c412d48 2021-06-25 op restore_excursion(&place, buffer);
402 1c412d48 2021-06-25 op message("No next heading");
405 1c412d48 2021-06-25 op } while (!is_heading(buffer->current_line->parent));
409 2b2d2872 2021-06-20 op cmd_previous_page(struct buffer *buffer)
411 83dce83d 2021-07-17 op if (!load_previous_page(current_tab))
412 2b2d2872 2021-06-20 op message("No previous page");
416 2b2d2872 2021-06-20 op cmd_next_page(struct buffer *buffer)
418 83dce83d 2021-07-17 op if (!load_next_page(current_tab))
419 2b2d2872 2021-06-20 op message("No next page");
423 2b2d2872 2021-06-20 op cmd_clear_minibuf(struct buffer *buffer)
425 95a8c791 2021-08-26 op message(NULL);
429 2b2d2872 2021-06-20 op cmd_execute_extended_command(struct buffer *buffer)
433 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
435 004fe817 2021-07-24 op enter_minibuffer(sensible_self_insert, eecmd_select, exit_minibuffer,
436 65c49665 2024-01-23 op eecmd_history, compl_eecmd, NULL, 1);
438 2b2d2872 2021-06-20 op len = sizeof(ministate.prompt);
439 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "", len);
441 2b2d2872 2021-06-20 op if (thiskey.meta)
442 2b2d2872 2021-06-20 op strlcat(ministate.prompt, "M-", len);
444 2b2d2872 2021-06-20 op strlcat(ministate.prompt, ui_keyname(thiskey.key), len);
446 2b2d2872 2021-06-20 op if (thiskey.meta)
447 2b2d2872 2021-06-20 op strlcat(ministate.prompt, " ", len);
451 2b2d2872 2021-06-20 op cmd_tab_close(struct buffer *buffer)
453 2b2d2872 2021-06-20 op struct tab *tab, *t;
455 83dce83d 2021-07-17 op tab = current_tab;
457 90730426 2021-07-21 op if ((t = TAILQ_NEXT(tab, tabs)) != NULL ||
458 90730426 2021-07-21 op (t = TAILQ_PREV(tab, tabshead, tabs)) != NULL) {
459 90730426 2021-07-21 op switch_to_tab(t);
460 05de8ac3 2022-01-06 op kill_tab(tab, 0);
462 90730426 2021-07-21 op message("Can't close the only tab.");
467 2b2d2872 2021-06-20 op cmd_tab_close_other(struct buffer *buffer)
469 2b2d2872 2021-06-20 op struct tab *t, *i;
471 2b2d2872 2021-06-20 op TAILQ_FOREACH_SAFE(t, &tabshead, tabs, i) {
472 83dce83d 2021-07-17 op if (t == current_tab)
475 05de8ac3 2022-01-06 op kill_tab(t, 0);
480 6c74799d 2022-01-05 op cmd_tab_undo_close(struct buffer *buffer)
482 6c74799d 2022-01-05 op struct tab *t;
484 6c74799d 2022-01-05 op if ((t = unkill_tab()) == NULL) {
485 6c74799d 2022-01-05 op message("No recently-closed tabs");
489 6c74799d 2022-01-05 op switch_to_tab(t);
493 2b2d2872 2021-06-20 op cmd_tab_new(struct buffer *buffer)
495 2b2d2872 2021-06-20 op const char *url;
497 2b2d2872 2021-06-20 op if ((url = new_tab_url) == NULL)
498 2b2d2872 2021-06-20 op url = NEW_TAB_URL;
500 55eb4d95 2021-08-12 op new_tab(url, NULL, NULL);
504 2b2d2872 2021-06-20 op cmd_tab_next(struct buffer *buffer)
506 83dce83d 2021-07-17 op struct tab *t;
508 83dce83d 2021-07-17 op if ((t = TAILQ_NEXT(current_tab, tabs)) == NULL)
509 2b2d2872 2021-06-20 op t = TAILQ_FIRST(&tabshead);
510 2ddbda6b 2021-07-17 op switch_to_tab(t);
514 2b2d2872 2021-06-20 op cmd_tab_previous(struct buffer *buffer)
516 83dce83d 2021-07-17 op struct tab *t;
518 83dce83d 2021-07-17 op if ((t = TAILQ_PREV(current_tab, tabshead, tabs)) == NULL)
519 2b2d2872 2021-06-20 op t = TAILQ_LAST(&tabshead, tabshead);
520 2ddbda6b 2021-07-17 op switch_to_tab(t);
524 2b2d2872 2021-06-20 op cmd_tab_move(struct buffer *buffer)
526 83dce83d 2021-07-17 op struct tab *t;
528 83dce83d 2021-07-17 op t = TAILQ_NEXT(current_tab, tabs);
529 83dce83d 2021-07-17 op TAILQ_REMOVE(&tabshead, current_tab, tabs);
531 2b2d2872 2021-06-20 op if (t == NULL)
532 83dce83d 2021-07-17 op TAILQ_INSERT_HEAD(&tabshead, current_tab, tabs);
534 83dce83d 2021-07-17 op TAILQ_INSERT_AFTER(&tabshead, t, current_tab, tabs);
538 2b2d2872 2021-06-20 op cmd_tab_move_to(struct buffer *buffer)
540 83dce83d 2021-07-17 op struct tab *t;
542 83dce83d 2021-07-17 op t = TAILQ_PREV(current_tab, tabshead, tabs);
543 83dce83d 2021-07-17 op TAILQ_REMOVE(&tabshead, current_tab, tabs);
545 32ac17a4 2021-08-12 op if (t == NULL)
546 32ac17a4 2021-08-12 op TAILQ_INSERT_TAIL(&tabshead, current_tab, tabs);
548 83dce83d 2021-07-17 op TAILQ_INSERT_BEFORE(t, current_tab, tabs);
552 65601367 2021-07-14 op cmd_tab_select(struct buffer *buffer)
554 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
556 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, ts_select, exit_minibuffer,
557 27dbcaab 2022-04-13 op NULL, compl_ts, NULL, 1);
558 65601367 2021-07-14 op strlcpy(ministate.prompt, "Select tab: ", sizeof(ministate.prompt));
562 2b2d2872 2021-06-20 op cmd_load_url(struct buffer *buffer)
564 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
566 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, lu_select, exit_minibuffer,
567 65c49665 2024-01-23 op lu_history, compl_lu, NULL, 0);
568 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
572 2b2d2872 2021-06-20 op cmd_load_current_url(struct buffer *buffer)
574 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
576 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, lu_select, exit_minibuffer,
577 65c49665 2024-01-23 op lu_history, compl_lu, NULL, 0);
578 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
579 65c49665 2024-01-23 op strlcpy(ministate.buf, hist_cur(current_tab->hist), sizeof(ministate.buf));
580 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
584 661233ed 2021-07-14 op cmd_reload_page(struct buffer *buffer)
586 65c49665 2024-01-23 op load_url_in_tab(current_tab, hist_cur(current_tab->hist), NULL,
587 ed21a9a1 2022-01-11 op LU_MODE_NOHIST|LU_MODE_NOCACHE);
591 2b2d2872 2021-06-20 op cmd_bookmark_page(struct buffer *buffer)
593 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
595 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, bp_select, exit_minibuffer, NULL,
596 27dbcaab 2022-04-13 op NULL, NULL, 0);
597 2b2d2872 2021-06-20 op strlcpy(ministate.prompt, "Bookmark URL: ", sizeof(ministate.prompt));
598 65c49665 2024-01-23 op strlcpy(ministate.buf, hist_cur(current_tab->hist),
599 65c49665 2024-01-23 op sizeof(ministate.buf));
600 2b2d2872 2021-06-20 op ministate.buffer.cpoff = utf8_cplen(ministate.buf);
604 2b2d2872 2021-06-20 op cmd_list_bookmarks(struct buffer *buffer)
606 ed21a9a1 2022-01-11 op load_url_in_tab(current_tab, "about:bookmarks", NULL, LU_MODE_NONE);
610 2b2d2872 2021-06-20 op cmd_toggle_help(struct buffer *buffer)
612 3b5f459e 2021-11-05 op ui_toggle_side_window(SIDE_WINDOW_LEFT);
616 753c6ac7 2021-07-14 op cmd_link_select(struct buffer *buffer)
618 c1a72389 2021-07-15 op struct line *l;
620 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
622 c1a72389 2021-07-15 op l = TAILQ_FIRST(&buffer->page.head);
623 c1a72389 2021-07-15 op while (l != NULL && l->type != LINE_LINK)
624 c1a72389 2021-07-15 op l = TAILQ_NEXT(l, lines);
626 c1a72389 2021-07-15 op if (l == NULL) {
627 c1a72389 2021-07-15 op message("No links found");
631 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, ls_select, exit_minibuffer,
632 27dbcaab 2022-04-13 op NULL, compl_ls, l, 1);
633 753c6ac7 2021-07-14 op strlcpy(ministate.prompt, "Select link: ", sizeof(ministate.prompt));
637 753c6ac7 2021-07-14 op cmd_swiper(struct buffer *buffer)
639 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
641 40fbc354 2021-07-14 op enter_minibuffer(sensible_self_insert, swiper_select, exit_minibuffer,
642 27dbcaab 2022-04-13 op NULL, compl_swiper, TAILQ_FIRST(&buffer->page.head), 1);
643 753c6ac7 2021-07-14 op strlcpy(ministate.prompt, "Select line: ", sizeof(ministate.prompt));
647 edd9a650 2021-07-15 op cmd_toc(struct buffer *buffer)
649 c1a72389 2021-07-15 op struct line *l;
651 ca231710 2021-07-15 op GUARD_RECURSIVE_MINIBUFFER();
653 c1a72389 2021-07-15 op l = TAILQ_FIRST(&buffer->page.head);
654 c1a72389 2021-07-15 op while (l != NULL &&
655 c1a72389 2021-07-15 op l->type != LINE_TITLE_1 &&
656 c1a72389 2021-07-15 op l->type != LINE_TITLE_2 &&
657 c1a72389 2021-07-15 op l->type != LINE_TITLE_3)
658 c1a72389 2021-07-15 op l = TAILQ_NEXT(l, lines);
660 c1a72389 2021-07-15 op if (l == NULL) {
661 c1a72389 2021-07-15 op message("No headings found");
665 edd9a650 2021-07-15 op enter_minibuffer(sensible_self_insert, toc_select, exit_minibuffer,
666 27dbcaab 2022-04-13 op NULL, compl_toc, l, 1);
667 edd9a650 2021-07-15 op strlcpy(ministate.prompt, "Select heading: ",
668 edd9a650 2021-07-15 op sizeof(ministate.prompt));
672 61251035 2021-06-26 op cmd_inc_fill_column(struct buffer *buffer)
674 61251035 2021-06-26 op if (fill_column == INT_MAX)
677 61251035 2021-06-26 op fill_column += 2;
678 61251035 2021-06-26 op message("fill-column: %d", fill_column);
680 61251035 2021-06-26 op ui_schedule_redraw();
684 61251035 2021-06-26 op cmd_dec_fill_column(struct buffer *buffer)
686 61251035 2021-06-26 op if (fill_column == INT_MAX || fill_column < 8)
689 61251035 2021-06-26 op fill_column -= 2;
690 61251035 2021-06-26 op message("fill-column: %d", fill_column);
692 61251035 2021-06-26 op ui_schedule_redraw();
696 2b2d2872 2021-06-20 op cmd_olivetti_mode(struct buffer *buffer)
698 2b2d2872 2021-06-20 op olivetti_mode = !olivetti_mode;
699 2b2d2872 2021-06-20 op if (olivetti_mode)
700 2b2d2872 2021-06-20 op message("olivetti-mode enabled");
702 2b2d2872 2021-06-20 op message("olivetti-mode disabled");
704 2b2d2872 2021-06-20 op ui_schedule_redraw();
708 2b2d2872 2021-06-20 op cmd_mini_delete_char(struct buffer *buffer)
710 bd4a08a7 2022-11-07 op char *line, *c, *n;
712 5a3c3ede 2021-07-19 op GUARD_READ_ONLY();
714 2b2d2872 2021-06-20 op minibuffer_taint_hist();
716 bd4a08a7 2022-11-07 op line = buffer->current_line->parent->line + buffer->current_line->from;
717 bd4a08a7 2022-11-07 op c = utf8_nth(line, buffer->cpoff);
718 2b2d2872 2021-06-20 op if (*c == '\0')
720 2b2d2872 2021-06-20 op n = utf8_next_cp(c);
722 2b2d2872 2021-06-20 op memmove(c, n, strlen(n)+1);
724 b1e1e41a 2021-07-14 op recompute_completions(0);
728 2b2d2872 2021-06-20 op cmd_mini_delete_backward_char(struct buffer *buffer)
730 bd4a08a7 2022-11-07 op char *line, *c, *p;
732 5a3c3ede 2021-07-19 op GUARD_READ_ONLY();
734 2b2d2872 2021-06-20 op minibuffer_taint_hist();
736 bd4a08a7 2022-11-07 op line = buffer->current_line->parent->line + buffer->current_line->from;
737 bd4a08a7 2022-11-07 op c = utf8_nth(line, buffer->cpoff);
738 bd4a08a7 2022-11-07 op if (c == line)
740 bd4a08a7 2022-11-07 op p = utf8_prev_cp(c-1, line);
742 2b2d2872 2021-06-20 op memmove(p, c, strlen(c)+1);
743 2b2d2872 2021-06-20 op buffer->cpoff--;
745 b1e1e41a 2021-07-14 op recompute_completions(0);
749 2b2d2872 2021-06-20 op cmd_mini_kill_line(struct buffer *buffer)
751 bd4a08a7 2022-11-07 op char *line, *c;
753 5a3c3ede 2021-07-19 op GUARD_READ_ONLY();
755 2b2d2872 2021-06-20 op minibuffer_taint_hist();
757 bd4a08a7 2022-11-07 op line = buffer->current_line->parent->line + buffer->current_line->from;
758 bd4a08a7 2022-11-07 op c = utf8_nth(line, buffer->cpoff);
761 b1e1e41a 2021-07-14 op recompute_completions(0);
765 067b7ffd 2022-04-15 op cmd_mini_kill_whole_line(struct buffer *buffer)
767 067b7ffd 2022-04-15 op GUARD_READ_ONLY();
769 067b7ffd 2022-04-15 op minibuffer_taint_hist();
770 bd4a08a7 2022-11-07 op *buffer->current_line->parent->line = '\0';
771 067b7ffd 2022-04-15 op buffer->cpoff = 0;
775 2b2d2872 2021-06-20 op cmd_mini_abort(struct buffer *buffer)
777 2b2d2872 2021-06-20 op if (!in_minibuffer)
780 2b2d2872 2021-06-20 op ministate.abortfn();
784 2b2d2872 2021-06-20 op cmd_mini_complete_and_exit(struct buffer *buffer)
786 27dbcaab 2022-04-13 op struct vline *vl;
788 2b2d2872 2021-06-20 op if (!in_minibuffer)
791 65c49665 2024-01-23 op if (ministate.compl.must_select && ministate.hist == NULL) {
792 27dbcaab 2022-04-13 op vl = ministate.compl.buffer.current_line;
793 27dbcaab 2022-04-13 op if (vl == NULL || vl->parent->flags & L_HIDDEN ||
794 27dbcaab 2022-04-13 op vl->parent->type == LINE_COMPL) {
795 27dbcaab 2022-04-13 op message("no match");
800 2b2d2872 2021-06-20 op minibuffer_taint_hist();
801 2b2d2872 2021-06-20 op ministate.donefn();
805 2b2d2872 2021-06-20 op cmd_mini_previous_history_element(struct buffer *buffer)
809 65c49665 2024-01-23 op if (ministate.hist == NULL) {
810 2b2d2872 2021-06-20 op message("No history");
814 65c49665 2024-01-23 op if (hist_prev(ministate.hist) == NULL) {
815 65c49665 2024-01-23 op message("No prev history item");
819 65c49665 2024-01-23 op ministate.editing = 0;
821 65c49665 2024-01-23 op /* XXX the minibuffer line is never modified so this is fine */
822 65c49665 2024-01-23 op text = (char *)hist_cur(ministate.hist);
823 65c49665 2024-01-23 op buffer->current_line->parent->line = text;
824 65c49665 2024-01-23 op recompute_completions(0);
828 2b2d2872 2021-06-20 op cmd_mini_next_history_element(struct buffer *buffer)
832 65c49665 2024-01-23 op if (ministate.hist == NULL) {
833 2b2d2872 2021-06-20 op message("No history");
837 65c49665 2024-01-23 op if (hist_next(ministate.hist) == NULL) {
838 65c49665 2024-01-23 op message("No next history item");
842 65c49665 2024-01-23 op ministate.editing = 0;
844 65c49665 2024-01-23 op /* XXX the minibuffer line is never modified so this is fine */
845 65c49665 2024-01-23 op text = (char *)hist_cur(ministate.hist);
846 65c49665 2024-01-23 op buffer->current_line->parent->line = text;
847 65c49665 2024-01-23 op recompute_completions(0);
851 e7b982f4 2021-07-14 op cmd_previous_completion(struct buffer *buffer)
853 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
856 e7b982f4 2021-07-14 op buffer = &ministate.compl.buffer;
857 fea02b0b 2022-04-13 op if (buffer->current_line == NULL)
860 fea02b0b 2022-04-13 op buffer->current_line->parent->type = LINE_COMPL;
861 fea02b0b 2022-04-13 op if (!forward_line(buffer, -1))
862 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL;
864 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL_CURRENT;
868 e7b982f4 2021-07-14 op cmd_next_completion(struct buffer *buffer)
870 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
873 e7b982f4 2021-07-14 op buffer = &ministate.compl.buffer;
874 fea02b0b 2022-04-13 op if (buffer->current_line == NULL)
877 fea02b0b 2022-04-13 op if (buffer->current_line->parent->type == LINE_COMPL_CURRENT) {
878 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL;
879 fea02b0b 2022-04-13 op forward_line(buffer, +1);
882 e7b982f4 2021-07-14 op if (buffer->current_line != NULL)
883 e7b982f4 2021-07-14 op buffer->current_line->parent->type = LINE_COMPL_CURRENT;
887 e7b982f4 2021-07-14 op cmd_insert_current_candidate(struct buffer *buffer)
889 e7b982f4 2021-07-14 op if (in_minibuffer != MB_COMPREAD)
892 16578ca5 2021-01-02 op minibuffer_insert_current_candidate();
896 8a3b5609 2021-07-15 op cmd_suspend_telescope(struct buffer *buffer)
898 8a3b5609 2021-07-15 op message("Zzz...");
899 8a3b5609 2021-07-15 op ui_suspend();
903 987d9c88 2021-07-15 op cmd_toggle_pre_wrap(struct buffer *buffer)
905 987d9c88 2021-07-15 op dont_wrap_pre = !dont_wrap_pre;
907 987d9c88 2021-07-15 op if (dont_wrap_pre)
908 987d9c88 2021-07-15 op message("Don't wrap preformatted blocks");
910 987d9c88 2021-07-15 op message("Wrap preformatted blocks");
912 987d9c88 2021-07-15 op ui_schedule_redraw();
916 de190a2b 2021-07-17 op cmd_mini_goto_beginning(struct buffer *buffer)
918 de190a2b 2021-07-17 op struct vline *vl;
920 de190a2b 2021-07-17 op if (!in_minibuffer)
923 de190a2b 2021-07-17 op buffer = &ministate.compl.buffer;
925 de190a2b 2021-07-17 op if ((vl = buffer->current_line) != NULL)
926 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL;
928 de190a2b 2021-07-17 op vl = TAILQ_FIRST(&buffer->head);
929 de190a2b 2021-07-17 op while (vl != NULL && vl->parent->flags & L_HIDDEN)
930 de190a2b 2021-07-17 op vl = TAILQ_NEXT(vl, vlines);
932 de190a2b 2021-07-17 op if (vl == NULL)
935 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL_CURRENT;
936 de190a2b 2021-07-17 op buffer->top_line = vl;
937 de190a2b 2021-07-17 op buffer->current_line = vl;
941 de190a2b 2021-07-17 op cmd_mini_goto_end(struct buffer *buffer)
943 de190a2b 2021-07-17 op struct vline *vl;
945 de190a2b 2021-07-17 op if (!in_minibuffer)
948 de190a2b 2021-07-17 op buffer = &ministate.compl.buffer;
950 de190a2b 2021-07-17 op if ((vl = buffer->current_line) != NULL)
951 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL;
953 de190a2b 2021-07-17 op vl = TAILQ_LAST(&buffer->head, vhead);
954 de190a2b 2021-07-17 op while (vl != NULL && vl->parent->flags & L_HIDDEN)
955 de190a2b 2021-07-17 op vl = TAILQ_PREV(vl, vhead, vlines);
957 de190a2b 2021-07-17 op if (vl == NULL)
960 de190a2b 2021-07-17 op vl->parent->type = LINE_COMPL_CURRENT;
961 de190a2b 2021-07-17 op buffer->current_line = vl;
965 65340174 2021-07-21 op cmd_other_window(struct buffer *buffer)
967 65340174 2021-07-21 op ui_other_window();
971 167131d5 2021-07-24 op cmd_mini_scroll_up(struct buffer *buffer)
973 167131d5 2021-07-24 op if (!in_minibuffer)
976 0e2ac864 2021-08-26 op buffer = &ministate.compl.buffer;
977 167131d5 2021-07-24 op if (buffer->current_line == NULL)
980 167131d5 2021-07-24 op buffer->current_line->parent->type = LINE_COMPL;
981 167131d5 2021-07-24 op cmd_scroll_up(buffer);
982 167131d5 2021-07-24 op buffer->current_line->parent->type = LINE_COMPL_CURRENT;
986 167131d5 2021-07-24 op cmd_mini_scroll_down(struct buffer *buffer)
988 167131d5 2021-07-24 op if (!in_minibuffer)
991 0e2ac864 2021-08-26 op buffer = &ministate.compl.buffer;
992 167131d5 2021-07-24 op if (buffer->current_line == NULL)
995 167131d5 2021-07-24 op buffer->current_line->parent->type = LINE_COMPL;
996 167131d5 2021-07-24 op cmd_scroll_down(buffer);
997 167131d5 2021-07-24 op buffer->current_line->parent->type = LINE_COMPL_CURRENT;
1001 3b5f459e 2021-11-05 op cmd_toggle_downloads(struct buffer *buffer)
1003 3b5f459e 2021-11-05 op ui_toggle_side_window(SIDE_WINDOW_BOTTOM);
1007 eeebca22 2022-01-11 op cmd_cache_info(struct buffer *buffer)
1009 eeebca22 2022-01-11 op size_t npages, tot;
1010 eeebca22 2022-01-11 op char fmt[FMT_SCALED_STRSIZE];
1012 eeebca22 2022-01-11 op mcache_info(&npages, &tot);
1014 eeebca22 2022-01-11 op if (fmt_scaled(tot, fmt) == 0)
1015 bb5abe9f 2022-01-13 op message("pages: %zu, total: %s", npages, fmt);
1017 bb5abe9f 2022-01-13 op message("pages: %zu, total: %zu", npages, tot);
1021 ed504b9e 2022-02-07 op cmd_reply_last_input(struct buffer *buffer)
1023 ed504b9e 2022-02-07 op GUARD_RECURSIVE_MINIBUFFER();
1025 ed504b9e 2022-02-07 op if (current_tab->last_input_url == NULL) {
1026 ed504b9e 2022-02-07 op message("there was no previous input request in this tab");
1030 d89eb764 2022-04-24 op if (!strncmp(current_tab->last_input_url, "gopher", 6)) {
1031 acf9defe 2022-02-08 op load_url_in_tab(current_tab, current_tab->last_input_url,
1032 acf9defe 2022-02-08 op NULL, LU_MODE_NOCACHE);
1036 ed504b9e 2022-02-07 op message("%s", current_tab->last_input_url);
1037 ed504b9e 2022-02-07 op ui_require_input(current_tab, 0, ir_select_reply);
1041 868b3a8f 2022-04-13 op cmd_write_buffer(struct buffer *buffer)
1043 868b3a8f 2022-04-13 op const char *f, *url;
1044 868b3a8f 2022-04-13 op char path[PATH_MAX];
1046 868b3a8f 2022-04-13 op GUARD_RECURSIVE_MINIBUFFER();
1048 868b3a8f 2022-04-13 op if (safe_mode) {
1049 868b3a8f 2022-04-13 op message("Can't write buffer in safe-mode.");
1053 65c49665 2024-01-23 op url = hist_cur(current_tab->hist);
1055 868b3a8f 2022-04-13 op if ((f = strrchr(url, '/')) != NULL)
1057 868b3a8f 2022-04-13 op if (f == NULL || *f == '\0') {
1058 868b3a8f 2022-04-13 op /* guess a decent file name based on the protocol used */
1059 868b3a8f 2022-04-13 op if (!strncmp(url, "gemini://", 9))
1060 868b3a8f 2022-04-13 op f = "index.gmi";
1062 868b3a8f 2022-04-13 op f = "index.txt";
1065 868b3a8f 2022-04-13 op strlcpy(path, download_path, sizeof(path));
1066 868b3a8f 2022-04-13 op strlcat(path, f, sizeof(path));
1068 868b3a8f 2022-04-13 op ui_read("Write file", write_buffer, current_tab, path);
1072 a36bb43a 2024-01-15 op cmd_home(struct buffer *buffer)
1074 86294a09 2024-01-16 op char path[GEMINI_URL_LEN];
1075 86294a09 2024-01-16 op char *tilde, *t;
1077 86294a09 2024-01-16 op strlcpy(path, current_tab->iri.iri_path, sizeof(path));
1079 a526f3eb 2024-02-02 op if ((tilde = strstr(path, "/~")) != NULL &&
1080 a526f3eb 2024-02-02 op tilde[2] != '\0' && tilde[2] != '/') {
1081 a526f3eb 2024-02-02 op if ((t = strchr(tilde + 2, '/')) != NULL)
1082 86294a09 2024-01-16 op *++t = '\0';
1083 65c49665 2024-01-23 op load_url_in_tab(current_tab, path, NULL, LU_MODE_NOCACHE);
1085 86294a09 2024-01-16 op cmd_root(buffer);
1089 a36bb43a 2024-01-15 op cmd_root(struct buffer *buffer)
1091 65c49665 2024-01-23 op load_url_in_tab(current_tab, "/", NULL, LU_MODE_NOCACHE);
1095 a36bb43a 2024-01-15 op cmd_up(struct buffer *buffer)
1097 65c49665 2024-01-23 op load_url_in_tab(current_tab, "..", NULL, LU_MODE_NOCACHE);
1101 5a39f593 2024-02-05 op cmd_use_certificate(struct buffer *buffer)
1103 5a39f593 2024-02-05 op GUARD_RECURSIVE_MINIBUFFER();
1105 5a39f593 2024-02-05 op enter_minibuffer(sensible_self_insert, uc_select, exit_minibuffer,
1106 5a39f593 2024-02-05 op NULL, compl_uc, NULL, 1);
1107 5a39f593 2024-02-05 op strlcpy(ministate.prompt, "Select certificate: ",
1108 5a39f593 2024-02-05 op sizeof(ministate.prompt));
1112 4655add6 2024-02-05 op cmd_client_certificate_info(struct buffer *buffer)
1114 4655add6 2024-02-05 op if (current_tab->client_cert)
1115 4655add6 2024-02-05 op message("Using certificate %s", current_tab->client_cert);
1117 4655add6 2024-02-05 op message("Not using any client certificate.");
1121 4fdc9933 2024-02-05 op unload_certificate_cb(int r, struct tab *tab)
1123 71bc1636 2024-02-06 op message("Won't use %s for this site.", tab->client_cert);
1124 4fdc9933 2024-02-05 op cert_delete_for(tab->client_cert, &tab->iri, r);
1128 4fdc9933 2024-02-05 op cmd_unload_certificate(struct buffer *buffer)
1130 71bc1636 2024-02-06 op struct tab *tab = current_tab;
1132 4fdc9933 2024-02-05 op GUARD_RECURSIVE_MINIBUFFER();
1134 71bc1636 2024-02-06 op if (tab->client_cert == NULL) {
1135 4fdc9933 2024-02-05 op message("No client certificate in use!");
1139 71bc1636 2024-02-06 op if (tab->client_cert_temp) {
1140 71bc1636 2024-02-06 op message("Won't use %s for this site.", tab->client_cert);
1141 71bc1636 2024-02-06 op cert_delete_for(tab->client_cert, &tab->iri, 0);
1145 4fdc9933 2024-02-05 op yornp("Unload only for the current session?", unload_certificate_cb,
1146 4fdc9933 2024-02-05 op current_tab);
1150 fd6c540b 2024-02-12 op cmd_search(struct buffer *buffer)
1152 fd6c540b 2024-02-12 op GUARD_RECURSIVE_MINIBUFFER();
1154 50fd8b26 2024-02-12 op if (!strncmp(default_search_engine, "gopher://", 9)) {
1155 50fd8b26 2024-02-12 op load_url_in_tab(current_tab, default_search_engine, NULL,
1156 50fd8b26 2024-02-12 op LU_MODE_NOCACHE);
1160 fd6c540b 2024-02-12 op enter_minibuffer(sensible_self_insert, search_select, exit_minibuffer, NULL,
1161 fd6c540b 2024-02-12 op NULL, NULL, 0);
1162 fd6c540b 2024-02-12 op strlcpy(ministate.prompt, "Search: ", sizeof(ministate.prompt));