2 5e11c00c 2021-03-02 op * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
4 5e11c00c 2021-03-02 op * Permission to use, copy, modify, and distribute this software for any
5 5e11c00c 2021-03-02 op * purpose with or without fee is hereby granted, provided that the above
6 5e11c00c 2021-03-02 op * copyright notice and this permission notice appear in all copies.
8 5e11c00c 2021-03-02 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 5e11c00c 2021-03-02 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 5e11c00c 2021-03-02 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 5e11c00c 2021-03-02 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 5e11c00c 2021-03-02 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 5e11c00c 2021-03-02 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 5e11c00c 2021-03-02 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 1d08c280 2021-03-06 op * Ncurses UI for telescope.
20 1d08c280 2021-03-06 op * Text scrolling
21 1d08c280 2021-03-06 op * ==============
23 1d08c280 2021-03-06 op * ncurses allows you to scroll a window, but when a line goes out of
24 1d08c280 2021-03-06 op * the visible area it's forgotten. We keep a list of formatted lines
25 1d08c280 2021-03-06 op * (``visual lines'') that we know fits in the window, and draw them.
26 1d08c280 2021-03-06 op * This way is easy to scroll: just call wscrl and then render the
27 1d08c280 2021-03-06 op * first/last line!
29 1d08c280 2021-03-06 op * This means that on every resize we have to clear our list of lines
30 1d08c280 2021-03-06 op * and re-render everything. A clever approach would be to do this
31 1d08c280 2021-03-06 op * ``on-demand''.
33 1d08c280 2021-03-06 op * TODO: make the text formatting on-demand.
37 5e11c00c 2021-03-02 op #include <telescope.h>
39 f832146f 2021-03-09 op #include <ctype.h>
40 5e11c00c 2021-03-02 op #include <curses.h>
41 5e11c00c 2021-03-02 op #include <event.h>
42 5e11c00c 2021-03-02 op #include <locale.h>
43 5e11c00c 2021-03-02 op #include <signal.h>
44 7953dd72 2021-03-07 op #include <stdarg.h>
45 eb259e66 2021-03-02 op #include <stdlib.h>
46 eb259e66 2021-03-02 op #include <string.h>
47 f832146f 2021-03-09 op #include <unistd.h>
49 5e11c00c 2021-03-02 op #define TAB_CURRENT 0x1
51 1b81bc33 2021-03-15 op #define NEW_TAB_URL "about:new"
53 5e11c00c 2021-03-02 op static struct event stdioev, winchev;
55 f832146f 2021-03-09 op static void load_default_keys(void);
56 1d08c280 2021-03-06 op static void empty_vlist(struct tab*);
57 48e9d457 2021-03-06 op static void restore_cursor(struct tab *);
59 46a9311e 2021-03-08 op static void cmd_previous_line(struct tab*);
60 46a9311e 2021-03-08 op static void cmd_next_line(struct tab*);
61 46a9311e 2021-03-08 op static void cmd_backward_char(struct tab*);
62 88597eaf 2021-03-17 op static void cmd_forward_char(struct tab*);
63 852d03e8 2021-03-17 op static void cmd_backward_paragraph(struct tab*);
64 852d03e8 2021-03-17 op static void cmd_forward_paragraph(struct tab*);
65 a329982b 2021-03-11 op static void cmd_move_beginning_of_line(struct tab*);
66 a329982b 2021-03-11 op static void cmd_move_end_of_line(struct tab*);
67 46a9311e 2021-03-08 op static void cmd_redraw(struct tab*);
68 ed44414d 2021-03-09 op static void cmd_scroll_line_down(struct tab*);
69 ed44414d 2021-03-09 op static void cmd_scroll_line_up(struct tab*);
70 46a9311e 2021-03-08 op static void cmd_scroll_up(struct tab*);
71 ed44414d 2021-03-09 op static void cmd_scroll_down(struct tab*);
72 e19f9a04 2021-03-11 op static void cmd_beginning_of_buffer(struct tab*);
73 e19f9a04 2021-03-11 op static void cmd_end_of_buffer(struct tab*);
74 46a9311e 2021-03-08 op static void cmd_kill_telescope(struct tab*);
75 46a9311e 2021-03-08 op static void cmd_push_button(struct tab*);
76 b1df9b71 2021-03-12 op static void cmd_push_button_new_tab(struct tab*);
77 a8c28919 2021-03-16 op static void cmd_previous_button(struct tab*);
78 a8c28919 2021-03-16 op static void cmd_next_button(struct tab*);
79 2051e653 2021-03-13 op static void cmd_previous_page(struct tab*);
80 2051e653 2021-03-13 op static void cmd_next_page(struct tab*);
81 3b4f9e49 2021-03-11 op static void cmd_clear_minibuf(struct tab*);
82 9ca15951 2021-03-09 op static void cmd_execute_extended_command(struct tab*);
83 7c7d7bb7 2021-03-10 op static void cmd_tab_close(struct tab*);
84 fea845b6 2021-03-15 op static void cmd_tab_close_other(struct tab*);
85 7c7d7bb7 2021-03-10 op static void cmd_tab_new(struct tab*);
86 7c7d7bb7 2021-03-10 op static void cmd_tab_next(struct tab*);
87 7c7d7bb7 2021-03-10 op static void cmd_tab_previous(struct tab*);
88 5cd2ebb1 2021-03-11 op static void cmd_load_url(struct tab*);
89 5cd2ebb1 2021-03-11 op static void cmd_load_current_url(struct tab*);
90 740f578b 2021-03-15 op static void cmd_bookmark_page(struct tab*);
91 de0b2139 2021-03-15 op static void cmd_goto_bookmarks(struct tab*);
93 9ca15951 2021-03-09 op static void global_key_unbound(void);
95 d67133bf 2021-03-12 op static void cmd_mini_delete_char(struct tab*);
96 d67133bf 2021-03-12 op static void cmd_mini_delete_backward_char(struct tab*);
97 9ca15951 2021-03-09 op static void cmd_mini_forward_char(struct tab*);
98 9ca15951 2021-03-09 op static void cmd_mini_backward_char(struct tab*);
99 9ca15951 2021-03-09 op static void cmd_mini_move_end_of_line(struct tab*);
100 9ca15951 2021-03-09 op static void cmd_mini_move_beginning_of_line(struct tab*);
101 fa3fd864 2021-03-10 op static void cmd_mini_kill_line(struct tab*);
102 22268e11 2021-03-11 op static void cmd_mini_abort(struct tab*);
103 22268e11 2021-03-11 op static void cmd_mini_complete_and_exit(struct tab*);
104 22268e11 2021-03-11 op static void cmd_mini_previous_history_element(struct tab*);
105 22268e11 2021-03-11 op static void cmd_mini_next_history_element(struct tab*);
107 22268e11 2021-03-11 op static void minibuffer_hist_save_entry(void);
108 22268e11 2021-03-11 op static void minibuffer_taint_hist(void);
109 5cd2ebb1 2021-03-11 op static void minibuffer_self_insert(void);
110 9ca15951 2021-03-09 op static void eecmd_self_insert(void);
111 b360ebb3 2021-03-10 op static void eecmd_select(void);
112 5cd2ebb1 2021-03-11 op static void ir_self_insert(void);
113 5cd2ebb1 2021-03-11 op static void ir_select(void);
114 5cd2ebb1 2021-03-11 op static void lu_self_insert(void);
115 5cd2ebb1 2021-03-11 op static void lu_select(void);
116 740f578b 2021-03-15 op static void bp_select(void);
118 9a25f829 2021-03-14 op static struct vline *nth_line(struct tab*, size_t);
119 5e11c00c 2021-03-02 op static struct tab *current_tab(void);
120 5e11c00c 2021-03-02 op static void dispatch_stdio(int, short, void*);
121 a6d450c1 2021-03-06 op static void handle_clear_minibuf(int, short, void*);
122 5e11c00c 2021-03-02 op static void handle_resize(int, short, void*);
123 1d08c280 2021-03-06 op static int wrap_page(struct tab*);
124 9a25f829 2021-03-14 op static void print_vline(struct vline*);
125 8af5e5ed 2021-03-08 op static void redraw_tabline(void);
126 e19f9a04 2021-03-11 op static void redraw_body(struct tab*);
127 8af5e5ed 2021-03-08 op static void redraw_modeline(struct tab*);
128 9ca15951 2021-03-09 op static void redraw_minibuffer(void);
129 5e11c00c 2021-03-02 op static void redraw_tab(struct tab*);
130 740f578b 2021-03-15 op static void vmessage(const char*, va_list);
131 7953dd72 2021-03-07 op static void message(const char*, ...) __attribute__((format(printf, 1, 2)));
132 8af5e5ed 2021-03-08 op static void start_loading_anim(struct tab*);
133 8af5e5ed 2021-03-08 op static void update_loading_anim(int, short, void*);
134 8af5e5ed 2021-03-08 op static void stop_loading_anim(struct tab*);
135 43a1b8d0 2021-03-09 op static void load_url_in_tab(struct tab*, const char*);
136 3148eeac 2021-03-13 op static void enter_minibuffer(void(*)(void), void(*)(void), void(*)(void), struct histhead*);
137 b360ebb3 2021-03-10 op static void exit_minibuffer(void);
138 5cd2ebb1 2021-03-11 op static void switch_to_tab(struct tab*);
139 1b81bc33 2021-03-15 op static struct tab *new_tab(const char*);
141 9ca15951 2021-03-09 op static struct { int meta, key; } thiskey;
143 48e9d457 2021-03-06 op static WINDOW *tabline, *body, *modeline, *minibuf;
144 48e9d457 2021-03-06 op static int body_lines, body_cols;
146 48e9d457 2021-03-06 op static struct event clminibufev;
147 a6d450c1 2021-03-06 op static struct timeval clminibufev_timer = { 5, 0 };
148 8af5e5ed 2021-03-08 op static struct timeval loadingev_timer = { 0, 250000 };
150 bcb0b073 2021-03-07 op static uint32_t tab_counter;
152 7c7d7bb7 2021-03-10 op static char keybuf[64];
154 9ca15951 2021-03-09 op struct kmap global_map,
155 fa3fd864 2021-03-10 op minibuffer_map,
156 9ca15951 2021-03-09 op *current_map,
159 3148eeac 2021-03-13 op static struct histhead eecmd_history,
163 9ca15951 2021-03-09 op static int in_minibuffer;
165 9ca15951 2021-03-09 op static struct {
166 9cb0f9ce 2021-03-10 op char *curmesg;
168 040fbdf8 2021-03-10 op char buf[1025];
169 9ca15951 2021-03-09 op size_t off, len;
170 5cd2ebb1 2021-03-11 op char prompt[32];
171 b360ebb3 2021-03-10 op void (*donefn)(void);
172 b360ebb3 2021-03-10 op void (*abortfn)(void);
174 3148eeac 2021-03-13 op struct histhead *history;
175 3148eeac 2021-03-13 op struct hist *hist_cur;
176 22268e11 2021-03-11 op size_t hist_off;
179 f95d82dd 2021-03-11 op struct lineprefix {
180 f95d82dd 2021-03-11 op const char *prfx1;
181 f95d82dd 2021-03-11 op const char *prfx2;
182 f95d82dd 2021-03-11 op } line_prefixes[] = {
183 f95d82dd 2021-03-11 op [LINE_TEXT] = { "", "" },
184 f95d82dd 2021-03-11 op [LINE_LINK] = { "=> ", " " },
185 f95d82dd 2021-03-11 op [LINE_TITLE_1] = { "# ", " " },
186 f95d82dd 2021-03-11 op [LINE_TITLE_2] = { "## ", " " },
187 f95d82dd 2021-03-11 op [LINE_TITLE_3] = { "### ", " " },
188 f95d82dd 2021-03-11 op [LINE_ITEM] = { "* ", " " },
189 f95d82dd 2021-03-11 op [LINE_QUOTE] = { "> ", "> " },
190 803ff456 2021-03-17 op [LINE_PRE_START] = { "```", " " },
191 f95d82dd 2021-03-11 op [LINE_PRE_CONTENT] = { "", "" },
192 f95d82dd 2021-03-11 op [LINE_PRE_END] = { "```", "```" },
195 31840026 2021-03-16 op static struct line_face {
196 803ff456 2021-03-17 op int prefix_prop;
197 803ff456 2021-03-17 op int text_prop;
198 d3d56d8a 2021-03-11 op } line_faces[] = {
199 803ff456 2021-03-17 op [LINE_TEXT] = { 0, 0 },
200 803ff456 2021-03-17 op [LINE_LINK] = { 0, A_UNDERLINE },
201 803ff456 2021-03-17 op [LINE_TITLE_1] = { A_BOLD, A_BOLD },
202 803ff456 2021-03-17 op [LINE_TITLE_2] = { A_BOLD, A_BOLD },
203 803ff456 2021-03-17 op [LINE_TITLE_3] = { A_BOLD, A_BOLD },
204 803ff456 2021-03-17 op [LINE_ITEM] = { 0, 0 },
205 803ff456 2021-03-17 op [LINE_QUOTE] = { 0, A_DIM },
206 803ff456 2021-03-17 op [LINE_PRE_START] = { 0, 0 },
207 803ff456 2021-03-17 op [LINE_PRE_CONTENT] = { 0, 0 },
208 803ff456 2021-03-17 op [LINE_PRE_END] = { 0, 0 },
211 cb6c7aa0 2021-03-16 op static struct tab_face {
212 cb6c7aa0 2021-03-16 op int background, tab, current_tab;
213 cb6c7aa0 2021-03-16 op } tab_face = {
214 cb6c7aa0 2021-03-16 op A_REVERSE, A_REVERSE, A_NORMAL
218 65d9b3ca 2021-03-14 op empty_vlist(struct tab *tab)
220 65d9b3ca 2021-03-14 op struct vline *vl, *t;
222 452589f7 2021-03-16 op tab->s.current_line = NULL;
223 65d9b3ca 2021-03-14 op tab->s.line_max = 0;
225 65d9b3ca 2021-03-14 op TAILQ_FOREACH_SAFE(vl, &tab->s.head, vlines, t) {
226 65d9b3ca 2021-03-14 op TAILQ_REMOVE(&tab->s.head, vl, vlines);
227 65d9b3ca 2021-03-14 op free(vl->line);
232 f832146f 2021-03-09 op static inline void
233 f832146f 2021-03-09 op global_set_key(const char *key, void (*fn)(struct tab*))
235 67c8ed7f 2021-03-13 op if (!kmap_define_key(&global_map, key, fn))
239 9ca15951 2021-03-09 op static inline void
240 fa3fd864 2021-03-10 op minibuffer_set_key(const char *key, void (*fn)(struct tab*))
242 67c8ed7f 2021-03-13 op if (!kmap_define_key(&minibuffer_map, key, fn))
247 f832146f 2021-03-09 op load_default_keys(void)
249 9ca15951 2021-03-09 op /* === global map === */
252 f832146f 2021-03-09 op global_set_key("C-p", cmd_previous_line);
253 f832146f 2021-03-09 op global_set_key("C-n", cmd_next_line);
254 f832146f 2021-03-09 op global_set_key("C-f", cmd_forward_char);
255 f832146f 2021-03-09 op global_set_key("C-b", cmd_backward_char);
256 852d03e8 2021-03-17 op global_set_key("M-{", cmd_backward_paragraph);
257 852d03e8 2021-03-17 op global_set_key("M-}", cmd_forward_paragraph);
258 a329982b 2021-03-11 op global_set_key("C-a", cmd_move_beginning_of_line);
259 a329982b 2021-03-11 op global_set_key("C-e", cmd_move_end_of_line);
261 f832146f 2021-03-09 op global_set_key("M-v", cmd_scroll_up);
262 f832146f 2021-03-09 op global_set_key("C-v", cmd_scroll_down);
263 929c2d9f 2021-03-13 op global_set_key("M-space", cmd_scroll_up);
264 929c2d9f 2021-03-13 op global_set_key("space", cmd_scroll_down);
266 f832146f 2021-03-09 op global_set_key("C-x C-c", cmd_kill_telescope);
268 3b4f9e49 2021-03-11 op global_set_key("C-g", cmd_clear_minibuf);
270 9ca15951 2021-03-09 op global_set_key("M-x", cmd_execute_extended_command);
271 5cd2ebb1 2021-03-11 op global_set_key("C-x C-f", cmd_load_url);
272 5cd2ebb1 2021-03-11 op global_set_key("C-x M-f", cmd_load_current_url);
274 7c7d7bb7 2021-03-10 op global_set_key("C-x t 0", cmd_tab_close);
275 fea845b6 2021-03-15 op global_set_key("C-x t 1", cmd_tab_close_other);
276 7c7d7bb7 2021-03-10 op global_set_key("C-x t 2", cmd_tab_new);
277 7c7d7bb7 2021-03-10 op global_set_key("C-x t o", cmd_tab_next);
278 7c7d7bb7 2021-03-10 op global_set_key("C-x t O", cmd_tab_previous);
280 e19f9a04 2021-03-11 op global_set_key("M-<", cmd_beginning_of_buffer);
281 e19f9a04 2021-03-11 op global_set_key("M->", cmd_end_of_buffer);
283 2051e653 2021-03-13 op global_set_key("C-M-b", cmd_previous_page);
284 2051e653 2021-03-13 op global_set_key("C-M-f", cmd_next_page);
286 740f578b 2021-03-15 op global_set_key("<f7> a", cmd_bookmark_page);
287 de0b2139 2021-03-15 op global_set_key("<f7> <f7>", cmd_goto_bookmarks);
289 f832146f 2021-03-09 op /* vi/vi-like */
290 f832146f 2021-03-09 op global_set_key("k", cmd_previous_line);
291 f832146f 2021-03-09 op global_set_key("j", cmd_next_line);
292 f832146f 2021-03-09 op global_set_key("l", cmd_forward_char);
293 f832146f 2021-03-09 op global_set_key("h", cmd_backward_char);
294 852d03e8 2021-03-17 op global_set_key("{", cmd_backward_paragraph);
295 852d03e8 2021-03-17 op global_set_key("}", cmd_forward_paragraph);
296 a329982b 2021-03-11 op global_set_key("^", cmd_move_beginning_of_line);
297 a329982b 2021-03-11 op global_set_key("$", cmd_move_end_of_line);
299 ed44414d 2021-03-09 op global_set_key("K", cmd_scroll_line_up);
300 ed44414d 2021-03-09 op global_set_key("J", cmd_scroll_line_down);
302 a02335e9 2021-03-15 op global_set_key("g D", cmd_tab_close);
303 a02335e9 2021-03-15 op global_set_key("g N", cmd_tab_new);
304 a02335e9 2021-03-15 op global_set_key("g t", cmd_tab_next);
305 a02335e9 2021-03-15 op global_set_key("g T", cmd_tab_previous);
307 e19f9a04 2021-03-11 op global_set_key("g g", cmd_beginning_of_buffer);
308 e19f9a04 2021-03-11 op global_set_key("G", cmd_end_of_buffer);
310 2051e653 2021-03-13 op global_set_key("H", cmd_previous_page);
311 2051e653 2021-03-13 op global_set_key("L", cmd_next_page);
314 f832146f 2021-03-09 op global_set_key("q", cmd_kill_telescope);
316 3b4f9e49 2021-03-11 op global_set_key("esc", cmd_clear_minibuf);
318 9ca15951 2021-03-09 op global_set_key(":", cmd_execute_extended_command);
321 f832146f 2021-03-09 op global_set_key("<up>", cmd_previous_line);
322 f832146f 2021-03-09 op global_set_key("<down>", cmd_next_line);
323 f832146f 2021-03-09 op global_set_key("<right>", cmd_forward_char);
324 f832146f 2021-03-09 op global_set_key("<left>", cmd_backward_char);
325 ed44414d 2021-03-09 op global_set_key("<prior>", cmd_scroll_up);
326 ed44414d 2021-03-09 op global_set_key("<next>", cmd_scroll_down);
328 2051e653 2021-03-13 op global_set_key("M-<left>", cmd_previous_page);
329 2051e653 2021-03-13 op global_set_key("M-<right>", cmd_next_page);
331 f832146f 2021-03-09 op /* "ncurses standard" */
332 f832146f 2021-03-09 op global_set_key("C-l", cmd_redraw);
335 f832146f 2021-03-09 op global_set_key("C-m", cmd_push_button);
336 b1df9b71 2021-03-12 op global_set_key("M-enter", cmd_push_button_new_tab);
337 a8c28919 2021-03-16 op global_set_key("M-tab", cmd_previous_button);
338 a8c28919 2021-03-16 op global_set_key("tab", cmd_next_button);
340 fa3fd864 2021-03-10 op /* === minibuffer map === */
341 b360ebb3 2021-03-10 op minibuffer_set_key("ret", cmd_mini_complete_and_exit);
342 b360ebb3 2021-03-10 op minibuffer_set_key("C-g", cmd_mini_abort);
343 b360ebb3 2021-03-10 op minibuffer_set_key("esc", cmd_mini_abort);
344 d67133bf 2021-03-12 op minibuffer_set_key("C-d", cmd_mini_delete_char);
345 d67133bf 2021-03-12 op minibuffer_set_key("del", cmd_mini_delete_backward_char);
347 fa3fd864 2021-03-10 op minibuffer_set_key("C-f", cmd_mini_forward_char);
348 fa3fd864 2021-03-10 op minibuffer_set_key("C-b", cmd_mini_backward_char);
349 5b2bf704 2021-03-12 op minibuffer_set_key("<right>", cmd_mini_forward_char);
350 5b2bf704 2021-03-12 op minibuffer_set_key("<left>", cmd_mini_backward_char);
351 fa3fd864 2021-03-10 op minibuffer_set_key("C-e", cmd_mini_move_end_of_line);
352 fa3fd864 2021-03-10 op minibuffer_set_key("C-a", cmd_mini_move_beginning_of_line);
353 fa3fd864 2021-03-10 op minibuffer_set_key("<end>", cmd_mini_move_end_of_line);
354 fa3fd864 2021-03-10 op minibuffer_set_key("<home>", cmd_mini_move_beginning_of_line);
355 fa3fd864 2021-03-10 op minibuffer_set_key("C-k", cmd_mini_kill_line);
357 22268e11 2021-03-11 op minibuffer_set_key("M-p", cmd_mini_previous_history_element);
358 22268e11 2021-03-11 op minibuffer_set_key("M-n", cmd_mini_next_history_element);
359 22268e11 2021-03-11 op minibuffer_set_key("<up>", cmd_mini_previous_history_element);
360 22268e11 2021-03-11 op minibuffer_set_key("<down>", cmd_mini_next_history_element);
364 48e9d457 2021-03-06 op restore_cursor(struct tab *tab)
366 452589f7 2021-03-16 op struct vline *vl;
367 452589f7 2021-03-16 op const char *prfx;
369 452589f7 2021-03-16 op vl =tab->s.current_line;
370 452589f7 2021-03-16 op if (vl == NULL || vl->line == NULL)
371 452589f7 2021-03-16 op tab->s.curs_x = tab->s.line_x = 0;
373 452589f7 2021-03-16 op tab->s.line_x = MIN(tab->s.line_x, strlen(vl->line));
375 452589f7 2021-03-16 op if (vl != NULL) {
376 452589f7 2021-03-16 op prfx = line_prefixes[vl->parent->type].prfx1;
377 452589f7 2021-03-16 op tab->s.curs_x = tab->s.line_x + strlen(prfx);
380 65d9b3ca 2021-03-14 op wmove(body, tab->s.curs_y, tab->s.curs_x);
384 46a9311e 2021-03-08 op cmd_previous_line(struct tab *tab)
386 452589f7 2021-03-16 op struct vline *vl;
388 452589f7 2021-03-16 op if (tab->s.current_line == NULL
389 452589f7 2021-03-16 op || (vl = TAILQ_PREV(tab->s.current_line, vhead, vlines)) == NULL)
392 65d9b3ca 2021-03-14 op if (--tab->s.curs_y < 0) {
393 65d9b3ca 2021-03-14 op tab->s.curs_y = 0;
394 ed44414d 2021-03-09 op cmd_scroll_line_up(tab);
398 452589f7 2021-03-16 op tab->s.current_line = vl;
399 48e9d457 2021-03-06 op restore_cursor(tab);
403 46a9311e 2021-03-08 op cmd_next_line(struct tab *tab)
405 452589f7 2021-03-16 op struct vline *vl;
407 452589f7 2021-03-16 op if (tab->s.current_line == NULL
408 452589f7 2021-03-16 op || (vl = TAILQ_NEXT(tab->s.current_line, vlines)) == NULL)
411 65d9b3ca 2021-03-14 op if (++tab->s.curs_y > body_lines-1) {
412 65d9b3ca 2021-03-14 op tab->s.curs_y = body_lines-1;
413 ed44414d 2021-03-09 op cmd_scroll_line_down(tab);
417 452589f7 2021-03-16 op tab->s.current_line = vl;
418 48e9d457 2021-03-06 op restore_cursor(tab);
422 88597eaf 2021-03-17 op cmd_backward_char(struct tab *tab)
424 88597eaf 2021-03-17 op if (tab->s.line_x != 0)
425 88597eaf 2021-03-17 op tab->s.line_x--;
426 48e9d457 2021-03-06 op restore_cursor(tab);
430 88597eaf 2021-03-17 op cmd_forward_char(struct tab *tab)
432 88597eaf 2021-03-17 op tab->s.line_x++;
433 a329982b 2021-03-11 op restore_cursor(tab);
437 852d03e8 2021-03-17 op cmd_backward_paragraph(struct tab *tab)
440 852d03e8 2021-03-17 op if (tab->s.current_line == NULL ||
441 852d03e8 2021-03-17 op tab->s.current_line == TAILQ_FIRST(&tab->s.head)) {
442 852d03e8 2021-03-17 op message("No previous paragraph");
445 852d03e8 2021-03-17 op cmd_previous_line(tab);
446 852d03e8 2021-03-17 op } while (tab->s.current_line->line != NULL ||
447 852d03e8 2021-03-17 op tab->s.current_line->parent->type != LINE_TEXT);
451 852d03e8 2021-03-17 op cmd_forward_paragraph(struct tab *tab)
454 852d03e8 2021-03-17 op if (tab->s.current_line == NULL ||
455 852d03e8 2021-03-17 op tab->s.current_line == TAILQ_LAST(&tab->s.head, vhead)) {
456 852d03e8 2021-03-17 op message("No next paragraph");
459 852d03e8 2021-03-17 op cmd_next_line(tab);
460 852d03e8 2021-03-17 op } while (tab->s.current_line->line != NULL ||
461 852d03e8 2021-03-17 op tab->s.current_line->parent->type != LINE_TEXT);
465 a329982b 2021-03-11 op cmd_move_beginning_of_line(struct tab *tab)
467 452589f7 2021-03-16 op tab->s.line_x = 0;
468 a329982b 2021-03-11 op restore_cursor(tab);
472 a329982b 2021-03-11 op cmd_move_end_of_line(struct tab *tab)
474 9a25f829 2021-03-14 op struct vline *vl;
476 452589f7 2021-03-16 op vl = tab->s.current_line;
477 452589f7 2021-03-16 op if (vl->line == NULL)
479 452589f7 2021-03-16 op tab->s.line_x = body_cols;
480 48e9d457 2021-03-06 op restore_cursor(tab);
484 46a9311e 2021-03-08 op cmd_redraw(struct tab *tab)
486 b1738d2e 2021-03-06 op handle_resize(0, 0, NULL);
490 ed44414d 2021-03-09 op cmd_scroll_line_up(struct tab *tab)
492 9a25f829 2021-03-14 op struct vline *vl;
494 65d9b3ca 2021-03-14 op if (tab->s.line_off == 0)
497 65d9b3ca 2021-03-14 op vl = nth_line(tab, --tab->s.line_off);
498 48e9d457 2021-03-06 op wscrl(body, -1);
499 48e9d457 2021-03-06 op wmove(body, 0, 0);
500 9a25f829 2021-03-14 op print_vline(vl);
502 452589f7 2021-03-16 op tab->s.current_line = TAILQ_PREV(tab->s.current_line, vhead, vlines);
506 ed44414d 2021-03-09 op cmd_scroll_line_down(struct tab *tab)
508 9a25f829 2021-03-14 op struct vline *vl;
510 452589f7 2021-03-16 op vl = tab->s.current_line;
511 452589f7 2021-03-16 op if ((vl = TAILQ_NEXT(vl, vlines)) == NULL)
513 452589f7 2021-03-16 op tab->s.current_line = vl;
515 65d9b3ca 2021-03-14 op tab->s.line_off++;
516 48e9d457 2021-03-06 op wscrl(body, 1);
518 754622a2 2021-03-15 op if (tab->s.line_max - tab->s.line_off < (size_t)body_lines)
521 65d9b3ca 2021-03-14 op vl = nth_line(tab, tab->s.line_off + body_lines-1);
522 48e9d457 2021-03-06 op wmove(body, body_lines-1, 0);
523 9a25f829 2021-03-14 op print_vline(vl);
527 ed44414d 2021-03-09 op cmd_scroll_up(struct tab *tab)
531 ed44414d 2021-03-09 op off = body_lines+1;
533 ed44414d 2021-03-09 op for (; off > 0; --off)
534 ed44414d 2021-03-09 op cmd_scroll_line_up(tab);
538 ed44414d 2021-03-09 op cmd_scroll_down(struct tab *tab)
542 338eecdc 2021-03-12 op off = body_lines+1;
544 338eecdc 2021-03-12 op for (; off > 0; --off)
545 ed44414d 2021-03-09 op cmd_scroll_line_down(tab);
549 e19f9a04 2021-03-11 op cmd_beginning_of_buffer(struct tab *tab)
551 452589f7 2021-03-16 op tab->s.current_line = TAILQ_FIRST(&tab->s.head);
552 65d9b3ca 2021-03-14 op tab->s.line_off = 0;
553 65d9b3ca 2021-03-14 op tab->s.curs_y = 0;
554 452589f7 2021-03-16 op tab->s.line_x = 0;
555 452589f7 2021-03-16 op restore_cursor(tab);
556 e19f9a04 2021-03-11 op redraw_body(tab);
560 e19f9a04 2021-03-11 op cmd_end_of_buffer(struct tab *tab)
564 65d9b3ca 2021-03-14 op off = tab->s.line_max - body_lines;
565 e19f9a04 2021-03-11 op off = MAX(0, off);
567 65d9b3ca 2021-03-14 op tab->s.line_off = off;
568 452589f7 2021-03-16 op tab->s.curs_y = MIN((size_t)body_lines, tab->s.line_max-1);
570 452589f7 2021-03-16 op tab->s.current_line = TAILQ_LAST(&tab->s.head, vhead);
571 452589f7 2021-03-16 op tab->s.line_x = body_cols;
572 452589f7 2021-03-16 op restore_cursor(tab);
573 e19f9a04 2021-03-11 op redraw_body(tab);
577 46a9311e 2021-03-08 op cmd_kill_telescope(struct tab *tab)
579 1d08c280 2021-03-06 op event_loopbreak();
583 46a9311e 2021-03-08 op cmd_push_button(struct tab *tab)
585 9a25f829 2021-03-14 op struct vline *vl;
588 65d9b3ca 2021-03-14 op nth = tab->s.line_off + tab->s.curs_y;
589 65d9b3ca 2021-03-14 op if (nth >= tab->s.line_max)
591 9a25f829 2021-03-14 op vl = nth_line(tab, nth);
592 9a25f829 2021-03-14 op if (vl->parent->type != LINE_LINK)
595 9a25f829 2021-03-14 op load_url_in_tab(tab, vl->parent->alt);
599 b1df9b71 2021-03-12 op cmd_push_button_new_tab(struct tab *tab)
601 9a25f829 2021-03-14 op struct vline *vl;
604 65d9b3ca 2021-03-14 op nth = tab->s.line_off + tab->s.curs_y;
605 65d9b3ca 2021-03-14 op if (nth > tab->s.line_max)
607 9a25f829 2021-03-14 op vl = nth_line(tab, nth);
608 9a25f829 2021-03-14 op if (vl->parent->type != LINE_LINK)
611 1b81bc33 2021-03-15 op new_tab(vl->parent->alt);
615 a8c28919 2021-03-16 op cmd_previous_button(struct tab *tab)
618 a8c28919 2021-03-16 op if (tab->s.current_line == NULL ||
619 a8c28919 2021-03-16 op tab->s.current_line == TAILQ_FIRST(&tab->s.head)) {
620 a8c28919 2021-03-16 op message("No previous link");
623 a8c28919 2021-03-16 op cmd_previous_line(tab);
624 a8c28919 2021-03-16 op } while (tab->s.current_line->parent->type != LINE_LINK);
628 a8c28919 2021-03-16 op cmd_next_button(struct tab *tab)
631 a8c28919 2021-03-16 op if (tab->s.current_line == NULL ||
632 a8c28919 2021-03-16 op tab->s.current_line == TAILQ_LAST(&tab->s.head, vhead)) {
633 a8c28919 2021-03-16 op message("No next link");
636 a8c28919 2021-03-16 op cmd_next_line(tab);
637 a8c28919 2021-03-16 op } while (tab->s.current_line->parent->type != LINE_LINK);
641 2051e653 2021-03-13 op cmd_previous_page(struct tab *tab)
643 2051e653 2021-03-13 op if (!load_previous_page(tab))
644 2051e653 2021-03-13 op message("No previous page");
646 c40c2250 2021-03-14 op start_loading_anim(tab);
650 2051e653 2021-03-13 op cmd_next_page(struct tab *tab)
652 2051e653 2021-03-13 op if (!load_next_page(tab))
653 2051e653 2021-03-13 op message("No next page");
655 c40c2250 2021-03-14 op start_loading_anim(tab);
659 3b4f9e49 2021-03-11 op cmd_clear_minibuf(struct tab *tab)
661 3b4f9e49 2021-03-11 op handle_clear_minibuf(0, 0, NULL);
665 9ca15951 2021-03-09 op cmd_execute_extended_command(struct tab *tab)
669 22268e11 2021-03-11 op enter_minibuffer(eecmd_self_insert, eecmd_select, exit_minibuffer,
670 22268e11 2021-03-11 op &eecmd_history);
672 9ca15951 2021-03-09 op len = sizeof(ministate.prompt);
673 9ca15951 2021-03-09 op strlcpy(ministate.prompt, "", len);
675 9ca15951 2021-03-09 op if (thiskey.meta)
676 9ca15951 2021-03-09 op strlcat(ministate.prompt, "M-", len);
678 9ca15951 2021-03-09 op strlcat(ministate.prompt, keyname(thiskey.key), len);
679 9ca15951 2021-03-09 op strlcat(ministate.prompt, " ", len);
683 7c7d7bb7 2021-03-10 op cmd_tab_close(struct tab *tab)
685 7c7d7bb7 2021-03-10 op struct tab *t;
687 7c7d7bb7 2021-03-10 op if (TAILQ_PREV(tab, tabshead, tabs) == NULL &&
688 7c7d7bb7 2021-03-10 op TAILQ_NEXT(tab, tabs) == NULL) {
689 7c7d7bb7 2021-03-10 op message("Can't close the only tab.");
693 7c7d7bb7 2021-03-10 op stop_tab(tab);
695 7c7d7bb7 2021-03-10 op t = TAILQ_PREV(tab, tabshead, tabs);
696 7c7d7bb7 2021-03-10 op t->flags |= TAB_CURRENT;
698 7c7d7bb7 2021-03-10 op TAILQ_REMOVE(&tabshead, tab, tabs);
704 fea845b6 2021-03-15 op cmd_tab_close_other(struct tab *tab)
706 fea845b6 2021-03-15 op struct tab *t, *i;
708 fea845b6 2021-03-15 op TAILQ_FOREACH_SAFE(t, &tabshead, tabs, i) {
709 fea845b6 2021-03-15 op if (t->flags & TAB_CURRENT)
713 fea845b6 2021-03-15 op TAILQ_REMOVE(&tabshead, t, tabs);
719 7c7d7bb7 2021-03-10 op cmd_tab_new(struct tab *tab)
721 1b81bc33 2021-03-15 op new_tab(NEW_TAB_URL);
725 7c7d7bb7 2021-03-10 op cmd_tab_next(struct tab *tab)
727 7c7d7bb7 2021-03-10 op struct tab *t;
729 7c7d7bb7 2021-03-10 op tab->flags &= ~TAB_CURRENT;
731 7c7d7bb7 2021-03-10 op if ((t = TAILQ_NEXT(tab, tabs)) == NULL)
732 7c7d7bb7 2021-03-10 op t = TAILQ_FIRST(&tabshead);
733 7c7d7bb7 2021-03-10 op t->flags |= TAB_CURRENT;
737 7c7d7bb7 2021-03-10 op cmd_tab_previous(struct tab *tab)
739 7c7d7bb7 2021-03-10 op struct tab *t;
741 7c7d7bb7 2021-03-10 op tab->flags &= ~TAB_CURRENT;
743 7c7d7bb7 2021-03-10 op if ((t = TAILQ_PREV(tab, tabshead, tabs)) == NULL)
744 7c7d7bb7 2021-03-10 op t = TAILQ_LAST(&tabshead, tabshead);
745 7c7d7bb7 2021-03-10 op t->flags |= TAB_CURRENT;
749 5cd2ebb1 2021-03-11 op cmd_load_url(struct tab *tab)
751 22268e11 2021-03-11 op enter_minibuffer(lu_self_insert, lu_select, exit_minibuffer,
752 22268e11 2021-03-11 op &lu_history);
753 5cd2ebb1 2021-03-11 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
757 5cd2ebb1 2021-03-11 op cmd_load_current_url(struct tab *tab)
759 22268e11 2021-03-11 op enter_minibuffer(lu_self_insert, lu_select, exit_minibuffer,
760 22268e11 2021-03-11 op &lu_history);
761 5cd2ebb1 2021-03-11 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
762 740f578b 2021-03-15 op strlcpy(ministate.buf, tab->hist_cur->h, sizeof(ministate.buf));
763 740f578b 2021-03-15 op ministate.off = strlen(tab->hist_cur->h);
764 740f578b 2021-03-15 op ministate.len = ministate.off;
768 740f578b 2021-03-15 op cmd_bookmark_page(struct tab *tab)
770 740f578b 2021-03-15 op enter_minibuffer(lu_self_insert, bp_select, exit_minibuffer, NULL);
771 740f578b 2021-03-15 op strlcpy(ministate.prompt, "Bookmark URL: ", sizeof(ministate.prompt));
772 2051e653 2021-03-13 op strlcpy(ministate.buf, tab->hist_cur->h, sizeof(ministate.buf));
773 2051e653 2021-03-13 op ministate.off = strlen(tab->hist_cur->h);
774 5cd2ebb1 2021-03-11 op ministate.len = ministate.off;
778 de0b2139 2021-03-15 op cmd_goto_bookmarks(struct tab *tab)
780 de0b2139 2021-03-15 op load_url_in_tab(tab, "about:bookmarks");
784 7c7d7bb7 2021-03-10 op global_key_unbound(void)
786 7c7d7bb7 2021-03-10 op message("%s is undefined", keybuf);
790 d67133bf 2021-03-12 op cmd_mini_delete_char(struct tab *tab)
792 3eecee9e 2021-03-12 op minibuffer_taint_hist();
794 d67133bf 2021-03-12 op if (ministate.len == 0 || ministate.off == ministate.len)
797 d67133bf 2021-03-12 op memmove(&ministate.buf[ministate.off],
798 d67133bf 2021-03-12 op &ministate.buf[ministate.off+1],
799 d67133bf 2021-03-12 op ministate.len - ministate.off + 1);
800 d67133bf 2021-03-12 op ministate.len--;
804 d67133bf 2021-03-12 op cmd_mini_delete_backward_char(struct tab *tab)
806 3eecee9e 2021-03-12 op minibuffer_taint_hist();
808 9ca15951 2021-03-09 op if (ministate.len == 0 || ministate.off == 0)
811 9ca15951 2021-03-09 op memmove(&ministate.buf[ministate.off-1],
812 9ca15951 2021-03-09 op &ministate.buf[ministate.off],
813 9ca15951 2021-03-09 op ministate.len - ministate.off + 1);
814 9ca15951 2021-03-09 op ministate.off--;
815 9ca15951 2021-03-09 op ministate.len--;
819 9ca15951 2021-03-09 op cmd_mini_forward_char(struct tab *tab)
821 9ca15951 2021-03-09 op if (ministate.off == ministate.len)
823 9ca15951 2021-03-09 op ministate.off++;
827 9ca15951 2021-03-09 op cmd_mini_backward_char(struct tab *tab)
829 9ca15951 2021-03-09 op if (ministate.off == 0)
831 9ca15951 2021-03-09 op ministate.off--;
835 9ca15951 2021-03-09 op cmd_mini_move_end_of_line(struct tab *tab)
837 9ca15951 2021-03-09 op ministate.off = ministate.len;
841 9ca15951 2021-03-09 op cmd_mini_move_beginning_of_line(struct tab *tab)
843 9ca15951 2021-03-09 op ministate.off = 0;
847 fa3fd864 2021-03-10 op cmd_mini_kill_line(struct tab *tab)
849 3eecee9e 2021-03-12 op minibuffer_taint_hist();
851 fa3fd864 2021-03-10 op if (ministate.off == ministate.len)
853 fa3fd864 2021-03-10 op ministate.buf[ministate.off] = '\0';
854 fa3fd864 2021-03-10 op ministate.len -= ministate.off;
858 b360ebb3 2021-03-10 op cmd_mini_abort(struct tab *tab)
860 b360ebb3 2021-03-10 op ministate.abortfn();
864 b360ebb3 2021-03-10 op cmd_mini_complete_and_exit(struct tab *tab)
866 22268e11 2021-03-11 op minibuffer_taint_hist();
867 b360ebb3 2021-03-10 op ministate.donefn();
871 22268e11 2021-03-11 op cmd_mini_previous_history_element(struct tab *tab)
873 22268e11 2021-03-11 op if (ministate.history == NULL) {
874 22268e11 2021-03-11 op message("No history");
878 22268e11 2021-03-11 op if (ministate.hist_cur == NULL ||
879 22268e11 2021-03-11 op (ministate.hist_cur = TAILQ_PREV(ministate.hist_cur, mhisthead, entries)) == NULL) {
880 22268e11 2021-03-11 op ministate.hist_cur = TAILQ_LAST(&ministate.history->head, mhisthead);
881 22268e11 2021-03-11 op ministate.hist_off = ministate.history->len - 1;
882 22268e11 2021-03-11 op if (ministate.hist_cur == NULL)
883 22268e11 2021-03-11 op message("No prev item");
885 22268e11 2021-03-11 op ministate.hist_off--;
888 22268e11 2021-03-11 op if (ministate.hist_cur != NULL) {
889 22268e11 2021-03-11 op ministate.off = 0;
890 22268e11 2021-03-11 op ministate.len = strlen(ministate.hist_cur->h);
895 22268e11 2021-03-11 op cmd_mini_next_history_element(struct tab *tab)
897 22268e11 2021-03-11 op if (ministate.history == NULL) {
898 22268e11 2021-03-11 op message("No history");
902 22268e11 2021-03-11 op if (ministate.hist_cur == NULL ||
903 22268e11 2021-03-11 op (ministate.hist_cur = TAILQ_NEXT(ministate.hist_cur, entries)) == NULL) {
904 22268e11 2021-03-11 op ministate.hist_cur = TAILQ_FIRST(&ministate.history->head);
905 22268e11 2021-03-11 op ministate.hist_off = 0;
906 22268e11 2021-03-11 op if (ministate.hist_cur == NULL)
907 22268e11 2021-03-11 op message("No next item");
909 22268e11 2021-03-11 op ministate.hist_off++;
912 22268e11 2021-03-11 op if (ministate.hist_cur != NULL) {
913 22268e11 2021-03-11 op ministate.off = 0;
914 22268e11 2021-03-11 op ministate.len = strlen(ministate.hist_cur->h);
919 22268e11 2021-03-11 op minibuffer_hist_save_entry(void)
921 3148eeac 2021-03-13 op struct hist *hist;
923 22268e11 2021-03-11 op if (ministate.history == NULL)
926 22268e11 2021-03-11 op if ((hist = calloc(1, sizeof(*hist))) == NULL)
929 22268e11 2021-03-11 op strlcpy(hist->h, ministate.buf, sizeof(hist->h));
931 22268e11 2021-03-11 op if (TAILQ_EMPTY(&ministate.history->head))
932 22268e11 2021-03-11 op TAILQ_INSERT_HEAD(&ministate.history->head, hist, entries);
934 22268e11 2021-03-11 op TAILQ_INSERT_TAIL(&ministate.history->head, hist, entries);
935 22268e11 2021-03-11 op ministate.history->len++;
939 22268e11 2021-03-11 op * taint the minibuffer cache: if we're currently showing a history
940 22268e11 2021-03-11 op * element, copy that to the current buf and reset the "history
941 22268e11 2021-03-11 op * navigation" thing.
944 22268e11 2021-03-11 op minibuffer_taint_hist(void)
946 22268e11 2021-03-11 op if (ministate.hist_cur == NULL)
949 22268e11 2021-03-11 op strlcpy(ministate.buf, ministate.hist_cur->h, sizeof(ministate.buf));
950 22268e11 2021-03-11 op ministate.hist_cur = NULL;
954 5cd2ebb1 2021-03-11 op minibuffer_self_insert(void)
956 22268e11 2021-03-11 op minibuffer_taint_hist();
958 040fbdf8 2021-03-10 op if (ministate.len == sizeof(ministate.buf) -1)
961 9ca15951 2021-03-09 op /* TODO: utf8 handling! */
963 9ca15951 2021-03-09 op memmove(&ministate.buf[ministate.off+1],
964 9ca15951 2021-03-09 op &ministate.buf[ministate.off],
965 9ca15951 2021-03-09 op ministate.len - ministate.off + 1);
966 9ca15951 2021-03-09 op ministate.buf[ministate.off] = thiskey.key;
967 9ca15951 2021-03-09 op ministate.off++;
968 9ca15951 2021-03-09 op ministate.len++;
972 5cd2ebb1 2021-03-11 op eecmd_self_insert(void)
974 5cd2ebb1 2021-03-11 op if (thiskey.meta || isspace(thiskey.key) ||
975 5cd2ebb1 2021-03-11 op !isgraph(thiskey.key)) {
976 5cd2ebb1 2021-03-11 op global_key_unbound();
980 5cd2ebb1 2021-03-11 op minibuffer_self_insert();
984 b360ebb3 2021-03-10 op eecmd_select(void)
986 b360ebb3 2021-03-10 op exit_minibuffer();
987 22268e11 2021-03-11 op minibuffer_hist_save_entry();
988 b360ebb3 2021-03-10 op message("TODO: try to execute %s", ministate.buf);
992 5cd2ebb1 2021-03-11 op ir_self_insert(void)
994 5cd2ebb1 2021-03-11 op minibuffer_self_insert();
998 5cd2ebb1 2021-03-11 op ir_select(void)
1000 5cd2ebb1 2021-03-11 op char buf[1025] = {0};
1001 5cd2ebb1 2021-03-11 op struct url url;
1002 5cd2ebb1 2021-03-11 op struct tab *tab;
1004 5cd2ebb1 2021-03-11 op tab = current_tab();
1006 5cd2ebb1 2021-03-11 op exit_minibuffer();
1007 22268e11 2021-03-11 op minibuffer_hist_save_entry();
1009 5cd2ebb1 2021-03-11 op /* a bit ugly but... */
1010 5cd2ebb1 2021-03-11 op memcpy(&url, &tab->url, sizeof(tab->url));
1011 5cd2ebb1 2021-03-11 op url_set_query(&url, ministate.buf);
1012 5cd2ebb1 2021-03-11 op url_unparse(&url, buf, sizeof(buf));
1013 5cd2ebb1 2021-03-11 op load_url_in_tab(tab, buf);
1017 5cd2ebb1 2021-03-11 op lu_self_insert(void)
1019 5cd2ebb1 2021-03-11 op if (thiskey.meta || isspace(thiskey.key) ||
1020 5cd2ebb1 2021-03-11 op !isgraph(thiskey.key)) {
1021 5cd2ebb1 2021-03-11 op global_key_unbound();
1025 5cd2ebb1 2021-03-11 op minibuffer_self_insert();
1029 5cd2ebb1 2021-03-11 op lu_select(void)
1031 5cd2ebb1 2021-03-11 op exit_minibuffer();
1032 22268e11 2021-03-11 op minibuffer_hist_save_entry();
1033 5cd2ebb1 2021-03-11 op load_url_in_tab(current_tab(), ministate.buf);
1037 740f578b 2021-03-15 op bp_select(void)
1039 740f578b 2021-03-15 op exit_minibuffer();
1040 740f578b 2021-03-15 op if (*ministate.buf != '\0')
1041 740f578b 2021-03-15 op add_to_bookmarks(ministate.buf);
1043 740f578b 2021-03-15 op message("Abort.");
1046 9a25f829 2021-03-14 op static struct vline *
1047 48e9d457 2021-03-06 op nth_line(struct tab *tab, size_t n)
1049 9a25f829 2021-03-14 op struct vline *vl;
1053 65d9b3ca 2021-03-14 op TAILQ_FOREACH(vl, &tab->s.head, vlines) {
1059 48e9d457 2021-03-06 op /* unreachable */
1063 5e11c00c 2021-03-02 op static struct tab *
1064 5e11c00c 2021-03-02 op current_tab(void)
1066 5e11c00c 2021-03-02 op struct tab *t;
1068 5e11c00c 2021-03-02 op TAILQ_FOREACH(t, &tabshead, tabs) {
1069 5e11c00c 2021-03-02 op if (t->flags & TAB_CURRENT)
1073 5e11c00c 2021-03-02 op /* unreachable */
1078 5e11c00c 2021-03-02 op dispatch_stdio(int fd, short ev, void *d)
1080 f832146f 2021-03-09 op struct keymap *k;
1081 7c7d7bb7 2021-03-10 op const char *keyname;
1082 7c7d7bb7 2021-03-10 op char tmp[2] = {0};
1084 9ca15951 2021-03-09 op thiskey.key = wgetch(body);
1085 9ca15951 2021-03-09 op if (thiskey.key == ERR)
1087 9ca15951 2021-03-09 op if (thiskey.key == 27) {
1088 f832146f 2021-03-09 op /* TODO: make escape-time customizable */
1090 9ca15951 2021-03-09 op thiskey.meta = 1;
1091 9ca15951 2021-03-09 op thiskey.key = wgetch(body);
1092 c314a314 2021-03-11 op if (thiskey.key == ERR || thiskey.key == 27) {
1093 c314a314 2021-03-11 op thiskey.meta = 0;
1094 9ca15951 2021-03-09 op thiskey.key = 27;
1097 9ca15951 2021-03-09 op thiskey.meta = 0;
1099 7c7d7bb7 2021-03-10 op if (keybuf[0] != '\0')
1100 7c7d7bb7 2021-03-10 op strlcat(keybuf, " ", sizeof(keybuf));
1101 7c7d7bb7 2021-03-10 op if (thiskey.meta)
1102 7c7d7bb7 2021-03-10 op strlcat(keybuf, "M-", sizeof(keybuf));
1103 7c7d7bb7 2021-03-10 op if ((keyname = unkbd(thiskey.key)) != NULL)
1104 7c7d7bb7 2021-03-10 op strlcat(keybuf, keyname, sizeof(keybuf));
1106 7c7d7bb7 2021-03-10 op tmp[0] = thiskey.key;
1107 7c7d7bb7 2021-03-10 op strlcat(keybuf, tmp, sizeof(keybuf));
1110 9ca15951 2021-03-09 op TAILQ_FOREACH(k, ¤t_map->m, keymaps) {
1111 9ca15951 2021-03-09 op if (k->meta == thiskey.meta &&
1112 9ca15951 2021-03-09 op k->key == thiskey.key) {
1113 f832146f 2021-03-09 op if (k->fn == NULL)
1114 f832146f 2021-03-09 op current_map = &k->map;
1116 9ca15951 2021-03-09 op current_map = base_map;
1117 7c7d7bb7 2021-03-10 op strlcpy(keybuf, "", sizeof(keybuf));
1118 f832146f 2021-03-09 op k->fn(current_tab());
1124 7c7d7bb7 2021-03-10 op if (current_map->unhandled_input != NULL)
1125 7c7d7bb7 2021-03-10 op current_map->unhandled_input();
1127 7c7d7bb7 2021-03-10 op global_key_unbound();
1130 7c7d7bb7 2021-03-10 op strlcpy(keybuf, "", sizeof(keybuf));
1131 9ca15951 2021-03-09 op current_map = base_map;
1134 179f0f58 2021-03-11 op redraw_tab(current_tab());
1138 a6d450c1 2021-03-06 op handle_clear_minibuf(int fd, short ev, void *d)
1140 9cb0f9ce 2021-03-10 op free(ministate.curmesg);
1141 9cb0f9ce 2021-03-10 op ministate.curmesg = NULL;
1143 9cb0f9ce 2021-03-10 op redraw_minibuffer();
1144 9cb0f9ce 2021-03-10 op if (in_minibuffer) {
1145 9cb0f9ce 2021-03-10 op wrefresh(body);
1146 9cb0f9ce 2021-03-10 op wrefresh(minibuf);
1148 9cb0f9ce 2021-03-10 op wrefresh(minibuf);
1149 9cb0f9ce 2021-03-10 op wrefresh(body);
1154 5e11c00c 2021-03-02 op handle_resize(int sig, short ev, void *d)
1156 1d08c280 2021-03-06 op struct tab *tab;
1162 48e9d457 2021-03-06 op /* move and resize the windows, in reverse order! */
1164 b1738d2e 2021-03-06 op mvwin(minibuf, LINES-1, 0);
1165 48e9d457 2021-03-06 op wresize(minibuf, 1, COLS);
1167 48e9d457 2021-03-06 op mvwin(modeline, LINES-2, 0);
1168 48e9d457 2021-03-06 op wresize(modeline, 1, COLS);
1170 48e9d457 2021-03-06 op wresize(body, LINES-3, COLS);
1171 48e9d457 2021-03-06 op body_lines = LINES-3;
1172 bd9637e9 2021-03-06 op body_cols = COLS;
1174 48e9d457 2021-03-06 op wresize(tabline, 1, COLS);
1176 1d08c280 2021-03-06 op tab = current_tab();
1178 1d08c280 2021-03-06 op wrap_page(tab);
1179 1d08c280 2021-03-06 op redraw_tab(tab);
1183 1d08c280 2021-03-06 op wrap_page(struct tab *tab)
1185 452589f7 2021-03-16 op struct line *l;
1186 452589f7 2021-03-16 op const struct line *orig;
1187 d511dc85 2021-03-16 op struct vline *vl;
1188 452589f7 2021-03-16 op const char *prfx;
1190 452589f7 2021-03-16 op orig = tab->s.current_line == NULL
1192 452589f7 2021-03-16 op : tab->s.current_line->parent;
1193 452589f7 2021-03-16 op tab->s.current_line = NULL;
1195 452589f7 2021-03-16 op tab->s.curs_y = 0;
1196 452589f7 2021-03-16 op tab->s.line_off = 0;
1198 1d08c280 2021-03-06 op empty_vlist(tab);
1200 5e11c00c 2021-03-02 op TAILQ_FOREACH(l, &tab->page.head, lines) {
1201 0d568960 2021-03-11 op prfx = line_prefixes[l->type].prfx1;
1202 5e11c00c 2021-03-02 op switch (l->type) {
1203 5e11c00c 2021-03-02 op case LINE_TEXT:
1204 5e11c00c 2021-03-02 op case LINE_LINK:
1205 5e11c00c 2021-03-02 op case LINE_TITLE_1:
1206 5e11c00c 2021-03-02 op case LINE_TITLE_2:
1207 5e11c00c 2021-03-02 op case LINE_TITLE_3:
1208 5e11c00c 2021-03-02 op case LINE_ITEM:
1209 5e11c00c 2021-03-02 op case LINE_QUOTE:
1210 5e11c00c 2021-03-02 op case LINE_PRE_START:
1211 5e11c00c 2021-03-02 op case LINE_PRE_END:
1212 65d9b3ca 2021-03-14 op wrap_text(tab, prfx, l, body_cols);
1214 5e11c00c 2021-03-02 op case LINE_PRE_CONTENT:
1215 65d9b3ca 2021-03-14 op hardwrap_text(tab, l, body_cols);
1219 452589f7 2021-03-16 op if (orig == l && tab->s.current_line == NULL) {
1220 452589f7 2021-03-16 op tab->s.line_off = tab->s.line_max-1;
1221 452589f7 2021-03-16 op tab->s.current_line = TAILQ_LAST(&tab->s.head, vhead);
1224 d511dc85 2021-03-16 op vl = TAILQ_PREV(tab->s.current_line, vhead, vlines);
1225 d511dc85 2021-03-16 op if (vl == NULL || vl->parent != orig)
1227 d511dc85 2021-03-16 op tab->s.current_line = vl;
1228 d511dc85 2021-03-16 op tab->s.line_off--;
1233 452589f7 2021-03-16 op if (tab->s.current_line == NULL)
1234 452589f7 2021-03-16 op tab->s.current_line = TAILQ_FIRST(&tab->s.head);
1240 9a25f829 2021-03-14 op print_vline(struct vline *vl)
1242 9a25f829 2021-03-14 op const char *text = vl->line;
1243 768db5bb 2021-03-12 op const char *prfx;
1244 803ff456 2021-03-17 op int prefix_face = line_faces[vl->parent->type].prefix_prop;
1245 803ff456 2021-03-17 op int text_face = line_faces[vl->parent->type].text_prop;
1247 9a25f829 2021-03-14 op if (!vl->flags)
1248 9a25f829 2021-03-14 op prfx = line_prefixes[vl->parent->type].prfx1;
1250 9a25f829 2021-03-14 op prfx = line_prefixes[vl->parent->type].prfx2;
1252 bd9637e9 2021-03-06 op if (text == NULL)
1255 803ff456 2021-03-17 op wattron(body, prefix_face);
1256 803ff456 2021-03-17 op wprintw(body, "%s", prfx);
1257 803ff456 2021-03-17 op wattroff(body, prefix_face);
1259 803ff456 2021-03-17 op wattron(body, text_face);
1260 803ff456 2021-03-17 op wprintw(body, "%s", text);
1261 803ff456 2021-03-17 op wattroff(body, text_face);
1265 8af5e5ed 2021-03-08 op redraw_tabline(void)
1267 7c7d7bb7 2021-03-10 op struct tab *tab;
1268 a636f50e 2021-03-16 op size_t toskip;
1269 a636f50e 2021-03-16 op int current, x, y, truncated;
1270 dc5df781 2021-03-13 op const char *title;
1271 119f393c 2021-03-16 op char buf[25];
1275 a636f50e 2021-03-16 op TAILQ_FOREACH(tab, &tabshead, tabs) {
1276 a636f50e 2021-03-16 op x += sizeof(buf) + 1;
1278 a636f50e 2021-03-16 op if (tab->flags & TAB_CURRENT)
1281 a636f50e 2021-03-16 op if (x < COLS-2)
1286 a636f50e 2021-03-16 op werase(tabline);
1287 cb6c7aa0 2021-03-16 op wattron(tabline, tab_face.background);
1288 a636f50e 2021-03-16 op wprintw(tabline, toskip == 0 ? " " : "<");
1289 cb6c7aa0 2021-03-16 op wattroff(tabline, tab_face.background);
1291 a636f50e 2021-03-16 op truncated = 0;
1292 7c7d7bb7 2021-03-10 op TAILQ_FOREACH(tab, &tabshead, tabs) {
1293 a636f50e 2021-03-16 op if (truncated)
1295 a636f50e 2021-03-16 op if (toskip != 0) {
1300 a636f50e 2021-03-16 op getyx(tabline, y, x);
1301 a636f50e 2021-03-16 op if (x + sizeof(buf)+2 >= (size_t)COLS)
1302 a636f50e 2021-03-16 op truncated = 1;
1304 7c7d7bb7 2021-03-10 op current = tab->flags & TAB_CURRENT;
1306 dc5df781 2021-03-13 op if (*(title = tab->page.title) == '\0')
1307 2051e653 2021-03-13 op title = tab->hist_cur->h;
1309 119f393c 2021-03-16 op strlcpy(buf, " ", sizeof(buf));
1310 119f393c 2021-03-16 op if (strlcat(buf, title, sizeof(buf)) >= sizeof(buf)) {
1311 119f393c 2021-03-16 op /* truncation happens */
1312 119f393c 2021-03-16 op strlcpy(&buf[sizeof(buf)-4], "...", 4);
1314 119f393c 2021-03-16 op /* pad with spaces */
1315 119f393c 2021-03-16 op while (strlcat(buf, " ", sizeof(buf)) < sizeof(buf))
1319 a329982b 2021-03-11 op if (current)
1320 cb6c7aa0 2021-03-16 op wattron(tabline, tab_face.current_tab);
1322 cb6c7aa0 2021-03-16 op wattron(tabline, tab_face.tab);
1324 119f393c 2021-03-16 op wprintw(tabline, "%s", buf);
1325 119f393c 2021-03-16 op if (TAILQ_NEXT(tab, tabs) != NULL)
1326 119f393c 2021-03-16 op wprintw(tabline, " ");
1328 cb6c7aa0 2021-03-16 op if (current)
1329 cb6c7aa0 2021-03-16 op wattroff(tabline, tab_face.current_tab);
1331 cb6c7aa0 2021-03-16 op wattroff(tabline, tab_face.tab);
1334 cb6c7aa0 2021-03-16 op wattron(tabline, tab_face.background);
1335 119f393c 2021-03-16 op for (; x < COLS; ++x)
1336 119f393c 2021-03-16 op waddch(tabline, ' ');
1337 a636f50e 2021-03-16 op if (truncated)
1338 a636f50e 2021-03-16 op mvwprintw(tabline, 0, COLS-1, ">");
1341 10346511 2021-03-17 op static inline char
1342 10346511 2021-03-17 op trust_status_char(enum trust_state ts)
1344 10346511 2021-03-17 op switch (ts) {
1345 10346511 2021-03-17 op case TS_UNKNOWN: return 'u';
1346 10346511 2021-03-17 op case TS_UNTRUSTED: return '!';
1347 10346511 2021-03-17 op case TS_TRUSTED: return 'v';
1348 10346511 2021-03-17 op case TS_VERIFIED: return 'V';
1353 48e9d457 2021-03-06 op redraw_modeline(struct tab *tab)
1356 48e9d457 2021-03-06 op int x, y, max_x, max_y;
1357 fc43eadd 2021-03-12 op const char *mode = tab->page.name;
1358 8af5e5ed 2021-03-08 op const char *spin = "-\\|/";
1360 156f1501 2021-03-13 op werase(modeline);
1361 48e9d457 2021-03-06 op wattron(modeline, A_REVERSE);
1362 48e9d457 2021-03-06 op wmove(modeline, 0, 0);
1364 10346511 2021-03-17 op wprintw(modeline, "-%c%c %s ",
1365 58c75fab 2021-03-16 op spin[tab->s.loading_anim_step],
1366 10346511 2021-03-17 op trust_status_char(tab->trust),
1367 58c75fab 2021-03-16 op mode == NULL ? "(none)" : mode);
1369 65d9b3ca 2021-03-14 op pct = (tab->s.line_off + tab->s.curs_y) * 100.0 / tab->s.line_max;
1371 754622a2 2021-03-15 op if (tab->s.line_max <= (size_t)body_lines)
1372 481340cc 2021-03-11 op wprintw(modeline, "All ");
1373 65d9b3ca 2021-03-14 op else if (tab->s.line_off == 0)
1374 481340cc 2021-03-11 op wprintw(modeline, "Top ");
1375 65d9b3ca 2021-03-14 op else if (tab->s.line_off + body_lines >= tab->s.line_max)
1376 481340cc 2021-03-11 op wprintw(modeline, "Bottom ");
1378 481340cc 2021-03-11 op wprintw(modeline, "%.0f%% ", pct);
1380 481340cc 2021-03-11 op wprintw(modeline, "%d/%d %s ",
1381 65d9b3ca 2021-03-14 op tab->s.line_off + tab->s.curs_y,
1382 65d9b3ca 2021-03-14 op tab->s.line_max,
1383 2051e653 2021-03-13 op tab->hist_cur->h);
1385 48e9d457 2021-03-06 op getyx(modeline, y, x);
1386 48e9d457 2021-03-06 op getmaxyx(modeline, max_y, max_x);
1389 48e9d457 2021-03-06 op (void)max_y;
1391 48e9d457 2021-03-06 op for (; x < max_x; ++x)
1392 48e9d457 2021-03-06 op waddstr(modeline, "-");
1396 9ca15951 2021-03-09 op redraw_minibuffer(void)
1398 22268e11 2021-03-11 op size_t skip = 0, off_x = 0, off_y = 0;
1400 156f1501 2021-03-13 op werase(minibuf);
1401 22268e11 2021-03-11 op if (in_minibuffer) {
1402 22268e11 2021-03-11 op mvwprintw(minibuf, 0, 0, "%s", ministate.prompt);
1403 22268e11 2021-03-11 op if (ministate.hist_cur != NULL)
1404 22268e11 2021-03-11 op wprintw(minibuf, "(%zu/%zu) ",
1405 22268e11 2021-03-11 op ministate.hist_off + 1,
1406 22268e11 2021-03-11 op ministate.history->len);
1408 22268e11 2021-03-11 op getyx(minibuf, off_y, off_x);
1410 754622a2 2021-03-15 op while (ministate.off - skip > (size_t)COLS / 2) {
1411 22268e11 2021-03-11 op skip += MIN(ministate.off/4, 1);
1414 22268e11 2021-03-11 op if (ministate.hist_cur != NULL)
1415 22268e11 2021-03-11 op wprintw(minibuf, "%s", ministate.hist_cur->h + skip);
1417 22268e11 2021-03-11 op wprintw(minibuf, "%s", ministate.buf + skip);
1420 9cb0f9ce 2021-03-10 op if (ministate.curmesg != NULL) {
1421 9cb0f9ce 2021-03-10 op if (in_minibuffer)
1422 9cb0f9ce 2021-03-10 op wprintw(minibuf, " [%s]", ministate.curmesg);
1424 9cb0f9ce 2021-03-10 op wprintw(minibuf, "%s", ministate.curmesg);
1427 91a72220 2021-03-13 op if (!in_minibuffer && ministate.curmesg == NULL)
1428 91a72220 2021-03-13 op wprintw(minibuf, "%s", keybuf);
1430 2aaf475e 2021-03-13 op if (in_minibuffer)
1431 2aaf475e 2021-03-13 op wmove(minibuf, 0, off_x + ministate.off - skip);
1435 48e9d457 2021-03-06 op redraw_tab(struct tab *tab)
1437 e19f9a04 2021-03-11 op redraw_tabline();
1438 e19f9a04 2021-03-11 op redraw_body(tab);
1439 e19f9a04 2021-03-11 op redraw_modeline(tab);
1440 e19f9a04 2021-03-11 op redraw_minibuffer();
1442 e19f9a04 2021-03-11 op restore_cursor(tab);
1443 e19f9a04 2021-03-11 op wrefresh(tabline);
1444 e19f9a04 2021-03-11 op wrefresh(modeline);
1446 e19f9a04 2021-03-11 op if (in_minibuffer) {
1447 e19f9a04 2021-03-11 op wrefresh(body);
1448 e19f9a04 2021-03-11 op wrefresh(minibuf);
1450 e19f9a04 2021-03-11 op wrefresh(minibuf);
1451 e19f9a04 2021-03-11 op wrefresh(body);
1456 e19f9a04 2021-03-11 op redraw_body(struct tab *tab)
1458 9a25f829 2021-03-14 op struct vline *vl;
1461 48e9d457 2021-03-06 op werase(body);
1463 65d9b3ca 2021-03-14 op tab->s.line_off = MIN(tab->s.line_max-1, tab->s.line_off);
1464 65d9b3ca 2021-03-14 op if (TAILQ_EMPTY(&tab->s.head))
1468 65d9b3ca 2021-03-14 op vl = nth_line(tab, tab->s.line_off);
1469 9a25f829 2021-03-14 op for (; vl != NULL; vl = TAILQ_NEXT(vl, vlines)) {
1470 48e9d457 2021-03-06 op wmove(body, line, 0);
1471 9a25f829 2021-03-14 op print_vline(vl);
1473 48e9d457 2021-03-06 op if (line == body_lines)
1479 740f578b 2021-03-15 op vmessage(const char *fmt, va_list ap)
1481 e0e26735 2021-03-16 op if (evtimer_pending(&clminibufev, NULL))
1482 7953dd72 2021-03-07 op evtimer_del(&clminibufev);
1483 7953dd72 2021-03-07 op evtimer_set(&clminibufev, handle_clear_minibuf, NULL);
1484 7953dd72 2021-03-07 op evtimer_add(&clminibufev, &clminibufev_timer);
1486 bf992581 2021-03-12 op free(ministate.curmesg);
1488 9cb0f9ce 2021-03-10 op /* TODO: what to do if the allocation fails here? */
1489 9cb0f9ce 2021-03-10 op if (vasprintf(&ministate.curmesg, fmt, ap) == -1)
1490 9cb0f9ce 2021-03-10 op ministate.curmesg = NULL;
1492 9cb0f9ce 2021-03-10 op redraw_minibuffer();
1493 9cb0f9ce 2021-03-10 op if (in_minibuffer) {
1494 9cb0f9ce 2021-03-10 op wrefresh(body);
1495 9cb0f9ce 2021-03-10 op wrefresh(minibuf);
1497 9cb0f9ce 2021-03-10 op wrefresh(minibuf);
1498 9cb0f9ce 2021-03-10 op wrefresh(body);
1503 740f578b 2021-03-15 op message(const char *fmt, ...)
1507 740f578b 2021-03-15 op va_start(ap, fmt);
1508 740f578b 2021-03-15 op vmessage(fmt, ap);
1513 8af5e5ed 2021-03-08 op start_loading_anim(struct tab *tab)
1515 65d9b3ca 2021-03-14 op if (tab->s.loading_anim)
1517 65d9b3ca 2021-03-14 op tab->s.loading_anim = 1;
1518 65d9b3ca 2021-03-14 op evtimer_set(&tab->s.loadingev, update_loading_anim, tab);
1519 65d9b3ca 2021-03-14 op evtimer_add(&tab->s.loadingev, &loadingev_timer);
1523 8af5e5ed 2021-03-08 op update_loading_anim(int fd, short ev, void *d)
1525 8af5e5ed 2021-03-08 op struct tab *tab = d;
1527 65d9b3ca 2021-03-14 op tab->s.loading_anim_step = (tab->s.loading_anim_step+1)%4;
1529 6347dcd0 2021-03-16 op if (tab->flags & TAB_CURRENT) {
1530 6347dcd0 2021-03-16 op redraw_modeline(tab);
1531 6347dcd0 2021-03-16 op wrefresh(modeline);
1532 6347dcd0 2021-03-16 op wrefresh(body);
1533 6347dcd0 2021-03-16 op if (in_minibuffer)
1534 6347dcd0 2021-03-16 op wrefresh(minibuf);
1537 65d9b3ca 2021-03-14 op evtimer_add(&tab->s.loadingev, &loadingev_timer);
1541 8af5e5ed 2021-03-08 op stop_loading_anim(struct tab *tab)
1543 65d9b3ca 2021-03-14 op if (!tab->s.loading_anim)
1545 65d9b3ca 2021-03-14 op evtimer_del(&tab->s.loadingev);
1546 65d9b3ca 2021-03-14 op tab->s.loading_anim = 0;
1547 65d9b3ca 2021-03-14 op tab->s.loading_anim_step = 0;
1549 43a1b8d0 2021-03-09 op redraw_modeline(tab);
1551 43a1b8d0 2021-03-09 op wrefresh(modeline);
1552 43a1b8d0 2021-03-09 op wrefresh(body);
1553 9ca15951 2021-03-09 op if (in_minibuffer)
1554 9ca15951 2021-03-09 op wrefresh(minibuf);
1558 43a1b8d0 2021-03-09 op load_url_in_tab(struct tab *tab, const char *url)
1560 43a1b8d0 2021-03-09 op empty_vlist(tab);
1561 8af5e5ed 2021-03-08 op message("Loading %s...", url);
1562 8af5e5ed 2021-03-08 op start_loading_anim(tab);
1563 8af5e5ed 2021-03-08 op load_url(tab, url);
1565 65d9b3ca 2021-03-14 op tab->s.curs_x = 0;
1566 65d9b3ca 2021-03-14 op tab->s.curs_y = 0;
1567 43a1b8d0 2021-03-09 op redraw_tab(tab);
1571 b360ebb3 2021-03-10 op enter_minibuffer(void (*self_insert_fn)(void), void (*donefn)(void),
1572 3148eeac 2021-03-13 op void (*abortfn)(void), struct histhead *hist)
1574 9ca15951 2021-03-09 op in_minibuffer = 1;
1575 fa3fd864 2021-03-10 op base_map = &minibuffer_map;
1576 fa3fd864 2021-03-10 op current_map = &minibuffer_map;
1578 fa3fd864 2021-03-10 op base_map->unhandled_input = self_insert_fn;
1580 b360ebb3 2021-03-10 op ministate.donefn = donefn;
1581 b360ebb3 2021-03-10 op ministate.abortfn = abortfn;
1582 9ca15951 2021-03-09 op memset(ministate.buf, 0, sizeof(ministate.buf));
1583 9ca15951 2021-03-09 op ministate.off = 0;
1584 bb4e4ddf 2021-03-12 op ministate.len = 0;
1585 9ca15951 2021-03-09 op strlcpy(ministate.buf, "", sizeof(ministate.prompt));
1587 22268e11 2021-03-11 op ministate.history = hist;
1588 22268e11 2021-03-11 op ministate.hist_cur = NULL;
1589 22268e11 2021-03-11 op ministate.hist_off = 0;
1593 b360ebb3 2021-03-10 op exit_minibuffer(void)
1595 156f1501 2021-03-13 op werase(minibuf);
1597 9ca15951 2021-03-09 op in_minibuffer = 0;
1598 9ca15951 2021-03-09 op base_map = &global_map;
1599 9ca15951 2021-03-09 op current_map = &global_map;
1603 5cd2ebb1 2021-03-11 op switch_to_tab(struct tab *tab)
1605 5cd2ebb1 2021-03-11 op struct tab *t;
1607 5cd2ebb1 2021-03-11 op TAILQ_FOREACH(t, &tabshead, tabs) {
1608 5cd2ebb1 2021-03-11 op t->flags &= ~TAB_CURRENT;
1611 5cd2ebb1 2021-03-11 op tab->flags |= TAB_CURRENT;
1614 b1df9b71 2021-03-12 op static struct tab *
1615 1b81bc33 2021-03-15 op new_tab(const char *url)
1617 754622a2 2021-03-15 op struct tab *tab;
1619 71105afa 2021-03-16 op if ((tab = calloc(1, sizeof(*tab))) == NULL) {
1620 71105afa 2021-03-16 op event_loopbreak();
1621 71105afa 2021-03-16 op return NULL;
1624 2051e653 2021-03-13 op TAILQ_INIT(&tab->hist.head);
1626 65d9b3ca 2021-03-14 op TAILQ_INIT(&tab->s.head);
1628 bcb0b073 2021-03-07 op tab->id = tab_counter++;
1629 5cd2ebb1 2021-03-11 op switch_to_tab(tab);
1631 bcb0b073 2021-03-07 op if (TAILQ_EMPTY(&tabshead))
1632 bcb0b073 2021-03-07 op TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
1634 bcb0b073 2021-03-07 op TAILQ_INSERT_TAIL(&tabshead, tab, tabs);
1636 43a1b8d0 2021-03-09 op load_url_in_tab(tab, url);
1641 5e11c00c 2021-03-02 op ui_init(void)
1643 5e11c00c 2021-03-02 op setlocale(LC_ALL, "");
1645 9ca15951 2021-03-09 op TAILQ_INIT(&global_map.m);
1646 9ca15951 2021-03-09 op global_map.unhandled_input = global_key_unbound;
1648 fa3fd864 2021-03-10 op TAILQ_INIT(&minibuffer_map.m);
1650 22268e11 2021-03-11 op TAILQ_INIT(&eecmd_history.head);
1651 22268e11 2021-03-11 op TAILQ_INIT(&ir_history.head);
1652 22268e11 2021-03-11 op TAILQ_INIT(&lu_history.head);
1654 9ca15951 2021-03-09 op base_map = &global_map;
1655 f832146f 2021-03-09 op current_map = &global_map;
1656 f832146f 2021-03-09 op load_default_keys();
1663 5e11c00c 2021-03-02 op intrflush(stdscr, FALSE);
1665 48e9d457 2021-03-06 op if ((tabline = newwin(1, COLS, 0, 0)) == NULL)
1667 48e9d457 2021-03-06 op if ((body = newwin(LINES - 3, COLS, 1, 0)) == NULL)
1669 48e9d457 2021-03-06 op if ((modeline = newwin(1, COLS, LINES-2, 0)) == NULL)
1671 48e9d457 2021-03-06 op if ((minibuf = newwin(1, COLS, LINES-1, 0)) == NULL)
1674 48e9d457 2021-03-06 op body_lines = LINES-3;
1675 48e9d457 2021-03-06 op body_cols = COLS;
1677 43a1b8d0 2021-03-09 op keypad(body, TRUE);
1678 48e9d457 2021-03-06 op scrollok(body, TRUE);
1680 5e11c00c 2021-03-02 op /* non-blocking input */
1681 48e9d457 2021-03-06 op wtimeout(body, 0);
1683 48e9d457 2021-03-06 op mvwprintw(body, 0, 0, "");
1685 5e11c00c 2021-03-02 op event_set(&stdioev, 0, EV_READ | EV_PERSIST, dispatch_stdio, NULL);
1686 5e11c00c 2021-03-02 op event_add(&stdioev, NULL);
1688 5e11c00c 2021-03-02 op signal_set(&winchev, SIGWINCH, handle_resize, NULL);
1689 5e11c00c 2021-03-02 op signal_add(&winchev, NULL);
1691 1b81bc33 2021-03-15 op new_tab(NEW_TAB_URL);
1697 8af5e5ed 2021-03-08 op ui_on_tab_loaded(struct tab *tab)
1699 8af5e5ed 2021-03-08 op stop_loading_anim(tab);
1700 2051e653 2021-03-13 op message("Loaded %s", tab->hist_cur->h);
1704 5e11c00c 2021-03-02 op ui_on_tab_refresh(struct tab *tab)
1706 5e11c00c 2021-03-02 op if (!(tab->flags & TAB_CURRENT))
1709 1d08c280 2021-03-06 op wrap_page(tab);
1710 5e11c00c 2021-03-02 op redraw_tab(tab);
1714 5cd2ebb1 2021-03-11 op ui_require_input(struct tab *tab, int hide)
1716 5cd2ebb1 2021-03-11 op /* TODO: hard-switching to another tab is ugly */
1717 5cd2ebb1 2021-03-11 op switch_to_tab(tab);
1719 22268e11 2021-03-11 op enter_minibuffer(ir_self_insert, ir_select, exit_minibuffer,
1720 22268e11 2021-03-11 op &ir_history);
1721 5cd2ebb1 2021-03-11 op strlcpy(ministate.prompt, "Input required: ",
1722 5cd2ebb1 2021-03-11 op sizeof(ministate.prompt));
1723 5cd2ebb1 2021-03-11 op redraw_tab(tab);
1727 740f578b 2021-03-15 op ui_notify(const char *fmt, ...)
1731 740f578b 2021-03-15 op va_start(ap, fmt);
1732 740f578b 2021-03-15 op vmessage(fmt, ap);
1737 5e11c00c 2021-03-02 op ui_end(void)