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);
420 if (top_orig == l && buffer->top_line == NULL) {
421 buffer->line_off = buffer->line_max-1;
422 buffer->top_line = TAILQ_LAST(&buffer->head, vhead);
425 vl = TAILQ_PREV(buffer->top_line, vhead, vlines);
426 if (vl == NULL || vl->parent != orig)
428 buffer->top_line = vl;
433 if (orig == l && buffer->current_line == NULL) {
434 buffer->current_line = TAILQ_LAST(&buffer->head, vhead);
437 vl = TAILQ_PREV(buffer->current_line, vhead, vlines);
438 if (vl == NULL || vl->parent != orig)
440 buffer->current_line = vl;
445 if (buffer->current_line == NULL)
446 buffer->current_line = TAILQ_FIRST(&buffer->head);
448 if (buffer->top_line == NULL)
449 buffer->top_line = buffer->current_line;
455 print_vline(int off, int width, WINDOW *window, struct vline *vl)
462 f = &line_faces[vl->parent->type];
464 /* unused, set by getyx */
468 prfx = line_prefixes[vl->parent->type].prfx1;
470 prfx = line_prefixes[vl->parent->type].prfx2;
476 wattr_on(window, body_face.left, NULL);
477 for (i = 0; i < off; i++)
479 wattr_off(window, body_face.left, NULL);
481 wattr_on(window, f->prefix, NULL);
482 wprintw(window, "%s", prfx);
483 wattr_off(window, f->prefix, NULL);
485 wattr_on(window, f->text, NULL);
486 wprintw(window, "%s", text);
487 wattr_off(window, f->text, NULL);
493 wattr_on(window, f->trail, NULL);
494 for (i = 0; i < left - off; ++i)
496 wattr_off(window, f->trail, NULL);
498 wattr_on(window, body_face.right, NULL);
499 for (i = 0; i < off; i++)
501 wattr_off(window, body_face.right, NULL);
509 size_t toskip, ots, tabwidth, space, x;
510 int current, y, truncated;
516 /* unused, but setted by a getyx */
519 tabwidth = sizeof(buf)+1;
523 TAILQ_FOREACH(tab, &tabshead, tabs) {
525 if (tab->flags & TAB_CURRENT)
529 if (toskip * tabwidth < space)
534 while (toskip != 0 &&
535 (ots - toskip+1) * tabwidth < space)
540 wattr_on(tabline, tab_face.background, NULL);
541 wprintw(tabline, toskip == 0 ? " " : "<");
542 wattr_off(tabline, tab_face.background, NULL);
545 TAILQ_FOREACH(tab, &tabshead, tabs) {
553 getyx(tabline, y, x);
554 if (x + sizeof(buf)+2 >= (size_t)COLS)
557 current = tab->flags & TAB_CURRENT;
559 if (*(title = tab->buffer.page.title) == '\0')
560 title = tab->hist_cur->h;
562 if (tab->flags & TAB_URGENT)
563 strlcpy(buf, "!", sizeof(buf));
565 strlcpy(buf, " ", sizeof(buf));
567 if (strlcat(buf, title, sizeof(buf)) >= sizeof(buf)) {
568 /* truncation happens */
569 strlcpy(&buf[sizeof(buf)-4], "...", 4);
571 /* pad with spaces */
572 while (strlcat(buf, " ", sizeof(buf)) < sizeof(buf))
577 wattr_on(tabline, tab_face.current, NULL);
579 wattr_on(tabline, tab_face.tab, NULL);
581 wprintw(tabline, "%s", buf);
582 if (TAILQ_NEXT(tab, tabs) != NULL)
583 wprintw(tabline, " ");
586 wattr_off(tabline, tab_face.current, NULL);
588 wattr_off(tabline, tab_face.tab, NULL);
591 wattr_on(tabline, tab_face.background, NULL);
592 for (; x < (size_t)COLS; ++x)
593 waddch(tabline, ' ');
595 mvwprintw(tabline, 0, COLS-1, ">");
596 wattr_off(tabline, tab_face.background, NULL);
600 * Compute the first visible line around vl. Try to search forward
601 * until the end of the buffer; if a visible line is not found, search
602 * backward. Return NULL if no viable line was found.
604 static inline struct vline *
605 adjust_line(struct vline *vl, struct buffer *buffer)
612 if (!(vl->parent->flags & L_HIDDEN))
617 t != NULL && t->parent->flags & L_HIDDEN;
618 t = TAILQ_NEXT(t, vlines))
624 /* search backward */
626 t != NULL && t->parent->flags & L_HIDDEN;
627 t = TAILQ_PREV(t, vhead, vlines))
634 redraw_window(WINDOW *win, int height, int width, struct buffer *buffer)
639 restore_curs_x(buffer);
642 * TODO: ignoring buffer->force_update and always
643 * re-rendering. In theory we can recompute the y position
644 * without a re-render, and optimize here. It's not the only
645 * optimisation possible here, wscrl wolud also be an
653 if (TAILQ_EMPTY(&buffer->head))
656 if (buffer->top_line == NULL)
657 buffer->top_line = TAILQ_FIRST(&buffer->head);
659 buffer->top_line = adjust_line(buffer->top_line, buffer);
660 if (buffer->top_line == NULL)
663 buffer->current_line = adjust_line(buffer->current_line, buffer);
667 for (vl = buffer->top_line; vl != NULL; vl = TAILQ_NEXT(vl, vlines)) {
668 if (vl->parent->flags & L_HIDDEN)
672 print_vline(x_offset, width, win, vl);
674 if (vl == buffer->current_line)
686 for (; vl != NULL; vl = TAILQ_NEXT(vl, vlines)) {
687 if (vl == buffer->current_line)
689 if (vl->parent->flags & L_HIDDEN)
692 buffer->top_line = TAILQ_NEXT(buffer->top_line, vlines);
698 buffer->last_line_off = buffer->line_off;
699 buffer->force_redraw = 0;
701 wmove(win, buffer->curs_y, buffer->curs_x);
707 redraw_window(help, help_lines, help_cols, &helpwin);
711 redraw_body(struct tab *tab)
713 static struct tab *last_tab;
716 tab->buffer.force_redraw =1;
719 redraw_window(body, body_lines, body_cols, &tab->buffer);
723 trust_status_char(enum trust_state ts)
726 case TS_UNKNOWN: return 'u';
727 case TS_UNTRUSTED: return '!';
728 case TS_TEMP_TRUSTED: return '!';
729 case TS_TRUSTED: return 'v';
730 case TS_VERIFIED: return 'V';
736 redraw_modeline(struct tab *tab)
739 int x, y, max_x, max_y;
740 const char *mode = tab->buffer.page.name;
741 const char *spin = "-\\|/";
744 wattr_on(modeline, modeline_face.background, NULL);
745 wmove(modeline, 0, 0);
747 wprintw(modeline, "-%c%c %s ",
748 spin[tab->loading_anim_step],
749 trust_status_char(tab->trust),
750 mode == NULL ? "(none)" : mode);
752 pct = (tab->buffer.line_off + tab->buffer.curs_y) * 100.0 / tab->buffer.line_max;
754 if (tab->buffer.line_max <= (size_t)body_lines)
755 wprintw(modeline, "All ");
756 else if (tab->buffer.line_off == 0)
757 wprintw(modeline, "Top ");
758 else if (tab->buffer.line_off + body_lines >= tab->buffer.line_max)
759 wprintw(modeline, "Bottom ");
761 wprintw(modeline, "%.0f%% ", pct);
763 wprintw(modeline, "%d/%d %s ",
764 tab->buffer.line_off + tab->buffer.curs_y,
765 tab->buffer.line_max,
768 getyx(modeline, y, x);
769 getmaxyx(modeline, max_y, max_x);
774 for (; x < max_x; ++x)
775 waddstr(modeline, "-");
777 wattr_off(modeline, modeline_face.background, NULL);
781 redraw_minibuffer(void)
783 wattr_on(echoarea, minibuffer_face.background, NULL);
787 do_redraw_minibuffer();
789 do_redraw_echoarea();
791 if (in_minibuffer == MB_COMPREAD)
792 do_redraw_minibuffer_compl();
794 wattr_off(echoarea, minibuffer_face.background, NULL);
798 do_redraw_echoarea(void)
802 if (ministate.curmesg != NULL)
803 wprintw(echoarea, "%s", ministate.curmesg);
804 else if (*keybuf != '\0')
805 waddstr(echoarea, keybuf);
807 /* If nothing else, show the URL at point */
809 if (tab->buffer.current_line != NULL &&
810 tab->buffer.current_line->parent->type == LINE_LINK)
811 waddstr(echoarea, tab->buffer.current_line->parent->alt);
816 do_redraw_minibuffer(void)
818 size_t off_y, off_x = 0;
819 const char *start, *c;
821 /* unused, set by getyx */
824 mvwprintw(echoarea, 0, 0, "%s", ministate.prompt);
825 if (ministate.hist_cur != NULL)
826 wprintw(echoarea, "(%zu/%zu) ",
827 ministate.hist_off + 1,
828 ministate.history->len);
830 getyx(echoarea, off_y, off_x);
832 start = ministate.hist_cur != NULL
833 ? ministate.hist_cur->h
835 c = utf8_nth(ministate.buffer.current_line->line,
836 ministate.buffer.cpoff);
837 while (utf8_swidth_between(start, c) > (size_t)COLS/2) {
838 start = utf8_next_cp(start);
841 waddstr(echoarea, start);
843 if (ministate.curmesg != NULL)
844 wprintw(echoarea, " [%s]", ministate.curmesg);
846 wmove(echoarea, 0, off_x + utf8_swidth_between(start, c));
850 do_redraw_minibuffer_compl(void)
852 redraw_window(minibuffer, 10, body_cols,
853 &ministate.compl.buffer);
857 * Place the cursor in the right ncurses window. If soft is 1, use
858 * wnoutrefresh (which shouldn't cause any I/O); otherwise use
862 place_cursor(int soft)
864 int (*touch)(WINDOW *);
867 touch = wnoutrefresh;
881 redraw_tab(struct tab *tab)
893 redraw_modeline(tab);
896 wnoutrefresh(tabline);
897 wnoutrefresh(modeline);
899 if (in_minibuffer == MB_COMPREAD)
900 wnoutrefresh(minibuffer);
908 emit_help_item(char *prfx, void *fn)
913 for (cmd = cmds; cmd->cmd != NULL; ++cmd) {
919 if ((l = calloc(1, sizeof(*l))) == NULL)
925 asprintf(&l->line, "%s %s", prfx, cmd->cmd);
927 if (TAILQ_EMPTY(&helpwin.page.head))
928 TAILQ_INSERT_HEAD(&helpwin.page.head, l, lines);
930 TAILQ_INSERT_TAIL(&helpwin.page.head, l, lines);
934 rec_compute_help(struct kmap *keymap, char *prfx, size_t len)
940 TAILQ_FOREACH(k, &keymap->m, keymaps) {
941 strlcpy(p, prfx, sizeof(p));
943 strlcat(p, " ", sizeof(p));
945 strlcat(p, "M-", sizeof(p));
946 if ((kn = unkbd(k->key)) != NULL)
947 strlcat(p, kn, sizeof(p));
949 strlcat(p, keyname(k->key), sizeof(p));
952 rec_compute_help(&k->map, p, sizeof(p));
954 emit_help_item(p, k->fn);
963 empty_vlist(&helpwin);
964 empty_linelist(&helpwin);
965 rec_compute_help(current_map, p, sizeof(p));
966 wrap_page(&helpwin, help_cols);
970 vmessage(const char *fmt, va_list ap)
972 if (evtimer_pending(&clechoev, NULL))
973 evtimer_del(&clechoev);
975 free(ministate.curmesg);
976 ministate.curmesg = NULL;
979 evtimer_set(&clechoev, handle_clear_echoarea, NULL);
980 evtimer_add(&clechoev, &clechoev_timer);
982 /* TODO: what to do if the allocation fails here? */
983 if (vasprintf(&ministate.curmesg, fmt, ap) == -1)
984 ministate.curmesg = NULL;
992 message(const char *fmt, ...)
1002 start_loading_anim(struct tab *tab)
1004 if (tab->loading_anim)
1006 tab->loading_anim = 1;
1007 evtimer_set(&tab->loadingev, update_loading_anim, tab);
1008 evtimer_add(&tab->loadingev, &loadingev_timer);
1012 update_loading_anim(int fd, short ev, void *d)
1014 struct tab *tab = d;
1016 tab->loading_anim_step = (tab->loading_anim_step+1)%4;
1018 if (tab->flags & TAB_CURRENT) {
1019 redraw_modeline(tab);
1026 evtimer_add(&tab->loadingev, &loadingev_timer);
1030 stop_loading_anim(struct tab *tab)
1032 if (!tab->loading_anim)
1034 evtimer_del(&tab->loadingev);
1035 tab->loading_anim = 0;
1036 tab->loading_anim_step = 0;
1038 if (!(tab->flags & TAB_CURRENT))
1041 redraw_modeline(tab);
1050 load_url_in_tab(struct tab *tab, const char *url)
1052 message("Loading %s...", url);
1053 start_loading_anim(tab);
1056 tab->buffer.curs_x = 0;
1057 tab->buffer.curs_y = 0;
1062 switch_to_tab(struct tab *tab)
1066 TAILQ_FOREACH(t, &tabshead, tabs) {
1067 t->flags &= ~TAB_CURRENT;
1070 tab->flags |= TAB_CURRENT;
1071 tab->flags &= ~TAB_URGENT;
1077 return tab_counter++;
1081 new_tab(const char *url)
1085 if ((tab = calloc(1, sizeof(*tab))) == NULL) {
1091 TAILQ_INIT(&tab->hist.head);
1093 TAILQ_INIT(&tab->buffer.head);
1095 tab->id = tab_new_id();
1098 if (TAILQ_EMPTY(&tabshead))
1099 TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
1101 TAILQ_INSERT_TAIL(&tabshead, tab, tabs);
1103 load_url_in_tab(tab, url);
1110 setlocale(LC_ALL, "");
1112 TAILQ_INIT(&eecmd_history.head);
1113 TAILQ_INIT(&ir_history.head);
1114 TAILQ_INIT(&lu_history.head);
1116 ministate.line.type = LINE_TEXT;
1117 ministate.vline.parent = &ministate.line;
1118 ministate.buffer.current_line = &ministate.vline;
1120 /* initialize help window */
1121 TAILQ_INIT(&helpwin.head);
1123 base_map = &global_map;
1124 current_map = &global_map;
1128 if (enable_colors) {
1131 use_default_colors();
1136 config_apply_style();
1141 intrflush(stdscr, FALSE);
1143 if ((tabline = newwin(1, COLS, 0, 0)) == NULL)
1145 if ((body = newwin(LINES - 3, COLS, 1, 0)) == NULL)
1147 if ((modeline = newwin(1, COLS, LINES-2, 0)) == NULL)
1149 if ((echoarea = newwin(1, COLS, LINES-1, 0)) == NULL)
1151 if ((minibuffer = newwin(1, COLS, LINES-1, 0)) == NULL)
1153 if ((help = newwin(1, 1, 1, 0)) == NULL)
1156 body_lines = LINES-3;
1159 wbkgd(body, body_face.body);
1160 wbkgd(echoarea, minibuffer_face.background);
1165 scrollok(body, FALSE);
1167 /* non-blocking input */
1170 mvwprintw(body, 0, 0, "");
1172 event_set(&stdioev, 0, EV_READ | EV_PERSIST, dispatch_stdio, NULL);
1173 event_add(&stdioev, NULL);
1175 signal_set(&winchev, SIGWINCH, handle_resize, NULL);
1176 signal_add(&winchev, NULL);
1182 ui_on_tab_loaded(struct tab *tab)
1184 stop_loading_anim(tab);
1185 message("Loaded %s", tab->hist_cur->h);
1193 ui_on_tab_refresh(struct tab *tab)
1195 wrap_page(&tab->buffer, body_cols);
1196 if (tab->flags & TAB_CURRENT)
1199 tab->flags |= TAB_URGENT;
1209 ui_toggle_side_window(void)
1211 side_window = !side_window;
1216 * ugly hack, but otherwise the window doesn't get updated
1217 * until I call handle_resize a second time (i.e. C-l). I
1218 * will be happy to know why something like this is needed.
1220 handle_resize_nodelay(0, 0, NULL);
1221 handle_resize_nodelay(0, 0, NULL);
1225 ui_schedule_redraw(void)
1227 struct timeval tv = {0, 0};
1229 if (event_pending(&resizeev, EV_TIMEOUT, NULL))
1230 event_del(&resizeev);
1232 evtimer_set(&resizeev, handle_resize_nodelay, NULL);
1233 evtimer_add(&resizeev, &tv);
1237 ui_require_input(struct tab *tab, int hide)
1239 /* TODO: hard-switching to another tab is ugly */
1242 enter_minibuffer(ir_self_insert, ir_select, exit_minibuffer,
1243 &ir_history, NULL, NULL);
1244 strlcpy(ministate.prompt, "Input required: ",
1245 sizeof(ministate.prompt));
1250 ui_yornp(const char *prompt, void (*fn)(int, struct tab *),
1253 yornp(prompt, fn, data);
1254 redraw_tab(current_tab());
1258 ui_read(const char *prompt, void (*fn)(const char*, struct tab *),
1261 completing_read(prompt, fn, data);
1262 redraw_tab(current_tab());