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