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.
44 #include "minibuffer.h"
45 #include "telescope.h"
49 static struct event stdioev, winchev;
51 static void restore_curs_x(struct buffer *);
53 static struct vline *nth_line(struct buffer*, size_t);
54 static int readkey(void);
55 static void dispatch_stdio(int, short, void*);
56 static void handle_clear_echoarea(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 int wrap_page(struct buffer*, int);
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_help(void);
65 static void redraw_body(struct tab*);
66 static void redraw_modeline(struct tab*);
67 static void redraw_minibuffer(void);
68 static void do_redraw_echoarea(void);
69 static void do_redraw_minibuffer(void);
70 static void do_redraw_minibuffer_compl(void);
71 static void place_cursor(int);
72 static void redraw_tab(struct tab*);
73 static void emit_help_item(char*, void*);
74 static void rec_compute_help(struct kmap*, char*, size_t);
75 static void recompute_help(void);
76 static void update_loading_anim(int, short, void*);
77 static void stop_loading_anim(struct tab*);
79 static int should_rearrange_windows;
83 struct thiskey thiskey;
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 static struct buffer helpwin;
94 static int help_lines, help_cols;
96 static int side_window;
98 static struct event clechoev;
99 static struct timeval clechoev_timer = { 5, 0 };
100 static struct timeval loadingev_timer = { 0, 250000 };
102 static uint32_t tab_counter;
104 static char keybuf[64];
106 struct kmap global_map,
114 update_x_offset(void)
116 if (olivetti_mode && fill_column < body_cols)
117 x_offset = (body_cols - fill_column)/2;
123 save_excursion(struct excursion *place, struct buffer *buffer)
125 place->curs_x = buffer->curs_x;
126 place->curs_y = buffer->curs_y;
127 place->line_off = buffer->line_off;
128 place->current_line = buffer->current_line;
129 place->cpoff = buffer->cpoff;
133 restore_excursion(struct excursion *place, struct buffer *buffer)
135 buffer->curs_x = place->curs_x;
136 buffer->curs_y = place->curs_y;
137 buffer->line_off = place->line_off;
138 buffer->current_line = place->current_line;
139 buffer->cpoff = place->cpoff;
143 restore_curs_x(struct buffer *buffer)
148 vl = buffer->current_line;
149 if (vl == NULL || vl->line == NULL)
150 buffer->curs_x = buffer->cpoff = 0;
152 buffer->curs_x = utf8_snwidth(vl->line, buffer->cpoff);
154 buffer->curs_x += x_offset;
157 prfx = line_prefixes[vl->parent->type].prfx1;
158 buffer->curs_x += utf8_swidth(prfx);
163 global_key_unbound(void)
165 message("%s is undefined", keybuf);
168 static struct vline *
169 nth_line(struct buffer *buffer, size_t n)
175 TAILQ_FOREACH(vl, &buffer->head, vlines) {
190 TAILQ_FOREACH(t, &tabshead, tabs) {
191 if (t->flags & TAB_CURRENT)
203 return &ministate.buffer;
204 return ¤t_tab()->buffer;
212 if ((thiskey.key = wgetch(body)) == ERR)
215 thiskey.meta = thiskey.key == 27;
217 thiskey.key = wgetch(body);
218 if (thiskey.key == ERR || thiskey.key == 27) {
225 if ((unsigned int)thiskey.key < UINT8_MAX) {
227 if (!utf8_decode(&state, &thiskey.cp, (uint8_t)thiskey.key))
229 if ((thiskey.key = wgetch(body)) == ERR) {
230 message("Error decoding user input");
240 dispatch_stdio(int fd, short ev, void *d)
246 /* TODO: schedule a redraw? */
253 if (keybuf[0] != '\0')
254 strlcat(keybuf, " ", sizeof(keybuf));
256 strlcat(keybuf, "M-", sizeof(keybuf));
257 if (thiskey.cp != 0) {
258 utf8_encode(thiskey.cp, tmp);
259 strlcat(keybuf, tmp, sizeof(keybuf));
260 } else if ((keyname = unkbd(thiskey.key)) != NULL) {
261 strlcat(keybuf, keyname, sizeof(keybuf));
263 tmp[0] = thiskey.key;
264 strlcat(keybuf, tmp, sizeof(keybuf));
267 TAILQ_FOREACH(k, ¤t_map->m, keymaps) {
268 if (k->meta == thiskey.meta &&
269 k->key == thiskey.key) {
271 current_map = &k->map;
273 current_map = base_map;
274 strlcpy(keybuf, "", sizeof(keybuf));
275 k->fn(current_buffer());
281 if (current_map->unhandled_input != NULL)
282 current_map->unhandled_input();
284 global_key_unbound();
286 strlcpy(keybuf, "", sizeof(keybuf));
287 current_map = base_map;
293 if (should_rearrange_windows)
295 redraw_tab(current_tab());
299 handle_clear_echoarea(int fd, short ev, void *d)
301 free(ministate.curmesg);
302 ministate.curmesg = NULL;
309 handle_resize(int sig, short ev, void *d)
311 if (event_pending(&resizeev, EV_TIMEOUT, NULL)) {
312 event_del(&resizeev);
314 evtimer_set(&resizeev, handle_resize_nodelay, NULL);
315 evtimer_add(&resizeev, &resize_timer);
319 handle_resize_nodelay(int s, short ev, void *d)
329 rearrange_windows(void)
334 should_rearrange_windows = 0;
338 if ((too_small = lines < 15)) {
340 printw("Window too small.");
345 /* move and resize the windows, in reverse order! */
347 if (in_minibuffer == MB_COMPREAD) {
348 mvwin(minibuffer, lines-10, 0);
349 wresize(minibuffer, 10, COLS);
352 wrap_page(&ministate.compl.buffer, COLS);
355 mvwin(echoarea, --lines, 0);
356 wresize(echoarea, 1, COLS);
358 mvwin(modeline, --lines, 0);
359 wresize(modeline, 1, COLS);
361 body_lines = --lines;
365 help_cols = 0.3 * COLS;
368 wresize(help, help_lines, help_cols);
370 wrap_page(&helpwin, help_cols);
372 body_cols = COLS - help_cols - 1;
373 mvwin(body, 1, help_cols);
378 wresize(body, body_lines, body_cols);
380 wresize(tabline, 1, COLS);
384 wrap_page(&tab->buffer, body_cols);
389 wrap_page(struct buffer *buffer, int width)
392 const struct line *top_orig, *orig;
397 top_orig = buffer->top_line == NULL ? NULL : buffer->top_line->parent;
398 orig = buffer->current_line == NULL ? NULL : buffer->current_line->parent;
400 buffer->top_line = NULL;
401 buffer->current_line = NULL;
403 buffer->force_redraw = 1;
405 buffer->line_off = 0;
409 TAILQ_FOREACH(l, &buffer->page.head, lines) {
410 prfx = line_prefixes[l->type].prfx1;
421 wrap_text(buffer, prfx, l, MIN(fill_column, width));
423 case LINE_PRE_CONTENT:
425 pre_width = MIN(fill_column, width);
428 hardwrap_text(buffer, l, pre_width);
431 case LINE_COMPL_CURRENT:
432 wrap_one(buffer, prfx, l, width);
436 if (top_orig == l && buffer->top_line == NULL) {
437 buffer->line_off = buffer->line_max-1;
438 buffer->top_line = TAILQ_LAST(&buffer->head, vhead);
441 vl = TAILQ_PREV(buffer->top_line, vhead, vlines);
442 if (vl == NULL || vl->parent != orig)
444 buffer->top_line = vl;
449 if (orig == l && buffer->current_line == NULL) {
450 buffer->current_line = TAILQ_LAST(&buffer->head, vhead);
453 vl = TAILQ_PREV(buffer->current_line, vhead, vlines);
454 if (vl == NULL || vl->parent != orig)
456 buffer->current_line = vl;
461 if (buffer->current_line == NULL)
462 buffer->current_line = TAILQ_FIRST(&buffer->head);
464 if (buffer->top_line == NULL)
465 buffer->top_line = buffer->current_line;
471 print_vline(int off, int width, WINDOW *window, struct vline *vl)
478 f = &line_faces[vl->parent->type];
480 /* unused, set by getyx */
484 prfx = line_prefixes[vl->parent->type].prfx1;
486 prfx = line_prefixes[vl->parent->type].prfx2;
492 wattr_on(window, body_face.left, NULL);
493 for (i = 0; i < off; i++)
495 wattr_off(window, body_face.left, NULL);
497 wattr_on(window, f->prefix, NULL);
498 wprintw(window, "%s", prfx);
499 wattr_off(window, f->prefix, NULL);
501 wattr_on(window, f->text, NULL);
502 wprintw(window, "%s", text);
503 wattr_off(window, f->text, NULL);
509 wattr_on(window, f->trail, NULL);
510 for (i = 0; i < left - off; ++i)
512 wattr_off(window, f->trail, NULL);
514 wattr_on(window, body_face.right, NULL);
515 for (i = 0; i < off; i++)
517 wattr_off(window, body_face.right, NULL);
525 size_t toskip, ots, tabwidth, space, x;
526 int current, y, truncated;
532 /* unused, but setted by a getyx */
535 tabwidth = sizeof(buf)+1;
539 TAILQ_FOREACH(tab, &tabshead, tabs) {
541 if (tab->flags & TAB_CURRENT)
545 if (toskip * tabwidth < space)
550 while (toskip != 0 &&
551 (ots - toskip+1) * tabwidth < space)
556 wattr_on(tabline, tab_face.background, NULL);
557 wprintw(tabline, toskip == 0 ? " " : "<");
558 wattr_off(tabline, tab_face.background, NULL);
561 TAILQ_FOREACH(tab, &tabshead, tabs) {
569 getyx(tabline, y, x);
570 if (x + sizeof(buf)+2 >= (size_t)COLS)
573 current = tab->flags & TAB_CURRENT;
575 if (*(title = tab->buffer.page.title) == '\0')
576 title = tab->hist_cur->h;
578 if (tab->flags & TAB_URGENT)
579 strlcpy(buf, "!", sizeof(buf));
581 strlcpy(buf, " ", sizeof(buf));
583 if (strlcat(buf, title, sizeof(buf)) >= sizeof(buf)) {
584 /* truncation happens */
585 strlcpy(&buf[sizeof(buf)-4], "...", 4);
587 /* pad with spaces */
588 while (strlcat(buf, " ", sizeof(buf)) < sizeof(buf))
593 wattr_on(tabline, tab_face.current, NULL);
595 wattr_on(tabline, tab_face.tab, NULL);
597 wprintw(tabline, "%s", buf);
598 if (TAILQ_NEXT(tab, tabs) != NULL)
599 wprintw(tabline, " ");
602 wattr_off(tabline, tab_face.current, NULL);
604 wattr_off(tabline, tab_face.tab, NULL);
607 wattr_on(tabline, tab_face.background, NULL);
608 for (; x < (size_t)COLS; ++x)
609 waddch(tabline, ' ');
611 mvwprintw(tabline, 0, COLS-1, ">");
612 wattr_off(tabline, tab_face.background, NULL);
616 * Compute the first visible line around vl. Try to search forward
617 * until the end of the buffer; if a visible line is not found, search
618 * backward. Return NULL if no viable line was found.
621 adjust_line(struct vline *vl, struct buffer *buffer)
628 if (!(vl->parent->flags & L_HIDDEN))
633 t != NULL && t->parent->flags & L_HIDDEN;
634 t = TAILQ_NEXT(t, vlines))
640 /* search backward */
642 t != NULL && t->parent->flags & L_HIDDEN;
643 t = TAILQ_PREV(t, vhead, vlines))
650 redraw_window(WINDOW *win, int off, int height, int width, struct buffer *buffer)
655 restore_curs_x(buffer);
658 * TODO: ignoring buffer->force_update and always
659 * re-rendering. In theory we can recompute the y position
660 * without a re-render, and optimize here. It's not the only
661 * optimisation possible here, wscrl wolud also be an
669 if (TAILQ_EMPTY(&buffer->head))
672 if (buffer->top_line == NULL)
673 buffer->top_line = TAILQ_FIRST(&buffer->head);
675 buffer->top_line = adjust_line(buffer->top_line, buffer);
676 if (buffer->top_line == NULL)
679 buffer->current_line = adjust_line(buffer->current_line, buffer);
683 for (vl = buffer->top_line; vl != NULL; vl = TAILQ_NEXT(vl, vlines)) {
684 if (vl->parent->flags & L_HIDDEN)
688 print_vline(off, width, win, vl);
690 if (vl == buffer->current_line)
702 for (; vl != NULL; vl = TAILQ_NEXT(vl, vlines)) {
703 if (vl == buffer->current_line)
705 if (vl->parent->flags & L_HIDDEN)
708 buffer->top_line = TAILQ_NEXT(buffer->top_line, vlines);
715 buffer->last_line_off = buffer->line_off;
716 buffer->force_redraw = 0;
718 wmove(win, buffer->curs_y, buffer->curs_x);
724 redraw_window(help, 0, help_lines, help_cols, &helpwin);
728 redraw_body(struct tab *tab)
730 static struct tab *last_tab;
733 tab->buffer.force_redraw =1;
736 redraw_window(body, x_offset, body_lines, body_cols, &tab->buffer);
740 trust_status_char(enum trust_state ts)
743 case TS_UNKNOWN: return 'u';
744 case TS_UNTRUSTED: return '!';
745 case TS_TEMP_TRUSTED: return '!';
746 case TS_TRUSTED: return 'v';
747 case TS_VERIFIED: return 'V';
753 redraw_modeline(struct tab *tab)
756 int x, y, max_x, max_y;
757 const char *mode = tab->buffer.page.name;
758 const char *spin = "-\\|/";
761 wattr_on(modeline, modeline_face.background, NULL);
762 wmove(modeline, 0, 0);
764 wprintw(modeline, "-%c%c %s ",
765 spin[tab->loading_anim_step],
766 trust_status_char(tab->trust),
767 mode == NULL ? "(none)" : mode);
769 pct = (tab->buffer.line_off + tab->buffer.curs_y) * 100.0
770 / tab->buffer.line_max;
772 if (tab->buffer.line_max <= (size_t)body_lines)
773 wprintw(modeline, "All ");
774 else if (tab->buffer.line_off == 0)
775 wprintw(modeline, "Top ");
776 else if (tab->buffer.line_off + body_lines >= tab->buffer.line_max)
777 wprintw(modeline, "Bottom ");
779 wprintw(modeline, "%.0f%% ", pct);
781 wprintw(modeline, "%d/%d %s ",
782 tab->buffer.line_off + tab->buffer.curs_y,
783 tab->buffer.line_max,
786 getyx(modeline, y, x);
787 getmaxyx(modeline, max_y, max_x);
792 for (; x < max_x; ++x)
793 waddstr(modeline, "-");
795 wattr_off(modeline, modeline_face.background, NULL);
799 redraw_minibuffer(void)
801 wattr_on(echoarea, minibuffer_face.background, NULL);
805 do_redraw_minibuffer();
807 do_redraw_echoarea();
809 if (in_minibuffer == MB_COMPREAD)
810 do_redraw_minibuffer_compl();
812 wattr_off(echoarea, minibuffer_face.background, NULL);
816 do_redraw_echoarea(void)
820 if (ministate.curmesg != NULL)
821 wprintw(echoarea, "%s", ministate.curmesg);
822 else if (*keybuf != '\0')
823 waddstr(echoarea, keybuf);
825 /* If nothing else, show the URL at point */
827 if (tab->buffer.current_line != NULL &&
828 tab->buffer.current_line->parent->type == LINE_LINK)
830 tab->buffer.current_line->parent->meta.alt);
835 do_redraw_minibuffer(void)
837 size_t off_y, off_x = 0;
838 const char *start, *c;
840 /* unused, set by getyx */
843 wmove(echoarea, 0, 0);
845 if (in_minibuffer == MB_COMPREAD)
846 wprintw(echoarea, "(%2d) ",
847 ministate.compl.buffer.line_max);
849 wprintw(echoarea, "%s", ministate.prompt);
850 if (ministate.hist_cur != NULL)
851 wprintw(echoarea, "(%zu/%zu) ",
852 ministate.hist_off + 1,
853 ministate.history->len);
855 getyx(echoarea, off_y, off_x);
857 start = ministate.hist_cur != NULL
858 ? ministate.hist_cur->h
860 c = utf8_nth(ministate.buffer.current_line->line,
861 ministate.buffer.cpoff);
862 while (utf8_swidth_between(start, c) > (size_t)COLS/2) {
863 start = utf8_next_cp(start);
866 waddstr(echoarea, start);
868 if (ministate.curmesg != NULL)
869 wprintw(echoarea, " [%s]", ministate.curmesg);
871 wmove(echoarea, 0, off_x + utf8_swidth_between(start, c));
875 do_redraw_minibuffer_compl(void)
877 redraw_window(minibuffer, 0, 10, body_cols,
878 &ministate.compl.buffer);
882 * Place the cursor in the right ncurses window. If soft is 1, use
883 * wnoutrefresh (which shouldn't cause any I/O); otherwise use
887 place_cursor(int soft)
889 int (*touch)(WINDOW *);
892 touch = wnoutrefresh;
906 redraw_tab(struct tab *tab)
918 redraw_modeline(tab);
921 wnoutrefresh(tabline);
922 wnoutrefresh(modeline);
924 if (in_minibuffer == MB_COMPREAD)
925 wnoutrefresh(minibuffer);
933 emit_help_item(char *prfx, void *fn)
938 for (cmd = cmds; cmd->cmd != NULL; ++cmd) {
944 if ((l = calloc(1, sizeof(*l))) == NULL)
950 asprintf(&l->line, "%s %s", prfx, cmd->cmd);
952 if (TAILQ_EMPTY(&helpwin.page.head))
953 TAILQ_INSERT_HEAD(&helpwin.page.head, l, lines);
955 TAILQ_INSERT_TAIL(&helpwin.page.head, l, lines);
959 rec_compute_help(struct kmap *keymap, char *prfx, size_t len)
965 TAILQ_FOREACH(k, &keymap->m, keymaps) {
966 strlcpy(p, prfx, sizeof(p));
968 strlcat(p, " ", sizeof(p));
970 strlcat(p, "M-", sizeof(p));
971 if ((kn = unkbd(k->key)) != NULL)
972 strlcat(p, kn, sizeof(p));
974 strlcat(p, keyname(k->key), sizeof(p));
977 rec_compute_help(&k->map, p, sizeof(p));
979 emit_help_item(p, k->fn);
988 empty_vlist(&helpwin);
989 empty_linelist(&helpwin);
990 rec_compute_help(current_map, p, sizeof(p));
991 wrap_page(&helpwin, help_cols);
995 vmessage(const char *fmt, va_list ap)
997 if (evtimer_pending(&clechoev, NULL))
998 evtimer_del(&clechoev);
1000 free(ministate.curmesg);
1001 ministate.curmesg = NULL;
1004 evtimer_set(&clechoev, handle_clear_echoarea, NULL);
1005 evtimer_add(&clechoev, &clechoev_timer);
1007 /* TODO: what to do if the allocation fails here? */
1008 if (vasprintf(&ministate.curmesg, fmt, ap) == -1)
1009 ministate.curmesg = NULL;
1012 redraw_minibuffer();
1017 message(const char *fmt, ...)
1027 start_loading_anim(struct tab *tab)
1029 if (tab->loading_anim)
1031 tab->loading_anim = 1;
1032 evtimer_set(&tab->loadingev, update_loading_anim, tab);
1033 evtimer_add(&tab->loadingev, &loadingev_timer);
1037 update_loading_anim(int fd, short ev, void *d)
1039 struct tab *tab = d;
1041 tab->loading_anim_step = (tab->loading_anim_step+1)%4;
1043 if (tab->flags & TAB_CURRENT) {
1044 redraw_modeline(tab);
1051 evtimer_add(&tab->loadingev, &loadingev_timer);
1055 stop_loading_anim(struct tab *tab)
1057 if (!tab->loading_anim)
1059 evtimer_del(&tab->loadingev);
1060 tab->loading_anim = 0;
1061 tab->loading_anim_step = 0;
1063 if (!(tab->flags & TAB_CURRENT))
1066 redraw_modeline(tab);
1075 load_url_in_tab(struct tab *tab, const char *url)
1077 message("Loading %s...", url);
1078 start_loading_anim(tab);
1081 tab->buffer.curs_x = 0;
1082 tab->buffer.curs_y = 0;
1087 switch_to_tab(struct tab *tab)
1091 TAILQ_FOREACH(t, &tabshead, tabs) {
1092 t->flags &= ~TAB_CURRENT;
1095 tab->flags |= TAB_CURRENT;
1096 tab->flags &= ~TAB_URGENT;
1102 return tab_counter++;
1106 new_tab(const char *url)
1110 if ((tab = calloc(1, sizeof(*tab))) == NULL) {
1116 TAILQ_INIT(&tab->hist.head);
1118 TAILQ_INIT(&tab->buffer.head);
1120 tab->id = tab_new_id();
1123 if (TAILQ_EMPTY(&tabshead))
1124 TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
1126 TAILQ_INSERT_TAIL(&tabshead, tab, tabs);
1128 load_url_in_tab(tab, url);
1133 ui_print_colors(void)
1135 int colors = 0, pairs = 0, can_change = 0;
1136 int columns = 16, lines, color, i, j;
1141 use_default_colors();
1144 pairs = COLOR_PAIRS;
1145 can_change = can_change_color();
1149 printf("Term info:\n");
1150 printf("TERM=%s COLORS=%d COLOR_PAIRS=%d can_change_colors=%d\n",
1151 getenv("TERM"), colors, pairs, can_change);
1155 printf("No color support\n");
1159 printf("Available colors:\n\n");
1160 lines = (colors - 1) / columns + 1;
1162 for (i = 0; i < lines; ++i) {
1163 for (j = 0; j < columns; ++j, ++color) {
1164 printf("\033[0;38;5;%dm %03d", color, color);
1177 setlocale(LC_ALL, "");
1179 TAILQ_INIT(&eecmd_history.head);
1180 TAILQ_INIT(&ir_history.head);
1181 TAILQ_INIT(&lu_history.head);
1183 ministate.line.type = LINE_TEXT;
1184 ministate.vline.parent = &ministate.line;
1185 ministate.buffer.current_line = &ministate.vline;
1187 /* initialize help window */
1188 TAILQ_INIT(&helpwin.head);
1190 base_map = &global_map;
1191 current_map = &global_map;
1195 if (enable_colors) {
1198 use_default_colors();
1203 config_apply_style();
1208 intrflush(stdscr, FALSE);
1210 if ((tabline = newwin(1, COLS, 0, 0)) == NULL)
1212 if ((body = newwin(LINES - 3, COLS, 1, 0)) == NULL)
1214 if ((modeline = newwin(1, COLS, LINES-2, 0)) == NULL)
1216 if ((echoarea = newwin(1, COLS, LINES-1, 0)) == NULL)
1218 if ((minibuffer = newwin(1, COLS, LINES-1, 0)) == NULL)
1220 if ((help = newwin(1, 1, 1, 0)) == NULL)
1223 body_lines = LINES-3;
1226 wbkgd(body, body_face.body);
1227 wbkgd(echoarea, minibuffer_face.background);
1232 scrollok(body, FALSE);
1234 /* non-blocking input */
1237 mvwprintw(body, 0, 0, "");
1239 event_set(&stdioev, 0, EV_READ | EV_PERSIST, dispatch_stdio, NULL);
1240 event_add(&stdioev, NULL);
1242 signal_set(&winchev, SIGWINCH, handle_resize, NULL);
1243 signal_add(&winchev, NULL);
1249 ui_on_tab_loaded(struct tab *tab)
1251 stop_loading_anim(tab);
1252 message("Loaded %s", tab->hist_cur->h);
1260 ui_on_tab_refresh(struct tab *tab)
1262 wrap_page(&tab->buffer, body_cols);
1263 if (tab->flags & TAB_CURRENT)
1266 tab->flags |= TAB_URGENT;
1276 ui_toggle_side_window(void)
1278 side_window = !side_window;
1283 * ugly hack, but otherwise the window doesn't get updated
1284 * until I call rearrange_windows a second time (e.g. via
1285 * C-l). I will be happy to know why something like this is
1288 rearrange_windows();
1289 rearrange_windows();
1293 ui_schedule_redraw(void)
1295 should_rearrange_windows = 1;
1299 ui_require_input(struct tab *tab, int hide)
1301 /* TODO: hard-switching to another tab is ugly */
1304 enter_minibuffer(ir_self_insert, ir_select, exit_minibuffer,
1305 &ir_history, NULL, NULL);
1306 strlcpy(ministate.prompt, "Input required: ",
1307 sizeof(ministate.prompt));
1312 ui_yornp(const char *prompt, void (*fn)(int, struct tab *),
1315 yornp(prompt, fn, data);
1316 redraw_tab(current_tab());
1320 ui_read(const char *prompt, void (*fn)(const char*, struct tab *),
1323 completing_read(prompt, fn, data);
1324 redraw_tab(current_tab());