Blame


1 5e11c00c 2021-03-02 op /*
2 5e11c00c 2021-03-02 op * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
3 5e11c00c 2021-03-02 op *
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.
7 5e11c00c 2021-03-02 op *
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.
15 5e11c00c 2021-03-02 op */
16 5e11c00c 2021-03-02 op
17 1d08c280 2021-03-06 op /*
18 1d08c280 2021-03-06 op * Ncurses UI for telescope.
19 1d08c280 2021-03-06 op *
20 1d08c280 2021-03-06 op * Text scrolling
21 1d08c280 2021-03-06 op * ==============
22 1d08c280 2021-03-06 op *
23 1d08c280 2021-03-06 op * ncurses allows you to scroll a window, but when a line goes out of
24 1d08c280 2021-03-06 op * the visible area it's forgotten. We keep a list of formatted lines
25 1d08c280 2021-03-06 op * (``visual lines'') that we know fits in the window, and draw them.
26 1d08c280 2021-03-06 op *
27 1d08c280 2021-03-06 op * This means that on every resize we have to clear our list of lines
28 1d08c280 2021-03-06 op * and re-render everything. A clever approach would be to do this
29 970deec6 2021-04-24 op * ``on-demand'', but it's still missing.
30 1d08c280 2021-03-06 op *
31 1d08c280 2021-03-06 op */
32 1d08c280 2021-03-06 op
33 bddc7bbd 2021-04-01 op #include <assert.h>
34 5e11c00c 2021-03-02 op #include <curses.h>
35 5e11c00c 2021-03-02 op #include <event.h>
36 5e11c00c 2021-03-02 op #include <locale.h>
37 5e11c00c 2021-03-02 op #include <signal.h>
38 7953dd72 2021-03-07 op #include <stdarg.h>
39 eb259e66 2021-03-02 op #include <stdlib.h>
40 eb259e66 2021-03-02 op #include <string.h>
41 f832146f 2021-03-09 op #include <unistd.h>
42 5e11c00c 2021-03-02 op
43 d1a0f2a3 2021-07-12 op #include "minibuffer.h"
44 d1a0f2a3 2021-07-12 op #include "telescope.h"
45 d1a0f2a3 2021-07-12 op #include "ui.h"
46 5caf7d67 2021-07-12 op #include "utf8.h"
47 d1a0f2a3 2021-07-12 op
48 5e11c00c 2021-03-02 op static struct event stdioev, winchev;
49 5e11c00c 2021-03-02 op
50 0a805b02 2021-07-01 op static void restore_curs_x(struct buffer *);
51 9ca15951 2021-03-09 op
52 46f6e974 2021-05-17 op static struct vline *nth_line(struct buffer*, size_t);
53 8947c1f2 2021-03-21 op static int readkey(void);
54 5e11c00c 2021-03-02 op static void dispatch_stdio(int, short, void*);
55 8a7f2683 2021-07-10 op static void handle_clear_echoarea(int, short, void*);
56 5e11c00c 2021-03-02 op static void handle_resize(int, short, void*);
57 a8a482c8 2021-05-17 op static void handle_resize_nodelay(int, short, void*);
58 46f6e974 2021-05-17 op static int wrap_page(struct buffer*, int);
59 f3bcf8f2 2021-06-21 op static void print_vline(int, int, WINDOW*, struct vline*);
60 8af5e5ed 2021-03-08 op static void redraw_tabline(void);
61 f3bcf8f2 2021-06-21 op static void redraw_window(WINDOW*, int, int, struct buffer*);
62 bddc7bbd 2021-04-01 op static void redraw_help(void);
63 e19f9a04 2021-03-11 op static void redraw_body(struct tab*);
64 8af5e5ed 2021-03-08 op static void redraw_modeline(struct tab*);
65 e9af06b9 2021-07-12 op static void redraw_minibuffer(void);
66 e9af06b9 2021-07-12 op static void do_redraw_echoarea(void);
67 e9af06b9 2021-07-12 op static void do_redraw_minibuffer(void);
68 5e11c00c 2021-03-02 op static void redraw_tab(struct tab*);
69 bddc7bbd 2021-04-01 op static void emit_help_item(char*, void*);
70 bddc7bbd 2021-04-01 op static void rec_compute_help(struct kmap*, char*, size_t);
71 bddc7bbd 2021-04-01 op static void recompute_help(void);
72 8af5e5ed 2021-03-08 op static void update_loading_anim(int, short, void*);
73 8af5e5ed 2021-03-08 op static void stop_loading_anim(struct tab*);
74 5e11c00c 2021-03-02 op
75 72b18268 2021-06-19 op static int x_offset;
76 72b18268 2021-06-19 op
77 2b2d2872 2021-06-20 op struct thiskey thiskey;
78 9ca15951 2021-03-09 op
79 831deb20 2021-05-12 op static struct event resizeev;
80 831deb20 2021-05-12 op static struct timeval resize_timer = { 0, 250000 };
81 831deb20 2021-05-12 op
82 8a7f2683 2021-07-10 op static WINDOW *tabline, *body, *modeline, *echoarea;
83 48e9d457 2021-03-06 op
84 2b2d2872 2021-06-20 op int body_lines, body_cols;
85 2b2d2872 2021-06-20 op
86 bddc7bbd 2021-04-01 op static WINDOW *help;
87 46f6e974 2021-05-17 op static struct buffer helpwin;
88 bddc7bbd 2021-04-01 op static int help_lines, help_cols;
89 bddc7bbd 2021-04-01 op
90 bddc7bbd 2021-04-01 op static int side_window;
91 bddc7bbd 2021-04-01 op
92 8a7f2683 2021-07-10 op static struct event clechoev;
93 8a7f2683 2021-07-10 op static struct timeval clechoev_timer = { 5, 0 };
94 8af5e5ed 2021-03-08 op static struct timeval loadingev_timer = { 0, 250000 };
95 48e9d457 2021-03-06 op
96 bcb0b073 2021-03-07 op static uint32_t tab_counter;
97 bcb0b073 2021-03-07 op
98 7c7d7bb7 2021-03-10 op static char keybuf[64];
99 9ca15951 2021-03-09 op
100 9ca15951 2021-03-09 op struct kmap global_map,
101 fa3fd864 2021-03-10 op minibuffer_map,
102 9ca15951 2021-03-09 op *current_map,
103 9ca15951 2021-03-09 op *base_map;
104 9ca15951 2021-03-09 op
105 2b2d2872 2021-06-20 op int in_minibuffer;
106 9ca15951 2021-03-09 op
107 72b18268 2021-06-19 op static inline void
108 923f9ce5 2021-06-21 op update_x_offset(void)
109 72b18268 2021-06-19 op {
110 72b18268 2021-06-19 op if (olivetti_mode && fill_column < body_cols)
111 72b18268 2021-06-19 op x_offset = (body_cols - fill_column)/2;
112 72b18268 2021-06-19 op else
113 72b18268 2021-06-19 op x_offset = 0;
114 72b18268 2021-06-19 op }
115 65d9b3ca 2021-03-14 op
116 98411855 2021-06-23 op void
117 98411855 2021-06-23 op save_excursion(struct excursion *place, struct buffer *buffer)
118 98411855 2021-06-23 op {
119 98411855 2021-06-23 op place->curs_x = buffer->curs_x;
120 98411855 2021-06-23 op place->curs_y = buffer->curs_y;
121 98411855 2021-06-23 op place->line_off = buffer->line_off;
122 98411855 2021-06-23 op place->current_line = buffer->current_line;
123 98411855 2021-06-23 op place->cpoff = buffer->cpoff;
124 98411855 2021-06-23 op }
125 98411855 2021-06-23 op
126 98411855 2021-06-23 op void
127 98411855 2021-06-23 op restore_excursion(struct excursion *place, struct buffer *buffer)
128 98411855 2021-06-23 op {
129 98411855 2021-06-23 op buffer->curs_x = place->curs_x;
130 98411855 2021-06-23 op buffer->curs_y = place->curs_y;
131 98411855 2021-06-23 op buffer->line_off = place->line_off;
132 98411855 2021-06-23 op buffer->current_line = place->current_line;
133 98411855 2021-06-23 op buffer->cpoff = place->cpoff;
134 1d08c280 2021-03-06 op }
135 1d08c280 2021-03-06 op
136 0a805b02 2021-07-01 op static void
137 0a805b02 2021-07-01 op restore_curs_x(struct buffer *buffer)
138 48e9d457 2021-03-06 op {
139 452589f7 2021-03-16 op struct vline *vl;
140 452589f7 2021-03-16 op const char *prfx;
141 452589f7 2021-03-16 op
142 46f6e974 2021-05-17 op vl = buffer->current_line;
143 452589f7 2021-03-16 op if (vl == NULL || vl->line == NULL)
144 46f6e974 2021-05-17 op buffer->curs_x = buffer->cpoff = 0;
145 452589f7 2021-03-16 op else
146 46f6e974 2021-05-17 op buffer->curs_x = utf8_snwidth(vl->line, buffer->cpoff);
147 452589f7 2021-03-16 op
148 72b18268 2021-06-19 op buffer->curs_x += x_offset;
149 72b18268 2021-06-19 op
150 452589f7 2021-03-16 op if (vl != NULL) {
151 452589f7 2021-03-16 op prfx = line_prefixes[vl->parent->type].prfx1;
152 46f6e974 2021-05-17 op buffer->curs_x += utf8_swidth(prfx);
153 2ba66cea 2021-03-22 op }
154 9ca15951 2021-03-09 op }
155 9ca15951 2021-03-09 op
156 d5bdf203 2021-07-08 op void
157 870210fb 2021-03-26 op global_key_unbound(void)
158 870210fb 2021-03-26 op {
159 870210fb 2021-03-26 op message("%s is undefined", keybuf);
160 870210fb 2021-03-26 op }
161 870210fb 2021-03-26 op
162 9a25f829 2021-03-14 op static struct vline *
163 46f6e974 2021-05-17 op nth_line(struct buffer *buffer, size_t n)
164 48e9d457 2021-03-06 op {
165 9a25f829 2021-03-14 op struct vline *vl;
166 48e9d457 2021-03-06 op size_t i;
167 48e9d457 2021-03-06 op
168 48e9d457 2021-03-06 op i = 0;
169 46f6e974 2021-05-17 op TAILQ_FOREACH(vl, &buffer->head, vlines) {
170 48e9d457 2021-03-06 op if (i == n)
171 9a25f829 2021-03-14 op return vl;
172 48e9d457 2021-03-06 op i++;
173 48e9d457 2021-03-06 op }
174 48e9d457 2021-03-06 op
175 48e9d457 2021-03-06 op /* unreachable */
176 48e9d457 2021-03-06 op abort();
177 48e9d457 2021-03-06 op }
178 48e9d457 2021-03-06 op
179 2b2d2872 2021-06-20 op struct tab *
180 5e11c00c 2021-03-02 op current_tab(void)
181 5e11c00c 2021-03-02 op {
182 5e11c00c 2021-03-02 op struct tab *t;
183 5e11c00c 2021-03-02 op
184 5e11c00c 2021-03-02 op TAILQ_FOREACH(t, &tabshead, tabs) {
185 5e11c00c 2021-03-02 op if (t->flags & TAB_CURRENT)
186 5e11c00c 2021-03-02 op return t;
187 5e11c00c 2021-03-02 op }
188 5e11c00c 2021-03-02 op
189 5e11c00c 2021-03-02 op /* unreachable */
190 5e11c00c 2021-03-02 op abort();
191 5e11c00c 2021-03-02 op }
192 5e11c00c 2021-03-02 op
193 2b2d2872 2021-06-20 op struct buffer *
194 46f6e974 2021-05-17 op current_buffer(void)
195 2ba66cea 2021-03-22 op {
196 2ba66cea 2021-03-22 op if (in_minibuffer)
197 46f6e974 2021-05-17 op return &ministate.buffer;
198 46f6e974 2021-05-17 op return &current_tab()->buffer;
199 2ba66cea 2021-03-22 op }
200 2ba66cea 2021-03-22 op
201 8947c1f2 2021-03-21 op static int
202 8947c1f2 2021-03-21 op readkey(void)
203 5e11c00c 2021-03-02 op {
204 8947c1f2 2021-03-21 op uint32_t state = 0;
205 19f1448e 2021-03-08 op
206 8947c1f2 2021-03-21 op if ((thiskey.key = wgetch(body)) == ERR)
207 8947c1f2 2021-03-21 op return 0;
208 5e11c00c 2021-03-02 op
209 8947c1f2 2021-03-21 op thiskey.meta = thiskey.key == 27;
210 8947c1f2 2021-03-21 op if (thiskey.meta) {
211 9ca15951 2021-03-09 op thiskey.key = wgetch(body);
212 c314a314 2021-03-11 op if (thiskey.key == ERR || thiskey.key == 27) {
213 c314a314 2021-03-11 op thiskey.meta = 0;
214 9ca15951 2021-03-09 op thiskey.key = 27;
215 c314a314 2021-03-11 op }
216 8947c1f2 2021-03-21 op }
217 8947c1f2 2021-03-21 op
218 8947c1f2 2021-03-21 op thiskey.cp = 0;
219 8947c1f2 2021-03-21 op if ((unsigned int)thiskey.key < UINT8_MAX) {
220 8947c1f2 2021-03-21 op while (1) {
221 8947c1f2 2021-03-21 op if (!utf8_decode(&state, &thiskey.cp, (uint8_t)thiskey.key))
222 8947c1f2 2021-03-21 op break;
223 8947c1f2 2021-03-21 op if ((thiskey.key = wgetch(body)) == ERR) {
224 8947c1f2 2021-03-21 op message("Error decoding user input");
225 8947c1f2 2021-03-21 op return 0;
226 8947c1f2 2021-03-21 op }
227 8947c1f2 2021-03-21 op }
228 8947c1f2 2021-03-21 op }
229 19f1448e 2021-03-08 op
230 8947c1f2 2021-03-21 op return 1;
231 8947c1f2 2021-03-21 op }
232 8947c1f2 2021-03-21 op
233 8947c1f2 2021-03-21 op static void
234 8947c1f2 2021-03-21 op dispatch_stdio(int fd, short ev, void *d)
235 8947c1f2 2021-03-21 op {
236 8947c1f2 2021-03-21 op struct keymap *k;
237 8947c1f2 2021-03-21 op const char *keyname;
238 8947c1f2 2021-03-21 op char tmp[5] = {0};
239 8947c1f2 2021-03-21 op
240 8947c1f2 2021-03-21 op if (!readkey())
241 8947c1f2 2021-03-21 op return;
242 8947c1f2 2021-03-21 op
243 7c7d7bb7 2021-03-10 op if (keybuf[0] != '\0')
244 7c7d7bb7 2021-03-10 op strlcat(keybuf, " ", sizeof(keybuf));
245 7c7d7bb7 2021-03-10 op if (thiskey.meta)
246 7c7d7bb7 2021-03-10 op strlcat(keybuf, "M-", sizeof(keybuf));
247 8947c1f2 2021-03-21 op if (thiskey.cp != 0) {
248 8947c1f2 2021-03-21 op utf8_encode(thiskey.cp, tmp);
249 7c7d7bb7 2021-03-10 op strlcat(keybuf, tmp, sizeof(keybuf));
250 8947c1f2 2021-03-21 op } else {
251 8947c1f2 2021-03-21 op if ((keyname = unkbd(thiskey.key)) != NULL)
252 8947c1f2 2021-03-21 op strlcat(keybuf, keyname, sizeof(keybuf));
253 8947c1f2 2021-03-21 op else {
254 8947c1f2 2021-03-21 op tmp[0] = thiskey.key;
255 8947c1f2 2021-03-21 op strlcat(keybuf, tmp, sizeof(keybuf));
256 8947c1f2 2021-03-21 op }
257 7c7d7bb7 2021-03-10 op }
258 7c7d7bb7 2021-03-10 op
259 9ca15951 2021-03-09 op TAILQ_FOREACH(k, &current_map->m, keymaps) {
260 9ca15951 2021-03-09 op if (k->meta == thiskey.meta &&
261 9ca15951 2021-03-09 op k->key == thiskey.key) {
262 f832146f 2021-03-09 op if (k->fn == NULL)
263 f832146f 2021-03-09 op current_map = &k->map;
264 f832146f 2021-03-09 op else {
265 9ca15951 2021-03-09 op current_map = base_map;
266 7c7d7bb7 2021-03-10 op strlcpy(keybuf, "", sizeof(keybuf));
267 46f6e974 2021-05-17 op k->fn(current_buffer());
268 f832146f 2021-03-09 op }
269 1d08c280 2021-03-06 op goto done;
270 1d08c280 2021-03-06 op }
271 eb259e66 2021-03-02 op }
272 eb259e66 2021-03-02 op
273 7c7d7bb7 2021-03-10 op if (current_map->unhandled_input != NULL)
274 7c7d7bb7 2021-03-10 op current_map->unhandled_input();
275 d2399aef 2021-06-20 op else
276 7c7d7bb7 2021-03-10 op global_key_unbound();
277 7c7d7bb7 2021-03-10 op
278 7c7d7bb7 2021-03-10 op strlcpy(keybuf, "", sizeof(keybuf));
279 9ca15951 2021-03-09 op current_map = base_map;
280 1d08c280 2021-03-06 op
281 1d08c280 2021-03-06 op done:
282 bddc7bbd 2021-04-01 op if (side_window)
283 bddc7bbd 2021-04-01 op recompute_help();
284 bddc7bbd 2021-04-01 op
285 179f0f58 2021-03-11 op redraw_tab(current_tab());
286 a6d450c1 2021-03-06 op }
287 48e9d457 2021-03-06 op
288 a6d450c1 2021-03-06 op static void
289 8a7f2683 2021-07-10 op handle_clear_echoarea(int fd, short ev, void *d)
290 a6d450c1 2021-03-06 op {
291 9cb0f9ce 2021-03-10 op free(ministate.curmesg);
292 9cb0f9ce 2021-03-10 op ministate.curmesg = NULL;
293 9cb0f9ce 2021-03-10 op
294 e9af06b9 2021-07-12 op redraw_minibuffer();
295 9cb0f9ce 2021-03-10 op if (in_minibuffer) {
296 9cb0f9ce 2021-03-10 op wrefresh(body);
297 8a7f2683 2021-07-10 op wrefresh(echoarea);
298 9cb0f9ce 2021-03-10 op } else {
299 8a7f2683 2021-07-10 op wrefresh(echoarea);
300 9cb0f9ce 2021-03-10 op wrefresh(body);
301 9cb0f9ce 2021-03-10 op }
302 5e11c00c 2021-03-02 op }
303 5e11c00c 2021-03-02 op
304 5e11c00c 2021-03-02 op static void
305 5e11c00c 2021-03-02 op handle_resize(int sig, short ev, void *d)
306 831deb20 2021-05-12 op {
307 831deb20 2021-05-12 op if (event_pending(&resizeev, EV_TIMEOUT, NULL)) {
308 831deb20 2021-05-12 op event_del(&resizeev);
309 831deb20 2021-05-12 op }
310 a8a482c8 2021-05-17 op evtimer_set(&resizeev, handle_resize_nodelay, NULL);
311 831deb20 2021-05-12 op evtimer_add(&resizeev, &resize_timer);
312 831deb20 2021-05-12 op }
313 831deb20 2021-05-12 op
314 831deb20 2021-05-12 op static void
315 a8a482c8 2021-05-17 op handle_resize_nodelay(int s, short ev, void *d)
316 5e11c00c 2021-03-02 op {
317 1d08c280 2021-03-06 op struct tab *tab;
318 1d08c280 2021-03-06 op
319 5e11c00c 2021-03-02 op endwin();
320 5e11c00c 2021-03-02 op refresh();
321 5e11c00c 2021-03-02 op clear();
322 5e11c00c 2021-03-02 op
323 48e9d457 2021-03-06 op /* move and resize the windows, in reverse order! */
324 48e9d457 2021-03-06 op
325 8a7f2683 2021-07-10 op mvwin(echoarea, LINES-1, 0);
326 8a7f2683 2021-07-10 op wresize(echoarea, 1, COLS);
327 48e9d457 2021-03-06 op
328 48e9d457 2021-03-06 op mvwin(modeline, LINES-2, 0);
329 48e9d457 2021-03-06 op wresize(modeline, 1, COLS);
330 48e9d457 2021-03-06 op
331 48e9d457 2021-03-06 op body_lines = LINES-3;
332 bd9637e9 2021-03-06 op body_cols = COLS;
333 bddc7bbd 2021-04-01 op
334 bddc7bbd 2021-04-01 op if (side_window) {
335 bddc7bbd 2021-04-01 op help_cols = 0.3 * COLS;
336 bddc7bbd 2021-04-01 op help_lines = LINES-3;
337 bddc7bbd 2021-04-01 op mvwin(help, 1, 0);
338 bddc7bbd 2021-04-01 op wresize(help, help_lines, help_cols);
339 48e9d457 2021-03-06 op
340 bddc7bbd 2021-04-01 op wrap_page(&helpwin, help_cols);
341 bddc7bbd 2021-04-01 op
342 bddc7bbd 2021-04-01 op body_cols = COLS - help_cols - 1;
343 bddc7bbd 2021-04-01 op mvwin(body, 1, help_cols);
344 bddc7bbd 2021-04-01 op } else
345 bddc7bbd 2021-04-01 op mvwin(body, 1, 0);
346 bddc7bbd 2021-04-01 op
347 72b18268 2021-06-19 op update_x_offset();
348 bddc7bbd 2021-04-01 op wresize(body, body_lines, body_cols);
349 bddc7bbd 2021-04-01 op
350 48e9d457 2021-03-06 op wresize(tabline, 1, COLS);
351 48e9d457 2021-03-06 op
352 1d08c280 2021-03-06 op tab = current_tab();
353 1d08c280 2021-03-06 op
354 46f6e974 2021-05-17 op wrap_page(&tab->buffer, body_cols);
355 1d08c280 2021-03-06 op redraw_tab(tab);
356 eb259e66 2021-03-02 op }
357 eb259e66 2021-03-02 op
358 1d08c280 2021-03-06 op static int
359 46f6e974 2021-05-17 op wrap_page(struct buffer *buffer, int width)
360 1d08c280 2021-03-06 op {
361 452589f7 2021-03-16 op struct line *l;
362 2bfa414d 2021-07-01 op const struct line *top_orig, *orig;
363 d511dc85 2021-03-16 op struct vline *vl;
364 72b18268 2021-06-19 op int pre_width;
365 452589f7 2021-03-16 op const char *prfx;
366 452589f7 2021-03-16 op
367 2bfa414d 2021-07-01 op top_orig = buffer->top_line == NULL ? NULL : buffer->top_line->parent;
368 94ec38e8 2021-06-29 op orig = buffer->current_line == NULL ? NULL : buffer->current_line->parent;
369 94ec38e8 2021-06-29 op
370 94ec38e8 2021-06-29 op buffer->top_line = NULL;
371 46f6e974 2021-05-17 op buffer->current_line = NULL;
372 452589f7 2021-03-16 op
373 a00b4c97 2021-06-20 op buffer->force_redraw = 1;
374 46f6e974 2021-05-17 op buffer->curs_y = 0;
375 46f6e974 2021-05-17 op buffer->line_off = 0;
376 1d08c280 2021-03-06 op
377 46f6e974 2021-05-17 op empty_vlist(buffer);
378 1d08c280 2021-03-06 op
379 46f6e974 2021-05-17 op TAILQ_FOREACH(l, &buffer->page.head, lines) {
380 0d568960 2021-03-11 op prfx = line_prefixes[l->type].prfx1;
381 5e11c00c 2021-03-02 op switch (l->type) {
382 5e11c00c 2021-03-02 op case LINE_TEXT:
383 5e11c00c 2021-03-02 op case LINE_LINK:
384 5e11c00c 2021-03-02 op case LINE_TITLE_1:
385 5e11c00c 2021-03-02 op case LINE_TITLE_2:
386 5e11c00c 2021-03-02 op case LINE_TITLE_3:
387 5e11c00c 2021-03-02 op case LINE_ITEM:
388 5e11c00c 2021-03-02 op case LINE_QUOTE:
389 5e11c00c 2021-03-02 op case LINE_PRE_START:
390 5e11c00c 2021-03-02 op case LINE_PRE_END:
391 1a99965e 2021-06-19 op wrap_text(buffer, prfx, l, MIN(fill_column, width));
392 5e11c00c 2021-03-02 op break;
393 5e11c00c 2021-03-02 op case LINE_PRE_CONTENT:
394 72b18268 2021-06-19 op if (olivetti_mode)
395 72b18268 2021-06-19 op pre_width = MIN(fill_column, width);
396 72b18268 2021-06-19 op else
397 72b18268 2021-06-19 op pre_width = width;
398 72b18268 2021-06-19 op hardwrap_text(buffer, l, pre_width);
399 5e11c00c 2021-03-02 op break;
400 452589f7 2021-03-16 op }
401 452589f7 2021-03-16 op
402 2bfa414d 2021-07-01 op if (top_orig == l && buffer->top_line == NULL) {
403 46f6e974 2021-05-17 op buffer->line_off = buffer->line_max-1;
404 2bfa414d 2021-07-01 op buffer->top_line = TAILQ_LAST(&buffer->head, vhead);
405 2bfa414d 2021-07-01 op
406 2bfa414d 2021-07-01 op while (1) {
407 2bfa414d 2021-07-01 op vl = TAILQ_PREV(buffer->top_line, vhead, vlines);
408 2bfa414d 2021-07-01 op if (vl == NULL || vl->parent != orig)
409 2bfa414d 2021-07-01 op break;
410 2bfa414d 2021-07-01 op buffer->top_line = vl;
411 2bfa414d 2021-07-01 op buffer->line_off--;
412 2bfa414d 2021-07-01 op }
413 2bfa414d 2021-07-01 op }
414 2bfa414d 2021-07-01 op
415 2bfa414d 2021-07-01 op if (orig == l && buffer->current_line == NULL) {
416 46f6e974 2021-05-17 op buffer->current_line = TAILQ_LAST(&buffer->head, vhead);
417 d511dc85 2021-03-16 op
418 d511dc85 2021-03-16 op while (1) {
419 46f6e974 2021-05-17 op vl = TAILQ_PREV(buffer->current_line, vhead, vlines);
420 d511dc85 2021-03-16 op if (vl == NULL || vl->parent != orig)
421 d511dc85 2021-03-16 op break;
422 46f6e974 2021-05-17 op buffer->current_line = vl;
423 d511dc85 2021-03-16 op }
424 5e11c00c 2021-03-02 op }
425 5e11c00c 2021-03-02 op }
426 452589f7 2021-03-16 op
427 46f6e974 2021-05-17 op if (buffer->current_line == NULL)
428 46f6e974 2021-05-17 op buffer->current_line = TAILQ_FIRST(&buffer->head);
429 452589f7 2021-03-16 op
430 2bfa414d 2021-07-01 op if (buffer->top_line == NULL)
431 2bfa414d 2021-07-01 op buffer->top_line = buffer->current_line;
432 94ec38e8 2021-06-29 op
433 1d08c280 2021-03-06 op return 1;
434 1d08c280 2021-03-06 op }
435 5e11c00c 2021-03-02 op
436 754622a2 2021-03-15 op static void
437 f3bcf8f2 2021-06-21 op print_vline(int off, int width, WINDOW *window, struct vline *vl)
438 1d08c280 2021-03-06 op {
439 2af29222 2021-06-24 op const char *text;
440 768db5bb 2021-03-12 op const char *prfx;
441 2af29222 2021-06-24 op struct line_face *f;
442 f3bcf8f2 2021-06-21 op int i, left, x, y;
443 bd9637e9 2021-03-06 op
444 2af29222 2021-06-24 op f = &line_faces[vl->parent->type];
445 2af29222 2021-06-24 op
446 d89b86d6 2021-06-21 op /* unused, set by getyx */
447 f3bcf8f2 2021-06-21 op (void)y;
448 f3bcf8f2 2021-06-21 op
449 9a25f829 2021-03-14 op if (!vl->flags)
450 9a25f829 2021-03-14 op prfx = line_prefixes[vl->parent->type].prfx1;
451 768db5bb 2021-03-12 op else
452 9a25f829 2021-03-14 op prfx = line_prefixes[vl->parent->type].prfx2;
453 768db5bb 2021-03-12 op
454 2af29222 2021-06-24 op text = vl->line;
455 bd9637e9 2021-03-06 op if (text == NULL)
456 bd9637e9 2021-03-06 op text = "";
457 bd9637e9 2021-03-06 op
458 ab47e7d4 2021-06-24 op wattr_on(window, body_face.left, NULL);
459 f3bcf8f2 2021-06-21 op for (i = 0; i < off; i++)
460 f3bcf8f2 2021-06-21 op waddch(window, ' ');
461 ab47e7d4 2021-06-24 op wattr_off(window, body_face.left, NULL);
462 ab47e7d4 2021-06-24 op
463 2af29222 2021-06-24 op wattr_on(window, f->prefix, NULL);
464 bddc7bbd 2021-04-01 op wprintw(window, "%s", prfx);
465 2af29222 2021-06-24 op wattr_off(window, f->prefix, NULL);
466 803ff456 2021-03-17 op
467 2af29222 2021-06-24 op wattr_on(window, f->text, NULL);
468 bddc7bbd 2021-04-01 op wprintw(window, "%s", text);
469 2af29222 2021-06-24 op wattr_off(window, f->text, NULL);
470 f3bcf8f2 2021-06-21 op
471 f3bcf8f2 2021-06-21 op getyx(window, y, x);
472 f3bcf8f2 2021-06-21 op
473 f3bcf8f2 2021-06-21 op left = width - x;
474 f3bcf8f2 2021-06-21 op
475 2af29222 2021-06-24 op wattr_on(window, f->trail, NULL);
476 04d32eda 2021-07-08 op for (i = 0; i < left - off; ++i)
477 f3bcf8f2 2021-06-21 op waddch(window, ' ');
478 2af29222 2021-06-24 op wattr_off(window, f->trail, NULL);
479 160abe04 2021-06-21 op
480 ab47e7d4 2021-06-24 op wattr_on(window, body_face.right, NULL);
481 160abe04 2021-06-21 op for (i = 0; i < off; i++)
482 160abe04 2021-06-21 op waddch(window, ' ');
483 ab47e7d4 2021-06-24 op wattr_off(window, body_face.right, NULL);
484 f3bcf8f2 2021-06-21 op
485 1d08c280 2021-03-06 op }
486 1d08c280 2021-03-06 op
487 1d08c280 2021-03-06 op static void
488 8af5e5ed 2021-03-08 op redraw_tabline(void)
489 8af5e5ed 2021-03-08 op {
490 7c7d7bb7 2021-03-10 op struct tab *tab;
491 8f127baa 2021-04-22 op size_t toskip, ots, tabwidth, space, x;
492 8f127baa 2021-04-22 op int current, y, truncated;
493 dc5df781 2021-03-13 op const char *title;
494 119f393c 2021-03-16 op char buf[25];
495 7c7d7bb7 2021-03-10 op
496 923f9ce5 2021-06-21 op x = 0;
497 923f9ce5 2021-06-21 op
498 923f9ce5 2021-06-21 op /* unused, but setted by a getyx */
499 923f9ce5 2021-06-21 op (void)y;
500 923f9ce5 2021-06-21 op
501 8f127baa 2021-04-22 op tabwidth = sizeof(buf)+1;
502 8f127baa 2021-04-22 op space = COLS-2;
503 8f127baa 2021-04-22 op
504 a636f50e 2021-03-16 op toskip = 0;
505 a636f50e 2021-03-16 op TAILQ_FOREACH(tab, &tabshead, tabs) {
506 a636f50e 2021-03-16 op toskip++;
507 a636f50e 2021-03-16 op if (tab->flags & TAB_CURRENT)
508 a636f50e 2021-03-16 op break;
509 a636f50e 2021-03-16 op }
510 8f127baa 2021-04-22 op
511 8f127baa 2021-04-22 op if (toskip * tabwidth < space)
512 8f127baa 2021-04-22 op toskip = 0;
513 8f127baa 2021-04-22 op else {
514 8f127baa 2021-04-22 op ots = toskip;
515 a636f50e 2021-03-16 op toskip--;
516 8f127baa 2021-04-22 op while (toskip != 0 &&
517 8f127baa 2021-04-22 op (ots - toskip+1) * tabwidth < space)
518 8f127baa 2021-04-22 op toskip--;
519 8f127baa 2021-04-22 op }
520 7c7d7bb7 2021-03-10 op
521 a636f50e 2021-03-16 op werase(tabline);
522 ab47e7d4 2021-06-24 op wattr_on(tabline, tab_face.background, NULL);
523 a636f50e 2021-03-16 op wprintw(tabline, toskip == 0 ? " " : "<");
524 ab47e7d4 2021-06-24 op wattr_off(tabline, tab_face.background, NULL);
525 a636f50e 2021-03-16 op
526 a636f50e 2021-03-16 op truncated = 0;
527 7c7d7bb7 2021-03-10 op TAILQ_FOREACH(tab, &tabshead, tabs) {
528 a636f50e 2021-03-16 op if (truncated)
529 a636f50e 2021-03-16 op break;
530 a636f50e 2021-03-16 op if (toskip != 0) {
531 a636f50e 2021-03-16 op toskip--;
532 a636f50e 2021-03-16 op continue;
533 a636f50e 2021-03-16 op }
534 a636f50e 2021-03-16 op
535 a636f50e 2021-03-16 op getyx(tabline, y, x);
536 a636f50e 2021-03-16 op if (x + sizeof(buf)+2 >= (size_t)COLS)
537 a636f50e 2021-03-16 op truncated = 1;
538 a636f50e 2021-03-16 op
539 7c7d7bb7 2021-03-10 op current = tab->flags & TAB_CURRENT;
540 a329982b 2021-03-11 op
541 46f6e974 2021-05-17 op if (*(title = tab->buffer.page.title) == '\0')
542 2051e653 2021-03-13 op title = tab->hist_cur->h;
543 dc5df781 2021-03-13 op
544 e8a76665 2021-05-12 op if (tab->flags & TAB_URGENT)
545 e8a76665 2021-05-12 op strlcpy(buf, "!", sizeof(buf));
546 e8a76665 2021-05-12 op else
547 e8a76665 2021-05-12 op strlcpy(buf, " ", sizeof(buf));
548 e8a76665 2021-05-12 op
549 119f393c 2021-03-16 op if (strlcat(buf, title, sizeof(buf)) >= sizeof(buf)) {
550 119f393c 2021-03-16 op /* truncation happens */
551 119f393c 2021-03-16 op strlcpy(&buf[sizeof(buf)-4], "...", 4);
552 119f393c 2021-03-16 op } else {
553 119f393c 2021-03-16 op /* pad with spaces */
554 119f393c 2021-03-16 op while (strlcat(buf, " ", sizeof(buf)) < sizeof(buf))
555 119f393c 2021-03-16 op /* nop */ ;
556 119f393c 2021-03-16 op }
557 a329982b 2021-03-11 op
558 a329982b 2021-03-11 op if (current)
559 ab47e7d4 2021-06-24 op wattr_on(tabline, tab_face.current, NULL);
560 cb6c7aa0 2021-03-16 op else
561 ab47e7d4 2021-06-24 op wattr_on(tabline, tab_face.tab, NULL);
562 119f393c 2021-03-16 op
563 119f393c 2021-03-16 op wprintw(tabline, "%s", buf);
564 119f393c 2021-03-16 op if (TAILQ_NEXT(tab, tabs) != NULL)
565 119f393c 2021-03-16 op wprintw(tabline, " ");
566 cb6c7aa0 2021-03-16 op
567 cb6c7aa0 2021-03-16 op if (current)
568 ab47e7d4 2021-06-24 op wattr_off(tabline, tab_face.current, NULL);
569 cb6c7aa0 2021-03-16 op else
570 ab47e7d4 2021-06-24 op wattr_off(tabline, tab_face.tab, NULL);
571 7c7d7bb7 2021-03-10 op }
572 119f393c 2021-03-16 op
573 ab47e7d4 2021-06-24 op wattr_on(tabline, tab_face.background, NULL);
574 8f127baa 2021-04-22 op for (; x < (size_t)COLS; ++x)
575 119f393c 2021-03-16 op waddch(tabline, ' ');
576 a636f50e 2021-03-16 op if (truncated)
577 a636f50e 2021-03-16 op mvwprintw(tabline, 0, COLS-1, ">");
578 ab47e7d4 2021-06-24 op wattr_off(tabline, tab_face.background, NULL);
579 10346511 2021-03-17 op }
580 77dd24f4 2021-07-05 op
581 77dd24f4 2021-07-05 op /*
582 77dd24f4 2021-07-05 op * Compute the first visible line around vl. Try to search forward
583 77dd24f4 2021-07-05 op * until the end of the buffer; if a visible line is not found, search
584 77dd24f4 2021-07-05 op * backward. Return NULL if no viable line was found.
585 77dd24f4 2021-07-05 op */
586 77dd24f4 2021-07-05 op static inline struct vline *
587 77dd24f4 2021-07-05 op adjust_line(struct vline *vl, struct buffer *buffer)
588 77dd24f4 2021-07-05 op {
589 77dd24f4 2021-07-05 op struct vline *t;
590 10346511 2021-03-17 op
591 77dd24f4 2021-07-05 op if (!(vl->parent->flags & L_HIDDEN))
592 77dd24f4 2021-07-05 op return vl;
593 77dd24f4 2021-07-05 op
594 77dd24f4 2021-07-05 op /* search forward */
595 77dd24f4 2021-07-05 op for (t = vl;
596 77dd24f4 2021-07-05 op t != NULL && t->parent->flags & L_HIDDEN;
597 77dd24f4 2021-07-05 op t = TAILQ_NEXT(t, vlines))
598 77dd24f4 2021-07-05 op ; /* nop */
599 77dd24f4 2021-07-05 op
600 77dd24f4 2021-07-05 op if (t != NULL)
601 77dd24f4 2021-07-05 op return t;
602 77dd24f4 2021-07-05 op
603 77dd24f4 2021-07-05 op /* search backward */
604 77dd24f4 2021-07-05 op for (t = vl;
605 77dd24f4 2021-07-05 op t != NULL && t->parent->flags & L_HIDDEN;
606 77dd24f4 2021-07-05 op t = TAILQ_PREV(t, vhead, vlines))
607 77dd24f4 2021-07-05 op ; /* nop */
608 77dd24f4 2021-07-05 op
609 77dd24f4 2021-07-05 op return t;
610 77dd24f4 2021-07-05 op }
611 77dd24f4 2021-07-05 op
612 bddc7bbd 2021-04-01 op static void
613 f3bcf8f2 2021-06-21 op redraw_window(WINDOW *win, int height, int width, struct buffer *buffer)
614 bddc7bbd 2021-04-01 op {
615 2bfa414d 2021-07-01 op struct vline *vl;
616 2bfa414d 2021-07-01 op int l, onscreen;
617 13e8b82f 2021-07-01 op
618 0a805b02 2021-07-01 op restore_curs_x(buffer);
619 a00b4c97 2021-06-20 op
620 a00b4c97 2021-06-20 op /*
621 0a805b02 2021-07-01 op * TODO: ignoring buffer->force_update and always
622 0a805b02 2021-07-01 op * re-rendering. In theory we can recompute the y position
623 0a805b02 2021-07-01 op * without a re-render, and optimize here. It's not the only
624 0a805b02 2021-07-01 op * optimisation possible here, wscrl wolud also be an
625 0a805b02 2021-07-01 op * interesting one.
626 a00b4c97 2021-06-20 op */
627 bddc7bbd 2021-04-01 op
628 2bfa414d 2021-07-01 op again:
629 bddc7bbd 2021-04-01 op werase(win);
630 2bfa414d 2021-07-01 op buffer->curs_y = 0;
631 a00b4c97 2021-06-20 op
632 46f6e974 2021-05-17 op if (TAILQ_EMPTY(&buffer->head))
633 77dd24f4 2021-07-05 op goto end;
634 77dd24f4 2021-07-05 op
635 77dd24f4 2021-07-05 op buffer->top_line = adjust_line(buffer->top_line, buffer);
636 77dd24f4 2021-07-05 op if (buffer->top_line == NULL)
637 a00b4c97 2021-06-20 op goto end;
638 bddc7bbd 2021-04-01 op
639 77dd24f4 2021-07-05 op buffer->current_line = adjust_line(buffer->current_line, buffer);
640 77dd24f4 2021-07-05 op
641 bddc7bbd 2021-04-01 op l = 0;
642 2bfa414d 2021-07-01 op onscreen = 0;
643 94ec38e8 2021-06-29 op for (vl = buffer->top_line; vl != NULL; vl = TAILQ_NEXT(vl, vlines)) {
644 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
645 963c680c 2021-07-05 op continue;
646 963c680c 2021-07-05 op
647 f3bcf8f2 2021-06-21 op wmove(win, l, 0);
648 f3bcf8f2 2021-06-21 op print_vline(x_offset, width, win, vl);
649 2bfa414d 2021-07-01 op
650 2bfa414d 2021-07-01 op if (vl == buffer->current_line)
651 2bfa414d 2021-07-01 op onscreen = 1;
652 2bfa414d 2021-07-01 op
653 2bfa414d 2021-07-01 op if (!onscreen)
654 2bfa414d 2021-07-01 op buffer->curs_y++;
655 2bfa414d 2021-07-01 op
656 bddc7bbd 2021-04-01 op l++;
657 bddc7bbd 2021-04-01 op if (l == height)
658 bddc7bbd 2021-04-01 op break;
659 2bfa414d 2021-07-01 op }
660 2bfa414d 2021-07-01 op
661 2bfa414d 2021-07-01 op if (!onscreen) {
662 2bfa414d 2021-07-01 op for (; vl != NULL; vl = TAILQ_NEXT(vl, vlines)) {
663 2bfa414d 2021-07-01 op if (vl == buffer->current_line)
664 2bfa414d 2021-07-01 op break;
665 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
666 963c680c 2021-07-05 op continue;
667 2bfa414d 2021-07-01 op buffer->line_off++;
668 2bfa414d 2021-07-01 op buffer->top_line = TAILQ_NEXT(buffer->top_line, vlines);
669 2bfa414d 2021-07-01 op }
670 2bfa414d 2021-07-01 op
671 2bfa414d 2021-07-01 op goto again;
672 bddc7bbd 2021-04-01 op }
673 bddc7bbd 2021-04-01 op
674 2bfa414d 2021-07-01 op buffer->last_line_off = buffer->line_off;
675 2bfa414d 2021-07-01 op buffer->force_redraw = 0;
676 a00b4c97 2021-06-20 op end:
677 46f6e974 2021-05-17 op wmove(win, buffer->curs_y, buffer->curs_x);
678 bddc7bbd 2021-04-01 op }
679 bddc7bbd 2021-04-01 op
680 bddc7bbd 2021-04-01 op static void
681 bddc7bbd 2021-04-01 op redraw_help(void)
682 bddc7bbd 2021-04-01 op {
683 f3bcf8f2 2021-06-21 op redraw_window(help, help_lines, help_cols, &helpwin);
684 bddc7bbd 2021-04-01 op }
685 bddc7bbd 2021-04-01 op
686 bddc7bbd 2021-04-01 op static void
687 bddc7bbd 2021-04-01 op redraw_body(struct tab *tab)
688 bddc7bbd 2021-04-01 op {
689 3323faaf 2021-06-21 op static struct tab *last_tab;
690 3323faaf 2021-06-21 op
691 3323faaf 2021-06-21 op if (last_tab != tab)
692 3323faaf 2021-06-21 op tab->buffer.force_redraw =1;
693 3323faaf 2021-06-21 op last_tab = tab;
694 3323faaf 2021-06-21 op
695 f3bcf8f2 2021-06-21 op redraw_window(body, body_lines, body_cols, &tab->buffer);
696 bddc7bbd 2021-04-01 op }
697 bddc7bbd 2021-04-01 op
698 10346511 2021-03-17 op static inline char
699 10346511 2021-03-17 op trust_status_char(enum trust_state ts)
700 10346511 2021-03-17 op {
701 10346511 2021-03-17 op switch (ts) {
702 10346511 2021-03-17 op case TS_UNKNOWN: return 'u';
703 10346511 2021-03-17 op case TS_UNTRUSTED: return '!';
704 a2fd3805 2021-07-06 op case TS_TEMP_TRUSTED: return '!';
705 10346511 2021-03-17 op case TS_TRUSTED: return 'v';
706 10346511 2021-03-17 op case TS_VERIFIED: return 'V';
707 923f9ce5 2021-06-21 op default: return 'X';
708 10346511 2021-03-17 op }
709 8af5e5ed 2021-03-08 op }
710 8af5e5ed 2021-03-08 op
711 8af5e5ed 2021-03-08 op static void
712 48e9d457 2021-03-06 op redraw_modeline(struct tab *tab)
713 1d08c280 2021-03-06 op {
714 481340cc 2021-03-11 op double pct;
715 48e9d457 2021-03-06 op int x, y, max_x, max_y;
716 46f6e974 2021-05-17 op const char *mode = tab->buffer.page.name;
717 8af5e5ed 2021-03-08 op const char *spin = "-\\|/";
718 1d08c280 2021-03-06 op
719 156f1501 2021-03-13 op werase(modeline);
720 ab47e7d4 2021-06-24 op wattr_on(modeline, modeline_face.background, NULL);
721 48e9d457 2021-03-06 op wmove(modeline, 0, 0);
722 1d08c280 2021-03-06 op
723 10346511 2021-03-17 op wprintw(modeline, "-%c%c %s ",
724 2ba66cea 2021-03-22 op spin[tab->loading_anim_step],
725 10346511 2021-03-17 op trust_status_char(tab->trust),
726 58c75fab 2021-03-16 op mode == NULL ? "(none)" : mode);
727 481340cc 2021-03-11 op
728 46f6e974 2021-05-17 op pct = (tab->buffer.line_off + tab->buffer.curs_y) * 100.0 / tab->buffer.line_max;
729 481340cc 2021-03-11 op
730 46f6e974 2021-05-17 op if (tab->buffer.line_max <= (size_t)body_lines)
731 481340cc 2021-03-11 op wprintw(modeline, "All ");
732 46f6e974 2021-05-17 op else if (tab->buffer.line_off == 0)
733 481340cc 2021-03-11 op wprintw(modeline, "Top ");
734 46f6e974 2021-05-17 op else if (tab->buffer.line_off + body_lines >= tab->buffer.line_max)
735 481340cc 2021-03-11 op wprintw(modeline, "Bottom ");
736 481340cc 2021-03-11 op else
737 481340cc 2021-03-11 op wprintw(modeline, "%.0f%% ", pct);
738 481340cc 2021-03-11 op
739 481340cc 2021-03-11 op wprintw(modeline, "%d/%d %s ",
740 46f6e974 2021-05-17 op tab->buffer.line_off + tab->buffer.curs_y,
741 46f6e974 2021-05-17 op tab->buffer.line_max,
742 2051e653 2021-03-13 op tab->hist_cur->h);
743 481340cc 2021-03-11 op
744 48e9d457 2021-03-06 op getyx(modeline, y, x);
745 48e9d457 2021-03-06 op getmaxyx(modeline, max_y, max_x);
746 48e9d457 2021-03-06 op
747 48e9d457 2021-03-06 op (void)y;
748 48e9d457 2021-03-06 op (void)max_y;
749 48e9d457 2021-03-06 op
750 48e9d457 2021-03-06 op for (; x < max_x; ++x)
751 48e9d457 2021-03-06 op waddstr(modeline, "-");
752 d5493194 2021-06-15 op
753 ab47e7d4 2021-06-24 op wattr_off(modeline, modeline_face.background, NULL);
754 9ca15951 2021-03-09 op }
755 9ca15951 2021-03-09 op
756 9ca15951 2021-03-09 op static void
757 e9af06b9 2021-07-12 op redraw_minibuffer(void)
758 9ca15951 2021-03-09 op {
759 8a7f2683 2021-07-10 op wattr_on(echoarea, minibuffer_face.background, NULL);
760 8a7f2683 2021-07-10 op werase(echoarea);
761 17e5106b 2021-03-21 op
762 e9af06b9 2021-07-12 op if (in_minibuffer)
763 e9af06b9 2021-07-12 op do_redraw_minibuffer();
764 e9af06b9 2021-07-12 op else
765 e9af06b9 2021-07-12 op do_redraw_echoarea();
766 9cb0f9ce 2021-03-10 op
767 e9af06b9 2021-07-12 op wattr_off(echoarea, minibuffer_face.background, NULL);
768 e9af06b9 2021-07-12 op }
769 9cb0f9ce 2021-03-10 op
770 e9af06b9 2021-07-12 op static void
771 e9af06b9 2021-07-12 op do_redraw_echoarea(void)
772 e9af06b9 2021-07-12 op {
773 e9af06b9 2021-07-12 op struct tab *tab;
774 9cb0f9ce 2021-03-10 op
775 17e5106b 2021-03-21 op if (ministate.curmesg != NULL)
776 e9af06b9 2021-07-12 op wprintw(echoarea, "%s", ministate.curmesg);
777 e9af06b9 2021-07-12 op else if (*keybuf != '\0')
778 8a7f2683 2021-07-10 op waddstr(echoarea, keybuf);
779 e9af06b9 2021-07-12 op else {
780 e9af06b9 2021-07-12 op /* If nothing else, show the URL at point */
781 8300dd3c 2021-03-18 op tab = current_tab();
782 46f6e974 2021-05-17 op if (tab->buffer.current_line != NULL &&
783 46f6e974 2021-05-17 op tab->buffer.current_line->parent->type == LINE_LINK)
784 8a7f2683 2021-07-10 op waddstr(echoarea, tab->buffer.current_line->parent->alt);
785 8300dd3c 2021-03-18 op }
786 e9af06b9 2021-07-12 op }
787 91a72220 2021-03-13 op
788 e9af06b9 2021-07-12 op static void
789 e9af06b9 2021-07-12 op do_redraw_minibuffer(void)
790 e9af06b9 2021-07-12 op {
791 e9af06b9 2021-07-12 op size_t off_y, off_x = 0;
792 e9af06b9 2021-07-12 op const char *start, *c;
793 d5493194 2021-06-15 op
794 e9af06b9 2021-07-12 op /* unused, set by getyx */
795 e9af06b9 2021-07-12 op (void)off_y;
796 e9af06b9 2021-07-12 op
797 e9af06b9 2021-07-12 op mvwprintw(echoarea, 0, 0, "%s", ministate.prompt);
798 e9af06b9 2021-07-12 op if (ministate.hist_cur != NULL)
799 e9af06b9 2021-07-12 op wprintw(echoarea, "(%zu/%zu) ",
800 e9af06b9 2021-07-12 op ministate.hist_off + 1,
801 e9af06b9 2021-07-12 op ministate.history->len);
802 e9af06b9 2021-07-12 op
803 e9af06b9 2021-07-12 op getyx(echoarea, off_y, off_x);
804 e9af06b9 2021-07-12 op
805 e9af06b9 2021-07-12 op start = ministate.hist_cur != NULL
806 e9af06b9 2021-07-12 op ? ministate.hist_cur->h
807 e9af06b9 2021-07-12 op : ministate.buf;
808 e9af06b9 2021-07-12 op c = utf8_nth(ministate.buffer.current_line->line,
809 e9af06b9 2021-07-12 op ministate.buffer.cpoff);
810 e9af06b9 2021-07-12 op while (utf8_swidth_between(start, c) > (size_t)COLS/2) {
811 e9af06b9 2021-07-12 op start = utf8_next_cp(start);
812 e9af06b9 2021-07-12 op }
813 e9af06b9 2021-07-12 op
814 e9af06b9 2021-07-12 op waddstr(echoarea, start);
815 e9af06b9 2021-07-12 op
816 e9af06b9 2021-07-12 op if (ministate.curmesg != NULL)
817 e9af06b9 2021-07-12 op wprintw(echoarea, " [%s]", ministate.curmesg);
818 e9af06b9 2021-07-12 op
819 e9af06b9 2021-07-12 op wmove(echoarea, 0, off_x + utf8_swidth_between(start, c));
820 48e9d457 2021-03-06 op }
821 48e9d457 2021-03-06 op
822 48e9d457 2021-03-06 op static void
823 48e9d457 2021-03-06 op redraw_tab(struct tab *tab)
824 48e9d457 2021-03-06 op {
825 bddc7bbd 2021-04-01 op if (side_window) {
826 bddc7bbd 2021-04-01 op redraw_help();
827 bddc7bbd 2021-04-01 op wnoutrefresh(help);
828 bddc7bbd 2021-04-01 op }
829 bddc7bbd 2021-04-01 op
830 e19f9a04 2021-03-11 op redraw_tabline();
831 e19f9a04 2021-03-11 op redraw_body(tab);
832 e19f9a04 2021-03-11 op redraw_modeline(tab);
833 e9af06b9 2021-07-12 op redraw_minibuffer();
834 e19f9a04 2021-03-11 op
835 bddc7bbd 2021-04-01 op wnoutrefresh(tabline);
836 bddc7bbd 2021-04-01 op wnoutrefresh(modeline);
837 e19f9a04 2021-03-11 op
838 e19f9a04 2021-03-11 op if (in_minibuffer) {
839 bddc7bbd 2021-04-01 op wnoutrefresh(body);
840 8a7f2683 2021-07-10 op wnoutrefresh(echoarea);
841 e19f9a04 2021-03-11 op } else {
842 8a7f2683 2021-07-10 op wnoutrefresh(echoarea);
843 bddc7bbd 2021-04-01 op wnoutrefresh(body);
844 e19f9a04 2021-03-11 op }
845 bddc7bbd 2021-04-01 op
846 bddc7bbd 2021-04-01 op doupdate();
847 e19f9a04 2021-03-11 op }
848 e19f9a04 2021-03-11 op
849 e19f9a04 2021-03-11 op static void
850 bddc7bbd 2021-04-01 op emit_help_item(char *prfx, void *fn)
851 e19f9a04 2021-03-11 op {
852 bddc7bbd 2021-04-01 op struct line *l;
853 a3666ed5 2021-06-25 op struct cmd *cmd;
854 48e9d457 2021-03-06 op
855 bddc7bbd 2021-04-01 op for (cmd = cmds; cmd->cmd != NULL; ++cmd) {
856 bddc7bbd 2021-04-01 op if (fn == cmd->fn)
857 bddc7bbd 2021-04-01 op break;
858 bddc7bbd 2021-04-01 op }
859 bddc7bbd 2021-04-01 op assert(cmd != NULL);
860 48e9d457 2021-03-06 op
861 bddc7bbd 2021-04-01 op if ((l = calloc(1, sizeof(*l))) == NULL)
862 bddc7bbd 2021-04-01 op abort();
863 48e9d457 2021-03-06 op
864 bddc7bbd 2021-04-01 op l->type = LINE_TEXT;
865 bddc7bbd 2021-04-01 op l->alt = NULL;
866 bddc7bbd 2021-04-01 op
867 bddc7bbd 2021-04-01 op asprintf(&l->line, "%s %s", prfx, cmd->cmd);
868 bddc7bbd 2021-04-01 op
869 bddc7bbd 2021-04-01 op if (TAILQ_EMPTY(&helpwin.page.head))
870 bddc7bbd 2021-04-01 op TAILQ_INSERT_HEAD(&helpwin.page.head, l, lines);
871 bddc7bbd 2021-04-01 op else
872 bddc7bbd 2021-04-01 op TAILQ_INSERT_TAIL(&helpwin.page.head, l, lines);
873 bddc7bbd 2021-04-01 op }
874 bddc7bbd 2021-04-01 op
875 bddc7bbd 2021-04-01 op static void
876 bddc7bbd 2021-04-01 op rec_compute_help(struct kmap *keymap, char *prfx, size_t len)
877 bddc7bbd 2021-04-01 op {
878 bddc7bbd 2021-04-01 op struct keymap *k;
879 bddc7bbd 2021-04-01 op char p[32];
880 bddc7bbd 2021-04-01 op const char *kn;
881 bddc7bbd 2021-04-01 op
882 bddc7bbd 2021-04-01 op TAILQ_FOREACH(k, &keymap->m, keymaps) {
883 bddc7bbd 2021-04-01 op strlcpy(p, prfx, sizeof(p));
884 bddc7bbd 2021-04-01 op if (*p != '\0')
885 bddc7bbd 2021-04-01 op strlcat(p, " ", sizeof(p));
886 bddc7bbd 2021-04-01 op if (k->meta)
887 bddc7bbd 2021-04-01 op strlcat(p, "M-", sizeof(p));
888 bddc7bbd 2021-04-01 op if ((kn = unkbd(k->key)) != NULL)
889 bddc7bbd 2021-04-01 op strlcat(p, kn, sizeof(p));
890 bddc7bbd 2021-04-01 op else
891 bddc7bbd 2021-04-01 op strlcat(p, keyname(k->key), sizeof(p));
892 bddc7bbd 2021-04-01 op
893 bddc7bbd 2021-04-01 op if (k->fn == NULL)
894 bddc7bbd 2021-04-01 op rec_compute_help(&k->map, p, sizeof(p));
895 bddc7bbd 2021-04-01 op else
896 bddc7bbd 2021-04-01 op emit_help_item(p, k->fn);
897 9ca15951 2021-03-09 op }
898 bddc7bbd 2021-04-01 op }
899 174b3cdf 2021-03-21 op
900 bddc7bbd 2021-04-01 op static void
901 bddc7bbd 2021-04-01 op recompute_help(void)
902 bddc7bbd 2021-04-01 op {
903 bddc7bbd 2021-04-01 op char p[32] = { 0 };
904 bddc7bbd 2021-04-01 op
905 bddc7bbd 2021-04-01 op empty_vlist(&helpwin);
906 bddc7bbd 2021-04-01 op empty_linelist(&helpwin);
907 bddc7bbd 2021-04-01 op rec_compute_help(current_map, p, sizeof(p));
908 bddc7bbd 2021-04-01 op wrap_page(&helpwin, help_cols);
909 7953dd72 2021-03-07 op }
910 7953dd72 2021-03-07 op
911 7f963c41 2021-06-20 op void
912 740f578b 2021-03-15 op vmessage(const char *fmt, va_list ap)
913 7953dd72 2021-03-07 op {
914 8a7f2683 2021-07-10 op if (evtimer_pending(&clechoev, NULL))
915 8a7f2683 2021-07-10 op evtimer_del(&clechoev);
916 bf992581 2021-03-12 op
917 bf992581 2021-03-12 op free(ministate.curmesg);
918 2b2d2872 2021-06-20 op ministate.curmesg = NULL;
919 7953dd72 2021-03-07 op
920 2b2d2872 2021-06-20 op if (fmt != NULL) {
921 8a7f2683 2021-07-10 op evtimer_set(&clechoev, handle_clear_echoarea, NULL);
922 8a7f2683 2021-07-10 op evtimer_add(&clechoev, &clechoev_timer);
923 9cb0f9ce 2021-03-10 op
924 2b2d2872 2021-06-20 op /* TODO: what to do if the allocation fails here? */
925 2b2d2872 2021-06-20 op if (vasprintf(&ministate.curmesg, fmt, ap) == -1)
926 2b2d2872 2021-06-20 op ministate.curmesg = NULL;
927 2b2d2872 2021-06-20 op }
928 2b2d2872 2021-06-20 op
929 e9af06b9 2021-07-12 op redraw_minibuffer();
930 9cb0f9ce 2021-03-10 op if (in_minibuffer) {
931 9cb0f9ce 2021-03-10 op wrefresh(body);
932 8a7f2683 2021-07-10 op wrefresh(echoarea);
933 9cb0f9ce 2021-03-10 op } else {
934 8a7f2683 2021-07-10 op wrefresh(echoarea);
935 9cb0f9ce 2021-03-10 op wrefresh(body);
936 9cb0f9ce 2021-03-10 op }
937 bcb0b073 2021-03-07 op }
938 bcb0b073 2021-03-07 op
939 7f963c41 2021-06-20 op void
940 740f578b 2021-03-15 op message(const char *fmt, ...)
941 740f578b 2021-03-15 op {
942 740f578b 2021-03-15 op va_list ap;
943 740f578b 2021-03-15 op
944 740f578b 2021-03-15 op va_start(ap, fmt);
945 740f578b 2021-03-15 op vmessage(fmt, ap);
946 740f578b 2021-03-15 op va_end(ap);
947 740f578b 2021-03-15 op }
948 740f578b 2021-03-15 op
949 2b2d2872 2021-06-20 op void
950 8af5e5ed 2021-03-08 op start_loading_anim(struct tab *tab)
951 8af5e5ed 2021-03-08 op {
952 2ba66cea 2021-03-22 op if (tab->loading_anim)
953 8af5e5ed 2021-03-08 op return;
954 2ba66cea 2021-03-22 op tab->loading_anim = 1;
955 2ba66cea 2021-03-22 op evtimer_set(&tab->loadingev, update_loading_anim, tab);
956 2ba66cea 2021-03-22 op evtimer_add(&tab->loadingev, &loadingev_timer);
957 8af5e5ed 2021-03-08 op }
958 8af5e5ed 2021-03-08 op
959 8af5e5ed 2021-03-08 op static void
960 8af5e5ed 2021-03-08 op update_loading_anim(int fd, short ev, void *d)
961 8af5e5ed 2021-03-08 op {
962 8af5e5ed 2021-03-08 op struct tab *tab = d;
963 8af5e5ed 2021-03-08 op
964 2ba66cea 2021-03-22 op tab->loading_anim_step = (tab->loading_anim_step+1)%4;
965 9ca15951 2021-03-09 op
966 6347dcd0 2021-03-16 op if (tab->flags & TAB_CURRENT) {
967 6347dcd0 2021-03-16 op redraw_modeline(tab);
968 6347dcd0 2021-03-16 op wrefresh(modeline);
969 6347dcd0 2021-03-16 op wrefresh(body);
970 6347dcd0 2021-03-16 op if (in_minibuffer)
971 8a7f2683 2021-07-10 op wrefresh(echoarea);
972 6347dcd0 2021-03-16 op }
973 8af5e5ed 2021-03-08 op
974 2ba66cea 2021-03-22 op evtimer_add(&tab->loadingev, &loadingev_timer);
975 8af5e5ed 2021-03-08 op }
976 8af5e5ed 2021-03-08 op
977 8af5e5ed 2021-03-08 op static void
978 8af5e5ed 2021-03-08 op stop_loading_anim(struct tab *tab)
979 8af5e5ed 2021-03-08 op {
980 2ba66cea 2021-03-22 op if (!tab->loading_anim)
981 8af5e5ed 2021-03-08 op return;
982 2ba66cea 2021-03-22 op evtimer_del(&tab->loadingev);
983 2ba66cea 2021-03-22 op tab->loading_anim = 0;
984 2ba66cea 2021-03-22 op tab->loading_anim_step = 0;
985 3d8c2326 2021-03-18 op
986 3d8c2326 2021-03-18 op if (!(tab->flags & TAB_CURRENT))
987 3d8c2326 2021-03-18 op return;
988 43a1b8d0 2021-03-09 op
989 43a1b8d0 2021-03-09 op redraw_modeline(tab);
990 9ca15951 2021-03-09 op
991 43a1b8d0 2021-03-09 op wrefresh(modeline);
992 43a1b8d0 2021-03-09 op wrefresh(body);
993 9ca15951 2021-03-09 op if (in_minibuffer)
994 8a7f2683 2021-07-10 op wrefresh(echoarea);
995 8af5e5ed 2021-03-08 op }
996 8af5e5ed 2021-03-08 op
997 2b2d2872 2021-06-20 op void
998 43a1b8d0 2021-03-09 op load_url_in_tab(struct tab *tab, const char *url)
999 8af5e5ed 2021-03-08 op {
1000 8af5e5ed 2021-03-08 op message("Loading %s...", url);
1001 8af5e5ed 2021-03-08 op start_loading_anim(tab);
1002 8af5e5ed 2021-03-08 op load_url(tab, url);
1003 43a1b8d0 2021-03-09 op
1004 46f6e974 2021-05-17 op tab->buffer.curs_x = 0;
1005 46f6e974 2021-05-17 op tab->buffer.curs_y = 0;
1006 43a1b8d0 2021-03-09 op redraw_tab(tab);
1007 9ca15951 2021-03-09 op }
1008 9ca15951 2021-03-09 op
1009 2b2d2872 2021-06-20 op void
1010 5cd2ebb1 2021-03-11 op switch_to_tab(struct tab *tab)
1011 5cd2ebb1 2021-03-11 op {
1012 5cd2ebb1 2021-03-11 op struct tab *t;
1013 5cd2ebb1 2021-03-11 op
1014 5cd2ebb1 2021-03-11 op TAILQ_FOREACH(t, &tabshead, tabs) {
1015 5cd2ebb1 2021-03-11 op t->flags &= ~TAB_CURRENT;
1016 5cd2ebb1 2021-03-11 op }
1017 5cd2ebb1 2021-03-11 op
1018 5cd2ebb1 2021-03-11 op tab->flags |= TAB_CURRENT;
1019 cf25a90f 2021-06-11 op tab->flags &= ~TAB_URGENT;
1020 2eef3403 2021-04-22 op }
1021 2eef3403 2021-04-22 op
1022 2eef3403 2021-04-22 op unsigned int
1023 2eef3403 2021-04-22 op tab_new_id(void)
1024 2eef3403 2021-04-22 op {
1025 2eef3403 2021-04-22 op return tab_counter++;
1026 5cd2ebb1 2021-03-11 op }
1027 5cd2ebb1 2021-03-11 op
1028 2b2d2872 2021-06-20 op struct tab *
1029 1b81bc33 2021-03-15 op new_tab(const char *url)
1030 bcb0b073 2021-03-07 op {
1031 754622a2 2021-03-15 op struct tab *tab;
1032 bcb0b073 2021-03-07 op
1033 71105afa 2021-03-16 op if ((tab = calloc(1, sizeof(*tab))) == NULL) {
1034 71105afa 2021-03-16 op event_loopbreak();
1035 71105afa 2021-03-16 op return NULL;
1036 71105afa 2021-03-16 op }
1037 de2a69bb 2021-05-17 op tab->fd = -1;
1038 bcb0b073 2021-03-07 op
1039 2051e653 2021-03-13 op TAILQ_INIT(&tab->hist.head);
1040 2051e653 2021-03-13 op
1041 46f6e974 2021-05-17 op TAILQ_INIT(&tab->buffer.head);
1042 bcb0b073 2021-03-07 op
1043 2eef3403 2021-04-22 op tab->id = tab_new_id();
1044 5cd2ebb1 2021-03-11 op switch_to_tab(tab);
1045 bcb0b073 2021-03-07 op
1046 bcb0b073 2021-03-07 op if (TAILQ_EMPTY(&tabshead))
1047 bcb0b073 2021-03-07 op TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
1048 bcb0b073 2021-03-07 op else
1049 bcb0b073 2021-03-07 op TAILQ_INSERT_TAIL(&tabshead, tab, tabs);
1050 bcb0b073 2021-03-07 op
1051 43a1b8d0 2021-03-09 op load_url_in_tab(tab, url);
1052 b1df9b71 2021-03-12 op return tab;
1053 5e11c00c 2021-03-02 op }
1054 5e11c00c 2021-03-02 op
1055 941b3761 2021-03-18 op int
1056 d2544989 2021-07-08 op ui_init()
1057 941b3761 2021-03-18 op {
1058 5e11c00c 2021-03-02 op setlocale(LC_ALL, "");
1059 5e11c00c 2021-03-02 op
1060 22268e11 2021-03-11 op TAILQ_INIT(&eecmd_history.head);
1061 22268e11 2021-03-11 op TAILQ_INIT(&ir_history.head);
1062 22268e11 2021-03-11 op TAILQ_INIT(&lu_history.head);
1063 22268e11 2021-03-11 op
1064 2ba66cea 2021-03-22 op ministate.line.type = LINE_TEXT;
1065 2ba66cea 2021-03-22 op ministate.vline.parent = &ministate.line;
1066 46f6e974 2021-05-17 op ministate.buffer.current_line = &ministate.vline;
1067 2ba66cea 2021-03-22 op
1068 bddc7bbd 2021-04-01 op /* initialize help window */
1069 bddc7bbd 2021-04-01 op TAILQ_INIT(&helpwin.head);
1070 bddc7bbd 2021-04-01 op
1071 9ca15951 2021-03-09 op base_map = &global_map;
1072 f832146f 2021-03-09 op current_map = &global_map;
1073 f832146f 2021-03-09 op
1074 5e11c00c 2021-03-02 op initscr();
1075 74a2587f 2021-06-21 op
1076 74a2587f 2021-06-21 op if (enable_colors) {
1077 74a2587f 2021-06-21 op if (has_colors()) {
1078 74a2587f 2021-06-21 op start_color();
1079 160abe04 2021-06-21 op use_default_colors();
1080 f3bcf8f2 2021-06-21 op } else
1081 74a2587f 2021-06-21 op enable_colors = 0;
1082 f3bcf8f2 2021-06-21 op }
1083 74a2587f 2021-06-21 op
1084 42d61f50 2021-06-24 op config_apply_style();
1085 42d61f50 2021-06-24 op
1086 15e1b108 2021-03-02 op raw();
1087 5e11c00c 2021-03-02 op noecho();
1088 5e11c00c 2021-03-02 op nonl();
1089 5e11c00c 2021-03-02 op intrflush(stdscr, FALSE);
1090 5e11c00c 2021-03-02 op
1091 48e9d457 2021-03-06 op if ((tabline = newwin(1, COLS, 0, 0)) == NULL)
1092 48e9d457 2021-03-06 op return 0;
1093 48e9d457 2021-03-06 op if ((body = newwin(LINES - 3, COLS, 1, 0)) == NULL)
1094 48e9d457 2021-03-06 op return 0;
1095 48e9d457 2021-03-06 op if ((modeline = newwin(1, COLS, LINES-2, 0)) == NULL)
1096 48e9d457 2021-03-06 op return 0;
1097 8a7f2683 2021-07-10 op if ((echoarea = newwin(1, COLS, LINES-1, 0)) == NULL)
1098 48e9d457 2021-03-06 op return 0;
1099 bddc7bbd 2021-04-01 op if ((help = newwin(1, 1, 1, 0)) == NULL)
1100 bddc7bbd 2021-04-01 op return 0;
1101 1d08c280 2021-03-06 op
1102 48e9d457 2021-03-06 op body_lines = LINES-3;
1103 48e9d457 2021-03-06 op body_cols = COLS;
1104 33d904b6 2021-06-22 op
1105 b598590d 2021-06-21 op wbkgd(body, body_face.body);
1106 8a7f2683 2021-07-10 op wbkgd(echoarea, minibuffer_face.background);
1107 72b18268 2021-06-19 op
1108 72b18268 2021-06-19 op update_x_offset();
1109 48e9d457 2021-03-06 op
1110 43a1b8d0 2021-03-09 op keypad(body, TRUE);
1111 f3bcf8f2 2021-06-21 op scrollok(body, FALSE);
1112 48e9d457 2021-03-06 op
1113 5e11c00c 2021-03-02 op /* non-blocking input */
1114 48e9d457 2021-03-06 op wtimeout(body, 0);
1115 5e11c00c 2021-03-02 op
1116 48e9d457 2021-03-06 op mvwprintw(body, 0, 0, "");
1117 5e11c00c 2021-03-02 op
1118 5e11c00c 2021-03-02 op event_set(&stdioev, 0, EV_READ | EV_PERSIST, dispatch_stdio, NULL);
1119 5e11c00c 2021-03-02 op event_add(&stdioev, NULL);
1120 5e11c00c 2021-03-02 op
1121 5e11c00c 2021-03-02 op signal_set(&winchev, SIGWINCH, handle_resize, NULL);
1122 5e11c00c 2021-03-02 op signal_add(&winchev, NULL);
1123 5e11c00c 2021-03-02 op
1124 1d08c280 2021-03-06 op return 1;
1125 5e11c00c 2021-03-02 op }
1126 5e11c00c 2021-03-02 op
1127 5e11c00c 2021-03-02 op void
1128 8af5e5ed 2021-03-08 op ui_on_tab_loaded(struct tab *tab)
1129 8af5e5ed 2021-03-08 op {
1130 8af5e5ed 2021-03-08 op stop_loading_anim(tab);
1131 2051e653 2021-03-13 op message("Loaded %s", tab->hist_cur->h);
1132 3d8c2326 2021-03-18 op
1133 3d8c2326 2021-03-18 op redraw_tabline();
1134 3d8c2326 2021-03-18 op wrefresh(tabline);
1135 3d8c2326 2021-03-18 op if (in_minibuffer)
1136 8a7f2683 2021-07-10 op wrefresh(echoarea);
1137 3d8c2326 2021-03-18 op else
1138 3d8c2326 2021-03-18 op wrefresh(body);
1139 8af5e5ed 2021-03-08 op }
1140 8af5e5ed 2021-03-08 op
1141 8af5e5ed 2021-03-08 op void
1142 5e11c00c 2021-03-02 op ui_on_tab_refresh(struct tab *tab)
1143 5e11c00c 2021-03-02 op {
1144 46f6e974 2021-05-17 op wrap_page(&tab->buffer, body_cols);
1145 02a74b53 2021-07-01 op if (tab->flags & TAB_CURRENT)
1146 3d8c2326 2021-03-18 op redraw_tab(tab);
1147 02a74b53 2021-07-01 op else
1148 e8a76665 2021-05-12 op tab->flags |= TAB_URGENT;
1149 5e11c00c 2021-03-02 op }
1150 5e11c00c 2021-03-02 op
1151 2b2d2872 2021-06-20 op const char *
1152 2b2d2872 2021-06-20 op ui_keyname(int k)
1153 2b2d2872 2021-06-20 op {
1154 2b2d2872 2021-06-20 op return keyname(k);
1155 2b2d2872 2021-06-20 op }
1156 2b2d2872 2021-06-20 op
1157 5e11c00c 2021-03-02 op void
1158 2b2d2872 2021-06-20 op ui_toggle_side_window(void)
1159 2b2d2872 2021-06-20 op {
1160 2b2d2872 2021-06-20 op side_window = !side_window;
1161 2b2d2872 2021-06-20 op if (side_window)
1162 2b2d2872 2021-06-20 op recompute_help();
1163 960b01da 2021-06-20 op
1164 960b01da 2021-06-20 op /*
1165 960b01da 2021-06-20 op * ugly hack, but otherwise the window doesn't get updated
1166 960b01da 2021-06-20 op * until I call handle_resize a second time (i.e. C-l). I
1167 960b01da 2021-06-20 op * will be happy to know why something like this is needed.
1168 960b01da 2021-06-20 op */
1169 960b01da 2021-06-20 op handle_resize_nodelay(0, 0, NULL);
1170 960b01da 2021-06-20 op handle_resize_nodelay(0, 0, NULL);
1171 2b2d2872 2021-06-20 op }
1172 2b2d2872 2021-06-20 op
1173 2b2d2872 2021-06-20 op void
1174 2b2d2872 2021-06-20 op ui_schedule_redraw(void)
1175 2b2d2872 2021-06-20 op {
1176 2b2d2872 2021-06-20 op handle_resize_nodelay(0, 0, NULL);
1177 2b2d2872 2021-06-20 op }
1178 2b2d2872 2021-06-20 op
1179 2b2d2872 2021-06-20 op void
1180 5cd2ebb1 2021-03-11 op ui_require_input(struct tab *tab, int hide)
1181 5cd2ebb1 2021-03-11 op {
1182 5cd2ebb1 2021-03-11 op /* TODO: hard-switching to another tab is ugly */
1183 5cd2ebb1 2021-03-11 op switch_to_tab(tab);
1184 5cd2ebb1 2021-03-11 op
1185 22268e11 2021-03-11 op enter_minibuffer(ir_self_insert, ir_select, exit_minibuffer,
1186 22268e11 2021-03-11 op &ir_history);
1187 5cd2ebb1 2021-03-11 op strlcpy(ministate.prompt, "Input required: ",
1188 5cd2ebb1 2021-03-11 op sizeof(ministate.prompt));
1189 5cd2ebb1 2021-03-11 op redraw_tab(tab);
1190 5cd2ebb1 2021-03-11 op }
1191 5cd2ebb1 2021-03-11 op
1192 5cd2ebb1 2021-03-11 op void
1193 a2fd3805 2021-07-06 op ui_yornp(const char *prompt, void (*fn)(int, struct tab *),
1194 a2fd3805 2021-07-06 op struct tab *data)
1195 5d1bac73 2021-03-25 op {
1196 84b88039 2021-07-12 op yornp(prompt, fn, data);
1197 5d1bac73 2021-03-25 op redraw_tab(current_tab());
1198 5d1bac73 2021-03-25 op }
1199 5d1bac73 2021-03-25 op
1200 5d1bac73 2021-03-25 op void
1201 de2a69bb 2021-05-17 op ui_read(const char *prompt, void (*fn)(const char*, unsigned int),
1202 de2a69bb 2021-05-17 op unsigned int data)
1203 de2a69bb 2021-05-17 op {
1204 84b88039 2021-07-12 op completing_read(prompt, fn, data);
1205 de2a69bb 2021-05-17 op redraw_tab(current_tab());
1206 740f578b 2021-03-15 op }
1207 740f578b 2021-03-15 op
1208 740f578b 2021-03-15 op void
1209 5e11c00c 2021-03-02 op ui_end(void)
1210 5e11c00c 2021-03-02 op {
1211 5e11c00c 2021-03-02 op endwin();
1212 5e11c00c 2021-03-02 op }