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, 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:
420 wrap_one(buffer, prfx, l, width);
424 if (top_orig == l && buffer->top_line == NULL) {
425 buffer->line_off = buffer->line_max-1;
426 buffer->top_line = TAILQ_LAST(&buffer->head, vhead);
429 vl = TAILQ_PREV(buffer->top_line, vhead, vlines);
430 if (vl == NULL || vl->parent != orig)
432 buffer->top_line = vl;
437 if (orig == l && buffer->current_line == NULL) {
438 buffer->current_line = TAILQ_LAST(&buffer->head, vhead);
441 vl = TAILQ_PREV(buffer->current_line, vhead, vlines);
442 if (vl == NULL || vl->parent != orig)
444 buffer->current_line = vl;
449 if (buffer->current_line == NULL)
450 buffer->current_line = TAILQ_FIRST(&buffer->head);
452 if (buffer->top_line == NULL)
453 buffer->top_line = buffer->current_line;
459 print_vline(int off, int width, WINDOW *window, struct vline *vl)
466 f = &line_faces[vl->parent->type];
468 /* unused, set by getyx */
472 prfx = line_prefixes[vl->parent->type].prfx1;
474 prfx = line_prefixes[vl->parent->type].prfx2;
480 wattr_on(window, body_face.left, NULL);
481 for (i = 0; i < off; i++)
483 wattr_off(window, body_face.left, NULL);
485 wattr_on(window, f->prefix, NULL);
486 wprintw(window, "%s", prfx);
487 wattr_off(window, f->prefix, NULL);
489 wattr_on(window, f->text, NULL);
490 wprintw(window, "%s", text);
491 wattr_off(window, f->text, NULL);
497 wattr_on(window, f->trail, NULL);
498 for (i = 0; i < left - off; ++i)
500 wattr_off(window, f->trail, NULL);
502 wattr_on(window, body_face.right, NULL);
503 for (i = 0; i < off; i++)
505 wattr_off(window, body_face.right, NULL);
513 size_t toskip, ots, tabwidth, space, x;
514 int current, y, truncated;
520 /* unused, but setted by a getyx */
523 tabwidth = sizeof(buf)+1;
527 TAILQ_FOREACH(tab, &tabshead, tabs) {
529 if (tab->flags & TAB_CURRENT)
533 if (toskip * tabwidth < space)
538 while (toskip != 0 &&
539 (ots - toskip+1) * tabwidth < space)
544 wattr_on(tabline, tab_face.background, NULL);
545 wprintw(tabline, toskip == 0 ? " " : "<");
546 wattr_off(tabline, tab_face.background, NULL);
549 TAILQ_FOREACH(tab, &tabshead, tabs) {
557 getyx(tabline, y, x);
558 if (x + sizeof(buf)+2 >= (size_t)COLS)
561 current = tab->flags & TAB_CURRENT;
563 if (*(title = tab->buffer.page.title) == '\0')
564 title = tab->hist_cur->h;
566 if (tab->flags & TAB_URGENT)
567 strlcpy(buf, "!", sizeof(buf));
569 strlcpy(buf, " ", sizeof(buf));
571 if (strlcat(buf, title, sizeof(buf)) >= sizeof(buf)) {
572 /* truncation happens */
573 strlcpy(&buf[sizeof(buf)-4], "...", 4);
575 /* pad with spaces */
576 while (strlcat(buf, " ", sizeof(buf)) < sizeof(buf))
581 wattr_on(tabline, tab_face.current, NULL);
583 wattr_on(tabline, tab_face.tab, NULL);
585 wprintw(tabline, "%s", buf);
586 if (TAILQ_NEXT(tab, tabs) != NULL)
587 wprintw(tabline, " ");
590 wattr_off(tabline, tab_face.current, NULL);
592 wattr_off(tabline, tab_face.tab, NULL);
595 wattr_on(tabline, tab_face.background, NULL);
596 for (; x < (size_t)COLS; ++x)
597 waddch(tabline, ' ');
599 mvwprintw(tabline, 0, COLS-1, ">");
600 wattr_off(tabline, tab_face.background, NULL);
604 * Compute the first visible line around vl. Try to search forward
605 * until the end of the buffer; if a visible line is not found, search
606 * backward. Return NULL if no viable line was found.
609 adjust_line(struct vline *vl, struct buffer *buffer)
616 if (!(vl->parent->flags & L_HIDDEN))
621 t != NULL && t->parent->flags & L_HIDDEN;
622 t = TAILQ_NEXT(t, vlines))
628 /* search backward */
630 t != NULL && t->parent->flags & L_HIDDEN;
631 t = TAILQ_PREV(t, vhead, vlines))
638 redraw_window(WINDOW *win, int off, int height, int width, struct buffer *buffer)
643 restore_curs_x(buffer);
646 * TODO: ignoring buffer->force_update and always
647 * re-rendering. In theory we can recompute the y position
648 * without a re-render, and optimize here. It's not the only
649 * optimisation possible here, wscrl wolud also be an
657 if (TAILQ_EMPTY(&buffer->head))
660 if (buffer->top_line == NULL)
661 buffer->top_line = TAILQ_FIRST(&buffer->head);
663 buffer->top_line = adjust_line(buffer->top_line, buffer);
664 if (buffer->top_line == NULL)
667 buffer->current_line = adjust_line(buffer->current_line, buffer);
671 for (vl = buffer->top_line; vl != NULL; vl = TAILQ_NEXT(vl, vlines)) {
672 if (vl->parent->flags & L_HIDDEN)
676 print_vline(off, width, win, vl);
678 if (vl == buffer->current_line)
690 for (; vl != NULL; vl = TAILQ_NEXT(vl, vlines)) {
691 if (vl == buffer->current_line)
693 if (vl->parent->flags & L_HIDDEN)
696 buffer->top_line = TAILQ_NEXT(buffer->top_line, vlines);
703 buffer->last_line_off = buffer->line_off;
704 buffer->force_redraw = 0;
706 wmove(win, buffer->curs_y, buffer->curs_x);
712 redraw_window(help, 0, help_lines, help_cols, &helpwin);
716 redraw_body(struct tab *tab)
718 static struct tab *last_tab;
721 tab->buffer.force_redraw =1;
724 redraw_window(body, x_offset, body_lines, body_cols, &tab->buffer);
728 trust_status_char(enum trust_state ts)
731 case TS_UNKNOWN: return 'u';
732 case TS_UNTRUSTED: return '!';
733 case TS_TEMP_TRUSTED: return '!';
734 case TS_TRUSTED: return 'v';
735 case TS_VERIFIED: return 'V';
741 redraw_modeline(struct tab *tab)
744 int x, y, max_x, max_y;
745 const char *mode = tab->buffer.page.name;
746 const char *spin = "-\\|/";
749 wattr_on(modeline, modeline_face.background, NULL);
750 wmove(modeline, 0, 0);
752 wprintw(modeline, "-%c%c %s ",
753 spin[tab->loading_anim_step],
754 trust_status_char(tab->trust),
755 mode == NULL ? "(none)" : mode);
757 pct = (tab->buffer.line_off + tab->buffer.curs_y) * 100.0
758 / tab->buffer.line_max;
760 if (tab->buffer.line_max <= (size_t)body_lines)
761 wprintw(modeline, "All ");
762 else if (tab->buffer.line_off == 0)
763 wprintw(modeline, "Top ");
764 else if (tab->buffer.line_off + body_lines >= tab->buffer.line_max)
765 wprintw(modeline, "Bottom ");
767 wprintw(modeline, "%.0f%% ", pct);
769 wprintw(modeline, "%d/%d %s ",
770 tab->buffer.line_off + tab->buffer.curs_y,
771 tab->buffer.line_max,
774 getyx(modeline, y, x);
775 getmaxyx(modeline, max_y, max_x);
780 for (; x < max_x; ++x)
781 waddstr(modeline, "-");
783 wattr_off(modeline, modeline_face.background, NULL);
787 redraw_minibuffer(void)
789 wattr_on(echoarea, minibuffer_face.background, NULL);
793 do_redraw_minibuffer();
795 do_redraw_echoarea();
797 if (in_minibuffer == MB_COMPREAD)
798 do_redraw_minibuffer_compl();
800 wattr_off(echoarea, minibuffer_face.background, NULL);
804 do_redraw_echoarea(void)
808 if (ministate.curmesg != NULL)
809 wprintw(echoarea, "%s", ministate.curmesg);
810 else if (*keybuf != '\0')
811 waddstr(echoarea, keybuf);
813 /* If nothing else, show the URL at point */
815 if (tab->buffer.current_line != NULL &&
816 tab->buffer.current_line->parent->type == LINE_LINK)
818 tab->buffer.current_line->parent->meta.alt);
823 do_redraw_minibuffer(void)
825 size_t off_y, off_x = 0;
826 const char *start, *c;
828 /* unused, set by getyx */
831 mvwprintw(echoarea, 0, 0, "%s", ministate.prompt);
832 if (ministate.hist_cur != NULL)
833 wprintw(echoarea, "(%zu/%zu) ",
834 ministate.hist_off + 1,
835 ministate.history->len);
837 getyx(echoarea, off_y, off_x);
839 start = ministate.hist_cur != NULL
840 ? ministate.hist_cur->h
842 c = utf8_nth(ministate.buffer.current_line->line,
843 ministate.buffer.cpoff);
844 while (utf8_swidth_between(start, c) > (size_t)COLS/2) {
845 start = utf8_next_cp(start);
848 waddstr(echoarea, start);
850 if (ministate.curmesg != NULL)
851 wprintw(echoarea, " [%s]", ministate.curmesg);
853 wmove(echoarea, 0, off_x + utf8_swidth_between(start, c));
857 do_redraw_minibuffer_compl(void)
859 redraw_window(minibuffer, 0, 10, body_cols,
860 &ministate.compl.buffer);
864 * Place the cursor in the right ncurses window. If soft is 1, use
865 * wnoutrefresh (which shouldn't cause any I/O); otherwise use
869 place_cursor(int soft)
871 int (*touch)(WINDOW *);
874 touch = wnoutrefresh;
888 redraw_tab(struct tab *tab)
900 redraw_modeline(tab);
903 wnoutrefresh(tabline);
904 wnoutrefresh(modeline);
906 if (in_minibuffer == MB_COMPREAD)
907 wnoutrefresh(minibuffer);
915 emit_help_item(char *prfx, void *fn)
920 for (cmd = cmds; cmd->cmd != NULL; ++cmd) {
926 if ((l = calloc(1, sizeof(*l))) == NULL)
932 asprintf(&l->line, "%s %s", prfx, cmd->cmd);
934 if (TAILQ_EMPTY(&helpwin.page.head))
935 TAILQ_INSERT_HEAD(&helpwin.page.head, l, lines);
937 TAILQ_INSERT_TAIL(&helpwin.page.head, l, lines);
941 rec_compute_help(struct kmap *keymap, char *prfx, size_t len)
947 TAILQ_FOREACH(k, &keymap->m, keymaps) {
948 strlcpy(p, prfx, sizeof(p));
950 strlcat(p, " ", sizeof(p));
952 strlcat(p, "M-", sizeof(p));
953 if ((kn = unkbd(k->key)) != NULL)
954 strlcat(p, kn, sizeof(p));
956 strlcat(p, keyname(k->key), sizeof(p));
959 rec_compute_help(&k->map, p, sizeof(p));
961 emit_help_item(p, k->fn);
970 empty_vlist(&helpwin);
971 empty_linelist(&helpwin);
972 rec_compute_help(current_map, p, sizeof(p));
973 wrap_page(&helpwin, help_cols);
977 vmessage(const char *fmt, va_list ap)
979 if (evtimer_pending(&clechoev, NULL))
980 evtimer_del(&clechoev);
982 free(ministate.curmesg);
983 ministate.curmesg = NULL;
986 evtimer_set(&clechoev, handle_clear_echoarea, NULL);
987 evtimer_add(&clechoev, &clechoev_timer);
989 /* TODO: what to do if the allocation fails here? */
990 if (vasprintf(&ministate.curmesg, fmt, ap) == -1)
991 ministate.curmesg = NULL;
999 message(const char *fmt, ...)
1009 start_loading_anim(struct tab *tab)
1011 if (tab->loading_anim)
1013 tab->loading_anim = 1;
1014 evtimer_set(&tab->loadingev, update_loading_anim, tab);
1015 evtimer_add(&tab->loadingev, &loadingev_timer);
1019 update_loading_anim(int fd, short ev, void *d)
1021 struct tab *tab = d;
1023 tab->loading_anim_step = (tab->loading_anim_step+1)%4;
1025 if (tab->flags & TAB_CURRENT) {
1026 redraw_modeline(tab);
1033 evtimer_add(&tab->loadingev, &loadingev_timer);
1037 stop_loading_anim(struct tab *tab)
1039 if (!tab->loading_anim)
1041 evtimer_del(&tab->loadingev);
1042 tab->loading_anim = 0;
1043 tab->loading_anim_step = 0;
1045 if (!(tab->flags & TAB_CURRENT))
1048 redraw_modeline(tab);
1057 load_url_in_tab(struct tab *tab, const char *url)
1059 message("Loading %s...", url);
1060 start_loading_anim(tab);
1063 tab->buffer.curs_x = 0;
1064 tab->buffer.curs_y = 0;
1069 switch_to_tab(struct tab *tab)
1073 TAILQ_FOREACH(t, &tabshead, tabs) {
1074 t->flags &= ~TAB_CURRENT;
1077 tab->flags |= TAB_CURRENT;
1078 tab->flags &= ~TAB_URGENT;
1084 return tab_counter++;
1088 new_tab(const char *url)
1092 if ((tab = calloc(1, sizeof(*tab))) == NULL) {
1098 TAILQ_INIT(&tab->hist.head);
1100 TAILQ_INIT(&tab->buffer.head);
1102 tab->id = tab_new_id();
1105 if (TAILQ_EMPTY(&tabshead))
1106 TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
1108 TAILQ_INSERT_TAIL(&tabshead, tab, tabs);
1110 load_url_in_tab(tab, url);
1117 setlocale(LC_ALL, "");
1119 TAILQ_INIT(&eecmd_history.head);
1120 TAILQ_INIT(&ir_history.head);
1121 TAILQ_INIT(&lu_history.head);
1123 ministate.line.type = LINE_TEXT;
1124 ministate.vline.parent = &ministate.line;
1125 ministate.buffer.current_line = &ministate.vline;
1127 /* initialize help window */
1128 TAILQ_INIT(&helpwin.head);
1130 base_map = &global_map;
1131 current_map = &global_map;
1135 if (enable_colors) {
1138 use_default_colors();
1143 config_apply_style();
1148 intrflush(stdscr, FALSE);
1150 if ((tabline = newwin(1, COLS, 0, 0)) == NULL)
1152 if ((body = newwin(LINES - 3, COLS, 1, 0)) == NULL)
1154 if ((modeline = newwin(1, COLS, LINES-2, 0)) == NULL)
1156 if ((echoarea = newwin(1, COLS, LINES-1, 0)) == NULL)
1158 if ((minibuffer = newwin(1, COLS, LINES-1, 0)) == NULL)
1160 if ((help = newwin(1, 1, 1, 0)) == NULL)
1163 body_lines = LINES-3;
1166 wbkgd(body, body_face.body);
1167 wbkgd(echoarea, minibuffer_face.background);
1172 scrollok(body, FALSE);
1174 /* non-blocking input */
1177 mvwprintw(body, 0, 0, "");
1179 event_set(&stdioev, 0, EV_READ | EV_PERSIST, dispatch_stdio, NULL);
1180 event_add(&stdioev, NULL);
1182 signal_set(&winchev, SIGWINCH, handle_resize, NULL);
1183 signal_add(&winchev, NULL);
1189 ui_on_tab_loaded(struct tab *tab)
1191 stop_loading_anim(tab);
1192 message("Loaded %s", tab->hist_cur->h);
1200 ui_on_tab_refresh(struct tab *tab)
1202 wrap_page(&tab->buffer, body_cols);
1203 if (tab->flags & TAB_CURRENT)
1206 tab->flags |= TAB_URGENT;
1216 ui_toggle_side_window(void)
1218 side_window = !side_window;
1223 * ugly hack, but otherwise the window doesn't get updated
1224 * until I call handle_resize a second time (i.e. C-l). I
1225 * will be happy to know why something like this is needed.
1227 handle_resize_nodelay(0, 0, NULL);
1228 handle_resize_nodelay(0, 0, NULL);
1232 ui_schedule_redraw(void)
1234 struct timeval tv = {0, 0};
1236 if (event_pending(&resizeev, EV_TIMEOUT, NULL))
1237 event_del(&resizeev);
1239 evtimer_set(&resizeev, handle_resize_nodelay, NULL);
1240 evtimer_add(&resizeev, &tv);
1244 ui_require_input(struct tab *tab, int hide)
1246 /* TODO: hard-switching to another tab is ugly */
1249 enter_minibuffer(ir_self_insert, ir_select, exit_minibuffer,
1250 &ir_history, NULL, NULL);
1251 strlcpy(ministate.prompt, "Input required: ",
1252 sizeof(ministate.prompt));
1257 ui_yornp(const char *prompt, void (*fn)(int, struct tab *),
1260 yornp(prompt, fn, data);
1261 redraw_tab(current_tab());
1265 ui_read(const char *prompt, void (*fn)(const char*, struct tab *),
1268 completing_read(prompt, fn, data);
1269 redraw_tab(current_tab());