Blob


1 /*
2 * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
3 *
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.
7 *
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.
15 */
17 /*
18 * Ncurses UI for telescope.
19 *
20 *
21 * Text wrapping
22 * =============
23 *
24 * There's a simple text wrapping algorithm.
25 *
26 * 1. if it's a line in a pre-formatted block:
27 * a. hard wrap.
28 * b. repeat
29 * 2. there is enough room for the next word?
30 * a. yes: render it
31 * b. no: break the current line.
32 * i. while there isn't enough space to draw the current
33 * word, hard-wrap it
34 * ii. draw the remainder of the current word (can be the
35 * the entirely)
36 * 3. render the spaces after the word
37 * a. but if there is not enough room break the line and
38 * forget them
39 * 4. repeat
40 *
41 *
42 * Text scrolling
43 * ==============
44 *
45 * ncurses allows you to scroll a window, but when a line goes out of
46 * the visible area it's forgotten. We keep a list of formatted lines
47 * (``visual lines'') that we know fits in the window, and draw them.
48 * This way is easy to scroll: just call wscrl and then render the
49 * first/last line!
50 *
51 * This means that on every resize we have to clear our list of lines
52 * and re-render everything. A clever approach would be to do this
53 * ``on-demand''.
54 *
55 * TODO: make the text formatting on-demand.
56 *
57 */
59 #include <telescope.h>
61 #include <ctype.h>
62 #include <curses.h>
63 #include <event.h>
64 #include <locale.h>
65 #include <signal.h>
66 #include <stdarg.h>
67 #include <stdlib.h>
68 #include <string.h>
69 #include <unistd.h>
71 #define TAB_CURRENT 0x1
73 #define MIN(a, b) ((a) < (b) ? (a) : (b))
74 #define MAX(a, b) ((a) > (b) ? (a) : (b))
76 struct kmap;
78 static struct event stdioev, winchev;
80 static int kbd(const char*);
81 static void kmap_define_key(struct kmap*, const char*, void(*)(struct tab*));
82 static void load_default_keys(void);
83 static int push_line(struct tab*, const struct line*, const char*, size_t);
84 static void empty_vlist(struct tab*);
85 static void restore_cursor(struct tab *);
86 static void cmd_previous_line(struct tab*);
87 static void cmd_next_line(struct tab*);
88 static void cmd_forward_char(struct tab*);
89 static void cmd_backward_char(struct tab*);
90 static void cmd_redraw(struct tab*);
91 static void cmd_scroll_down(struct tab*);
92 static void cmd_scroll_up(struct tab*);
93 static void cmd_kill_telescope(struct tab*);
94 static void cmd_push_button(struct tab*);
95 static struct line *nth_line(struct tab*, size_t);
96 static struct tab *current_tab(void);
97 static void dispatch_stdio(int, short, void*);
98 static void handle_clear_minibuf(int, short, void*);
99 static void handle_resize(int, short, void*);
100 static int word_bourdaries(const char*, const char*, const char**, const char**);
101 static void wrap_text(struct tab*, const char*, struct line*);
102 static int hardwrap_text(struct tab*, struct line*);
103 static int wrap_page(struct tab*);
104 static void print_line(struct line*);
105 static void redraw_tabline(void);
106 static void redraw_modeline(struct tab*);
107 static void redraw_tab(struct tab*);
108 static void message(const char*, ...) __attribute__((format(printf, 1, 2)));
109 static void start_loading_anim(struct tab*);
110 static void update_loading_anim(int, short, void*);
111 static void stop_loading_anim(struct tab*);
112 static void load_url_in_tab(struct tab*, const char*);
113 static void new_tab(void);
115 static WINDOW *tabline, *body, *modeline, *minibuf;
116 static int body_lines, body_cols;
118 static struct event clminibufev;
119 static int clminibufev_set;
120 static struct timeval clminibufev_timer = { 5, 0 };
121 static struct timeval loadingev_timer = { 0, 250000 };
123 static uint32_t tab_counter;
125 struct ui_state {
126 int curs_x;
127 int curs_y;
128 size_t line_off;
129 size_t line_max;
131 short loading_anim;
132 short loading_anim_step;
133 struct event loadingev;
135 TAILQ_HEAD(, line) head;
136 };
138 #define CTRL(n) ((n)&0x1F)
140 static TAILQ_HEAD(kmap, keymap) global_map, *current_map;
141 struct keymap {
142 int meta;
143 int key;
144 struct kmap map;
145 void (*fn)(struct tab*);
147 TAILQ_ENTRY(keymap) keymaps;
148 };
150 static int
151 kbd(const char *key)
153 struct table {
154 char *p;
155 int k;
156 } table[] = {
157 { "<up>", KEY_UP },
158 { "<down>", KEY_DOWN },
159 { "<left>", KEY_LEFT },
160 { "<right>", KEY_RIGHT },
161 /* ... */
162 { "space", ' ' },
163 { "spc", ' ' },
164 { "enter", CTRL('m') },
165 { "tab", CTRL('i') },
166 /* ... */
167 { NULL, 0 },
168 }, *t;
170 for (t = table; t->p != NULL; ++t) {
171 if (has_prefix(key, t->p))
172 return t->k;
175 return *key;
178 static void
179 kmap_define_key(struct kmap *map, const char *key, void (*fn)(struct tab*))
181 int ctrl, meta, k;
182 struct keymap *entry;
184 again:
185 if ((ctrl = has_prefix(key, "C-")))
186 key += 2;
187 if ((meta = has_prefix(key, "M-")))
188 key += 2;
189 if (*key == '\0')
190 _exit(1);
191 k = kbd(key);
193 if (ctrl)
194 k = CTRL(k);
196 /* skip key & spaces */
197 while (*key != '\0' && !isspace(*key))
198 ++key;
199 while (*key != '\0' && isspace(*key))
200 ++key;
202 TAILQ_FOREACH(entry, map, keymaps) {
203 if (entry->meta == meta && entry->key == k) {
204 if (*key == '\0') {
205 entry->fn = fn;
206 return;
208 map = &entry->map;
209 goto again;
213 if ((entry = calloc(1, sizeof(*entry))) == NULL)
214 abort();
216 entry->meta = meta;
217 entry->key = k;
218 TAILQ_INIT(&entry->map);
220 if (TAILQ_EMPTY(map))
221 TAILQ_INSERT_HEAD(map, entry, keymaps);
222 else
223 TAILQ_INSERT_TAIL(map, entry, keymaps);
225 if (*key != '\0') {
226 map = &entry->map;
227 goto again;
230 entry->fn = fn;
233 static inline void
234 global_set_key(const char *key, void (*fn)(struct tab*))
236 kmap_define_key(&global_map, key, fn);
239 static void
240 load_default_keys(void)
242 /* emacs */
243 global_set_key("C-p", cmd_previous_line);
244 global_set_key("C-n", cmd_next_line);
245 global_set_key("C-f", cmd_forward_char);
246 global_set_key("C-b", cmd_backward_char);
248 /* tmp */
249 global_set_key("M-v", cmd_scroll_up);
250 global_set_key("C-v", cmd_scroll_down);
252 global_set_key("C-x C-c", cmd_kill_telescope);
254 /* vi/vi-like */
255 global_set_key("k", cmd_previous_line);
256 global_set_key("j", cmd_next_line);
257 global_set_key("l", cmd_forward_char);
258 global_set_key("h", cmd_backward_char);
260 global_set_key("K", cmd_scroll_up);
261 global_set_key("J", cmd_scroll_down);
263 /* tmp */
264 global_set_key("q", cmd_kill_telescope);
266 /* cua */
267 global_set_key("<up>", cmd_previous_line);
268 global_set_key("<down>", cmd_next_line);
269 global_set_key("<right>", cmd_forward_char);
270 global_set_key("<left>", cmd_backward_char);
272 /* "ncurses standard" */
273 global_set_key("C-l", cmd_redraw);
275 /* global */
276 global_set_key("C-m", cmd_push_button);
279 static int
280 push_line(struct tab *tab, const struct line *l, const char *buf, size_t len)
282 struct line *vl;
284 tab->s->line_max++;
286 if ((vl = calloc(1, sizeof(*vl))) == NULL)
287 return 0;
289 if (len != 0 && (vl->line = calloc(1, len+1)) == NULL) {
290 free(vl);
291 return 0;
294 vl->type = l->type;
295 if (len != 0)
296 memcpy(vl->line, buf, len);
297 vl->alt = l->alt;
299 if (TAILQ_EMPTY(&tab->s->head))
300 TAILQ_INSERT_HEAD(&tab->s->head, vl, lines);
301 else
302 TAILQ_INSERT_TAIL(&tab->s->head, vl, lines);
303 return 1;
306 static void
307 empty_vlist(struct tab *tab)
309 struct line *l, *t;
311 tab->s->line_max = 0;
313 TAILQ_FOREACH_SAFE(l, &tab->s->head, lines, t) {
314 TAILQ_REMOVE(&tab->s->head, l, lines);
315 free(l->line);
316 /* l->alt references the original line! */
317 free(l);
321 static void
322 restore_cursor(struct tab *tab)
324 wmove(body, tab->s->curs_y, tab->s->curs_x);
327 static void
328 cmd_previous_line(struct tab *tab)
330 if (--tab->s->curs_y < 0) {
331 tab->s->curs_y = 0;
332 cmd_scroll_up(tab);
335 restore_cursor(tab);
338 static void
339 cmd_next_line(struct tab *tab)
341 if (++tab->s->curs_y > body_lines-1) {
342 tab->s->curs_y = body_lines-1;
343 cmd_scroll_down(tab);
346 restore_cursor(tab);
349 static void
350 cmd_forward_char(struct tab *tab)
352 tab->s->curs_x = MIN(body_cols-1, tab->s->curs_x+1);
353 restore_cursor(tab);
356 static void
357 cmd_backward_char(struct tab *tab)
359 tab->s->curs_x = MAX(0, tab->s->curs_x-1);
360 restore_cursor(tab);
363 static void
364 cmd_redraw(struct tab *tab)
366 handle_resize(0, 0, NULL);
369 static void
370 cmd_scroll_up(struct tab *tab)
372 struct line *l;
374 if (tab->s->line_off == 0)
375 return;
377 l = nth_line(tab, --tab->s->line_off);
378 wscrl(body, -1);
379 wmove(body, 0, 0);
380 print_line(l);
383 static void
384 cmd_scroll_down(struct tab *tab)
386 struct line *l;
387 size_t n;
389 if (tab->s->line_max == 0 || tab->s->line_off == tab->s->line_max-1)
390 return;
392 tab->s->line_off++;
393 wscrl(body, 1);
395 if (tab->s->line_max - tab->s->line_off < body_lines)
396 return;
398 l = nth_line(tab, tab->s->line_off + body_lines-1);
399 wmove(body, body_lines-1, 0);
400 print_line(l);
403 static void
404 cmd_kill_telescope(struct tab *tab)
406 event_loopbreak();
409 static void
410 cmd_push_button(struct tab *tab)
412 struct line *l;
413 size_t nth;
415 nth = tab->s->line_off + tab->s->curs_y;
416 if (nth > tab->s->line_max)
417 return;
418 l = nth_line(tab, nth);
419 if (l->type != LINE_LINK)
420 return;
422 load_url_in_tab(tab, l->alt);
425 static struct line *
426 nth_line(struct tab *tab, size_t n)
428 struct line *l;
429 size_t i;
431 i = 0;
432 TAILQ_FOREACH(l, &tab->s->head, lines) {
433 if (i == n)
434 return l;
435 i++;
438 /* unreachable */
439 abort();
442 static struct tab *
443 current_tab(void)
445 struct tab *t;
447 TAILQ_FOREACH(t, &tabshead, tabs) {
448 if (t->flags & TAB_CURRENT)
449 return t;
452 /* unreachable */
453 abort();
456 static void
457 dispatch_stdio(int fd, short ev, void *d)
459 struct keymap *k;
460 int meta, key;
462 key = wgetch(body);
463 if (key == ERR)
464 return;
465 if (key == 27) {
466 /* TODO: make escape-time customizable */
468 meta = 1;
469 key = wgetch(body);
470 if (key == ERR)
471 key = 27;
472 } else
473 meta = 0;
475 TAILQ_FOREACH(k, current_map, keymaps) {
476 if (k->meta == meta && k->key == key) {
477 if (k->fn == NULL)
478 current_map = &k->map;
479 else {
480 current_map = &global_map;
481 k->fn(current_tab());
483 goto done;
487 current_map = &global_map;
489 message("%s%c is undefined",
490 meta ? "M-" : "", key);
492 done:
493 restore_cursor(current_tab());
494 wrefresh(tabline);
495 wrefresh(modeline);
496 wrefresh(minibuf);
498 wrefresh(body);
501 static void
502 handle_clear_minibuf(int fd, short ev, void *d)
504 clminibufev_set = 0;
505 werase(minibuf);
506 wrefresh(minibuf);
507 wrefresh(body);
510 static void
511 handle_resize(int sig, short ev, void *d)
513 struct tab *tab;
515 endwin();
516 refresh();
517 clear();
519 /* move and resize the windows, in reverse order! */
521 mvwin(minibuf, LINES-1, 0);
522 wresize(minibuf, 1, COLS);
524 mvwin(modeline, LINES-2, 0);
525 wresize(modeline, 1, COLS);
527 wresize(body, LINES-3, COLS);
528 body_lines = LINES-3;
529 body_cols = COLS;
531 wresize(tabline, 1, COLS);
533 tab = current_tab();
535 wrap_page(tab);
536 redraw_tab(tab);
539 /*
540 * Helper function for wrap_text. Find the end of the current word
541 * and the end of the separator after the word.
542 */
543 static int
544 word_boundaries(const char *s, const char *sep, const char **endword, const char **endspc)
546 *endword = s;
547 *endword = s;
549 if (*s == '\0')
550 return 0;
552 /* find the end of the current world */
553 for (; *s != '\0'; ++s) {
554 if (strchr(sep, *s) != NULL)
555 break;
558 *endword = s;
560 /* find the end of the separator */
561 for (; *s != '\0'; ++s) {
562 if (strchr(sep, *s) == NULL)
563 break;
566 *endspc = s;
568 return 1;
571 static inline int
572 emitline(struct tab *tab, size_t zero, size_t *off, const struct line *l,
573 const char **line)
575 if (!push_line(tab, l, *line, *off - zero))
576 return 0;
577 *line += *off - zero;
578 *off = zero;
579 return 1;
582 static inline void
583 emitstr(const char **s, size_t len, size_t *off)
585 size_t i;
587 /* printw("%*s", ...) doesn't seem to respect the precision, so... */
588 for (i = 0; i < len; ++i)
589 addch((*s)[i]);
590 *off += len;
591 *s += len;
594 /*
595 * Build a list of visual line by wrapping the given line, assuming
596 * that when printed will have a leading prefix prfx.
598 * TODO: it considers each byte one cell on the screen!
599 */
600 static void
601 wrap_text(struct tab *tab, const char *prfx, struct line *l)
603 size_t zero, off, len, split;
604 const char *endword, *endspc, *line, *linestart;
606 zero = strlen(prfx);
607 off = zero;
608 line = l->line;
609 linestart = l->line;
611 while (word_boundaries(line, " \t-", &endword, &endspc)) {
612 len = endword - line;
613 if (off + len >= body_cols) {
614 emitline(tab, zero, &off, l, &linestart);
615 while (len >= body_cols) {
616 /* hard wrap */
617 emitline(tab, zero, &off, l, &linestart);
618 len -= body_cols-1;
619 line += body_cols-1;
622 if (len != 0)
623 off += len;
624 } else
625 off += len;
627 /* print the spaces iff not at bol */
628 len = endspc - endword;
629 /* line = endspc; */
630 if (off != zero) {
631 if (off + len >= body_cols) {
632 emitline(tab, zero, &off, l, &linestart);
633 linestart = endspc;
634 } else
635 off += len;
638 line = endspc;
641 emitline(tab, zero, &off, l, &linestart);
644 static int
645 hardwrap_text(struct tab *tab, struct line *l)
647 size_t off, len;
648 const char *linestart;
650 len = strlen(l->line);
651 off = 0;
652 linestart = l->line;
654 while (len >= COLS) {
655 len -= COLS-1;
656 off = COLS-1;
657 if (!emitline(tab, 0, &off, l, &linestart))
658 return 0;
661 if (len != 0)
662 return emitline(tab, 0, &len, l, &linestart);
664 return 1;
667 static int
668 wrap_page(struct tab *tab)
670 struct line *l;
672 empty_vlist(tab);
674 TAILQ_FOREACH(l, &tab->page.head, lines) {
675 switch (l->type) {
676 case LINE_TEXT:
677 wrap_text(tab, "", l);
678 break;
679 case LINE_LINK:
680 wrap_text(tab, "=> ", l);
681 break;
682 case LINE_TITLE_1:
683 wrap_text(tab, "# ", l);
684 break;
685 case LINE_TITLE_2:
686 wrap_text(tab, "## ", l);
687 break;
688 case LINE_TITLE_3:
689 wrap_text(tab, "### ", l);
690 break;
691 case LINE_ITEM:
692 wrap_text(tab, "* ", l);
693 break;
694 case LINE_QUOTE:
695 wrap_text(tab, "> ", l);
696 break;
697 case LINE_PRE_START:
698 case LINE_PRE_END:
699 push_line(tab, l, NULL, 0);
700 break;
701 case LINE_PRE_CONTENT:
702 hardwrap_text(tab, l);
703 break;
706 return 1;
709 static inline void
710 print_line(struct line *l)
712 const char *text = l->line;
714 if (text == NULL)
715 text = "";
717 switch (l->type) {
718 case LINE_TEXT:
719 wprintw(body, "%s", text);
720 break;
721 case LINE_LINK:
722 wattron(body, A_UNDERLINE);
723 wprintw(body, "=> %s", text);
724 wattroff(body, A_UNDERLINE);
725 return;
726 case LINE_TITLE_1:
727 wattron(body, A_BOLD);
728 wprintw(body, "# %s", text);
729 wattroff(body, A_BOLD);
730 return;
731 case LINE_TITLE_2:
732 wattron(body, A_BOLD);
733 wprintw(body, "## %s", text);
734 wattroff(body, A_BOLD);
735 return;
736 case LINE_TITLE_3:
737 wattron(body, A_BOLD);
738 wprintw(body, "### %s", text);
739 wattroff(body, A_BOLD);
740 return;
741 case LINE_ITEM:
742 wprintw(body, "* %s", text);
743 return;
744 case LINE_QUOTE:
745 wattron(body, A_DIM);
746 wprintw(body, "> %s", text);
747 wattroff(body, A_DIM);
748 return;
749 case LINE_PRE_START:
750 case LINE_PRE_END:
751 wprintw(body, "```");
752 return;
753 case LINE_PRE_CONTENT:
754 wprintw(body, "%s", text);
755 return;
759 static void
760 redraw_tabline(void)
762 wclear(tabline);
763 wbkgd(tabline, A_REVERSE);
764 mvwprintw(tabline, 0, 0, "TODO: tabs here");
767 static void
768 redraw_modeline(struct tab *tab)
770 int x, y, max_x, max_y;
771 const char *mode = "text/gemini-mode";
772 const char *spin = "-\\|/";
774 wclear(modeline);
775 wattron(modeline, A_REVERSE);
776 wmove(modeline, 0, 0);
778 wprintw(modeline, "-%c %s %s ",
779 spin[tab->s->loading_anim_step], mode, tab->urlstr);
780 getyx(modeline, y, x);
781 getmaxyx(modeline, max_y, max_x);
783 (void)y;
784 (void)max_y;
786 for (; x < max_x; ++x)
787 waddstr(modeline, "-");
790 static void
791 redraw_tab(struct tab *tab)
793 struct line *l;
794 int line;
796 werase(body);
798 tab->s->line_off = MIN(tab->s->line_max, tab->s->line_off);
799 if (TAILQ_EMPTY(&tab->s->head))
800 return;
802 line = 0;
803 l = nth_line(tab, tab->s->line_off);
804 for (; l != NULL; l = TAILQ_NEXT(l, lines)) {
805 wmove(body, line, 0);
806 print_line(l);
807 line++;
808 if (line == body_lines)
809 break;
812 redraw_tabline();
813 redraw_modeline(tab);
815 restore_cursor(tab);
816 wrefresh(tabline);
817 wrefresh(modeline);
818 wrefresh(minibuf);
820 wrefresh(body);
823 static void
824 message(const char *fmt, ...)
826 va_list ap;
828 va_start(ap, fmt);
830 if (clminibufev_set)
831 evtimer_del(&clminibufev);
832 evtimer_set(&clminibufev, handle_clear_minibuf, NULL);
833 evtimer_add(&clminibufev, &clminibufev_timer);
834 clminibufev_set = 1;
836 werase(minibuf);
837 vw_printw(minibuf, fmt, ap);
839 wrefresh(minibuf);
840 wrefresh(body);
842 va_end(ap);
845 static void
846 start_loading_anim(struct tab *tab)
848 if (tab->s->loading_anim)
849 return;
850 tab->s->loading_anim = 1;
851 evtimer_set(&tab->s->loadingev, update_loading_anim, tab);
852 evtimer_add(&tab->s->loadingev, &loadingev_timer);
855 static void
856 update_loading_anim(int fd, short ev, void *d)
858 struct tab *tab = d;
860 tab->s->loading_anim_step = (tab->s->loading_anim_step+1)%4;
862 redraw_modeline(tab);
863 wrefresh(modeline);
864 wrefresh(body);
866 evtimer_add(&tab->s->loadingev, &loadingev_timer);
869 static void
870 stop_loading_anim(struct tab *tab)
872 if (!tab->s->loading_anim)
873 return;
874 evtimer_del(&tab->s->loadingev);
875 tab->s->loading_anim = 0;
876 tab->s->loading_anim_step = 0;
878 redraw_modeline(tab);
879 wrefresh(modeline);
880 wrefresh(body);
883 static void
884 load_url_in_tab(struct tab *tab, const char *url)
886 empty_vlist(tab);
887 message("Loading %s...", url);
888 start_loading_anim(tab);
889 load_url(tab, url);
891 tab->s->curs_x = 0;
892 tab->s->curs_y = 0;
893 redraw_tab(tab);
896 static void
897 new_tab(void)
899 struct tab *tab, *t;
900 const char *url = "about:new";
902 if ((tab = calloc(1, sizeof(*tab))) == NULL)
903 goto err;
905 if ((tab->s = calloc(1, sizeof(*t->s))) == NULL)
906 goto err;
908 TAILQ_INIT(&tab->s->head);
909 TAILQ_FOREACH(t, &tabshead, tabs) {
910 t->flags &= ~TAB_CURRENT;
913 tab->id = tab_counter++;
914 tab->flags = TAB_CURRENT;
916 if (TAILQ_EMPTY(&tabshead))
917 TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
918 else
919 TAILQ_INSERT_TAIL(&tabshead, tab, tabs);
921 load_url_in_tab(tab, url);
922 return;
924 err:
925 event_loopbreak();
928 int
929 ui_init(void)
931 setlocale(LC_ALL, "");
933 TAILQ_INIT(&global_map);
934 current_map = &global_map;
935 load_default_keys();
937 initscr();
938 raw();
939 noecho();
941 nonl();
942 intrflush(stdscr, FALSE);
944 if ((tabline = newwin(1, COLS, 0, 0)) == NULL)
945 return 0;
946 if ((body = newwin(LINES - 3, COLS, 1, 0)) == NULL)
947 return 0;
948 if ((modeline = newwin(1, COLS, LINES-2, 0)) == NULL)
949 return 0;
950 if ((minibuf = newwin(1, COLS, LINES-1, 0)) == NULL)
951 return 0;
953 body_lines = LINES-3;
954 body_cols = COLS;
956 keypad(body, TRUE);
957 scrollok(body, TRUE);
959 /* non-blocking input */
960 wtimeout(body, 0);
962 mvwprintw(body, 0, 0, "");
964 event_set(&stdioev, 0, EV_READ | EV_PERSIST, dispatch_stdio, NULL);
965 event_add(&stdioev, NULL);
967 signal_set(&winchev, SIGWINCH, handle_resize, NULL);
968 signal_add(&winchev, NULL);
970 new_tab();
972 return 1;
975 void
976 ui_on_tab_loaded(struct tab *tab)
978 stop_loading_anim(tab);
979 message("Loaded %s", tab->urlstr);
982 void
983 ui_on_tab_refresh(struct tab *tab)
985 if (!(tab->flags & TAB_CURRENT))
986 return;
988 wrap_page(tab);
989 redraw_tab(tab);
992 void
993 ui_end(void)
995 endwin();