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_forward_char(struct tab*);
62 46a9311e 2021-03-08 op static void cmd_backward_char(struct tab*);
63 a329982b 2021-03-11 op static void cmd_move_beginning_of_line(struct tab*);
64 a329982b 2021-03-11 op static void cmd_move_end_of_line(struct tab*);
65 46a9311e 2021-03-08 op static void cmd_redraw(struct tab*);
66 ed44414d 2021-03-09 op static void cmd_scroll_line_down(struct tab*);
67 ed44414d 2021-03-09 op static void cmd_scroll_line_up(struct tab*);
68 46a9311e 2021-03-08 op static void cmd_scroll_up(struct tab*);
69 ed44414d 2021-03-09 op static void cmd_scroll_down(struct tab*);
70 e19f9a04 2021-03-11 op static void cmd_beginning_of_buffer(struct tab*);
71 e19f9a04 2021-03-11 op static void cmd_end_of_buffer(struct tab*);
72 46a9311e 2021-03-08 op static void cmd_kill_telescope(struct tab*);
73 46a9311e 2021-03-08 op static void cmd_push_button(struct tab*);
74 b1df9b71 2021-03-12 op static void cmd_push_button_new_tab(struct tab*);
75 a8c28919 2021-03-16 op static void cmd_previous_button(struct tab*);
76 a8c28919 2021-03-16 op static void cmd_next_button(struct tab*);
77 2051e653 2021-03-13 op static void cmd_previous_page(struct tab*);
78 2051e653 2021-03-13 op static void cmd_next_page(struct tab*);
79 3b4f9e49 2021-03-11 op static void cmd_clear_minibuf(struct tab*);
80 9ca15951 2021-03-09 op static void cmd_execute_extended_command(struct tab*);
81 7c7d7bb7 2021-03-10 op static void cmd_tab_close(struct tab*);
82 fea845b6 2021-03-15 op static void cmd_tab_close_other(struct tab*);
83 7c7d7bb7 2021-03-10 op static void cmd_tab_new(struct tab*);
84 7c7d7bb7 2021-03-10 op static void cmd_tab_next(struct tab*);
85 7c7d7bb7 2021-03-10 op static void cmd_tab_previous(struct tab*);
86 5cd2ebb1 2021-03-11 op static void cmd_load_url(struct tab*);
87 5cd2ebb1 2021-03-11 op static void cmd_load_current_url(struct tab*);
88 740f578b 2021-03-15 op static void cmd_bookmark_page(struct tab*);
89 de0b2139 2021-03-15 op static void cmd_goto_bookmarks(struct tab*);
91 9ca15951 2021-03-09 op static void global_key_unbound(void);
93 d67133bf 2021-03-12 op static void cmd_mini_delete_char(struct tab*);
94 d67133bf 2021-03-12 op static void cmd_mini_delete_backward_char(struct tab*);
95 9ca15951 2021-03-09 op static void cmd_mini_forward_char(struct tab*);
96 9ca15951 2021-03-09 op static void cmd_mini_backward_char(struct tab*);
97 9ca15951 2021-03-09 op static void cmd_mini_move_end_of_line(struct tab*);
98 9ca15951 2021-03-09 op static void cmd_mini_move_beginning_of_line(struct tab*);
99 fa3fd864 2021-03-10 op static void cmd_mini_kill_line(struct tab*);
100 22268e11 2021-03-11 op static void cmd_mini_abort(struct tab*);
101 22268e11 2021-03-11 op static void cmd_mini_complete_and_exit(struct tab*);
102 22268e11 2021-03-11 op static void cmd_mini_previous_history_element(struct tab*);
103 22268e11 2021-03-11 op static void cmd_mini_next_history_element(struct tab*);
105 22268e11 2021-03-11 op static void minibuffer_hist_save_entry(void);
106 22268e11 2021-03-11 op static void minibuffer_taint_hist(void);
107 5cd2ebb1 2021-03-11 op static void minibuffer_self_insert(void);
108 9ca15951 2021-03-09 op static void eecmd_self_insert(void);
109 b360ebb3 2021-03-10 op static void eecmd_select(void);
110 5cd2ebb1 2021-03-11 op static void ir_self_insert(void);
111 5cd2ebb1 2021-03-11 op static void ir_select(void);
112 5cd2ebb1 2021-03-11 op static void lu_self_insert(void);
113 5cd2ebb1 2021-03-11 op static void lu_select(void);
114 740f578b 2021-03-15 op static void bp_select(void);
116 9a25f829 2021-03-14 op static struct vline *nth_line(struct tab*, size_t);
117 5e11c00c 2021-03-02 op static struct tab *current_tab(void);
118 5e11c00c 2021-03-02 op static void dispatch_stdio(int, short, void*);
119 a6d450c1 2021-03-06 op static void handle_clear_minibuf(int, short, void*);
120 5e11c00c 2021-03-02 op static void handle_resize(int, short, void*);
121 1d08c280 2021-03-06 op static int wrap_page(struct tab*);
122 9a25f829 2021-03-14 op static void print_vline(struct vline*);
123 8af5e5ed 2021-03-08 op static void redraw_tabline(void);
124 e19f9a04 2021-03-11 op static void redraw_body(struct tab*);
125 8af5e5ed 2021-03-08 op static void redraw_modeline(struct tab*);
126 9ca15951 2021-03-09 op static void redraw_minibuffer(void);
127 5e11c00c 2021-03-02 op static void redraw_tab(struct tab*);
128 740f578b 2021-03-15 op static void vmessage(const char*, va_list);
129 7953dd72 2021-03-07 op static void message(const char*, ...) __attribute__((format(printf, 1, 2)));
130 8af5e5ed 2021-03-08 op static void start_loading_anim(struct tab*);
131 8af5e5ed 2021-03-08 op static void update_loading_anim(int, short, void*);
132 8af5e5ed 2021-03-08 op static void stop_loading_anim(struct tab*);
133 43a1b8d0 2021-03-09 op static void load_url_in_tab(struct tab*, const char*);
134 3148eeac 2021-03-13 op static void enter_minibuffer(void(*)(void), void(*)(void), void(*)(void), struct histhead*);
135 b360ebb3 2021-03-10 op static void exit_minibuffer(void);
136 5cd2ebb1 2021-03-11 op static void switch_to_tab(struct tab*);
137 1b81bc33 2021-03-15 op static struct tab *new_tab(const char*);
139 9ca15951 2021-03-09 op static struct { int meta, key; } thiskey;
141 48e9d457 2021-03-06 op static WINDOW *tabline, *body, *modeline, *minibuf;
142 48e9d457 2021-03-06 op static int body_lines, body_cols;
144 48e9d457 2021-03-06 op static struct event clminibufev;
145 a6d450c1 2021-03-06 op static struct timeval clminibufev_timer = { 5, 0 };
146 8af5e5ed 2021-03-08 op static struct timeval loadingev_timer = { 0, 250000 };
148 bcb0b073 2021-03-07 op static uint32_t tab_counter;
150 7c7d7bb7 2021-03-10 op static char keybuf[64];
152 9ca15951 2021-03-09 op struct kmap global_map,
153 fa3fd864 2021-03-10 op minibuffer_map,
154 9ca15951 2021-03-09 op *current_map,
157 3148eeac 2021-03-13 op static struct histhead eecmd_history,
161 9ca15951 2021-03-09 op static int in_minibuffer;
163 9ca15951 2021-03-09 op static struct {
164 9cb0f9ce 2021-03-10 op char *curmesg;
166 040fbdf8 2021-03-10 op char buf[1025];
167 9ca15951 2021-03-09 op size_t off, len;
168 5cd2ebb1 2021-03-11 op char prompt[32];
169 b360ebb3 2021-03-10 op void (*donefn)(void);
170 b360ebb3 2021-03-10 op void (*abortfn)(void);
172 3148eeac 2021-03-13 op struct histhead *history;
173 3148eeac 2021-03-13 op struct hist *hist_cur;
174 22268e11 2021-03-11 op size_t hist_off;
177 f95d82dd 2021-03-11 op struct lineprefix {
178 f95d82dd 2021-03-11 op const char *prfx1;
179 f95d82dd 2021-03-11 op const char *prfx2;
180 f95d82dd 2021-03-11 op } line_prefixes[] = {
181 f95d82dd 2021-03-11 op [LINE_TEXT] = { "", "" },
182 f95d82dd 2021-03-11 op [LINE_LINK] = { "=> ", " " },
183 f95d82dd 2021-03-11 op [LINE_TITLE_1] = { "# ", " " },
184 f95d82dd 2021-03-11 op [LINE_TITLE_2] = { "## ", " " },
185 f95d82dd 2021-03-11 op [LINE_TITLE_3] = { "### ", " " },
186 f95d82dd 2021-03-11 op [LINE_ITEM] = { "* ", " " },
187 f95d82dd 2021-03-11 op [LINE_QUOTE] = { "> ", "> " },
188 803ff456 2021-03-17 op [LINE_PRE_START] = { "```", " " },
189 f95d82dd 2021-03-11 op [LINE_PRE_CONTENT] = { "", "" },
190 f95d82dd 2021-03-11 op [LINE_PRE_END] = { "```", "```" },
193 31840026 2021-03-16 op static struct line_face {
194 803ff456 2021-03-17 op int prefix_prop;
195 803ff456 2021-03-17 op int text_prop;
196 d3d56d8a 2021-03-11 op } line_faces[] = {
197 803ff456 2021-03-17 op [LINE_TEXT] = { 0, 0 },
198 803ff456 2021-03-17 op [LINE_LINK] = { 0, A_UNDERLINE },
199 803ff456 2021-03-17 op [LINE_TITLE_1] = { A_BOLD, A_BOLD },
200 803ff456 2021-03-17 op [LINE_TITLE_2] = { A_BOLD, A_BOLD },
201 803ff456 2021-03-17 op [LINE_TITLE_3] = { A_BOLD, A_BOLD },
202 803ff456 2021-03-17 op [LINE_ITEM] = { 0, 0 },
203 803ff456 2021-03-17 op [LINE_QUOTE] = { 0, A_DIM },
204 803ff456 2021-03-17 op [LINE_PRE_START] = { 0, 0 },
205 803ff456 2021-03-17 op [LINE_PRE_CONTENT] = { 0, 0 },
206 803ff456 2021-03-17 op [LINE_PRE_END] = { 0, 0 },
209 cb6c7aa0 2021-03-16 op static struct tab_face {
210 cb6c7aa0 2021-03-16 op int background, tab, current_tab;
211 cb6c7aa0 2021-03-16 op } tab_face = {
212 cb6c7aa0 2021-03-16 op A_REVERSE, A_REVERSE, A_NORMAL
216 65d9b3ca 2021-03-14 op empty_vlist(struct tab *tab)
218 65d9b3ca 2021-03-14 op struct vline *vl, *t;
220 452589f7 2021-03-16 op tab->s.current_line = NULL;
221 65d9b3ca 2021-03-14 op tab->s.line_max = 0;
223 65d9b3ca 2021-03-14 op TAILQ_FOREACH_SAFE(vl, &tab->s.head, vlines, t) {
224 65d9b3ca 2021-03-14 op TAILQ_REMOVE(&tab->s.head, vl, vlines);
225 65d9b3ca 2021-03-14 op free(vl->line);
230 f832146f 2021-03-09 op static inline void
231 f832146f 2021-03-09 op global_set_key(const char *key, void (*fn)(struct tab*))
233 67c8ed7f 2021-03-13 op if (!kmap_define_key(&global_map, key, fn))
237 9ca15951 2021-03-09 op static inline void
238 fa3fd864 2021-03-10 op minibuffer_set_key(const char *key, void (*fn)(struct tab*))
240 67c8ed7f 2021-03-13 op if (!kmap_define_key(&minibuffer_map, key, fn))
245 f832146f 2021-03-09 op load_default_keys(void)
247 9ca15951 2021-03-09 op /* === global map === */
250 f832146f 2021-03-09 op global_set_key("C-p", cmd_previous_line);
251 f832146f 2021-03-09 op global_set_key("C-n", cmd_next_line);
252 f832146f 2021-03-09 op global_set_key("C-f", cmd_forward_char);
253 f832146f 2021-03-09 op global_set_key("C-b", cmd_backward_char);
254 a329982b 2021-03-11 op global_set_key("C-a", cmd_move_beginning_of_line);
255 a329982b 2021-03-11 op global_set_key("C-e", cmd_move_end_of_line);
257 f832146f 2021-03-09 op global_set_key("M-v", cmd_scroll_up);
258 f832146f 2021-03-09 op global_set_key("C-v", cmd_scroll_down);
259 929c2d9f 2021-03-13 op global_set_key("M-space", cmd_scroll_up);
260 929c2d9f 2021-03-13 op global_set_key("space", cmd_scroll_down);
262 f832146f 2021-03-09 op global_set_key("C-x C-c", cmd_kill_telescope);
264 3b4f9e49 2021-03-11 op global_set_key("C-g", cmd_clear_minibuf);
266 9ca15951 2021-03-09 op global_set_key("M-x", cmd_execute_extended_command);
267 5cd2ebb1 2021-03-11 op global_set_key("C-x C-f", cmd_load_url);
268 5cd2ebb1 2021-03-11 op global_set_key("C-x M-f", cmd_load_current_url);
270 7c7d7bb7 2021-03-10 op global_set_key("C-x t 0", cmd_tab_close);
271 fea845b6 2021-03-15 op global_set_key("C-x t 1", cmd_tab_close_other);
272 7c7d7bb7 2021-03-10 op global_set_key("C-x t 2", cmd_tab_new);
273 7c7d7bb7 2021-03-10 op global_set_key("C-x t o", cmd_tab_next);
274 7c7d7bb7 2021-03-10 op global_set_key("C-x t O", cmd_tab_previous);
276 e19f9a04 2021-03-11 op global_set_key("M-<", cmd_beginning_of_buffer);
277 e19f9a04 2021-03-11 op global_set_key("M->", cmd_end_of_buffer);
279 2051e653 2021-03-13 op global_set_key("C-M-b", cmd_previous_page);
280 2051e653 2021-03-13 op global_set_key("C-M-f", cmd_next_page);
282 740f578b 2021-03-15 op global_set_key("<f7> a", cmd_bookmark_page);
283 de0b2139 2021-03-15 op global_set_key("<f7> <f7>", cmd_goto_bookmarks);
285 f832146f 2021-03-09 op /* vi/vi-like */
286 f832146f 2021-03-09 op global_set_key("k", cmd_previous_line);
287 f832146f 2021-03-09 op global_set_key("j", cmd_next_line);
288 f832146f 2021-03-09 op global_set_key("l", cmd_forward_char);
289 f832146f 2021-03-09 op global_set_key("h", cmd_backward_char);
290 a329982b 2021-03-11 op global_set_key("^", cmd_move_beginning_of_line);
291 a329982b 2021-03-11 op global_set_key("$", cmd_move_end_of_line);
293 ed44414d 2021-03-09 op global_set_key("K", cmd_scroll_line_up);
294 ed44414d 2021-03-09 op global_set_key("J", cmd_scroll_line_down);
296 a02335e9 2021-03-15 op global_set_key("g D", cmd_tab_close);
297 a02335e9 2021-03-15 op global_set_key("g N", cmd_tab_new);
298 a02335e9 2021-03-15 op global_set_key("g t", cmd_tab_next);
299 a02335e9 2021-03-15 op global_set_key("g T", cmd_tab_previous);
301 e19f9a04 2021-03-11 op global_set_key("g g", cmd_beginning_of_buffer);
302 e19f9a04 2021-03-11 op global_set_key("G", cmd_end_of_buffer);
304 2051e653 2021-03-13 op global_set_key("H", cmd_previous_page);
305 2051e653 2021-03-13 op global_set_key("L", cmd_next_page);
308 f832146f 2021-03-09 op global_set_key("q", cmd_kill_telescope);
310 3b4f9e49 2021-03-11 op global_set_key("esc", cmd_clear_minibuf);
312 9ca15951 2021-03-09 op global_set_key(":", cmd_execute_extended_command);
315 f832146f 2021-03-09 op global_set_key("<up>", cmd_previous_line);
316 f832146f 2021-03-09 op global_set_key("<down>", cmd_next_line);
317 f832146f 2021-03-09 op global_set_key("<right>", cmd_forward_char);
318 f832146f 2021-03-09 op global_set_key("<left>", cmd_backward_char);
319 ed44414d 2021-03-09 op global_set_key("<prior>", cmd_scroll_up);
320 ed44414d 2021-03-09 op global_set_key("<next>", cmd_scroll_down);
322 2051e653 2021-03-13 op global_set_key("M-<left>", cmd_previous_page);
323 2051e653 2021-03-13 op global_set_key("M-<right>", cmd_next_page);
325 f832146f 2021-03-09 op /* "ncurses standard" */
326 f832146f 2021-03-09 op global_set_key("C-l", cmd_redraw);
329 f832146f 2021-03-09 op global_set_key("C-m", cmd_push_button);
330 b1df9b71 2021-03-12 op global_set_key("M-enter", cmd_push_button_new_tab);
331 a8c28919 2021-03-16 op global_set_key("M-tab", cmd_previous_button);
332 a8c28919 2021-03-16 op global_set_key("tab", cmd_next_button);
334 fa3fd864 2021-03-10 op /* === minibuffer map === */
335 b360ebb3 2021-03-10 op minibuffer_set_key("ret", cmd_mini_complete_and_exit);
336 b360ebb3 2021-03-10 op minibuffer_set_key("C-g", cmd_mini_abort);
337 b360ebb3 2021-03-10 op minibuffer_set_key("esc", cmd_mini_abort);
338 d67133bf 2021-03-12 op minibuffer_set_key("C-d", cmd_mini_delete_char);
339 d67133bf 2021-03-12 op minibuffer_set_key("del", cmd_mini_delete_backward_char);
341 fa3fd864 2021-03-10 op minibuffer_set_key("C-f", cmd_mini_forward_char);
342 fa3fd864 2021-03-10 op minibuffer_set_key("C-b", cmd_mini_backward_char);
343 5b2bf704 2021-03-12 op minibuffer_set_key("<right>", cmd_mini_forward_char);
344 5b2bf704 2021-03-12 op minibuffer_set_key("<left>", cmd_mini_backward_char);
345 fa3fd864 2021-03-10 op minibuffer_set_key("C-e", cmd_mini_move_end_of_line);
346 fa3fd864 2021-03-10 op minibuffer_set_key("C-a", cmd_mini_move_beginning_of_line);
347 fa3fd864 2021-03-10 op minibuffer_set_key("<end>", cmd_mini_move_end_of_line);
348 fa3fd864 2021-03-10 op minibuffer_set_key("<home>", cmd_mini_move_beginning_of_line);
349 fa3fd864 2021-03-10 op minibuffer_set_key("C-k", cmd_mini_kill_line);
351 22268e11 2021-03-11 op minibuffer_set_key("M-p", cmd_mini_previous_history_element);
352 22268e11 2021-03-11 op minibuffer_set_key("M-n", cmd_mini_next_history_element);
353 22268e11 2021-03-11 op minibuffer_set_key("<up>", cmd_mini_previous_history_element);
354 22268e11 2021-03-11 op minibuffer_set_key("<down>", cmd_mini_next_history_element);
358 48e9d457 2021-03-06 op restore_cursor(struct tab *tab)
360 452589f7 2021-03-16 op struct vline *vl;
361 452589f7 2021-03-16 op const char *prfx;
363 452589f7 2021-03-16 op vl =tab->s.current_line;
364 452589f7 2021-03-16 op if (vl == NULL || vl->line == NULL)
365 452589f7 2021-03-16 op tab->s.curs_x = tab->s.line_x = 0;
367 452589f7 2021-03-16 op tab->s.line_x = MIN(tab->s.line_x, strlen(vl->line));
369 452589f7 2021-03-16 op if (vl != NULL) {
370 452589f7 2021-03-16 op prfx = line_prefixes[vl->parent->type].prfx1;
371 452589f7 2021-03-16 op tab->s.curs_x = tab->s.line_x + strlen(prfx);
374 65d9b3ca 2021-03-14 op wmove(body, tab->s.curs_y, tab->s.curs_x);
378 46a9311e 2021-03-08 op cmd_previous_line(struct tab *tab)
380 452589f7 2021-03-16 op struct vline *vl;
382 452589f7 2021-03-16 op if (tab->s.current_line == NULL
383 452589f7 2021-03-16 op || (vl = TAILQ_PREV(tab->s.current_line, vhead, vlines)) == NULL)
386 65d9b3ca 2021-03-14 op if (--tab->s.curs_y < 0) {
387 65d9b3ca 2021-03-14 op tab->s.curs_y = 0;
388 ed44414d 2021-03-09 op cmd_scroll_line_up(tab);
392 452589f7 2021-03-16 op tab->s.current_line = vl;
393 48e9d457 2021-03-06 op restore_cursor(tab);
397 46a9311e 2021-03-08 op cmd_next_line(struct tab *tab)
399 452589f7 2021-03-16 op struct vline *vl;
401 452589f7 2021-03-16 op if (tab->s.current_line == NULL
402 452589f7 2021-03-16 op || (vl = TAILQ_NEXT(tab->s.current_line, vlines)) == NULL)
405 65d9b3ca 2021-03-14 op if (++tab->s.curs_y > body_lines-1) {
406 65d9b3ca 2021-03-14 op tab->s.curs_y = body_lines-1;
407 ed44414d 2021-03-09 op cmd_scroll_line_down(tab);
411 452589f7 2021-03-16 op tab->s.current_line = vl;
412 48e9d457 2021-03-06 op restore_cursor(tab);
416 46a9311e 2021-03-08 op cmd_forward_char(struct tab *tab)
418 452589f7 2021-03-16 op tab->s.line_x++;
419 48e9d457 2021-03-06 op restore_cursor(tab);
423 46a9311e 2021-03-08 op cmd_backward_char(struct tab *tab)
425 452589f7 2021-03-16 op if (tab->s.line_x != 0)
426 452589f7 2021-03-16 op tab->s.line_x--;
427 a329982b 2021-03-11 op restore_cursor(tab);
431 a329982b 2021-03-11 op cmd_move_beginning_of_line(struct tab *tab)
433 452589f7 2021-03-16 op tab->s.line_x = 0;
434 a329982b 2021-03-11 op restore_cursor(tab);
438 a329982b 2021-03-11 op cmd_move_end_of_line(struct tab *tab)
440 9a25f829 2021-03-14 op struct vline *vl;
442 452589f7 2021-03-16 op vl = tab->s.current_line;
443 452589f7 2021-03-16 op if (vl->line == NULL)
445 452589f7 2021-03-16 op tab->s.line_x = body_cols;
446 48e9d457 2021-03-06 op restore_cursor(tab);
450 46a9311e 2021-03-08 op cmd_redraw(struct tab *tab)
452 b1738d2e 2021-03-06 op handle_resize(0, 0, NULL);
456 ed44414d 2021-03-09 op cmd_scroll_line_up(struct tab *tab)
458 9a25f829 2021-03-14 op struct vline *vl;
460 65d9b3ca 2021-03-14 op if (tab->s.line_off == 0)
463 65d9b3ca 2021-03-14 op vl = nth_line(tab, --tab->s.line_off);
464 48e9d457 2021-03-06 op wscrl(body, -1);
465 48e9d457 2021-03-06 op wmove(body, 0, 0);
466 9a25f829 2021-03-14 op print_vline(vl);
468 452589f7 2021-03-16 op tab->s.current_line = TAILQ_PREV(tab->s.current_line, vhead, vlines);
472 ed44414d 2021-03-09 op cmd_scroll_line_down(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 = TAILQ_NEXT(vl, vlines)) == NULL)
479 452589f7 2021-03-16 op tab->s.current_line = vl;
481 65d9b3ca 2021-03-14 op tab->s.line_off++;
482 48e9d457 2021-03-06 op wscrl(body, 1);
484 754622a2 2021-03-15 op if (tab->s.line_max - tab->s.line_off < (size_t)body_lines)
487 65d9b3ca 2021-03-14 op vl = nth_line(tab, tab->s.line_off + body_lines-1);
488 48e9d457 2021-03-06 op wmove(body, body_lines-1, 0);
489 9a25f829 2021-03-14 op print_vline(vl);
493 ed44414d 2021-03-09 op cmd_scroll_up(struct tab *tab)
497 ed44414d 2021-03-09 op off = body_lines+1;
499 ed44414d 2021-03-09 op for (; off > 0; --off)
500 ed44414d 2021-03-09 op cmd_scroll_line_up(tab);
504 ed44414d 2021-03-09 op cmd_scroll_down(struct tab *tab)
508 338eecdc 2021-03-12 op off = body_lines+1;
510 338eecdc 2021-03-12 op for (; off > 0; --off)
511 ed44414d 2021-03-09 op cmd_scroll_line_down(tab);
515 e19f9a04 2021-03-11 op cmd_beginning_of_buffer(struct tab *tab)
517 452589f7 2021-03-16 op tab->s.current_line = TAILQ_FIRST(&tab->s.head);
518 65d9b3ca 2021-03-14 op tab->s.line_off = 0;
519 65d9b3ca 2021-03-14 op tab->s.curs_y = 0;
520 452589f7 2021-03-16 op tab->s.line_x = 0;
521 452589f7 2021-03-16 op restore_cursor(tab);
522 e19f9a04 2021-03-11 op redraw_body(tab);
526 e19f9a04 2021-03-11 op cmd_end_of_buffer(struct tab *tab)
530 65d9b3ca 2021-03-14 op off = tab->s.line_max - body_lines;
531 e19f9a04 2021-03-11 op off = MAX(0, off);
533 65d9b3ca 2021-03-14 op tab->s.line_off = off;
534 452589f7 2021-03-16 op tab->s.curs_y = MIN((size_t)body_lines, tab->s.line_max-1);
536 452589f7 2021-03-16 op tab->s.current_line = TAILQ_LAST(&tab->s.head, vhead);
537 452589f7 2021-03-16 op tab->s.line_x = body_cols;
538 452589f7 2021-03-16 op restore_cursor(tab);
539 e19f9a04 2021-03-11 op redraw_body(tab);
543 46a9311e 2021-03-08 op cmd_kill_telescope(struct tab *tab)
545 1d08c280 2021-03-06 op event_loopbreak();
549 46a9311e 2021-03-08 op cmd_push_button(struct tab *tab)
551 9a25f829 2021-03-14 op struct vline *vl;
554 65d9b3ca 2021-03-14 op nth = tab->s.line_off + tab->s.curs_y;
555 65d9b3ca 2021-03-14 op if (nth >= tab->s.line_max)
557 9a25f829 2021-03-14 op vl = nth_line(tab, nth);
558 9a25f829 2021-03-14 op if (vl->parent->type != LINE_LINK)
561 9a25f829 2021-03-14 op load_url_in_tab(tab, vl->parent->alt);
565 b1df9b71 2021-03-12 op cmd_push_button_new_tab(struct tab *tab)
567 9a25f829 2021-03-14 op struct vline *vl;
570 65d9b3ca 2021-03-14 op nth = tab->s.line_off + tab->s.curs_y;
571 65d9b3ca 2021-03-14 op if (nth > tab->s.line_max)
573 9a25f829 2021-03-14 op vl = nth_line(tab, nth);
574 9a25f829 2021-03-14 op if (vl->parent->type != LINE_LINK)
577 1b81bc33 2021-03-15 op new_tab(vl->parent->alt);
581 a8c28919 2021-03-16 op cmd_previous_button(struct tab *tab)
584 a8c28919 2021-03-16 op if (tab->s.current_line == NULL ||
585 a8c28919 2021-03-16 op tab->s.current_line == TAILQ_FIRST(&tab->s.head)) {
586 a8c28919 2021-03-16 op message("No previous link");
589 a8c28919 2021-03-16 op cmd_previous_line(tab);
590 a8c28919 2021-03-16 op } while (tab->s.current_line->parent->type != LINE_LINK);
594 a8c28919 2021-03-16 op cmd_next_button(struct tab *tab)
597 a8c28919 2021-03-16 op if (tab->s.current_line == NULL ||
598 a8c28919 2021-03-16 op tab->s.current_line == TAILQ_LAST(&tab->s.head, vhead)) {
599 a8c28919 2021-03-16 op message("No next link");
602 a8c28919 2021-03-16 op cmd_next_line(tab);
603 a8c28919 2021-03-16 op } while (tab->s.current_line->parent->type != LINE_LINK);
607 2051e653 2021-03-13 op cmd_previous_page(struct tab *tab)
609 2051e653 2021-03-13 op if (!load_previous_page(tab))
610 2051e653 2021-03-13 op message("No previous page");
612 c40c2250 2021-03-14 op start_loading_anim(tab);
616 2051e653 2021-03-13 op cmd_next_page(struct tab *tab)
618 2051e653 2021-03-13 op if (!load_next_page(tab))
619 2051e653 2021-03-13 op message("No next page");
621 c40c2250 2021-03-14 op start_loading_anim(tab);
625 3b4f9e49 2021-03-11 op cmd_clear_minibuf(struct tab *tab)
627 3b4f9e49 2021-03-11 op handle_clear_minibuf(0, 0, NULL);
631 9ca15951 2021-03-09 op cmd_execute_extended_command(struct tab *tab)
635 22268e11 2021-03-11 op enter_minibuffer(eecmd_self_insert, eecmd_select, exit_minibuffer,
636 22268e11 2021-03-11 op &eecmd_history);
638 9ca15951 2021-03-09 op len = sizeof(ministate.prompt);
639 9ca15951 2021-03-09 op strlcpy(ministate.prompt, "", len);
641 9ca15951 2021-03-09 op if (thiskey.meta)
642 9ca15951 2021-03-09 op strlcat(ministate.prompt, "M-", len);
644 9ca15951 2021-03-09 op strlcat(ministate.prompt, keyname(thiskey.key), len);
645 9ca15951 2021-03-09 op strlcat(ministate.prompt, " ", len);
649 7c7d7bb7 2021-03-10 op cmd_tab_close(struct tab *tab)
651 7c7d7bb7 2021-03-10 op struct tab *t;
653 7c7d7bb7 2021-03-10 op if (TAILQ_PREV(tab, tabshead, tabs) == NULL &&
654 7c7d7bb7 2021-03-10 op TAILQ_NEXT(tab, tabs) == NULL) {
655 7c7d7bb7 2021-03-10 op message("Can't close the only tab.");
659 7c7d7bb7 2021-03-10 op stop_tab(tab);
661 7c7d7bb7 2021-03-10 op t = TAILQ_PREV(tab, tabshead, tabs);
662 7c7d7bb7 2021-03-10 op t->flags |= TAB_CURRENT;
664 7c7d7bb7 2021-03-10 op TAILQ_REMOVE(&tabshead, tab, tabs);
670 fea845b6 2021-03-15 op cmd_tab_close_other(struct tab *tab)
672 fea845b6 2021-03-15 op struct tab *t, *i;
674 fea845b6 2021-03-15 op TAILQ_FOREACH_SAFE(t, &tabshead, tabs, i) {
675 fea845b6 2021-03-15 op if (t->flags & TAB_CURRENT)
679 fea845b6 2021-03-15 op TAILQ_REMOVE(&tabshead, t, tabs);
685 7c7d7bb7 2021-03-10 op cmd_tab_new(struct tab *tab)
687 1b81bc33 2021-03-15 op new_tab(NEW_TAB_URL);
691 7c7d7bb7 2021-03-10 op cmd_tab_next(struct tab *tab)
693 7c7d7bb7 2021-03-10 op struct tab *t;
695 7c7d7bb7 2021-03-10 op tab->flags &= ~TAB_CURRENT;
697 7c7d7bb7 2021-03-10 op if ((t = TAILQ_NEXT(tab, tabs)) == NULL)
698 7c7d7bb7 2021-03-10 op t = TAILQ_FIRST(&tabshead);
699 7c7d7bb7 2021-03-10 op t->flags |= TAB_CURRENT;
703 7c7d7bb7 2021-03-10 op cmd_tab_previous(struct tab *tab)
705 7c7d7bb7 2021-03-10 op struct tab *t;
707 7c7d7bb7 2021-03-10 op tab->flags &= ~TAB_CURRENT;
709 7c7d7bb7 2021-03-10 op if ((t = TAILQ_PREV(tab, tabshead, tabs)) == NULL)
710 7c7d7bb7 2021-03-10 op t = TAILQ_LAST(&tabshead, tabshead);
711 7c7d7bb7 2021-03-10 op t->flags |= TAB_CURRENT;
715 5cd2ebb1 2021-03-11 op cmd_load_url(struct tab *tab)
717 22268e11 2021-03-11 op enter_minibuffer(lu_self_insert, lu_select, exit_minibuffer,
718 22268e11 2021-03-11 op &lu_history);
719 5cd2ebb1 2021-03-11 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
723 5cd2ebb1 2021-03-11 op cmd_load_current_url(struct tab *tab)
725 22268e11 2021-03-11 op enter_minibuffer(lu_self_insert, lu_select, exit_minibuffer,
726 22268e11 2021-03-11 op &lu_history);
727 5cd2ebb1 2021-03-11 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
728 740f578b 2021-03-15 op strlcpy(ministate.buf, tab->hist_cur->h, sizeof(ministate.buf));
729 740f578b 2021-03-15 op ministate.off = strlen(tab->hist_cur->h);
730 740f578b 2021-03-15 op ministate.len = ministate.off;
734 740f578b 2021-03-15 op cmd_bookmark_page(struct tab *tab)
736 740f578b 2021-03-15 op enter_minibuffer(lu_self_insert, bp_select, exit_minibuffer, NULL);
737 740f578b 2021-03-15 op strlcpy(ministate.prompt, "Bookmark URL: ", sizeof(ministate.prompt));
738 2051e653 2021-03-13 op strlcpy(ministate.buf, tab->hist_cur->h, sizeof(ministate.buf));
739 2051e653 2021-03-13 op ministate.off = strlen(tab->hist_cur->h);
740 5cd2ebb1 2021-03-11 op ministate.len = ministate.off;
744 de0b2139 2021-03-15 op cmd_goto_bookmarks(struct tab *tab)
746 de0b2139 2021-03-15 op load_url_in_tab(tab, "about:bookmarks");
750 7c7d7bb7 2021-03-10 op global_key_unbound(void)
752 7c7d7bb7 2021-03-10 op message("%s is undefined", keybuf);
756 d67133bf 2021-03-12 op cmd_mini_delete_char(struct tab *tab)
758 3eecee9e 2021-03-12 op minibuffer_taint_hist();
760 d67133bf 2021-03-12 op if (ministate.len == 0 || ministate.off == ministate.len)
763 d67133bf 2021-03-12 op memmove(&ministate.buf[ministate.off],
764 d67133bf 2021-03-12 op &ministate.buf[ministate.off+1],
765 d67133bf 2021-03-12 op ministate.len - ministate.off + 1);
766 d67133bf 2021-03-12 op ministate.len--;
770 d67133bf 2021-03-12 op cmd_mini_delete_backward_char(struct tab *tab)
772 3eecee9e 2021-03-12 op minibuffer_taint_hist();
774 9ca15951 2021-03-09 op if (ministate.len == 0 || ministate.off == 0)
777 9ca15951 2021-03-09 op memmove(&ministate.buf[ministate.off-1],
778 9ca15951 2021-03-09 op &ministate.buf[ministate.off],
779 9ca15951 2021-03-09 op ministate.len - ministate.off + 1);
780 9ca15951 2021-03-09 op ministate.off--;
781 9ca15951 2021-03-09 op ministate.len--;
785 9ca15951 2021-03-09 op cmd_mini_forward_char(struct tab *tab)
787 9ca15951 2021-03-09 op if (ministate.off == ministate.len)
789 9ca15951 2021-03-09 op ministate.off++;
793 9ca15951 2021-03-09 op cmd_mini_backward_char(struct tab *tab)
795 9ca15951 2021-03-09 op if (ministate.off == 0)
797 9ca15951 2021-03-09 op ministate.off--;
801 9ca15951 2021-03-09 op cmd_mini_move_end_of_line(struct tab *tab)
803 9ca15951 2021-03-09 op ministate.off = ministate.len;
807 9ca15951 2021-03-09 op cmd_mini_move_beginning_of_line(struct tab *tab)
809 9ca15951 2021-03-09 op ministate.off = 0;
813 fa3fd864 2021-03-10 op cmd_mini_kill_line(struct tab *tab)
815 3eecee9e 2021-03-12 op minibuffer_taint_hist();
817 fa3fd864 2021-03-10 op if (ministate.off == ministate.len)
819 fa3fd864 2021-03-10 op ministate.buf[ministate.off] = '\0';
820 fa3fd864 2021-03-10 op ministate.len -= ministate.off;
824 b360ebb3 2021-03-10 op cmd_mini_abort(struct tab *tab)
826 b360ebb3 2021-03-10 op ministate.abortfn();
830 b360ebb3 2021-03-10 op cmd_mini_complete_and_exit(struct tab *tab)
832 22268e11 2021-03-11 op minibuffer_taint_hist();
833 b360ebb3 2021-03-10 op ministate.donefn();
837 22268e11 2021-03-11 op cmd_mini_previous_history_element(struct tab *tab)
839 22268e11 2021-03-11 op if (ministate.history == NULL) {
840 22268e11 2021-03-11 op message("No history");
844 22268e11 2021-03-11 op if (ministate.hist_cur == NULL ||
845 22268e11 2021-03-11 op (ministate.hist_cur = TAILQ_PREV(ministate.hist_cur, mhisthead, entries)) == NULL) {
846 22268e11 2021-03-11 op ministate.hist_cur = TAILQ_LAST(&ministate.history->head, mhisthead);
847 22268e11 2021-03-11 op ministate.hist_off = ministate.history->len - 1;
848 22268e11 2021-03-11 op if (ministate.hist_cur == NULL)
849 22268e11 2021-03-11 op message("No prev item");
851 22268e11 2021-03-11 op ministate.hist_off--;
854 22268e11 2021-03-11 op if (ministate.hist_cur != NULL) {
855 22268e11 2021-03-11 op ministate.off = 0;
856 22268e11 2021-03-11 op ministate.len = strlen(ministate.hist_cur->h);
861 22268e11 2021-03-11 op cmd_mini_next_history_element(struct tab *tab)
863 22268e11 2021-03-11 op if (ministate.history == NULL) {
864 22268e11 2021-03-11 op message("No history");
868 22268e11 2021-03-11 op if (ministate.hist_cur == NULL ||
869 22268e11 2021-03-11 op (ministate.hist_cur = TAILQ_NEXT(ministate.hist_cur, entries)) == NULL) {
870 22268e11 2021-03-11 op ministate.hist_cur = TAILQ_FIRST(&ministate.history->head);
871 22268e11 2021-03-11 op ministate.hist_off = 0;
872 22268e11 2021-03-11 op if (ministate.hist_cur == NULL)
873 22268e11 2021-03-11 op message("No next item");
875 22268e11 2021-03-11 op ministate.hist_off++;
878 22268e11 2021-03-11 op if (ministate.hist_cur != NULL) {
879 22268e11 2021-03-11 op ministate.off = 0;
880 22268e11 2021-03-11 op ministate.len = strlen(ministate.hist_cur->h);
885 22268e11 2021-03-11 op minibuffer_hist_save_entry(void)
887 3148eeac 2021-03-13 op struct hist *hist;
889 22268e11 2021-03-11 op if (ministate.history == NULL)
892 22268e11 2021-03-11 op if ((hist = calloc(1, sizeof(*hist))) == NULL)
895 22268e11 2021-03-11 op strlcpy(hist->h, ministate.buf, sizeof(hist->h));
897 22268e11 2021-03-11 op if (TAILQ_EMPTY(&ministate.history->head))
898 22268e11 2021-03-11 op TAILQ_INSERT_HEAD(&ministate.history->head, hist, entries);
900 22268e11 2021-03-11 op TAILQ_INSERT_TAIL(&ministate.history->head, hist, entries);
901 22268e11 2021-03-11 op ministate.history->len++;
905 22268e11 2021-03-11 op * taint the minibuffer cache: if we're currently showing a history
906 22268e11 2021-03-11 op * element, copy that to the current buf and reset the "history
907 22268e11 2021-03-11 op * navigation" thing.
910 22268e11 2021-03-11 op minibuffer_taint_hist(void)
912 22268e11 2021-03-11 op if (ministate.hist_cur == NULL)
915 22268e11 2021-03-11 op strlcpy(ministate.buf, ministate.hist_cur->h, sizeof(ministate.buf));
916 22268e11 2021-03-11 op ministate.hist_cur = NULL;
920 5cd2ebb1 2021-03-11 op minibuffer_self_insert(void)
922 22268e11 2021-03-11 op minibuffer_taint_hist();
924 040fbdf8 2021-03-10 op if (ministate.len == sizeof(ministate.buf) -1)
927 9ca15951 2021-03-09 op /* TODO: utf8 handling! */
929 9ca15951 2021-03-09 op memmove(&ministate.buf[ministate.off+1],
930 9ca15951 2021-03-09 op &ministate.buf[ministate.off],
931 9ca15951 2021-03-09 op ministate.len - ministate.off + 1);
932 9ca15951 2021-03-09 op ministate.buf[ministate.off] = thiskey.key;
933 9ca15951 2021-03-09 op ministate.off++;
934 9ca15951 2021-03-09 op ministate.len++;
938 5cd2ebb1 2021-03-11 op eecmd_self_insert(void)
940 5cd2ebb1 2021-03-11 op if (thiskey.meta || isspace(thiskey.key) ||
941 5cd2ebb1 2021-03-11 op !isgraph(thiskey.key)) {
942 5cd2ebb1 2021-03-11 op global_key_unbound();
946 5cd2ebb1 2021-03-11 op minibuffer_self_insert();
950 b360ebb3 2021-03-10 op eecmd_select(void)
952 b360ebb3 2021-03-10 op exit_minibuffer();
953 22268e11 2021-03-11 op minibuffer_hist_save_entry();
954 b360ebb3 2021-03-10 op message("TODO: try to execute %s", ministate.buf);
958 5cd2ebb1 2021-03-11 op ir_self_insert(void)
960 5cd2ebb1 2021-03-11 op minibuffer_self_insert();
964 5cd2ebb1 2021-03-11 op ir_select(void)
966 5cd2ebb1 2021-03-11 op char buf[1025] = {0};
967 5cd2ebb1 2021-03-11 op struct url url;
968 5cd2ebb1 2021-03-11 op struct tab *tab;
970 5cd2ebb1 2021-03-11 op tab = current_tab();
972 5cd2ebb1 2021-03-11 op exit_minibuffer();
973 22268e11 2021-03-11 op minibuffer_hist_save_entry();
975 5cd2ebb1 2021-03-11 op /* a bit ugly but... */
976 5cd2ebb1 2021-03-11 op memcpy(&url, &tab->url, sizeof(tab->url));
977 5cd2ebb1 2021-03-11 op url_set_query(&url, ministate.buf);
978 5cd2ebb1 2021-03-11 op url_unparse(&url, buf, sizeof(buf));
979 5cd2ebb1 2021-03-11 op load_url_in_tab(tab, buf);
983 5cd2ebb1 2021-03-11 op lu_self_insert(void)
985 5cd2ebb1 2021-03-11 op if (thiskey.meta || isspace(thiskey.key) ||
986 5cd2ebb1 2021-03-11 op !isgraph(thiskey.key)) {
987 5cd2ebb1 2021-03-11 op global_key_unbound();
991 5cd2ebb1 2021-03-11 op minibuffer_self_insert();
995 5cd2ebb1 2021-03-11 op lu_select(void)
997 5cd2ebb1 2021-03-11 op exit_minibuffer();
998 22268e11 2021-03-11 op minibuffer_hist_save_entry();
999 5cd2ebb1 2021-03-11 op load_url_in_tab(current_tab(), ministate.buf);
1003 740f578b 2021-03-15 op bp_select(void)
1005 740f578b 2021-03-15 op exit_minibuffer();
1006 740f578b 2021-03-15 op if (*ministate.buf != '\0')
1007 740f578b 2021-03-15 op add_to_bookmarks(ministate.buf);
1009 740f578b 2021-03-15 op message("Abort.");
1012 9a25f829 2021-03-14 op static struct vline *
1013 48e9d457 2021-03-06 op nth_line(struct tab *tab, size_t n)
1015 9a25f829 2021-03-14 op struct vline *vl;
1019 65d9b3ca 2021-03-14 op TAILQ_FOREACH(vl, &tab->s.head, vlines) {
1025 48e9d457 2021-03-06 op /* unreachable */
1029 5e11c00c 2021-03-02 op static struct tab *
1030 5e11c00c 2021-03-02 op current_tab(void)
1032 5e11c00c 2021-03-02 op struct tab *t;
1034 5e11c00c 2021-03-02 op TAILQ_FOREACH(t, &tabshead, tabs) {
1035 5e11c00c 2021-03-02 op if (t->flags & TAB_CURRENT)
1039 5e11c00c 2021-03-02 op /* unreachable */
1044 5e11c00c 2021-03-02 op dispatch_stdio(int fd, short ev, void *d)
1046 f832146f 2021-03-09 op struct keymap *k;
1047 7c7d7bb7 2021-03-10 op const char *keyname;
1048 7c7d7bb7 2021-03-10 op char tmp[2] = {0};
1050 9ca15951 2021-03-09 op thiskey.key = wgetch(body);
1051 9ca15951 2021-03-09 op if (thiskey.key == ERR)
1053 9ca15951 2021-03-09 op if (thiskey.key == 27) {
1054 f832146f 2021-03-09 op /* TODO: make escape-time customizable */
1056 9ca15951 2021-03-09 op thiskey.meta = 1;
1057 9ca15951 2021-03-09 op thiskey.key = wgetch(body);
1058 c314a314 2021-03-11 op if (thiskey.key == ERR || thiskey.key == 27) {
1059 c314a314 2021-03-11 op thiskey.meta = 0;
1060 9ca15951 2021-03-09 op thiskey.key = 27;
1063 9ca15951 2021-03-09 op thiskey.meta = 0;
1065 7c7d7bb7 2021-03-10 op if (keybuf[0] != '\0')
1066 7c7d7bb7 2021-03-10 op strlcat(keybuf, " ", sizeof(keybuf));
1067 7c7d7bb7 2021-03-10 op if (thiskey.meta)
1068 7c7d7bb7 2021-03-10 op strlcat(keybuf, "M-", sizeof(keybuf));
1069 7c7d7bb7 2021-03-10 op if ((keyname = unkbd(thiskey.key)) != NULL)
1070 7c7d7bb7 2021-03-10 op strlcat(keybuf, keyname, sizeof(keybuf));
1072 7c7d7bb7 2021-03-10 op tmp[0] = thiskey.key;
1073 7c7d7bb7 2021-03-10 op strlcat(keybuf, tmp, sizeof(keybuf));
1076 9ca15951 2021-03-09 op TAILQ_FOREACH(k, ¤t_map->m, keymaps) {
1077 9ca15951 2021-03-09 op if (k->meta == thiskey.meta &&
1078 9ca15951 2021-03-09 op k->key == thiskey.key) {
1079 f832146f 2021-03-09 op if (k->fn == NULL)
1080 f832146f 2021-03-09 op current_map = &k->map;
1082 9ca15951 2021-03-09 op current_map = base_map;
1083 7c7d7bb7 2021-03-10 op strlcpy(keybuf, "", sizeof(keybuf));
1084 f832146f 2021-03-09 op k->fn(current_tab());
1090 7c7d7bb7 2021-03-10 op if (current_map->unhandled_input != NULL)
1091 7c7d7bb7 2021-03-10 op current_map->unhandled_input();
1093 7c7d7bb7 2021-03-10 op global_key_unbound();
1096 7c7d7bb7 2021-03-10 op strlcpy(keybuf, "", sizeof(keybuf));
1097 9ca15951 2021-03-09 op current_map = base_map;
1100 179f0f58 2021-03-11 op redraw_tab(current_tab());
1104 a6d450c1 2021-03-06 op handle_clear_minibuf(int fd, short ev, void *d)
1106 9cb0f9ce 2021-03-10 op free(ministate.curmesg);
1107 9cb0f9ce 2021-03-10 op ministate.curmesg = NULL;
1109 9cb0f9ce 2021-03-10 op redraw_minibuffer();
1110 9cb0f9ce 2021-03-10 op if (in_minibuffer) {
1111 9cb0f9ce 2021-03-10 op wrefresh(body);
1112 9cb0f9ce 2021-03-10 op wrefresh(minibuf);
1114 9cb0f9ce 2021-03-10 op wrefresh(minibuf);
1115 9cb0f9ce 2021-03-10 op wrefresh(body);
1120 5e11c00c 2021-03-02 op handle_resize(int sig, short ev, void *d)
1122 1d08c280 2021-03-06 op struct tab *tab;
1128 48e9d457 2021-03-06 op /* move and resize the windows, in reverse order! */
1130 b1738d2e 2021-03-06 op mvwin(minibuf, LINES-1, 0);
1131 48e9d457 2021-03-06 op wresize(minibuf, 1, COLS);
1133 48e9d457 2021-03-06 op mvwin(modeline, LINES-2, 0);
1134 48e9d457 2021-03-06 op wresize(modeline, 1, COLS);
1136 48e9d457 2021-03-06 op wresize(body, LINES-3, COLS);
1137 48e9d457 2021-03-06 op body_lines = LINES-3;
1138 bd9637e9 2021-03-06 op body_cols = COLS;
1140 48e9d457 2021-03-06 op wresize(tabline, 1, COLS);
1142 1d08c280 2021-03-06 op tab = current_tab();
1144 1d08c280 2021-03-06 op wrap_page(tab);
1145 1d08c280 2021-03-06 op redraw_tab(tab);
1149 1d08c280 2021-03-06 op wrap_page(struct tab *tab)
1151 452589f7 2021-03-16 op struct line *l;
1152 452589f7 2021-03-16 op const struct line *orig;
1153 d511dc85 2021-03-16 op struct vline *vl;
1154 452589f7 2021-03-16 op const char *prfx;
1156 452589f7 2021-03-16 op orig = tab->s.current_line == NULL
1158 452589f7 2021-03-16 op : tab->s.current_line->parent;
1159 452589f7 2021-03-16 op tab->s.current_line = NULL;
1161 452589f7 2021-03-16 op tab->s.curs_y = 0;
1162 452589f7 2021-03-16 op tab->s.line_off = 0;
1164 1d08c280 2021-03-06 op empty_vlist(tab);
1166 5e11c00c 2021-03-02 op TAILQ_FOREACH(l, &tab->page.head, lines) {
1167 0d568960 2021-03-11 op prfx = line_prefixes[l->type].prfx1;
1168 5e11c00c 2021-03-02 op switch (l->type) {
1169 5e11c00c 2021-03-02 op case LINE_TEXT:
1170 5e11c00c 2021-03-02 op case LINE_LINK:
1171 5e11c00c 2021-03-02 op case LINE_TITLE_1:
1172 5e11c00c 2021-03-02 op case LINE_TITLE_2:
1173 5e11c00c 2021-03-02 op case LINE_TITLE_3:
1174 5e11c00c 2021-03-02 op case LINE_ITEM:
1175 5e11c00c 2021-03-02 op case LINE_QUOTE:
1176 5e11c00c 2021-03-02 op case LINE_PRE_START:
1177 5e11c00c 2021-03-02 op case LINE_PRE_END:
1178 65d9b3ca 2021-03-14 op wrap_text(tab, prfx, l, body_cols);
1180 5e11c00c 2021-03-02 op case LINE_PRE_CONTENT:
1181 65d9b3ca 2021-03-14 op hardwrap_text(tab, l, body_cols);
1185 452589f7 2021-03-16 op if (orig == l && tab->s.current_line == NULL) {
1186 452589f7 2021-03-16 op tab->s.line_off = tab->s.line_max-1;
1187 452589f7 2021-03-16 op tab->s.current_line = TAILQ_LAST(&tab->s.head, vhead);
1190 d511dc85 2021-03-16 op vl = TAILQ_PREV(tab->s.current_line, vhead, vlines);
1191 d511dc85 2021-03-16 op if (vl == NULL || vl->parent != orig)
1193 d511dc85 2021-03-16 op tab->s.current_line = vl;
1194 d511dc85 2021-03-16 op tab->s.line_off--;
1199 452589f7 2021-03-16 op if (tab->s.current_line == NULL)
1200 452589f7 2021-03-16 op tab->s.current_line = TAILQ_FIRST(&tab->s.head);
1206 9a25f829 2021-03-14 op print_vline(struct vline *vl)
1208 9a25f829 2021-03-14 op const char *text = vl->line;
1209 768db5bb 2021-03-12 op const char *prfx;
1210 803ff456 2021-03-17 op int prefix_face = line_faces[vl->parent->type].prefix_prop;
1211 803ff456 2021-03-17 op int text_face = line_faces[vl->parent->type].text_prop;
1213 9a25f829 2021-03-14 op if (!vl->flags)
1214 9a25f829 2021-03-14 op prfx = line_prefixes[vl->parent->type].prfx1;
1216 9a25f829 2021-03-14 op prfx = line_prefixes[vl->parent->type].prfx2;
1218 bd9637e9 2021-03-06 op if (text == NULL)
1221 803ff456 2021-03-17 op wattron(body, prefix_face);
1222 803ff456 2021-03-17 op wprintw(body, "%s", prfx);
1223 803ff456 2021-03-17 op wattroff(body, prefix_face);
1225 803ff456 2021-03-17 op wattron(body, text_face);
1226 803ff456 2021-03-17 op wprintw(body, "%s", text);
1227 803ff456 2021-03-17 op wattroff(body, text_face);
1231 8af5e5ed 2021-03-08 op redraw_tabline(void)
1233 7c7d7bb7 2021-03-10 op struct tab *tab;
1234 a636f50e 2021-03-16 op size_t toskip;
1235 a636f50e 2021-03-16 op int current, x, y, truncated;
1236 dc5df781 2021-03-13 op const char *title;
1237 119f393c 2021-03-16 op char buf[25];
1241 a636f50e 2021-03-16 op TAILQ_FOREACH(tab, &tabshead, tabs) {
1242 a636f50e 2021-03-16 op x += sizeof(buf) + 1;
1244 a636f50e 2021-03-16 op if (tab->flags & TAB_CURRENT)
1247 a636f50e 2021-03-16 op if (x < COLS-2)
1252 a636f50e 2021-03-16 op werase(tabline);
1253 cb6c7aa0 2021-03-16 op wattron(tabline, tab_face.background);
1254 a636f50e 2021-03-16 op wprintw(tabline, toskip == 0 ? " " : "<");
1255 cb6c7aa0 2021-03-16 op wattroff(tabline, tab_face.background);
1257 a636f50e 2021-03-16 op truncated = 0;
1258 7c7d7bb7 2021-03-10 op TAILQ_FOREACH(tab, &tabshead, tabs) {
1259 a636f50e 2021-03-16 op if (truncated)
1261 a636f50e 2021-03-16 op if (toskip != 0) {
1266 a636f50e 2021-03-16 op getyx(tabline, y, x);
1267 a636f50e 2021-03-16 op if (x + sizeof(buf)+2 >= (size_t)COLS)
1268 a636f50e 2021-03-16 op truncated = 1;
1270 7c7d7bb7 2021-03-10 op current = tab->flags & TAB_CURRENT;
1272 dc5df781 2021-03-13 op if (*(title = tab->page.title) == '\0')
1273 2051e653 2021-03-13 op title = tab->hist_cur->h;
1275 119f393c 2021-03-16 op strlcpy(buf, " ", sizeof(buf));
1276 119f393c 2021-03-16 op if (strlcat(buf, title, sizeof(buf)) >= sizeof(buf)) {
1277 119f393c 2021-03-16 op /* truncation happens */
1278 119f393c 2021-03-16 op strlcpy(&buf[sizeof(buf)-4], "...", 4);
1280 119f393c 2021-03-16 op /* pad with spaces */
1281 119f393c 2021-03-16 op while (strlcat(buf, " ", sizeof(buf)) < sizeof(buf))
1285 a329982b 2021-03-11 op if (current)
1286 cb6c7aa0 2021-03-16 op wattron(tabline, tab_face.current_tab);
1288 cb6c7aa0 2021-03-16 op wattron(tabline, tab_face.tab);
1290 119f393c 2021-03-16 op wprintw(tabline, "%s", buf);
1291 119f393c 2021-03-16 op if (TAILQ_NEXT(tab, tabs) != NULL)
1292 119f393c 2021-03-16 op wprintw(tabline, " ");
1294 cb6c7aa0 2021-03-16 op if (current)
1295 cb6c7aa0 2021-03-16 op wattroff(tabline, tab_face.current_tab);
1297 cb6c7aa0 2021-03-16 op wattroff(tabline, tab_face.tab);
1300 cb6c7aa0 2021-03-16 op wattron(tabline, tab_face.background);
1301 119f393c 2021-03-16 op for (; x < COLS; ++x)
1302 119f393c 2021-03-16 op waddch(tabline, ' ');
1303 a636f50e 2021-03-16 op if (truncated)
1304 a636f50e 2021-03-16 op mvwprintw(tabline, 0, COLS-1, ">");
1308 48e9d457 2021-03-06 op redraw_modeline(struct tab *tab)
1311 48e9d457 2021-03-06 op int x, y, max_x, max_y;
1312 fc43eadd 2021-03-12 op const char *mode = tab->page.name;
1313 8af5e5ed 2021-03-08 op const char *spin = "-\\|/";
1315 156f1501 2021-03-13 op werase(modeline);
1316 48e9d457 2021-03-06 op wattron(modeline, A_REVERSE);
1317 48e9d457 2021-03-06 op wmove(modeline, 0, 0);
1319 3710f27a 2021-03-14 op wprintw(modeline, "-%c %s ",
1320 58c75fab 2021-03-16 op spin[tab->s.loading_anim_step],
1321 58c75fab 2021-03-16 op mode == NULL ? "(none)" : mode);
1323 65d9b3ca 2021-03-14 op pct = (tab->s.line_off + tab->s.curs_y) * 100.0 / tab->s.line_max;
1325 754622a2 2021-03-15 op if (tab->s.line_max <= (size_t)body_lines)
1326 481340cc 2021-03-11 op wprintw(modeline, "All ");
1327 65d9b3ca 2021-03-14 op else if (tab->s.line_off == 0)
1328 481340cc 2021-03-11 op wprintw(modeline, "Top ");
1329 65d9b3ca 2021-03-14 op else if (tab->s.line_off + body_lines >= tab->s.line_max)
1330 481340cc 2021-03-11 op wprintw(modeline, "Bottom ");
1332 481340cc 2021-03-11 op wprintw(modeline, "%.0f%% ", pct);
1334 481340cc 2021-03-11 op wprintw(modeline, "%d/%d %s ",
1335 65d9b3ca 2021-03-14 op tab->s.line_off + tab->s.curs_y,
1336 65d9b3ca 2021-03-14 op tab->s.line_max,
1337 2051e653 2021-03-13 op tab->hist_cur->h);
1339 48e9d457 2021-03-06 op getyx(modeline, y, x);
1340 48e9d457 2021-03-06 op getmaxyx(modeline, max_y, max_x);
1343 48e9d457 2021-03-06 op (void)max_y;
1345 48e9d457 2021-03-06 op for (; x < max_x; ++x)
1346 48e9d457 2021-03-06 op waddstr(modeline, "-");
1350 9ca15951 2021-03-09 op redraw_minibuffer(void)
1352 22268e11 2021-03-11 op size_t skip = 0, off_x = 0, off_y = 0;
1354 156f1501 2021-03-13 op werase(minibuf);
1355 22268e11 2021-03-11 op if (in_minibuffer) {
1356 22268e11 2021-03-11 op mvwprintw(minibuf, 0, 0, "%s", ministate.prompt);
1357 22268e11 2021-03-11 op if (ministate.hist_cur != NULL)
1358 22268e11 2021-03-11 op wprintw(minibuf, "(%zu/%zu) ",
1359 22268e11 2021-03-11 op ministate.hist_off + 1,
1360 22268e11 2021-03-11 op ministate.history->len);
1362 22268e11 2021-03-11 op getyx(minibuf, off_y, off_x);
1364 754622a2 2021-03-15 op while (ministate.off - skip > (size_t)COLS / 2) {
1365 22268e11 2021-03-11 op skip += MIN(ministate.off/4, 1);
1368 22268e11 2021-03-11 op if (ministate.hist_cur != NULL)
1369 22268e11 2021-03-11 op wprintw(minibuf, "%s", ministate.hist_cur->h + skip);
1371 22268e11 2021-03-11 op wprintw(minibuf, "%s", ministate.buf + skip);
1374 9cb0f9ce 2021-03-10 op if (ministate.curmesg != NULL) {
1375 9cb0f9ce 2021-03-10 op if (in_minibuffer)
1376 9cb0f9ce 2021-03-10 op wprintw(minibuf, " [%s]", ministate.curmesg);
1378 9cb0f9ce 2021-03-10 op wprintw(minibuf, "%s", ministate.curmesg);
1381 91a72220 2021-03-13 op if (!in_minibuffer && ministate.curmesg == NULL)
1382 91a72220 2021-03-13 op wprintw(minibuf, "%s", keybuf);
1384 2aaf475e 2021-03-13 op if (in_minibuffer)
1385 2aaf475e 2021-03-13 op wmove(minibuf, 0, off_x + ministate.off - skip);
1389 48e9d457 2021-03-06 op redraw_tab(struct tab *tab)
1391 e19f9a04 2021-03-11 op redraw_tabline();
1392 e19f9a04 2021-03-11 op redraw_body(tab);
1393 e19f9a04 2021-03-11 op redraw_modeline(tab);
1394 e19f9a04 2021-03-11 op redraw_minibuffer();
1396 e19f9a04 2021-03-11 op restore_cursor(tab);
1397 e19f9a04 2021-03-11 op wrefresh(tabline);
1398 e19f9a04 2021-03-11 op wrefresh(modeline);
1400 e19f9a04 2021-03-11 op if (in_minibuffer) {
1401 e19f9a04 2021-03-11 op wrefresh(body);
1402 e19f9a04 2021-03-11 op wrefresh(minibuf);
1404 e19f9a04 2021-03-11 op wrefresh(minibuf);
1405 e19f9a04 2021-03-11 op wrefresh(body);
1410 e19f9a04 2021-03-11 op redraw_body(struct tab *tab)
1412 9a25f829 2021-03-14 op struct vline *vl;
1415 48e9d457 2021-03-06 op werase(body);
1417 65d9b3ca 2021-03-14 op tab->s.line_off = MIN(tab->s.line_max-1, tab->s.line_off);
1418 65d9b3ca 2021-03-14 op if (TAILQ_EMPTY(&tab->s.head))
1422 65d9b3ca 2021-03-14 op vl = nth_line(tab, tab->s.line_off);
1423 9a25f829 2021-03-14 op for (; vl != NULL; vl = TAILQ_NEXT(vl, vlines)) {
1424 48e9d457 2021-03-06 op wmove(body, line, 0);
1425 9a25f829 2021-03-14 op print_vline(vl);
1427 48e9d457 2021-03-06 op if (line == body_lines)
1433 740f578b 2021-03-15 op vmessage(const char *fmt, va_list ap)
1435 e0e26735 2021-03-16 op if (evtimer_pending(&clminibufev, NULL))
1436 7953dd72 2021-03-07 op evtimer_del(&clminibufev);
1437 7953dd72 2021-03-07 op evtimer_set(&clminibufev, handle_clear_minibuf, NULL);
1438 7953dd72 2021-03-07 op evtimer_add(&clminibufev, &clminibufev_timer);
1440 bf992581 2021-03-12 op free(ministate.curmesg);
1442 9cb0f9ce 2021-03-10 op /* TODO: what to do if the allocation fails here? */
1443 9cb0f9ce 2021-03-10 op if (vasprintf(&ministate.curmesg, fmt, ap) == -1)
1444 9cb0f9ce 2021-03-10 op ministate.curmesg = NULL;
1446 9cb0f9ce 2021-03-10 op redraw_minibuffer();
1447 9cb0f9ce 2021-03-10 op if (in_minibuffer) {
1448 9cb0f9ce 2021-03-10 op wrefresh(body);
1449 9cb0f9ce 2021-03-10 op wrefresh(minibuf);
1451 9cb0f9ce 2021-03-10 op wrefresh(minibuf);
1452 9cb0f9ce 2021-03-10 op wrefresh(body);
1457 740f578b 2021-03-15 op message(const char *fmt, ...)
1461 740f578b 2021-03-15 op va_start(ap, fmt);
1462 740f578b 2021-03-15 op vmessage(fmt, ap);
1467 8af5e5ed 2021-03-08 op start_loading_anim(struct tab *tab)
1469 65d9b3ca 2021-03-14 op if (tab->s.loading_anim)
1471 65d9b3ca 2021-03-14 op tab->s.loading_anim = 1;
1472 65d9b3ca 2021-03-14 op evtimer_set(&tab->s.loadingev, update_loading_anim, tab);
1473 65d9b3ca 2021-03-14 op evtimer_add(&tab->s.loadingev, &loadingev_timer);
1477 8af5e5ed 2021-03-08 op update_loading_anim(int fd, short ev, void *d)
1479 8af5e5ed 2021-03-08 op struct tab *tab = d;
1481 65d9b3ca 2021-03-14 op tab->s.loading_anim_step = (tab->s.loading_anim_step+1)%4;
1483 6347dcd0 2021-03-16 op if (tab->flags & TAB_CURRENT) {
1484 6347dcd0 2021-03-16 op redraw_modeline(tab);
1485 6347dcd0 2021-03-16 op wrefresh(modeline);
1486 6347dcd0 2021-03-16 op wrefresh(body);
1487 6347dcd0 2021-03-16 op if (in_minibuffer)
1488 6347dcd0 2021-03-16 op wrefresh(minibuf);
1491 65d9b3ca 2021-03-14 op evtimer_add(&tab->s.loadingev, &loadingev_timer);
1495 8af5e5ed 2021-03-08 op stop_loading_anim(struct tab *tab)
1497 65d9b3ca 2021-03-14 op if (!tab->s.loading_anim)
1499 65d9b3ca 2021-03-14 op evtimer_del(&tab->s.loadingev);
1500 65d9b3ca 2021-03-14 op tab->s.loading_anim = 0;
1501 65d9b3ca 2021-03-14 op tab->s.loading_anim_step = 0;
1503 43a1b8d0 2021-03-09 op redraw_modeline(tab);
1505 43a1b8d0 2021-03-09 op wrefresh(modeline);
1506 43a1b8d0 2021-03-09 op wrefresh(body);
1507 9ca15951 2021-03-09 op if (in_minibuffer)
1508 9ca15951 2021-03-09 op wrefresh(minibuf);
1512 43a1b8d0 2021-03-09 op load_url_in_tab(struct tab *tab, const char *url)
1514 43a1b8d0 2021-03-09 op empty_vlist(tab);
1515 8af5e5ed 2021-03-08 op message("Loading %s...", url);
1516 8af5e5ed 2021-03-08 op start_loading_anim(tab);
1517 8af5e5ed 2021-03-08 op load_url(tab, url);
1519 65d9b3ca 2021-03-14 op tab->s.curs_x = 0;
1520 65d9b3ca 2021-03-14 op tab->s.curs_y = 0;
1521 43a1b8d0 2021-03-09 op redraw_tab(tab);
1525 b360ebb3 2021-03-10 op enter_minibuffer(void (*self_insert_fn)(void), void (*donefn)(void),
1526 3148eeac 2021-03-13 op void (*abortfn)(void), struct histhead *hist)
1528 9ca15951 2021-03-09 op in_minibuffer = 1;
1529 fa3fd864 2021-03-10 op base_map = &minibuffer_map;
1530 fa3fd864 2021-03-10 op current_map = &minibuffer_map;
1532 fa3fd864 2021-03-10 op base_map->unhandled_input = self_insert_fn;
1534 b360ebb3 2021-03-10 op ministate.donefn = donefn;
1535 b360ebb3 2021-03-10 op ministate.abortfn = abortfn;
1536 9ca15951 2021-03-09 op memset(ministate.buf, 0, sizeof(ministate.buf));
1537 9ca15951 2021-03-09 op ministate.off = 0;
1538 bb4e4ddf 2021-03-12 op ministate.len = 0;
1539 9ca15951 2021-03-09 op strlcpy(ministate.buf, "", sizeof(ministate.prompt));
1541 22268e11 2021-03-11 op ministate.history = hist;
1542 22268e11 2021-03-11 op ministate.hist_cur = NULL;
1543 22268e11 2021-03-11 op ministate.hist_off = 0;
1547 b360ebb3 2021-03-10 op exit_minibuffer(void)
1549 156f1501 2021-03-13 op werase(minibuf);
1551 9ca15951 2021-03-09 op in_minibuffer = 0;
1552 9ca15951 2021-03-09 op base_map = &global_map;
1553 9ca15951 2021-03-09 op current_map = &global_map;
1557 5cd2ebb1 2021-03-11 op switch_to_tab(struct tab *tab)
1559 5cd2ebb1 2021-03-11 op struct tab *t;
1561 5cd2ebb1 2021-03-11 op TAILQ_FOREACH(t, &tabshead, tabs) {
1562 5cd2ebb1 2021-03-11 op t->flags &= ~TAB_CURRENT;
1565 5cd2ebb1 2021-03-11 op tab->flags |= TAB_CURRENT;
1568 b1df9b71 2021-03-12 op static struct tab *
1569 1b81bc33 2021-03-15 op new_tab(const char *url)
1571 754622a2 2021-03-15 op struct tab *tab;
1573 71105afa 2021-03-16 op if ((tab = calloc(1, sizeof(*tab))) == NULL) {
1574 71105afa 2021-03-16 op event_loopbreak();
1575 71105afa 2021-03-16 op return NULL;
1578 2051e653 2021-03-13 op TAILQ_INIT(&tab->hist.head);
1580 65d9b3ca 2021-03-14 op TAILQ_INIT(&tab->s.head);
1582 bcb0b073 2021-03-07 op tab->id = tab_counter++;
1583 5cd2ebb1 2021-03-11 op switch_to_tab(tab);
1585 bcb0b073 2021-03-07 op if (TAILQ_EMPTY(&tabshead))
1586 bcb0b073 2021-03-07 op TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
1588 bcb0b073 2021-03-07 op TAILQ_INSERT_TAIL(&tabshead, tab, tabs);
1590 43a1b8d0 2021-03-09 op load_url_in_tab(tab, url);
1595 5e11c00c 2021-03-02 op ui_init(void)
1597 5e11c00c 2021-03-02 op setlocale(LC_ALL, "");
1599 9ca15951 2021-03-09 op TAILQ_INIT(&global_map.m);
1600 9ca15951 2021-03-09 op global_map.unhandled_input = global_key_unbound;
1602 fa3fd864 2021-03-10 op TAILQ_INIT(&minibuffer_map.m);
1604 22268e11 2021-03-11 op TAILQ_INIT(&eecmd_history.head);
1605 22268e11 2021-03-11 op TAILQ_INIT(&ir_history.head);
1606 22268e11 2021-03-11 op TAILQ_INIT(&lu_history.head);
1608 9ca15951 2021-03-09 op base_map = &global_map;
1609 f832146f 2021-03-09 op current_map = &global_map;
1610 f832146f 2021-03-09 op load_default_keys();
1617 5e11c00c 2021-03-02 op intrflush(stdscr, FALSE);
1619 48e9d457 2021-03-06 op if ((tabline = newwin(1, COLS, 0, 0)) == NULL)
1621 48e9d457 2021-03-06 op if ((body = newwin(LINES - 3, COLS, 1, 0)) == NULL)
1623 48e9d457 2021-03-06 op if ((modeline = newwin(1, COLS, LINES-2, 0)) == NULL)
1625 48e9d457 2021-03-06 op if ((minibuf = newwin(1, COLS, LINES-1, 0)) == NULL)
1628 48e9d457 2021-03-06 op body_lines = LINES-3;
1629 48e9d457 2021-03-06 op body_cols = COLS;
1631 43a1b8d0 2021-03-09 op keypad(body, TRUE);
1632 48e9d457 2021-03-06 op scrollok(body, TRUE);
1634 5e11c00c 2021-03-02 op /* non-blocking input */
1635 48e9d457 2021-03-06 op wtimeout(body, 0);
1637 48e9d457 2021-03-06 op mvwprintw(body, 0, 0, "");
1639 5e11c00c 2021-03-02 op event_set(&stdioev, 0, EV_READ | EV_PERSIST, dispatch_stdio, NULL);
1640 5e11c00c 2021-03-02 op event_add(&stdioev, NULL);
1642 5e11c00c 2021-03-02 op signal_set(&winchev, SIGWINCH, handle_resize, NULL);
1643 5e11c00c 2021-03-02 op signal_add(&winchev, NULL);
1645 1b81bc33 2021-03-15 op new_tab(NEW_TAB_URL);
1651 8af5e5ed 2021-03-08 op ui_on_tab_loaded(struct tab *tab)
1653 8af5e5ed 2021-03-08 op stop_loading_anim(tab);
1654 2051e653 2021-03-13 op message("Loaded %s", tab->hist_cur->h);
1658 5e11c00c 2021-03-02 op ui_on_tab_refresh(struct tab *tab)
1660 5e11c00c 2021-03-02 op if (!(tab->flags & TAB_CURRENT))
1663 1d08c280 2021-03-06 op wrap_page(tab);
1664 5e11c00c 2021-03-02 op redraw_tab(tab);
1668 5cd2ebb1 2021-03-11 op ui_require_input(struct tab *tab, int hide)
1670 5cd2ebb1 2021-03-11 op /* TODO: hard-switching to another tab is ugly */
1671 5cd2ebb1 2021-03-11 op switch_to_tab(tab);
1673 22268e11 2021-03-11 op enter_minibuffer(ir_self_insert, ir_select, exit_minibuffer,
1674 22268e11 2021-03-11 op &ir_history);
1675 5cd2ebb1 2021-03-11 op strlcpy(ministate.prompt, "Input required: ",
1676 5cd2ebb1 2021-03-11 op sizeof(ministate.prompt));
1677 5cd2ebb1 2021-03-11 op redraw_tab(tab);
1681 740f578b 2021-03-15 op ui_notify(const char *fmt, ...)
1685 740f578b 2021-03-15 op va_start(ap, fmt);
1686 740f578b 2021-03-15 op vmessage(fmt, ap);
1691 5e11c00c 2021-03-02 op ui_end(void)