Commit Diff


commit - 81ea92ab8940bc75a4db7a1aa6b420acc633d4cb
commit + 8af5e5ed7d3241dbab8b862b93eabb320b12a801
blob - 4f0b597135810518b2c77c9cb396b34b6b6c778a
blob + b3843af884d65030adec705e5f5e5a61463884ab
--- telescope.c
+++ telescope.c
@@ -157,6 +157,7 @@ handle_imsg_eof(struct imsg *imsg, size_t datalen)
 		die();
 
 	ui_on_tab_refresh(t);
+	ui_on_tab_loaded(t);
 }
 
 static void
@@ -197,11 +198,14 @@ load_page_from_str(struct tab *tab, const char *page)
 	if (!tab->page.free(&tab->page))
 		die();
 	ui_on_tab_refresh(tab);
+	ui_on_tab_loaded(tab);
 }
 
 void
 load_url(struct tab *tab, const char *url)
 {
+	strlcpy(tab->url, url, sizeof(tab->url));
+
 	if (!strcmp(url, "about:new")) {
 		load_page_from_str(tab, about_new);
 		return;
blob - 9900036dcff323d80908cf44b7deee73ada44626
blob + 7bb35db2f1303dc2b2bd84586775d44b60c8758d
--- telescope.h
+++ telescope.h
@@ -93,6 +93,8 @@ struct tab {
 	uint32_t		 id;
 	uint32_t		 flags;
 
+	char			 url[GEMINI_URL_LEN];
+
 	int			 code;
 	char			 meta[GEMINI_URL_LEN];
 	int			 redirect_count;
@@ -120,6 +122,7 @@ void		 load_url(struct tab*, const char*);
 
 /* ui.c */
 int		 ui_init(void);
+void		 ui_on_tab_loaded(struct tab*);
 void		 ui_on_tab_refresh(struct tab*);
 void		 ui_end(void);
 
blob - 26fa8267b0daa1d5c11c0254fbc198b3171269d2
blob + 698b4fb14aae07254b36757d42dd726a60d36e51
--- ui.c
+++ ui.c
@@ -98,8 +98,13 @@ static void		 wrap_text(struct tab*, const char*, stru
 static int		 hardwrap_text(struct tab*, struct line*);
 static int		 wrap_page(struct tab*);
 static void		 print_line(struct line*);
+static void		 redraw_tabline(void);
+static void		 redraw_modeline(struct tab*);
 static void		 redraw_tab(struct tab*);
 static void		 message(const char*, ...) __attribute__((format(printf, 1, 2)));
+static void		 start_loading_anim(struct tab*);
+static void		 update_loading_anim(int, short, void*);
+static void		 stop_loading_anim(struct tab*);
 static void		 new_tab(void);
 
 typedef void (*interactivefn)(struct tab*);
@@ -110,6 +115,7 @@ static int	 body_lines, body_cols;
 static struct event	clminibufev;
 static int		clminibufev_set;
 static struct timeval	clminibufev_timer = { 5, 0 };
+static struct timeval	loadingev_timer = { 0, 250000 };
 
 static uint32_t		 tab_counter;
 
@@ -119,6 +125,10 @@ struct ui_state {
 	size_t			line_off;
 	size_t			line_max;
 
+	short			loading_anim;
+	short			loading_anim_step;
+	struct event		loadingev;
+
 	TAILQ_HEAD(, line)	head;
 };
 
@@ -639,17 +649,26 @@ print_line(struct line *l)
 }
 
 static void
+redraw_tabline(void)
+{
+	wclear(tabline);
+	wbkgd(tabline, A_REVERSE);
+	mvwprintw(tabline, 0, 0, "TODO: tabs here");
+}
+
+static void
 redraw_modeline(struct tab *tab)
 {
 	int		 x, y, max_x, max_y;
-	const char	*url = "TODO:url";
 	const char	*mode = "text/gemini-mode";
+	const char	*spin = "-\\|/";
 
 	wclear(modeline);
 	wattron(modeline, A_REVERSE);
 	wmove(modeline, 0, 0);
 
-	wprintw(modeline, "-- %s %s ", mode, url);
+	wprintw(modeline, "-%c %s %s ",
+	    spin[tab->s->loading_anim_step], mode, tab->url);
 	getyx(modeline, y, x);
 	getmaxyx(modeline, max_y, max_x);
 
@@ -682,6 +701,7 @@ redraw_tab(struct tab *tab)
 			break;
 	}
 
+	redraw_tabline();
 	redraw_modeline(tab);
 
 	restore_cursor(tab);
@@ -715,6 +735,48 @@ message(const char *fmt, ...)
 }
 
 static void
+start_loading_anim(struct tab *tab)
+{
+	if (tab->s->loading_anim)
+		return;
+	tab->s->loading_anim = 1;
+	evtimer_set(&tab->s->loadingev, update_loading_anim, tab);
+	evtimer_add(&tab->s->loadingev, &loadingev_timer);
+}
+
+static void
+update_loading_anim(int fd, short ev, void *d)
+{
+	struct tab	*tab = d;
+
+	tab->s->loading_anim_step = (tab->s->loading_anim_step+1)%4;
+
+	redraw_modeline(tab);
+	wrefresh(modeline);
+	wrefresh(body);
+
+	evtimer_add(&tab->s->loadingev, &loadingev_timer);
+}
+
+static void
+stop_loading_anim(struct tab *tab)
+{
+	if (!tab->s->loading_anim)
+		return;
+	evtimer_del(&tab->s->loadingev);
+	tab->s->loading_anim = 0;
+	tab->s->loading_anim_step = 0;
+}
+
+static void
+ui_load_url_in_tab(struct tab *tab, const char *url)
+{
+	message("Loading %s...", url);
+	start_loading_anim(tab);
+	load_url(tab, url);
+}
+
+static void
 new_tab(void)
 {
 	struct tab	*tab, *t;
@@ -739,7 +801,7 @@ new_tab(void)
 	else
 		TAILQ_INSERT_TAIL(&tabshead, tab, tabs);
 
-	load_url(tab, url);
+	ui_load_url_in_tab(tab, url);
 	return;
 
 err:
@@ -790,6 +852,13 @@ ui_init(void)
 }
 
 void
+ui_on_tab_loaded(struct tab *tab)
+{
+	stop_loading_anim(tab);
+	message("Loaded %s", tab->url);
+}
+
+void
 ui_on_tab_refresh(struct tab *tab)
 {
 	if (!(tab->flags & TAB_CURRENT))