commit - ede1f142436ff97c9244b2ddcd69f016d20596bf
commit + bcb0b0730e139513b6c811bed3691bcb1a0df8b6
blob - 3ff19e7ad790dfb9328cd07a0a6c07b5c34c2e6f
blob + 4f0b597135810518b2c77c9cb396b34b6b6c778a
--- telescope.c
+++ telescope.c
struct tabshead tabshead;
static struct imsgbuf *ibuf;
-static uint32_t tab_counter;
static void handle_imsg_err(struct imsg*, size_t);
static void handle_imsg_check_cert(struct imsg*, size_t);
static void handle_imsg_eof(struct imsg*, size_t);
static void load_page_from_str(struct tab*, const char*);
-static void load_url(struct tab*, const char*);
static imsg_handlerfn *handlers[] = {
[IMSG_ERR] = handle_imsg_err,
ui_on_tab_refresh(tab);
}
-static void
+void
load_url(struct tab *tab, const char *url)
{
if (!strcmp(url, "about:new")) {
imsg_flush(ibuf);
}
-void
-new_tab(void)
-{
- struct tab *tab;
- /* const char *url = "about:new"; */
- /* const char *url = "gemini://localhost.it/scroll.txt"; */
- const char *url = "gemini://localhost.it/test.gmi";
-
- if ((tab = calloc(1, sizeof(*tab))) == NULL)
- die();
-
- TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
-
- tab->id = tab_counter++;
- TAILQ_INIT(&tab->page.head);
-
- ui_on_new_tab(tab);
-
- load_url(tab, url);
-}
-
int
main(void)
{
ui_init();
- new_tab();
-
event_dispatch();
imsg_compose(ibuf, IMSG_QUIT, 0, 0, -1, NULL, 0);
blob - 88b28838e6b20443ee507a5789451fbb439d7d35
blob + 9900036dcff323d80908cf44b7deee73ada44626
--- telescope.h
+++ telescope.h
#define TOO_MUCH_REDIRECTS 1
extern const char *err_pages[70];
+/* telescope.c */
+void load_url(struct tab*, const char*);
+
/* ui.c */
int ui_init(void);
-int ui_on_new_tab(struct tab*);
void ui_on_tab_refresh(struct tab*);
void ui_end(void);
blob - be069bbbee2ac8a9c71027a29b70c7680ca41c3b
blob + 7232a73b78c8c4262349f3b0883d4d5b7623dce9
--- ui.c
+++ ui.c
static void print_line(struct line*);
static void redraw_tab(struct tab*);
static void message(const char*, ...) __attribute__((format(printf, 1, 2)));
+static void new_tab(void);
typedef void (*interactivefn)(int);
static int clminibufev_set;
static struct timeval clminibufev_timer = { 5, 0 };
+static uint32_t tab_counter;
+
struct ui_state {
int curs_x;
int curs_y;
wrefresh(body);
va_end(ap);
+}
+
+static void
+new_tab(void)
+{
+ struct tab *tab, *t;
+ const char *url = "about:new";
+
+ if ((tab = calloc(1, sizeof(*tab))) == NULL)
+ goto err;
+
+ if ((tab->s = calloc(1, sizeof(*t->s))) == NULL)
+ goto err;
+
+ TAILQ_INIT(&tab->s->head);
+ TAILQ_FOREACH(t, &tabshead, tabs) {
+ t->flags &= ~TAB_CURRENT;
+ }
+
+ tab->id = tab_counter++;
+ tab->flags = TAB_CURRENT;
+
+ if (TAILQ_EMPTY(&tabshead))
+ TAILQ_INSERT_HEAD(&tabshead, tab, tabs);
+ else
+ TAILQ_INSERT_TAIL(&tabshead, tab, tabs);
+
+ load_url(tab, url);
+ return;
+
+err:
+ event_loopbreak();
}
int
signal_set(&winchev, SIGWINCH, handle_resize, NULL);
signal_add(&winchev, NULL);
- return 1;
-}
+ new_tab();
-int
-ui_on_new_tab(struct tab *tab)
-{
- struct tab *t;
-
- if ((tab->s = calloc(1, sizeof(*t->s))) == NULL)
- return 0;
-
- TAILQ_INIT(&tab->s->head);
-
- TAILQ_FOREACH(t, &tabshead, tabs) {
- t->flags &= ~TAB_CURRENT;
- }
- tab->flags = TAB_CURRENT;
-
- /* TODO: redraw the tab list */
- /* TODO: switch to the new tab */
-
- wmove(body, 0, 0);
-
return 1;
}