Commit Diff


commit - ede1f142436ff97c9244b2ddcd69f016d20596bf
commit + bcb0b0730e139513b6c811bed3691bcb1a0df8b6
blob - 3ff19e7ad790dfb9328cd07a0a6c07b5c34c2e6f
blob + 4f0b597135810518b2c77c9cb396b34b6b6c778a
--- telescope.c
+++ telescope.c
@@ -15,7 +15,6 @@ struct event		 imsgev;
 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);
@@ -25,7 +24,6 @@ static void	handle_imsg_buf(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,
@@ -201,7 +199,7 @@ load_page_from_str(struct tab *tab, const char *page)
 	ui_on_tab_refresh(tab);
 }
 
-static void
+void
 load_url(struct tab *tab, const char *url)
 {
 	if (!strcmp(url, "about:new")) {
@@ -213,27 +211,6 @@ load_url(struct tab *tab, const char *url)
 	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)
 {
@@ -269,8 +246,6 @@ 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
@@ -115,9 +115,11 @@ extern const char	*about_new;
 #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
@@ -98,6 +98,7 @@ static int		 wrap_page(struct tab*);
 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);
 
@@ -110,6 +111,8 @@ static struct event	clminibufev;
 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;
@@ -685,6 +688,38 @@ message(const char *fmt, ...)
 	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
@@ -725,29 +760,8 @@ ui_init(void)
 	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;
 }