2 d35e18b3 2024-02-04 op * Copyright (c) 2021, 2024 Omar Polo <op@omarpolo.com>
4 5e11c00c 2021-03-02 op * Permission to use, copy, modify, and distribute this software for any
5 5e11c00c 2021-03-02 op * purpose with or without fee is hereby granted, provided that the above
6 5e11c00c 2021-03-02 op * copyright notice and this permission notice appear in all copies.
8 5e11c00c 2021-03-02 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 5e11c00c 2021-03-02 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 5e11c00c 2021-03-02 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 5e11c00c 2021-03-02 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 5e11c00c 2021-03-02 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 5e11c00c 2021-03-02 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 5e11c00c 2021-03-02 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 1d08c280 2021-03-06 op * Ncurses UI for telescope.
20 1d08c280 2021-03-06 op * Text scrolling
21 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.
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.
33 786e6deb 2021-07-21 op #include "compat.h"
35 98d3e6c1 2024-02-18 op #include <sys/time.h>
36 4e32d3a6 2024-06-04 thomas.ad #include <sys/wait.h>
38 5e11c00c 2021-03-02 op #include <curses.h>
39 4e32d3a6 2024-06-04 thomas.ad #include <errno.h>
40 5e11c00c 2021-03-02 op #include <locale.h>
41 5e11c00c 2021-03-02 op #include <signal.h>
42 7953dd72 2021-03-07 op #include <stdarg.h>
43 eb259e66 2021-03-02 op #include <stdlib.h>
44 eb259e66 2021-03-02 op #include <string.h>
45 f832146f 2021-03-09 op #include <unistd.h>
47 1dc96d88 2024-10-19 op #include <grapheme.h>
49 d252d87c 2024-02-05 op #include "cmd.h"
50 e659558c 2021-07-13 op #include "defaults.h"
51 98d3e6c1 2024-02-18 op #include "ev.h"
52 0548291a 2024-06-25 op #include "exec.h"
53 65c49665 2024-01-23 op #include "hist.h"
54 f7db6d13 2024-02-06 op #include "keymap.h"
55 7b7a69f2 2024-06-13 thomas.ad #include "mailcap.h"
56 d1a0f2a3 2021-07-12 op #include "minibuffer.h"
57 1fce2e75 2021-08-14 op #include "session.h"
58 d1a0f2a3 2021-07-12 op #include "telescope.h"
59 d1a0f2a3 2021-07-12 op #include "ui.h"
60 5caf7d67 2021-07-12 op #include "utf8.h"
62 e795e935 2022-01-18 op static void set_scroll_position(struct tab *, size_t, size_t);
64 0a805b02 2021-07-01 op static void restore_curs_x(struct buffer *);
66 8947c1f2 2021-03-21 op static int readkey(void);
67 98d3e6c1 2024-02-18 op static void dispatch_stdio(int, int, void*);
68 329cd624 2024-06-15 op static void handle_signal(int, int, void*);
69 98d3e6c1 2024-02-18 op static void handle_resize_nodelay(int, int, void*);
70 98d3e6c1 2024-02-18 op static void handle_download_refresh(int, int, void *);
71 32c6c75e 2021-07-15 op static void rearrange_windows(void);
72 f853ec6f 2024-10-22 op static void line_prefix_and_text(int, struct vline *, char *, size_t, const char **, const char **, int *);
73 f3bcf8f2 2021-06-21 op static void print_vline(int, int, WINDOW*, struct vline*);
74 8af5e5ed 2021-03-08 op static void redraw_tabline(void);
75 0aef305d 2022-01-10 op static void redraw_window(WINDOW *, int, int, int, int, struct buffer *);
76 3b5f459e 2021-11-05 op static void redraw_download(void);
77 bddc7bbd 2021-04-01 op static void redraw_help(void);
78 e19f9a04 2021-03-11 op static void redraw_body(struct tab*);
79 8af5e5ed 2021-03-08 op static void redraw_modeline(struct tab*);
80 e9af06b9 2021-07-12 op static void redraw_minibuffer(void);
81 e9af06b9 2021-07-12 op static void do_redraw_echoarea(void);
82 e9af06b9 2021-07-12 op static void do_redraw_minibuffer(void);
83 b1e1e41a 2021-07-14 op static void do_redraw_minibuffer_compl(void);
84 55df859f 2021-07-12 op static void place_cursor(int);
85 5e11c00c 2021-03-02 op static void redraw_tab(struct tab*);
86 98d3e6c1 2024-02-18 op static void update_loading_anim(int, int, void*);
87 8af5e5ed 2021-03-08 op static void stop_loading_anim(struct tab*);
89 32c6c75e 2021-07-15 op static int should_rearrange_windows;
90 56168aa8 2021-08-18 op static int show_tab_bar;
91 23f22c83 2021-07-13 op static int too_small;
92 72b18268 2021-06-19 op static int x_offset;
94 83dce83d 2021-07-17 op struct thiskey thiskey;
95 83dce83d 2021-07-17 op struct tab *current_tab;
97 98d3e6c1 2024-02-18 op static unsigned int resize_timer;
98 98d3e6c1 2024-02-18 op static struct timeval resize_tv = { 0, 250000 };
100 98d3e6c1 2024-02-18 op static unsigned int download_timer;
101 0e7b2e99 2022-05-05 op static struct timeval download_refresh_timer = { 0, 250000 };
103 e5a2797f 2021-07-13 op static WINDOW *tabline, *body, *modeline, *echoarea, *minibuffer;
105 2b2d2872 2021-06-20 op int body_lines, body_cols;
107 bddc7bbd 2021-04-01 op static WINDOW *help;
108 de278567 2021-07-21 op /* not static so we can see them from help.c */
109 de278567 2021-07-21 op struct buffer helpwin;
110 de278567 2021-07-21 op int help_lines, help_cols;
112 3b5f459e 2021-11-05 op static WINDOW *download;
113 3b5f459e 2021-11-05 op /* not static so we can see them from download.c */
114 3b5f459e 2021-11-05 op struct buffer downloadwin;
115 3b5f459e 2021-11-05 op int download_lines;
116 84892515 2021-11-27 op int download_cols;
118 bddc7bbd 2021-04-01 op static int side_window;
119 65340174 2021-07-21 op static int in_side_window;
121 98d3e6c1 2024-02-18 op static struct timeval loading_tv = { 0, 250000 };
123 7c7d7bb7 2021-03-10 op static char keybuf[64];
125 78894e73 2021-08-12 op /* XXX: don't forget to init these in main() */
126 9ca15951 2021-03-09 op struct kmap global_map,
127 fa3fd864 2021-03-10 op minibuffer_map,
128 9ca15951 2021-03-09 op *current_map,
131 72b18268 2021-06-19 op static inline void
132 923f9ce5 2021-06-21 op update_x_offset(void)
134 72b18268 2021-06-19 op if (olivetti_mode && fill_column < body_cols)
135 72b18268 2021-06-19 op x_offset = (body_cols - fill_column)/2;
137 72b18268 2021-06-19 op x_offset = 0;
141 e795e935 2022-01-18 op set_scroll_position(struct tab *tab, size_t top, size_t cur)
143 e795e935 2022-01-18 op struct line *last;
144 e795e935 2022-01-18 op struct vline *vl;
145 e795e935 2022-01-18 op size_t i = 0;
146 6d5348f3 2022-01-21 op int topfound = 0;
148 c1d27b0e 2024-06-14 op last = TAILQ_FIRST(&tab->buffer.head);
149 c1d27b0e 2024-06-14 op TAILQ_FOREACH(vl, &tab->buffer.vhead, vlines) {
150 e795e935 2022-01-18 op if (last != vl->parent) {
151 e795e935 2022-01-18 op last = vl->parent;
155 e795e935 2022-01-18 op if (!topfound && i == top) {
156 e795e935 2022-01-18 op topfound = 1;
157 e795e935 2022-01-18 op tab->buffer.top_line = vl;
160 6d5348f3 2022-01-21 op if (i == cur) {
161 e795e935 2022-01-18 op tab->buffer.current_line = vl;
166 6d5348f3 2022-01-21 op if (!topfound)
167 c1d27b0e 2024-06-14 op tab->buffer.top_line = TAILQ_FIRST(&tab->buffer.vhead);
169 6d5348f3 2022-01-21 op tab->buffer.current_line = tab->buffer.top_line;
173 e795e935 2022-01-18 op get_scroll_position(struct tab *tab, size_t *top, size_t *cur)
175 e795e935 2022-01-18 op struct line *l;
176 e795e935 2022-01-18 op int topfound = 0;
181 e795e935 2022-01-18 op if (tab->buffer.top_line == NULL ||
182 e795e935 2022-01-18 op tab->buffer.current_line == NULL)
185 c1d27b0e 2024-06-14 op TAILQ_FOREACH(l, &tab->buffer.head, lines) {
186 e795e935 2022-01-18 op if (tab->buffer.top_line->parent == l)
187 e795e935 2022-01-18 op topfound = 1;
188 e795e935 2022-01-18 op if (tab->buffer.current_line->parent == l)
191 e795e935 2022-01-18 op if (!topfound)
198 98411855 2021-06-23 op save_excursion(struct excursion *place, struct buffer *buffer)
200 98411855 2021-06-23 op place->curs_x = buffer->curs_x;
201 98411855 2021-06-23 op place->curs_y = buffer->curs_y;
202 98411855 2021-06-23 op place->line_off = buffer->line_off;
203 ca783de6 2021-07-18 op place->top_line = buffer->top_line;
204 98411855 2021-06-23 op place->current_line = buffer->current_line;
205 6d24bfb3 2024-10-19 op place->point_offset = buffer->point_offset;
209 98411855 2021-06-23 op restore_excursion(struct excursion *place, struct buffer *buffer)
211 98411855 2021-06-23 op buffer->curs_x = place->curs_x;
212 98411855 2021-06-23 op buffer->curs_y = place->curs_y;
213 98411855 2021-06-23 op buffer->line_off = place->line_off;
214 ca783de6 2021-07-18 op buffer->top_line = place->top_line;
215 98411855 2021-06-23 op buffer->current_line = place->current_line;
216 6d24bfb3 2024-10-19 op buffer->point_offset = place->point_offset;
220 0a805b02 2021-07-01 op restore_curs_x(struct buffer *buffer)
222 452589f7 2021-03-16 op struct vline *vl;
223 f350bc73 2024-05-27 thomas.ad struct lineprefix *lp = line_prefixes;
224 bd644709 2021-07-18 op const char *prfx, *text;
226 f350bc73 2024-05-27 thomas.ad if (dont_apply_styling)
227 f350bc73 2024-05-27 thomas.ad lp = raw_prefixes;
229 f853ec6f 2024-10-22 op buffer->curs_x = 0;
231 f853ec6f 2024-10-22 op /* small hack: don't olivetti-mode the download pane */
232 f853ec6f 2024-10-22 op if (buffer != &downloadwin)
233 f853ec6f 2024-10-22 op buffer->curs_x += x_offset;
235 46f6e974 2021-05-17 op vl = buffer->current_line;
236 c1d27b0e 2024-06-14 op if (vl == NULL || vl->len == 0 || vl->parent == NULL)
237 f853ec6f 2024-10-22 op buffer->curs_x += buffer->point_offset = 0;
238 bd644709 2021-07-18 op else if (vl->parent->data != NULL) {
239 bd644709 2021-07-18 op text = vl->parent->data;
240 f853ec6f 2024-10-22 op buffer->curs_x += utf8_snwidth(text, buffer->point_offset,
241 f853ec6f 2024-10-22 op buffer->curs_x);
243 bd4a08a7 2022-11-07 op text = vl->parent->line + vl->from;
244 f853ec6f 2024-10-22 op buffer->curs_x += utf8_snwidth(text, buffer->point_offset,
245 f853ec6f 2024-10-22 op buffer->curs_x);
248 47aec13e 2021-07-17 op if (vl == NULL)
251 47aec13e 2021-07-17 op if (vl->parent->data != NULL)
252 002b074d 2021-08-14 op buffer->curs_x += utf8_swidth_between(vl->parent->line,
253 f853ec6f 2024-10-22 op vl->parent->data, buffer->curs_x);
255 f350bc73 2024-05-27 thomas.ad prfx = lp[vl->parent->type].prfx1;
256 f853ec6f 2024-10-22 op buffer->curs_x += utf8_swidth(prfx, buffer->curs_x);
261 870210fb 2021-03-26 op global_key_unbound(void)
263 870210fb 2021-03-26 op message("%s is undefined", keybuf);
266 2b2d2872 2021-06-20 op struct buffer *
267 46f6e974 2021-05-17 op current_buffer(void)
269 2ba66cea 2021-03-22 op if (in_minibuffer)
270 46f6e974 2021-05-17 op return &ministate.buffer;
271 3b5f459e 2021-11-05 op if (in_side_window & SIDE_WINDOW_LEFT)
272 65340174 2021-07-21 op return &helpwin;
273 3b5f459e 2021-11-05 op if (in_side_window & SIDE_WINDOW_BOTTOM)
274 3b5f459e 2021-11-05 op return &downloadwin;
275 83dce83d 2021-07-17 op return ¤t_tab->buffer;
279 8947c1f2 2021-03-21 op readkey(void)
281 8947c1f2 2021-03-21 op uint32_t state = 0;
283 8947c1f2 2021-03-21 op if ((thiskey.key = wgetch(body)) == ERR)
286 3f66a33e 2021-12-01 op thiskey.meta = thiskey.key == '\e';
287 8947c1f2 2021-03-21 op if (thiskey.meta) {
288 9ca15951 2021-03-09 op thiskey.key = wgetch(body);
289 3f66a33e 2021-12-01 op if (thiskey.key == ERR || thiskey.key == '\e') {
290 c314a314 2021-03-11 op thiskey.meta = 0;
291 3f66a33e 2021-12-01 op thiskey.key = '\e';
295 8947c1f2 2021-03-21 op thiskey.cp = 0;
297 63ecae6d 2021-08-14 op if ((unsigned int)thiskey.key >= UINT8_MAX)
301 63ecae6d 2021-08-14 op if (!utf8_decode(&state, &thiskey.cp, (uint8_t)thiskey.key))
303 63ecae6d 2021-08-14 op if ((thiskey.key = wgetch(body)) == ERR) {
304 63ecae6d 2021-08-14 op message("Error decoding user input");
313 98d3e6c1 2024-02-18 op dispatch_stdio(int fd, int ev, void *d)
316 8947c1f2 2021-03-21 op const char *keyname;
317 8947c1f2 2021-03-21 op char tmp[5] = {0};
319 23f22c83 2021-07-13 op /* TODO: schedule a redraw? */
320 23f22c83 2021-07-13 op if (too_small)
323 8947c1f2 2021-03-21 op if (!readkey())
326 7c7d7bb7 2021-03-10 op if (keybuf[0] != '\0')
327 7c7d7bb7 2021-03-10 op strlcat(keybuf, " ", sizeof(keybuf));
328 7c7d7bb7 2021-03-10 op if (thiskey.meta)
329 7c7d7bb7 2021-03-10 op strlcat(keybuf, "M-", sizeof(keybuf));
330 8947c1f2 2021-03-21 op if (thiskey.cp != 0) {
331 dcbfbf59 2024-10-20 op grapheme_encode_utf8(thiskey.cp, tmp, sizeof(tmp));
332 7c7d7bb7 2021-03-10 op strlcat(keybuf, tmp, sizeof(keybuf));
333 af29d739 2021-07-13 op } else if ((keyname = unkbd(thiskey.key)) != NULL) {
334 af29d739 2021-07-13 op strlcat(keybuf, keyname, sizeof(keybuf));
336 af29d739 2021-07-13 op tmp[0] = thiskey.key;
337 af29d739 2021-07-13 op strlcat(keybuf, tmp, sizeof(keybuf));
340 57668c86 2021-11-05 op lk = lookup_key(¤t_map, &thiskey, current_buffer());
341 57668c86 2021-11-05 op if (lk == LK_UNBOUND) {
342 57668c86 2021-11-05 op if (current_map->unhandled_input != NULL)
343 57668c86 2021-11-05 op current_map->unhandled_input();
345 57668c86 2021-11-05 op global_key_unbound();
347 57668c86 2021-11-05 op if (lk != LK_ADVANCED_MAP) {
348 57668c86 2021-11-05 op current_map = base_map;
349 57668c86 2021-11-05 op strlcpy(keybuf, "", sizeof(keybuf));
352 3b5f459e 2021-11-05 op if (side_window & SIDE_WINDOW_LEFT)
353 bddc7bbd 2021-04-01 op recompute_help();
355 32c6c75e 2021-07-15 op if (should_rearrange_windows)
356 32c6c75e 2021-07-15 op rearrange_windows();
357 83dce83d 2021-07-17 op redraw_tab(current_tab);
361 329cd624 2024-06-15 op handle_signal(int sig, int ev, void *d)
365 329cd624 2024-06-15 op switch (sig) {
366 329cd624 2024-06-15 op case SIGWINCH:
367 329cd624 2024-06-15 op ev_timer_cancel(resize_timer);
368 329cd624 2024-06-15 op resize_timer = ev_timer(&resize_tv, handle_resize_nodelay,
371 329cd624 2024-06-15 op case SIGCHLD:
373 329cd624 2024-06-15 op ret = waitpid(-1, NULL, WNOHANG);
374 329cd624 2024-06-15 op } while (ret == -1 && errno == EINTR);
380 98d3e6c1 2024-02-18 op handle_resize_nodelay(int s, int ev, void *d)
386 32c6c75e 2021-07-15 op rearrange_windows();
390 98d3e6c1 2024-02-18 op handle_download_refresh(int s, int v, void *d)
392 0e7b2e99 2022-05-05 op if (side_window & SIDE_WINDOW_BOTTOM) {
393 0e7b2e99 2022-05-05 op recompute_downloads();
394 0e7b2e99 2022-05-05 op redraw_tab(current_tab);
398 56168aa8 2021-08-18 op static inline int
399 56168aa8 2021-08-18 op should_show_tab_bar(void)
401 56168aa8 2021-08-18 op if (tab_bar_show == -1)
403 56168aa8 2021-08-18 op if (tab_bar_show == 0)
406 56168aa8 2021-08-18 op return TAILQ_NEXT(TAILQ_FIRST(&tabshead), tabs) != NULL;
410 32c6c75e 2021-07-15 op rearrange_windows(void)
413 3b5f459e 2021-11-05 op int minibuffer_lines;
415 32c6c75e 2021-07-15 op should_rearrange_windows = 0;
416 56168aa8 2021-08-18 op show_tab_bar = should_show_tab_bar();
418 b3884fbe 2021-07-13 op lines = LINES;
420 45929003 2024-01-13 op /* 3 lines for the ui and 12 for the body and minibuffer */
421 23f22c83 2021-07-13 op if ((too_small = lines < 15)) {
423 23f22c83 2021-07-13 op printw("Window too small.");
428 48e9d457 2021-03-06 op /* move and resize the windows, in reverse order! */
430 b1e1e41a 2021-07-14 op if (in_minibuffer == MB_COMPREAD) {
431 3b5f459e 2021-11-05 op minibuffer_lines = MIN(10, lines/2);
432 3b5f459e 2021-11-05 op mvwin(minibuffer, lines - minibuffer_lines, 0);
433 3b5f459e 2021-11-05 op wresize(minibuffer, minibuffer_lines, COLS);
434 3b5f459e 2021-11-05 op lines -= minibuffer_lines;
436 f853ec6f 2024-10-22 op wrap_page(&ministate.compl.buffer, COLS, 0);
439 b3884fbe 2021-07-13 op mvwin(echoarea, --lines, 0);
440 8a7f2683 2021-07-10 op wresize(echoarea, 1, COLS);
442 b3884fbe 2021-07-13 op mvwin(modeline, --lines, 0);
443 48e9d457 2021-03-06 op wresize(modeline, 1, COLS);
445 3b5f459e 2021-11-05 op if (side_window & SIDE_WINDOW_BOTTOM) {
446 3b5f459e 2021-11-05 op download_lines = MIN(5, lines/2);
447 84892515 2021-11-27 op download_cols = COLS;
448 3b5f459e 2021-11-05 op mvwin(download, lines - download_lines, 0);
449 84892515 2021-11-27 op wresize(download, download_lines, download_cols);
450 3b5f459e 2021-11-05 op lines -= download_lines;
452 f853ec6f 2024-10-22 op wrap_page(&downloadwin, download_cols, 0);
455 56168aa8 2021-08-18 op body_lines = show_tab_bar ? --lines : lines;
456 bd9637e9 2021-03-06 op body_cols = COLS;
459 56168aa8 2021-08-18 op * Here we make the assumption that show_tab_bar is either 0
460 56168aa8 2021-08-18 op * or 1, and reuse that as argument to mvwin.
462 3b5f459e 2021-11-05 op if (side_window & SIDE_WINDOW_LEFT) {
463 bddc7bbd 2021-04-01 op help_cols = 0.3 * COLS;
464 b3884fbe 2021-07-13 op help_lines = lines;
465 56168aa8 2021-08-18 op mvwin(help, show_tab_bar, 0);
466 bddc7bbd 2021-04-01 op wresize(help, help_lines, help_cols);
468 f853ec6f 2024-10-22 op wrap_page(&helpwin, help_cols, 0);
470 bddc7bbd 2021-04-01 op body_cols = COLS - help_cols - 1;
471 56168aa8 2021-08-18 op mvwin(body, show_tab_bar, help_cols);
473 56168aa8 2021-08-18 op mvwin(body, show_tab_bar, 0);
475 72b18268 2021-06-19 op update_x_offset();
476 bddc7bbd 2021-04-01 op wresize(body, body_lines, body_cols);
478 56168aa8 2021-08-18 op if (show_tab_bar)
479 56168aa8 2021-08-18 op wresize(tabline, 1, COLS);
481 f853ec6f 2024-10-22 op wrap_page(¤t_tab->buffer, body_cols, x_offset);
482 83dce83d 2021-07-17 op redraw_tab(current_tab);
486 f853ec6f 2024-10-22 op line_prefix_and_text(int col, struct vline *vl, char *buf, size_t len,
487 bd4a08a7 2022-11-07 op const char **prfx_ret, const char **text_ret, int *text_len)
489 f350bc73 2024-05-27 thomas.ad struct lineprefix *lp = line_prefixes;
490 fd29e873 2024-01-13 op int type, cont;
491 fd29e873 2024-01-13 op size_t i, width;
492 6ca7e1b6 2021-07-16 op char *space, *t;
494 f350bc73 2024-05-27 thomas.ad if (dont_apply_styling)
495 f350bc73 2024-05-27 thomas.ad lp = raw_prefixes;
497 bd4a08a7 2022-11-07 op if (vl->len == 0) {
498 6ca7e1b6 2021-07-16 op *text_ret = "";
499 bd4a08a7 2022-11-07 op *text_len = 0;
502 6ca7e1b6 2021-07-16 op cont = vl->flags & L_CONTINUATION;
503 6ca7e1b6 2021-07-16 op type = vl->parent->type;
505 f350bc73 2024-05-27 thomas.ad *prfx_ret = lp[type].prfx1;
507 f350bc73 2024-05-27 thomas.ad *prfx_ret = lp[type].prfx2;
509 6ca7e1b6 2021-07-16 op space = vl->parent->data;
510 5ab1e3c1 2024-01-13 op *text_ret = vl->parent->line + vl->from;
511 5ab1e3c1 2024-01-13 op *text_len = MIN(INT_MAX, vl->len);
512 bd4a08a7 2022-11-07 op if (!emojify_link || type != LINE_LINK || space == NULL) {
517 6ca7e1b6 2021-07-16 op memset(buf, 0, len);
518 f853ec6f 2024-10-22 op width = utf8_swidth_between(vl->parent->line, space, col);
519 fd29e873 2024-01-13 op for (i = 0; i < width + 1 && i < len - 1; ++i)
520 fd29e873 2024-01-13 op buf[i] = ' ';
522 5ab1e3c1 2024-01-13 op strlcpy(buf, vl->parent->line, len);
523 6ca7e1b6 2021-07-16 op if ((t = strchr(buf, ' ')) != NULL)
525 6ca7e1b6 2021-07-16 op strlcat(buf, " ", len);
528 6ca7e1b6 2021-07-16 op *prfx_ret = buf;
531 b3be07ea 2021-07-18 op static inline void
532 b3be07ea 2021-07-18 op print_vline_descr(int width, WINDOW *window, struct vline *vl)
534 b3be07ea 2021-07-18 op int x, y, goal;
536 1577540c 2021-11-05 op switch (vl->parent->type) {
537 b8899faf 2021-11-05 op case LINE_COMPL:
538 b8899faf 2021-11-05 op case LINE_COMPL_CURRENT:
539 a7ce8d61 2021-11-05 op goal = width/2;
541 1577540c 2021-11-05 op case LINE_DOWNLOAD:
542 1577540c 2021-11-05 op case LINE_DOWNLOAD_DONE:
543 a7ce8d61 2021-11-05 op goal = width/4;
545 455b4545 2021-11-05 op case LINE_HELP:
552 b8899faf 2021-11-05 op if (vl->parent->alt == NULL)
556 b8899faf 2021-11-05 op getyx(window, y, x);
558 b3be07ea 2021-07-18 op if (goal <= x)
559 b3be07ea 2021-07-18 op wprintw(window, " ");
560 b3be07ea 2021-07-18 op for (; goal > x; ++x)
561 b3be07ea 2021-07-18 op wprintw(window, " ");
563 b3be07ea 2021-07-18 op wprintw(window, "%s", vl->parent->alt);
567 fbadd395 2021-07-16 op * Core part of the rendering. It prints a vline starting from the
568 fbadd395 2021-07-16 op * current cursor position. Printing a vline consists of skipping
569 fbadd395 2021-07-16 op * `off' columns (for olivetti-mode), print the correct prefix (which
570 fbadd395 2021-07-16 op * may be the emoji in case of emojified links-lines), printing the
571 fbadd395 2021-07-16 op * text itself, filling until width - off and filling off columns
575 f3bcf8f2 2021-06-21 op print_vline(int off, int width, WINDOW *window, struct vline *vl)
578 fbadd395 2021-07-16 op * Believe me or not, I've seen emoji ten code points long!
579 fbadd395 2021-07-16 op * That means, to stay large, 4*10 bytes + NUL.
581 fbadd395 2021-07-16 op char emojibuf[41] = {0};
582 fbadd395 2021-07-16 op const char *text, *prfx;
583 2af29222 2021-06-24 op struct line_face *f;
584 bd4a08a7 2022-11-07 op int i, left, x, y, textlen;
586 2af29222 2021-06-24 op f = &line_faces[vl->parent->type];
588 d89b86d6 2021-06-21 op /* unused, set by getyx */
591 28cfdf8f 2022-01-10 op if (vl->parent->type == LINE_FRINGE && fringe_ignore_offset)
594 f853ec6f 2024-10-22 op line_prefix_and_text(off, vl, emojibuf, sizeof(emojibuf), &prfx,
595 bd4a08a7 2022-11-07 op &text, &textlen);
597 ab47e7d4 2021-06-24 op wattr_on(window, body_face.left, NULL);
598 f3bcf8f2 2021-06-21 op for (i = 0; i < off; i++)
599 f3bcf8f2 2021-06-21 op waddch(window, ' ');
600 ab47e7d4 2021-06-24 op wattr_off(window, body_face.left, NULL);
602 2af29222 2021-06-24 op wattr_on(window, f->prefix, NULL);
603 6ca7e1b6 2021-07-16 op wprintw(window, "%s", prfx);
604 2af29222 2021-06-24 op wattr_off(window, f->prefix, NULL);
606 2af29222 2021-06-24 op wattr_on(window, f->text, NULL);
608 6b630429 2024-02-05 op wprintw(window, "%.*s", textlen, text);
609 b3be07ea 2021-07-18 op print_vline_descr(width, window, vl);
610 2af29222 2021-06-24 op wattr_off(window, f->text, NULL);
612 f3bcf8f2 2021-06-21 op getyx(window, y, x);
614 f3bcf8f2 2021-06-21 op left = width - x;
616 2af29222 2021-06-24 op wattr_on(window, f->trail, NULL);
617 04d32eda 2021-07-08 op for (i = 0; i < left - off; ++i)
618 f3bcf8f2 2021-06-21 op waddch(window, ' ');
619 2af29222 2021-06-24 op wattr_off(window, f->trail, NULL);
621 ab47e7d4 2021-06-24 op wattr_on(window, body_face.right, NULL);
622 160abe04 2021-06-21 op for (i = 0; i < off; i++)
623 160abe04 2021-06-21 op waddch(window, ' ');
624 ab47e7d4 2021-06-24 op wattr_off(window, body_face.right, NULL);
628 8af5e5ed 2021-03-08 op redraw_tabline(void)
630 7c7d7bb7 2021-03-10 op struct tab *tab;
631 8f127baa 2021-04-22 op size_t toskip, ots, tabwidth, space, x;
632 ce6d5335 2021-07-16 op int current, y, truncated, pair;
633 dc5df781 2021-03-13 op const char *title;
634 119f393c 2021-03-16 op char buf[25];
638 2815e3a0 2024-09-01 op /* unused, but set by a getyx */
641 8f127baa 2021-04-22 op tabwidth = sizeof(buf)+1;
642 8f127baa 2021-04-22 op space = COLS-2;
645 a636f50e 2021-03-16 op TAILQ_FOREACH(tab, &tabshead, tabs) {
647 83dce83d 2021-07-17 op if (tab == current_tab)
651 aa8228f3 2022-01-04 op if (toskip * tabwidth <= space)
654 8f127baa 2021-04-22 op ots = toskip;
656 95a8c791 2021-08-26 op while (toskip != 0 &&
657 8f127baa 2021-04-22 op (ots - toskip+1) * tabwidth < space)
661 a636f50e 2021-03-16 op werase(tabline);
662 ab47e7d4 2021-06-24 op wattr_on(tabline, tab_face.background, NULL);
663 a636f50e 2021-03-16 op wprintw(tabline, toskip == 0 ? " " : "<");
664 ab47e7d4 2021-06-24 op wattr_off(tabline, tab_face.background, NULL);
666 a636f50e 2021-03-16 op truncated = 0;
667 7c7d7bb7 2021-03-10 op TAILQ_FOREACH(tab, &tabshead, tabs) {
668 a636f50e 2021-03-16 op if (truncated)
670 a636f50e 2021-03-16 op if (toskip != 0) {
675 a636f50e 2021-03-16 op getyx(tabline, y, x);
676 a636f50e 2021-03-16 op if (x + sizeof(buf)+2 >= (size_t)COLS)
677 a636f50e 2021-03-16 op truncated = 1;
679 83dce83d 2021-07-17 op current = tab == current_tab;
681 c1d27b0e 2024-06-14 op if (*(title = tab->buffer.title) == '\0')
682 65c49665 2024-01-23 op title = hist_cur(tab->hist);
684 e8a76665 2021-05-12 op if (tab->flags & TAB_URGENT)
685 e8a76665 2021-05-12 op strlcpy(buf, "!", sizeof(buf));
687 e8a76665 2021-05-12 op strlcpy(buf, " ", sizeof(buf));
689 95a8c791 2021-08-26 op if (strlcat(buf, title, sizeof(buf)) >= sizeof(buf)) {
690 119f393c 2021-03-16 op /* truncation happens */
691 119f393c 2021-03-16 op strlcpy(&buf[sizeof(buf)-4], "...", 4);
693 119f393c 2021-03-16 op /* pad with spaces */
694 119f393c 2021-03-16 op while (strlcat(buf, " ", sizeof(buf)) < sizeof(buf))
698 ce6d5335 2021-07-16 op pair = current ? tab_face.current : tab_face.tab;
699 ce6d5335 2021-07-16 op wattr_on(tabline, pair, NULL);
700 119f393c 2021-03-16 op wprintw(tabline, "%s", buf);
701 ce6d5335 2021-07-16 op wattr_off(tabline, pair, NULL);
703 ce6d5335 2021-07-16 op wattr_on(tabline, tab_face.background, NULL);
704 119f393c 2021-03-16 op if (TAILQ_NEXT(tab, tabs) != NULL)
705 05bc942e 2021-07-23 op wprintw(tabline, "┃");
706 ce6d5335 2021-07-16 op wattr_off(tabline, tab_face.background, NULL);
709 ab47e7d4 2021-06-24 op wattr_on(tabline, tab_face.background, NULL);
710 8f127baa 2021-04-22 op for (; x < (size_t)COLS; ++x)
711 119f393c 2021-03-16 op waddch(tabline, ' ');
712 a636f50e 2021-03-16 op if (truncated)
713 a636f50e 2021-03-16 op mvwprintw(tabline, 0, COLS-1, ">");
714 ab47e7d4 2021-06-24 op wattr_off(tabline, tab_face.background, NULL);
718 77dd24f4 2021-07-05 op * Compute the first visible line around vl. Try to search forward
719 77dd24f4 2021-07-05 op * until the end of the buffer; if a visible line is not found, search
720 77dd24f4 2021-07-05 op * backward. Return NULL if no viable line was found.
722 e7b982f4 2021-07-14 op struct vline *
723 77dd24f4 2021-07-05 op adjust_line(struct vline *vl, struct buffer *buffer)
725 77dd24f4 2021-07-05 op struct vline *t;
727 b1e1e41a 2021-07-14 op if (vl == NULL)
730 77dd24f4 2021-07-05 op if (!(vl->parent->flags & L_HIDDEN))
733 77dd24f4 2021-07-05 op /* search forward */
735 77dd24f4 2021-07-05 op t != NULL && t->parent->flags & L_HIDDEN;
736 77dd24f4 2021-07-05 op t = TAILQ_NEXT(t, vlines))
739 77dd24f4 2021-07-05 op if (t != NULL)
742 77dd24f4 2021-07-05 op /* search backward */
744 77dd24f4 2021-07-05 op t != NULL && t->parent->flags & L_HIDDEN;
745 77dd24f4 2021-07-05 op t = TAILQ_PREV(t, vhead, vlines))
752 002b074d 2021-08-14 op redraw_window(WINDOW *win, int off, int height, int width,
753 0aef305d 2022-01-10 op int show_fringe, struct buffer *buffer)
755 1a8f0d27 2021-07-20 op struct vline *vl;
756 0aef305d 2022-01-10 op int onscreen = 0, l = 0;
758 0a805b02 2021-07-01 op restore_curs_x(buffer);
761 0a805b02 2021-07-01 op * TODO: ignoring buffer->force_update and always
762 0a805b02 2021-07-01 op * re-rendering. In theory we can recompute the y position
763 0a805b02 2021-07-01 op * without a re-render, and optimize here. It's not the only
764 0a805b02 2021-07-01 op * optimisation possible here, wscrl wolud also be an
765 0a805b02 2021-07-01 op * interesting one.
770 2bfa414d 2021-07-01 op buffer->curs_y = 0;
772 46f6e974 2021-05-17 op if (TAILQ_EMPTY(&buffer->head))
775 b1e1e41a 2021-07-14 op if (buffer->top_line == NULL)
776 c1d27b0e 2024-06-14 op buffer->top_line = TAILQ_FIRST(&buffer->vhead);
778 77dd24f4 2021-07-05 op buffer->top_line = adjust_line(buffer->top_line, buffer);
779 77dd24f4 2021-07-05 op if (buffer->top_line == NULL)
782 77dd24f4 2021-07-05 op buffer->current_line = adjust_line(buffer->current_line, buffer);
784 94ec38e8 2021-06-29 op for (vl = buffer->top_line; vl != NULL; vl = TAILQ_NEXT(vl, vlines)) {
785 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
788 f3bcf8f2 2021-06-21 op wmove(win, l, 0);
789 ec9aa106 2021-07-14 op print_vline(off, width, win, vl);
791 2bfa414d 2021-07-01 op if (vl == buffer->current_line)
792 2bfa414d 2021-07-01 op onscreen = 1;
794 2bfa414d 2021-07-01 op if (!onscreen)
795 2bfa414d 2021-07-01 op buffer->curs_y++;
798 bddc7bbd 2021-04-01 op if (l == height)
802 2bfa414d 2021-07-01 op if (!onscreen) {
803 2bfa414d 2021-07-01 op for (; vl != NULL; vl = TAILQ_NEXT(vl, vlines)) {
804 2bfa414d 2021-07-01 op if (vl == buffer->current_line)
806 963c680c 2021-07-05 op if (vl->parent->flags & L_HIDDEN)
808 2bfa414d 2021-07-01 op buffer->line_off++;
809 2bfa414d 2021-07-01 op buffer->top_line = TAILQ_NEXT(buffer->top_line, vlines);
812 e7b982f4 2021-07-14 op if (vl != NULL)
816 2bfa414d 2021-07-01 op buffer->last_line_off = buffer->line_off;
817 2bfa414d 2021-07-01 op buffer->force_redraw = 0;
819 0aef305d 2022-01-10 op for (; show_fringe && l < height; l++)
820 28cfdf8f 2022-01-10 op print_vline(off, width, win, &fringe);
822 46f6e974 2021-05-17 op wmove(win, buffer->curs_y, buffer->curs_x);
826 3b5f459e 2021-11-05 op redraw_download(void)
828 0aef305d 2022-01-10 op redraw_window(download, 0, download_lines, COLS, 0, &downloadwin);
832 bddc7bbd 2021-04-01 op redraw_help(void)
834 0aef305d 2022-01-10 op redraw_window(help, 0, help_lines, help_cols, 1, &helpwin);
838 bddc7bbd 2021-04-01 op redraw_body(struct tab *tab)
840 3323faaf 2021-06-21 op static struct tab *last_tab;
842 3323faaf 2021-06-21 op if (last_tab != tab)
843 3323faaf 2021-06-21 op tab->buffer.force_redraw =1;
844 3323faaf 2021-06-21 op last_tab = tab;
846 0aef305d 2022-01-10 op redraw_window(body, x_offset, body_lines, body_cols, 1, &tab->buffer);
849 10346511 2021-03-17 op static inline char
850 10346511 2021-03-17 op trust_status_char(enum trust_state ts)
852 10346511 2021-03-17 op switch (ts) {
853 de278567 2021-07-21 op case TS_UNKNOWN: return '-';
854 10346511 2021-03-17 op case TS_UNTRUSTED: return '!';
855 a2fd3805 2021-07-06 op case TS_TEMP_TRUSTED: return '!';
856 10346511 2021-03-17 op case TS_TRUSTED: return 'v';
857 10346511 2021-03-17 op case TS_VERIFIED: return 'V';
858 923f9ce5 2021-06-21 op default: return 'X';
863 48e9d457 2021-03-06 op redraw_modeline(struct tab *tab)
865 65340174 2021-07-21 op struct buffer *buffer;
867 48e9d457 2021-03-06 op int x, y, max_x, max_y;
868 65340174 2021-07-21 op const char *mode;
869 8af5e5ed 2021-03-08 op const char *spin = "-\\|/";
871 65340174 2021-07-21 op buffer = current_buffer();
872 c1d27b0e 2024-06-14 op mode = buffer->mode;
874 156f1501 2021-03-13 op werase(modeline);
875 ab47e7d4 2021-06-24 op wattr_on(modeline, modeline_face.background, NULL);
876 48e9d457 2021-03-06 op wmove(modeline, 0, 0);
878 a3e4d56b 2024-05-25 thomas.ad wprintw(modeline, "-%c%c%c%c %s ",
879 2ba66cea 2021-03-22 op spin[tab->loading_anim_step],
880 10346511 2021-03-17 op trust_status_char(tab->trust),
881 d35e18b3 2024-02-04 op tab->client_cert ? 'C' : '-',
882 a3e4d56b 2024-05-25 thomas.ad tab->faulty_gemserver ? 'W' : '-',
883 58c75fab 2021-03-16 op mode == NULL ? "(none)" : mode);
885 65340174 2021-07-21 op pct = (buffer->line_off + buffer->curs_y) * 100.0
886 65340174 2021-07-21 op / buffer->line_max;
888 65340174 2021-07-21 op if (buffer->line_max <= (size_t)body_lines)
889 95a8c791 2021-08-26 op wprintw(modeline, "All ");
890 65340174 2021-07-21 op else if (buffer->line_off == 0)
891 95a8c791 2021-08-26 op wprintw(modeline, "Top ");
892 65340174 2021-07-21 op else if (buffer->line_off + body_lines >= buffer->line_max)
893 481340cc 2021-03-11 op wprintw(modeline, "Bottom ");
895 481340cc 2021-03-11 op wprintw(modeline, "%.0f%% ", pct);
897 77e9591f 2022-01-13 op wprintw(modeline, "%zu/%zu %s ",
898 65340174 2021-07-21 op buffer->line_off + buffer->curs_y,
899 65340174 2021-07-21 op buffer->line_max,
900 65c49665 2024-01-23 op hist_cur(tab->hist));
902 48e9d457 2021-03-06 op getyx(modeline, y, x);
903 48e9d457 2021-03-06 op getmaxyx(modeline, max_y, max_x);
908 48e9d457 2021-03-06 op for (; x < max_x; ++x)
909 48e9d457 2021-03-06 op waddstr(modeline, "-");
911 ab47e7d4 2021-06-24 op wattr_off(modeline, modeline_face.background, NULL);
915 e9af06b9 2021-07-12 op redraw_minibuffer(void)
917 8a7f2683 2021-07-10 op wattr_on(echoarea, minibuffer_face.background, NULL);
918 8a7f2683 2021-07-10 op werase(echoarea);
920 e9af06b9 2021-07-12 op if (in_minibuffer)
921 e9af06b9 2021-07-12 op do_redraw_minibuffer();
923 e9af06b9 2021-07-12 op do_redraw_echoarea();
925 b1e1e41a 2021-07-14 op if (in_minibuffer == MB_COMPREAD)
926 b1e1e41a 2021-07-14 op do_redraw_minibuffer_compl();
928 e9af06b9 2021-07-12 op wattr_off(echoarea, minibuffer_face.background, NULL);
932 e9af06b9 2021-07-12 op do_redraw_echoarea(void)
934 83dce83d 2021-07-17 op struct vline *vl;
936 17e5106b 2021-03-21 op if (ministate.curmesg != NULL)
937 95a8c791 2021-08-26 op wprintw(echoarea, "%s", ministate.curmesg);
938 e9af06b9 2021-07-12 op else if (*keybuf != '\0')
939 8a7f2683 2021-07-10 op waddstr(echoarea, keybuf);
941 e9af06b9 2021-07-12 op /* If nothing else, show the URL at point */
942 83dce83d 2021-07-17 op vl = current_tab->buffer.current_line;
943 83dce83d 2021-07-17 op if (vl != NULL && vl->parent->type == LINE_LINK)
944 83dce83d 2021-07-17 op waddstr(echoarea, vl->parent->alt);
949 e9af06b9 2021-07-12 op do_redraw_minibuffer(void)
951 738a231a 2021-07-24 op struct buffer *cmplbuf, *buffer;
952 e9af06b9 2021-07-12 op size_t off_y, off_x = 0;
953 e9af06b9 2021-07-12 op const char *start, *c;
956 738a231a 2021-07-24 op cmplbuf = &ministate.compl.buffer;
957 738a231a 2021-07-24 op buffer = &ministate.buffer;
958 738a231a 2021-07-24 op (void)off_y; /* unused, set by getyx */
960 35965938 2021-07-15 op wmove(echoarea, 0, 0);
962 35965938 2021-07-15 op if (in_minibuffer == MB_COMPREAD)
963 77e9591f 2022-01-13 op wprintw(echoarea, "(%2zu) ",
964 738a231a 2021-07-24 op cmplbuf->line_max);
966 35965938 2021-07-15 op wprintw(echoarea, "%s", ministate.prompt);
967 65c49665 2024-01-23 op if (!ministate.editing)
968 e9af06b9 2021-07-12 op wprintw(echoarea, "(%zu/%zu) ",
969 65c49665 2024-01-23 op hist_off(ministate.hist) + 1,
970 65c49665 2024-01-23 op hist_size(ministate.hist));
972 e9af06b9 2021-07-12 op getyx(echoarea, off_y, off_x);
974 65c49665 2024-01-23 op start = ministate.buf;
975 65c49665 2024-01-23 op if (!ministate.editing)
976 65c49665 2024-01-23 op start = hist_cur(ministate.hist);
977 bd4a08a7 2022-11-07 op line = buffer->current_line->parent->line + buffer->current_line->from;
978 6d24bfb3 2024-10-19 op c = line + buffer->point_offset;
979 f853ec6f 2024-10-22 op while (start < c && utf8_swidth_between(start, c, off_x) > (size_t)COLS/2) {
980 1dc96d88 2024-10-19 op start += grapheme_next_character_break_utf8(start, SIZE_MAX);
983 e9af06b9 2021-07-12 op waddstr(echoarea, start);
985 e9af06b9 2021-07-12 op if (ministate.curmesg != NULL)
986 e9af06b9 2021-07-12 op wprintw(echoarea, " [%s]", ministate.curmesg);
988 f853ec6f 2024-10-22 op wmove(echoarea, 0, off_x + utf8_swidth_between(start, c, off_x));
992 b1e1e41a 2021-07-14 op do_redraw_minibuffer_compl(void)
994 0aef305d 2022-01-10 op redraw_window(minibuffer, 0, 10, COLS, 1,
995 b1e1e41a 2021-07-14 op &ministate.compl.buffer);
999 55df859f 2021-07-12 op * Place the cursor in the right ncurses window. If soft is 1, use
1000 4ff12389 2021-07-12 op * wnoutrefresh (which shouldn't cause any I/O); otherwise use
1004 55df859f 2021-07-12 op place_cursor(int soft)
1006 4ff12389 2021-07-12 op int (*touch)(WINDOW *);
1009 55df859f 2021-07-12 op touch = wnoutrefresh;
1011 55df859f 2021-07-12 op touch = wrefresh;
1013 55df859f 2021-07-12 op if (in_minibuffer) {
1014 3b5f459e 2021-11-05 op if (side_window & SIDE_WINDOW_LEFT)
1015 65340174 2021-07-21 op touch(help);
1016 3b5f459e 2021-11-05 op if (side_window & SIDE_WINDOW_BOTTOM)
1017 3b5f459e 2021-11-05 op touch(download);
1018 65340174 2021-07-21 op touch(body);
1019 65340174 2021-07-21 op touch(echoarea);
1020 3b5f459e 2021-11-05 op } else if (in_side_window & SIDE_WINDOW_LEFT) {
1021 55df859f 2021-07-12 op touch(body);
1022 55df859f 2021-07-12 op touch(echoarea);
1023 3b5f459e 2021-11-05 op if (in_side_window & SIDE_WINDOW_BOTTOM)
1024 3b5f459e 2021-11-05 op touch(download);
1025 65340174 2021-07-21 op touch(help);
1026 3b5f459e 2021-11-05 op } else if (in_side_window & SIDE_WINDOW_BOTTOM) {
1027 3b5f459e 2021-11-05 op touch(body);
1028 3b5f459e 2021-11-05 op touch(echoarea);
1029 3b5f459e 2021-11-05 op if (in_side_window & SIDE_WINDOW_LEFT)
1030 65340174 2021-07-21 op touch(help);
1031 3b5f459e 2021-11-05 op touch(download);
1033 3b5f459e 2021-11-05 op if (side_window & SIDE_WINDOW_LEFT)
1034 3b5f459e 2021-11-05 op touch(help);
1035 3b5f459e 2021-11-05 op if (side_window & SIDE_WINDOW_BOTTOM)
1036 3b5f459e 2021-11-05 op touch(download);
1037 55df859f 2021-07-12 op touch(echoarea);
1038 55df859f 2021-07-12 op touch(body);
1043 48e9d457 2021-03-06 op redraw_tab(struct tab *tab)
1045 23f22c83 2021-07-13 op if (too_small)
1048 3b5f459e 2021-11-05 op if (side_window & SIDE_WINDOW_LEFT) {
1049 bddc7bbd 2021-04-01 op redraw_help();
1050 bddc7bbd 2021-04-01 op wnoutrefresh(help);
1053 3b5f459e 2021-11-05 op if (side_window & SIDE_WINDOW_BOTTOM) {
1054 3b5f459e 2021-11-05 op redraw_download();
1055 3b5f459e 2021-11-05 op wnoutrefresh(download);
1058 56168aa8 2021-08-18 op if (show_tab_bar)
1059 56168aa8 2021-08-18 op redraw_tabline();
1061 e19f9a04 2021-03-11 op redraw_body(tab);
1062 e19f9a04 2021-03-11 op redraw_modeline(tab);
1063 e9af06b9 2021-07-12 op redraw_minibuffer();
1065 bddc7bbd 2021-04-01 op wnoutrefresh(tabline);
1066 bddc7bbd 2021-04-01 op wnoutrefresh(modeline);
1068 b1e1e41a 2021-07-14 op if (in_minibuffer == MB_COMPREAD)
1069 b1e1e41a 2021-07-14 op wnoutrefresh(minibuffer);
1071 55df859f 2021-07-12 op place_cursor(1);
1075 9886bf97 2021-07-17 op if (set_title)
1076 47f9af78 2021-08-14 op dprintf(1, "\033]2;%s - Telescope\a",
1077 c1d27b0e 2024-06-14 op current_tab->buffer.title);
1081 8af5e5ed 2021-03-08 op start_loading_anim(struct tab *tab)
1083 2ba66cea 2021-03-22 op if (tab->loading_anim)
1085 2ba66cea 2021-03-22 op tab->loading_anim = 1;
1087 98d3e6c1 2024-02-18 op ev_timer_cancel(tab->loading_timer);
1088 98d3e6c1 2024-02-18 op tab->loading_timer = ev_timer(&loading_tv, update_loading_anim, tab);
1092 98d3e6c1 2024-02-18 op update_loading_anim(int fd, int ev, void *d)
1094 8af5e5ed 2021-03-08 op struct tab *tab = d;
1096 2ba66cea 2021-03-22 op tab->loading_anim_step = (tab->loading_anim_step+1)%4;
1098 83dce83d 2021-07-17 op if (tab == current_tab) {
1099 6347dcd0 2021-03-16 op redraw_modeline(tab);
1100 6347dcd0 2021-03-16 op wrefresh(modeline);
1101 6347dcd0 2021-03-16 op wrefresh(body);
1102 6347dcd0 2021-03-16 op if (in_minibuffer)
1103 8a7f2683 2021-07-10 op wrefresh(echoarea);
1106 98d3e6c1 2024-02-18 op tab->loading_timer = ev_timer(&loading_tv, update_loading_anim, tab);
1110 8af5e5ed 2021-03-08 op stop_loading_anim(struct tab *tab)
1112 2ba66cea 2021-03-22 op if (!tab->loading_anim)
1115 98d3e6c1 2024-02-18 op ev_timer_cancel(tab->loading_timer);
1116 2ba66cea 2021-03-22 op tab->loading_anim = 0;
1117 2ba66cea 2021-03-22 op tab->loading_anim_step = 0;
1119 83dce83d 2021-07-17 op if (tab != current_tab)
1122 43a1b8d0 2021-03-09 op redraw_modeline(tab);
1124 43a1b8d0 2021-03-09 op wrefresh(modeline);
1125 43a1b8d0 2021-03-09 op wrefresh(body);
1126 9ca15951 2021-03-09 op if (in_minibuffer)
1127 8a7f2683 2021-07-10 op wrefresh(echoarea);
1131 ad8e93f5 2024-01-13 op ui_init(void)
1133 5e11c00c 2021-03-02 op setlocale(LC_ALL, "");
1135 1fa16111 2021-08-12 op if (TAILQ_EMPTY(&global_map.m)) {
1136 1fa16111 2021-08-12 op fprintf(stderr, "no keys defined!\n");
1140 4bc446b9 2021-07-21 op minibuffer_init();
1142 3b5f459e 2021-11-05 op /* initialize download window */
1143 3b5f459e 2021-11-05 op TAILQ_INIT(&downloadwin.head);
1144 c1d27b0e 2024-06-14 op TAILQ_INIT(&downloadwin.vhead);
1146 bddc7bbd 2021-04-01 op /* initialize help window */
1147 bddc7bbd 2021-04-01 op TAILQ_INIT(&helpwin.head);
1148 c1d27b0e 2024-06-14 op TAILQ_INIT(&helpwin.vhead);
1150 9ca15951 2021-03-09 op base_map = &global_map;
1151 f832146f 2021-03-09 op current_map = &global_map;
1155 74a2587f 2021-06-21 op if (enable_colors) {
1156 74a2587f 2021-06-21 op if (has_colors()) {
1157 74a2587f 2021-06-21 op start_color();
1158 160abe04 2021-06-21 op use_default_colors();
1160 74a2587f 2021-06-21 op enable_colors = 0;
1163 42d61f50 2021-06-24 op config_apply_style();
1168 5e11c00c 2021-03-02 op intrflush(stdscr, FALSE);
1170 3cea4ff5 2021-08-18 op if ((tabline = newwin(1, 1, 0, 0)) == NULL)
1172 3cea4ff5 2021-08-18 op if ((body = newwin(1, 1, 0, 0)) == NULL)
1174 3cea4ff5 2021-08-18 op if ((modeline = newwin(1, 1, 0, 0)) == NULL)
1176 3cea4ff5 2021-08-18 op if ((echoarea = newwin(1, 1, 0, 0)) == NULL)
1178 3cea4ff5 2021-08-18 op if ((minibuffer = newwin(1, 1, 0, 0)) == NULL)
1180 3b5f459e 2021-11-05 op if ((download = newwin(1, 1, 0, 0)) == NULL)
1182 3cea4ff5 2021-08-18 op if ((help = newwin(1, 1, 0, 0)) == NULL)
1185 b598590d 2021-06-21 op wbkgd(body, body_face.body);
1186 1577540c 2021-11-05 op wbkgd(download, download_face.background);
1187 8a7f2683 2021-07-10 op wbkgd(echoarea, minibuffer_face.background);
1189 72b18268 2021-06-19 op update_x_offset();
1191 43a1b8d0 2021-03-09 op keypad(body, TRUE);
1192 f3bcf8f2 2021-06-21 op scrollok(body, FALSE);
1194 5e11c00c 2021-03-02 op /* non-blocking input */
1195 48e9d457 2021-03-06 op wtimeout(body, 0);
1196 65340174 2021-07-21 op wtimeout(help, 0);
1198 12ba5e21 2024-02-19 op wmove(body, 0, 0);
1204 bb28f1c2 2021-12-30 op ui_main_loop(void)
1206 329cd624 2024-06-15 op if (ev_signal(SIGWINCH, handle_signal, NULL) == -1 ||
1207 329cd624 2024-06-15 op ev_signal(SIGCHLD, handle_signal, NULL) == -1 ||
1208 98d3e6c1 2024-02-18 op ev_add(0, EV_READ, dispatch_stdio, NULL) == -1)
1209 98d3e6c1 2024-02-18 op err(1, "ev_signal or ev_add failed");
1211 2ddbda6b 2021-07-17 op switch_to_tab(current_tab);
1212 3cea4ff5 2021-08-18 op rearrange_windows();
1218 8af5e5ed 2021-03-08 op ui_on_tab_loaded(struct tab *tab)
1220 65c49665 2024-01-23 op size_t line_off, curr_off;
1222 8af5e5ed 2021-03-08 op stop_loading_anim(tab);
1223 65c49665 2024-01-23 op message("Loaded %s", hist_cur(tab->hist));
1225 65c49665 2024-01-23 op hist_cur_offs(tab->hist, &line_off, &curr_off);
1226 65c49665 2024-01-23 op if (curr_off != 0 &&
1227 c1d27b0e 2024-06-14 op tab->buffer.current_line == TAILQ_FIRST(&tab->buffer.vhead)) {
1228 65c49665 2024-01-23 op set_scroll_position(tab, line_off, curr_off);
1229 e795e935 2022-01-18 op redraw_tab(tab);
1233 56168aa8 2021-08-18 op if (show_tab_bar)
1234 56168aa8 2021-08-18 op redraw_tabline();
1236 3d8c2326 2021-03-18 op wrefresh(tabline);
1237 55df859f 2021-07-12 op place_cursor(0);
1241 5e11c00c 2021-03-02 op ui_on_tab_refresh(struct tab *tab)
1243 f853ec6f 2024-10-22 op wrap_page(&tab->buffer, body_cols, x_offset);
1244 83dce83d 2021-07-17 op if (tab == current_tab)
1245 3d8c2326 2021-03-18 op redraw_tab(tab);
1247 e8a76665 2021-05-12 op tab->flags |= TAB_URGENT;
1251 7a7f8f40 2024-10-22 op ui_force_tab_refresh(struct tab *tab)
1253 7a7f8f40 2024-10-22 op switch_to_tab(tab);
1254 7a7f8f40 2024-10-22 op rearrange_windows();
1255 7a7f8f40 2024-10-22 op redraw_tab(tab);
1259 fcd99a0d 2021-11-05 op ui_on_download_refresh(void)
1261 98d3e6c1 2024-02-18 op if (ev_timer_pending(download_timer))
1264 98d3e6c1 2024-02-18 op download_timer = ev_timer(&download_refresh_timer,
1265 98d3e6c1 2024-02-18 op handle_download_refresh, NULL);
1269 2f0ffab4 2024-06-22 op open_download(int res, void *data)
1271 2f0ffab4 2024-06-22 op struct download *d = data;
1272 7b7a69f2 2024-06-13 thomas.ad struct mailcap *mc = NULL;
1273 329cd624 2024-06-15 op enum exec_mode mode = EXEC_BACKGROUND;
1276 7b7a69f2 2024-06-13 thomas.ad return;
1278 2f0ffab4 2024-06-22 op if ((mc = mailcap_cmd_from_mimetype(d->mime_type, d->path)) == NULL)
1281 329cd624 2024-06-15 op if (mc->flags & MAILCAP_NEEDSTERMINAL)
1282 329cd624 2024-06-15 op mode = EXEC_FOREGROUND;
1284 2f0ffab4 2024-06-22 op message("Loaded %s with %s", d->mime_type, mc->cmd_argv[0]);
1285 0548291a 2024-06-25 op exec_cmd(mc->cmd_argv, mode);
1289 2f0ffab4 2024-06-22 op ui_prompt_download_cmd(struct download *d)
1291 2f0ffab4 2024-06-22 op char prompt[64];
1293 2f0ffab4 2024-06-22 op snprintf(prompt, sizeof(prompt), "Open %s?", d->path);
1294 2f0ffab4 2024-06-22 op ui_yornp(prompt, open_download, d);
1298 0a987358 2022-02-24 op ui_remotely_open_link(const char *uri)
1300 0a987358 2022-02-24 op new_tab(uri, NULL, NULL);
1301 0a987358 2022-02-24 op ui_on_tab_refresh(current_tab);
1303 0a987358 2022-02-24 op /* ring the bell */
1304 0a987358 2022-02-24 op printf("\a");
1305 0a987358 2022-02-24 op fflush(stdout);
1308 2b2d2872 2021-06-20 op const char *
1309 2b2d2872 2021-06-20 op ui_keyname(int k)
1311 2b2d2872 2021-06-20 op return keyname(k);
1315 3b5f459e 2021-11-05 op ui_toggle_side_window(int kind)
1317 3b5f459e 2021-11-05 op if (in_side_window & kind)
1318 3b5f459e 2021-11-05 op ui_other_window();
1320 3b5f459e 2021-11-05 op side_window ^= kind;
1321 3b5f459e 2021-11-05 op if (side_window & SIDE_WINDOW_LEFT)
1322 2b2d2872 2021-06-20 op recompute_help();
1323 3b5f459e 2021-11-05 op if (side_window & SIDE_WINDOW_BOTTOM)
1324 3b5f459e 2021-11-05 op recompute_downloads();
1327 960b01da 2021-06-20 op * ugly hack, but otherwise the window doesn't get updated
1328 32c6c75e 2021-07-15 op * until I call rearrange_windows a second time (e.g. via
1329 32c6c75e 2021-07-15 op * C-l). I will be happy to know why something like this is
1332 32c6c75e 2021-07-15 op rearrange_windows();
1333 32c6c75e 2021-07-15 op rearrange_windows();
1337 fcd99a0d 2021-11-05 op ui_show_downloads_pane(void)
1339 fcd99a0d 2021-11-05 op if (!(side_window & SIDE_WINDOW_BOTTOM))
1340 fcd99a0d 2021-11-05 op ui_toggle_side_window(SIDE_WINDOW_BOTTOM);
1344 2b2d2872 2021-06-20 op ui_schedule_redraw(void)
1346 32c6c75e 2021-07-15 op should_rearrange_windows = 1;
1350 0fceedb5 2024-06-07 op ui_require_input(struct tab *tab, int hide, void (*fn)(const char *))
1352 dfd1efcc 2024-06-23 op struct minibuffer m = {
1353 dfd1efcc 2024-06-23 op .self_insert = sensible_self_insert,
1355 dfd1efcc 2024-06-23 op .history = ir_history,
1358 5cd2ebb1 2021-03-11 op /* TODO: hard-switching to another tab is ugly */
1359 5cd2ebb1 2021-03-11 op switch_to_tab(tab);
1361 dfd1efcc 2024-06-23 op enter_minibuffer(&m, "Input required: ");
1362 5cd2ebb1 2021-03-11 op redraw_tab(tab);
1366 4bc446b9 2021-07-21 op ui_after_message_hook(void)
1368 4bc446b9 2021-07-21 op redraw_minibuffer();
1369 4bc446b9 2021-07-21 op place_cursor(0);
1373 057e7eb6 2024-06-22 op ui_yornp(const char *prompt, void (*fn)(int, void *), void *data)
1375 84b88039 2021-07-12 op yornp(prompt, fn, data);
1376 83dce83d 2021-07-17 op redraw_tab(current_tab);
1380 d1353324 2021-07-13 op ui_read(const char *prompt, void (*fn)(const char*, struct tab *),
1381 bb9912eb 2021-08-29 op struct tab *data, const char *input)
1383 479b240a 2024-06-25 op minibuffer_read(prompt, fn, data, input);
1384 83dce83d 2021-07-17 op redraw_tab(current_tab);
1388 65340174 2021-07-21 op ui_other_window(void)
1390 3b5f459e 2021-11-05 op if (in_side_window & SIDE_WINDOW_LEFT &&
1391 3b5f459e 2021-11-05 op side_window & SIDE_WINDOW_BOTTOM)
1392 3b5f459e 2021-11-05 op in_side_window = SIDE_WINDOW_BOTTOM;
1393 3b5f459e 2021-11-05 op else if (in_side_window)
1394 3b5f459e 2021-11-05 op in_side_window = 0;
1395 3b5f459e 2021-11-05 op else if (!in_side_window && side_window & SIDE_WINDOW_LEFT)
1396 3b5f459e 2021-11-05 op in_side_window = SIDE_WINDOW_LEFT;
1397 3b5f459e 2021-11-05 op else if (!in_side_window && side_window)
1398 3b5f459e 2021-11-05 op in_side_window = SIDE_WINDOW_BOTTOM;
1400 65340174 2021-07-21 op message("No other window to select");
1404 8a3b5609 2021-07-15 op ui_suspend(void)
1410 0548291a 2024-06-25 op ui_resume(void)
1414 8a3b5609 2021-07-15 op rearrange_windows();
1418 5e11c00c 2021-03-02 op ui_end(void)
1420 4e32d3a6 2024-06-04 thomas.ad endwin();