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 int kbd(const char*);
82 f832146f 2021-03-09 op static void kmap_define_key(struct kmap*, const char*, void(*)(struct tab*));
83 f832146f 2021-03-09 op static void load_default_keys(void);
84 1d08c280 2021-03-06 op static int push_line(struct tab*, const struct line*, const char*, size_t);
85 1d08c280 2021-03-06 op static void empty_vlist(struct tab*);
86 48e9d457 2021-03-06 op static void restore_cursor(struct tab *);
88 46a9311e 2021-03-08 op static void cmd_previous_line(struct tab*);
89 46a9311e 2021-03-08 op static void cmd_next_line(struct tab*);
90 46a9311e 2021-03-08 op static void cmd_forward_char(struct tab*);
91 46a9311e 2021-03-08 op static void cmd_backward_char(struct tab*);
92 a329982b 2021-03-11 op static void cmd_move_beginning_of_line(struct tab*);
93 a329982b 2021-03-11 op static void cmd_move_end_of_line(struct tab*);
94 46a9311e 2021-03-08 op static void cmd_redraw(struct tab*);
95 ed44414d 2021-03-09 op static void cmd_scroll_line_down(struct tab*);
96 ed44414d 2021-03-09 op static void cmd_scroll_line_up(struct tab*);
97 46a9311e 2021-03-08 op static void cmd_scroll_up(struct tab*);
98 ed44414d 2021-03-09 op static void cmd_scroll_down(struct tab*);
99 e19f9a04 2021-03-11 op static void cmd_beginning_of_buffer(struct tab*);
100 e19f9a04 2021-03-11 op static void cmd_end_of_buffer(struct tab*);
101 46a9311e 2021-03-08 op static void cmd_kill_telescope(struct tab*);
102 46a9311e 2021-03-08 op static void cmd_push_button(struct tab*);
103 3b4f9e49 2021-03-11 op static void cmd_clear_minibuf(struct tab*);
104 9ca15951 2021-03-09 op static void cmd_execute_extended_command(struct tab*);
105 7c7d7bb7 2021-03-10 op static void cmd_tab_close(struct tab*);
106 7c7d7bb7 2021-03-10 op static void cmd_tab_new(struct tab*);
107 7c7d7bb7 2021-03-10 op static void cmd_tab_next(struct tab*);
108 7c7d7bb7 2021-03-10 op static void cmd_tab_previous(struct tab*);
109 5cd2ebb1 2021-03-11 op static void cmd_load_url(struct tab*);
110 5cd2ebb1 2021-03-11 op static void cmd_load_current_url(struct tab*);
112 9ca15951 2021-03-09 op static void global_key_unbound(void);
114 9ca15951 2021-03-09 op static void cmd_mini_del(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 bcb0b073 2021-03-07 op static void 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 f832146f 2021-03-09 op #define CTRL(n) ((n)&0x1F)
189 a777f81f 2021-03-10 op struct keytable {
192 a777f81f 2021-03-10 op } keytable[] = {
193 a777f81f 2021-03-10 op { "<up>", KEY_UP },
194 a777f81f 2021-03-10 op { "<down>", KEY_DOWN },
195 a777f81f 2021-03-10 op { "<left>", KEY_LEFT },
196 a777f81f 2021-03-10 op { "<right>", KEY_RIGHT },
197 a777f81f 2021-03-10 op { "<prior>", KEY_PPAGE },
198 a777f81f 2021-03-10 op { "<next>", KEY_NPAGE },
199 a777f81f 2021-03-10 op { "<home>", KEY_HOME },
200 a777f81f 2021-03-10 op { "<end>", KEY_END },
202 a777f81f 2021-03-10 op { "del", KEY_BACKSPACE },
203 a777f81f 2021-03-10 op { "esc", 27 },
204 a777f81f 2021-03-10 op { "space", ' ' },
205 a777f81f 2021-03-10 op { "spc", ' ' },
206 a777f81f 2021-03-10 op { "enter", CTRL('m') },
207 a777f81f 2021-03-10 op { "ret", CTRL('m' )},
208 a777f81f 2021-03-10 op { "tab", CTRL('i') },
213 9ca15951 2021-03-09 op struct kmap {
214 9ca15951 2021-03-09 op TAILQ_HEAD(map, keymap) m;
215 9ca15951 2021-03-09 op void (*unhandled_input)(void);
218 9ca15951 2021-03-09 op struct kmap global_map,
219 fa3fd864 2021-03-10 op minibuffer_map,
220 9ca15951 2021-03-09 op *current_map,
223 f832146f 2021-03-09 op struct keymap {
226 f832146f 2021-03-09 op struct kmap map;
227 f832146f 2021-03-09 op void (*fn)(struct tab*);
229 f832146f 2021-03-09 op TAILQ_ENTRY(keymap) keymaps;
232 22268e11 2021-03-11 op /* TODO: limit to a maximum number of entries */
233 22268e11 2021-03-11 op struct minibuf_histhead {
234 22268e11 2021-03-11 op TAILQ_HEAD(mhisthead, minibuf_hist) head;
237 22268e11 2021-03-11 op struct minibuf_hist {
238 22268e11 2021-03-11 op char h[1025];
239 22268e11 2021-03-11 op TAILQ_ENTRY(minibuf_hist) entries;
242 22268e11 2021-03-11 op static struct minibuf_histhead eecmd_history,
246 9ca15951 2021-03-09 op static int in_minibuffer;
248 9ca15951 2021-03-09 op static struct {
249 9cb0f9ce 2021-03-10 op char *curmesg;
251 040fbdf8 2021-03-10 op char buf[1025];
252 9ca15951 2021-03-09 op size_t off, len;
253 5cd2ebb1 2021-03-11 op char prompt[32];
254 b360ebb3 2021-03-10 op void (*donefn)(void);
255 b360ebb3 2021-03-10 op void (*abortfn)(void);
257 22268e11 2021-03-11 op struct minibuf_histhead *history;
258 22268e11 2021-03-11 op struct minibuf_hist *hist_cur;
259 22268e11 2021-03-11 op size_t hist_off;
262 f95d82dd 2021-03-11 op struct lineprefix {
263 f95d82dd 2021-03-11 op const char *prfx1;
264 f95d82dd 2021-03-11 op const char *prfx2;
265 f95d82dd 2021-03-11 op } line_prefixes[] = {
266 f95d82dd 2021-03-11 op [LINE_TEXT] = { "", "" },
267 f95d82dd 2021-03-11 op [LINE_LINK] = { "=> ", " " },
268 f95d82dd 2021-03-11 op [LINE_TITLE_1] = { "# ", " " },
269 f95d82dd 2021-03-11 op [LINE_TITLE_2] = { "## ", " " },
270 f95d82dd 2021-03-11 op [LINE_TITLE_3] = { "### ", " " },
271 f95d82dd 2021-03-11 op [LINE_ITEM] = { "* ", " " },
272 f95d82dd 2021-03-11 op [LINE_QUOTE] = { "> ", "> " },
273 f95d82dd 2021-03-11 op [LINE_PRE_START] = { "```", "```" },
274 f95d82dd 2021-03-11 op [LINE_PRE_CONTENT] = { "", "" },
275 f95d82dd 2021-03-11 op [LINE_PRE_END] = { "```", "```" },
278 d3d56d8a 2021-03-11 op struct line_face {
280 d3d56d8a 2021-03-11 op } line_faces[] = {
281 d3d56d8a 2021-03-11 op [LINE_TEXT] = { 0 },
282 d3d56d8a 2021-03-11 op [LINE_LINK] = { A_UNDERLINE },
283 d3d56d8a 2021-03-11 op [LINE_TITLE_1] = { A_BOLD },
284 d3d56d8a 2021-03-11 op [LINE_TITLE_2] = { A_BOLD },
285 d3d56d8a 2021-03-11 op [LINE_TITLE_3] = { A_BOLD },
286 d3d56d8a 2021-03-11 op [LINE_ITEM] = { 0 },
287 d3d56d8a 2021-03-11 op [LINE_QUOTE] = { A_DIM },
288 d3d56d8a 2021-03-11 op [LINE_PRE_START] = { 0 },
289 d3d56d8a 2021-03-11 op [LINE_PRE_CONTENT] = { 0 },
290 d3d56d8a 2021-03-11 op [LINE_PRE_END] = { 0 },
294 f832146f 2021-03-09 op kbd(const char *key)
296 a777f81f 2021-03-10 op struct keytable *t;
298 a777f81f 2021-03-10 op for (t = keytable; t->p != NULL; ++t) {
299 f832146f 2021-03-09 op if (has_prefix(key, t->p))
306 a777f81f 2021-03-10 op static const char *
309 a777f81f 2021-03-10 op struct keytable *t;
311 a777f81f 2021-03-10 op for (t = keytable; t->p != NULL; ++t) {
312 a777f81f 2021-03-10 op if (k == t->k)
320 f832146f 2021-03-09 op kmap_define_key(struct kmap *map, const char *key, void (*fn)(struct tab*))
322 f832146f 2021-03-09 op int ctrl, meta, k;
323 f832146f 2021-03-09 op struct keymap *entry;
326 f832146f 2021-03-09 op if ((ctrl = has_prefix(key, "C-")))
328 f832146f 2021-03-09 op if ((meta = has_prefix(key, "M-")))
330 f832146f 2021-03-09 op if (*key == '\0')
332 f832146f 2021-03-09 op k = kbd(key);
337 f832146f 2021-03-09 op /* skip key & spaces */
338 f832146f 2021-03-09 op while (*key != '\0' && !isspace(*key))
340 f832146f 2021-03-09 op while (*key != '\0' && isspace(*key))
343 9ca15951 2021-03-09 op TAILQ_FOREACH(entry, &map->m, keymaps) {
344 f832146f 2021-03-09 op if (entry->meta == meta && entry->key == k) {
345 f832146f 2021-03-09 op if (*key == '\0') {
346 f832146f 2021-03-09 op entry->fn = fn;
349 f832146f 2021-03-09 op map = &entry->map;
354 f832146f 2021-03-09 op if ((entry = calloc(1, sizeof(*entry))) == NULL)
357 f832146f 2021-03-09 op entry->meta = meta;
358 f832146f 2021-03-09 op entry->key = k;
359 9ca15951 2021-03-09 op TAILQ_INIT(&entry->map.m);
361 9ca15951 2021-03-09 op if (TAILQ_EMPTY(&map->m))
362 9ca15951 2021-03-09 op TAILQ_INSERT_HEAD(&map->m, entry, keymaps);
364 9ca15951 2021-03-09 op TAILQ_INSERT_TAIL(&map->m, entry, keymaps);
366 f832146f 2021-03-09 op if (*key != '\0') {
367 f832146f 2021-03-09 op map = &entry->map;
371 f832146f 2021-03-09 op entry->fn = fn;
374 f832146f 2021-03-09 op static inline void
375 f832146f 2021-03-09 op global_set_key(const char *key, void (*fn)(struct tab*))
377 f832146f 2021-03-09 op kmap_define_key(&global_map, key, fn);
380 9ca15951 2021-03-09 op static inline void
381 fa3fd864 2021-03-10 op minibuffer_set_key(const char *key, void (*fn)(struct tab*))
383 fa3fd864 2021-03-10 op kmap_define_key(&minibuffer_map, key, fn);
387 f832146f 2021-03-09 op load_default_keys(void)
389 9ca15951 2021-03-09 op /* === global map === */
392 f832146f 2021-03-09 op global_set_key("C-p", cmd_previous_line);
393 f832146f 2021-03-09 op global_set_key("C-n", cmd_next_line);
394 f832146f 2021-03-09 op global_set_key("C-f", cmd_forward_char);
395 f832146f 2021-03-09 op global_set_key("C-b", cmd_backward_char);
396 a329982b 2021-03-11 op global_set_key("C-a", cmd_move_beginning_of_line);
397 a329982b 2021-03-11 op global_set_key("C-e", cmd_move_end_of_line);
399 f832146f 2021-03-09 op global_set_key("M-v", cmd_scroll_up);
400 f832146f 2021-03-09 op global_set_key("C-v", cmd_scroll_down);
402 f832146f 2021-03-09 op global_set_key("C-x C-c", cmd_kill_telescope);
404 3b4f9e49 2021-03-11 op global_set_key("C-g", cmd_clear_minibuf);
406 9ca15951 2021-03-09 op global_set_key("M-x", cmd_execute_extended_command);
407 5cd2ebb1 2021-03-11 op global_set_key("C-x C-f", cmd_load_url);
408 5cd2ebb1 2021-03-11 op global_set_key("C-x M-f", cmd_load_current_url);
410 7c7d7bb7 2021-03-10 op global_set_key("C-x t 0", cmd_tab_close);
411 7c7d7bb7 2021-03-10 op global_set_key("C-x t 2", cmd_tab_new);
412 7c7d7bb7 2021-03-10 op global_set_key("C-x t o", cmd_tab_next);
413 7c7d7bb7 2021-03-10 op global_set_key("C-x t O", cmd_tab_previous);
415 e19f9a04 2021-03-11 op global_set_key("M-<", cmd_beginning_of_buffer);
416 e19f9a04 2021-03-11 op global_set_key("M->", cmd_end_of_buffer);
418 f832146f 2021-03-09 op /* vi/vi-like */
419 f832146f 2021-03-09 op global_set_key("k", cmd_previous_line);
420 f832146f 2021-03-09 op global_set_key("j", cmd_next_line);
421 f832146f 2021-03-09 op global_set_key("l", cmd_forward_char);
422 f832146f 2021-03-09 op global_set_key("h", cmd_backward_char);
423 a329982b 2021-03-11 op global_set_key("^", cmd_move_beginning_of_line);
424 a329982b 2021-03-11 op global_set_key("$", cmd_move_end_of_line);
426 ed44414d 2021-03-09 op global_set_key("K", cmd_scroll_line_up);
427 ed44414d 2021-03-09 op global_set_key("J", cmd_scroll_line_down);
429 e19f9a04 2021-03-11 op global_set_key("g g", cmd_beginning_of_buffer);
430 e19f9a04 2021-03-11 op global_set_key("G", cmd_end_of_buffer);
433 f832146f 2021-03-09 op global_set_key("q", cmd_kill_telescope);
435 3b4f9e49 2021-03-11 op global_set_key("esc", cmd_clear_minibuf);
437 9ca15951 2021-03-09 op global_set_key(":", cmd_execute_extended_command);
440 f832146f 2021-03-09 op global_set_key("<up>", cmd_previous_line);
441 f832146f 2021-03-09 op global_set_key("<down>", cmd_next_line);
442 f832146f 2021-03-09 op global_set_key("<right>", cmd_forward_char);
443 f832146f 2021-03-09 op global_set_key("<left>", cmd_backward_char);
444 ed44414d 2021-03-09 op global_set_key("<prior>", cmd_scroll_up);
445 ed44414d 2021-03-09 op global_set_key("<next>", cmd_scroll_down);
447 f832146f 2021-03-09 op /* "ncurses standard" */
448 f832146f 2021-03-09 op global_set_key("C-l", cmd_redraw);
451 f832146f 2021-03-09 op global_set_key("C-m", cmd_push_button);
453 fa3fd864 2021-03-10 op /* === minibuffer map === */
454 b360ebb3 2021-03-10 op minibuffer_set_key("ret", cmd_mini_complete_and_exit);
455 b360ebb3 2021-03-10 op minibuffer_set_key("C-g", cmd_mini_abort);
456 b360ebb3 2021-03-10 op minibuffer_set_key("esc", cmd_mini_abort);
457 fa3fd864 2021-03-10 op minibuffer_set_key("del", cmd_mini_del);
459 fa3fd864 2021-03-10 op minibuffer_set_key("C-f", cmd_mini_forward_char);
460 fa3fd864 2021-03-10 op minibuffer_set_key("C-b", cmd_mini_backward_char);
461 fa3fd864 2021-03-10 op minibuffer_set_key("C-e", cmd_mini_move_end_of_line);
462 fa3fd864 2021-03-10 op minibuffer_set_key("C-a", cmd_mini_move_beginning_of_line);
463 fa3fd864 2021-03-10 op minibuffer_set_key("<end>", cmd_mini_move_end_of_line);
464 fa3fd864 2021-03-10 op minibuffer_set_key("<home>", cmd_mini_move_beginning_of_line);
465 fa3fd864 2021-03-10 op minibuffer_set_key("C-k", cmd_mini_kill_line);
467 22268e11 2021-03-11 op minibuffer_set_key("M-p", cmd_mini_previous_history_element);
468 22268e11 2021-03-11 op minibuffer_set_key("M-n", cmd_mini_next_history_element);
469 22268e11 2021-03-11 op minibuffer_set_key("<up>", cmd_mini_previous_history_element);
470 22268e11 2021-03-11 op minibuffer_set_key("<down>", cmd_mini_next_history_element);
474 1d08c280 2021-03-06 op push_line(struct tab *tab, const struct line *l, const char *buf, size_t len)
476 1d08c280 2021-03-06 op struct line *vl;
478 48e9d457 2021-03-06 op tab->s->line_max++;
480 1d08c280 2021-03-06 op if ((vl = calloc(1, sizeof(*vl))) == NULL)
483 1d08c280 2021-03-06 op if (len != 0 && (vl->line = calloc(1, len+1)) == NULL) {
488 1d08c280 2021-03-06 op vl->type = l->type;
489 1d08c280 2021-03-06 op if (len != 0)
490 1d08c280 2021-03-06 op memcpy(vl->line, buf, len);
491 1d08c280 2021-03-06 op vl->alt = l->alt;
493 1d08c280 2021-03-06 op if (TAILQ_EMPTY(&tab->s->head))
494 1d08c280 2021-03-06 op TAILQ_INSERT_HEAD(&tab->s->head, vl, lines);
496 1d08c280 2021-03-06 op TAILQ_INSERT_TAIL(&tab->s->head, vl, lines);
501 1d08c280 2021-03-06 op empty_vlist(struct tab *tab)
503 1d08c280 2021-03-06 op struct line *l, *t;
505 48e9d457 2021-03-06 op tab->s->line_max = 0;
507 1d08c280 2021-03-06 op TAILQ_FOREACH_SAFE(l, &tab->s->head, lines, t) {
508 1d08c280 2021-03-06 op TAILQ_REMOVE(&tab->s->head, l, lines);
509 1d08c280 2021-03-06 op free(l->line);
510 1d08c280 2021-03-06 op /* l->alt references the original line! */
516 48e9d457 2021-03-06 op restore_cursor(struct tab *tab)
518 48e9d457 2021-03-06 op wmove(body, tab->s->curs_y, tab->s->curs_x);
522 46a9311e 2021-03-08 op cmd_previous_line(struct tab *tab)
524 4dd664ce 2021-03-06 op if (--tab->s->curs_y < 0) {
525 4dd664ce 2021-03-06 op tab->s->curs_y = 0;
526 ed44414d 2021-03-09 op cmd_scroll_line_up(tab);
529 48e9d457 2021-03-06 op restore_cursor(tab);
533 46a9311e 2021-03-08 op cmd_next_line(struct tab *tab)
535 fed61466 2021-03-11 op if (tab->s->line_off + tab->s->curs_y >= tab->s->line_max)
538 4dd664ce 2021-03-06 op if (++tab->s->curs_y > body_lines-1) {
539 4dd664ce 2021-03-06 op tab->s->curs_y = body_lines-1;
540 ed44414d 2021-03-09 op cmd_scroll_line_down(tab);
543 48e9d457 2021-03-06 op restore_cursor(tab);
547 46a9311e 2021-03-08 op cmd_forward_char(struct tab *tab)
549 4dd664ce 2021-03-06 op tab->s->curs_x = MIN(body_cols-1, tab->s->curs_x+1);
550 48e9d457 2021-03-06 op restore_cursor(tab);
554 46a9311e 2021-03-08 op cmd_backward_char(struct tab *tab)
556 b2cd5e06 2021-03-06 op tab->s->curs_x = MAX(0, tab->s->curs_x-1);
557 a329982b 2021-03-11 op restore_cursor(tab);
561 a329982b 2021-03-11 op cmd_move_beginning_of_line(struct tab *tab)
563 a329982b 2021-03-11 op tab->s->curs_x = 0;
564 a329982b 2021-03-11 op restore_cursor(tab);
568 a329982b 2021-03-11 op cmd_move_end_of_line(struct tab *tab)
570 a329982b 2021-03-11 op struct line *line;
572 f95d82dd 2021-03-11 op const char *prfx;
574 a329982b 2021-03-11 op off = tab->s->line_off + tab->s->curs_y;
575 a329982b 2021-03-11 op if (off >= tab->s->line_max) {
576 a329982b 2021-03-11 op tab->s->curs_x = 0;
580 a329982b 2021-03-11 op line = nth_line(tab, off);
581 a329982b 2021-03-11 op if (line->line != NULL)
582 a329982b 2021-03-11 op tab->s->curs_x = strlen(line->line);
584 a329982b 2021-03-11 op tab->s->curs_x = 0;
586 f95d82dd 2021-03-11 op prfx = line_prefixes[line->type].prfx1;
587 f95d82dd 2021-03-11 op tab->s->curs_x += strlen(prfx);
590 48e9d457 2021-03-06 op restore_cursor(tab);
594 46a9311e 2021-03-08 op cmd_redraw(struct tab *tab)
596 b1738d2e 2021-03-06 op handle_resize(0, 0, NULL);
600 ed44414d 2021-03-09 op cmd_scroll_line_up(struct tab *tab)
602 48e9d457 2021-03-06 op struct line *l;
604 48e9d457 2021-03-06 op if (tab->s->line_off == 0)
607 48e9d457 2021-03-06 op l = nth_line(tab, --tab->s->line_off);
608 48e9d457 2021-03-06 op wscrl(body, -1);
609 48e9d457 2021-03-06 op wmove(body, 0, 0);
610 48e9d457 2021-03-06 op print_line(l);
614 ed44414d 2021-03-09 op cmd_scroll_line_down(struct tab *tab)
616 48e9d457 2021-03-06 op struct line *l;
619 48e9d457 2021-03-06 op if (tab->s->line_max == 0 || tab->s->line_off == tab->s->line_max-1)
622 48e9d457 2021-03-06 op tab->s->line_off++;
623 48e9d457 2021-03-06 op wscrl(body, 1);
625 48e9d457 2021-03-06 op if (tab->s->line_max - tab->s->line_off < body_lines)
628 48e9d457 2021-03-06 op l = nth_line(tab, tab->s->line_off + body_lines-1);
629 48e9d457 2021-03-06 op wmove(body, body_lines-1, 0);
630 48e9d457 2021-03-06 op print_line(l);
634 ed44414d 2021-03-09 op cmd_scroll_up(struct tab *tab)
638 ed44414d 2021-03-09 op off = body_lines+1;
640 ed44414d 2021-03-09 op for (; off > 0; --off)
641 ed44414d 2021-03-09 op cmd_scroll_line_up(tab);
645 ed44414d 2021-03-09 op cmd_scroll_down(struct tab *tab)
649 ed44414d 2021-03-09 op off = tab->s->line_off + body_lines;
650 ed44414d 2021-03-09 op off = MIN(tab->s->line_max, off);
652 ed44414d 2021-03-09 op for (; off >= 0; --off)
653 ed44414d 2021-03-09 op cmd_scroll_line_down(tab);
657 e19f9a04 2021-03-11 op cmd_beginning_of_buffer(struct tab *tab)
659 e19f9a04 2021-03-11 op tab->s->line_off = 0;
660 e19f9a04 2021-03-11 op tab->s->curs_y = 0;
661 e19f9a04 2021-03-11 op redraw_body(tab);
665 e19f9a04 2021-03-11 op cmd_end_of_buffer(struct tab *tab)
669 e19f9a04 2021-03-11 op off = tab->s->line_max - body_lines;
670 e19f9a04 2021-03-11 op off = MAX(0, off);
672 e19f9a04 2021-03-11 op tab->s->line_off = off;
673 e19f9a04 2021-03-11 op tab->s->curs_y = MIN(body_lines, tab->s->line_max);
675 e19f9a04 2021-03-11 op redraw_body(tab);
679 46a9311e 2021-03-08 op cmd_kill_telescope(struct tab *tab)
681 1d08c280 2021-03-06 op event_loopbreak();
685 46a9311e 2021-03-08 op cmd_push_button(struct tab *tab)
687 2a4ad912 2021-03-08 op struct line *l;
690 2a4ad912 2021-03-08 op nth = tab->s->line_off + tab->s->curs_y;
691 2a4ad912 2021-03-08 op if (nth > tab->s->line_max)
693 2a4ad912 2021-03-08 op l = nth_line(tab, nth);
694 43a1b8d0 2021-03-09 op if (l->type != LINE_LINK)
697 43a1b8d0 2021-03-09 op load_url_in_tab(tab, l->alt);
701 3b4f9e49 2021-03-11 op cmd_clear_minibuf(struct tab *tab)
703 3b4f9e49 2021-03-11 op handle_clear_minibuf(0, 0, NULL);
707 9ca15951 2021-03-09 op cmd_execute_extended_command(struct tab *tab)
711 22268e11 2021-03-11 op enter_minibuffer(eecmd_self_insert, eecmd_select, exit_minibuffer,
712 22268e11 2021-03-11 op &eecmd_history);
714 9ca15951 2021-03-09 op len = sizeof(ministate.prompt);
715 9ca15951 2021-03-09 op strlcpy(ministate.prompt, "", len);
717 9ca15951 2021-03-09 op if (thiskey.meta)
718 9ca15951 2021-03-09 op strlcat(ministate.prompt, "M-", len);
720 9ca15951 2021-03-09 op strlcat(ministate.prompt, keyname(thiskey.key), len);
721 9ca15951 2021-03-09 op strlcat(ministate.prompt, " ", len);
725 7c7d7bb7 2021-03-10 op cmd_tab_close(struct tab *tab)
727 7c7d7bb7 2021-03-10 op struct tab *t;
729 7c7d7bb7 2021-03-10 op if (TAILQ_PREV(tab, tabshead, tabs) == NULL &&
730 7c7d7bb7 2021-03-10 op TAILQ_NEXT(tab, tabs) == NULL) {
731 7c7d7bb7 2021-03-10 op message("Can't close the only tab.");
735 7c7d7bb7 2021-03-10 op stop_tab(tab);
737 7c7d7bb7 2021-03-10 op t = TAILQ_PREV(tab, tabshead, tabs);
738 7c7d7bb7 2021-03-10 op t->flags |= TAB_CURRENT;
740 7c7d7bb7 2021-03-10 op TAILQ_REMOVE(&tabshead, tab, tabs);
742 7c7d7bb7 2021-03-10 op free(tab->s);
747 7c7d7bb7 2021-03-10 op cmd_tab_new(struct tab *tab)
753 7c7d7bb7 2021-03-10 op cmd_tab_next(struct tab *tab)
755 7c7d7bb7 2021-03-10 op struct tab *t;
757 7c7d7bb7 2021-03-10 op tab->flags &= ~TAB_CURRENT;
759 7c7d7bb7 2021-03-10 op if ((t = TAILQ_NEXT(tab, tabs)) == NULL)
760 7c7d7bb7 2021-03-10 op t = TAILQ_FIRST(&tabshead);
761 7c7d7bb7 2021-03-10 op t->flags |= TAB_CURRENT;
765 7c7d7bb7 2021-03-10 op cmd_tab_previous(struct tab *tab)
767 7c7d7bb7 2021-03-10 op struct tab *t;
769 7c7d7bb7 2021-03-10 op tab->flags &= ~TAB_CURRENT;
771 7c7d7bb7 2021-03-10 op if ((t = TAILQ_PREV(tab, tabshead, tabs)) == NULL)
772 7c7d7bb7 2021-03-10 op t = TAILQ_LAST(&tabshead, tabshead);
773 7c7d7bb7 2021-03-10 op t->flags |= TAB_CURRENT;
777 5cd2ebb1 2021-03-11 op cmd_load_url(struct tab *tab)
779 22268e11 2021-03-11 op enter_minibuffer(lu_self_insert, lu_select, exit_minibuffer,
780 22268e11 2021-03-11 op &lu_history);
781 5cd2ebb1 2021-03-11 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
785 5cd2ebb1 2021-03-11 op cmd_load_current_url(struct tab *tab)
787 22268e11 2021-03-11 op enter_minibuffer(lu_self_insert, lu_select, exit_minibuffer,
788 22268e11 2021-03-11 op &lu_history);
789 5cd2ebb1 2021-03-11 op strlcpy(ministate.prompt, "Load URL: ", sizeof(ministate.prompt));
790 5cd2ebb1 2021-03-11 op strlcpy(ministate.buf, tab->urlstr, sizeof(ministate.buf));
791 5cd2ebb1 2021-03-11 op ministate.off = strlen(tab->urlstr);
792 5cd2ebb1 2021-03-11 op ministate.len = ministate.off;
796 7c7d7bb7 2021-03-10 op global_key_unbound(void)
798 7c7d7bb7 2021-03-10 op message("%s is undefined", keybuf);
802 9ca15951 2021-03-09 op cmd_mini_del(struct tab *tab)
804 9ca15951 2021-03-09 op if (ministate.len == 0 || ministate.off == 0)
807 9ca15951 2021-03-09 op memmove(&ministate.buf[ministate.off-1],
808 9ca15951 2021-03-09 op &ministate.buf[ministate.off],
809 9ca15951 2021-03-09 op ministate.len - ministate.off + 1);
810 9ca15951 2021-03-09 op ministate.off--;
811 9ca15951 2021-03-09 op ministate.len--;
815 9ca15951 2021-03-09 op cmd_mini_forward_char(struct tab *tab)
817 9ca15951 2021-03-09 op if (ministate.off == ministate.len)
819 9ca15951 2021-03-09 op ministate.off++;
823 9ca15951 2021-03-09 op cmd_mini_backward_char(struct tab *tab)
825 9ca15951 2021-03-09 op if (ministate.off == 0)
827 9ca15951 2021-03-09 op ministate.off--;
831 9ca15951 2021-03-09 op cmd_mini_move_end_of_line(struct tab *tab)
833 9ca15951 2021-03-09 op ministate.off = ministate.len;
837 9ca15951 2021-03-09 op cmd_mini_move_beginning_of_line(struct tab *tab)
839 9ca15951 2021-03-09 op ministate.off = 0;
843 fa3fd864 2021-03-10 op cmd_mini_kill_line(struct tab *tab)
845 fa3fd864 2021-03-10 op if (ministate.off == ministate.len)
847 fa3fd864 2021-03-10 op ministate.buf[ministate.off] = '\0';
848 fa3fd864 2021-03-10 op ministate.len -= ministate.off;
852 b360ebb3 2021-03-10 op cmd_mini_abort(struct tab *tab)
854 b360ebb3 2021-03-10 op ministate.abortfn();
858 b360ebb3 2021-03-10 op cmd_mini_complete_and_exit(struct tab *tab)
860 22268e11 2021-03-11 op minibuffer_taint_hist();
861 b360ebb3 2021-03-10 op ministate.donefn();
865 22268e11 2021-03-11 op cmd_mini_previous_history_element(struct tab *tab)
867 22268e11 2021-03-11 op if (ministate.history == NULL) {
868 22268e11 2021-03-11 op message("No history");
872 22268e11 2021-03-11 op if (ministate.hist_cur == NULL ||
873 22268e11 2021-03-11 op (ministate.hist_cur = TAILQ_PREV(ministate.hist_cur, mhisthead, entries)) == NULL) {
874 22268e11 2021-03-11 op ministate.hist_cur = TAILQ_LAST(&ministate.history->head, mhisthead);
875 22268e11 2021-03-11 op ministate.hist_off = ministate.history->len - 1;
876 22268e11 2021-03-11 op if (ministate.hist_cur == NULL)
877 22268e11 2021-03-11 op message("No prev item");
879 22268e11 2021-03-11 op ministate.hist_off--;
882 22268e11 2021-03-11 op if (ministate.hist_cur != NULL) {
883 22268e11 2021-03-11 op ministate.off = 0;
884 22268e11 2021-03-11 op ministate.len = strlen(ministate.hist_cur->h);
889 22268e11 2021-03-11 op cmd_mini_next_history_element(struct tab *tab)
891 22268e11 2021-03-11 op if (ministate.history == NULL) {
892 22268e11 2021-03-11 op message("No history");
896 22268e11 2021-03-11 op if (ministate.hist_cur == NULL ||
897 22268e11 2021-03-11 op (ministate.hist_cur = TAILQ_NEXT(ministate.hist_cur, entries)) == NULL) {
898 22268e11 2021-03-11 op ministate.hist_cur = TAILQ_FIRST(&ministate.history->head);
899 22268e11 2021-03-11 op ministate.hist_off = 0;
900 22268e11 2021-03-11 op if (ministate.hist_cur == NULL)
901 22268e11 2021-03-11 op message("No next item");
903 22268e11 2021-03-11 op ministate.hist_off++;
906 22268e11 2021-03-11 op if (ministate.hist_cur != NULL) {
907 22268e11 2021-03-11 op ministate.off = 0;
908 22268e11 2021-03-11 op ministate.len = strlen(ministate.hist_cur->h);
913 22268e11 2021-03-11 op minibuffer_hist_save_entry(void)
915 22268e11 2021-03-11 op struct minibuf_hist *hist;
917 22268e11 2021-03-11 op if (ministate.history == NULL)
920 22268e11 2021-03-11 op if ((hist = calloc(1, sizeof(*hist))) == NULL)
923 22268e11 2021-03-11 op strlcpy(hist->h, ministate.buf, sizeof(hist->h));
925 22268e11 2021-03-11 op if (TAILQ_EMPTY(&ministate.history->head))
926 22268e11 2021-03-11 op TAILQ_INSERT_HEAD(&ministate.history->head, hist, entries);
928 22268e11 2021-03-11 op TAILQ_INSERT_TAIL(&ministate.history->head, hist, entries);
929 22268e11 2021-03-11 op ministate.history->len++;
933 22268e11 2021-03-11 op * taint the minibuffer cache: if we're currently showing a history
934 22268e11 2021-03-11 op * element, copy that to the current buf and reset the "history
935 22268e11 2021-03-11 op * navigation" thing.
938 22268e11 2021-03-11 op minibuffer_taint_hist(void)
940 22268e11 2021-03-11 op if (ministate.hist_cur == NULL)
943 22268e11 2021-03-11 op strlcpy(ministate.buf, ministate.hist_cur->h, sizeof(ministate.buf));
944 22268e11 2021-03-11 op ministate.hist_cur = NULL;
948 5cd2ebb1 2021-03-11 op minibuffer_self_insert(void)
950 22268e11 2021-03-11 op minibuffer_taint_hist();
952 040fbdf8 2021-03-10 op if (ministate.len == sizeof(ministate.buf) -1)
955 9ca15951 2021-03-09 op /* TODO: utf8 handling! */
957 9ca15951 2021-03-09 op memmove(&ministate.buf[ministate.off+1],
958 9ca15951 2021-03-09 op &ministate.buf[ministate.off],
959 9ca15951 2021-03-09 op ministate.len - ministate.off + 1);
960 9ca15951 2021-03-09 op ministate.buf[ministate.off] = thiskey.key;
961 9ca15951 2021-03-09 op ministate.off++;
962 9ca15951 2021-03-09 op ministate.len++;
966 5cd2ebb1 2021-03-11 op eecmd_self_insert(void)
968 5cd2ebb1 2021-03-11 op if (thiskey.meta || isspace(thiskey.key) ||
969 5cd2ebb1 2021-03-11 op !isgraph(thiskey.key)) {
970 5cd2ebb1 2021-03-11 op global_key_unbound();
974 5cd2ebb1 2021-03-11 op minibuffer_self_insert();
978 b360ebb3 2021-03-10 op eecmd_select(void)
980 b360ebb3 2021-03-10 op exit_minibuffer();
981 22268e11 2021-03-11 op minibuffer_hist_save_entry();
982 b360ebb3 2021-03-10 op message("TODO: try to execute %s", ministate.buf);
986 5cd2ebb1 2021-03-11 op ir_self_insert(void)
988 5cd2ebb1 2021-03-11 op minibuffer_self_insert();
992 5cd2ebb1 2021-03-11 op ir_select(void)
994 5cd2ebb1 2021-03-11 op char buf[1025] = {0};
995 5cd2ebb1 2021-03-11 op struct url url;
996 5cd2ebb1 2021-03-11 op struct tab *tab;
998 5cd2ebb1 2021-03-11 op tab = current_tab();
1000 5cd2ebb1 2021-03-11 op exit_minibuffer();
1001 22268e11 2021-03-11 op minibuffer_hist_save_entry();
1003 5cd2ebb1 2021-03-11 op /* a bit ugly but... */
1004 5cd2ebb1 2021-03-11 op memcpy(&url, &tab->url, sizeof(tab->url));
1005 5cd2ebb1 2021-03-11 op url_set_query(&url, ministate.buf);
1006 5cd2ebb1 2021-03-11 op url_unparse(&url, buf, sizeof(buf));
1007 5cd2ebb1 2021-03-11 op load_url_in_tab(tab, buf);
1011 5cd2ebb1 2021-03-11 op lu_self_insert(void)
1013 5cd2ebb1 2021-03-11 op if (thiskey.meta || isspace(thiskey.key) ||
1014 5cd2ebb1 2021-03-11 op !isgraph(thiskey.key)) {
1015 5cd2ebb1 2021-03-11 op global_key_unbound();
1019 5cd2ebb1 2021-03-11 op minibuffer_self_insert();
1023 5cd2ebb1 2021-03-11 op lu_select(void)
1025 5cd2ebb1 2021-03-11 op exit_minibuffer();
1026 22268e11 2021-03-11 op minibuffer_hist_save_entry();
1027 5cd2ebb1 2021-03-11 op load_url_in_tab(current_tab(), ministate.buf);
1030 48e9d457 2021-03-06 op static struct line *
1031 48e9d457 2021-03-06 op nth_line(struct tab *tab, size_t n)
1033 48e9d457 2021-03-06 op struct line *l;
1037 48e9d457 2021-03-06 op TAILQ_FOREACH(l, &tab->s->head, lines) {
1043 48e9d457 2021-03-06 op /* unreachable */
1047 5e11c00c 2021-03-02 op static struct tab *
1048 5e11c00c 2021-03-02 op current_tab(void)
1050 5e11c00c 2021-03-02 op struct tab *t;
1052 5e11c00c 2021-03-02 op TAILQ_FOREACH(t, &tabshead, tabs) {
1053 5e11c00c 2021-03-02 op if (t->flags & TAB_CURRENT)
1057 5e11c00c 2021-03-02 op /* unreachable */
1062 5e11c00c 2021-03-02 op dispatch_stdio(int fd, short ev, void *d)
1064 481340cc 2021-03-11 op struct tab *tab;
1065 f832146f 2021-03-09 op struct keymap *k;
1066 7c7d7bb7 2021-03-10 op const char *keyname;
1067 7c7d7bb7 2021-03-10 op char tmp[2] = {0};
1069 9ca15951 2021-03-09 op thiskey.key = wgetch(body);
1070 9ca15951 2021-03-09 op if (thiskey.key == ERR)
1072 9ca15951 2021-03-09 op if (thiskey.key == 27) {
1073 f832146f 2021-03-09 op /* TODO: make escape-time customizable */
1075 9ca15951 2021-03-09 op thiskey.meta = 1;
1076 9ca15951 2021-03-09 op thiskey.key = wgetch(body);
1077 c314a314 2021-03-11 op if (thiskey.key == ERR || thiskey.key == 27) {
1078 c314a314 2021-03-11 op thiskey.meta = 0;
1079 9ca15951 2021-03-09 op thiskey.key = 27;
1082 9ca15951 2021-03-09 op thiskey.meta = 0;
1084 7c7d7bb7 2021-03-10 op if (keybuf[0] != '\0')
1085 7c7d7bb7 2021-03-10 op strlcat(keybuf, " ", sizeof(keybuf));
1086 7c7d7bb7 2021-03-10 op if (thiskey.meta)
1087 7c7d7bb7 2021-03-10 op strlcat(keybuf, "M-", sizeof(keybuf));
1088 7c7d7bb7 2021-03-10 op if ((keyname = unkbd(thiskey.key)) != NULL)
1089 7c7d7bb7 2021-03-10 op strlcat(keybuf, keyname, sizeof(keybuf));
1091 7c7d7bb7 2021-03-10 op tmp[0] = thiskey.key;
1092 7c7d7bb7 2021-03-10 op strlcat(keybuf, tmp, sizeof(keybuf));
1095 9ca15951 2021-03-09 op TAILQ_FOREACH(k, ¤t_map->m, keymaps) {
1096 9ca15951 2021-03-09 op if (k->meta == thiskey.meta &&
1097 9ca15951 2021-03-09 op k->key == thiskey.key) {
1098 f832146f 2021-03-09 op if (k->fn == NULL)
1099 f832146f 2021-03-09 op current_map = &k->map;
1101 9ca15951 2021-03-09 op current_map = base_map;
1102 7c7d7bb7 2021-03-10 op strlcpy(keybuf, "", sizeof(keybuf));
1103 f832146f 2021-03-09 op k->fn(current_tab());
1109 7c7d7bb7 2021-03-10 op if (current_map->unhandled_input != NULL)
1110 7c7d7bb7 2021-03-10 op current_map->unhandled_input();
1112 7c7d7bb7 2021-03-10 op global_key_unbound();
1115 7c7d7bb7 2021-03-10 op strlcpy(keybuf, "", sizeof(keybuf));
1116 9ca15951 2021-03-09 op current_map = base_map;
1119 179f0f58 2021-03-11 op redraw_tab(current_tab());
1123 a6d450c1 2021-03-06 op handle_clear_minibuf(int fd, short ev, void *d)
1125 a6d450c1 2021-03-06 op clminibufev_set = 0;
1127 9cb0f9ce 2021-03-10 op free(ministate.curmesg);
1128 9cb0f9ce 2021-03-10 op ministate.curmesg = NULL;
1130 9cb0f9ce 2021-03-10 op redraw_minibuffer();
1131 9cb0f9ce 2021-03-10 op if (in_minibuffer) {
1132 9cb0f9ce 2021-03-10 op wrefresh(body);
1133 9cb0f9ce 2021-03-10 op wrefresh(minibuf);
1135 9cb0f9ce 2021-03-10 op wrefresh(minibuf);
1136 9cb0f9ce 2021-03-10 op wrefresh(body);
1141 5e11c00c 2021-03-02 op handle_resize(int sig, short ev, void *d)
1143 1d08c280 2021-03-06 op struct tab *tab;
1149 48e9d457 2021-03-06 op /* move and resize the windows, in reverse order! */
1151 b1738d2e 2021-03-06 op mvwin(minibuf, LINES-1, 0);
1152 48e9d457 2021-03-06 op wresize(minibuf, 1, COLS);
1154 48e9d457 2021-03-06 op mvwin(modeline, LINES-2, 0);
1155 48e9d457 2021-03-06 op wresize(modeline, 1, COLS);
1157 48e9d457 2021-03-06 op wresize(body, LINES-3, COLS);
1158 48e9d457 2021-03-06 op body_lines = LINES-3;
1159 bd9637e9 2021-03-06 op body_cols = COLS;
1161 48e9d457 2021-03-06 op wresize(tabline, 1, COLS);
1163 1d08c280 2021-03-06 op tab = current_tab();
1165 1d08c280 2021-03-06 op wrap_page(tab);
1166 1d08c280 2021-03-06 op redraw_tab(tab);
1170 eb259e66 2021-03-02 op * Helper function for wrap_text. Find the end of the current word
1171 eb259e66 2021-03-02 op * and the end of the separator after the word.
1174 eb259e66 2021-03-02 op word_boundaries(const char *s, const char *sep, const char **endword, const char **endspc)
1176 eb259e66 2021-03-02 op *endword = s;
1177 eb259e66 2021-03-02 op *endword = s;
1179 eb259e66 2021-03-02 op if (*s == '\0')
1182 eb259e66 2021-03-02 op /* find the end of the current world */
1183 eb259e66 2021-03-02 op for (; *s != '\0'; ++s) {
1184 eb259e66 2021-03-02 op if (strchr(sep, *s) != NULL)
1188 eb259e66 2021-03-02 op *endword = s;
1190 eb259e66 2021-03-02 op /* find the end of the separator */
1191 eb259e66 2021-03-02 op for (; *s != '\0'; ++s) {
1192 eb259e66 2021-03-02 op if (strchr(sep, *s) == NULL)
1196 eb259e66 2021-03-02 op *endspc = s;
1201 1d08c280 2021-03-06 op static inline int
1202 1d08c280 2021-03-06 op emitline(struct tab *tab, size_t zero, size_t *off, const struct line *l,
1203 1d08c280 2021-03-06 op const char **line)
1205 1d08c280 2021-03-06 op if (!push_line(tab, l, *line, *off - zero))
1207 1d08c280 2021-03-06 op *line += *off - zero;
1208 eb259e66 2021-03-02 op *off = zero;
1212 eb259e66 2021-03-02 op static inline void
1213 eb259e66 2021-03-02 op emitstr(const char **s, size_t len, size_t *off)
1217 eb259e66 2021-03-02 op /* printw("%*s", ...) doesn't seem to respect the precision, so... */
1218 eb259e66 2021-03-02 op for (i = 0; i < len; ++i)
1219 eb259e66 2021-03-02 op addch((*s)[i]);
1220 eb259e66 2021-03-02 op *off += len;
1225 1d08c280 2021-03-06 op * Build a list of visual line by wrapping the given line, assuming
1226 1d08c280 2021-03-06 op * that when printed will have a leading prefix prfx.
1228 eb259e66 2021-03-02 op * TODO: it considers each byte one cell on the screen!
1231 1d08c280 2021-03-06 op wrap_text(struct tab *tab, const char *prfx, struct line *l)
1233 eb259e66 2021-03-02 op size_t zero, off, len, split;
1234 1d08c280 2021-03-06 op const char *endword, *endspc, *line, *linestart;
1236 1d08c280 2021-03-06 op zero = strlen(prfx);
1238 1d08c280 2021-03-06 op line = l->line;
1239 1d08c280 2021-03-06 op linestart = l->line;
1241 1d08c280 2021-03-06 op while (word_boundaries(line, " \t-", &endword, &endspc)) {
1242 eb259e66 2021-03-02 op len = endword - line;
1243 48e9d457 2021-03-06 op if (off + len >= body_cols) {
1244 1d08c280 2021-03-06 op emitline(tab, zero, &off, l, &linestart);
1245 48e9d457 2021-03-06 op while (len >= body_cols) {
1246 eb259e66 2021-03-02 op /* hard wrap */
1247 1d08c280 2021-03-06 op emitline(tab, zero, &off, l, &linestart);
1248 48e9d457 2021-03-06 op len -= body_cols-1;
1249 48e9d457 2021-03-06 op line += body_cols-1;
1252 eb259e66 2021-03-02 op if (len != 0)
1257 eb259e66 2021-03-02 op /* print the spaces iff not at bol */
1258 eb259e66 2021-03-02 op len = endspc - endword;
1259 eb259e66 2021-03-02 op /* line = endspc; */
1260 eb259e66 2021-03-02 op if (off != zero) {
1261 48e9d457 2021-03-06 op if (off + len >= body_cols) {
1262 1d08c280 2021-03-06 op emitline(tab, zero, &off, l, &linestart);
1263 1d08c280 2021-03-06 op linestart = endspc;
1268 eb259e66 2021-03-02 op line = endspc;
1271 1d08c280 2021-03-06 op emitline(tab, zero, &off, l, &linestart);
1275 1d08c280 2021-03-06 op hardwrap_text(struct tab *tab, struct line *l)
1277 1d08c280 2021-03-06 op size_t off, len;
1278 1d08c280 2021-03-06 op const char *linestart;
1280 1d08c280 2021-03-06 op len = strlen(l->line);
1282 1d08c280 2021-03-06 op linestart = l->line;
1284 1d08c280 2021-03-06 op while (len >= COLS) {
1285 1d08c280 2021-03-06 op len -= COLS-1;
1286 1d08c280 2021-03-06 op off = COLS-1;
1287 1d08c280 2021-03-06 op if (!emitline(tab, 0, &off, l, &linestart))
1291 ede1f142 2021-03-07 op if (len != 0)
1292 ede1f142 2021-03-07 op return emitline(tab, 0, &len, l, &linestart);
1298 1d08c280 2021-03-06 op wrap_page(struct tab *tab)
1300 1d08c280 2021-03-06 op struct line *l;
1301 0d568960 2021-03-11 op const char *prfx;
1303 1d08c280 2021-03-06 op empty_vlist(tab);
1305 5e11c00c 2021-03-02 op TAILQ_FOREACH(l, &tab->page.head, lines) {
1306 0d568960 2021-03-11 op prfx = line_prefixes[l->type].prfx1;
1307 5e11c00c 2021-03-02 op switch (l->type) {
1308 5e11c00c 2021-03-02 op case LINE_TEXT:
1309 5e11c00c 2021-03-02 op case LINE_LINK:
1310 5e11c00c 2021-03-02 op case LINE_TITLE_1:
1311 5e11c00c 2021-03-02 op case LINE_TITLE_2:
1312 5e11c00c 2021-03-02 op case LINE_TITLE_3:
1313 5e11c00c 2021-03-02 op case LINE_ITEM:
1314 5e11c00c 2021-03-02 op case LINE_QUOTE:
1315 0d568960 2021-03-11 op wrap_text(tab, prfx, l);
1317 5e11c00c 2021-03-02 op case LINE_PRE_START:
1318 5e11c00c 2021-03-02 op case LINE_PRE_END:
1319 1d08c280 2021-03-06 op push_line(tab, l, NULL, 0);
1321 5e11c00c 2021-03-02 op case LINE_PRE_CONTENT:
1322 1d08c280 2021-03-06 op hardwrap_text(tab, l);
1329 1d08c280 2021-03-06 op static inline void
1330 1d08c280 2021-03-06 op print_line(struct line *l)
1332 bd9637e9 2021-03-06 op const char *text = l->line;
1333 f95d82dd 2021-03-11 op const char *prfx = line_prefixes[l->type].prfx1;
1334 d3d56d8a 2021-03-11 op int face = line_faces[l->type].prop;
1336 bd9637e9 2021-03-06 op if (text == NULL)
1339 d3d56d8a 2021-03-11 op if (face != 0)
1340 d3d56d8a 2021-03-11 op wattron(body, face);
1341 d3d56d8a 2021-03-11 op wprintw(body, "%s%s", prfx, text);
1342 d3d56d8a 2021-03-11 op if (face != 0)
1343 d3d56d8a 2021-03-11 op wattroff(body, face);
1347 8af5e5ed 2021-03-08 op redraw_tabline(void)
1349 7c7d7bb7 2021-03-10 op struct tab *tab;
1350 7c7d7bb7 2021-03-10 op int current;
1352 8af5e5ed 2021-03-08 op wclear(tabline);
1353 8af5e5ed 2021-03-08 op wbkgd(tabline, A_REVERSE);
1355 7c7d7bb7 2021-03-10 op wprintw(tabline, " ");
1356 7c7d7bb7 2021-03-10 op TAILQ_FOREACH(tab, &tabshead, tabs) {
1357 7c7d7bb7 2021-03-10 op current = tab->flags & TAB_CURRENT;
1359 a329982b 2021-03-11 op if (current)
1360 a329982b 2021-03-11 op wattron(tabline, A_UNDERLINE);
1362 a329982b 2021-03-11 op wprintw(tabline, "%s%d:todo title ",
1363 a329982b 2021-03-11 op current ? "*" : " ", tab->id);
1365 a329982b 2021-03-11 op if (current)
1366 a329982b 2021-03-11 op wattroff(tabline, A_UNDERLINE);
1371 48e9d457 2021-03-06 op redraw_modeline(struct tab *tab)
1374 48e9d457 2021-03-06 op int x, y, max_x, max_y;
1375 48e9d457 2021-03-06 op const char *mode = "text/gemini-mode";
1376 8af5e5ed 2021-03-08 op const char *spin = "-\\|/";
1378 48e9d457 2021-03-06 op wclear(modeline);
1379 48e9d457 2021-03-06 op wattron(modeline, A_REVERSE);
1380 48e9d457 2021-03-06 op wmove(modeline, 0, 0);
1382 481340cc 2021-03-11 op wprintw(modeline, "-%c %s ",
1383 481340cc 2021-03-11 op spin[tab->s->loading_anim_step], mode);
1385 481340cc 2021-03-11 op pct = (tab->s->line_off + tab->s->curs_y) * 100.0 / tab->s->line_max;
1387 481340cc 2021-03-11 op if (tab->s->line_max <= body_lines)
1388 481340cc 2021-03-11 op wprintw(modeline, "All ");
1389 481340cc 2021-03-11 op else if (tab->s->line_off == 0)
1390 481340cc 2021-03-11 op wprintw(modeline, "Top ");
1391 481340cc 2021-03-11 op else if (tab->s->line_off + body_lines >= tab->s->line_max)
1392 481340cc 2021-03-11 op wprintw(modeline, "Bottom ");
1394 481340cc 2021-03-11 op wprintw(modeline, "%.0f%% ", pct);
1396 481340cc 2021-03-11 op wprintw(modeline, "%d/%d %s ",
1397 481340cc 2021-03-11 op tab->s->line_off + tab->s->curs_y,
1398 481340cc 2021-03-11 op tab->s->line_max,
1399 481340cc 2021-03-11 op tab->urlstr);
1401 48e9d457 2021-03-06 op getyx(modeline, y, x);
1402 48e9d457 2021-03-06 op getmaxyx(modeline, max_y, max_x);
1405 48e9d457 2021-03-06 op (void)max_y;
1407 48e9d457 2021-03-06 op for (; x < max_x; ++x)
1408 48e9d457 2021-03-06 op waddstr(modeline, "-");
1412 9ca15951 2021-03-09 op redraw_minibuffer(void)
1414 22268e11 2021-03-11 op size_t skip = 0, off_x = 0, off_y = 0;
1416 9ca15951 2021-03-09 op wclear(minibuf);
1417 22268e11 2021-03-11 op if (in_minibuffer) {
1418 22268e11 2021-03-11 op mvwprintw(minibuf, 0, 0, "%s", ministate.prompt);
1419 22268e11 2021-03-11 op if (ministate.hist_cur != NULL)
1420 22268e11 2021-03-11 op wprintw(minibuf, "(%zu/%zu) ",
1421 22268e11 2021-03-11 op ministate.hist_off + 1,
1422 22268e11 2021-03-11 op ministate.history->len);
1424 22268e11 2021-03-11 op getyx(minibuf, off_y, off_x);
1426 22268e11 2021-03-11 op while (ministate.off - skip > COLS / 2) {
1427 22268e11 2021-03-11 op skip += MIN(ministate.off/4, 1);
1430 22268e11 2021-03-11 op if (ministate.hist_cur != NULL)
1431 22268e11 2021-03-11 op wprintw(minibuf, "%s", ministate.hist_cur->h + skip);
1433 22268e11 2021-03-11 op wprintw(minibuf, "%s", ministate.buf + skip);
1436 9cb0f9ce 2021-03-10 op if (ministate.curmesg != NULL) {
1437 9cb0f9ce 2021-03-10 op if (in_minibuffer)
1438 9cb0f9ce 2021-03-10 op wprintw(minibuf, " [%s]", ministate.curmesg);
1440 9cb0f9ce 2021-03-10 op wprintw(minibuf, "%s", ministate.curmesg);
1443 22268e11 2021-03-11 op wmove(minibuf, 0, off_x + ministate.off - skip);
1447 48e9d457 2021-03-06 op redraw_tab(struct tab *tab)
1449 e19f9a04 2021-03-11 op redraw_tabline();
1450 e19f9a04 2021-03-11 op redraw_body(tab);
1451 e19f9a04 2021-03-11 op redraw_modeline(tab);
1452 e19f9a04 2021-03-11 op redraw_minibuffer();
1454 e19f9a04 2021-03-11 op restore_cursor(tab);
1455 e19f9a04 2021-03-11 op wrefresh(tabline);
1456 e19f9a04 2021-03-11 op wrefresh(modeline);
1458 e19f9a04 2021-03-11 op if (in_minibuffer) {
1459 e19f9a04 2021-03-11 op wrefresh(body);
1460 e19f9a04 2021-03-11 op wrefresh(minibuf);
1462 e19f9a04 2021-03-11 op wrefresh(minibuf);
1463 e19f9a04 2021-03-11 op wrefresh(body);
1468 e19f9a04 2021-03-11 op redraw_body(struct tab *tab)
1470 48e9d457 2021-03-06 op struct line *l;
1473 48e9d457 2021-03-06 op werase(body);
1475 48e9d457 2021-03-06 op tab->s->line_off = MIN(tab->s->line_max, tab->s->line_off);
1476 48e9d457 2021-03-06 op if (TAILQ_EMPTY(&tab->s->head))
1480 48e9d457 2021-03-06 op l = nth_line(tab, tab->s->line_off);
1481 48e9d457 2021-03-06 op for (; l != NULL; l = TAILQ_NEXT(l, lines)) {
1482 48e9d457 2021-03-06 op wmove(body, line, 0);
1483 1d08c280 2021-03-06 op print_line(l);
1485 48e9d457 2021-03-06 op if (line == body_lines)
1491 7953dd72 2021-03-07 op message(const char *fmt, ...)
1495 7953dd72 2021-03-07 op if (clminibufev_set)
1496 7953dd72 2021-03-07 op evtimer_del(&clminibufev);
1497 7953dd72 2021-03-07 op evtimer_set(&clminibufev, handle_clear_minibuf, NULL);
1498 7953dd72 2021-03-07 op evtimer_add(&clminibufev, &clminibufev_timer);
1499 7953dd72 2021-03-07 op clminibufev_set = 1;
1501 9cb0f9ce 2021-03-10 op va_start(ap, fmt);
1502 9cb0f9ce 2021-03-10 op /* TODO: what to do if the allocation fails here? */
1503 9cb0f9ce 2021-03-10 op if (vasprintf(&ministate.curmesg, fmt, ap) == -1)
1504 9cb0f9ce 2021-03-10 op ministate.curmesg = NULL;
1507 9cb0f9ce 2021-03-10 op redraw_minibuffer();
1509 9cb0f9ce 2021-03-10 op if (in_minibuffer) {
1510 9cb0f9ce 2021-03-10 op wrefresh(body);
1511 9cb0f9ce 2021-03-10 op wrefresh(minibuf);
1513 9cb0f9ce 2021-03-10 op wrefresh(minibuf);
1514 9cb0f9ce 2021-03-10 op wrefresh(body);
1519 8af5e5ed 2021-03-08 op start_loading_anim(struct tab *tab)
1521 8af5e5ed 2021-03-08 op if (tab->s->loading_anim)
1523 8af5e5ed 2021-03-08 op tab->s->loading_anim = 1;
1524 8af5e5ed 2021-03-08 op evtimer_set(&tab->s->loadingev, update_loading_anim, tab);
1525 8af5e5ed 2021-03-08 op evtimer_add(&tab->s->loadingev, &loadingev_timer);
1529 8af5e5ed 2021-03-08 op update_loading_anim(int fd, short ev, void *d)
1531 8af5e5ed 2021-03-08 op struct tab *tab = d;
1533 8af5e5ed 2021-03-08 op tab->s->loading_anim_step = (tab->s->loading_anim_step+1)%4;
1535 8af5e5ed 2021-03-08 op redraw_modeline(tab);
1536 8af5e5ed 2021-03-08 op wrefresh(modeline);
1538 8af5e5ed 2021-03-08 op wrefresh(body);
1539 9ca15951 2021-03-09 op if (in_minibuffer)
1540 9ca15951 2021-03-09 op wrefresh(minibuf);
1542 8af5e5ed 2021-03-08 op evtimer_add(&tab->s->loadingev, &loadingev_timer);
1546 8af5e5ed 2021-03-08 op stop_loading_anim(struct tab *tab)
1548 8af5e5ed 2021-03-08 op if (!tab->s->loading_anim)
1550 8af5e5ed 2021-03-08 op evtimer_del(&tab->s->loadingev);
1551 8af5e5ed 2021-03-08 op tab->s->loading_anim = 0;
1552 8af5e5ed 2021-03-08 op tab->s->loading_anim_step = 0;
1554 43a1b8d0 2021-03-09 op redraw_modeline(tab);
1556 43a1b8d0 2021-03-09 op wrefresh(modeline);
1557 43a1b8d0 2021-03-09 op wrefresh(body);
1558 9ca15951 2021-03-09 op if (in_minibuffer)
1559 9ca15951 2021-03-09 op wrefresh(minibuf);
1563 43a1b8d0 2021-03-09 op load_url_in_tab(struct tab *tab, const char *url)
1565 43a1b8d0 2021-03-09 op empty_vlist(tab);
1566 8af5e5ed 2021-03-08 op message("Loading %s...", url);
1567 8af5e5ed 2021-03-08 op start_loading_anim(tab);
1568 8af5e5ed 2021-03-08 op load_url(tab, url);
1570 43a1b8d0 2021-03-09 op tab->s->curs_x = 0;
1571 43a1b8d0 2021-03-09 op tab->s->curs_y = 0;
1572 43a1b8d0 2021-03-09 op redraw_tab(tab);
1576 b360ebb3 2021-03-10 op enter_minibuffer(void (*self_insert_fn)(void), void (*donefn)(void),
1577 22268e11 2021-03-11 op void (*abortfn)(void), struct minibuf_histhead *hist)
1579 9ca15951 2021-03-09 op in_minibuffer = 1;
1580 fa3fd864 2021-03-10 op base_map = &minibuffer_map;
1581 fa3fd864 2021-03-10 op current_map = &minibuffer_map;
1583 fa3fd864 2021-03-10 op base_map->unhandled_input = self_insert_fn;
1585 b360ebb3 2021-03-10 op ministate.donefn = donefn;
1586 b360ebb3 2021-03-10 op ministate.abortfn = abortfn;
1587 9ca15951 2021-03-09 op memset(ministate.buf, 0, sizeof(ministate.buf));
1588 9ca15951 2021-03-09 op ministate.off = 0;
1589 9ca15951 2021-03-09 op strlcpy(ministate.buf, "", sizeof(ministate.prompt));
1591 22268e11 2021-03-11 op ministate.history = hist;
1592 22268e11 2021-03-11 op ministate.hist_cur = NULL;
1593 22268e11 2021-03-11 op ministate.hist_off = 0;
1597 b360ebb3 2021-03-10 op exit_minibuffer(void)
1599 9ca15951 2021-03-09 op wclear(minibuf);
1601 9ca15951 2021-03-09 op in_minibuffer = 0;
1602 9ca15951 2021-03-09 op base_map = &global_map;
1603 9ca15951 2021-03-09 op current_map = &global_map;
1607 5cd2ebb1 2021-03-11 op switch_to_tab(struct tab *tab)
1609 5cd2ebb1 2021-03-11 op struct tab *t;
1611 5cd2ebb1 2021-03-11 op TAILQ_FOREACH(t, &tabshead, tabs) {
1612 5cd2ebb1 2021-03-11 op t->flags &= ~TAB_CURRENT;
1615 5cd2ebb1 2021-03-11 op tab->flags |= TAB_CURRENT;
1619 bcb0b073 2021-03-07 op new_tab(void)
1621 bcb0b073 2021-03-07 op struct tab *tab, *t;
1622 bcb0b073 2021-03-07 op const char *url = "about:new";
1624 bcb0b073 2021-03-07 op if ((tab = calloc(1, sizeof(*tab))) == NULL)
1627 bcb0b073 2021-03-07 op if ((tab->s = calloc(1, sizeof(*t->s))) == NULL)
1630 bcb0b073 2021-03-07 op TAILQ_INIT(&tab->s->head);
1632 bcb0b073 2021-03-07 op tab->id = tab_counter++;
1633 5cd2ebb1 2021-03-11 op switch_to_tab(tab);
1635 bcb0b073 2021-03-07 op if (TAILQ_EMPTY(&tabshead))
1636 bcb0b073 2021-03-07 op TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
1638 bcb0b073 2021-03-07 op TAILQ_INSERT_TAIL(&tabshead, tab, tabs);
1640 43a1b8d0 2021-03-09 op load_url_in_tab(tab, url);
1644 bcb0b073 2021-03-07 op event_loopbreak();
1648 5e11c00c 2021-03-02 op ui_init(void)
1650 5e11c00c 2021-03-02 op setlocale(LC_ALL, "");
1652 9ca15951 2021-03-09 op TAILQ_INIT(&global_map.m);
1653 9ca15951 2021-03-09 op global_map.unhandled_input = global_key_unbound;
1655 fa3fd864 2021-03-10 op TAILQ_INIT(&minibuffer_map.m);
1657 22268e11 2021-03-11 op TAILQ_INIT(&eecmd_history.head);
1658 22268e11 2021-03-11 op TAILQ_INIT(&ir_history.head);
1659 22268e11 2021-03-11 op TAILQ_INIT(&lu_history.head);
1661 9ca15951 2021-03-09 op base_map = &global_map;
1662 f832146f 2021-03-09 op current_map = &global_map;
1663 f832146f 2021-03-09 op load_default_keys();
1670 5e11c00c 2021-03-02 op intrflush(stdscr, FALSE);
1672 48e9d457 2021-03-06 op if ((tabline = newwin(1, COLS, 0, 0)) == NULL)
1674 48e9d457 2021-03-06 op if ((body = newwin(LINES - 3, COLS, 1, 0)) == NULL)
1676 48e9d457 2021-03-06 op if ((modeline = newwin(1, COLS, LINES-2, 0)) == NULL)
1678 48e9d457 2021-03-06 op if ((minibuf = newwin(1, COLS, LINES-1, 0)) == NULL)
1681 48e9d457 2021-03-06 op body_lines = LINES-3;
1682 48e9d457 2021-03-06 op body_cols = COLS;
1684 43a1b8d0 2021-03-09 op keypad(body, TRUE);
1685 48e9d457 2021-03-06 op scrollok(body, TRUE);
1687 5e11c00c 2021-03-02 op /* non-blocking input */
1688 48e9d457 2021-03-06 op wtimeout(body, 0);
1690 48e9d457 2021-03-06 op mvwprintw(body, 0, 0, "");
1692 5e11c00c 2021-03-02 op event_set(&stdioev, 0, EV_READ | EV_PERSIST, dispatch_stdio, NULL);
1693 5e11c00c 2021-03-02 op event_add(&stdioev, NULL);
1695 5e11c00c 2021-03-02 op signal_set(&winchev, SIGWINCH, handle_resize, NULL);
1696 5e11c00c 2021-03-02 op signal_add(&winchev, NULL);
1704 8af5e5ed 2021-03-08 op ui_on_tab_loaded(struct tab *tab)
1706 8af5e5ed 2021-03-08 op stop_loading_anim(tab);
1707 4d3785b1 2021-03-09 op message("Loaded %s", tab->urlstr);
1711 5e11c00c 2021-03-02 op ui_on_tab_refresh(struct tab *tab)
1713 5e11c00c 2021-03-02 op if (!(tab->flags & TAB_CURRENT))
1716 1d08c280 2021-03-06 op wrap_page(tab);
1717 5e11c00c 2021-03-02 op redraw_tab(tab);
1721 5cd2ebb1 2021-03-11 op ui_require_input(struct tab *tab, int hide)
1723 5cd2ebb1 2021-03-11 op /* TODO: hard-switching to another tab is ugly */
1724 5cd2ebb1 2021-03-11 op switch_to_tab(tab);
1726 22268e11 2021-03-11 op enter_minibuffer(ir_self_insert, ir_select, exit_minibuffer,
1727 22268e11 2021-03-11 op &ir_history);
1728 5cd2ebb1 2021-03-11 op strlcpy(ministate.prompt, "Input required: ",
1729 5cd2ebb1 2021-03-11 op sizeof(ministate.prompt));
1730 5cd2ebb1 2021-03-11 op redraw_tab(tab);
1734 5e11c00c 2021-03-02 op ui_end(void)