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 int wrap_page(struct buffer*, int);
60 static void print_vline(int, int, WINDOW*, struct vline*);
61 static void redraw_tabline(void);
62 static void redraw_window(WINDOW*, 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 emit_help_item(char*, void*);
73 static void rec_compute_help(struct kmap*, char*, size_t);
74 static void recompute_help(void);
75 static void update_loading_anim(int, short, void*);
76 static void stop_loading_anim(struct tab*);
81 struct thiskey thiskey;
83 static struct event resizeev;
84 static struct timeval resize_timer = { 0, 250000 };
86 static WINDOW *tabline, *body, *modeline, *echoarea, *minibuffer;
88 int body_lines, body_cols;
91 static struct buffer helpwin;
92 static int help_lines, help_cols;
94 static int side_window;
96 static struct event clechoev;
97 static struct timeval clechoev_timer = { 5, 0 };
98 static struct timeval loadingev_timer = { 0, 250000 };
100 static uint32_t tab_counter;
102 static char keybuf[64];
104 struct kmap global_map,
112 update_x_offset(void)
114 if (olivetti_mode && fill_column < body_cols)
115 x_offset = (body_cols - fill_column)/2;
121 save_excursion(struct excursion *place, struct buffer *buffer)
123 place->curs_x = buffer->curs_x;
124 place->curs_y = buffer->curs_y;
125 place->line_off = buffer->line_off;
126 place->current_line = buffer->current_line;
127 place->cpoff = buffer->cpoff;
131 restore_excursion(struct excursion *place, struct buffer *buffer)
133 buffer->curs_x = place->curs_x;
134 buffer->curs_y = place->curs_y;
135 buffer->line_off = place->line_off;
136 buffer->current_line = place->current_line;
137 buffer->cpoff = place->cpoff;
141 restore_curs_x(struct buffer *buffer)
146 vl = buffer->current_line;
147 if (vl == NULL || vl->line == NULL)
148 buffer->curs_x = buffer->cpoff = 0;
150 buffer->curs_x = utf8_snwidth(vl->line, buffer->cpoff);
152 buffer->curs_x += x_offset;
155 prfx = line_prefixes[vl->parent->type].prfx1;
156 buffer->curs_x += utf8_swidth(prfx);
161 global_key_unbound(void)
163 message("%s is undefined", keybuf);
166 static struct vline *
167 nth_line(struct buffer *buffer, size_t n)
173 TAILQ_FOREACH(vl, &buffer->head, vlines) {
188 TAILQ_FOREACH(t, &tabshead, tabs) {
189 if (t->flags & TAB_CURRENT)
201 return &ministate.buffer;
202 return ¤t_tab()->buffer;
210 if ((thiskey.key = wgetch(body)) == ERR)
213 thiskey.meta = thiskey.key == 27;
215 thiskey.key = wgetch(body);
216 if (thiskey.key == ERR || thiskey.key == 27) {
223 if ((unsigned int)thiskey.key < UINT8_MAX) {
225 if (!utf8_decode(&state, &thiskey.cp, (uint8_t)thiskey.key))
227 if ((thiskey.key = wgetch(body)) == ERR) {
228 message("Error decoding user input");
238 dispatch_stdio(int fd, short ev, void *d)
244 /* TODO: schedule a redraw? */
251 if (keybuf[0] != '\0')
252 strlcat(keybuf, " ", sizeof(keybuf));
254 strlcat(keybuf, "M-", sizeof(keybuf));
255 if (thiskey.cp != 0) {
256 utf8_encode(thiskey.cp, tmp);
257 strlcat(keybuf, tmp, sizeof(keybuf));
258 } else if ((keyname = unkbd(thiskey.key)) != NULL) {
259 strlcat(keybuf, keyname, sizeof(keybuf));
261 tmp[0] = thiskey.key;
262 strlcat(keybuf, tmp, sizeof(keybuf));
265 TAILQ_FOREACH(k, ¤t_map->m, keymaps) {
266 if (k->meta == thiskey.meta &&
267 k->key == thiskey.key) {
269 current_map = &k->map;
271 current_map = base_map;
272 strlcpy(keybuf, "", sizeof(keybuf));
273 k->fn(current_buffer());
279 if (current_map->unhandled_input != NULL)
280 current_map->unhandled_input();
282 global_key_unbound();
284 strlcpy(keybuf, "", sizeof(keybuf));
285 current_map = base_map;
291 redraw_tab(current_tab());
295 handle_clear_echoarea(int fd, short ev, void *d)
297 free(ministate.curmesg);
298 ministate.curmesg = NULL;
305 handle_resize(int sig, short ev, void *d)
307 if (event_pending(&resizeev, EV_TIMEOUT, NULL)) {
308 event_del(&resizeev);
310 evtimer_set(&resizeev, handle_resize_nodelay, NULL);
311 evtimer_add(&resizeev, &resize_timer);
315 handle_resize_nodelay(int s, short ev, void *d)
326 if ((too_small = lines < 15)) {
328 printw("Window too small.");
333 /* move and resize the windows, in reverse order! */
335 if (in_minibuffer == MB_COMPREAD) {
336 mvwin(minibuffer, lines-10, 0);
337 wresize(minibuffer, 10, COLS);
340 wrap_page(&ministate.compl.buffer, COLS);
343 mvwin(echoarea, --lines, 0);
344 wresize(echoarea, 1, COLS);
346 mvwin(modeline, --lines, 0);
347 wresize(modeline, 1, COLS);
349 body_lines = --lines;
353 help_cols = 0.3 * COLS;
356 wresize(help, help_lines, help_cols);
358 wrap_page(&helpwin, help_cols);
360 body_cols = COLS - help_cols - 1;
361 mvwin(body, 1, help_cols);
366 wresize(body, body_lines, body_cols);
368 wresize(tabline, 1, COLS);
372 wrap_page(&tab->buffer, body_cols);
377 wrap_page(struct buffer *buffer, int width)
380 const struct line *top_orig, *orig;
385 top_orig = buffer->top_line == NULL ? NULL : buffer->top_line->parent;
386 orig = buffer->current_line == NULL ? NULL : buffer->current_line->parent;
388 buffer->top_line = NULL;
389 buffer->current_line = NULL;
391 buffer->force_redraw = 1;
393 buffer->line_off = 0;
397 TAILQ_FOREACH(l, &buffer->page.head, lines) {
398 prfx = line_prefixes[l->type].prfx1;
409 wrap_text(buffer, prfx, l, MIN(fill_column, width));
411 case LINE_PRE_CONTENT:
413 pre_width = MIN(fill_column, width);
416 hardwrap_text(buffer, l, pre_width);
419 case LINE_COMPL_CURRENT:
421 * TODO: should be width, but will break the
422 * rendering. Fix when unlocking completions
423 * buffer from olivetti-mode.
425 wrap_one(buffer, prfx, l, MIN(fill_column, width));
428 if (top_orig == l && buffer->top_line == NULL) {
429 buffer->line_off = buffer->line_max-1;
430 buffer->top_line = TAILQ_LAST(&buffer->head, vhead);
433 vl = TAILQ_PREV(buffer->top_line, vhead, vlines);
434 if (vl == NULL || vl->parent != orig)
436 buffer->top_line = vl;
441 if (orig == l && buffer->current_line == NULL) {
442 buffer->current_line = TAILQ_LAST(&buffer->head, vhead);
445 vl = TAILQ_PREV(buffer->current_line, vhead, vlines);
446 if (vl == NULL || vl->parent != orig)
448 buffer->current_line = vl;
453 if (buffer->current_line == NULL)
454 buffer->current_line = TAILQ_FIRST(&buffer->head);
456 if (buffer->top_line == NULL)
457 buffer->top_line = buffer->current_line;
463 print_vline(int off, int width, WINDOW *window, struct vline *vl)
470 f = &line_faces[vl->parent->type];
472 /* unused, set by getyx */
476 prfx = line_prefixes[vl->parent->type].prfx1;
478 prfx = line_prefixes[vl->parent->type].prfx2;
484 wattr_on(window, body_face.left, NULL);
485 for (i = 0; i < off; i++)
487 wattr_off(window, body_face.left, NULL);
489 wattr_on(window, f->prefix, NULL);
490 wprintw(window, "%s", prfx);
491 wattr_off(window, f->prefix, NULL);
493 wattr_on(window, f->text, NULL);
494 wprintw(window, "%s", text);
495 wattr_off(window, f->text, NULL);
501 wattr_on(window, f->trail, NULL);
502 for (i = 0; i < left - off; ++i)
504 wattr_off(window, f->trail, NULL);
506 wattr_on(window, body_face.right, NULL);
507 for (i = 0; i < off; i++)
509 wattr_off(window, body_face.right, NULL);
517 size_t toskip, ots, tabwidth, space, x;
518 int current, y, truncated;
524 /* unused, but setted by a getyx */
527 tabwidth = sizeof(buf)+1;
531 TAILQ_FOREACH(tab, &tabshead, tabs) {
533 if (tab->flags & TAB_CURRENT)
537 if (toskip * tabwidth < space)
542 while (toskip != 0 &&
543 (ots - toskip+1) * tabwidth < space)
548 wattr_on(tabline, tab_face.background, NULL);
549 wprintw(tabline, toskip == 0 ? " " : "<");
550 wattr_off(tabline, tab_face.background, NULL);
553 TAILQ_FOREACH(tab, &tabshead, tabs) {
561 getyx(tabline, y, x);
562 if (x + sizeof(buf)+2 >= (size_t)COLS)
565 current = tab->flags & TAB_CURRENT;
567 if (*(title = tab->buffer.page.title) == '\0')
568 title = tab->hist_cur->h;
570 if (tab->flags & TAB_URGENT)
571 strlcpy(buf, "!", sizeof(buf));
573 strlcpy(buf, " ", sizeof(buf));
575 if (strlcat(buf, title, sizeof(buf)) >= sizeof(buf)) {
576 /* truncation happens */
577 strlcpy(&buf[sizeof(buf)-4], "...", 4);
579 /* pad with spaces */
580 while (strlcat(buf, " ", sizeof(buf)) < sizeof(buf))
585 wattr_on(tabline, tab_face.current, NULL);
587 wattr_on(tabline, tab_face.tab, NULL);
589 wprintw(tabline, "%s", buf);
590 if (TAILQ_NEXT(tab, tabs) != NULL)
591 wprintw(tabline, " ");
594 wattr_off(tabline, tab_face.current, NULL);
596 wattr_off(tabline, tab_face.tab, NULL);
599 wattr_on(tabline, tab_face.background, NULL);
600 for (; x < (size_t)COLS; ++x)
601 waddch(tabline, ' ');
603 mvwprintw(tabline, 0, COLS-1, ">");
604 wattr_off(tabline, tab_face.background, NULL);
608 * Compute the first visible line around vl. Try to search forward
609 * until the end of the buffer; if a visible line is not found, search
610 * backward. Return NULL if no viable line was found.
613 adjust_line(struct vline *vl, struct buffer *buffer)
620 if (!(vl->parent->flags & L_HIDDEN))
625 t != NULL && t->parent->flags & L_HIDDEN;
626 t = TAILQ_NEXT(t, vlines))
632 /* search backward */
634 t != NULL && t->parent->flags & L_HIDDEN;
635 t = TAILQ_PREV(t, vhead, vlines))
642 redraw_window(WINDOW *win, int height, int width, struct buffer *buffer)
647 restore_curs_x(buffer);
650 * TODO: ignoring buffer->force_update and always
651 * re-rendering. In theory we can recompute the y position
652 * without a re-render, and optimize here. It's not the only
653 * optimisation possible here, wscrl wolud also be an
661 if (TAILQ_EMPTY(&buffer->head))
664 if (buffer->top_line == NULL)
665 buffer->top_line = TAILQ_FIRST(&buffer->head);
667 buffer->top_line = adjust_line(buffer->top_line, buffer);
668 if (buffer->top_line == NULL)
671 buffer->current_line = adjust_line(buffer->current_line, buffer);
675 for (vl = buffer->top_line; vl != NULL; vl = TAILQ_NEXT(vl, vlines)) {
676 if (vl->parent->flags & L_HIDDEN)
680 print_vline(x_offset, width, win, vl);
682 if (vl == buffer->current_line)
694 for (; vl != NULL; vl = TAILQ_NEXT(vl, vlines)) {
695 if (vl == buffer->current_line)
697 if (vl->parent->flags & L_HIDDEN)
700 buffer->top_line = TAILQ_NEXT(buffer->top_line, vlines);
707 buffer->last_line_off = buffer->line_off;
708 buffer->force_redraw = 0;
710 wmove(win, buffer->curs_y, buffer->curs_x);
716 redraw_window(help, help_lines, help_cols, &helpwin);
720 redraw_body(struct tab *tab)
722 static struct tab *last_tab;
725 tab->buffer.force_redraw =1;
728 redraw_window(body, body_lines, body_cols, &tab->buffer);
732 trust_status_char(enum trust_state ts)
735 case TS_UNKNOWN: return 'u';
736 case TS_UNTRUSTED: return '!';
737 case TS_TEMP_TRUSTED: return '!';
738 case TS_TRUSTED: return 'v';
739 case TS_VERIFIED: return 'V';
745 redraw_modeline(struct tab *tab)
748 int x, y, max_x, max_y;
749 const char *mode = tab->buffer.page.name;
750 const char *spin = "-\\|/";
753 wattr_on(modeline, modeline_face.background, NULL);
754 wmove(modeline, 0, 0);
756 wprintw(modeline, "-%c%c %s ",
757 spin[tab->loading_anim_step],
758 trust_status_char(tab->trust),
759 mode == NULL ? "(none)" : mode);
761 pct = (tab->buffer.line_off + tab->buffer.curs_y) * 100.0
762 / tab->buffer.line_max;
764 if (tab->buffer.line_max <= (size_t)body_lines)
765 wprintw(modeline, "All ");
766 else if (tab->buffer.line_off == 0)
767 wprintw(modeline, "Top ");
768 else if (tab->buffer.line_off + body_lines >= tab->buffer.line_max)
769 wprintw(modeline, "Bottom ");
771 wprintw(modeline, "%.0f%% ", pct);
773 wprintw(modeline, "%d/%d %s ",
774 tab->buffer.line_off + tab->buffer.curs_y,
775 tab->buffer.line_max,
778 getyx(modeline, y, x);
779 getmaxyx(modeline, max_y, max_x);
784 for (; x < max_x; ++x)
785 waddstr(modeline, "-");
787 wattr_off(modeline, modeline_face.background, NULL);
791 redraw_minibuffer(void)
793 wattr_on(echoarea, minibuffer_face.background, NULL);
797 do_redraw_minibuffer();
799 do_redraw_echoarea();
801 if (in_minibuffer == MB_COMPREAD)
802 do_redraw_minibuffer_compl();
804 wattr_off(echoarea, minibuffer_face.background, NULL);
808 do_redraw_echoarea(void)
812 if (ministate.curmesg != NULL)
813 wprintw(echoarea, "%s", ministate.curmesg);
814 else if (*keybuf != '\0')
815 waddstr(echoarea, keybuf);
817 /* If nothing else, show the URL at point */
819 if (tab->buffer.current_line != NULL &&
820 tab->buffer.current_line->parent->type == LINE_LINK)
821 waddstr(echoarea, tab->buffer.current_line->parent->alt);
826 do_redraw_minibuffer(void)
828 size_t off_y, off_x = 0;
829 const char *start, *c;
831 /* unused, set by getyx */
834 mvwprintw(echoarea, 0, 0, "%s", ministate.prompt);
835 if (ministate.hist_cur != NULL)
836 wprintw(echoarea, "(%zu/%zu) ",
837 ministate.hist_off + 1,
838 ministate.history->len);
840 getyx(echoarea, off_y, off_x);
842 start = ministate.hist_cur != NULL
843 ? ministate.hist_cur->h
845 c = utf8_nth(ministate.buffer.current_line->line,
846 ministate.buffer.cpoff);
847 while (utf8_swidth_between(start, c) > (size_t)COLS/2) {
848 start = utf8_next_cp(start);
851 waddstr(echoarea, start);
853 if (ministate.curmesg != NULL)
854 wprintw(echoarea, " [%s]", ministate.curmesg);
856 wmove(echoarea, 0, off_x + utf8_swidth_between(start, c));
860 do_redraw_minibuffer_compl(void)
862 redraw_window(minibuffer, 10, body_cols,
863 &ministate.compl.buffer);
867 * Place the cursor in the right ncurses window. If soft is 1, use
868 * wnoutrefresh (which shouldn't cause any I/O); otherwise use
872 place_cursor(int soft)
874 int (*touch)(WINDOW *);
877 touch = wnoutrefresh;
891 redraw_tab(struct tab *tab)
903 redraw_modeline(tab);
906 wnoutrefresh(tabline);
907 wnoutrefresh(modeline);
909 if (in_minibuffer == MB_COMPREAD)
910 wnoutrefresh(minibuffer);
918 emit_help_item(char *prfx, void *fn)
923 for (cmd = cmds; cmd->cmd != NULL; ++cmd) {
929 if ((l = calloc(1, sizeof(*l))) == NULL)
935 asprintf(&l->line, "%s %s", prfx, cmd->cmd);
937 if (TAILQ_EMPTY(&helpwin.page.head))
938 TAILQ_INSERT_HEAD(&helpwin.page.head, l, lines);
940 TAILQ_INSERT_TAIL(&helpwin.page.head, l, lines);
944 rec_compute_help(struct kmap *keymap, char *prfx, size_t len)
950 TAILQ_FOREACH(k, &keymap->m, keymaps) {
951 strlcpy(p, prfx, sizeof(p));
953 strlcat(p, " ", sizeof(p));
955 strlcat(p, "M-", sizeof(p));
956 if ((kn = unkbd(k->key)) != NULL)
957 strlcat(p, kn, sizeof(p));
959 strlcat(p, keyname(k->key), sizeof(p));
962 rec_compute_help(&k->map, p, sizeof(p));
964 emit_help_item(p, k->fn);
973 empty_vlist(&helpwin);
974 empty_linelist(&helpwin);
975 rec_compute_help(current_map, p, sizeof(p));
976 wrap_page(&helpwin, help_cols);
980 vmessage(const char *fmt, va_list ap)
982 if (evtimer_pending(&clechoev, NULL))
983 evtimer_del(&clechoev);
985 free(ministate.curmesg);
986 ministate.curmesg = NULL;
989 evtimer_set(&clechoev, handle_clear_echoarea, NULL);
990 evtimer_add(&clechoev, &clechoev_timer);
992 /* TODO: what to do if the allocation fails here? */
993 if (vasprintf(&ministate.curmesg, fmt, ap) == -1)
994 ministate.curmesg = NULL;
1002 message(const char *fmt, ...)
1012 start_loading_anim(struct tab *tab)
1014 if (tab->loading_anim)
1016 tab->loading_anim = 1;
1017 evtimer_set(&tab->loadingev, update_loading_anim, tab);
1018 evtimer_add(&tab->loadingev, &loadingev_timer);
1022 update_loading_anim(int fd, short ev, void *d)
1024 struct tab *tab = d;
1026 tab->loading_anim_step = (tab->loading_anim_step+1)%4;
1028 if (tab->flags & TAB_CURRENT) {
1029 redraw_modeline(tab);
1036 evtimer_add(&tab->loadingev, &loadingev_timer);
1040 stop_loading_anim(struct tab *tab)
1042 if (!tab->loading_anim)
1044 evtimer_del(&tab->loadingev);
1045 tab->loading_anim = 0;
1046 tab->loading_anim_step = 0;
1048 if (!(tab->flags & TAB_CURRENT))
1051 redraw_modeline(tab);
1060 load_url_in_tab(struct tab *tab, const char *url)
1062 message("Loading %s...", url);
1063 start_loading_anim(tab);
1066 tab->buffer.curs_x = 0;
1067 tab->buffer.curs_y = 0;
1072 switch_to_tab(struct tab *tab)
1076 TAILQ_FOREACH(t, &tabshead, tabs) {
1077 t->flags &= ~TAB_CURRENT;
1080 tab->flags |= TAB_CURRENT;
1081 tab->flags &= ~TAB_URGENT;
1087 return tab_counter++;
1091 new_tab(const char *url)
1095 if ((tab = calloc(1, sizeof(*tab))) == NULL) {
1101 TAILQ_INIT(&tab->hist.head);
1103 TAILQ_INIT(&tab->buffer.head);
1105 tab->id = tab_new_id();
1108 if (TAILQ_EMPTY(&tabshead))
1109 TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
1111 TAILQ_INSERT_TAIL(&tabshead, tab, tabs);
1113 load_url_in_tab(tab, url);
1120 setlocale(LC_ALL, "");
1122 TAILQ_INIT(&eecmd_history.head);
1123 TAILQ_INIT(&ir_history.head);
1124 TAILQ_INIT(&lu_history.head);
1126 ministate.line.type = LINE_TEXT;
1127 ministate.vline.parent = &ministate.line;
1128 ministate.buffer.current_line = &ministate.vline;
1130 /* initialize help window */
1131 TAILQ_INIT(&helpwin.head);
1133 base_map = &global_map;
1134 current_map = &global_map;
1138 if (enable_colors) {
1141 use_default_colors();
1146 config_apply_style();
1151 intrflush(stdscr, FALSE);
1153 if ((tabline = newwin(1, COLS, 0, 0)) == NULL)
1155 if ((body = newwin(LINES - 3, COLS, 1, 0)) == NULL)
1157 if ((modeline = newwin(1, COLS, LINES-2, 0)) == NULL)
1159 if ((echoarea = newwin(1, COLS, LINES-1, 0)) == NULL)
1161 if ((minibuffer = newwin(1, COLS, LINES-1, 0)) == NULL)
1163 if ((help = newwin(1, 1, 1, 0)) == NULL)
1166 body_lines = LINES-3;
1169 wbkgd(body, body_face.body);
1170 wbkgd(echoarea, minibuffer_face.background);
1175 scrollok(body, FALSE);
1177 /* non-blocking input */
1180 mvwprintw(body, 0, 0, "");
1182 event_set(&stdioev, 0, EV_READ | EV_PERSIST, dispatch_stdio, NULL);
1183 event_add(&stdioev, NULL);
1185 signal_set(&winchev, SIGWINCH, handle_resize, NULL);
1186 signal_add(&winchev, NULL);
1192 ui_on_tab_loaded(struct tab *tab)
1194 stop_loading_anim(tab);
1195 message("Loaded %s", tab->hist_cur->h);
1203 ui_on_tab_refresh(struct tab *tab)
1205 wrap_page(&tab->buffer, body_cols);
1206 if (tab->flags & TAB_CURRENT)
1209 tab->flags |= TAB_URGENT;
1219 ui_toggle_side_window(void)
1221 side_window = !side_window;
1226 * ugly hack, but otherwise the window doesn't get updated
1227 * until I call handle_resize a second time (i.e. C-l). I
1228 * will be happy to know why something like this is needed.
1230 handle_resize_nodelay(0, 0, NULL);
1231 handle_resize_nodelay(0, 0, NULL);
1235 ui_schedule_redraw(void)
1237 struct timeval tv = {0, 0};
1239 if (event_pending(&resizeev, EV_TIMEOUT, NULL))
1240 event_del(&resizeev);
1242 evtimer_set(&resizeev, handle_resize_nodelay, NULL);
1243 evtimer_add(&resizeev, &tv);
1247 ui_require_input(struct tab *tab, int hide)
1249 /* TODO: hard-switching to another tab is ugly */
1252 enter_minibuffer(ir_self_insert, ir_select, exit_minibuffer,
1253 &ir_history, NULL, NULL);
1254 strlcpy(ministate.prompt, "Input required: ",
1255 sizeof(ministate.prompt));
1260 ui_yornp(const char *prompt, void (*fn)(int, struct tab *),
1263 yornp(prompt, fn, data);
1264 redraw_tab(current_tab());
1268 ui_read(const char *prompt, void (*fn)(const char*, struct tab *),
1271 completing_read(prompt, fn, data);
1272 redraw_tab(current_tab());