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 int readkey(void);
54 static void dispatch_stdio(int, short, void*);
55 static void handle_clear_echoarea(int, short, void*);
56 static void handle_resize(int, short, void*);
57 static void handle_resize_nodelay(int, short, void*);
58 static void rearrange_windows(void);
59 static void line_prefix_and_text(struct vline *, char *, size_t, const char **, const char **);
60 static void print_vline(int, int, WINDOW*, struct vline*);
61 static void redraw_tabline(void);
62 static void redraw_window(WINDOW*, int, int, int, struct buffer*);
63 static void redraw_help(void);
64 static void redraw_body(struct tab*);
65 static void redraw_modeline(struct tab*);
66 static void redraw_minibuffer(void);
67 static void do_redraw_echoarea(void);
68 static void do_redraw_minibuffer(void);
69 static void do_redraw_minibuffer_compl(void);
70 static void place_cursor(int);
71 static void redraw_tab(struct tab*);
72 static void update_loading_anim(int, short, void*);
73 static void stop_loading_anim(struct tab*);
76 * Used to know when we're finished loading.
80 static int should_rearrange_windows;
84 struct thiskey thiskey;
85 struct tab *current_tab;
87 static struct event resizeev;
88 static struct timeval resize_timer = { 0, 250000 };
90 static WINDOW *tabline, *body, *modeline, *echoarea, *minibuffer;
92 int body_lines, body_cols;
95 /* not static so we can see them from help.c */
96 struct buffer helpwin;
97 int help_lines, help_cols;
99 static int side_window;
101 static struct event clechoev;
102 static struct timeval clechoev_timer = { 5, 0 };
103 static struct timeval loadingev_timer = { 0, 250000 };
105 static uint32_t tab_counter;
107 static char keybuf[64];
109 struct kmap global_map,
117 update_x_offset(void)
119 if (olivetti_mode && fill_column < body_cols)
120 x_offset = (body_cols - fill_column)/2;
126 save_excursion(struct excursion *place, struct buffer *buffer)
128 place->curs_x = buffer->curs_x;
129 place->curs_y = buffer->curs_y;
130 place->line_off = buffer->line_off;
131 place->top_line = buffer->top_line;
132 place->current_line = buffer->current_line;
133 place->cpoff = buffer->cpoff;
137 restore_excursion(struct excursion *place, struct buffer *buffer)
139 buffer->curs_x = place->curs_x;
140 buffer->curs_y = place->curs_y;
141 buffer->line_off = place->line_off;
142 buffer->top_line = place->top_line;
143 buffer->current_line = place->current_line;
144 buffer->cpoff = place->cpoff;
148 restore_curs_x(struct buffer *buffer)
151 const char *prfx, *text;
153 vl = buffer->current_line;
154 if (vl == NULL || vl->line == NULL)
155 buffer->curs_x = buffer->cpoff = 0;
156 else if (vl->parent->data != NULL) {
157 text = vl->parent->data;
158 buffer->curs_x = utf8_snwidth(text + 1, buffer->cpoff) + 1;
160 buffer->curs_x = utf8_snwidth(vl->line, buffer->cpoff);
162 buffer->curs_x += x_offset;
167 if (vl->parent->data != NULL)
168 buffer->curs_x += utf8_swidth_between(vl->parent->line, vl->parent->data);
170 prfx = line_prefixes[vl->parent->type].prfx1;
171 buffer->curs_x += utf8_swidth(prfx);
176 global_key_unbound(void)
178 message("%s is undefined", keybuf);
185 return &ministate.buffer;
186 return ¤t_tab->buffer;
194 if ((thiskey.key = wgetch(body)) == ERR)
197 thiskey.meta = thiskey.key == 27;
199 thiskey.key = wgetch(body);
200 if (thiskey.key == ERR || thiskey.key == 27) {
207 if ((unsigned int)thiskey.key < UINT8_MAX) {
209 if (!utf8_decode(&state, &thiskey.cp, (uint8_t)thiskey.key))
211 if ((thiskey.key = wgetch(body)) == ERR) {
212 message("Error decoding user input");
222 dispatch_stdio(int fd, short ev, void *d)
228 /* TODO: schedule a redraw? */
235 if (keybuf[0] != '\0')
236 strlcat(keybuf, " ", sizeof(keybuf));
238 strlcat(keybuf, "M-", sizeof(keybuf));
239 if (thiskey.cp != 0) {
240 utf8_encode(thiskey.cp, tmp);
241 strlcat(keybuf, tmp, sizeof(keybuf));
242 } else if ((keyname = unkbd(thiskey.key)) != NULL) {
243 strlcat(keybuf, keyname, sizeof(keybuf));
245 tmp[0] = thiskey.key;
246 strlcat(keybuf, tmp, sizeof(keybuf));
249 TAILQ_FOREACH(k, ¤t_map->m, keymaps) {
250 if (k->meta == thiskey.meta &&
251 k->key == thiskey.key) {
253 current_map = &k->map;
255 current_map = base_map;
256 strlcpy(keybuf, "", sizeof(keybuf));
257 k->fn(current_buffer());
263 if (current_map->unhandled_input != NULL)
264 current_map->unhandled_input();
266 global_key_unbound();
268 strlcpy(keybuf, "", sizeof(keybuf));
269 current_map = base_map;
275 if (should_rearrange_windows)
277 redraw_tab(current_tab);
281 handle_clear_echoarea(int fd, short ev, void *d)
283 free(ministate.curmesg);
284 ministate.curmesg = NULL;
291 handle_resize(int sig, short ev, void *d)
293 if (event_pending(&resizeev, EV_TIMEOUT, NULL)) {
294 event_del(&resizeev);
296 evtimer_set(&resizeev, handle_resize_nodelay, NULL);
297 evtimer_add(&resizeev, &resize_timer);
301 handle_resize_nodelay(int s, short ev, void *d)
311 rearrange_windows(void)
315 should_rearrange_windows = 0;
319 if ((too_small = lines < 15)) {
321 printw("Window too small.");
326 /* move and resize the windows, in reverse order! */
328 if (in_minibuffer == MB_COMPREAD) {
329 mvwin(minibuffer, lines-10, 0);
330 wresize(minibuffer, 10, COLS);
333 wrap_page(&ministate.compl.buffer, COLS);
336 mvwin(echoarea, --lines, 0);
337 wresize(echoarea, 1, COLS);
339 mvwin(modeline, --lines, 0);
340 wresize(modeline, 1, COLS);
342 body_lines = --lines;
346 help_cols = 0.3 * COLS;
349 wresize(help, help_lines, help_cols);
351 wrap_page(&helpwin, help_cols);
353 body_cols = COLS - help_cols - 1;
354 mvwin(body, 1, help_cols);
359 wresize(body, body_lines, body_cols);
361 wresize(tabline, 1, COLS);
363 wrap_page(¤t_tab->buffer, body_cols);
364 redraw_tab(current_tab);
368 line_prefix_and_text(struct vline *vl, char *buf, size_t len,
369 const char **prfx_ret, const char **text_ret)
371 int type, i, cont, width;
374 if ((*text_ret = vl->line) == NULL)
377 cont = vl->flags & L_CONTINUATION;
378 type = vl->parent->type;
380 *prfx_ret = line_prefixes[type].prfx1;
382 *prfx_ret = line_prefixes[type].prfx2;
384 space = vl->parent->data;
385 if (!emojify_link || type != LINE_LINK || space == NULL)
390 width = utf8_swidth_between(vl->parent->line, space);
391 for (i = 0; i < width + 1; ++i)
392 strlcat(buf, " ", len);
394 strlcpy(buf, *text_ret, len);
395 if ((t = strchr(buf, ' ')) != NULL)
397 strlcat(buf, " ", len);
400 *text_ret += (space - vl->parent->line) + 1;
407 print_vline_descr(int width, WINDOW *window, struct vline *vl)
411 if (vl->parent->type != LINE_COMPL &&
412 vl->parent->type != LINE_COMPL_CURRENT)
415 if (vl->parent->alt == NULL)
423 wprintw(window, " ");
424 for (; goal > x; ++x)
425 wprintw(window, " ");
427 wprintw(window, "%s", vl->parent->alt);
431 * Core part of the rendering. It prints a vline starting from the
432 * current cursor position. Printing a vline consists of skipping
433 * `off' columns (for olivetti-mode), print the correct prefix (which
434 * may be the emoji in case of emojified links-lines), printing the
435 * text itself, filling until width - off and filling off columns
439 print_vline(int off, int width, WINDOW *window, struct vline *vl)
442 * Believe me or not, I've seen emoji ten code points long!
443 * That means, to stay large, 4*10 bytes + NUL.
445 char emojibuf[41] = {0};
446 const char *text, *prfx;
450 f = &line_faces[vl->parent->type];
452 /* unused, set by getyx */
455 line_prefix_and_text(vl, emojibuf, sizeof(emojibuf), &prfx, &text);
457 wattr_on(window, body_face.left, NULL);
458 for (i = 0; i < off; i++)
460 wattr_off(window, body_face.left, NULL);
462 wattr_on(window, f->prefix, NULL);
463 wprintw(window, "%s", prfx);
464 wattr_off(window, f->prefix, NULL);
466 wattr_on(window, f->text, NULL);
467 wprintw(window, "%s", text);
468 print_vline_descr(width, window, vl);
469 wattr_off(window, f->text, NULL);
475 wattr_on(window, f->trail, NULL);
476 for (i = 0; i < left - off; ++i)
478 wattr_off(window, f->trail, NULL);
480 wattr_on(window, body_face.right, NULL);
481 for (i = 0; i < off; i++)
483 wattr_off(window, body_face.right, NULL);
491 size_t toskip, ots, tabwidth, space, x;
492 int current, y, truncated, pair;
498 /* unused, but setted by a getyx */
501 tabwidth = sizeof(buf)+1;
505 TAILQ_FOREACH(tab, &tabshead, tabs) {
507 if (tab == current_tab)
511 if (toskip * tabwidth < space)
516 while (toskip != 0 &&
517 (ots - toskip+1) * tabwidth < space)
522 wattr_on(tabline, tab_face.background, NULL);
523 wprintw(tabline, toskip == 0 ? " " : "<");
524 wattr_off(tabline, tab_face.background, NULL);
527 TAILQ_FOREACH(tab, &tabshead, tabs) {
535 getyx(tabline, y, x);
536 if (x + sizeof(buf)+2 >= (size_t)COLS)
539 current = tab == current_tab;
541 if (*(title = tab->buffer.page.title) == '\0')
542 title = tab->hist_cur->h;
544 if (tab->flags & TAB_URGENT)
545 strlcpy(buf, "!", sizeof(buf));
547 strlcpy(buf, " ", sizeof(buf));
549 if (strlcat(buf, title, sizeof(buf)) >= sizeof(buf)) {
550 /* truncation happens */
551 strlcpy(&buf[sizeof(buf)-4], "...", 4);
553 /* pad with spaces */
554 while (strlcat(buf, " ", sizeof(buf)) < sizeof(buf))
558 pair = current ? tab_face.current : tab_face.tab;
559 wattr_on(tabline, pair, NULL);
560 wprintw(tabline, "%s", buf);
561 wattr_off(tabline, pair, NULL);
563 wattr_on(tabline, tab_face.background, NULL);
564 if (TAILQ_NEXT(tab, tabs) != NULL)
565 wprintw(tabline, "│");
566 wattr_off(tabline, tab_face.background, NULL);
569 wattr_on(tabline, tab_face.background, NULL);
570 for (; x < (size_t)COLS; ++x)
571 waddch(tabline, ' ');
573 mvwprintw(tabline, 0, COLS-1, ">");
574 wattr_off(tabline, tab_face.background, NULL);
578 * Compute the first visible line around vl. Try to search forward
579 * until the end of the buffer; if a visible line is not found, search
580 * backward. Return NULL if no viable line was found.
583 adjust_line(struct vline *vl, struct buffer *buffer)
590 if (!(vl->parent->flags & L_HIDDEN))
595 t != NULL && t->parent->flags & L_HIDDEN;
596 t = TAILQ_NEXT(t, vlines))
602 /* search backward */
604 t != NULL && t->parent->flags & L_HIDDEN;
605 t = TAILQ_PREV(t, vhead, vlines))
612 redraw_window(WINDOW *win, int off, int height, int width, struct buffer *buffer)
617 restore_curs_x(buffer);
620 * TODO: ignoring buffer->force_update and always
621 * re-rendering. In theory we can recompute the y position
622 * without a re-render, and optimize here. It's not the only
623 * optimisation possible here, wscrl wolud also be an
631 if (TAILQ_EMPTY(&buffer->head))
634 if (buffer->top_line == NULL)
635 buffer->top_line = TAILQ_FIRST(&buffer->head);
637 buffer->top_line = adjust_line(buffer->top_line, buffer);
638 if (buffer->top_line == NULL)
641 buffer->current_line = adjust_line(buffer->current_line, buffer);
645 for (vl = buffer->top_line; vl != NULL; vl = TAILQ_NEXT(vl, vlines)) {
646 if (vl->parent->flags & L_HIDDEN)
650 print_vline(off, width, win, vl);
652 if (vl == buffer->current_line)
664 for (; vl != NULL; vl = TAILQ_NEXT(vl, vlines)) {
665 if (vl == buffer->current_line)
667 if (vl->parent->flags & L_HIDDEN)
670 buffer->top_line = TAILQ_NEXT(buffer->top_line, vlines);
677 buffer->last_line_off = buffer->line_off;
678 buffer->force_redraw = 0;
680 wmove(win, buffer->curs_y, buffer->curs_x);
686 redraw_window(help, 0, help_lines, help_cols, &helpwin);
690 redraw_body(struct tab *tab)
692 static struct tab *last_tab;
695 tab->buffer.force_redraw =1;
698 redraw_window(body, x_offset, body_lines, body_cols, &tab->buffer);
702 trust_status_char(enum trust_state ts)
705 case TS_UNKNOWN: return '-';
706 case TS_UNTRUSTED: return '!';
707 case TS_TEMP_TRUSTED: return '!';
708 case TS_TRUSTED: return 'v';
709 case TS_VERIFIED: return 'V';
715 redraw_modeline(struct tab *tab)
718 int x, y, max_x, max_y;
719 const char *mode = tab->buffer.page.name;
720 const char *spin = "-\\|/";
723 wattr_on(modeline, modeline_face.background, NULL);
724 wmove(modeline, 0, 0);
726 wprintw(modeline, "-%c%c %s ",
727 spin[tab->loading_anim_step],
728 trust_status_char(tab->trust),
729 mode == NULL ? "(none)" : mode);
731 pct = (tab->buffer.line_off + tab->buffer.curs_y) * 100.0
732 / tab->buffer.line_max;
734 if (tab->buffer.line_max <= (size_t)body_lines)
735 wprintw(modeline, "All ");
736 else if (tab->buffer.line_off == 0)
737 wprintw(modeline, "Top ");
738 else if (tab->buffer.line_off + body_lines >= tab->buffer.line_max)
739 wprintw(modeline, "Bottom ");
741 wprintw(modeline, "%.0f%% ", pct);
743 wprintw(modeline, "%d/%d %s ",
744 tab->buffer.line_off + tab->buffer.curs_y,
745 tab->buffer.line_max,
748 getyx(modeline, y, x);
749 getmaxyx(modeline, max_y, max_x);
754 for (; x < max_x; ++x)
755 waddstr(modeline, "-");
757 wattr_off(modeline, modeline_face.background, NULL);
761 redraw_minibuffer(void)
763 wattr_on(echoarea, minibuffer_face.background, NULL);
767 do_redraw_minibuffer();
769 do_redraw_echoarea();
771 if (in_minibuffer == MB_COMPREAD)
772 do_redraw_minibuffer_compl();
774 wattr_off(echoarea, minibuffer_face.background, NULL);
778 do_redraw_echoarea(void)
782 if (ministate.curmesg != NULL)
783 wprintw(echoarea, "%s", ministate.curmesg);
784 else if (*keybuf != '\0')
785 waddstr(echoarea, keybuf);
787 /* If nothing else, show the URL at point */
788 vl = current_tab->buffer.current_line;
789 if (vl != NULL && vl->parent->type == LINE_LINK)
790 waddstr(echoarea, vl->parent->alt);
795 do_redraw_minibuffer(void)
797 size_t off_y, off_x = 0;
798 const char *start, *c;
800 /* unused, set by getyx */
803 wmove(echoarea, 0, 0);
805 if (in_minibuffer == MB_COMPREAD)
806 wprintw(echoarea, "(%2d) ",
807 ministate.compl.buffer.line_max);
809 wprintw(echoarea, "%s", ministate.prompt);
810 if (ministate.hist_cur != NULL)
811 wprintw(echoarea, "(%zu/%zu) ",
812 ministate.hist_off + 1,
813 ministate.history->len);
815 getyx(echoarea, off_y, off_x);
817 start = ministate.hist_cur != NULL
818 ? ministate.hist_cur->h
820 c = utf8_nth(ministate.buffer.current_line->line,
821 ministate.buffer.cpoff);
822 while (utf8_swidth_between(start, c) > (size_t)COLS/2) {
823 start = utf8_next_cp(start);
826 waddstr(echoarea, start);
828 if (ministate.curmesg != NULL)
829 wprintw(echoarea, " [%s]", ministate.curmesg);
831 wmove(echoarea, 0, off_x + utf8_swidth_between(start, c));
835 do_redraw_minibuffer_compl(void)
837 redraw_window(minibuffer, 0, 10, body_cols,
838 &ministate.compl.buffer);
842 * Place the cursor in the right ncurses window. If soft is 1, use
843 * wnoutrefresh (which shouldn't cause any I/O); otherwise use
847 place_cursor(int soft)
849 int (*touch)(WINDOW *);
852 touch = wnoutrefresh;
866 redraw_tab(struct tab *tab)
878 redraw_modeline(tab);
881 wnoutrefresh(tabline);
882 wnoutrefresh(modeline);
884 if (in_minibuffer == MB_COMPREAD)
885 wnoutrefresh(minibuffer);
892 dprintf(1, "\033]0;%s - Telescope\a",
893 current_tab->buffer.page.title);
897 vmessage(const char *fmt, va_list ap)
899 if (evtimer_pending(&clechoev, NULL))
900 evtimer_del(&clechoev);
902 free(ministate.curmesg);
903 ministate.curmesg = NULL;
906 evtimer_set(&clechoev, handle_clear_echoarea, NULL);
907 evtimer_add(&clechoev, &clechoev_timer);
909 /* TODO: what to do if the allocation fails here? */
910 if (vasprintf(&ministate.curmesg, fmt, ap) == -1)
911 ministate.curmesg = NULL;
919 message(const char *fmt, ...)
929 start_loading_anim(struct tab *tab)
931 if (tab->loading_anim)
933 tab->loading_anim = 1;
934 evtimer_set(&tab->loadingev, update_loading_anim, tab);
935 evtimer_add(&tab->loadingev, &loadingev_timer);
939 update_loading_anim(int fd, short ev, void *d)
943 tab->loading_anim_step = (tab->loading_anim_step+1)%4;
945 if (tab == current_tab) {
946 redraw_modeline(tab);
953 evtimer_add(&tab->loadingev, &loadingev_timer);
957 stop_loading_anim(struct tab *tab)
959 if (!tab->loading_anim)
961 evtimer_del(&tab->loadingev);
962 tab->loading_anim = 0;
963 tab->loading_anim_step = 0;
965 if (tab != current_tab)
968 redraw_modeline(tab);
977 load_url_in_tab(struct tab *tab, const char *url, const char *base)
980 load_url(tab, url, base);
984 message("Loading %s...", url);
985 start_loading_anim(tab);
986 load_url(tab, url, base);
992 switch_to_tab(struct tab *tab)
995 tab->flags &= ~TAB_URGENT;
997 if (operating && tab->flags & TAB_LAZY)
998 load_url_in_tab(tab, tab->hist_cur->h, NULL);
1004 return tab_counter++;
1008 new_tab(const char *url, const char *base)
1012 if ((tab = calloc(1, sizeof(*tab))) == NULL) {
1018 TAILQ_INIT(&tab->hist.head);
1020 TAILQ_INIT(&tab->buffer.head);
1022 tab->id = tab_new_id();
1024 tab->flags |= TAB_LAZY;
1027 if (TAILQ_EMPTY(&tabshead))
1028 TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
1030 TAILQ_INSERT_TAIL(&tabshead, tab, tabs);
1032 load_url_in_tab(tab, url, base);
1037 ui_print_colors(void)
1039 int colors = 0, pairs = 0, can_change = 0;
1040 int columns = 16, lines, color, i, j;
1045 use_default_colors();
1048 pairs = COLOR_PAIRS;
1049 can_change = can_change_color();
1053 printf("Term info:\n");
1054 printf("TERM=%s COLORS=%d COLOR_PAIRS=%d can_change_colors=%d\n",
1055 getenv("TERM"), colors, pairs, can_change);
1059 printf("No color support\n");
1063 printf("Available colors:\n\n");
1064 lines = (colors - 1) / columns + 1;
1066 for (i = 0; i < lines; ++i) {
1067 for (j = 0; j < columns; ++j, ++color) {
1068 printf("\033[0;38;5;%dm %03d", color, color);
1081 setlocale(LC_ALL, "");
1083 TAILQ_INIT(&eecmd_history.head);
1084 TAILQ_INIT(&ir_history.head);
1085 TAILQ_INIT(&lu_history.head);
1087 ministate.line.type = LINE_TEXT;
1088 ministate.vline.parent = &ministate.line;
1089 ministate.buffer.current_line = &ministate.vline;
1091 /* initialize help window */
1092 TAILQ_INIT(&helpwin.head);
1094 base_map = &global_map;
1095 current_map = &global_map;
1099 if (enable_colors) {
1102 use_default_colors();
1107 config_apply_style();
1112 intrflush(stdscr, FALSE);
1114 if ((tabline = newwin(1, COLS, 0, 0)) == NULL)
1116 if ((body = newwin(LINES - 3, COLS, 1, 0)) == NULL)
1118 if ((modeline = newwin(1, COLS, LINES-2, 0)) == NULL)
1120 if ((echoarea = newwin(1, COLS, LINES-1, 0)) == NULL)
1122 if ((minibuffer = newwin(1, COLS, LINES-1, 0)) == NULL)
1124 if ((help = newwin(1, 1, 1, 0)) == NULL)
1127 body_lines = LINES-3;
1130 wbkgd(body, body_face.body);
1131 wbkgd(echoarea, minibuffer_face.background);
1136 scrollok(body, FALSE);
1138 /* non-blocking input */
1141 mvwprintw(body, 0, 0, "");
1144 * Dummy so libevent2 won't complain that no event_base is set
1145 * when checking event_pending for the first time
1147 evtimer_set(&clechoev, handle_clear_echoarea, NULL);
1148 evtimer_set(&resizeev, handle_resize, NULL);
1150 event_set(&stdioev, 0, EV_READ | EV_PERSIST, dispatch_stdio, NULL);
1151 event_add(&stdioev, NULL);
1153 signal_set(&winchev, SIGWINCH, handle_resize, NULL);
1154 signal_add(&winchev, NULL);
1163 switch_to_tab(current_tab);
1164 redraw_tab(current_tab);
1170 ui_on_tab_loaded(struct tab *tab)
1172 stop_loading_anim(tab);
1173 message("Loaded %s", tab->hist_cur->h);
1181 ui_on_tab_refresh(struct tab *tab)
1183 wrap_page(&tab->buffer, body_cols);
1184 if (tab == current_tab)
1187 tab->flags |= TAB_URGENT;
1197 ui_toggle_side_window(void)
1199 side_window = !side_window;
1204 * ugly hack, but otherwise the window doesn't get updated
1205 * until I call rearrange_windows a second time (e.g. via
1206 * C-l). I will be happy to know why something like this is
1209 rearrange_windows();
1210 rearrange_windows();
1214 ui_schedule_redraw(void)
1216 should_rearrange_windows = 1;
1220 ui_require_input(struct tab *tab, int hide)
1222 /* TODO: hard-switching to another tab is ugly */
1225 enter_minibuffer(ir_self_insert, ir_select, exit_minibuffer,
1226 &ir_history, NULL, NULL);
1227 strlcpy(ministate.prompt, "Input required: ",
1228 sizeof(ministate.prompt));
1233 ui_yornp(const char *prompt, void (*fn)(int, struct tab *),
1236 yornp(prompt, fn, data);
1237 redraw_tab(current_tab);
1241 ui_read(const char *prompt, void (*fn)(const char*, struct tab *),
1244 completing_read(prompt, fn, data);
1245 redraw_tab(current_tab);
1253 kill(getpid(), SIGSTOP);
1257 rearrange_windows();