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 5e11c00c 2021-03-02 op static struct event stdioev, winchev;
75 f832146f 2021-03-09 op static void load_default_keys(void);
76 768db5bb 2021-03-12 op static int push_line(struct tab*, const struct line*, const char*, size_t, int);
77 1d08c280 2021-03-06 op static void empty_vlist(struct tab*);
78 48e9d457 2021-03-06 op static void restore_cursor(struct tab *);
80 46a9311e 2021-03-08 op static void cmd_previous_line(struct tab*);
81 46a9311e 2021-03-08 op static void cmd_next_line(struct tab*);
82 46a9311e 2021-03-08 op static void cmd_forward_char(struct tab*);
83 46a9311e 2021-03-08 op static void cmd_backward_char(struct tab*);
84 a329982b 2021-03-11 op static void cmd_move_beginning_of_line(struct tab*);
85 a329982b 2021-03-11 op static void cmd_move_end_of_line(struct tab*);
86 46a9311e 2021-03-08 op static void cmd_redraw(struct tab*);
87 ed44414d 2021-03-09 op static void cmd_scroll_line_down(struct tab*);
88 ed44414d 2021-03-09 op static void cmd_scroll_line_up(struct tab*);
89 46a9311e 2021-03-08 op static void cmd_scroll_up(struct tab*);
90 ed44414d 2021-03-09 op static void cmd_scroll_down(struct tab*);
91 e19f9a04 2021-03-11 op static void cmd_beginning_of_buffer(struct tab*);
92 e19f9a04 2021-03-11 op static void cmd_end_of_buffer(struct tab*);
93 46a9311e 2021-03-08 op static void cmd_kill_telescope(struct tab*);
94 46a9311e 2021-03-08 op static void cmd_push_button(struct tab*);
95 b1df9b71 2021-03-12 op static void cmd_push_button_new_tab(struct tab*);
96 2051e653 2021-03-13 op static void cmd_previous_page(struct tab*);
97 2051e653 2021-03-13 op static void cmd_next_page(struct tab*);
98 3b4f9e49 2021-03-11 op static void cmd_clear_minibuf(struct tab*);
99 9ca15951 2021-03-09 op static void cmd_execute_extended_command(struct tab*);
100 7c7d7bb7 2021-03-10 op static void cmd_tab_close(struct tab*);
101 7c7d7bb7 2021-03-10 op static void cmd_tab_new(struct tab*);
102 7c7d7bb7 2021-03-10 op static void cmd_tab_next(struct tab*);
103 7c7d7bb7 2021-03-10 op static void cmd_tab_previous(struct tab*);
104 5cd2ebb1 2021-03-11 op static void cmd_load_url(struct tab*);
105 5cd2ebb1 2021-03-11 op static void cmd_load_current_url(struct tab*);
107 9ca15951 2021-03-09 op static void global_key_unbound(void);
109 d67133bf 2021-03-12 op static void cmd_mini_delete_char(struct tab*);
110 d67133bf 2021-03-12 op static void cmd_mini_delete_backward_char(struct tab*);
111 9ca15951 2021-03-09 op static void cmd_mini_forward_char(struct tab*);
112 9ca15951 2021-03-09 op static void cmd_mini_backward_char(struct tab*);
113 9ca15951 2021-03-09 op static void cmd_mini_move_end_of_line(struct tab*);
114 9ca15951 2021-03-09 op static void cmd_mini_move_beginning_of_line(struct tab*);
115 fa3fd864 2021-03-10 op static void cmd_mini_kill_line(struct tab*);
116 22268e11 2021-03-11 op static void cmd_mini_abort(struct tab*);
117 22268e11 2021-03-11 op static void cmd_mini_complete_and_exit(struct tab*);
118 22268e11 2021-03-11 op static void cmd_mini_previous_history_element(struct tab*);
119 22268e11 2021-03-11 op static void cmd_mini_next_history_element(struct tab*);
121 22268e11 2021-03-11 op static void minibuffer_hist_save_entry(void);
122 22268e11 2021-03-11 op static void minibuffer_taint_hist(void);
123 5cd2ebb1 2021-03-11 op static void minibuffer_self_insert(void);
124 9ca15951 2021-03-09 op static void eecmd_self_insert(void);
125 b360ebb3 2021-03-10 op static void eecmd_select(void);
126 5cd2ebb1 2021-03-11 op static void ir_self_insert(void);
127 5cd2ebb1 2021-03-11 op static void ir_select(void);
128 5cd2ebb1 2021-03-11 op static void lu_self_insert(void);
129 5cd2ebb1 2021-03-11 op static void lu_select(void);
131 48e9d457 2021-03-06 op static struct line *nth_line(struct tab*, size_t);
132 5e11c00c 2021-03-02 op static struct tab *current_tab(void);
133 5e11c00c 2021-03-02 op static void dispatch_stdio(int, short, void*);
134 a6d450c1 2021-03-06 op static void handle_clear_minibuf(int, short, void*);
135 5e11c00c 2021-03-02 op static void handle_resize(int, short, void*);
136 eb259e66 2021-03-02 op static int word_bourdaries(const char*, const char*, const char**, const char**);
137 1d08c280 2021-03-06 op static void wrap_text(struct tab*, const char*, struct line*);
138 1d08c280 2021-03-06 op static int hardwrap_text(struct tab*, struct line*);
139 1d08c280 2021-03-06 op static int wrap_page(struct tab*);
140 48e9d457 2021-03-06 op static void print_line(struct line*);
141 8af5e5ed 2021-03-08 op static void redraw_tabline(void);
142 e19f9a04 2021-03-11 op static void redraw_body(struct tab*);
143 8af5e5ed 2021-03-08 op static void redraw_modeline(struct tab*);
144 9ca15951 2021-03-09 op static void redraw_minibuffer(void);
145 5e11c00c 2021-03-02 op static void redraw_tab(struct tab*);
146 7953dd72 2021-03-07 op static void message(const char*, ...) __attribute__((format(printf, 1, 2)));
147 8af5e5ed 2021-03-08 op static void start_loading_anim(struct tab*);
148 8af5e5ed 2021-03-08 op static void update_loading_anim(int, short, void*);
149 8af5e5ed 2021-03-08 op static void stop_loading_anim(struct tab*);
150 43a1b8d0 2021-03-09 op static void load_url_in_tab(struct tab*, const char*);
151 3148eeac 2021-03-13 op static void enter_minibuffer(void(*)(void), void(*)(void), void(*)(void), struct histhead*);
152 b360ebb3 2021-03-10 op static void exit_minibuffer(void);
153 5cd2ebb1 2021-03-11 op static void switch_to_tab(struct tab*);
154 b1df9b71 2021-03-12 op static struct tab *new_tab(void);
156 9ca15951 2021-03-09 op static struct { int meta, key; } thiskey;
158 48e9d457 2021-03-06 op static WINDOW *tabline, *body, *modeline, *minibuf;
159 48e9d457 2021-03-06 op static int body_lines, body_cols;
161 48e9d457 2021-03-06 op static struct event clminibufev;
162 48e9d457 2021-03-06 op static int clminibufev_set;
163 a6d450c1 2021-03-06 op static struct timeval clminibufev_timer = { 5, 0 };
164 8af5e5ed 2021-03-08 op static struct timeval loadingev_timer = { 0, 250000 };
166 bcb0b073 2021-03-07 op static uint32_t tab_counter;
168 1d08c280 2021-03-06 op struct ui_state {
171 48e9d457 2021-03-06 op size_t line_off;
172 48e9d457 2021-03-06 op size_t line_max;
174 8af5e5ed 2021-03-08 op short loading_anim;
175 8af5e5ed 2021-03-08 op short loading_anim_step;
176 8af5e5ed 2021-03-08 op struct event loadingev;
178 1d08c280 2021-03-06 op TAILQ_HEAD(, line) head;
181 7c7d7bb7 2021-03-10 op static char keybuf[64];
183 9ca15951 2021-03-09 op struct kmap global_map,
184 fa3fd864 2021-03-10 op minibuffer_map,
185 9ca15951 2021-03-09 op *current_map,
188 3148eeac 2021-03-13 op static struct histhead eecmd_history,
192 9ca15951 2021-03-09 op static int in_minibuffer;
194 9ca15951 2021-03-09 op static struct {
195 9cb0f9ce 2021-03-10 op char *curmesg;
197 040fbdf8 2021-03-10 op char buf[1025];
198 9ca15951 2021-03-09 op size_t off, len;
199 5cd2ebb1 2021-03-11 op char prompt[32];
200 b360ebb3 2021-03-10 op void (*donefn)(void);
201 b360ebb3 2021-03-10 op void (*abortfn)(void);
203 3148eeac 2021-03-13 op struct histhead *history;
204 3148eeac 2021-03-13 op struct hist *hist_cur;
205 22268e11 2021-03-11 op size_t hist_off;
208 f95d82dd 2021-03-11 op struct lineprefix {
209 f95d82dd 2021-03-11 op const char *prfx1;
210 f95d82dd 2021-03-11 op const char *prfx2;
211 f95d82dd 2021-03-11 op } line_prefixes[] = {
212 f95d82dd 2021-03-11 op [LINE_TEXT] = { "", "" },
213 f95d82dd 2021-03-11 op [LINE_LINK] = { "=> ", " " },
214 f95d82dd 2021-03-11 op [LINE_TITLE_1] = { "# ", " " },
215 f95d82dd 2021-03-11 op [LINE_TITLE_2] = { "## ", " " },
216 f95d82dd 2021-03-11 op [LINE_TITLE_3] = { "### ", " " },
217 f95d82dd 2021-03-11 op [LINE_ITEM] = { "* ", " " },
218 f95d82dd 2021-03-11 op [LINE_QUOTE] = { "> ", "> " },
219 f95d82dd 2021-03-11 op [LINE_PRE_START] = { "```", "```" },
220 f95d82dd 2021-03-11 op [LINE_PRE_CONTENT] = { "", "" },
221 f95d82dd 2021-03-11 op [LINE_PRE_END] = { "```", "```" },
224 d3d56d8a 2021-03-11 op struct line_face {
226 d3d56d8a 2021-03-11 op } line_faces[] = {
227 d3d56d8a 2021-03-11 op [LINE_TEXT] = { 0 },
228 d3d56d8a 2021-03-11 op [LINE_LINK] = { A_UNDERLINE },
229 d3d56d8a 2021-03-11 op [LINE_TITLE_1] = { A_BOLD },
230 d3d56d8a 2021-03-11 op [LINE_TITLE_2] = { A_BOLD },
231 d3d56d8a 2021-03-11 op [LINE_TITLE_3] = { A_BOLD },
232 d3d56d8a 2021-03-11 op [LINE_ITEM] = { 0 },
233 d3d56d8a 2021-03-11 op [LINE_QUOTE] = { A_DIM },
234 d3d56d8a 2021-03-11 op [LINE_PRE_START] = { 0 },
235 d3d56d8a 2021-03-11 op [LINE_PRE_CONTENT] = { 0 },
236 d3d56d8a 2021-03-11 op [LINE_PRE_END] = { 0 },
239 f832146f 2021-03-09 op static inline void
240 f832146f 2021-03-09 op global_set_key(const char *key, void (*fn)(struct tab*))
242 67c8ed7f 2021-03-13 op if (!kmap_define_key(&global_map, key, fn))
246 9ca15951 2021-03-09 op static inline void
247 fa3fd864 2021-03-10 op minibuffer_set_key(const char *key, void (*fn)(struct tab*))
249 67c8ed7f 2021-03-13 op if (!kmap_define_key(&minibuffer_map, key, fn))
254 f832146f 2021-03-09 op load_default_keys(void)
256 9ca15951 2021-03-09 op /* === global map === */
259 f832146f 2021-03-09 op global_set_key("C-p", cmd_previous_line);
260 f832146f 2021-03-09 op global_set_key("C-n", cmd_next_line);
261 f832146f 2021-03-09 op global_set_key("C-f", cmd_forward_char);
262 f832146f 2021-03-09 op global_set_key("C-b", cmd_backward_char);
263 a329982b 2021-03-11 op global_set_key("C-a", cmd_move_beginning_of_line);
264 a329982b 2021-03-11 op global_set_key("C-e", cmd_move_end_of_line);
266 f832146f 2021-03-09 op global_set_key("M-v", cmd_scroll_up);
267 f832146f 2021-03-09 op global_set_key("C-v", cmd_scroll_down);
268 929c2d9f 2021-03-13 op global_set_key("M-space", cmd_scroll_up);
269 929c2d9f 2021-03-13 op global_set_key("space", cmd_scroll_down);
271 f832146f 2021-03-09 op global_set_key("C-x C-c", cmd_kill_telescope);
273 3b4f9e49 2021-03-11 op global_set_key("C-g", cmd_clear_minibuf);
275 9ca15951 2021-03-09 op global_set_key("M-x", cmd_execute_extended_command);
276 5cd2ebb1 2021-03-11 op global_set_key("C-x C-f", cmd_load_url);
277 5cd2ebb1 2021-03-11 op global_set_key("C-x M-f", cmd_load_current_url);
279 7c7d7bb7 2021-03-10 op global_set_key("C-x t 0", cmd_tab_close);
280 7c7d7bb7 2021-03-10 op global_set_key("C-x t 2", cmd_tab_new);
281 7c7d7bb7 2021-03-10 op global_set_key("C-x t o", cmd_tab_next);
282 7c7d7bb7 2021-03-10 op global_set_key("C-x t O", cmd_tab_previous);
284 e19f9a04 2021-03-11 op global_set_key("M-<", cmd_beginning_of_buffer);
285 e19f9a04 2021-03-11 op global_set_key("M->", cmd_end_of_buffer);
287 2051e653 2021-03-13 op global_set_key("C-M-b", cmd_previous_page);
288 2051e653 2021-03-13 op global_set_key("C-M-f", cmd_next_page);
290 f832146f 2021-03-09 op /* vi/vi-like */
291 f832146f 2021-03-09 op global_set_key("k", cmd_previous_line);
292 f832146f 2021-03-09 op global_set_key("j", cmd_next_line);
293 f832146f 2021-03-09 op global_set_key("l", cmd_forward_char);
294 f832146f 2021-03-09 op global_set_key("h", cmd_backward_char);
295 a329982b 2021-03-11 op global_set_key("^", cmd_move_beginning_of_line);
296 a329982b 2021-03-11 op global_set_key("$", cmd_move_end_of_line);
298 ed44414d 2021-03-09 op global_set_key("K", cmd_scroll_line_up);
299 ed44414d 2021-03-09 op global_set_key("J", cmd_scroll_line_down);
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);
332 fa3fd864 2021-03-10 op /* === minibuffer map === */
333 b360ebb3 2021-03-10 op minibuffer_set_key("ret", cmd_mini_complete_and_exit);
334 b360ebb3 2021-03-10 op minibuffer_set_key("C-g", cmd_mini_abort);
335 b360ebb3 2021-03-10 op minibuffer_set_key("esc", cmd_mini_abort);
336 d67133bf 2021-03-12 op minibuffer_set_key("C-d", cmd_mini_delete_char);
337 d67133bf 2021-03-12 op minibuffer_set_key("del", cmd_mini_delete_backward_char);
339 fa3fd864 2021-03-10 op minibuffer_set_key("C-f", cmd_mini_forward_char);
340 fa3fd864 2021-03-10 op minibuffer_set_key("C-b", cmd_mini_backward_char);
341 5b2bf704 2021-03-12 op minibuffer_set_key("<right>", cmd_mini_forward_char);
342 5b2bf704 2021-03-12 op minibuffer_set_key("<left>", cmd_mini_backward_char);
343 fa3fd864 2021-03-10 op minibuffer_set_key("C-e", cmd_mini_move_end_of_line);
344 fa3fd864 2021-03-10 op minibuffer_set_key("C-a", cmd_mini_move_beginning_of_line);
345 fa3fd864 2021-03-10 op minibuffer_set_key("<end>", cmd_mini_move_end_of_line);
346 fa3fd864 2021-03-10 op minibuffer_set_key("<home>", cmd_mini_move_beginning_of_line);
347 fa3fd864 2021-03-10 op minibuffer_set_key("C-k", cmd_mini_kill_line);
349 22268e11 2021-03-11 op minibuffer_set_key("M-p", cmd_mini_previous_history_element);
350 22268e11 2021-03-11 op minibuffer_set_key("M-n", cmd_mini_next_history_element);
351 22268e11 2021-03-11 op minibuffer_set_key("<up>", cmd_mini_previous_history_element);
352 22268e11 2021-03-11 op minibuffer_set_key("<down>", cmd_mini_next_history_element);
356 768db5bb 2021-03-12 op push_line(struct tab *tab, const struct line *l, const char *buf, size_t len, int cont)
358 1d08c280 2021-03-06 op struct line *vl;
360 48e9d457 2021-03-06 op tab->s->line_max++;
362 1d08c280 2021-03-06 op if ((vl = calloc(1, sizeof(*vl))) == NULL)
365 1d08c280 2021-03-06 op if (len != 0 && (vl->line = calloc(1, len+1)) == NULL) {
370 1d08c280 2021-03-06 op vl->type = l->type;
371 1d08c280 2021-03-06 op if (len != 0)
372 1d08c280 2021-03-06 op memcpy(vl->line, buf, len);
373 1d08c280 2021-03-06 op vl->alt = l->alt;
374 768db5bb 2021-03-12 op vl->flags = cont;
376 1d08c280 2021-03-06 op if (TAILQ_EMPTY(&tab->s->head))
377 1d08c280 2021-03-06 op TAILQ_INSERT_HEAD(&tab->s->head, vl, lines);
379 1d08c280 2021-03-06 op TAILQ_INSERT_TAIL(&tab->s->head, vl, lines);
384 1d08c280 2021-03-06 op empty_vlist(struct tab *tab)
386 1d08c280 2021-03-06 op struct line *l, *t;
388 48e9d457 2021-03-06 op tab->s->line_max = 0;
390 1d08c280 2021-03-06 op TAILQ_FOREACH_SAFE(l, &tab->s->head, lines, t) {
391 1d08c280 2021-03-06 op TAILQ_REMOVE(&tab->s->head, l, lines);
392 1d08c280 2021-03-06 op free(l->line);
393 1d08c280 2021-03-06 op /* l->alt references the original line! */
399 48e9d457 2021-03-06 op restore_cursor(struct tab *tab)
401 48e9d457 2021-03-06 op wmove(body, tab->s->curs_y, tab->s->curs_x);
405 46a9311e 2021-03-08 op cmd_previous_line(struct tab *tab)
407 4dd664ce 2021-03-06 op if (--tab->s->curs_y < 0) {
408 4dd664ce 2021-03-06 op tab->s->curs_y = 0;
409 ed44414d 2021-03-09 op cmd_scroll_line_up(tab);
412 48e9d457 2021-03-06 op restore_cursor(tab);
416 46a9311e 2021-03-08 op cmd_next_line(struct tab *tab)
418 fed61466 2021-03-11 op if (tab->s->line_off + tab->s->curs_y >= tab->s->line_max)
421 4dd664ce 2021-03-06 op if (++tab->s->curs_y > body_lines-1) {
422 4dd664ce 2021-03-06 op tab->s->curs_y = body_lines-1;
423 ed44414d 2021-03-09 op cmd_scroll_line_down(tab);
426 48e9d457 2021-03-06 op restore_cursor(tab);
430 46a9311e 2021-03-08 op cmd_forward_char(struct tab *tab)
432 4dd664ce 2021-03-06 op tab->s->curs_x = MIN(body_cols-1, tab->s->curs_x+1);
433 48e9d457 2021-03-06 op restore_cursor(tab);
437 46a9311e 2021-03-08 op cmd_backward_char(struct tab *tab)
439 b2cd5e06 2021-03-06 op tab->s->curs_x = MAX(0, tab->s->curs_x-1);
440 a329982b 2021-03-11 op restore_cursor(tab);
444 a329982b 2021-03-11 op cmd_move_beginning_of_line(struct tab *tab)
446 a329982b 2021-03-11 op tab->s->curs_x = 0;
447 a329982b 2021-03-11 op restore_cursor(tab);
451 a329982b 2021-03-11 op cmd_move_end_of_line(struct tab *tab)
453 a329982b 2021-03-11 op struct line *line;
455 f95d82dd 2021-03-11 op const char *prfx;
457 a329982b 2021-03-11 op off = tab->s->line_off + tab->s->curs_y;
458 a329982b 2021-03-11 op if (off >= tab->s->line_max) {
459 a329982b 2021-03-11 op tab->s->curs_x = 0;
463 a329982b 2021-03-11 op line = nth_line(tab, off);
464 a329982b 2021-03-11 op if (line->line != NULL)
465 a329982b 2021-03-11 op tab->s->curs_x = strlen(line->line);
467 a329982b 2021-03-11 op tab->s->curs_x = 0;
469 f95d82dd 2021-03-11 op prfx = line_prefixes[line->type].prfx1;
470 f95d82dd 2021-03-11 op tab->s->curs_x += strlen(prfx);
473 48e9d457 2021-03-06 op restore_cursor(tab);
477 46a9311e 2021-03-08 op cmd_redraw(struct tab *tab)
479 b1738d2e 2021-03-06 op handle_resize(0, 0, NULL);
483 ed44414d 2021-03-09 op cmd_scroll_line_up(struct tab *tab)
485 48e9d457 2021-03-06 op struct line *l;
487 48e9d457 2021-03-06 op if (tab->s->line_off == 0)
490 48e9d457 2021-03-06 op l = nth_line(tab, --tab->s->line_off);
491 48e9d457 2021-03-06 op wscrl(body, -1);
492 48e9d457 2021-03-06 op wmove(body, 0, 0);
493 48e9d457 2021-03-06 op print_line(l);
497 ed44414d 2021-03-09 op cmd_scroll_line_down(struct tab *tab)
499 48e9d457 2021-03-06 op struct line *l;
502 48e9d457 2021-03-06 op if (tab->s->line_max == 0 || tab->s->line_off == tab->s->line_max-1)
505 48e9d457 2021-03-06 op tab->s->line_off++;
506 48e9d457 2021-03-06 op wscrl(body, 1);
508 48e9d457 2021-03-06 op if (tab->s->line_max - tab->s->line_off < body_lines)
511 48e9d457 2021-03-06 op l = nth_line(tab, tab->s->line_off + body_lines-1);
512 48e9d457 2021-03-06 op wmove(body, body_lines-1, 0);
513 48e9d457 2021-03-06 op print_line(l);
517 ed44414d 2021-03-09 op cmd_scroll_up(struct tab *tab)
521 ed44414d 2021-03-09 op off = body_lines+1;
523 ed44414d 2021-03-09 op for (; off > 0; --off)
524 ed44414d 2021-03-09 op cmd_scroll_line_up(tab);
528 ed44414d 2021-03-09 op cmd_scroll_down(struct tab *tab)
532 338eecdc 2021-03-12 op off = body_lines+1;
534 338eecdc 2021-03-12 op for (; off > 0; --off)
535 ed44414d 2021-03-09 op cmd_scroll_line_down(tab);
539 e19f9a04 2021-03-11 op cmd_beginning_of_buffer(struct tab *tab)
541 e19f9a04 2021-03-11 op tab->s->line_off = 0;
542 e19f9a04 2021-03-11 op tab->s->curs_y = 0;
543 e19f9a04 2021-03-11 op redraw_body(tab);
547 e19f9a04 2021-03-11 op cmd_end_of_buffer(struct tab *tab)
551 e19f9a04 2021-03-11 op off = tab->s->line_max - body_lines;
552 e19f9a04 2021-03-11 op off = MAX(0, off);
554 e19f9a04 2021-03-11 op tab->s->line_off = off;
555 e19f9a04 2021-03-11 op tab->s->curs_y = MIN(body_lines, tab->s->line_max);
557 e19f9a04 2021-03-11 op redraw_body(tab);
561 46a9311e 2021-03-08 op cmd_kill_telescope(struct tab *tab)
563 1d08c280 2021-03-06 op event_loopbreak();
567 46a9311e 2021-03-08 op cmd_push_button(struct tab *tab)
569 2a4ad912 2021-03-08 op struct line *l;
572 2a4ad912 2021-03-08 op nth = tab->s->line_off + tab->s->curs_y;
573 cb8d5d9b 2021-03-13 op if (nth >= tab->s->line_max)
575 2a4ad912 2021-03-08 op l = nth_line(tab, nth);
576 43a1b8d0 2021-03-09 op if (l->type != LINE_LINK)
579 43a1b8d0 2021-03-09 op load_url_in_tab(tab, l->alt);
583 b1df9b71 2021-03-12 op cmd_push_button_new_tab(struct tab *tab)
585 b1df9b71 2021-03-12 op struct tab *t;
586 b1df9b71 2021-03-12 op struct line *l;
589 b1df9b71 2021-03-12 op nth = tab->s->line_off + tab->s->curs_y;
590 b1df9b71 2021-03-12 op if (nth > tab->s->line_max)
592 b1df9b71 2021-03-12 op l = nth_line(tab, nth);
593 b1df9b71 2021-03-12 op if (l->type != LINE_LINK)
596 b1df9b71 2021-03-12 op t = new_tab();
597 b1df9b71 2021-03-12 op memcpy(&t->url, &tab->url, sizeof(tab->url));
598 b1df9b71 2021-03-12 op load_url_in_tab(t, l->alt);
602 2051e653 2021-03-13 op cmd_previous_page(struct tab *tab)
604 2051e653 2021-03-13 op if (!load_previous_page(tab))
605 2051e653 2021-03-13 op message("No previous page");
609 2051e653 2021-03-13 op cmd_next_page(struct tab *tab)
611 2051e653 2021-03-13 op if (!load_next_page(tab))
612 2051e653 2021-03-13 op message("No next page");
616 3b4f9e49 2021-03-11 op cmd_clear_minibuf(struct tab *tab)
618 3b4f9e49 2021-03-11 op handle_clear_minibuf(0, 0, NULL);
622 9ca15951 2021-03-09 op cmd_execute_extended_command(struct tab *tab)
626 22268e11 2021-03-11 op enter_minibuffer(eecmd_self_insert, eecmd_select, exit_minibuffer,
627 22268e11 2021-03-11 op &eecmd_history);
629 9ca15951 2021-03-09 op len = sizeof(ministate.prompt);
630 9ca15951 2021-03-09 op strlcpy(ministate.prompt, "", len);
632 9ca15951 2021-03-09 op if (thiskey.meta)
633 9ca15951 2021-03-09 op strlcat(ministate.prompt, "M-", len);
635 9ca15951 2021-03-09 op strlcat(ministate.prompt, keyname(thiskey.key), len);
636 9ca15951 2021-03-09 op strlcat(ministate.prompt, " ", len);
640 7c7d7bb7 2021-03-10 op cmd_tab_close(struct tab *tab)
642 7c7d7bb7 2021-03-10 op struct tab *t;
644 7c7d7bb7 2021-03-10 op if (TAILQ_PREV(tab, tabshead, tabs) == NULL &&
645 7c7d7bb7 2021-03-10 op TAILQ_NEXT(tab, tabs) == NULL) {
646 7c7d7bb7 2021-03-10 op message("Can't close the only tab.");
650 7c7d7bb7 2021-03-10 op stop_tab(tab);
652 7c7d7bb7 2021-03-10 op t = TAILQ_PREV(tab, tabshead, tabs);
653 7c7d7bb7 2021-03-10 op t->flags |= TAB_CURRENT;
655 7c7d7bb7 2021-03-10 op TAILQ_REMOVE(&tabshead, tab, tabs);
657 7c7d7bb7 2021-03-10 op free(tab->s);
662 7c7d7bb7 2021-03-10 op cmd_tab_new(struct tab *tab)
668 7c7d7bb7 2021-03-10 op cmd_tab_next(struct tab *tab)
670 7c7d7bb7 2021-03-10 op struct tab *t;
672 7c7d7bb7 2021-03-10 op tab->flags &= ~TAB_CURRENT;
674 7c7d7bb7 2021-03-10 op if ((t = TAILQ_NEXT(tab, tabs)) == NULL)
675 7c7d7bb7 2021-03-10 op t = TAILQ_FIRST(&tabshead);
676 7c7d7bb7 2021-03-10 op t->flags |= TAB_CURRENT;
680 7c7d7bb7 2021-03-10 op cmd_tab_previous(struct tab *tab)
682 7c7d7bb7 2021-03-10 op struct tab *t;
684 7c7d7bb7 2021-03-10 op tab->flags &= ~TAB_CURRENT;
686 7c7d7bb7 2021-03-10 op if ((t = TAILQ_PREV(tab, tabshead, tabs)) == NULL)
687 7c7d7bb7 2021-03-10 op t = TAILQ_LAST(&tabshead, tabshead);
688 7c7d7bb7 2021-03-10 op t->flags |= TAB_CURRENT;
692 5cd2ebb1 2021-03-11 op cmd_load_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));
700 5cd2ebb1 2021-03-11 op cmd_load_current_url(struct tab *tab)
702 22268e11 2021-03-11 op enter_minibuffer(lu_self_insert, lu_select, exit_minibuffer,
703 22268e11 2021-03-11 op &lu_history);
704 5cd2ebb1 2021-03-11 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
705 2051e653 2021-03-13 op strlcpy(ministate.buf, tab->hist_cur->h, sizeof(ministate.buf));
706 2051e653 2021-03-13 op ministate.off = strlen(tab->hist_cur->h);
707 5cd2ebb1 2021-03-11 op ministate.len = ministate.off;
711 7c7d7bb7 2021-03-10 op global_key_unbound(void)
713 7c7d7bb7 2021-03-10 op message("%s is undefined", keybuf);
717 d67133bf 2021-03-12 op cmd_mini_delete_char(struct tab *tab)
719 3eecee9e 2021-03-12 op minibuffer_taint_hist();
721 d67133bf 2021-03-12 op if (ministate.len == 0 || ministate.off == ministate.len)
724 d67133bf 2021-03-12 op memmove(&ministate.buf[ministate.off],
725 d67133bf 2021-03-12 op &ministate.buf[ministate.off+1],
726 d67133bf 2021-03-12 op ministate.len - ministate.off + 1);
727 d67133bf 2021-03-12 op ministate.len--;
731 d67133bf 2021-03-12 op cmd_mini_delete_backward_char(struct tab *tab)
733 3eecee9e 2021-03-12 op minibuffer_taint_hist();
735 9ca15951 2021-03-09 op if (ministate.len == 0 || ministate.off == 0)
738 9ca15951 2021-03-09 op memmove(&ministate.buf[ministate.off-1],
739 9ca15951 2021-03-09 op &ministate.buf[ministate.off],
740 9ca15951 2021-03-09 op ministate.len - ministate.off + 1);
741 9ca15951 2021-03-09 op ministate.off--;
742 9ca15951 2021-03-09 op ministate.len--;
746 9ca15951 2021-03-09 op cmd_mini_forward_char(struct tab *tab)
748 9ca15951 2021-03-09 op if (ministate.off == ministate.len)
750 9ca15951 2021-03-09 op ministate.off++;
754 9ca15951 2021-03-09 op cmd_mini_backward_char(struct tab *tab)
756 9ca15951 2021-03-09 op if (ministate.off == 0)
758 9ca15951 2021-03-09 op ministate.off--;
762 9ca15951 2021-03-09 op cmd_mini_move_end_of_line(struct tab *tab)
764 9ca15951 2021-03-09 op ministate.off = ministate.len;
768 9ca15951 2021-03-09 op cmd_mini_move_beginning_of_line(struct tab *tab)
770 9ca15951 2021-03-09 op ministate.off = 0;
774 fa3fd864 2021-03-10 op cmd_mini_kill_line(struct tab *tab)
776 3eecee9e 2021-03-12 op minibuffer_taint_hist();
778 fa3fd864 2021-03-10 op if (ministate.off == ministate.len)
780 fa3fd864 2021-03-10 op ministate.buf[ministate.off] = '\0';
781 fa3fd864 2021-03-10 op ministate.len -= ministate.off;
785 b360ebb3 2021-03-10 op cmd_mini_abort(struct tab *tab)
787 b360ebb3 2021-03-10 op ministate.abortfn();
791 b360ebb3 2021-03-10 op cmd_mini_complete_and_exit(struct tab *tab)
793 22268e11 2021-03-11 op minibuffer_taint_hist();
794 b360ebb3 2021-03-10 op ministate.donefn();
798 22268e11 2021-03-11 op cmd_mini_previous_history_element(struct tab *tab)
800 22268e11 2021-03-11 op if (ministate.history == NULL) {
801 22268e11 2021-03-11 op message("No history");
805 22268e11 2021-03-11 op if (ministate.hist_cur == NULL ||
806 22268e11 2021-03-11 op (ministate.hist_cur = TAILQ_PREV(ministate.hist_cur, mhisthead, entries)) == NULL) {
807 22268e11 2021-03-11 op ministate.hist_cur = TAILQ_LAST(&ministate.history->head, mhisthead);
808 22268e11 2021-03-11 op ministate.hist_off = ministate.history->len - 1;
809 22268e11 2021-03-11 op if (ministate.hist_cur == NULL)
810 22268e11 2021-03-11 op message("No prev item");
812 22268e11 2021-03-11 op ministate.hist_off--;
815 22268e11 2021-03-11 op if (ministate.hist_cur != NULL) {
816 22268e11 2021-03-11 op ministate.off = 0;
817 22268e11 2021-03-11 op ministate.len = strlen(ministate.hist_cur->h);
822 22268e11 2021-03-11 op cmd_mini_next_history_element(struct tab *tab)
824 22268e11 2021-03-11 op if (ministate.history == NULL) {
825 22268e11 2021-03-11 op message("No history");
829 22268e11 2021-03-11 op if (ministate.hist_cur == NULL ||
830 22268e11 2021-03-11 op (ministate.hist_cur = TAILQ_NEXT(ministate.hist_cur, entries)) == NULL) {
831 22268e11 2021-03-11 op ministate.hist_cur = TAILQ_FIRST(&ministate.history->head);
832 22268e11 2021-03-11 op ministate.hist_off = 0;
833 22268e11 2021-03-11 op if (ministate.hist_cur == NULL)
834 22268e11 2021-03-11 op message("No next item");
836 22268e11 2021-03-11 op ministate.hist_off++;
839 22268e11 2021-03-11 op if (ministate.hist_cur != NULL) {
840 22268e11 2021-03-11 op ministate.off = 0;
841 22268e11 2021-03-11 op ministate.len = strlen(ministate.hist_cur->h);
846 22268e11 2021-03-11 op minibuffer_hist_save_entry(void)
848 3148eeac 2021-03-13 op struct hist *hist;
850 22268e11 2021-03-11 op if (ministate.history == NULL)
853 22268e11 2021-03-11 op if ((hist = calloc(1, sizeof(*hist))) == NULL)
856 22268e11 2021-03-11 op strlcpy(hist->h, ministate.buf, sizeof(hist->h));
858 22268e11 2021-03-11 op if (TAILQ_EMPTY(&ministate.history->head))
859 22268e11 2021-03-11 op TAILQ_INSERT_HEAD(&ministate.history->head, hist, entries);
861 22268e11 2021-03-11 op TAILQ_INSERT_TAIL(&ministate.history->head, hist, entries);
862 22268e11 2021-03-11 op ministate.history->len++;
866 22268e11 2021-03-11 op * taint the minibuffer cache: if we're currently showing a history
867 22268e11 2021-03-11 op * element, copy that to the current buf and reset the "history
868 22268e11 2021-03-11 op * navigation" thing.
871 22268e11 2021-03-11 op minibuffer_taint_hist(void)
873 22268e11 2021-03-11 op if (ministate.hist_cur == NULL)
876 22268e11 2021-03-11 op strlcpy(ministate.buf, ministate.hist_cur->h, sizeof(ministate.buf));
877 22268e11 2021-03-11 op ministate.hist_cur = NULL;
881 5cd2ebb1 2021-03-11 op minibuffer_self_insert(void)
883 22268e11 2021-03-11 op minibuffer_taint_hist();
885 040fbdf8 2021-03-10 op if (ministate.len == sizeof(ministate.buf) -1)
888 9ca15951 2021-03-09 op /* TODO: utf8 handling! */
890 9ca15951 2021-03-09 op memmove(&ministate.buf[ministate.off+1],
891 9ca15951 2021-03-09 op &ministate.buf[ministate.off],
892 9ca15951 2021-03-09 op ministate.len - ministate.off + 1);
893 9ca15951 2021-03-09 op ministate.buf[ministate.off] = thiskey.key;
894 9ca15951 2021-03-09 op ministate.off++;
895 9ca15951 2021-03-09 op ministate.len++;
899 5cd2ebb1 2021-03-11 op eecmd_self_insert(void)
901 5cd2ebb1 2021-03-11 op if (thiskey.meta || isspace(thiskey.key) ||
902 5cd2ebb1 2021-03-11 op !isgraph(thiskey.key)) {
903 5cd2ebb1 2021-03-11 op global_key_unbound();
907 5cd2ebb1 2021-03-11 op minibuffer_self_insert();
911 b360ebb3 2021-03-10 op eecmd_select(void)
913 b360ebb3 2021-03-10 op exit_minibuffer();
914 22268e11 2021-03-11 op minibuffer_hist_save_entry();
915 b360ebb3 2021-03-10 op message("TODO: try to execute %s", ministate.buf);
919 5cd2ebb1 2021-03-11 op ir_self_insert(void)
921 5cd2ebb1 2021-03-11 op minibuffer_self_insert();
925 5cd2ebb1 2021-03-11 op ir_select(void)
927 5cd2ebb1 2021-03-11 op char buf[1025] = {0};
928 5cd2ebb1 2021-03-11 op struct url url;
929 5cd2ebb1 2021-03-11 op struct tab *tab;
931 5cd2ebb1 2021-03-11 op tab = current_tab();
933 5cd2ebb1 2021-03-11 op exit_minibuffer();
934 22268e11 2021-03-11 op minibuffer_hist_save_entry();
936 5cd2ebb1 2021-03-11 op /* a bit ugly but... */
937 5cd2ebb1 2021-03-11 op memcpy(&url, &tab->url, sizeof(tab->url));
938 5cd2ebb1 2021-03-11 op url_set_query(&url, ministate.buf);
939 5cd2ebb1 2021-03-11 op url_unparse(&url, buf, sizeof(buf));
940 5cd2ebb1 2021-03-11 op load_url_in_tab(tab, buf);
944 5cd2ebb1 2021-03-11 op lu_self_insert(void)
946 5cd2ebb1 2021-03-11 op if (thiskey.meta || isspace(thiskey.key) ||
947 5cd2ebb1 2021-03-11 op !isgraph(thiskey.key)) {
948 5cd2ebb1 2021-03-11 op global_key_unbound();
952 5cd2ebb1 2021-03-11 op minibuffer_self_insert();
956 5cd2ebb1 2021-03-11 op lu_select(void)
958 5cd2ebb1 2021-03-11 op exit_minibuffer();
959 22268e11 2021-03-11 op minibuffer_hist_save_entry();
960 5cd2ebb1 2021-03-11 op load_url_in_tab(current_tab(), ministate.buf);
963 48e9d457 2021-03-06 op static struct line *
964 48e9d457 2021-03-06 op nth_line(struct tab *tab, size_t n)
966 48e9d457 2021-03-06 op struct line *l;
970 48e9d457 2021-03-06 op TAILQ_FOREACH(l, &tab->s->head, lines) {
976 48e9d457 2021-03-06 op /* unreachable */
980 5e11c00c 2021-03-02 op static struct tab *
981 5e11c00c 2021-03-02 op current_tab(void)
983 5e11c00c 2021-03-02 op struct tab *t;
985 5e11c00c 2021-03-02 op TAILQ_FOREACH(t, &tabshead, tabs) {
986 5e11c00c 2021-03-02 op if (t->flags & TAB_CURRENT)
990 5e11c00c 2021-03-02 op /* unreachable */
995 5e11c00c 2021-03-02 op dispatch_stdio(int fd, short ev, void *d)
997 481340cc 2021-03-11 op struct tab *tab;
998 f832146f 2021-03-09 op struct keymap *k;
999 7c7d7bb7 2021-03-10 op const char *keyname;
1000 7c7d7bb7 2021-03-10 op char tmp[2] = {0};
1002 9ca15951 2021-03-09 op thiskey.key = wgetch(body);
1003 9ca15951 2021-03-09 op if (thiskey.key == ERR)
1005 9ca15951 2021-03-09 op if (thiskey.key == 27) {
1006 f832146f 2021-03-09 op /* TODO: make escape-time customizable */
1008 9ca15951 2021-03-09 op thiskey.meta = 1;
1009 9ca15951 2021-03-09 op thiskey.key = wgetch(body);
1010 c314a314 2021-03-11 op if (thiskey.key == ERR || thiskey.key == 27) {
1011 c314a314 2021-03-11 op thiskey.meta = 0;
1012 9ca15951 2021-03-09 op thiskey.key = 27;
1015 9ca15951 2021-03-09 op thiskey.meta = 0;
1017 7c7d7bb7 2021-03-10 op if (keybuf[0] != '\0')
1018 7c7d7bb7 2021-03-10 op strlcat(keybuf, " ", sizeof(keybuf));
1019 7c7d7bb7 2021-03-10 op if (thiskey.meta)
1020 7c7d7bb7 2021-03-10 op strlcat(keybuf, "M-", sizeof(keybuf));
1021 7c7d7bb7 2021-03-10 op if ((keyname = unkbd(thiskey.key)) != NULL)
1022 7c7d7bb7 2021-03-10 op strlcat(keybuf, keyname, sizeof(keybuf));
1024 7c7d7bb7 2021-03-10 op tmp[0] = thiskey.key;
1025 7c7d7bb7 2021-03-10 op strlcat(keybuf, tmp, sizeof(keybuf));
1028 9ca15951 2021-03-09 op TAILQ_FOREACH(k, ¤t_map->m, keymaps) {
1029 9ca15951 2021-03-09 op if (k->meta == thiskey.meta &&
1030 9ca15951 2021-03-09 op k->key == thiskey.key) {
1031 f832146f 2021-03-09 op if (k->fn == NULL)
1032 f832146f 2021-03-09 op current_map = &k->map;
1034 9ca15951 2021-03-09 op current_map = base_map;
1035 7c7d7bb7 2021-03-10 op strlcpy(keybuf, "", sizeof(keybuf));
1036 f832146f 2021-03-09 op k->fn(current_tab());
1042 7c7d7bb7 2021-03-10 op if (current_map->unhandled_input != NULL)
1043 7c7d7bb7 2021-03-10 op current_map->unhandled_input();
1045 7c7d7bb7 2021-03-10 op global_key_unbound();
1048 7c7d7bb7 2021-03-10 op strlcpy(keybuf, "", sizeof(keybuf));
1049 9ca15951 2021-03-09 op current_map = base_map;
1052 179f0f58 2021-03-11 op redraw_tab(current_tab());
1056 a6d450c1 2021-03-06 op handle_clear_minibuf(int fd, short ev, void *d)
1058 a6d450c1 2021-03-06 op clminibufev_set = 0;
1060 9cb0f9ce 2021-03-10 op free(ministate.curmesg);
1061 9cb0f9ce 2021-03-10 op ministate.curmesg = NULL;
1063 9cb0f9ce 2021-03-10 op redraw_minibuffer();
1064 9cb0f9ce 2021-03-10 op if (in_minibuffer) {
1065 9cb0f9ce 2021-03-10 op wrefresh(body);
1066 9cb0f9ce 2021-03-10 op wrefresh(minibuf);
1068 9cb0f9ce 2021-03-10 op wrefresh(minibuf);
1069 9cb0f9ce 2021-03-10 op wrefresh(body);
1074 5e11c00c 2021-03-02 op handle_resize(int sig, short ev, void *d)
1076 1d08c280 2021-03-06 op struct tab *tab;
1082 48e9d457 2021-03-06 op /* move and resize the windows, in reverse order! */
1084 b1738d2e 2021-03-06 op mvwin(minibuf, LINES-1, 0);
1085 48e9d457 2021-03-06 op wresize(minibuf, 1, COLS);
1087 48e9d457 2021-03-06 op mvwin(modeline, LINES-2, 0);
1088 48e9d457 2021-03-06 op wresize(modeline, 1, COLS);
1090 48e9d457 2021-03-06 op wresize(body, LINES-3, COLS);
1091 48e9d457 2021-03-06 op body_lines = LINES-3;
1092 bd9637e9 2021-03-06 op body_cols = COLS;
1094 48e9d457 2021-03-06 op wresize(tabline, 1, COLS);
1096 1d08c280 2021-03-06 op tab = current_tab();
1098 1d08c280 2021-03-06 op wrap_page(tab);
1099 1d08c280 2021-03-06 op redraw_tab(tab);
1103 eb259e66 2021-03-02 op * Helper function for wrap_text. Find the end of the current word
1104 eb259e66 2021-03-02 op * and the end of the separator after the word.
1107 eb259e66 2021-03-02 op word_boundaries(const char *s, const char *sep, const char **endword, const char **endspc)
1109 eb259e66 2021-03-02 op *endword = s;
1110 eb259e66 2021-03-02 op *endword = s;
1112 eb259e66 2021-03-02 op if (*s == '\0')
1115 eb259e66 2021-03-02 op /* find the end of the current world */
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 *endword = s;
1123 eb259e66 2021-03-02 op /* find the end of the separator */
1124 eb259e66 2021-03-02 op for (; *s != '\0'; ++s) {
1125 eb259e66 2021-03-02 op if (strchr(sep, *s) == NULL)
1129 eb259e66 2021-03-02 op *endspc = s;
1134 1d08c280 2021-03-06 op static inline int
1135 1d08c280 2021-03-06 op emitline(struct tab *tab, size_t zero, size_t *off, const struct line *l,
1136 768db5bb 2021-03-12 op const char **line, int *cont)
1138 768db5bb 2021-03-12 op if (!push_line(tab, l, *line, *off - zero, *cont))
1142 1d08c280 2021-03-06 op *line += *off - zero;
1143 eb259e66 2021-03-02 op *off = zero;
1147 eb259e66 2021-03-02 op static inline void
1148 eb259e66 2021-03-02 op emitstr(const char **s, size_t len, size_t *off)
1152 eb259e66 2021-03-02 op /* printw("%*s", ...) doesn't seem to respect the precision, so... */
1153 eb259e66 2021-03-02 op for (i = 0; i < len; ++i)
1154 eb259e66 2021-03-02 op addch((*s)[i]);
1155 eb259e66 2021-03-02 op *off += len;
1160 1d08c280 2021-03-06 op * Build a list of visual line by wrapping the given line, assuming
1161 1d08c280 2021-03-06 op * that when printed will have a leading prefix prfx.
1163 eb259e66 2021-03-02 op * TODO: it considers each byte one cell on the screen!
1166 1d08c280 2021-03-06 op wrap_text(struct tab *tab, const char *prfx, struct line *l)
1168 eb259e66 2021-03-02 op size_t zero, off, len, split;
1169 768db5bb 2021-03-12 op int cont = 0;
1170 1d08c280 2021-03-06 op const char *endword, *endspc, *line, *linestart;
1172 1d08c280 2021-03-06 op zero = strlen(prfx);
1174 1d08c280 2021-03-06 op line = l->line;
1175 1d08c280 2021-03-06 op linestart = l->line;
1177 1d08c280 2021-03-06 op while (word_boundaries(line, " \t-", &endword, &endspc)) {
1178 eb259e66 2021-03-02 op len = endword - line;
1179 48e9d457 2021-03-06 op if (off + len >= body_cols) {
1180 768db5bb 2021-03-12 op emitline(tab, zero, &off, l, &linestart, &cont);
1181 48e9d457 2021-03-06 op while (len >= body_cols) {
1182 eb259e66 2021-03-02 op /* hard wrap */
1183 768db5bb 2021-03-12 op emitline(tab, zero, &off, l, &linestart, &cont);
1184 48e9d457 2021-03-06 op len -= body_cols-1;
1185 48e9d457 2021-03-06 op line += body_cols-1;
1188 eb259e66 2021-03-02 op if (len != 0)
1193 eb259e66 2021-03-02 op /* print the spaces iff not at bol */
1194 eb259e66 2021-03-02 op len = endspc - endword;
1195 eb259e66 2021-03-02 op /* line = endspc; */
1196 eb259e66 2021-03-02 op if (off != zero) {
1197 48e9d457 2021-03-06 op if (off + len >= body_cols) {
1198 768db5bb 2021-03-12 op emitline(tab, zero, &off, l, &linestart, &cont);
1199 1d08c280 2021-03-06 op linestart = endspc;
1204 eb259e66 2021-03-02 op line = endspc;
1207 768db5bb 2021-03-12 op emitline(tab, zero, &off, l, &linestart, &cont);
1211 1d08c280 2021-03-06 op hardwrap_text(struct tab *tab, struct line *l)
1213 1d08c280 2021-03-06 op size_t off, len;
1215 1d08c280 2021-03-06 op const char *linestart;
1217 c49d61bc 2021-03-12 op if (l->line == NULL)
1218 768db5bb 2021-03-12 op return emitline(tab, 0, &off, l, &linestart, &cont);
1220 1d08c280 2021-03-06 op len = strlen(l->line);
1222 1d08c280 2021-03-06 op linestart = l->line;
1224 1d08c280 2021-03-06 op while (len >= COLS) {
1225 1d08c280 2021-03-06 op len -= COLS-1;
1226 1d08c280 2021-03-06 op off = COLS-1;
1227 768db5bb 2021-03-12 op if (!emitline(tab, 0, &off, l, &linestart, &cont))
1231 ede1f142 2021-03-07 op if (len != 0)
1232 768db5bb 2021-03-12 op return emitline(tab, 0, &len, l, &linestart, &cont);
1238 1d08c280 2021-03-06 op wrap_page(struct tab *tab)
1240 1d08c280 2021-03-06 op struct line *l;
1241 0d568960 2021-03-11 op const char *prfx;
1243 1d08c280 2021-03-06 op empty_vlist(tab);
1245 5e11c00c 2021-03-02 op TAILQ_FOREACH(l, &tab->page.head, lines) {
1246 0d568960 2021-03-11 op prfx = line_prefixes[l->type].prfx1;
1247 5e11c00c 2021-03-02 op switch (l->type) {
1248 5e11c00c 2021-03-02 op case LINE_TEXT:
1249 5e11c00c 2021-03-02 op case LINE_LINK:
1250 5e11c00c 2021-03-02 op case LINE_TITLE_1:
1251 5e11c00c 2021-03-02 op case LINE_TITLE_2:
1252 5e11c00c 2021-03-02 op case LINE_TITLE_3:
1253 5e11c00c 2021-03-02 op case LINE_ITEM:
1254 5e11c00c 2021-03-02 op case LINE_QUOTE:
1255 0d568960 2021-03-11 op wrap_text(tab, prfx, l);
1257 5e11c00c 2021-03-02 op case LINE_PRE_START:
1258 5e11c00c 2021-03-02 op case LINE_PRE_END:
1259 768db5bb 2021-03-12 op push_line(tab, l, NULL, 0, 0);
1261 5e11c00c 2021-03-02 op case LINE_PRE_CONTENT:
1262 1d08c280 2021-03-06 op hardwrap_text(tab, l);
1269 1d08c280 2021-03-06 op static inline void
1270 1d08c280 2021-03-06 op print_line(struct line *l)
1272 bd9637e9 2021-03-06 op const char *text = l->line;
1273 768db5bb 2021-03-12 op const char *prfx;
1274 d3d56d8a 2021-03-11 op int face = line_faces[l->type].prop;
1276 768db5bb 2021-03-12 op if (!l->flags)
1277 768db5bb 2021-03-12 op prfx = line_prefixes[l->type].prfx1;
1279 768db5bb 2021-03-12 op prfx = line_prefixes[l->type].prfx2;
1281 bd9637e9 2021-03-06 op if (text == NULL)
1284 d3d56d8a 2021-03-11 op if (face != 0)
1285 d3d56d8a 2021-03-11 op wattron(body, face);
1286 d3d56d8a 2021-03-11 op wprintw(body, "%s%s", prfx, text);
1287 d3d56d8a 2021-03-11 op if (face != 0)
1288 d3d56d8a 2021-03-11 op wattroff(body, face);
1292 8af5e5ed 2021-03-08 op redraw_tabline(void)
1294 7c7d7bb7 2021-03-10 op struct tab *tab;
1295 7c7d7bb7 2021-03-10 op int current;
1296 dc5df781 2021-03-13 op const char *title;
1298 156f1501 2021-03-13 op werase(tabline);
1299 8af5e5ed 2021-03-08 op wbkgd(tabline, A_REVERSE);
1301 7c7d7bb7 2021-03-10 op wprintw(tabline, " ");
1302 7c7d7bb7 2021-03-10 op TAILQ_FOREACH(tab, &tabshead, tabs) {
1303 7c7d7bb7 2021-03-10 op current = tab->flags & TAB_CURRENT;
1305 dc5df781 2021-03-13 op if (*(title = tab->page.title) == '\0')
1306 2051e653 2021-03-13 op title = tab->hist_cur->h;
1308 a329982b 2021-03-11 op if (current)
1309 a329982b 2021-03-11 op wattron(tabline, A_UNDERLINE);
1311 dc5df781 2021-03-13 op wprintw(tabline, "%s%d: %s",
1312 dc5df781 2021-03-13 op current ? "*" : " ", tab->id, title);
1314 a329982b 2021-03-11 op if (current)
1315 a329982b 2021-03-11 op wattroff(tabline, A_UNDERLINE);
1320 48e9d457 2021-03-06 op redraw_modeline(struct tab *tab)
1323 48e9d457 2021-03-06 op int x, y, max_x, max_y;
1324 fc43eadd 2021-03-12 op const char *mode = tab->page.name;
1325 8af5e5ed 2021-03-08 op const char *spin = "-\\|/";
1327 156f1501 2021-03-13 op werase(modeline);
1328 48e9d457 2021-03-06 op wattron(modeline, A_REVERSE);
1329 48e9d457 2021-03-06 op wmove(modeline, 0, 0);
1331 fc43eadd 2021-03-12 op wprintw(modeline, "-%c %s-mode ",
1332 481340cc 2021-03-11 op spin[tab->s->loading_anim_step], mode);
1334 481340cc 2021-03-11 op pct = (tab->s->line_off + tab->s->curs_y) * 100.0 / tab->s->line_max;
1336 481340cc 2021-03-11 op if (tab->s->line_max <= body_lines)
1337 481340cc 2021-03-11 op wprintw(modeline, "All ");
1338 481340cc 2021-03-11 op else if (tab->s->line_off == 0)
1339 481340cc 2021-03-11 op wprintw(modeline, "Top ");
1340 481340cc 2021-03-11 op else if (tab->s->line_off + body_lines >= tab->s->line_max)
1341 481340cc 2021-03-11 op wprintw(modeline, "Bottom ");
1343 481340cc 2021-03-11 op wprintw(modeline, "%.0f%% ", pct);
1345 481340cc 2021-03-11 op wprintw(modeline, "%d/%d %s ",
1346 481340cc 2021-03-11 op tab->s->line_off + tab->s->curs_y,
1347 481340cc 2021-03-11 op tab->s->line_max,
1348 2051e653 2021-03-13 op tab->hist_cur->h);
1350 48e9d457 2021-03-06 op getyx(modeline, y, x);
1351 48e9d457 2021-03-06 op getmaxyx(modeline, max_y, max_x);
1354 48e9d457 2021-03-06 op (void)max_y;
1356 48e9d457 2021-03-06 op for (; x < max_x; ++x)
1357 48e9d457 2021-03-06 op waddstr(modeline, "-");
1361 9ca15951 2021-03-09 op redraw_minibuffer(void)
1363 22268e11 2021-03-11 op size_t skip = 0, off_x = 0, off_y = 0;
1365 156f1501 2021-03-13 op werase(minibuf);
1366 22268e11 2021-03-11 op if (in_minibuffer) {
1367 22268e11 2021-03-11 op mvwprintw(minibuf, 0, 0, "%s", ministate.prompt);
1368 22268e11 2021-03-11 op if (ministate.hist_cur != NULL)
1369 22268e11 2021-03-11 op wprintw(minibuf, "(%zu/%zu) ",
1370 22268e11 2021-03-11 op ministate.hist_off + 1,
1371 22268e11 2021-03-11 op ministate.history->len);
1373 22268e11 2021-03-11 op getyx(minibuf, off_y, off_x);
1375 22268e11 2021-03-11 op while (ministate.off - skip > COLS / 2) {
1376 22268e11 2021-03-11 op skip += MIN(ministate.off/4, 1);
1379 22268e11 2021-03-11 op if (ministate.hist_cur != NULL)
1380 22268e11 2021-03-11 op wprintw(minibuf, "%s", ministate.hist_cur->h + skip);
1382 22268e11 2021-03-11 op wprintw(minibuf, "%s", ministate.buf + skip);
1385 9cb0f9ce 2021-03-10 op if (ministate.curmesg != NULL) {
1386 9cb0f9ce 2021-03-10 op if (in_minibuffer)
1387 9cb0f9ce 2021-03-10 op wprintw(minibuf, " [%s]", ministate.curmesg);
1389 9cb0f9ce 2021-03-10 op wprintw(minibuf, "%s", ministate.curmesg);
1392 91a72220 2021-03-13 op if (!in_minibuffer && ministate.curmesg == NULL)
1393 91a72220 2021-03-13 op wprintw(minibuf, "%s", keybuf);
1395 2aaf475e 2021-03-13 op if (in_minibuffer)
1396 2aaf475e 2021-03-13 op wmove(minibuf, 0, off_x + ministate.off - skip);
1400 48e9d457 2021-03-06 op redraw_tab(struct tab *tab)
1402 e19f9a04 2021-03-11 op redraw_tabline();
1403 e19f9a04 2021-03-11 op redraw_body(tab);
1404 e19f9a04 2021-03-11 op redraw_modeline(tab);
1405 e19f9a04 2021-03-11 op redraw_minibuffer();
1407 e19f9a04 2021-03-11 op restore_cursor(tab);
1408 e19f9a04 2021-03-11 op wrefresh(tabline);
1409 e19f9a04 2021-03-11 op wrefresh(modeline);
1411 e19f9a04 2021-03-11 op if (in_minibuffer) {
1412 e19f9a04 2021-03-11 op wrefresh(body);
1413 e19f9a04 2021-03-11 op wrefresh(minibuf);
1415 e19f9a04 2021-03-11 op wrefresh(minibuf);
1416 e19f9a04 2021-03-11 op wrefresh(body);
1421 e19f9a04 2021-03-11 op redraw_body(struct tab *tab)
1423 48e9d457 2021-03-06 op struct line *l;
1426 48e9d457 2021-03-06 op werase(body);
1428 48e9d457 2021-03-06 op tab->s->line_off = MIN(tab->s->line_max, tab->s->line_off);
1429 48e9d457 2021-03-06 op if (TAILQ_EMPTY(&tab->s->head))
1433 48e9d457 2021-03-06 op l = nth_line(tab, tab->s->line_off);
1434 48e9d457 2021-03-06 op for (; l != NULL; l = TAILQ_NEXT(l, lines)) {
1435 48e9d457 2021-03-06 op wmove(body, line, 0);
1436 1d08c280 2021-03-06 op print_line(l);
1438 48e9d457 2021-03-06 op if (line == body_lines)
1444 7953dd72 2021-03-07 op message(const char *fmt, ...)
1448 7953dd72 2021-03-07 op if (clminibufev_set)
1449 7953dd72 2021-03-07 op evtimer_del(&clminibufev);
1450 7953dd72 2021-03-07 op evtimer_set(&clminibufev, handle_clear_minibuf, NULL);
1451 7953dd72 2021-03-07 op evtimer_add(&clminibufev, &clminibufev_timer);
1452 7953dd72 2021-03-07 op clminibufev_set = 1;
1454 bf992581 2021-03-12 op free(ministate.curmesg);
1456 9cb0f9ce 2021-03-10 op va_start(ap, fmt);
1457 9cb0f9ce 2021-03-10 op /* TODO: what to do if the allocation fails here? */
1458 9cb0f9ce 2021-03-10 op if (vasprintf(&ministate.curmesg, fmt, ap) == -1)
1459 9cb0f9ce 2021-03-10 op ministate.curmesg = NULL;
1462 9cb0f9ce 2021-03-10 op redraw_minibuffer();
1464 9cb0f9ce 2021-03-10 op if (in_minibuffer) {
1465 9cb0f9ce 2021-03-10 op wrefresh(body);
1466 9cb0f9ce 2021-03-10 op wrefresh(minibuf);
1468 9cb0f9ce 2021-03-10 op wrefresh(minibuf);
1469 9cb0f9ce 2021-03-10 op wrefresh(body);
1474 8af5e5ed 2021-03-08 op start_loading_anim(struct tab *tab)
1476 8af5e5ed 2021-03-08 op if (tab->s->loading_anim)
1478 8af5e5ed 2021-03-08 op tab->s->loading_anim = 1;
1479 8af5e5ed 2021-03-08 op evtimer_set(&tab->s->loadingev, update_loading_anim, tab);
1480 8af5e5ed 2021-03-08 op evtimer_add(&tab->s->loadingev, &loadingev_timer);
1484 8af5e5ed 2021-03-08 op update_loading_anim(int fd, short ev, void *d)
1486 8af5e5ed 2021-03-08 op struct tab *tab = d;
1488 8af5e5ed 2021-03-08 op tab->s->loading_anim_step = (tab->s->loading_anim_step+1)%4;
1490 8af5e5ed 2021-03-08 op redraw_modeline(tab);
1491 8af5e5ed 2021-03-08 op wrefresh(modeline);
1493 8af5e5ed 2021-03-08 op wrefresh(body);
1494 9ca15951 2021-03-09 op if (in_minibuffer)
1495 9ca15951 2021-03-09 op wrefresh(minibuf);
1497 8af5e5ed 2021-03-08 op evtimer_add(&tab->s->loadingev, &loadingev_timer);
1501 8af5e5ed 2021-03-08 op stop_loading_anim(struct tab *tab)
1503 8af5e5ed 2021-03-08 op if (!tab->s->loading_anim)
1505 8af5e5ed 2021-03-08 op evtimer_del(&tab->s->loadingev);
1506 8af5e5ed 2021-03-08 op tab->s->loading_anim = 0;
1507 8af5e5ed 2021-03-08 op tab->s->loading_anim_step = 0;
1509 43a1b8d0 2021-03-09 op redraw_modeline(tab);
1511 43a1b8d0 2021-03-09 op wrefresh(modeline);
1512 43a1b8d0 2021-03-09 op wrefresh(body);
1513 9ca15951 2021-03-09 op if (in_minibuffer)
1514 9ca15951 2021-03-09 op wrefresh(minibuf);
1518 43a1b8d0 2021-03-09 op load_url_in_tab(struct tab *tab, const char *url)
1520 43a1b8d0 2021-03-09 op empty_vlist(tab);
1521 8af5e5ed 2021-03-08 op message("Loading %s...", url);
1522 8af5e5ed 2021-03-08 op start_loading_anim(tab);
1523 8af5e5ed 2021-03-08 op load_url(tab, url);
1525 43a1b8d0 2021-03-09 op tab->s->curs_x = 0;
1526 43a1b8d0 2021-03-09 op tab->s->curs_y = 0;
1527 43a1b8d0 2021-03-09 op redraw_tab(tab);
1531 b360ebb3 2021-03-10 op enter_minibuffer(void (*self_insert_fn)(void), void (*donefn)(void),
1532 3148eeac 2021-03-13 op void (*abortfn)(void), struct histhead *hist)
1534 9ca15951 2021-03-09 op in_minibuffer = 1;
1535 fa3fd864 2021-03-10 op base_map = &minibuffer_map;
1536 fa3fd864 2021-03-10 op current_map = &minibuffer_map;
1538 fa3fd864 2021-03-10 op base_map->unhandled_input = self_insert_fn;
1540 b360ebb3 2021-03-10 op ministate.donefn = donefn;
1541 b360ebb3 2021-03-10 op ministate.abortfn = abortfn;
1542 9ca15951 2021-03-09 op memset(ministate.buf, 0, sizeof(ministate.buf));
1543 9ca15951 2021-03-09 op ministate.off = 0;
1544 bb4e4ddf 2021-03-12 op ministate.len = 0;
1545 9ca15951 2021-03-09 op strlcpy(ministate.buf, "", sizeof(ministate.prompt));
1547 22268e11 2021-03-11 op ministate.history = hist;
1548 22268e11 2021-03-11 op ministate.hist_cur = NULL;
1549 22268e11 2021-03-11 op ministate.hist_off = 0;
1553 b360ebb3 2021-03-10 op exit_minibuffer(void)
1555 156f1501 2021-03-13 op werase(minibuf);
1557 9ca15951 2021-03-09 op in_minibuffer = 0;
1558 9ca15951 2021-03-09 op base_map = &global_map;
1559 9ca15951 2021-03-09 op current_map = &global_map;
1563 5cd2ebb1 2021-03-11 op switch_to_tab(struct tab *tab)
1565 5cd2ebb1 2021-03-11 op struct tab *t;
1567 5cd2ebb1 2021-03-11 op TAILQ_FOREACH(t, &tabshead, tabs) {
1568 5cd2ebb1 2021-03-11 op t->flags &= ~TAB_CURRENT;
1571 5cd2ebb1 2021-03-11 op tab->flags |= TAB_CURRENT;
1574 b1df9b71 2021-03-12 op static struct tab *
1575 bcb0b073 2021-03-07 op new_tab(void)
1577 bcb0b073 2021-03-07 op struct tab *tab, *t;
1578 bcb0b073 2021-03-07 op const char *url = "about:new";
1580 bcb0b073 2021-03-07 op if ((tab = calloc(1, sizeof(*tab))) == NULL)
1583 2051e653 2021-03-13 op TAILQ_INIT(&tab->hist.head);
1585 bcb0b073 2021-03-07 op if ((tab->s = calloc(1, sizeof(*t->s))) == NULL)
1588 bcb0b073 2021-03-07 op TAILQ_INIT(&tab->s->head);
1590 bcb0b073 2021-03-07 op tab->id = tab_counter++;
1591 5cd2ebb1 2021-03-11 op switch_to_tab(tab);
1593 bcb0b073 2021-03-07 op if (TAILQ_EMPTY(&tabshead))
1594 bcb0b073 2021-03-07 op TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
1596 bcb0b073 2021-03-07 op TAILQ_INSERT_TAIL(&tabshead, tab, tabs);
1598 43a1b8d0 2021-03-09 op load_url_in_tab(tab, url);
1602 bcb0b073 2021-03-07 op event_loopbreak();
1603 b1df9b71 2021-03-12 op return NULL;
1607 5e11c00c 2021-03-02 op ui_init(void)
1609 5e11c00c 2021-03-02 op setlocale(LC_ALL, "");
1611 9ca15951 2021-03-09 op TAILQ_INIT(&global_map.m);
1612 9ca15951 2021-03-09 op global_map.unhandled_input = global_key_unbound;
1614 fa3fd864 2021-03-10 op TAILQ_INIT(&minibuffer_map.m);
1616 22268e11 2021-03-11 op TAILQ_INIT(&eecmd_history.head);
1617 22268e11 2021-03-11 op TAILQ_INIT(&ir_history.head);
1618 22268e11 2021-03-11 op TAILQ_INIT(&lu_history.head);
1620 9ca15951 2021-03-09 op base_map = &global_map;
1621 f832146f 2021-03-09 op current_map = &global_map;
1622 f832146f 2021-03-09 op load_default_keys();
1629 5e11c00c 2021-03-02 op intrflush(stdscr, FALSE);
1631 48e9d457 2021-03-06 op if ((tabline = newwin(1, COLS, 0, 0)) == NULL)
1633 48e9d457 2021-03-06 op if ((body = newwin(LINES - 3, COLS, 1, 0)) == NULL)
1635 48e9d457 2021-03-06 op if ((modeline = newwin(1, COLS, LINES-2, 0)) == NULL)
1637 48e9d457 2021-03-06 op if ((minibuf = newwin(1, COLS, LINES-1, 0)) == NULL)
1640 48e9d457 2021-03-06 op body_lines = LINES-3;
1641 48e9d457 2021-03-06 op body_cols = COLS;
1643 43a1b8d0 2021-03-09 op keypad(body, TRUE);
1644 48e9d457 2021-03-06 op scrollok(body, TRUE);
1646 5e11c00c 2021-03-02 op /* non-blocking input */
1647 48e9d457 2021-03-06 op wtimeout(body, 0);
1649 48e9d457 2021-03-06 op mvwprintw(body, 0, 0, "");
1651 5e11c00c 2021-03-02 op event_set(&stdioev, 0, EV_READ | EV_PERSIST, dispatch_stdio, NULL);
1652 5e11c00c 2021-03-02 op event_add(&stdioev, NULL);
1654 5e11c00c 2021-03-02 op signal_set(&winchev, SIGWINCH, handle_resize, NULL);
1655 5e11c00c 2021-03-02 op signal_add(&winchev, NULL);
1663 8af5e5ed 2021-03-08 op ui_on_tab_loaded(struct tab *tab)
1665 8af5e5ed 2021-03-08 op stop_loading_anim(tab);
1666 2051e653 2021-03-13 op message("Loaded %s", tab->hist_cur->h);
1670 5e11c00c 2021-03-02 op ui_on_tab_refresh(struct tab *tab)
1672 5e11c00c 2021-03-02 op if (!(tab->flags & TAB_CURRENT))
1675 1d08c280 2021-03-06 op wrap_page(tab);
1676 5e11c00c 2021-03-02 op redraw_tab(tab);
1680 5cd2ebb1 2021-03-11 op ui_require_input(struct tab *tab, int hide)
1682 5cd2ebb1 2021-03-11 op /* TODO: hard-switching to another tab is ugly */
1683 5cd2ebb1 2021-03-11 op switch_to_tab(tab);
1685 22268e11 2021-03-11 op enter_minibuffer(ir_self_insert, ir_select, exit_minibuffer,
1686 22268e11 2021-03-11 op &ir_history);
1687 5cd2ebb1 2021-03-11 op strlcpy(ministate.prompt, "Input required: ",
1688 5cd2ebb1 2021-03-11 op sizeof(ministate.prompt));
1689 5cd2ebb1 2021-03-11 op redraw_tab(tab);
1693 5e11c00c 2021-03-02 op ui_end(void)