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 place_cursor(int);
70 static void redraw_tab(struct tab*);
71 static void emit_help_item(char*, void*);
72 static void rec_compute_help(struct kmap*, char*, size_t);
73 static void recompute_help(void);
74 static void update_loading_anim(int, short, void*);
75 static void stop_loading_anim(struct tab*);
80 struct thiskey thiskey;
82 static struct event resizeev;
83 static struct timeval resize_timer = { 0, 250000 };
85 static WINDOW *tabline, *body, *modeline, *echoarea, *minibuffer;
87 int body_lines, body_cols;
90 static struct buffer helpwin;
91 static int help_lines, help_cols;
93 static int side_window;
95 static struct event clechoev;
96 static struct timeval clechoev_timer = { 5, 0 };
97 static struct timeval loadingev_timer = { 0, 250000 };
99 static uint32_t tab_counter;
101 static char keybuf[64];
103 struct kmap global_map,
111 update_x_offset(void)
113 if (olivetti_mode && fill_column < body_cols)
114 x_offset = (body_cols - fill_column)/2;
120 save_excursion(struct excursion *place, struct buffer *buffer)
122 place->curs_x = buffer->curs_x;
123 place->curs_y = buffer->curs_y;
124 place->line_off = buffer->line_off;
125 place->current_line = buffer->current_line;
126 place->cpoff = buffer->cpoff;
130 restore_excursion(struct excursion *place, struct buffer *buffer)
132 buffer->curs_x = place->curs_x;
133 buffer->curs_y = place->curs_y;
134 buffer->line_off = place->line_off;
135 buffer->current_line = place->current_line;
136 buffer->cpoff = place->cpoff;
140 restore_curs_x(struct buffer *buffer)
145 vl = buffer->current_line;
146 if (vl == NULL || vl->line == NULL)
147 buffer->curs_x = buffer->cpoff = 0;
149 buffer->curs_x = utf8_snwidth(vl->line, buffer->cpoff);
151 buffer->curs_x += x_offset;
154 prfx = line_prefixes[vl->parent->type].prfx1;
155 buffer->curs_x += utf8_swidth(prfx);
160 global_key_unbound(void)
162 message("%s is undefined", keybuf);
165 static struct vline *
166 nth_line(struct buffer *buffer, size_t n)
172 TAILQ_FOREACH(vl, &buffer->head, vlines) {
187 TAILQ_FOREACH(t, &tabshead, tabs) {
188 if (t->flags & TAB_CURRENT)
200 return &ministate.buffer;
201 return ¤t_tab()->buffer;
209 if ((thiskey.key = wgetch(body)) == ERR)
212 thiskey.meta = thiskey.key == 27;
214 thiskey.key = wgetch(body);
215 if (thiskey.key == ERR || thiskey.key == 27) {
222 if ((unsigned int)thiskey.key < UINT8_MAX) {
224 if (!utf8_decode(&state, &thiskey.cp, (uint8_t)thiskey.key))
226 if ((thiskey.key = wgetch(body)) == ERR) {
227 message("Error decoding user input");
237 dispatch_stdio(int fd, short ev, void *d)
243 /* TODO: schedule a redraw? */
250 if (keybuf[0] != '\0')
251 strlcat(keybuf, " ", sizeof(keybuf));
253 strlcat(keybuf, "M-", sizeof(keybuf));
254 if (thiskey.cp != 0) {
255 utf8_encode(thiskey.cp, tmp);
256 strlcat(keybuf, tmp, sizeof(keybuf));
257 } else if ((keyname = unkbd(thiskey.key)) != NULL) {
258 strlcat(keybuf, keyname, sizeof(keybuf));
260 tmp[0] = thiskey.key;
261 strlcat(keybuf, tmp, sizeof(keybuf));
264 TAILQ_FOREACH(k, ¤t_map->m, keymaps) {
265 if (k->meta == thiskey.meta &&
266 k->key == thiskey.key) {
268 current_map = &k->map;
270 current_map = base_map;
271 strlcpy(keybuf, "", sizeof(keybuf));
272 k->fn(current_buffer());
278 if (current_map->unhandled_input != NULL)
279 current_map->unhandled_input();
281 global_key_unbound();
283 strlcpy(keybuf, "", sizeof(keybuf));
284 current_map = base_map;
290 redraw_tab(current_tab());
294 handle_clear_echoarea(int fd, short ev, void *d)
296 free(ministate.curmesg);
297 ministate.curmesg = NULL;
304 handle_resize(int sig, short ev, void *d)
306 if (event_pending(&resizeev, EV_TIMEOUT, NULL)) {
307 event_del(&resizeev);
309 evtimer_set(&resizeev, handle_resize_nodelay, NULL);
310 evtimer_add(&resizeev, &resize_timer);
314 handle_resize_nodelay(int s, short ev, void *d)
325 if ((too_small = lines < 15)) {
327 printw("Window too small.");
332 /* move and resize the windows, in reverse order! */
334 mvwin(echoarea, --lines, 0);
335 wresize(echoarea, 1, COLS);
337 mvwin(modeline, --lines, 0);
338 wresize(modeline, 1, COLS);
340 body_lines = --lines;
344 help_cols = 0.3 * COLS;
347 wresize(help, help_lines, help_cols);
349 wrap_page(&helpwin, help_cols);
351 body_cols = COLS - help_cols - 1;
352 mvwin(body, 1, help_cols);
357 wresize(body, body_lines, body_cols);
359 wresize(tabline, 1, COLS);
363 wrap_page(&tab->buffer, body_cols);
368 wrap_page(struct buffer *buffer, int width)
371 const struct line *top_orig, *orig;
376 top_orig = buffer->top_line == NULL ? NULL : buffer->top_line->parent;
377 orig = buffer->current_line == NULL ? NULL : buffer->current_line->parent;
379 buffer->top_line = NULL;
380 buffer->current_line = NULL;
382 buffer->force_redraw = 1;
384 buffer->line_off = 0;
388 TAILQ_FOREACH(l, &buffer->page.head, lines) {
389 prfx = line_prefixes[l->type].prfx1;
400 wrap_text(buffer, prfx, l, MIN(fill_column, width));
402 case LINE_PRE_CONTENT:
404 pre_width = MIN(fill_column, width);
407 hardwrap_text(buffer, l, pre_width);
411 if (top_orig == l && buffer->top_line == NULL) {
412 buffer->line_off = buffer->line_max-1;
413 buffer->top_line = TAILQ_LAST(&buffer->head, vhead);
416 vl = TAILQ_PREV(buffer->top_line, vhead, vlines);
417 if (vl == NULL || vl->parent != orig)
419 buffer->top_line = vl;
424 if (orig == l && buffer->current_line == NULL) {
425 buffer->current_line = TAILQ_LAST(&buffer->head, vhead);
428 vl = TAILQ_PREV(buffer->current_line, vhead, vlines);
429 if (vl == NULL || vl->parent != orig)
431 buffer->current_line = vl;
436 if (buffer->current_line == NULL)
437 buffer->current_line = TAILQ_FIRST(&buffer->head);
439 if (buffer->top_line == NULL)
440 buffer->top_line = buffer->current_line;
446 print_vline(int off, int width, WINDOW *window, struct vline *vl)
453 f = &line_faces[vl->parent->type];
455 /* unused, set by getyx */
459 prfx = line_prefixes[vl->parent->type].prfx1;
461 prfx = line_prefixes[vl->parent->type].prfx2;
467 wattr_on(window, body_face.left, NULL);
468 for (i = 0; i < off; i++)
470 wattr_off(window, body_face.left, NULL);
472 wattr_on(window, f->prefix, NULL);
473 wprintw(window, "%s", prfx);
474 wattr_off(window, f->prefix, NULL);
476 wattr_on(window, f->text, NULL);
477 wprintw(window, "%s", text);
478 wattr_off(window, f->text, NULL);
484 wattr_on(window, f->trail, NULL);
485 for (i = 0; i < left - off; ++i)
487 wattr_off(window, f->trail, NULL);
489 wattr_on(window, body_face.right, NULL);
490 for (i = 0; i < off; i++)
492 wattr_off(window, body_face.right, NULL);
500 size_t toskip, ots, tabwidth, space, x;
501 int current, y, truncated;
507 /* unused, but setted by a getyx */
510 tabwidth = sizeof(buf)+1;
514 TAILQ_FOREACH(tab, &tabshead, tabs) {
516 if (tab->flags & TAB_CURRENT)
520 if (toskip * tabwidth < space)
525 while (toskip != 0 &&
526 (ots - toskip+1) * tabwidth < space)
531 wattr_on(tabline, tab_face.background, NULL);
532 wprintw(tabline, toskip == 0 ? " " : "<");
533 wattr_off(tabline, tab_face.background, NULL);
536 TAILQ_FOREACH(tab, &tabshead, tabs) {
544 getyx(tabline, y, x);
545 if (x + sizeof(buf)+2 >= (size_t)COLS)
548 current = tab->flags & TAB_CURRENT;
550 if (*(title = tab->buffer.page.title) == '\0')
551 title = tab->hist_cur->h;
553 if (tab->flags & TAB_URGENT)
554 strlcpy(buf, "!", sizeof(buf));
556 strlcpy(buf, " ", sizeof(buf));
558 if (strlcat(buf, title, sizeof(buf)) >= sizeof(buf)) {
559 /* truncation happens */
560 strlcpy(&buf[sizeof(buf)-4], "...", 4);
562 /* pad with spaces */
563 while (strlcat(buf, " ", sizeof(buf)) < sizeof(buf))
568 wattr_on(tabline, tab_face.current, NULL);
570 wattr_on(tabline, tab_face.tab, NULL);
572 wprintw(tabline, "%s", buf);
573 if (TAILQ_NEXT(tab, tabs) != NULL)
574 wprintw(tabline, " ");
577 wattr_off(tabline, tab_face.current, NULL);
579 wattr_off(tabline, tab_face.tab, NULL);
582 wattr_on(tabline, tab_face.background, NULL);
583 for (; x < (size_t)COLS; ++x)
584 waddch(tabline, ' ');
586 mvwprintw(tabline, 0, COLS-1, ">");
587 wattr_off(tabline, tab_face.background, NULL);
591 * Compute the first visible line around vl. Try to search forward
592 * until the end of the buffer; if a visible line is not found, search
593 * backward. Return NULL if no viable line was found.
595 static inline struct vline *
596 adjust_line(struct vline *vl, struct buffer *buffer)
600 if (!(vl->parent->flags & L_HIDDEN))
605 t != NULL && t->parent->flags & L_HIDDEN;
606 t = TAILQ_NEXT(t, vlines))
612 /* search backward */
614 t != NULL && t->parent->flags & L_HIDDEN;
615 t = TAILQ_PREV(t, vhead, vlines))
622 redraw_window(WINDOW *win, int height, int width, struct buffer *buffer)
627 restore_curs_x(buffer);
630 * TODO: ignoring buffer->force_update and always
631 * re-rendering. In theory we can recompute the y position
632 * without a re-render, and optimize here. It's not the only
633 * optimisation possible here, wscrl wolud also be an
641 if (TAILQ_EMPTY(&buffer->head))
644 buffer->top_line = adjust_line(buffer->top_line, buffer);
645 if (buffer->top_line == NULL)
648 buffer->current_line = adjust_line(buffer->current_line, buffer);
652 for (vl = buffer->top_line; vl != NULL; vl = TAILQ_NEXT(vl, vlines)) {
653 if (vl->parent->flags & L_HIDDEN)
657 print_vline(x_offset, width, win, vl);
659 if (vl == buffer->current_line)
671 for (; vl != NULL; vl = TAILQ_NEXT(vl, vlines)) {
672 if (vl == buffer->current_line)
674 if (vl->parent->flags & L_HIDDEN)
677 buffer->top_line = TAILQ_NEXT(buffer->top_line, vlines);
683 buffer->last_line_off = buffer->line_off;
684 buffer->force_redraw = 0;
686 wmove(win, buffer->curs_y, buffer->curs_x);
692 redraw_window(help, help_lines, help_cols, &helpwin);
696 redraw_body(struct tab *tab)
698 static struct tab *last_tab;
701 tab->buffer.force_redraw =1;
704 redraw_window(body, body_lines, body_cols, &tab->buffer);
708 trust_status_char(enum trust_state ts)
711 case TS_UNKNOWN: return 'u';
712 case TS_UNTRUSTED: return '!';
713 case TS_TEMP_TRUSTED: return '!';
714 case TS_TRUSTED: return 'v';
715 case TS_VERIFIED: return 'V';
721 redraw_modeline(struct tab *tab)
724 int x, y, max_x, max_y;
725 const char *mode = tab->buffer.page.name;
726 const char *spin = "-\\|/";
729 wattr_on(modeline, modeline_face.background, NULL);
730 wmove(modeline, 0, 0);
732 wprintw(modeline, "-%c%c %s ",
733 spin[tab->loading_anim_step],
734 trust_status_char(tab->trust),
735 mode == NULL ? "(none)" : mode);
737 pct = (tab->buffer.line_off + tab->buffer.curs_y) * 100.0 / tab->buffer.line_max;
739 if (tab->buffer.line_max <= (size_t)body_lines)
740 wprintw(modeline, "All ");
741 else if (tab->buffer.line_off == 0)
742 wprintw(modeline, "Top ");
743 else if (tab->buffer.line_off + body_lines >= tab->buffer.line_max)
744 wprintw(modeline, "Bottom ");
746 wprintw(modeline, "%.0f%% ", pct);
748 wprintw(modeline, "%d/%d %s ",
749 tab->buffer.line_off + tab->buffer.curs_y,
750 tab->buffer.line_max,
753 getyx(modeline, y, x);
754 getmaxyx(modeline, max_y, max_x);
759 for (; x < max_x; ++x)
760 waddstr(modeline, "-");
762 wattr_off(modeline, modeline_face.background, NULL);
766 redraw_minibuffer(void)
768 wattr_on(echoarea, minibuffer_face.background, NULL);
772 do_redraw_minibuffer();
774 do_redraw_echoarea();
776 wattr_off(echoarea, minibuffer_face.background, NULL);
780 do_redraw_echoarea(void)
784 if (ministate.curmesg != NULL)
785 wprintw(echoarea, "%s", ministate.curmesg);
786 else if (*keybuf != '\0')
787 waddstr(echoarea, keybuf);
789 /* If nothing else, show the URL at point */
791 if (tab->buffer.current_line != NULL &&
792 tab->buffer.current_line->parent->type == LINE_LINK)
793 waddstr(echoarea, tab->buffer.current_line->parent->alt);
798 do_redraw_minibuffer(void)
800 size_t off_y, off_x = 0;
801 const char *start, *c;
803 /* unused, set by getyx */
806 mvwprintw(echoarea, 0, 0, "%s", ministate.prompt);
807 if (ministate.hist_cur != NULL)
808 wprintw(echoarea, "(%zu/%zu) ",
809 ministate.hist_off + 1,
810 ministate.history->len);
812 getyx(echoarea, off_y, off_x);
814 start = ministate.hist_cur != NULL
815 ? ministate.hist_cur->h
817 c = utf8_nth(ministate.buffer.current_line->line,
818 ministate.buffer.cpoff);
819 while (utf8_swidth_between(start, c) > (size_t)COLS/2) {
820 start = utf8_next_cp(start);
823 waddstr(echoarea, start);
825 if (ministate.curmesg != NULL)
826 wprintw(echoarea, " [%s]", ministate.curmesg);
828 wmove(echoarea, 0, off_x + utf8_swidth_between(start, c));
832 * Place the cursor in the right ncurses window. If soft is 1, use
833 * wnoutrefresh (which shouldn't cause any I/O); otherwise use
837 place_cursor(int soft)
839 int (*touch)(WINDOW *);
842 touch = wnoutrefresh;
856 redraw_tab(struct tab *tab)
868 redraw_modeline(tab);
871 wnoutrefresh(tabline);
872 wnoutrefresh(modeline);
880 emit_help_item(char *prfx, void *fn)
885 for (cmd = cmds; cmd->cmd != NULL; ++cmd) {
891 if ((l = calloc(1, sizeof(*l))) == NULL)
897 asprintf(&l->line, "%s %s", prfx, cmd->cmd);
899 if (TAILQ_EMPTY(&helpwin.page.head))
900 TAILQ_INSERT_HEAD(&helpwin.page.head, l, lines);
902 TAILQ_INSERT_TAIL(&helpwin.page.head, l, lines);
906 rec_compute_help(struct kmap *keymap, char *prfx, size_t len)
912 TAILQ_FOREACH(k, &keymap->m, keymaps) {
913 strlcpy(p, prfx, sizeof(p));
915 strlcat(p, " ", sizeof(p));
917 strlcat(p, "M-", sizeof(p));
918 if ((kn = unkbd(k->key)) != NULL)
919 strlcat(p, kn, sizeof(p));
921 strlcat(p, keyname(k->key), sizeof(p));
924 rec_compute_help(&k->map, p, sizeof(p));
926 emit_help_item(p, k->fn);
935 empty_vlist(&helpwin);
936 empty_linelist(&helpwin);
937 rec_compute_help(current_map, p, sizeof(p));
938 wrap_page(&helpwin, help_cols);
942 vmessage(const char *fmt, va_list ap)
944 if (evtimer_pending(&clechoev, NULL))
945 evtimer_del(&clechoev);
947 free(ministate.curmesg);
948 ministate.curmesg = NULL;
951 evtimer_set(&clechoev, handle_clear_echoarea, NULL);
952 evtimer_add(&clechoev, &clechoev_timer);
954 /* TODO: what to do if the allocation fails here? */
955 if (vasprintf(&ministate.curmesg, fmt, ap) == -1)
956 ministate.curmesg = NULL;
964 message(const char *fmt, ...)
974 start_loading_anim(struct tab *tab)
976 if (tab->loading_anim)
978 tab->loading_anim = 1;
979 evtimer_set(&tab->loadingev, update_loading_anim, tab);
980 evtimer_add(&tab->loadingev, &loadingev_timer);
984 update_loading_anim(int fd, short ev, void *d)
988 tab->loading_anim_step = (tab->loading_anim_step+1)%4;
990 if (tab->flags & TAB_CURRENT) {
991 redraw_modeline(tab);
998 evtimer_add(&tab->loadingev, &loadingev_timer);
1002 stop_loading_anim(struct tab *tab)
1004 if (!tab->loading_anim)
1006 evtimer_del(&tab->loadingev);
1007 tab->loading_anim = 0;
1008 tab->loading_anim_step = 0;
1010 if (!(tab->flags & TAB_CURRENT))
1013 redraw_modeline(tab);
1022 load_url_in_tab(struct tab *tab, const char *url)
1024 message("Loading %s...", url);
1025 start_loading_anim(tab);
1028 tab->buffer.curs_x = 0;
1029 tab->buffer.curs_y = 0;
1034 switch_to_tab(struct tab *tab)
1038 TAILQ_FOREACH(t, &tabshead, tabs) {
1039 t->flags &= ~TAB_CURRENT;
1042 tab->flags |= TAB_CURRENT;
1043 tab->flags &= ~TAB_URGENT;
1049 return tab_counter++;
1053 new_tab(const char *url)
1057 if ((tab = calloc(1, sizeof(*tab))) == NULL) {
1063 TAILQ_INIT(&tab->hist.head);
1065 TAILQ_INIT(&tab->buffer.head);
1067 tab->id = tab_new_id();
1070 if (TAILQ_EMPTY(&tabshead))
1071 TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
1073 TAILQ_INSERT_TAIL(&tabshead, tab, tabs);
1075 load_url_in_tab(tab, url);
1082 setlocale(LC_ALL, "");
1084 TAILQ_INIT(&eecmd_history.head);
1085 TAILQ_INIT(&ir_history.head);
1086 TAILQ_INIT(&lu_history.head);
1088 ministate.line.type = LINE_TEXT;
1089 ministate.vline.parent = &ministate.line;
1090 ministate.buffer.current_line = &ministate.vline;
1092 /* initialize help window */
1093 TAILQ_INIT(&helpwin.head);
1095 base_map = &global_map;
1096 current_map = &global_map;
1100 if (enable_colors) {
1103 use_default_colors();
1108 config_apply_style();
1113 intrflush(stdscr, FALSE);
1115 if ((tabline = newwin(1, COLS, 0, 0)) == NULL)
1117 if ((body = newwin(LINES - 3, COLS, 1, 0)) == NULL)
1119 if ((modeline = newwin(1, COLS, LINES-2, 0)) == NULL)
1121 if ((echoarea = newwin(1, COLS, LINES-1, 0)) == NULL)
1123 if ((minibuffer = newwin(1, COLS, LINES-1, 0)) == NULL)
1125 if ((help = newwin(1, 1, 1, 0)) == NULL)
1128 body_lines = LINES-3;
1131 wbkgd(body, body_face.body);
1132 wbkgd(echoarea, minibuffer_face.background);
1137 scrollok(body, FALSE);
1139 /* non-blocking input */
1142 mvwprintw(body, 0, 0, "");
1144 event_set(&stdioev, 0, EV_READ | EV_PERSIST, dispatch_stdio, NULL);
1145 event_add(&stdioev, NULL);
1147 signal_set(&winchev, SIGWINCH, handle_resize, NULL);
1148 signal_add(&winchev, NULL);
1154 ui_on_tab_loaded(struct tab *tab)
1156 stop_loading_anim(tab);
1157 message("Loaded %s", tab->hist_cur->h);
1165 ui_on_tab_refresh(struct tab *tab)
1167 wrap_page(&tab->buffer, body_cols);
1168 if (tab->flags & TAB_CURRENT)
1171 tab->flags |= TAB_URGENT;
1181 ui_toggle_side_window(void)
1183 side_window = !side_window;
1188 * ugly hack, but otherwise the window doesn't get updated
1189 * until I call handle_resize a second time (i.e. C-l). I
1190 * will be happy to know why something like this is needed.
1192 handle_resize_nodelay(0, 0, NULL);
1193 handle_resize_nodelay(0, 0, NULL);
1197 ui_schedule_redraw(void)
1199 handle_resize_nodelay(0, 0, NULL);
1203 ui_require_input(struct tab *tab, int hide)
1205 /* TODO: hard-switching to another tab is ugly */
1208 enter_minibuffer(ir_self_insert, ir_select, exit_minibuffer,
1209 &ir_history, NULL, NULL);
1210 strlcpy(ministate.prompt, "Input required: ",
1211 sizeof(ministate.prompt));
1216 ui_yornp(const char *prompt, void (*fn)(int, struct tab *),
1219 yornp(prompt, fn, data);
1220 redraw_tab(current_tab());
1224 ui_read(const char *prompt, void (*fn)(const char*, struct tab *),
1227 completing_read(prompt, fn, data, NULL, NULL);
1228 redraw_tab(current_tab());