2 * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 * Ncurses UI for telescope.
23 * ncurses allows you to scroll a window, but when a line goes out of
24 * the visible area it's forgotten. We keep a list of formatted lines
25 * (``visual lines'') that we know fits in the window, and draw them.
27 * This means that on every resize we have to clear our list of lines
28 * and re-render everything. A clever approach would be to do this
29 * ``on-demand'', but it's still missing.
45 #include "minibuffer.h"
47 #include "telescope.h"
51 static struct event stdioev, winchev;
53 static void restore_curs_x(struct buffer *);
55 static int readkey(void);
56 static void dispatch_stdio(int, short, void*);
57 static void handle_resize(int, short, void*);
58 static void handle_resize_nodelay(int, short, void*);
59 static void rearrange_windows(void);
60 static void line_prefix_and_text(struct vline *, char *, size_t, const char **, const char **);
61 static void print_vline(int, int, WINDOW*, struct vline*);
62 static void redraw_tabline(void);
63 static void redraw_window(WINDOW*, int, int, int, struct buffer*);
64 static void redraw_download(void);
65 static void redraw_help(void);
66 static void redraw_body(struct tab*);
67 static void redraw_modeline(struct tab*);
68 static void redraw_minibuffer(void);
69 static void do_redraw_echoarea(void);
70 static void do_redraw_minibuffer(void);
71 static void do_redraw_minibuffer_compl(void);
72 static void place_cursor(int);
73 static void redraw_tab(struct tab*);
74 static void update_loading_anim(int, short, void*);
75 static void stop_loading_anim(struct tab*);
77 static int should_rearrange_windows;
78 static int show_tab_bar;
82 struct thiskey thiskey;
83 struct tab *current_tab;
85 static struct event resizeev;
86 static struct timeval resize_timer = { 0, 250000 };
88 static WINDOW *tabline, *body, *modeline, *echoarea, *minibuffer;
90 int body_lines, body_cols;
93 /* not static so we can see them from help.c */
94 struct buffer helpwin;
95 int help_lines, help_cols;
97 static WINDOW *download;
98 /* not static so we can see them from download.c */
99 struct buffer downloadwin;
102 static int side_window;
103 static int in_side_window;
105 static struct timeval loadingev_timer = { 0, 250000 };
107 static char keybuf[64];
109 /* XXX: don't forget to init these in main() */
110 struct kmap global_map,
116 update_x_offset(void)
118 if (olivetti_mode && fill_column < body_cols)
119 x_offset = (body_cols - fill_column)/2;
125 save_excursion(struct excursion *place, struct buffer *buffer)
127 place->curs_x = buffer->curs_x;
128 place->curs_y = buffer->curs_y;
129 place->line_off = buffer->line_off;
130 place->top_line = buffer->top_line;
131 place->current_line = buffer->current_line;
132 place->cpoff = buffer->cpoff;
136 restore_excursion(struct excursion *place, struct buffer *buffer)
138 buffer->curs_x = place->curs_x;
139 buffer->curs_y = place->curs_y;
140 buffer->line_off = place->line_off;
141 buffer->top_line = place->top_line;
142 buffer->current_line = place->current_line;
143 buffer->cpoff = place->cpoff;
147 restore_curs_x(struct buffer *buffer)
150 const char *prfx, *text;
152 vl = buffer->current_line;
153 if (vl == NULL || vl->line == NULL)
154 buffer->curs_x = buffer->cpoff = 0;
155 else if (vl->parent->data != NULL) {
156 text = vl->parent->data;
157 buffer->curs_x = utf8_snwidth(text + 1, buffer->cpoff) + 1;
159 buffer->curs_x = utf8_snwidth(vl->line, buffer->cpoff);
161 /* small hack: don't olivetti-mode the download pane */
162 if (buffer != &downloadwin)
163 buffer->curs_x += x_offset;
168 if (vl->parent->data != NULL)
169 buffer->curs_x += utf8_swidth_between(vl->parent->line,
172 prfx = line_prefixes[vl->parent->type].prfx1;
173 buffer->curs_x += utf8_swidth(prfx);
178 global_key_unbound(void)
180 message("%s is undefined", keybuf);
187 return &ministate.buffer;
188 if (in_side_window & SIDE_WINDOW_LEFT)
190 if (in_side_window & SIDE_WINDOW_BOTTOM)
192 return ¤t_tab->buffer;
200 if ((thiskey.key = wgetch(body)) == ERR)
203 thiskey.meta = thiskey.key == 27;
205 thiskey.key = wgetch(body);
206 if (thiskey.key == ERR || thiskey.key == 27) {
214 if ((unsigned int)thiskey.key >= UINT8_MAX)
218 if (!utf8_decode(&state, &thiskey.cp, (uint8_t)thiskey.key))
220 if ((thiskey.key = wgetch(body)) == ERR) {
221 message("Error decoding user input");
230 dispatch_stdio(int fd, short ev, void *d)
236 /* TODO: schedule a redraw? */
243 if (keybuf[0] != '\0')
244 strlcat(keybuf, " ", sizeof(keybuf));
246 strlcat(keybuf, "M-", sizeof(keybuf));
247 if (thiskey.cp != 0) {
248 utf8_encode(thiskey.cp, tmp);
249 strlcat(keybuf, tmp, sizeof(keybuf));
250 } else if ((keyname = unkbd(thiskey.key)) != NULL) {
251 strlcat(keybuf, keyname, sizeof(keybuf));
253 tmp[0] = thiskey.key;
254 strlcat(keybuf, tmp, sizeof(keybuf));
257 TAILQ_FOREACH(k, ¤t_map->m, keymaps) {
258 if (k->meta == thiskey.meta &&
259 k->key == thiskey.key) {
261 current_map = &k->map;
263 current_map = base_map;
264 strlcpy(keybuf, "", sizeof(keybuf));
265 k->fn(current_buffer());
271 if (current_map->unhandled_input != NULL)
272 current_map->unhandled_input();
274 global_key_unbound();
276 strlcpy(keybuf, "", sizeof(keybuf));
277 current_map = base_map;
280 if (side_window & SIDE_WINDOW_LEFT)
283 if (should_rearrange_windows)
285 redraw_tab(current_tab);
289 handle_resize(int sig, short ev, void *d)
291 if (event_pending(&resizeev, EV_TIMEOUT, NULL)) {
292 event_del(&resizeev);
294 evtimer_set(&resizeev, handle_resize_nodelay, NULL);
295 evtimer_add(&resizeev, &resize_timer);
299 handle_resize_nodelay(int s, short ev, void *d)
309 should_show_tab_bar(void)
311 if (tab_bar_show == -1)
313 if (tab_bar_show == 0)
316 return TAILQ_NEXT(TAILQ_FIRST(&tabshead), tabs) != NULL;
320 rearrange_windows(void)
323 int minibuffer_lines;
325 should_rearrange_windows = 0;
326 show_tab_bar = should_show_tab_bar();
330 /* 3 lines for the ui and 12 for the */
331 if ((too_small = lines < 15)) {
333 printw("Window too small.");
338 /* move and resize the windows, in reverse order! */
340 if (in_minibuffer == MB_COMPREAD) {
341 minibuffer_lines = MIN(10, lines/2);
342 mvwin(minibuffer, lines - minibuffer_lines, 0);
343 wresize(minibuffer, minibuffer_lines, COLS);
344 lines -= minibuffer_lines;
346 wrap_page(&ministate.compl.buffer, COLS);
349 mvwin(echoarea, --lines, 0);
350 wresize(echoarea, 1, COLS);
352 mvwin(modeline, --lines, 0);
353 wresize(modeline, 1, COLS);
355 if (side_window & SIDE_WINDOW_BOTTOM) {
356 download_lines = MIN(5, lines/2);
357 mvwin(download, lines - download_lines, 0);
358 wresize(download, download_lines, COLS);
359 lines -= download_lines;
361 wrap_page(&downloadwin, COLS);
364 body_lines = show_tab_bar ? --lines : lines;
368 * Here we make the assumption that show_tab_bar is either 0
369 * or 1, and reuse that as argument to mvwin.
371 if (side_window & SIDE_WINDOW_LEFT) {
372 help_cols = 0.3 * COLS;
374 mvwin(help, show_tab_bar, 0);
375 wresize(help, help_lines, help_cols);
377 wrap_page(&helpwin, help_cols);
379 body_cols = COLS - help_cols - 1;
380 mvwin(body, show_tab_bar, help_cols);
382 mvwin(body, show_tab_bar, 0);
385 wresize(body, body_lines, body_cols);
388 wresize(tabline, 1, COLS);
390 wrap_page(¤t_tab->buffer, body_cols);
391 redraw_tab(current_tab);
395 line_prefix_and_text(struct vline *vl, char *buf, size_t len,
396 const char **prfx_ret, const char **text_ret)
398 int type, i, cont, width;
401 if ((*text_ret = vl->line) == NULL)
404 cont = vl->flags & L_CONTINUATION;
405 type = vl->parent->type;
407 *prfx_ret = line_prefixes[type].prfx1;
409 *prfx_ret = line_prefixes[type].prfx2;
411 space = vl->parent->data;
412 if (!emojify_link || type != LINE_LINK || space == NULL)
417 width = utf8_swidth_between(vl->parent->line, space);
418 for (i = 0; i < width + 1; ++i)
419 strlcat(buf, " ", len);
421 strlcpy(buf, *text_ret, len);
422 if ((t = strchr(buf, ' ')) != NULL)
424 strlcat(buf, " ", len);
427 *text_ret += (space - vl->parent->line) + 1;
434 print_vline_descr(int width, WINDOW *window, struct vline *vl)
438 if (vl->parent->type != LINE_COMPL &&
439 vl->parent->type != LINE_COMPL_CURRENT &&
440 vl->parent->type != LINE_HELP &&
441 vl->parent->type != LINE_DOWNLOAD &&
442 vl->parent->type != LINE_DOWNLOAD_DONE &&
443 vl->parent->type != LINE_DOWNLOAD_INFO)
446 if (vl->parent->alt == NULL)
452 switch (vl->parent->type) {
455 case LINE_DOWNLOAD_DONE:
456 case LINE_DOWNLOAD_INFO:
464 wprintw(window, " ");
465 for (; goal > x; ++x)
466 wprintw(window, " ");
468 wprintw(window, "%s", vl->parent->alt);
472 * Core part of the rendering. It prints a vline starting from the
473 * current cursor position. Printing a vline consists of skipping
474 * `off' columns (for olivetti-mode), print the correct prefix (which
475 * may be the emoji in case of emojified links-lines), printing the
476 * text itself, filling until width - off and filling off columns
480 print_vline(int off, int width, WINDOW *window, struct vline *vl)
483 * Believe me or not, I've seen emoji ten code points long!
484 * That means, to stay large, 4*10 bytes + NUL.
486 char emojibuf[41] = {0};
487 const char *text, *prfx;
491 f = &line_faces[vl->parent->type];
493 /* unused, set by getyx */
496 line_prefix_and_text(vl, emojibuf, sizeof(emojibuf), &prfx, &text);
498 wattr_on(window, body_face.left, NULL);
499 for (i = 0; i < off; i++)
501 wattr_off(window, body_face.left, NULL);
503 wattr_on(window, f->prefix, NULL);
504 wprintw(window, "%s", prfx);
505 wattr_off(window, f->prefix, NULL);
507 wattr_on(window, f->text, NULL);
508 wprintw(window, "%s", text);
509 print_vline_descr(width, window, vl);
510 wattr_off(window, f->text, NULL);
516 wattr_on(window, f->trail, NULL);
517 for (i = 0; i < left - off; ++i)
519 wattr_off(window, f->trail, NULL);
521 wattr_on(window, body_face.right, NULL);
522 for (i = 0; i < off; i++)
524 wattr_off(window, body_face.right, NULL);
532 size_t toskip, ots, tabwidth, space, x;
533 int current, y, truncated, pair;
539 /* unused, but setted by a getyx */
542 tabwidth = sizeof(buf)+1;
546 TAILQ_FOREACH(tab, &tabshead, tabs) {
548 if (tab == current_tab)
552 if (toskip * tabwidth < space)
557 while (toskip != 0 &&
558 (ots - toskip+1) * tabwidth < space)
563 wattr_on(tabline, tab_face.background, NULL);
564 wprintw(tabline, toskip == 0 ? " " : "<");
565 wattr_off(tabline, tab_face.background, NULL);
568 TAILQ_FOREACH(tab, &tabshead, tabs) {
576 getyx(tabline, y, x);
577 if (x + sizeof(buf)+2 >= (size_t)COLS)
580 current = tab == current_tab;
582 if (*(title = tab->buffer.page.title) == '\0')
583 title = tab->hist_cur->h;
585 if (tab->flags & TAB_URGENT)
586 strlcpy(buf, "!", sizeof(buf));
588 strlcpy(buf, " ", sizeof(buf));
590 if (strlcat(buf, title, sizeof(buf)) >= sizeof(buf)) {
591 /* truncation happens */
592 strlcpy(&buf[sizeof(buf)-4], "...", 4);
594 /* pad with spaces */
595 while (strlcat(buf, " ", sizeof(buf)) < sizeof(buf))
599 pair = current ? tab_face.current : tab_face.tab;
600 wattr_on(tabline, pair, NULL);
601 wprintw(tabline, "%s", buf);
602 wattr_off(tabline, pair, NULL);
604 wattr_on(tabline, tab_face.background, NULL);
605 if (TAILQ_NEXT(tab, tabs) != NULL)
606 wprintw(tabline, "┃");
607 wattr_off(tabline, tab_face.background, NULL);
610 wattr_on(tabline, tab_face.background, NULL);
611 for (; x < (size_t)COLS; ++x)
612 waddch(tabline, ' ');
614 mvwprintw(tabline, 0, COLS-1, ">");
615 wattr_off(tabline, tab_face.background, NULL);
619 * Compute the first visible line around vl. Try to search forward
620 * until the end of the buffer; if a visible line is not found, search
621 * backward. Return NULL if no viable line was found.
624 adjust_line(struct vline *vl, struct buffer *buffer)
631 if (!(vl->parent->flags & L_HIDDEN))
636 t != NULL && t->parent->flags & L_HIDDEN;
637 t = TAILQ_NEXT(t, vlines))
643 /* search backward */
645 t != NULL && t->parent->flags & L_HIDDEN;
646 t = TAILQ_PREV(t, vhead, vlines))
653 redraw_window(WINDOW *win, int off, int height, int width,
654 struct buffer *buffer)
659 restore_curs_x(buffer);
662 * TODO: ignoring buffer->force_update and always
663 * re-rendering. In theory we can recompute the y position
664 * without a re-render, and optimize here. It's not the only
665 * optimisation possible here, wscrl wolud also be an
673 if (TAILQ_EMPTY(&buffer->head))
676 if (buffer->top_line == NULL)
677 buffer->top_line = TAILQ_FIRST(&buffer->head);
679 buffer->top_line = adjust_line(buffer->top_line, buffer);
680 if (buffer->top_line == NULL)
683 buffer->current_line = adjust_line(buffer->current_line, buffer);
687 for (vl = buffer->top_line; vl != NULL; vl = TAILQ_NEXT(vl, vlines)) {
688 if (vl->parent->flags & L_HIDDEN)
692 print_vline(off, width, win, vl);
694 if (vl == buffer->current_line)
706 for (; vl != NULL; vl = TAILQ_NEXT(vl, vlines)) {
707 if (vl == buffer->current_line)
709 if (vl->parent->flags & L_HIDDEN)
712 buffer->top_line = TAILQ_NEXT(buffer->top_line, vlines);
719 buffer->last_line_off = buffer->line_off;
720 buffer->force_redraw = 0;
722 wmove(win, buffer->curs_y, buffer->curs_x);
726 redraw_download(void)
728 redraw_window(download, 0, download_lines, COLS, &downloadwin);
734 redraw_window(help, 0, help_lines, help_cols, &helpwin);
738 redraw_body(struct tab *tab)
740 static struct tab *last_tab;
743 tab->buffer.force_redraw =1;
746 redraw_window(body, x_offset, body_lines, body_cols, &tab->buffer);
750 trust_status_char(enum trust_state ts)
753 case TS_UNKNOWN: return '-';
754 case TS_UNTRUSTED: return '!';
755 case TS_TEMP_TRUSTED: return '!';
756 case TS_TRUSTED: return 'v';
757 case TS_VERIFIED: return 'V';
763 redraw_modeline(struct tab *tab)
765 struct buffer *buffer;
767 int x, y, max_x, max_y;
769 const char *spin = "-\\|/";
771 buffer = current_buffer();
772 mode = buffer->page.name;
775 wattr_on(modeline, modeline_face.background, NULL);
776 wmove(modeline, 0, 0);
778 wprintw(modeline, "-%c%c %s ",
779 spin[tab->loading_anim_step],
780 trust_status_char(tab->trust),
781 mode == NULL ? "(none)" : mode);
783 pct = (buffer->line_off + buffer->curs_y) * 100.0
786 if (buffer->line_max <= (size_t)body_lines)
787 wprintw(modeline, "All ");
788 else if (buffer->line_off == 0)
789 wprintw(modeline, "Top ");
790 else if (buffer->line_off + body_lines >= buffer->line_max)
791 wprintw(modeline, "Bottom ");
793 wprintw(modeline, "%.0f%% ", pct);
795 wprintw(modeline, "%d/%d %s ",
796 buffer->line_off + buffer->curs_y,
800 getyx(modeline, y, x);
801 getmaxyx(modeline, max_y, max_x);
806 for (; x < max_x; ++x)
807 waddstr(modeline, "-");
809 wattr_off(modeline, modeline_face.background, NULL);
813 redraw_minibuffer(void)
815 wattr_on(echoarea, minibuffer_face.background, NULL);
819 do_redraw_minibuffer();
821 do_redraw_echoarea();
823 if (in_minibuffer == MB_COMPREAD)
824 do_redraw_minibuffer_compl();
826 wattr_off(echoarea, minibuffer_face.background, NULL);
830 do_redraw_echoarea(void)
834 if (ministate.curmesg != NULL)
835 wprintw(echoarea, "%s", ministate.curmesg);
836 else if (*keybuf != '\0')
837 waddstr(echoarea, keybuf);
839 /* If nothing else, show the URL at point */
840 vl = current_tab->buffer.current_line;
841 if (vl != NULL && vl->parent->type == LINE_LINK)
842 waddstr(echoarea, vl->parent->alt);
847 do_redraw_minibuffer(void)
849 struct buffer *cmplbuf, *buffer;
850 size_t off_y, off_x = 0;
851 const char *start, *c;
853 cmplbuf = &ministate.compl.buffer;
854 buffer = &ministate.buffer;
855 (void)off_y; /* unused, set by getyx */
857 wmove(echoarea, 0, 0);
859 if (in_minibuffer == MB_COMPREAD)
860 wprintw(echoarea, "(%2d) ",
863 wprintw(echoarea, "%s", ministate.prompt);
864 if (ministate.hist_cur != NULL)
865 wprintw(echoarea, "(%zu/%zu) ",
866 ministate.hist_off + 1,
867 ministate.history->len);
869 getyx(echoarea, off_y, off_x);
871 start = ministate.hist_cur != NULL
872 ? ministate.hist_cur->h
874 c = utf8_nth(buffer->current_line->line, buffer->cpoff);
875 while (utf8_swidth_between(start, c) > (size_t)COLS/2) {
876 start = utf8_next_cp(start);
879 waddstr(echoarea, start);
881 if (ministate.curmesg != NULL)
882 wprintw(echoarea, " [%s]", ministate.curmesg);
884 wmove(echoarea, 0, off_x + utf8_swidth_between(start, c));
888 do_redraw_minibuffer_compl(void)
890 redraw_window(minibuffer, 0, 10, COLS,
891 &ministate.compl.buffer);
895 * Place the cursor in the right ncurses window. If soft is 1, use
896 * wnoutrefresh (which shouldn't cause any I/O); otherwise use
900 place_cursor(int soft)
902 int (*touch)(WINDOW *);
905 touch = wnoutrefresh;
910 if (side_window & SIDE_WINDOW_LEFT)
912 if (side_window & SIDE_WINDOW_BOTTOM)
916 } else if (in_side_window & SIDE_WINDOW_LEFT) {
919 if (in_side_window & SIDE_WINDOW_BOTTOM)
922 } else if (in_side_window & SIDE_WINDOW_BOTTOM) {
925 if (in_side_window & SIDE_WINDOW_LEFT)
929 if (side_window & SIDE_WINDOW_LEFT)
931 if (side_window & SIDE_WINDOW_BOTTOM)
939 redraw_tab(struct tab *tab)
944 if (side_window & SIDE_WINDOW_LEFT) {
949 if (side_window & SIDE_WINDOW_BOTTOM) {
951 wnoutrefresh(download);
958 redraw_modeline(tab);
961 wnoutrefresh(tabline);
962 wnoutrefresh(modeline);
964 if (in_minibuffer == MB_COMPREAD)
965 wnoutrefresh(minibuffer);
972 dprintf(1, "\033]2;%s - Telescope\a",
973 current_tab->buffer.page.title);
977 start_loading_anim(struct tab *tab)
979 if (tab->loading_anim)
981 tab->loading_anim = 1;
982 evtimer_set(&tab->loadingev, update_loading_anim, tab);
983 evtimer_add(&tab->loadingev, &loadingev_timer);
987 update_loading_anim(int fd, short ev, void *d)
991 tab->loading_anim_step = (tab->loading_anim_step+1)%4;
993 if (tab == current_tab) {
994 redraw_modeline(tab);
1001 evtimer_add(&tab->loadingev, &loadingev_timer);
1005 stop_loading_anim(struct tab *tab)
1007 if (!tab->loading_anim)
1009 evtimer_del(&tab->loadingev);
1010 tab->loading_anim = 0;
1011 tab->loading_anim_step = 0;
1013 if (tab != current_tab)
1016 redraw_modeline(tab);
1025 ui_print_colors(void)
1027 int colors = 0, pairs = 0, can_change = 0;
1028 int columns = 16, lines, color, i, j;
1033 use_default_colors();
1036 pairs = COLOR_PAIRS;
1037 can_change = can_change_color();
1041 printf("Term info:\n");
1042 printf("TERM=%s COLORS=%d COLOR_PAIRS=%d can_change_colors=%d\n",
1043 getenv("TERM"), colors, pairs, can_change);
1047 printf("No color support\n");
1051 printf("Available colors:\n\n");
1052 lines = (colors - 1) / columns + 1;
1054 for (i = 0; i < lines; ++i) {
1055 for (j = 0; j < columns; ++j, ++color) {
1056 printf("\033[0;38;5;%dm %03d", color, color);
1069 setlocale(LC_ALL, "");
1071 if (TAILQ_EMPTY(&global_map.m)) {
1072 fprintf(stderr, "no keys defined!\n");
1078 /* initialize download window */
1079 TAILQ_INIT(&downloadwin.head);
1080 TAILQ_INIT(&downloadwin.page.head);
1082 /* initialize help window */
1083 TAILQ_INIT(&helpwin.head);
1084 TAILQ_INIT(&helpwin.page.head);
1086 base_map = &global_map;
1087 current_map = &global_map;
1091 if (enable_colors) {
1094 use_default_colors();
1099 config_apply_style();
1104 intrflush(stdscr, FALSE);
1106 if ((tabline = newwin(1, 1, 0, 0)) == NULL)
1108 if ((body = newwin(1, 1, 0, 0)) == NULL)
1110 if ((modeline = newwin(1, 1, 0, 0)) == NULL)
1112 if ((echoarea = newwin(1, 1, 0, 0)) == NULL)
1114 if ((minibuffer = newwin(1, 1, 0, 0)) == NULL)
1116 if ((download = newwin(1, 1, 0, 0)) == NULL)
1118 if ((help = newwin(1, 1, 0, 0)) == NULL)
1121 wbkgd(body, body_face.body);
1122 wbkgd(download, download_face.background);
1123 wbkgd(echoarea, minibuffer_face.background);
1128 scrollok(body, FALSE);
1130 /* non-blocking input */
1134 mvwprintw(body, 0, 0, "");
1136 evtimer_set(&resizeev, handle_resize, NULL);
1138 event_set(&stdioev, 0, EV_READ | EV_PERSIST, dispatch_stdio, NULL);
1139 event_add(&stdioev, NULL);
1141 signal_set(&winchev, SIGWINCH, handle_resize, NULL);
1142 signal_add(&winchev, NULL);
1150 switch_to_tab(current_tab);
1151 rearrange_windows();
1157 ui_on_tab_loaded(struct tab *tab)
1159 stop_loading_anim(tab);
1160 message("Loaded %s", tab->hist_cur->h);
1170 ui_on_tab_refresh(struct tab *tab)
1172 wrap_page(&tab->buffer, body_cols);
1173 if (tab == current_tab)
1176 tab->flags |= TAB_URGENT;
1186 ui_toggle_side_window(int kind)
1188 if (in_side_window & kind)
1191 side_window ^= kind;
1192 if (side_window & SIDE_WINDOW_LEFT)
1194 if (side_window & SIDE_WINDOW_BOTTOM)
1195 recompute_downloads();
1198 * ugly hack, but otherwise the window doesn't get updated
1199 * until I call rearrange_windows a second time (e.g. via
1200 * C-l). I will be happy to know why something like this is
1203 rearrange_windows();
1204 rearrange_windows();
1208 ui_schedule_redraw(void)
1210 should_rearrange_windows = 1;
1214 ui_require_input(struct tab *tab, int hide, int proto)
1218 if (proto == PROTO_GEMINI)
1219 fn = ir_select_gemini;
1220 else if (proto == PROTO_GOPHER)
1221 fn = ir_select_gopher;
1225 /* TODO: hard-switching to another tab is ugly */
1228 enter_minibuffer(sensible_self_insert, fn, exit_minibuffer,
1229 &ir_history, NULL, NULL);
1230 strlcpy(ministate.prompt, "Input required: ",
1231 sizeof(ministate.prompt));
1236 ui_after_message_hook(void)
1238 redraw_minibuffer();
1243 ui_yornp(const char *prompt, void (*fn)(int, struct tab *),
1246 yornp(prompt, fn, data);
1247 redraw_tab(current_tab);
1251 ui_read(const char *prompt, void (*fn)(const char*, struct tab *),
1252 struct tab *data, const char *input)
1254 minibuffer_read(prompt, fn, data);
1256 if (input != NULL) {
1257 strlcpy(ministate.buf, input, sizeof(ministate.buf));
1258 cmd_move_end_of_line(&ministate.buffer);
1261 redraw_tab(current_tab);
1265 ui_other_window(void)
1267 if (in_side_window & SIDE_WINDOW_LEFT &&
1268 side_window & SIDE_WINDOW_BOTTOM)
1269 in_side_window = SIDE_WINDOW_BOTTOM;
1270 else if (in_side_window)
1272 else if (!in_side_window && side_window & SIDE_WINDOW_LEFT)
1273 in_side_window = SIDE_WINDOW_LEFT;
1274 else if (!in_side_window && side_window)
1275 in_side_window = SIDE_WINDOW_BOTTOM;
1277 message("No other window to select");
1285 kill(getpid(), SIGSTOP);
1289 rearrange_windows();