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.
43 #include "minibuffer.h"
44 #include "telescope.h"
48 static struct event stdioev, winchev;
50 static void restore_curs_x(struct buffer *);
52 static struct vline *nth_line(struct buffer*, size_t);
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 int wrap_page(struct buffer*, int);
59 static void print_vline(int, int, WINDOW*, struct vline*);
60 static void redraw_tabline(void);
61 static void redraw_window(WINDOW*, int, int, struct buffer*);
62 static void redraw_help(void);
63 static void redraw_body(struct tab*);
64 static void redraw_modeline(struct tab*);
65 static void redraw_minibuffer(void);
66 static void do_redraw_echoarea(void);
67 static void do_redraw_minibuffer(void);
68 static void place_cursor(int);
69 static void redraw_tab(struct tab*);
70 static void emit_help_item(char*, void*);
71 static void rec_compute_help(struct kmap*, char*, size_t);
72 static void recompute_help(void);
73 static void update_loading_anim(int, short, void*);
74 static void stop_loading_anim(struct tab*);
78 struct thiskey thiskey;
80 static struct event resizeev;
81 static struct timeval resize_timer = { 0, 250000 };
83 static WINDOW *tabline, *body, *modeline, *echoarea;
85 int body_lines, body_cols;
88 static struct buffer helpwin;
89 static int help_lines, help_cols;
91 static int side_window;
93 static struct event clechoev;
94 static struct timeval clechoev_timer = { 5, 0 };
95 static struct timeval loadingev_timer = { 0, 250000 };
97 static uint32_t tab_counter;
99 static char keybuf[64];
101 struct kmap global_map,
109 update_x_offset(void)
111 if (olivetti_mode && fill_column < body_cols)
112 x_offset = (body_cols - fill_column)/2;
118 save_excursion(struct excursion *place, struct buffer *buffer)
120 place->curs_x = buffer->curs_x;
121 place->curs_y = buffer->curs_y;
122 place->line_off = buffer->line_off;
123 place->current_line = buffer->current_line;
124 place->cpoff = buffer->cpoff;
128 restore_excursion(struct excursion *place, struct buffer *buffer)
130 buffer->curs_x = place->curs_x;
131 buffer->curs_y = place->curs_y;
132 buffer->line_off = place->line_off;
133 buffer->current_line = place->current_line;
134 buffer->cpoff = place->cpoff;
138 restore_curs_x(struct buffer *buffer)
143 vl = buffer->current_line;
144 if (vl == NULL || vl->line == NULL)
145 buffer->curs_x = buffer->cpoff = 0;
147 buffer->curs_x = utf8_snwidth(vl->line, buffer->cpoff);
149 buffer->curs_x += x_offset;
152 prfx = line_prefixes[vl->parent->type].prfx1;
153 buffer->curs_x += utf8_swidth(prfx);
158 global_key_unbound(void)
160 message("%s is undefined", keybuf);
163 static struct vline *
164 nth_line(struct buffer *buffer, size_t n)
170 TAILQ_FOREACH(vl, &buffer->head, vlines) {
185 TAILQ_FOREACH(t, &tabshead, tabs) {
186 if (t->flags & TAB_CURRENT)
198 return &ministate.buffer;
199 return ¤t_tab()->buffer;
207 if ((thiskey.key = wgetch(body)) == ERR)
210 thiskey.meta = thiskey.key == 27;
212 thiskey.key = wgetch(body);
213 if (thiskey.key == ERR || thiskey.key == 27) {
220 if ((unsigned int)thiskey.key < UINT8_MAX) {
222 if (!utf8_decode(&state, &thiskey.cp, (uint8_t)thiskey.key))
224 if ((thiskey.key = wgetch(body)) == ERR) {
225 message("Error decoding user input");
235 dispatch_stdio(int fd, short ev, void *d)
244 if (keybuf[0] != '\0')
245 strlcat(keybuf, " ", sizeof(keybuf));
247 strlcat(keybuf, "M-", sizeof(keybuf));
248 if (thiskey.cp != 0) {
249 utf8_encode(thiskey.cp, tmp);
250 strlcat(keybuf, tmp, sizeof(keybuf));
252 if ((keyname = unkbd(thiskey.key)) != NULL)
253 strlcat(keybuf, keyname, sizeof(keybuf));
255 tmp[0] = thiskey.key;
256 strlcat(keybuf, tmp, sizeof(keybuf));
260 TAILQ_FOREACH(k, ¤t_map->m, keymaps) {
261 if (k->meta == thiskey.meta &&
262 k->key == thiskey.key) {
264 current_map = &k->map;
266 current_map = base_map;
267 strlcpy(keybuf, "", sizeof(keybuf));
268 k->fn(current_buffer());
274 if (current_map->unhandled_input != NULL)
275 current_map->unhandled_input();
277 global_key_unbound();
279 strlcpy(keybuf, "", sizeof(keybuf));
280 current_map = base_map;
286 redraw_tab(current_tab());
290 handle_clear_echoarea(int fd, short ev, void *d)
292 free(ministate.curmesg);
293 ministate.curmesg = NULL;
300 handle_resize(int sig, short ev, void *d)
302 if (event_pending(&resizeev, EV_TIMEOUT, NULL)) {
303 event_del(&resizeev);
305 evtimer_set(&resizeev, handle_resize_nodelay, NULL);
306 evtimer_add(&resizeev, &resize_timer);
310 handle_resize_nodelay(int s, short ev, void *d)
318 /* move and resize the windows, in reverse order! */
320 mvwin(echoarea, LINES-1, 0);
321 wresize(echoarea, 1, COLS);
323 mvwin(modeline, LINES-2, 0);
324 wresize(modeline, 1, COLS);
326 body_lines = LINES-3;
330 help_cols = 0.3 * COLS;
331 help_lines = LINES-3;
333 wresize(help, help_lines, help_cols);
335 wrap_page(&helpwin, help_cols);
337 body_cols = COLS - help_cols - 1;
338 mvwin(body, 1, help_cols);
343 wresize(body, body_lines, body_cols);
345 wresize(tabline, 1, COLS);
349 wrap_page(&tab->buffer, body_cols);
354 wrap_page(struct buffer *buffer, int width)
357 const struct line *top_orig, *orig;
362 top_orig = buffer->top_line == NULL ? NULL : buffer->top_line->parent;
363 orig = buffer->current_line == NULL ? NULL : buffer->current_line->parent;
365 buffer->top_line = NULL;
366 buffer->current_line = NULL;
368 buffer->force_redraw = 1;
370 buffer->line_off = 0;
374 TAILQ_FOREACH(l, &buffer->page.head, lines) {
375 prfx = line_prefixes[l->type].prfx1;
386 wrap_text(buffer, prfx, l, MIN(fill_column, width));
388 case LINE_PRE_CONTENT:
390 pre_width = MIN(fill_column, width);
393 hardwrap_text(buffer, l, pre_width);
397 if (top_orig == l && buffer->top_line == NULL) {
398 buffer->line_off = buffer->line_max-1;
399 buffer->top_line = TAILQ_LAST(&buffer->head, vhead);
402 vl = TAILQ_PREV(buffer->top_line, vhead, vlines);
403 if (vl == NULL || vl->parent != orig)
405 buffer->top_line = vl;
410 if (orig == l && buffer->current_line == NULL) {
411 buffer->current_line = TAILQ_LAST(&buffer->head, vhead);
414 vl = TAILQ_PREV(buffer->current_line, vhead, vlines);
415 if (vl == NULL || vl->parent != orig)
417 buffer->current_line = vl;
422 if (buffer->current_line == NULL)
423 buffer->current_line = TAILQ_FIRST(&buffer->head);
425 if (buffer->top_line == NULL)
426 buffer->top_line = buffer->current_line;
432 print_vline(int off, int width, WINDOW *window, struct vline *vl)
439 f = &line_faces[vl->parent->type];
441 /* unused, set by getyx */
445 prfx = line_prefixes[vl->parent->type].prfx1;
447 prfx = line_prefixes[vl->parent->type].prfx2;
453 wattr_on(window, body_face.left, NULL);
454 for (i = 0; i < off; i++)
456 wattr_off(window, body_face.left, NULL);
458 wattr_on(window, f->prefix, NULL);
459 wprintw(window, "%s", prfx);
460 wattr_off(window, f->prefix, NULL);
462 wattr_on(window, f->text, NULL);
463 wprintw(window, "%s", text);
464 wattr_off(window, f->text, NULL);
470 wattr_on(window, f->trail, NULL);
471 for (i = 0; i < left - off; ++i)
473 wattr_off(window, f->trail, NULL);
475 wattr_on(window, body_face.right, NULL);
476 for (i = 0; i < off; i++)
478 wattr_off(window, body_face.right, NULL);
486 size_t toskip, ots, tabwidth, space, x;
487 int current, y, truncated;
493 /* unused, but setted by a getyx */
496 tabwidth = sizeof(buf)+1;
500 TAILQ_FOREACH(tab, &tabshead, tabs) {
502 if (tab->flags & TAB_CURRENT)
506 if (toskip * tabwidth < space)
511 while (toskip != 0 &&
512 (ots - toskip+1) * tabwidth < space)
517 wattr_on(tabline, tab_face.background, NULL);
518 wprintw(tabline, toskip == 0 ? " " : "<");
519 wattr_off(tabline, tab_face.background, NULL);
522 TAILQ_FOREACH(tab, &tabshead, tabs) {
530 getyx(tabline, y, x);
531 if (x + sizeof(buf)+2 >= (size_t)COLS)
534 current = tab->flags & TAB_CURRENT;
536 if (*(title = tab->buffer.page.title) == '\0')
537 title = tab->hist_cur->h;
539 if (tab->flags & TAB_URGENT)
540 strlcpy(buf, "!", sizeof(buf));
542 strlcpy(buf, " ", sizeof(buf));
544 if (strlcat(buf, title, sizeof(buf)) >= sizeof(buf)) {
545 /* truncation happens */
546 strlcpy(&buf[sizeof(buf)-4], "...", 4);
548 /* pad with spaces */
549 while (strlcat(buf, " ", sizeof(buf)) < sizeof(buf))
554 wattr_on(tabline, tab_face.current, NULL);
556 wattr_on(tabline, tab_face.tab, NULL);
558 wprintw(tabline, "%s", buf);
559 if (TAILQ_NEXT(tab, tabs) != NULL)
560 wprintw(tabline, " ");
563 wattr_off(tabline, tab_face.current, NULL);
565 wattr_off(tabline, tab_face.tab, NULL);
568 wattr_on(tabline, tab_face.background, NULL);
569 for (; x < (size_t)COLS; ++x)
570 waddch(tabline, ' ');
572 mvwprintw(tabline, 0, COLS-1, ">");
573 wattr_off(tabline, tab_face.background, NULL);
577 * Compute the first visible line around vl. Try to search forward
578 * until the end of the buffer; if a visible line is not found, search
579 * backward. Return NULL if no viable line was found.
581 static inline struct vline *
582 adjust_line(struct vline *vl, struct buffer *buffer)
586 if (!(vl->parent->flags & L_HIDDEN))
591 t != NULL && t->parent->flags & L_HIDDEN;
592 t = TAILQ_NEXT(t, vlines))
598 /* search backward */
600 t != NULL && t->parent->flags & L_HIDDEN;
601 t = TAILQ_PREV(t, vhead, vlines))
608 redraw_window(WINDOW *win, int height, int width, struct buffer *buffer)
613 restore_curs_x(buffer);
616 * TODO: ignoring buffer->force_update and always
617 * re-rendering. In theory we can recompute the y position
618 * without a re-render, and optimize here. It's not the only
619 * optimisation possible here, wscrl wolud also be an
627 if (TAILQ_EMPTY(&buffer->head))
630 buffer->top_line = adjust_line(buffer->top_line, buffer);
631 if (buffer->top_line == NULL)
634 buffer->current_line = adjust_line(buffer->current_line, buffer);
638 for (vl = buffer->top_line; vl != NULL; vl = TAILQ_NEXT(vl, vlines)) {
639 if (vl->parent->flags & L_HIDDEN)
643 print_vline(x_offset, width, win, vl);
645 if (vl == buffer->current_line)
657 for (; vl != NULL; vl = TAILQ_NEXT(vl, vlines)) {
658 if (vl == buffer->current_line)
660 if (vl->parent->flags & L_HIDDEN)
663 buffer->top_line = TAILQ_NEXT(buffer->top_line, vlines);
669 buffer->last_line_off = buffer->line_off;
670 buffer->force_redraw = 0;
672 wmove(win, buffer->curs_y, buffer->curs_x);
678 redraw_window(help, help_lines, help_cols, &helpwin);
682 redraw_body(struct tab *tab)
684 static struct tab *last_tab;
687 tab->buffer.force_redraw =1;
690 redraw_window(body, body_lines, body_cols, &tab->buffer);
694 trust_status_char(enum trust_state ts)
697 case TS_UNKNOWN: return 'u';
698 case TS_UNTRUSTED: return '!';
699 case TS_TEMP_TRUSTED: return '!';
700 case TS_TRUSTED: return 'v';
701 case TS_VERIFIED: return 'V';
707 redraw_modeline(struct tab *tab)
710 int x, y, max_x, max_y;
711 const char *mode = tab->buffer.page.name;
712 const char *spin = "-\\|/";
715 wattr_on(modeline, modeline_face.background, NULL);
716 wmove(modeline, 0, 0);
718 wprintw(modeline, "-%c%c %s ",
719 spin[tab->loading_anim_step],
720 trust_status_char(tab->trust),
721 mode == NULL ? "(none)" : mode);
723 pct = (tab->buffer.line_off + tab->buffer.curs_y) * 100.0 / tab->buffer.line_max;
725 if (tab->buffer.line_max <= (size_t)body_lines)
726 wprintw(modeline, "All ");
727 else if (tab->buffer.line_off == 0)
728 wprintw(modeline, "Top ");
729 else if (tab->buffer.line_off + body_lines >= tab->buffer.line_max)
730 wprintw(modeline, "Bottom ");
732 wprintw(modeline, "%.0f%% ", pct);
734 wprintw(modeline, "%d/%d %s ",
735 tab->buffer.line_off + tab->buffer.curs_y,
736 tab->buffer.line_max,
739 getyx(modeline, y, x);
740 getmaxyx(modeline, max_y, max_x);
745 for (; x < max_x; ++x)
746 waddstr(modeline, "-");
748 wattr_off(modeline, modeline_face.background, NULL);
752 redraw_minibuffer(void)
754 wattr_on(echoarea, minibuffer_face.background, NULL);
758 do_redraw_minibuffer();
760 do_redraw_echoarea();
762 wattr_off(echoarea, minibuffer_face.background, NULL);
766 do_redraw_echoarea(void)
770 if (ministate.curmesg != NULL)
771 wprintw(echoarea, "%s", ministate.curmesg);
772 else if (*keybuf != '\0')
773 waddstr(echoarea, keybuf);
775 /* If nothing else, show the URL at point */
777 if (tab->buffer.current_line != NULL &&
778 tab->buffer.current_line->parent->type == LINE_LINK)
779 waddstr(echoarea, tab->buffer.current_line->parent->alt);
784 do_redraw_minibuffer(void)
786 size_t off_y, off_x = 0;
787 const char *start, *c;
789 /* unused, set by getyx */
792 mvwprintw(echoarea, 0, 0, "%s", ministate.prompt);
793 if (ministate.hist_cur != NULL)
794 wprintw(echoarea, "(%zu/%zu) ",
795 ministate.hist_off + 1,
796 ministate.history->len);
798 getyx(echoarea, off_y, off_x);
800 start = ministate.hist_cur != NULL
801 ? ministate.hist_cur->h
803 c = utf8_nth(ministate.buffer.current_line->line,
804 ministate.buffer.cpoff);
805 while (utf8_swidth_between(start, c) > (size_t)COLS/2) {
806 start = utf8_next_cp(start);
809 waddstr(echoarea, start);
811 if (ministate.curmesg != NULL)
812 wprintw(echoarea, " [%s]", ministate.curmesg);
814 wmove(echoarea, 0, off_x + utf8_swidth_between(start, c));
818 * Place the cursor in the right ncurses window. If soft is 1, use
819 * wnoutrefresh (which shouldn't cause any I/O); otherwise use
823 place_cursor(int soft)
825 int (*touch)(WINDOW *);
828 touch = wnoutrefresh;
842 redraw_tab(struct tab *tab)
851 redraw_modeline(tab);
854 wnoutrefresh(tabline);
855 wnoutrefresh(modeline);
863 emit_help_item(char *prfx, void *fn)
868 for (cmd = cmds; cmd->cmd != NULL; ++cmd) {
874 if ((l = calloc(1, sizeof(*l))) == NULL)
880 asprintf(&l->line, "%s %s", prfx, cmd->cmd);
882 if (TAILQ_EMPTY(&helpwin.page.head))
883 TAILQ_INSERT_HEAD(&helpwin.page.head, l, lines);
885 TAILQ_INSERT_TAIL(&helpwin.page.head, l, lines);
889 rec_compute_help(struct kmap *keymap, char *prfx, size_t len)
895 TAILQ_FOREACH(k, &keymap->m, keymaps) {
896 strlcpy(p, prfx, sizeof(p));
898 strlcat(p, " ", sizeof(p));
900 strlcat(p, "M-", sizeof(p));
901 if ((kn = unkbd(k->key)) != NULL)
902 strlcat(p, kn, sizeof(p));
904 strlcat(p, keyname(k->key), sizeof(p));
907 rec_compute_help(&k->map, p, sizeof(p));
909 emit_help_item(p, k->fn);
918 empty_vlist(&helpwin);
919 empty_linelist(&helpwin);
920 rec_compute_help(current_map, p, sizeof(p));
921 wrap_page(&helpwin, help_cols);
925 vmessage(const char *fmt, va_list ap)
927 if (evtimer_pending(&clechoev, NULL))
928 evtimer_del(&clechoev);
930 free(ministate.curmesg);
931 ministate.curmesg = NULL;
934 evtimer_set(&clechoev, handle_clear_echoarea, NULL);
935 evtimer_add(&clechoev, &clechoev_timer);
937 /* TODO: what to do if the allocation fails here? */
938 if (vasprintf(&ministate.curmesg, fmt, ap) == -1)
939 ministate.curmesg = NULL;
947 message(const char *fmt, ...)
957 start_loading_anim(struct tab *tab)
959 if (tab->loading_anim)
961 tab->loading_anim = 1;
962 evtimer_set(&tab->loadingev, update_loading_anim, tab);
963 evtimer_add(&tab->loadingev, &loadingev_timer);
967 update_loading_anim(int fd, short ev, void *d)
971 tab->loading_anim_step = (tab->loading_anim_step+1)%4;
973 if (tab->flags & TAB_CURRENT) {
974 redraw_modeline(tab);
981 evtimer_add(&tab->loadingev, &loadingev_timer);
985 stop_loading_anim(struct tab *tab)
987 if (!tab->loading_anim)
989 evtimer_del(&tab->loadingev);
990 tab->loading_anim = 0;
991 tab->loading_anim_step = 0;
993 if (!(tab->flags & TAB_CURRENT))
996 redraw_modeline(tab);
1005 load_url_in_tab(struct tab *tab, const char *url)
1007 message("Loading %s...", url);
1008 start_loading_anim(tab);
1011 tab->buffer.curs_x = 0;
1012 tab->buffer.curs_y = 0;
1017 switch_to_tab(struct tab *tab)
1021 TAILQ_FOREACH(t, &tabshead, tabs) {
1022 t->flags &= ~TAB_CURRENT;
1025 tab->flags |= TAB_CURRENT;
1026 tab->flags &= ~TAB_URGENT;
1032 return tab_counter++;
1036 new_tab(const char *url)
1040 if ((tab = calloc(1, sizeof(*tab))) == NULL) {
1046 TAILQ_INIT(&tab->hist.head);
1048 TAILQ_INIT(&tab->buffer.head);
1050 tab->id = tab_new_id();
1053 if (TAILQ_EMPTY(&tabshead))
1054 TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
1056 TAILQ_INSERT_TAIL(&tabshead, tab, tabs);
1058 load_url_in_tab(tab, url);
1065 setlocale(LC_ALL, "");
1067 TAILQ_INIT(&eecmd_history.head);
1068 TAILQ_INIT(&ir_history.head);
1069 TAILQ_INIT(&lu_history.head);
1071 ministate.line.type = LINE_TEXT;
1072 ministate.vline.parent = &ministate.line;
1073 ministate.buffer.current_line = &ministate.vline;
1075 /* initialize help window */
1076 TAILQ_INIT(&helpwin.head);
1078 base_map = &global_map;
1079 current_map = &global_map;
1083 if (enable_colors) {
1086 use_default_colors();
1091 config_apply_style();
1096 intrflush(stdscr, FALSE);
1098 if ((tabline = newwin(1, COLS, 0, 0)) == NULL)
1100 if ((body = newwin(LINES - 3, COLS, 1, 0)) == NULL)
1102 if ((modeline = newwin(1, COLS, LINES-2, 0)) == NULL)
1104 if ((echoarea = newwin(1, COLS, LINES-1, 0)) == NULL)
1106 if ((help = newwin(1, 1, 1, 0)) == NULL)
1109 body_lines = LINES-3;
1112 wbkgd(body, body_face.body);
1113 wbkgd(echoarea, minibuffer_face.background);
1118 scrollok(body, FALSE);
1120 /* non-blocking input */
1123 mvwprintw(body, 0, 0, "");
1125 event_set(&stdioev, 0, EV_READ | EV_PERSIST, dispatch_stdio, NULL);
1126 event_add(&stdioev, NULL);
1128 signal_set(&winchev, SIGWINCH, handle_resize, NULL);
1129 signal_add(&winchev, NULL);
1135 ui_on_tab_loaded(struct tab *tab)
1137 stop_loading_anim(tab);
1138 message("Loaded %s", tab->hist_cur->h);
1146 ui_on_tab_refresh(struct tab *tab)
1148 wrap_page(&tab->buffer, body_cols);
1149 if (tab->flags & TAB_CURRENT)
1152 tab->flags |= TAB_URGENT;
1162 ui_toggle_side_window(void)
1164 side_window = !side_window;
1169 * ugly hack, but otherwise the window doesn't get updated
1170 * until I call handle_resize a second time (i.e. C-l). I
1171 * will be happy to know why something like this is needed.
1173 handle_resize_nodelay(0, 0, NULL);
1174 handle_resize_nodelay(0, 0, NULL);
1178 ui_schedule_redraw(void)
1180 handle_resize_nodelay(0, 0, NULL);
1184 ui_require_input(struct tab *tab, int hide)
1186 /* TODO: hard-switching to another tab is ugly */
1189 enter_minibuffer(ir_self_insert, ir_select, exit_minibuffer,
1191 strlcpy(ministate.prompt, "Input required: ",
1192 sizeof(ministate.prompt));
1197 ui_yornp(const char *prompt, void (*fn)(int, struct tab *),
1200 yornp(prompt, fn, data);
1201 redraw_tab(current_tab());
1205 ui_read(const char *prompt, void (*fn)(const char*, unsigned int),
1208 completing_read(prompt, fn, data);
1209 redraw_tab(current_tab());