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.
21 1d08c280 2021-03-06 op * Text wrapping
22 1d08c280 2021-03-06 op * =============
24 1d08c280 2021-03-06 op * There's a simple text wrapping algorithm.
26 1d08c280 2021-03-06 op * 1. if it's a line in a pre-formatted block:
27 1d08c280 2021-03-06 op * a. hard wrap.
29 1d08c280 2021-03-06 op * 2. there is enough room for the next word?
30 1d08c280 2021-03-06 op * a. yes: render it
31 1d08c280 2021-03-06 op * b. no: break the current line.
32 1d08c280 2021-03-06 op * i. while there isn't enough space to draw the current
33 1d08c280 2021-03-06 op * word, hard-wrap it
34 1d08c280 2021-03-06 op * ii. draw the remainder of the current word (can be the
35 1d08c280 2021-03-06 op * the entirely)
36 1d08c280 2021-03-06 op * 3. render the spaces after the word
37 1d08c280 2021-03-06 op * a. but if there is not enough room break the line and
42 1d08c280 2021-03-06 op * Text scrolling
43 1d08c280 2021-03-06 op * ==============
45 1d08c280 2021-03-06 op * ncurses allows you to scroll a window, but when a line goes out of
46 1d08c280 2021-03-06 op * the visible area it's forgotten. We keep a list of formatted lines
47 1d08c280 2021-03-06 op * (``visual lines'') that we know fits in the window, and draw them.
48 1d08c280 2021-03-06 op * This way is easy to scroll: just call wscrl and then render the
49 1d08c280 2021-03-06 op * first/last line!
51 1d08c280 2021-03-06 op * This means that on every resize we have to clear our list of lines
52 1d08c280 2021-03-06 op * and re-render everything. A clever approach would be to do this
53 1d08c280 2021-03-06 op * ``on-demand''.
55 1d08c280 2021-03-06 op * TODO: make the text formatting on-demand.
59 5e11c00c 2021-03-02 op #include <telescope.h>
61 f832146f 2021-03-09 op #include <ctype.h>
62 5e11c00c 2021-03-02 op #include <curses.h>
63 5e11c00c 2021-03-02 op #include <event.h>
64 5e11c00c 2021-03-02 op #include <locale.h>
65 5e11c00c 2021-03-02 op #include <signal.h>
66 7953dd72 2021-03-07 op #include <stdarg.h>
67 eb259e66 2021-03-02 op #include <stdlib.h>
68 eb259e66 2021-03-02 op #include <string.h>
69 f832146f 2021-03-09 op #include <unistd.h>
71 5e11c00c 2021-03-02 op #define TAB_CURRENT 0x1
73 1d08c280 2021-03-06 op #define MIN(a, b) ((a) < (b) ? (a) : (b))
74 1d08c280 2021-03-06 op #define MAX(a, b) ((a) > (b) ? (a) : (b))
77 22268e11 2021-03-11 op struct minibuf_histhead;
79 5e11c00c 2021-03-02 op static struct event stdioev, winchev;
81 f832146f 2021-03-09 op static void load_default_keys(void);
82 768db5bb 2021-03-12 op static int push_line(struct tab*, const struct line*, const char*, size_t, int);
83 1d08c280 2021-03-06 op static void empty_vlist(struct tab*);
84 48e9d457 2021-03-06 op static void restore_cursor(struct tab *);
86 46a9311e 2021-03-08 op static void cmd_previous_line(struct tab*);
87 46a9311e 2021-03-08 op static void cmd_next_line(struct tab*);
88 46a9311e 2021-03-08 op static void cmd_forward_char(struct tab*);
89 46a9311e 2021-03-08 op static void cmd_backward_char(struct tab*);
90 a329982b 2021-03-11 op static void cmd_move_beginning_of_line(struct tab*);
91 a329982b 2021-03-11 op static void cmd_move_end_of_line(struct tab*);
92 46a9311e 2021-03-08 op static void cmd_redraw(struct tab*);
93 ed44414d 2021-03-09 op static void cmd_scroll_line_down(struct tab*);
94 ed44414d 2021-03-09 op static void cmd_scroll_line_up(struct tab*);
95 46a9311e 2021-03-08 op static void cmd_scroll_up(struct tab*);
96 ed44414d 2021-03-09 op static void cmd_scroll_down(struct tab*);
97 e19f9a04 2021-03-11 op static void cmd_beginning_of_buffer(struct tab*);
98 e19f9a04 2021-03-11 op static void cmd_end_of_buffer(struct tab*);
99 46a9311e 2021-03-08 op static void cmd_kill_telescope(struct tab*);
100 46a9311e 2021-03-08 op static void cmd_push_button(struct tab*);
101 b1df9b71 2021-03-12 op static void cmd_push_button_new_tab(struct tab*);
102 3b4f9e49 2021-03-11 op static void cmd_clear_minibuf(struct tab*);
103 9ca15951 2021-03-09 op static void cmd_execute_extended_command(struct tab*);
104 7c7d7bb7 2021-03-10 op static void cmd_tab_close(struct tab*);
105 7c7d7bb7 2021-03-10 op static void cmd_tab_new(struct tab*);
106 7c7d7bb7 2021-03-10 op static void cmd_tab_next(struct tab*);
107 7c7d7bb7 2021-03-10 op static void cmd_tab_previous(struct tab*);
108 5cd2ebb1 2021-03-11 op static void cmd_load_url(struct tab*);
109 5cd2ebb1 2021-03-11 op static void cmd_load_current_url(struct tab*);
111 9ca15951 2021-03-09 op static void global_key_unbound(void);
113 d67133bf 2021-03-12 op static void cmd_mini_delete_char(struct tab*);
114 d67133bf 2021-03-12 op static void cmd_mini_delete_backward_char(struct tab*);
115 9ca15951 2021-03-09 op static void cmd_mini_forward_char(struct tab*);
116 9ca15951 2021-03-09 op static void cmd_mini_backward_char(struct tab*);
117 9ca15951 2021-03-09 op static void cmd_mini_move_end_of_line(struct tab*);
118 9ca15951 2021-03-09 op static void cmd_mini_move_beginning_of_line(struct tab*);
119 fa3fd864 2021-03-10 op static void cmd_mini_kill_line(struct tab*);
120 22268e11 2021-03-11 op static void cmd_mini_abort(struct tab*);
121 22268e11 2021-03-11 op static void cmd_mini_complete_and_exit(struct tab*);
122 22268e11 2021-03-11 op static void cmd_mini_previous_history_element(struct tab*);
123 22268e11 2021-03-11 op static void cmd_mini_next_history_element(struct tab*);
125 22268e11 2021-03-11 op static void minibuffer_hist_save_entry(void);
126 22268e11 2021-03-11 op static void minibuffer_taint_hist(void);
127 5cd2ebb1 2021-03-11 op static void minibuffer_self_insert(void);
128 9ca15951 2021-03-09 op static void eecmd_self_insert(void);
129 b360ebb3 2021-03-10 op static void eecmd_select(void);
130 5cd2ebb1 2021-03-11 op static void ir_self_insert(void);
131 5cd2ebb1 2021-03-11 op static void ir_select(void);
132 5cd2ebb1 2021-03-11 op static void lu_self_insert(void);
133 5cd2ebb1 2021-03-11 op static void lu_select(void);
135 48e9d457 2021-03-06 op static struct line *nth_line(struct tab*, size_t);
136 5e11c00c 2021-03-02 op static struct tab *current_tab(void);
137 5e11c00c 2021-03-02 op static void dispatch_stdio(int, short, void*);
138 a6d450c1 2021-03-06 op static void handle_clear_minibuf(int, short, void*);
139 5e11c00c 2021-03-02 op static void handle_resize(int, short, void*);
140 eb259e66 2021-03-02 op static int word_bourdaries(const char*, const char*, const char**, const char**);
141 1d08c280 2021-03-06 op static void wrap_text(struct tab*, const char*, struct line*);
142 1d08c280 2021-03-06 op static int hardwrap_text(struct tab*, struct line*);
143 1d08c280 2021-03-06 op static int wrap_page(struct tab*);
144 48e9d457 2021-03-06 op static void print_line(struct line*);
145 8af5e5ed 2021-03-08 op static void redraw_tabline(void);
146 e19f9a04 2021-03-11 op static void redraw_body(struct tab*);
147 8af5e5ed 2021-03-08 op static void redraw_modeline(struct tab*);
148 9ca15951 2021-03-09 op static void redraw_minibuffer(void);
149 5e11c00c 2021-03-02 op static void redraw_tab(struct tab*);
150 7953dd72 2021-03-07 op static void message(const char*, ...) __attribute__((format(printf, 1, 2)));
151 8af5e5ed 2021-03-08 op static void start_loading_anim(struct tab*);
152 8af5e5ed 2021-03-08 op static void update_loading_anim(int, short, void*);
153 8af5e5ed 2021-03-08 op static void stop_loading_anim(struct tab*);
154 43a1b8d0 2021-03-09 op static void load_url_in_tab(struct tab*, const char*);
155 22268e11 2021-03-11 op static void enter_minibuffer(void(*)(void), void(*)(void), void(*)(void), struct minibuf_histhead*);
156 b360ebb3 2021-03-10 op static void exit_minibuffer(void);
157 5cd2ebb1 2021-03-11 op static void switch_to_tab(struct tab*);
158 b1df9b71 2021-03-12 op static struct tab *new_tab(void);
160 9ca15951 2021-03-09 op static struct { int meta, key; } thiskey;
162 48e9d457 2021-03-06 op static WINDOW *tabline, *body, *modeline, *minibuf;
163 48e9d457 2021-03-06 op static int body_lines, body_cols;
165 48e9d457 2021-03-06 op static struct event clminibufev;
166 48e9d457 2021-03-06 op static int clminibufev_set;
167 a6d450c1 2021-03-06 op static struct timeval clminibufev_timer = { 5, 0 };
168 8af5e5ed 2021-03-08 op static struct timeval loadingev_timer = { 0, 250000 };
170 bcb0b073 2021-03-07 op static uint32_t tab_counter;
172 1d08c280 2021-03-06 op struct ui_state {
175 48e9d457 2021-03-06 op size_t line_off;
176 48e9d457 2021-03-06 op size_t line_max;
178 8af5e5ed 2021-03-08 op short loading_anim;
179 8af5e5ed 2021-03-08 op short loading_anim_step;
180 8af5e5ed 2021-03-08 op struct event loadingev;
182 1d08c280 2021-03-06 op TAILQ_HEAD(, line) head;
185 7c7d7bb7 2021-03-10 op static char keybuf[64];
187 9ca15951 2021-03-09 op struct kmap global_map,
188 fa3fd864 2021-03-10 op minibuffer_map,
189 9ca15951 2021-03-09 op *current_map,
192 22268e11 2021-03-11 op /* TODO: limit to a maximum number of entries */
193 22268e11 2021-03-11 op struct minibuf_histhead {
194 22268e11 2021-03-11 op TAILQ_HEAD(mhisthead, minibuf_hist) head;
197 22268e11 2021-03-11 op struct minibuf_hist {
198 22268e11 2021-03-11 op char h[1025];
199 22268e11 2021-03-11 op TAILQ_ENTRY(minibuf_hist) entries;
202 22268e11 2021-03-11 op static struct minibuf_histhead eecmd_history,
206 9ca15951 2021-03-09 op static int in_minibuffer;
208 9ca15951 2021-03-09 op static struct {
209 9cb0f9ce 2021-03-10 op char *curmesg;
211 040fbdf8 2021-03-10 op char buf[1025];
212 9ca15951 2021-03-09 op size_t off, len;
213 5cd2ebb1 2021-03-11 op char prompt[32];
214 b360ebb3 2021-03-10 op void (*donefn)(void);
215 b360ebb3 2021-03-10 op void (*abortfn)(void);
217 22268e11 2021-03-11 op struct minibuf_histhead *history;
218 22268e11 2021-03-11 op struct minibuf_hist *hist_cur;
219 22268e11 2021-03-11 op size_t hist_off;
222 f95d82dd 2021-03-11 op struct lineprefix {
223 f95d82dd 2021-03-11 op const char *prfx1;
224 f95d82dd 2021-03-11 op const char *prfx2;
225 f95d82dd 2021-03-11 op } line_prefixes[] = {
226 f95d82dd 2021-03-11 op [LINE_TEXT] = { "", "" },
227 f95d82dd 2021-03-11 op [LINE_LINK] = { "=> ", " " },
228 f95d82dd 2021-03-11 op [LINE_TITLE_1] = { "# ", " " },
229 f95d82dd 2021-03-11 op [LINE_TITLE_2] = { "## ", " " },
230 f95d82dd 2021-03-11 op [LINE_TITLE_3] = { "### ", " " },
231 f95d82dd 2021-03-11 op [LINE_ITEM] = { "* ", " " },
232 f95d82dd 2021-03-11 op [LINE_QUOTE] = { "> ", "> " },
233 f95d82dd 2021-03-11 op [LINE_PRE_START] = { "```", "```" },
234 f95d82dd 2021-03-11 op [LINE_PRE_CONTENT] = { "", "" },
235 f95d82dd 2021-03-11 op [LINE_PRE_END] = { "```", "```" },
238 d3d56d8a 2021-03-11 op struct line_face {
240 d3d56d8a 2021-03-11 op } line_faces[] = {
241 d3d56d8a 2021-03-11 op [LINE_TEXT] = { 0 },
242 d3d56d8a 2021-03-11 op [LINE_LINK] = { A_UNDERLINE },
243 d3d56d8a 2021-03-11 op [LINE_TITLE_1] = { A_BOLD },
244 d3d56d8a 2021-03-11 op [LINE_TITLE_2] = { A_BOLD },
245 d3d56d8a 2021-03-11 op [LINE_TITLE_3] = { A_BOLD },
246 d3d56d8a 2021-03-11 op [LINE_ITEM] = { 0 },
247 d3d56d8a 2021-03-11 op [LINE_QUOTE] = { A_DIM },
248 d3d56d8a 2021-03-11 op [LINE_PRE_START] = { 0 },
249 d3d56d8a 2021-03-11 op [LINE_PRE_CONTENT] = { 0 },
250 d3d56d8a 2021-03-11 op [LINE_PRE_END] = { 0 },
253 f832146f 2021-03-09 op static inline void
254 f832146f 2021-03-09 op global_set_key(const char *key, void (*fn)(struct tab*))
256 67c8ed7f 2021-03-13 op if (!kmap_define_key(&global_map, key, fn))
260 9ca15951 2021-03-09 op static inline void
261 fa3fd864 2021-03-10 op minibuffer_set_key(const char *key, void (*fn)(struct tab*))
263 67c8ed7f 2021-03-13 op if (!kmap_define_key(&minibuffer_map, key, fn))
268 f832146f 2021-03-09 op load_default_keys(void)
270 9ca15951 2021-03-09 op /* === global map === */
273 f832146f 2021-03-09 op global_set_key("C-p", cmd_previous_line);
274 f832146f 2021-03-09 op global_set_key("C-n", cmd_next_line);
275 f832146f 2021-03-09 op global_set_key("C-f", cmd_forward_char);
276 f832146f 2021-03-09 op global_set_key("C-b", cmd_backward_char);
277 a329982b 2021-03-11 op global_set_key("C-a", cmd_move_beginning_of_line);
278 a329982b 2021-03-11 op global_set_key("C-e", cmd_move_end_of_line);
280 f832146f 2021-03-09 op global_set_key("M-v", cmd_scroll_up);
281 f832146f 2021-03-09 op global_set_key("C-v", cmd_scroll_down);
282 929c2d9f 2021-03-13 op global_set_key("M-space", cmd_scroll_up);
283 929c2d9f 2021-03-13 op global_set_key("space", cmd_scroll_down);
285 f832146f 2021-03-09 op global_set_key("C-x C-c", cmd_kill_telescope);
287 3b4f9e49 2021-03-11 op global_set_key("C-g", cmd_clear_minibuf);
289 9ca15951 2021-03-09 op global_set_key("M-x", cmd_execute_extended_command);
290 5cd2ebb1 2021-03-11 op global_set_key("C-x C-f", cmd_load_url);
291 5cd2ebb1 2021-03-11 op global_set_key("C-x M-f", cmd_load_current_url);
293 7c7d7bb7 2021-03-10 op global_set_key("C-x t 0", cmd_tab_close);
294 7c7d7bb7 2021-03-10 op global_set_key("C-x t 2", cmd_tab_new);
295 7c7d7bb7 2021-03-10 op global_set_key("C-x t o", cmd_tab_next);
296 7c7d7bb7 2021-03-10 op global_set_key("C-x t O", cmd_tab_previous);
298 e19f9a04 2021-03-11 op global_set_key("M-<", cmd_beginning_of_buffer);
299 e19f9a04 2021-03-11 op global_set_key("M->", cmd_end_of_buffer);
301 f832146f 2021-03-09 op /* vi/vi-like */
302 f832146f 2021-03-09 op global_set_key("k", cmd_previous_line);
303 f832146f 2021-03-09 op global_set_key("j", cmd_next_line);
304 f832146f 2021-03-09 op global_set_key("l", cmd_forward_char);
305 f832146f 2021-03-09 op global_set_key("h", cmd_backward_char);
306 a329982b 2021-03-11 op global_set_key("^", cmd_move_beginning_of_line);
307 a329982b 2021-03-11 op global_set_key("$", cmd_move_end_of_line);
309 ed44414d 2021-03-09 op global_set_key("K", cmd_scroll_line_up);
310 ed44414d 2021-03-09 op global_set_key("J", cmd_scroll_line_down);
312 e19f9a04 2021-03-11 op global_set_key("g g", cmd_beginning_of_buffer);
313 e19f9a04 2021-03-11 op global_set_key("G", cmd_end_of_buffer);
316 f832146f 2021-03-09 op global_set_key("q", cmd_kill_telescope);
318 3b4f9e49 2021-03-11 op global_set_key("esc", cmd_clear_minibuf);
320 9ca15951 2021-03-09 op global_set_key(":", cmd_execute_extended_command);
323 f832146f 2021-03-09 op global_set_key("<up>", cmd_previous_line);
324 f832146f 2021-03-09 op global_set_key("<down>", cmd_next_line);
325 f832146f 2021-03-09 op global_set_key("<right>", cmd_forward_char);
326 f832146f 2021-03-09 op global_set_key("<left>", cmd_backward_char);
327 ed44414d 2021-03-09 op global_set_key("<prior>", cmd_scroll_up);
328 ed44414d 2021-03-09 op global_set_key("<next>", cmd_scroll_down);
330 f832146f 2021-03-09 op /* "ncurses standard" */
331 f832146f 2021-03-09 op global_set_key("C-l", cmd_redraw);
334 f832146f 2021-03-09 op global_set_key("C-m", cmd_push_button);
335 b1df9b71 2021-03-12 op global_set_key("M-enter", cmd_push_button_new_tab);
337 fa3fd864 2021-03-10 op /* === minibuffer map === */
338 b360ebb3 2021-03-10 op minibuffer_set_key("ret", cmd_mini_complete_and_exit);
339 b360ebb3 2021-03-10 op minibuffer_set_key("C-g", cmd_mini_abort);
340 b360ebb3 2021-03-10 op minibuffer_set_key("esc", cmd_mini_abort);
341 d67133bf 2021-03-12 op minibuffer_set_key("C-d", cmd_mini_delete_char);
342 d67133bf 2021-03-12 op minibuffer_set_key("del", cmd_mini_delete_backward_char);
344 fa3fd864 2021-03-10 op minibuffer_set_key("C-f", cmd_mini_forward_char);
345 fa3fd864 2021-03-10 op minibuffer_set_key("C-b", cmd_mini_backward_char);
346 5b2bf704 2021-03-12 op minibuffer_set_key("<right>", cmd_mini_forward_char);
347 5b2bf704 2021-03-12 op minibuffer_set_key("<left>", cmd_mini_backward_char);
348 fa3fd864 2021-03-10 op minibuffer_set_key("C-e", cmd_mini_move_end_of_line);
349 fa3fd864 2021-03-10 op minibuffer_set_key("C-a", cmd_mini_move_beginning_of_line);
350 fa3fd864 2021-03-10 op minibuffer_set_key("<end>", cmd_mini_move_end_of_line);
351 fa3fd864 2021-03-10 op minibuffer_set_key("<home>", cmd_mini_move_beginning_of_line);
352 fa3fd864 2021-03-10 op minibuffer_set_key("C-k", cmd_mini_kill_line);
354 22268e11 2021-03-11 op minibuffer_set_key("M-p", cmd_mini_previous_history_element);
355 22268e11 2021-03-11 op minibuffer_set_key("M-n", cmd_mini_next_history_element);
356 22268e11 2021-03-11 op minibuffer_set_key("<up>", cmd_mini_previous_history_element);
357 22268e11 2021-03-11 op minibuffer_set_key("<down>", cmd_mini_next_history_element);
361 768db5bb 2021-03-12 op push_line(struct tab *tab, const struct line *l, const char *buf, size_t len, int cont)
363 1d08c280 2021-03-06 op struct line *vl;
365 48e9d457 2021-03-06 op tab->s->line_max++;
367 1d08c280 2021-03-06 op if ((vl = calloc(1, sizeof(*vl))) == NULL)
370 1d08c280 2021-03-06 op if (len != 0 && (vl->line = calloc(1, len+1)) == NULL) {
375 1d08c280 2021-03-06 op vl->type = l->type;
376 1d08c280 2021-03-06 op if (len != 0)
377 1d08c280 2021-03-06 op memcpy(vl->line, buf, len);
378 1d08c280 2021-03-06 op vl->alt = l->alt;
379 768db5bb 2021-03-12 op vl->flags = cont;
381 1d08c280 2021-03-06 op if (TAILQ_EMPTY(&tab->s->head))
382 1d08c280 2021-03-06 op TAILQ_INSERT_HEAD(&tab->s->head, vl, lines);
384 1d08c280 2021-03-06 op TAILQ_INSERT_TAIL(&tab->s->head, vl, lines);
389 1d08c280 2021-03-06 op empty_vlist(struct tab *tab)
391 1d08c280 2021-03-06 op struct line *l, *t;
393 48e9d457 2021-03-06 op tab->s->line_max = 0;
395 1d08c280 2021-03-06 op TAILQ_FOREACH_SAFE(l, &tab->s->head, lines, t) {
396 1d08c280 2021-03-06 op TAILQ_REMOVE(&tab->s->head, l, lines);
397 1d08c280 2021-03-06 op free(l->line);
398 1d08c280 2021-03-06 op /* l->alt references the original line! */
404 48e9d457 2021-03-06 op restore_cursor(struct tab *tab)
406 48e9d457 2021-03-06 op wmove(body, tab->s->curs_y, tab->s->curs_x);
410 46a9311e 2021-03-08 op cmd_previous_line(struct tab *tab)
412 4dd664ce 2021-03-06 op if (--tab->s->curs_y < 0) {
413 4dd664ce 2021-03-06 op tab->s->curs_y = 0;
414 ed44414d 2021-03-09 op cmd_scroll_line_up(tab);
417 48e9d457 2021-03-06 op restore_cursor(tab);
421 46a9311e 2021-03-08 op cmd_next_line(struct tab *tab)
423 fed61466 2021-03-11 op if (tab->s->line_off + tab->s->curs_y >= tab->s->line_max)
426 4dd664ce 2021-03-06 op if (++tab->s->curs_y > body_lines-1) {
427 4dd664ce 2021-03-06 op tab->s->curs_y = body_lines-1;
428 ed44414d 2021-03-09 op cmd_scroll_line_down(tab);
431 48e9d457 2021-03-06 op restore_cursor(tab);
435 46a9311e 2021-03-08 op cmd_forward_char(struct tab *tab)
437 4dd664ce 2021-03-06 op tab->s->curs_x = MIN(body_cols-1, tab->s->curs_x+1);
438 48e9d457 2021-03-06 op restore_cursor(tab);
442 46a9311e 2021-03-08 op cmd_backward_char(struct tab *tab)
444 b2cd5e06 2021-03-06 op tab->s->curs_x = MAX(0, tab->s->curs_x-1);
445 a329982b 2021-03-11 op restore_cursor(tab);
449 a329982b 2021-03-11 op cmd_move_beginning_of_line(struct tab *tab)
451 a329982b 2021-03-11 op tab->s->curs_x = 0;
452 a329982b 2021-03-11 op restore_cursor(tab);
456 a329982b 2021-03-11 op cmd_move_end_of_line(struct tab *tab)
458 a329982b 2021-03-11 op struct line *line;
460 f95d82dd 2021-03-11 op const char *prfx;
462 a329982b 2021-03-11 op off = tab->s->line_off + tab->s->curs_y;
463 a329982b 2021-03-11 op if (off >= tab->s->line_max) {
464 a329982b 2021-03-11 op tab->s->curs_x = 0;
468 a329982b 2021-03-11 op line = nth_line(tab, off);
469 a329982b 2021-03-11 op if (line->line != NULL)
470 a329982b 2021-03-11 op tab->s->curs_x = strlen(line->line);
472 a329982b 2021-03-11 op tab->s->curs_x = 0;
474 f95d82dd 2021-03-11 op prfx = line_prefixes[line->type].prfx1;
475 f95d82dd 2021-03-11 op tab->s->curs_x += strlen(prfx);
478 48e9d457 2021-03-06 op restore_cursor(tab);
482 46a9311e 2021-03-08 op cmd_redraw(struct tab *tab)
484 b1738d2e 2021-03-06 op handle_resize(0, 0, NULL);
488 ed44414d 2021-03-09 op cmd_scroll_line_up(struct tab *tab)
490 48e9d457 2021-03-06 op struct line *l;
492 48e9d457 2021-03-06 op if (tab->s->line_off == 0)
495 48e9d457 2021-03-06 op l = nth_line(tab, --tab->s->line_off);
496 48e9d457 2021-03-06 op wscrl(body, -1);
497 48e9d457 2021-03-06 op wmove(body, 0, 0);
498 48e9d457 2021-03-06 op print_line(l);
502 ed44414d 2021-03-09 op cmd_scroll_line_down(struct tab *tab)
504 48e9d457 2021-03-06 op struct line *l;
507 48e9d457 2021-03-06 op if (tab->s->line_max == 0 || tab->s->line_off == tab->s->line_max-1)
510 48e9d457 2021-03-06 op tab->s->line_off++;
511 48e9d457 2021-03-06 op wscrl(body, 1);
513 48e9d457 2021-03-06 op if (tab->s->line_max - tab->s->line_off < body_lines)
516 48e9d457 2021-03-06 op l = nth_line(tab, tab->s->line_off + body_lines-1);
517 48e9d457 2021-03-06 op wmove(body, body_lines-1, 0);
518 48e9d457 2021-03-06 op print_line(l);
522 ed44414d 2021-03-09 op cmd_scroll_up(struct tab *tab)
526 ed44414d 2021-03-09 op off = body_lines+1;
528 ed44414d 2021-03-09 op for (; off > 0; --off)
529 ed44414d 2021-03-09 op cmd_scroll_line_up(tab);
533 ed44414d 2021-03-09 op cmd_scroll_down(struct tab *tab)
537 338eecdc 2021-03-12 op off = body_lines+1;
539 338eecdc 2021-03-12 op for (; off > 0; --off)
540 ed44414d 2021-03-09 op cmd_scroll_line_down(tab);
544 e19f9a04 2021-03-11 op cmd_beginning_of_buffer(struct tab *tab)
546 e19f9a04 2021-03-11 op tab->s->line_off = 0;
547 e19f9a04 2021-03-11 op tab->s->curs_y = 0;
548 e19f9a04 2021-03-11 op redraw_body(tab);
552 e19f9a04 2021-03-11 op cmd_end_of_buffer(struct tab *tab)
556 e19f9a04 2021-03-11 op off = tab->s->line_max - body_lines;
557 e19f9a04 2021-03-11 op off = MAX(0, off);
559 e19f9a04 2021-03-11 op tab->s->line_off = off;
560 e19f9a04 2021-03-11 op tab->s->curs_y = MIN(body_lines, tab->s->line_max);
562 e19f9a04 2021-03-11 op redraw_body(tab);
566 46a9311e 2021-03-08 op cmd_kill_telescope(struct tab *tab)
568 1d08c280 2021-03-06 op event_loopbreak();
572 46a9311e 2021-03-08 op cmd_push_button(struct tab *tab)
574 2a4ad912 2021-03-08 op struct line *l;
577 2a4ad912 2021-03-08 op nth = tab->s->line_off + tab->s->curs_y;
578 cb8d5d9b 2021-03-13 op if (nth >= tab->s->line_max)
580 2a4ad912 2021-03-08 op l = nth_line(tab, nth);
581 43a1b8d0 2021-03-09 op if (l->type != LINE_LINK)
584 43a1b8d0 2021-03-09 op load_url_in_tab(tab, l->alt);
588 b1df9b71 2021-03-12 op cmd_push_button_new_tab(struct tab *tab)
590 b1df9b71 2021-03-12 op struct tab *t;
591 b1df9b71 2021-03-12 op struct line *l;
594 b1df9b71 2021-03-12 op nth = tab->s->line_off + tab->s->curs_y;
595 b1df9b71 2021-03-12 op if (nth > tab->s->line_max)
597 b1df9b71 2021-03-12 op l = nth_line(tab, nth);
598 b1df9b71 2021-03-12 op if (l->type != LINE_LINK)
601 b1df9b71 2021-03-12 op t = new_tab();
602 b1df9b71 2021-03-12 op memcpy(&t->url, &tab->url, sizeof(tab->url));
603 b1df9b71 2021-03-12 op memcpy(&t->urlstr, &tab->urlstr, sizeof(tab->urlstr));
604 b1df9b71 2021-03-12 op load_url_in_tab(t, l->alt);
608 3b4f9e49 2021-03-11 op cmd_clear_minibuf(struct tab *tab)
610 3b4f9e49 2021-03-11 op handle_clear_minibuf(0, 0, NULL);
614 9ca15951 2021-03-09 op cmd_execute_extended_command(struct tab *tab)
618 22268e11 2021-03-11 op enter_minibuffer(eecmd_self_insert, eecmd_select, exit_minibuffer,
619 22268e11 2021-03-11 op &eecmd_history);
621 9ca15951 2021-03-09 op len = sizeof(ministate.prompt);
622 9ca15951 2021-03-09 op strlcpy(ministate.prompt, "", len);
624 9ca15951 2021-03-09 op if (thiskey.meta)
625 9ca15951 2021-03-09 op strlcat(ministate.prompt, "M-", len);
627 9ca15951 2021-03-09 op strlcat(ministate.prompt, keyname(thiskey.key), len);
628 9ca15951 2021-03-09 op strlcat(ministate.prompt, " ", len);
632 7c7d7bb7 2021-03-10 op cmd_tab_close(struct tab *tab)
634 7c7d7bb7 2021-03-10 op struct tab *t;
636 7c7d7bb7 2021-03-10 op if (TAILQ_PREV(tab, tabshead, tabs) == NULL &&
637 7c7d7bb7 2021-03-10 op TAILQ_NEXT(tab, tabs) == NULL) {
638 7c7d7bb7 2021-03-10 op message("Can't close the only tab.");
642 7c7d7bb7 2021-03-10 op stop_tab(tab);
644 7c7d7bb7 2021-03-10 op t = TAILQ_PREV(tab, tabshead, tabs);
645 7c7d7bb7 2021-03-10 op t->flags |= TAB_CURRENT;
647 7c7d7bb7 2021-03-10 op TAILQ_REMOVE(&tabshead, tab, tabs);
649 7c7d7bb7 2021-03-10 op free(tab->s);
654 7c7d7bb7 2021-03-10 op cmd_tab_new(struct tab *tab)
660 7c7d7bb7 2021-03-10 op cmd_tab_next(struct tab *tab)
662 7c7d7bb7 2021-03-10 op struct tab *t;
664 7c7d7bb7 2021-03-10 op tab->flags &= ~TAB_CURRENT;
666 7c7d7bb7 2021-03-10 op if ((t = TAILQ_NEXT(tab, tabs)) == NULL)
667 7c7d7bb7 2021-03-10 op t = TAILQ_FIRST(&tabshead);
668 7c7d7bb7 2021-03-10 op t->flags |= TAB_CURRENT;
672 7c7d7bb7 2021-03-10 op cmd_tab_previous(struct tab *tab)
674 7c7d7bb7 2021-03-10 op struct tab *t;
676 7c7d7bb7 2021-03-10 op tab->flags &= ~TAB_CURRENT;
678 7c7d7bb7 2021-03-10 op if ((t = TAILQ_PREV(tab, tabshead, tabs)) == NULL)
679 7c7d7bb7 2021-03-10 op t = TAILQ_LAST(&tabshead, tabshead);
680 7c7d7bb7 2021-03-10 op t->flags |= TAB_CURRENT;
684 5cd2ebb1 2021-03-11 op cmd_load_url(struct tab *tab)
686 22268e11 2021-03-11 op enter_minibuffer(lu_self_insert, lu_select, exit_minibuffer,
687 22268e11 2021-03-11 op &lu_history);
688 5cd2ebb1 2021-03-11 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
692 5cd2ebb1 2021-03-11 op cmd_load_current_url(struct tab *tab)
694 22268e11 2021-03-11 op enter_minibuffer(lu_self_insert, lu_select, exit_minibuffer,
695 22268e11 2021-03-11 op &lu_history);
696 5cd2ebb1 2021-03-11 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
697 5cd2ebb1 2021-03-11 op strlcpy(ministate.buf, tab->urlstr, sizeof(ministate.buf));
698 5cd2ebb1 2021-03-11 op ministate.off = strlen(tab->urlstr);
699 5cd2ebb1 2021-03-11 op ministate.len = ministate.off;
703 7c7d7bb7 2021-03-10 op global_key_unbound(void)
705 7c7d7bb7 2021-03-10 op message("%s is undefined", keybuf);
709 d67133bf 2021-03-12 op cmd_mini_delete_char(struct tab *tab)
711 3eecee9e 2021-03-12 op minibuffer_taint_hist();
713 d67133bf 2021-03-12 op if (ministate.len == 0 || ministate.off == ministate.len)
716 d67133bf 2021-03-12 op memmove(&ministate.buf[ministate.off],
717 d67133bf 2021-03-12 op &ministate.buf[ministate.off+1],
718 d67133bf 2021-03-12 op ministate.len - ministate.off + 1);
719 d67133bf 2021-03-12 op ministate.len--;
723 d67133bf 2021-03-12 op cmd_mini_delete_backward_char(struct tab *tab)
725 3eecee9e 2021-03-12 op minibuffer_taint_hist();
727 9ca15951 2021-03-09 op if (ministate.len == 0 || ministate.off == 0)
730 9ca15951 2021-03-09 op memmove(&ministate.buf[ministate.off-1],
731 9ca15951 2021-03-09 op &ministate.buf[ministate.off],
732 9ca15951 2021-03-09 op ministate.len - ministate.off + 1);
733 9ca15951 2021-03-09 op ministate.off--;
734 9ca15951 2021-03-09 op ministate.len--;
738 9ca15951 2021-03-09 op cmd_mini_forward_char(struct tab *tab)
740 9ca15951 2021-03-09 op if (ministate.off == ministate.len)
742 9ca15951 2021-03-09 op ministate.off++;
746 9ca15951 2021-03-09 op cmd_mini_backward_char(struct tab *tab)
748 9ca15951 2021-03-09 op if (ministate.off == 0)
750 9ca15951 2021-03-09 op ministate.off--;
754 9ca15951 2021-03-09 op cmd_mini_move_end_of_line(struct tab *tab)
756 9ca15951 2021-03-09 op ministate.off = ministate.len;
760 9ca15951 2021-03-09 op cmd_mini_move_beginning_of_line(struct tab *tab)
762 9ca15951 2021-03-09 op ministate.off = 0;
766 fa3fd864 2021-03-10 op cmd_mini_kill_line(struct tab *tab)
768 3eecee9e 2021-03-12 op minibuffer_taint_hist();
770 fa3fd864 2021-03-10 op if (ministate.off == ministate.len)
772 fa3fd864 2021-03-10 op ministate.buf[ministate.off] = '\0';
773 fa3fd864 2021-03-10 op ministate.len -= ministate.off;
777 b360ebb3 2021-03-10 op cmd_mini_abort(struct tab *tab)
779 b360ebb3 2021-03-10 op ministate.abortfn();
783 b360ebb3 2021-03-10 op cmd_mini_complete_and_exit(struct tab *tab)
785 22268e11 2021-03-11 op minibuffer_taint_hist();
786 b360ebb3 2021-03-10 op ministate.donefn();
790 22268e11 2021-03-11 op cmd_mini_previous_history_element(struct tab *tab)
792 22268e11 2021-03-11 op if (ministate.history == NULL) {
793 22268e11 2021-03-11 op message("No history");
797 22268e11 2021-03-11 op if (ministate.hist_cur == NULL ||
798 22268e11 2021-03-11 op (ministate.hist_cur = TAILQ_PREV(ministate.hist_cur, mhisthead, entries)) == NULL) {
799 22268e11 2021-03-11 op ministate.hist_cur = TAILQ_LAST(&ministate.history->head, mhisthead);
800 22268e11 2021-03-11 op ministate.hist_off = ministate.history->len - 1;
801 22268e11 2021-03-11 op if (ministate.hist_cur == NULL)
802 22268e11 2021-03-11 op message("No prev item");
804 22268e11 2021-03-11 op ministate.hist_off--;
807 22268e11 2021-03-11 op if (ministate.hist_cur != NULL) {
808 22268e11 2021-03-11 op ministate.off = 0;
809 22268e11 2021-03-11 op ministate.len = strlen(ministate.hist_cur->h);
814 22268e11 2021-03-11 op cmd_mini_next_history_element(struct tab *tab)
816 22268e11 2021-03-11 op if (ministate.history == NULL) {
817 22268e11 2021-03-11 op message("No history");
821 22268e11 2021-03-11 op if (ministate.hist_cur == NULL ||
822 22268e11 2021-03-11 op (ministate.hist_cur = TAILQ_NEXT(ministate.hist_cur, entries)) == NULL) {
823 22268e11 2021-03-11 op ministate.hist_cur = TAILQ_FIRST(&ministate.history->head);
824 22268e11 2021-03-11 op ministate.hist_off = 0;
825 22268e11 2021-03-11 op if (ministate.hist_cur == NULL)
826 22268e11 2021-03-11 op message("No next item");
828 22268e11 2021-03-11 op ministate.hist_off++;
831 22268e11 2021-03-11 op if (ministate.hist_cur != NULL) {
832 22268e11 2021-03-11 op ministate.off = 0;
833 22268e11 2021-03-11 op ministate.len = strlen(ministate.hist_cur->h);
838 22268e11 2021-03-11 op minibuffer_hist_save_entry(void)
840 22268e11 2021-03-11 op struct minibuf_hist *hist;
842 22268e11 2021-03-11 op if (ministate.history == NULL)
845 22268e11 2021-03-11 op if ((hist = calloc(1, sizeof(*hist))) == NULL)
848 22268e11 2021-03-11 op strlcpy(hist->h, ministate.buf, sizeof(hist->h));
850 22268e11 2021-03-11 op if (TAILQ_EMPTY(&ministate.history->head))
851 22268e11 2021-03-11 op TAILQ_INSERT_HEAD(&ministate.history->head, hist, entries);
853 22268e11 2021-03-11 op TAILQ_INSERT_TAIL(&ministate.history->head, hist, entries);
854 22268e11 2021-03-11 op ministate.history->len++;
858 22268e11 2021-03-11 op * taint the minibuffer cache: if we're currently showing a history
859 22268e11 2021-03-11 op * element, copy that to the current buf and reset the "history
860 22268e11 2021-03-11 op * navigation" thing.
863 22268e11 2021-03-11 op minibuffer_taint_hist(void)
865 22268e11 2021-03-11 op if (ministate.hist_cur == NULL)
868 22268e11 2021-03-11 op strlcpy(ministate.buf, ministate.hist_cur->h, sizeof(ministate.buf));
869 22268e11 2021-03-11 op ministate.hist_cur = NULL;
873 5cd2ebb1 2021-03-11 op minibuffer_self_insert(void)
875 22268e11 2021-03-11 op minibuffer_taint_hist();
877 040fbdf8 2021-03-10 op if (ministate.len == sizeof(ministate.buf) -1)
880 9ca15951 2021-03-09 op /* TODO: utf8 handling! */
882 9ca15951 2021-03-09 op memmove(&ministate.buf[ministate.off+1],
883 9ca15951 2021-03-09 op &ministate.buf[ministate.off],
884 9ca15951 2021-03-09 op ministate.len - ministate.off + 1);
885 9ca15951 2021-03-09 op ministate.buf[ministate.off] = thiskey.key;
886 9ca15951 2021-03-09 op ministate.off++;
887 9ca15951 2021-03-09 op ministate.len++;
891 5cd2ebb1 2021-03-11 op eecmd_self_insert(void)
893 5cd2ebb1 2021-03-11 op if (thiskey.meta || isspace(thiskey.key) ||
894 5cd2ebb1 2021-03-11 op !isgraph(thiskey.key)) {
895 5cd2ebb1 2021-03-11 op global_key_unbound();
899 5cd2ebb1 2021-03-11 op minibuffer_self_insert();
903 b360ebb3 2021-03-10 op eecmd_select(void)
905 b360ebb3 2021-03-10 op exit_minibuffer();
906 22268e11 2021-03-11 op minibuffer_hist_save_entry();
907 b360ebb3 2021-03-10 op message("TODO: try to execute %s", ministate.buf);
911 5cd2ebb1 2021-03-11 op ir_self_insert(void)
913 5cd2ebb1 2021-03-11 op minibuffer_self_insert();
917 5cd2ebb1 2021-03-11 op ir_select(void)
919 5cd2ebb1 2021-03-11 op char buf[1025] = {0};
920 5cd2ebb1 2021-03-11 op struct url url;
921 5cd2ebb1 2021-03-11 op struct tab *tab;
923 5cd2ebb1 2021-03-11 op tab = current_tab();
925 5cd2ebb1 2021-03-11 op exit_minibuffer();
926 22268e11 2021-03-11 op minibuffer_hist_save_entry();
928 5cd2ebb1 2021-03-11 op /* a bit ugly but... */
929 5cd2ebb1 2021-03-11 op memcpy(&url, &tab->url, sizeof(tab->url));
930 5cd2ebb1 2021-03-11 op url_set_query(&url, ministate.buf);
931 5cd2ebb1 2021-03-11 op url_unparse(&url, buf, sizeof(buf));
932 5cd2ebb1 2021-03-11 op load_url_in_tab(tab, buf);
936 5cd2ebb1 2021-03-11 op lu_self_insert(void)
938 5cd2ebb1 2021-03-11 op if (thiskey.meta || isspace(thiskey.key) ||
939 5cd2ebb1 2021-03-11 op !isgraph(thiskey.key)) {
940 5cd2ebb1 2021-03-11 op global_key_unbound();
944 5cd2ebb1 2021-03-11 op minibuffer_self_insert();
948 5cd2ebb1 2021-03-11 op lu_select(void)
950 5cd2ebb1 2021-03-11 op exit_minibuffer();
951 22268e11 2021-03-11 op minibuffer_hist_save_entry();
952 5cd2ebb1 2021-03-11 op load_url_in_tab(current_tab(), ministate.buf);
955 48e9d457 2021-03-06 op static struct line *
956 48e9d457 2021-03-06 op nth_line(struct tab *tab, size_t n)
958 48e9d457 2021-03-06 op struct line *l;
962 48e9d457 2021-03-06 op TAILQ_FOREACH(l, &tab->s->head, lines) {
968 48e9d457 2021-03-06 op /* unreachable */
972 5e11c00c 2021-03-02 op static struct tab *
973 5e11c00c 2021-03-02 op current_tab(void)
975 5e11c00c 2021-03-02 op struct tab *t;
977 5e11c00c 2021-03-02 op TAILQ_FOREACH(t, &tabshead, tabs) {
978 5e11c00c 2021-03-02 op if (t->flags & TAB_CURRENT)
982 5e11c00c 2021-03-02 op /* unreachable */
987 5e11c00c 2021-03-02 op dispatch_stdio(int fd, short ev, void *d)
989 481340cc 2021-03-11 op struct tab *tab;
990 f832146f 2021-03-09 op struct keymap *k;
991 7c7d7bb7 2021-03-10 op const char *keyname;
992 7c7d7bb7 2021-03-10 op char tmp[2] = {0};
994 9ca15951 2021-03-09 op thiskey.key = wgetch(body);
995 9ca15951 2021-03-09 op if (thiskey.key == ERR)
997 9ca15951 2021-03-09 op if (thiskey.key == 27) {
998 f832146f 2021-03-09 op /* TODO: make escape-time customizable */
1000 9ca15951 2021-03-09 op thiskey.meta = 1;
1001 9ca15951 2021-03-09 op thiskey.key = wgetch(body);
1002 c314a314 2021-03-11 op if (thiskey.key == ERR || thiskey.key == 27) {
1003 c314a314 2021-03-11 op thiskey.meta = 0;
1004 9ca15951 2021-03-09 op thiskey.key = 27;
1007 9ca15951 2021-03-09 op thiskey.meta = 0;
1009 7c7d7bb7 2021-03-10 op if (keybuf[0] != '\0')
1010 7c7d7bb7 2021-03-10 op strlcat(keybuf, " ", sizeof(keybuf));
1011 7c7d7bb7 2021-03-10 op if (thiskey.meta)
1012 7c7d7bb7 2021-03-10 op strlcat(keybuf, "M-", sizeof(keybuf));
1013 7c7d7bb7 2021-03-10 op if ((keyname = unkbd(thiskey.key)) != NULL)
1014 7c7d7bb7 2021-03-10 op strlcat(keybuf, keyname, sizeof(keybuf));
1016 7c7d7bb7 2021-03-10 op tmp[0] = thiskey.key;
1017 7c7d7bb7 2021-03-10 op strlcat(keybuf, tmp, sizeof(keybuf));
1020 9ca15951 2021-03-09 op TAILQ_FOREACH(k, ¤t_map->m, keymaps) {
1021 9ca15951 2021-03-09 op if (k->meta == thiskey.meta &&
1022 9ca15951 2021-03-09 op k->key == thiskey.key) {
1023 f832146f 2021-03-09 op if (k->fn == NULL)
1024 f832146f 2021-03-09 op current_map = &k->map;
1026 9ca15951 2021-03-09 op current_map = base_map;
1027 7c7d7bb7 2021-03-10 op strlcpy(keybuf, "", sizeof(keybuf));
1028 f832146f 2021-03-09 op k->fn(current_tab());
1034 7c7d7bb7 2021-03-10 op if (current_map->unhandled_input != NULL)
1035 7c7d7bb7 2021-03-10 op current_map->unhandled_input();
1037 7c7d7bb7 2021-03-10 op global_key_unbound();
1040 7c7d7bb7 2021-03-10 op strlcpy(keybuf, "", sizeof(keybuf));
1041 9ca15951 2021-03-09 op current_map = base_map;
1044 179f0f58 2021-03-11 op redraw_tab(current_tab());
1048 a6d450c1 2021-03-06 op handle_clear_minibuf(int fd, short ev, void *d)
1050 a6d450c1 2021-03-06 op clminibufev_set = 0;
1052 9cb0f9ce 2021-03-10 op free(ministate.curmesg);
1053 9cb0f9ce 2021-03-10 op ministate.curmesg = NULL;
1055 9cb0f9ce 2021-03-10 op redraw_minibuffer();
1056 9cb0f9ce 2021-03-10 op if (in_minibuffer) {
1057 9cb0f9ce 2021-03-10 op wrefresh(body);
1058 9cb0f9ce 2021-03-10 op wrefresh(minibuf);
1060 9cb0f9ce 2021-03-10 op wrefresh(minibuf);
1061 9cb0f9ce 2021-03-10 op wrefresh(body);
1066 5e11c00c 2021-03-02 op handle_resize(int sig, short ev, void *d)
1068 1d08c280 2021-03-06 op struct tab *tab;
1074 48e9d457 2021-03-06 op /* move and resize the windows, in reverse order! */
1076 b1738d2e 2021-03-06 op mvwin(minibuf, LINES-1, 0);
1077 48e9d457 2021-03-06 op wresize(minibuf, 1, COLS);
1079 48e9d457 2021-03-06 op mvwin(modeline, LINES-2, 0);
1080 48e9d457 2021-03-06 op wresize(modeline, 1, COLS);
1082 48e9d457 2021-03-06 op wresize(body, LINES-3, COLS);
1083 48e9d457 2021-03-06 op body_lines = LINES-3;
1084 bd9637e9 2021-03-06 op body_cols = COLS;
1086 48e9d457 2021-03-06 op wresize(tabline, 1, COLS);
1088 1d08c280 2021-03-06 op tab = current_tab();
1090 1d08c280 2021-03-06 op wrap_page(tab);
1091 1d08c280 2021-03-06 op redraw_tab(tab);
1095 eb259e66 2021-03-02 op * Helper function for wrap_text. Find the end of the current word
1096 eb259e66 2021-03-02 op * and the end of the separator after the word.
1099 eb259e66 2021-03-02 op word_boundaries(const char *s, const char *sep, const char **endword, const char **endspc)
1101 eb259e66 2021-03-02 op *endword = s;
1102 eb259e66 2021-03-02 op *endword = s;
1104 eb259e66 2021-03-02 op if (*s == '\0')
1107 eb259e66 2021-03-02 op /* find the end of the current world */
1108 eb259e66 2021-03-02 op for (; *s != '\0'; ++s) {
1109 eb259e66 2021-03-02 op if (strchr(sep, *s) != NULL)
1113 eb259e66 2021-03-02 op *endword = s;
1115 eb259e66 2021-03-02 op /* find the end of the separator */
1116 eb259e66 2021-03-02 op for (; *s != '\0'; ++s) {
1117 eb259e66 2021-03-02 op if (strchr(sep, *s) == NULL)
1121 eb259e66 2021-03-02 op *endspc = s;
1126 1d08c280 2021-03-06 op static inline int
1127 1d08c280 2021-03-06 op emitline(struct tab *tab, size_t zero, size_t *off, const struct line *l,
1128 768db5bb 2021-03-12 op const char **line, int *cont)
1130 768db5bb 2021-03-12 op if (!push_line(tab, l, *line, *off - zero, *cont))
1134 1d08c280 2021-03-06 op *line += *off - zero;
1135 eb259e66 2021-03-02 op *off = zero;
1139 eb259e66 2021-03-02 op static inline void
1140 eb259e66 2021-03-02 op emitstr(const char **s, size_t len, size_t *off)
1144 eb259e66 2021-03-02 op /* printw("%*s", ...) doesn't seem to respect the precision, so... */
1145 eb259e66 2021-03-02 op for (i = 0; i < len; ++i)
1146 eb259e66 2021-03-02 op addch((*s)[i]);
1147 eb259e66 2021-03-02 op *off += len;
1152 1d08c280 2021-03-06 op * Build a list of visual line by wrapping the given line, assuming
1153 1d08c280 2021-03-06 op * that when printed will have a leading prefix prfx.
1155 eb259e66 2021-03-02 op * TODO: it considers each byte one cell on the screen!
1158 1d08c280 2021-03-06 op wrap_text(struct tab *tab, const char *prfx, struct line *l)
1160 eb259e66 2021-03-02 op size_t zero, off, len, split;
1161 768db5bb 2021-03-12 op int cont = 0;
1162 1d08c280 2021-03-06 op const char *endword, *endspc, *line, *linestart;
1164 1d08c280 2021-03-06 op zero = strlen(prfx);
1166 1d08c280 2021-03-06 op line = l->line;
1167 1d08c280 2021-03-06 op linestart = l->line;
1169 1d08c280 2021-03-06 op while (word_boundaries(line, " \t-", &endword, &endspc)) {
1170 eb259e66 2021-03-02 op len = endword - line;
1171 48e9d457 2021-03-06 op if (off + len >= body_cols) {
1172 768db5bb 2021-03-12 op emitline(tab, zero, &off, l, &linestart, &cont);
1173 48e9d457 2021-03-06 op while (len >= body_cols) {
1174 eb259e66 2021-03-02 op /* hard wrap */
1175 768db5bb 2021-03-12 op emitline(tab, zero, &off, l, &linestart, &cont);
1176 48e9d457 2021-03-06 op len -= body_cols-1;
1177 48e9d457 2021-03-06 op line += body_cols-1;
1180 eb259e66 2021-03-02 op if (len != 0)
1185 eb259e66 2021-03-02 op /* print the spaces iff not at bol */
1186 eb259e66 2021-03-02 op len = endspc - endword;
1187 eb259e66 2021-03-02 op /* line = endspc; */
1188 eb259e66 2021-03-02 op if (off != zero) {
1189 48e9d457 2021-03-06 op if (off + len >= body_cols) {
1190 768db5bb 2021-03-12 op emitline(tab, zero, &off, l, &linestart, &cont);
1191 1d08c280 2021-03-06 op linestart = endspc;
1196 eb259e66 2021-03-02 op line = endspc;
1199 768db5bb 2021-03-12 op emitline(tab, zero, &off, l, &linestart, &cont);
1203 1d08c280 2021-03-06 op hardwrap_text(struct tab *tab, struct line *l)
1205 1d08c280 2021-03-06 op size_t off, len;
1207 1d08c280 2021-03-06 op const char *linestart;
1209 c49d61bc 2021-03-12 op if (l->line == NULL)
1210 768db5bb 2021-03-12 op return emitline(tab, 0, &off, l, &linestart, &cont);
1212 1d08c280 2021-03-06 op len = strlen(l->line);
1214 1d08c280 2021-03-06 op linestart = l->line;
1216 1d08c280 2021-03-06 op while (len >= COLS) {
1217 1d08c280 2021-03-06 op len -= COLS-1;
1218 1d08c280 2021-03-06 op off = COLS-1;
1219 768db5bb 2021-03-12 op if (!emitline(tab, 0, &off, l, &linestart, &cont))
1223 ede1f142 2021-03-07 op if (len != 0)
1224 768db5bb 2021-03-12 op return emitline(tab, 0, &len, l, &linestart, &cont);
1230 1d08c280 2021-03-06 op wrap_page(struct tab *tab)
1232 1d08c280 2021-03-06 op struct line *l;
1233 0d568960 2021-03-11 op const char *prfx;
1235 1d08c280 2021-03-06 op empty_vlist(tab);
1237 5e11c00c 2021-03-02 op TAILQ_FOREACH(l, &tab->page.head, lines) {
1238 0d568960 2021-03-11 op prfx = line_prefixes[l->type].prfx1;
1239 5e11c00c 2021-03-02 op switch (l->type) {
1240 5e11c00c 2021-03-02 op case LINE_TEXT:
1241 5e11c00c 2021-03-02 op case LINE_LINK:
1242 5e11c00c 2021-03-02 op case LINE_TITLE_1:
1243 5e11c00c 2021-03-02 op case LINE_TITLE_2:
1244 5e11c00c 2021-03-02 op case LINE_TITLE_3:
1245 5e11c00c 2021-03-02 op case LINE_ITEM:
1246 5e11c00c 2021-03-02 op case LINE_QUOTE:
1247 0d568960 2021-03-11 op wrap_text(tab, prfx, l);
1249 5e11c00c 2021-03-02 op case LINE_PRE_START:
1250 5e11c00c 2021-03-02 op case LINE_PRE_END:
1251 768db5bb 2021-03-12 op push_line(tab, l, NULL, 0, 0);
1253 5e11c00c 2021-03-02 op case LINE_PRE_CONTENT:
1254 1d08c280 2021-03-06 op hardwrap_text(tab, l);
1261 1d08c280 2021-03-06 op static inline void
1262 1d08c280 2021-03-06 op print_line(struct line *l)
1264 bd9637e9 2021-03-06 op const char *text = l->line;
1265 768db5bb 2021-03-12 op const char *prfx;
1266 d3d56d8a 2021-03-11 op int face = line_faces[l->type].prop;
1268 768db5bb 2021-03-12 op if (!l->flags)
1269 768db5bb 2021-03-12 op prfx = line_prefixes[l->type].prfx1;
1271 768db5bb 2021-03-12 op prfx = line_prefixes[l->type].prfx2;
1273 bd9637e9 2021-03-06 op if (text == NULL)
1276 d3d56d8a 2021-03-11 op if (face != 0)
1277 d3d56d8a 2021-03-11 op wattron(body, face);
1278 d3d56d8a 2021-03-11 op wprintw(body, "%s%s", prfx, text);
1279 d3d56d8a 2021-03-11 op if (face != 0)
1280 d3d56d8a 2021-03-11 op wattroff(body, face);
1284 8af5e5ed 2021-03-08 op redraw_tabline(void)
1286 7c7d7bb7 2021-03-10 op struct tab *tab;
1287 7c7d7bb7 2021-03-10 op int current;
1289 156f1501 2021-03-13 op werase(tabline);
1290 8af5e5ed 2021-03-08 op wbkgd(tabline, A_REVERSE);
1292 7c7d7bb7 2021-03-10 op wprintw(tabline, " ");
1293 7c7d7bb7 2021-03-10 op TAILQ_FOREACH(tab, &tabshead, tabs) {
1294 7c7d7bb7 2021-03-10 op current = tab->flags & TAB_CURRENT;
1296 a329982b 2021-03-11 op if (current)
1297 a329982b 2021-03-11 op wattron(tabline, A_UNDERLINE);
1299 a329982b 2021-03-11 op wprintw(tabline, "%s%d:todo title ",
1300 a329982b 2021-03-11 op current ? "*" : " ", tab->id);
1302 a329982b 2021-03-11 op if (current)
1303 a329982b 2021-03-11 op wattroff(tabline, A_UNDERLINE);
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 fc43eadd 2021-03-12 op wprintw(modeline, "-%c %s-mode ",
1320 481340cc 2021-03-11 op spin[tab->s->loading_anim_step], mode);
1322 481340cc 2021-03-11 op pct = (tab->s->line_off + tab->s->curs_y) * 100.0 / tab->s->line_max;
1324 481340cc 2021-03-11 op if (tab->s->line_max <= body_lines)
1325 481340cc 2021-03-11 op wprintw(modeline, "All ");
1326 481340cc 2021-03-11 op else if (tab->s->line_off == 0)
1327 481340cc 2021-03-11 op wprintw(modeline, "Top ");
1328 481340cc 2021-03-11 op else if (tab->s->line_off + body_lines >= tab->s->line_max)
1329 481340cc 2021-03-11 op wprintw(modeline, "Bottom ");
1331 481340cc 2021-03-11 op wprintw(modeline, "%.0f%% ", pct);
1333 481340cc 2021-03-11 op wprintw(modeline, "%d/%d %s ",
1334 481340cc 2021-03-11 op tab->s->line_off + tab->s->curs_y,
1335 481340cc 2021-03-11 op tab->s->line_max,
1336 481340cc 2021-03-11 op tab->urlstr);
1338 48e9d457 2021-03-06 op getyx(modeline, y, x);
1339 48e9d457 2021-03-06 op getmaxyx(modeline, max_y, max_x);
1342 48e9d457 2021-03-06 op (void)max_y;
1344 48e9d457 2021-03-06 op for (; x < max_x; ++x)
1345 48e9d457 2021-03-06 op waddstr(modeline, "-");
1349 9ca15951 2021-03-09 op redraw_minibuffer(void)
1351 22268e11 2021-03-11 op size_t skip = 0, off_x = 0, off_y = 0;
1353 156f1501 2021-03-13 op werase(minibuf);
1354 22268e11 2021-03-11 op if (in_minibuffer) {
1355 22268e11 2021-03-11 op mvwprintw(minibuf, 0, 0, "%s", ministate.prompt);
1356 22268e11 2021-03-11 op if (ministate.hist_cur != NULL)
1357 22268e11 2021-03-11 op wprintw(minibuf, "(%zu/%zu) ",
1358 22268e11 2021-03-11 op ministate.hist_off + 1,
1359 22268e11 2021-03-11 op ministate.history->len);
1361 22268e11 2021-03-11 op getyx(minibuf, off_y, off_x);
1363 22268e11 2021-03-11 op while (ministate.off - skip > COLS / 2) {
1364 22268e11 2021-03-11 op skip += MIN(ministate.off/4, 1);
1367 22268e11 2021-03-11 op if (ministate.hist_cur != NULL)
1368 22268e11 2021-03-11 op wprintw(minibuf, "%s", ministate.hist_cur->h + skip);
1370 22268e11 2021-03-11 op wprintw(minibuf, "%s", ministate.buf + skip);
1373 9cb0f9ce 2021-03-10 op if (ministate.curmesg != NULL) {
1374 9cb0f9ce 2021-03-10 op if (in_minibuffer)
1375 9cb0f9ce 2021-03-10 op wprintw(minibuf, " [%s]", ministate.curmesg);
1377 9cb0f9ce 2021-03-10 op wprintw(minibuf, "%s", ministate.curmesg);
1380 91a72220 2021-03-13 op if (!in_minibuffer && ministate.curmesg == NULL)
1381 91a72220 2021-03-13 op wprintw(minibuf, "%s", keybuf);
1383 2aaf475e 2021-03-13 op if (in_minibuffer)
1384 2aaf475e 2021-03-13 op wmove(minibuf, 0, off_x + ministate.off - skip);
1388 48e9d457 2021-03-06 op redraw_tab(struct tab *tab)
1390 e19f9a04 2021-03-11 op redraw_tabline();
1391 e19f9a04 2021-03-11 op redraw_body(tab);
1392 e19f9a04 2021-03-11 op redraw_modeline(tab);
1393 e19f9a04 2021-03-11 op redraw_minibuffer();
1395 e19f9a04 2021-03-11 op restore_cursor(tab);
1396 e19f9a04 2021-03-11 op wrefresh(tabline);
1397 e19f9a04 2021-03-11 op wrefresh(modeline);
1399 e19f9a04 2021-03-11 op if (in_minibuffer) {
1400 e19f9a04 2021-03-11 op wrefresh(body);
1401 e19f9a04 2021-03-11 op wrefresh(minibuf);
1403 e19f9a04 2021-03-11 op wrefresh(minibuf);
1404 e19f9a04 2021-03-11 op wrefresh(body);
1409 e19f9a04 2021-03-11 op redraw_body(struct tab *tab)
1411 48e9d457 2021-03-06 op struct line *l;
1414 48e9d457 2021-03-06 op werase(body);
1416 48e9d457 2021-03-06 op tab->s->line_off = MIN(tab->s->line_max, tab->s->line_off);
1417 48e9d457 2021-03-06 op if (TAILQ_EMPTY(&tab->s->head))
1421 48e9d457 2021-03-06 op l = nth_line(tab, tab->s->line_off);
1422 48e9d457 2021-03-06 op for (; l != NULL; l = TAILQ_NEXT(l, lines)) {
1423 48e9d457 2021-03-06 op wmove(body, line, 0);
1424 1d08c280 2021-03-06 op print_line(l);
1426 48e9d457 2021-03-06 op if (line == body_lines)
1432 7953dd72 2021-03-07 op message(const char *fmt, ...)
1436 7953dd72 2021-03-07 op if (clminibufev_set)
1437 7953dd72 2021-03-07 op evtimer_del(&clminibufev);
1438 7953dd72 2021-03-07 op evtimer_set(&clminibufev, handle_clear_minibuf, NULL);
1439 7953dd72 2021-03-07 op evtimer_add(&clminibufev, &clminibufev_timer);
1440 7953dd72 2021-03-07 op clminibufev_set = 1;
1442 bf992581 2021-03-12 op free(ministate.curmesg);
1444 9cb0f9ce 2021-03-10 op va_start(ap, fmt);
1445 9cb0f9ce 2021-03-10 op /* TODO: what to do if the allocation fails here? */
1446 9cb0f9ce 2021-03-10 op if (vasprintf(&ministate.curmesg, fmt, ap) == -1)
1447 9cb0f9ce 2021-03-10 op ministate.curmesg = NULL;
1450 9cb0f9ce 2021-03-10 op redraw_minibuffer();
1452 9cb0f9ce 2021-03-10 op if (in_minibuffer) {
1453 9cb0f9ce 2021-03-10 op wrefresh(body);
1454 9cb0f9ce 2021-03-10 op wrefresh(minibuf);
1456 9cb0f9ce 2021-03-10 op wrefresh(minibuf);
1457 9cb0f9ce 2021-03-10 op wrefresh(body);
1462 8af5e5ed 2021-03-08 op start_loading_anim(struct tab *tab)
1464 8af5e5ed 2021-03-08 op if (tab->s->loading_anim)
1466 8af5e5ed 2021-03-08 op tab->s->loading_anim = 1;
1467 8af5e5ed 2021-03-08 op evtimer_set(&tab->s->loadingev, update_loading_anim, tab);
1468 8af5e5ed 2021-03-08 op evtimer_add(&tab->s->loadingev, &loadingev_timer);
1472 8af5e5ed 2021-03-08 op update_loading_anim(int fd, short ev, void *d)
1474 8af5e5ed 2021-03-08 op struct tab *tab = d;
1476 8af5e5ed 2021-03-08 op tab->s->loading_anim_step = (tab->s->loading_anim_step+1)%4;
1478 8af5e5ed 2021-03-08 op redraw_modeline(tab);
1479 8af5e5ed 2021-03-08 op wrefresh(modeline);
1481 8af5e5ed 2021-03-08 op wrefresh(body);
1482 9ca15951 2021-03-09 op if (in_minibuffer)
1483 9ca15951 2021-03-09 op wrefresh(minibuf);
1485 8af5e5ed 2021-03-08 op evtimer_add(&tab->s->loadingev, &loadingev_timer);
1489 8af5e5ed 2021-03-08 op stop_loading_anim(struct tab *tab)
1491 8af5e5ed 2021-03-08 op if (!tab->s->loading_anim)
1493 8af5e5ed 2021-03-08 op evtimer_del(&tab->s->loadingev);
1494 8af5e5ed 2021-03-08 op tab->s->loading_anim = 0;
1495 8af5e5ed 2021-03-08 op tab->s->loading_anim_step = 0;
1497 43a1b8d0 2021-03-09 op redraw_modeline(tab);
1499 43a1b8d0 2021-03-09 op wrefresh(modeline);
1500 43a1b8d0 2021-03-09 op wrefresh(body);
1501 9ca15951 2021-03-09 op if (in_minibuffer)
1502 9ca15951 2021-03-09 op wrefresh(minibuf);
1506 43a1b8d0 2021-03-09 op load_url_in_tab(struct tab *tab, const char *url)
1508 43a1b8d0 2021-03-09 op empty_vlist(tab);
1509 8af5e5ed 2021-03-08 op message("Loading %s...", url);
1510 8af5e5ed 2021-03-08 op start_loading_anim(tab);
1511 8af5e5ed 2021-03-08 op load_url(tab, url);
1513 43a1b8d0 2021-03-09 op tab->s->curs_x = 0;
1514 43a1b8d0 2021-03-09 op tab->s->curs_y = 0;
1515 43a1b8d0 2021-03-09 op redraw_tab(tab);
1519 b360ebb3 2021-03-10 op enter_minibuffer(void (*self_insert_fn)(void), void (*donefn)(void),
1520 22268e11 2021-03-11 op void (*abortfn)(void), struct minibuf_histhead *hist)
1522 9ca15951 2021-03-09 op in_minibuffer = 1;
1523 fa3fd864 2021-03-10 op base_map = &minibuffer_map;
1524 fa3fd864 2021-03-10 op current_map = &minibuffer_map;
1526 fa3fd864 2021-03-10 op base_map->unhandled_input = self_insert_fn;
1528 b360ebb3 2021-03-10 op ministate.donefn = donefn;
1529 b360ebb3 2021-03-10 op ministate.abortfn = abortfn;
1530 9ca15951 2021-03-09 op memset(ministate.buf, 0, sizeof(ministate.buf));
1531 9ca15951 2021-03-09 op ministate.off = 0;
1532 bb4e4ddf 2021-03-12 op ministate.len = 0;
1533 9ca15951 2021-03-09 op strlcpy(ministate.buf, "", sizeof(ministate.prompt));
1535 22268e11 2021-03-11 op ministate.history = hist;
1536 22268e11 2021-03-11 op ministate.hist_cur = NULL;
1537 22268e11 2021-03-11 op ministate.hist_off = 0;
1541 b360ebb3 2021-03-10 op exit_minibuffer(void)
1543 156f1501 2021-03-13 op werase(minibuf);
1545 9ca15951 2021-03-09 op in_minibuffer = 0;
1546 9ca15951 2021-03-09 op base_map = &global_map;
1547 9ca15951 2021-03-09 op current_map = &global_map;
1551 5cd2ebb1 2021-03-11 op switch_to_tab(struct tab *tab)
1553 5cd2ebb1 2021-03-11 op struct tab *t;
1555 5cd2ebb1 2021-03-11 op TAILQ_FOREACH(t, &tabshead, tabs) {
1556 5cd2ebb1 2021-03-11 op t->flags &= ~TAB_CURRENT;
1559 5cd2ebb1 2021-03-11 op tab->flags |= TAB_CURRENT;
1562 b1df9b71 2021-03-12 op static struct tab *
1563 bcb0b073 2021-03-07 op new_tab(void)
1565 bcb0b073 2021-03-07 op struct tab *tab, *t;
1566 bcb0b073 2021-03-07 op const char *url = "about:new";
1568 bcb0b073 2021-03-07 op if ((tab = calloc(1, sizeof(*tab))) == NULL)
1571 bcb0b073 2021-03-07 op if ((tab->s = calloc(1, sizeof(*t->s))) == NULL)
1574 bcb0b073 2021-03-07 op TAILQ_INIT(&tab->s->head);
1576 bcb0b073 2021-03-07 op tab->id = tab_counter++;
1577 5cd2ebb1 2021-03-11 op switch_to_tab(tab);
1579 bcb0b073 2021-03-07 op if (TAILQ_EMPTY(&tabshead))
1580 bcb0b073 2021-03-07 op TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
1582 bcb0b073 2021-03-07 op TAILQ_INSERT_TAIL(&tabshead, tab, tabs);
1584 43a1b8d0 2021-03-09 op load_url_in_tab(tab, url);
1588 bcb0b073 2021-03-07 op event_loopbreak();
1589 b1df9b71 2021-03-12 op return NULL;
1593 5e11c00c 2021-03-02 op ui_init(void)
1595 5e11c00c 2021-03-02 op setlocale(LC_ALL, "");
1597 9ca15951 2021-03-09 op TAILQ_INIT(&global_map.m);
1598 9ca15951 2021-03-09 op global_map.unhandled_input = global_key_unbound;
1600 fa3fd864 2021-03-10 op TAILQ_INIT(&minibuffer_map.m);
1602 22268e11 2021-03-11 op TAILQ_INIT(&eecmd_history.head);
1603 22268e11 2021-03-11 op TAILQ_INIT(&ir_history.head);
1604 22268e11 2021-03-11 op TAILQ_INIT(&lu_history.head);
1606 9ca15951 2021-03-09 op base_map = &global_map;
1607 f832146f 2021-03-09 op current_map = &global_map;
1608 f832146f 2021-03-09 op load_default_keys();
1615 5e11c00c 2021-03-02 op intrflush(stdscr, FALSE);
1617 48e9d457 2021-03-06 op if ((tabline = newwin(1, COLS, 0, 0)) == NULL)
1619 48e9d457 2021-03-06 op if ((body = newwin(LINES - 3, COLS, 1, 0)) == NULL)
1621 48e9d457 2021-03-06 op if ((modeline = newwin(1, COLS, LINES-2, 0)) == NULL)
1623 48e9d457 2021-03-06 op if ((minibuf = newwin(1, COLS, LINES-1, 0)) == NULL)
1626 48e9d457 2021-03-06 op body_lines = LINES-3;
1627 48e9d457 2021-03-06 op body_cols = COLS;
1629 43a1b8d0 2021-03-09 op keypad(body, TRUE);
1630 48e9d457 2021-03-06 op scrollok(body, TRUE);
1632 5e11c00c 2021-03-02 op /* non-blocking input */
1633 48e9d457 2021-03-06 op wtimeout(body, 0);
1635 48e9d457 2021-03-06 op mvwprintw(body, 0, 0, "");
1637 5e11c00c 2021-03-02 op event_set(&stdioev, 0, EV_READ | EV_PERSIST, dispatch_stdio, NULL);
1638 5e11c00c 2021-03-02 op event_add(&stdioev, NULL);
1640 5e11c00c 2021-03-02 op signal_set(&winchev, SIGWINCH, handle_resize, NULL);
1641 5e11c00c 2021-03-02 op signal_add(&winchev, NULL);
1649 8af5e5ed 2021-03-08 op ui_on_tab_loaded(struct tab *tab)
1651 8af5e5ed 2021-03-08 op stop_loading_anim(tab);
1652 4d3785b1 2021-03-09 op message("Loaded %s", tab->urlstr);
1656 5e11c00c 2021-03-02 op ui_on_tab_refresh(struct tab *tab)
1658 5e11c00c 2021-03-02 op if (!(tab->flags & TAB_CURRENT))
1661 1d08c280 2021-03-06 op wrap_page(tab);
1662 5e11c00c 2021-03-02 op redraw_tab(tab);
1666 5cd2ebb1 2021-03-11 op ui_require_input(struct tab *tab, int hide)
1668 5cd2ebb1 2021-03-11 op /* TODO: hard-switching to another tab is ugly */
1669 5cd2ebb1 2021-03-11 op switch_to_tab(tab);
1671 22268e11 2021-03-11 op enter_minibuffer(ir_self_insert, ir_select, exit_minibuffer,
1672 22268e11 2021-03-11 op &ir_history);
1673 5cd2ebb1 2021-03-11 op strlcpy(ministate.prompt, "Input required: ",
1674 5cd2ebb1 2021-03-11 op sizeof(ministate.prompt));
1675 5cd2ebb1 2021-03-11 op redraw_tab(tab);
1679 5e11c00c 2021-03-02 op ui_end(void)