Commit Diff


commit - a17dbcabb4ae2fd7144f18dc394277cca6f43969
commit + 2f524b17f5cc48bb6752037b1c88b684c39a7d2c
blob - c056284f05d9f84a9ccb325ba4d6955bf8a7881e
blob + 9d704ebc217737c63b2b5b1f1144b3c1caf5ec32
--- ChangeLog
+++ ChangeLog
@@ -1,6 +1,7 @@
 2021-07-17  Omar Polo  <op@omarpolo.com>
 
 	* telescope.c (load_url): lazy loading for telescope: don't load all the tabs when starting up, only the current one.  Defer the loading of the others when switching to them.
+	(load_last_session): cache the page title
 
 	* defaults.c (line_faces): don't underline links by default
 	add set-title option
blob - e4f215ea98921e76d7926eb4a98183f0bcf936e4
blob + 4df0dd10b376c1bfe218ffbe6e8303a7031d389c
--- fs.c
+++ fs.c
@@ -44,6 +44,7 @@ static void		 handle_update_cert(struct imsg*, size_t)
 static void		 handle_file_open(struct imsg*, size_t);
 static void		 handle_session_start(struct imsg*, size_t);
 static void		 handle_session_tab(struct imsg*, size_t);
+static void		 handle_session_tab_title(struct imsg*, size_t);
 static void		 handle_session_end(struct imsg*, size_t);
 static void		 handle_dispatch_imsg(int, short, void*);
 static int		 fs_send_ui(int, uint32_t, int, const void *, uint16_t);
@@ -66,6 +67,7 @@ static imsg_handlerfn *handlers[] = {
 	[IMSG_FILE_OPEN] = handle_file_open,
 	[IMSG_SESSION_START] = handle_session_start,
 	[IMSG_SESSION_TAB] = handle_session_tab,
+	[IMSG_SESSION_TAB_TITLE] = handle_session_tab_title,
 	[IMSG_SESSION_END] = handle_session_end,
 };
 
@@ -300,9 +302,26 @@ handle_session_tab(struct imsg *imsg, size_t datalen)
 	fprintf(session, "%s", url);
 
 	if (flags & TAB_CURRENT)
-		fprintf(session, " current");
+		fprintf(session, " current ");
+	else
+		fprintf(session, " - ");
+}
 
-	fprintf(session, "\n");
+static void
+handle_session_tab_title(struct imsg *imsg, size_t datalen)
+{
+	const char	*title;
+
+	title = imsg->data;
+	if (title == NULL) {
+		datalen = 1;
+		title = "";
+	}
+
+	if (title[datalen-1] != '\0')
+		die();
+
+	fprintf(session, "%s\n", title);
 }
 
 static void
blob - bb431883fc8665862e2ce9396f98d4ec3c9d57e6
blob + 8dc28bf785912f6358c37733e25fec6f96b27fd7
--- telescope.c
+++ telescope.c
@@ -61,7 +61,7 @@ static void		 handle_imsg_update_cert_ok(struct imsg *
 static void		 handle_dispatch_imsg(int, short, void*);
 static void		 load_page_from_str(struct tab*, const char*);
 static int		 do_load_url(struct tab*, const char*);
-static void		 parse_session_line(char *, uint32_t *);
+static void		 parse_session_line(char *, const char **, uint32_t *);
 static void		 load_last_session(void);
 static pid_t		 start_child(enum telescope_process, const char *, int);
 static int		 ui_send_net(int, uint32_t, const void *, uint16_t);
@@ -701,6 +701,7 @@ void
 save_session(void)
 {
 	struct tab	*tab;
+	char		*t;
 	int		 flags;
 
 	ui_send_fs(IMSG_SESSION_START, 0, NULL, 0);
@@ -709,8 +710,12 @@ save_session(void)
 		flags = tab->flags;
 		if (tab == current_tab)
 			flags |= TAB_CURRENT;
-		ui_send_fs(IMSG_SESSION_TAB, flags,
-		    tab->hist_cur->h, strlen(tab->hist_cur->h)+1);
+
+		t = tab->hist_cur->h;
+		ui_send_fs(IMSG_SESSION_TAB, flags, t, strlen(t)+1);
+
+		t = tab->buffer.page.title;
+		ui_send_fs(IMSG_SESSION_TAB_TITLE, 0, t, strlen(t)+1);
 	}
 
 	ui_send_fs(IMSG_SESSION_END, 0, NULL, 0);
@@ -719,18 +724,25 @@ save_session(void)
 /*
  * Parse a line of the session file.  The format is:
  *
- *	URL [flags,...]\n
+ *	URL [flags,...] [title]\n
  */
 static void
-parse_session_line(char *line, uint32_t *flags)
+parse_session_line(char *line, const char **title, uint32_t *flags)
 {
-	char *s, *ap;
+	char *s, *t, *ap;
 
+	*title = "";
 	*flags = 0;
 	if ((s = strchr(line, ' ')) == NULL)
 		return;
 
 	*s++ = '\0';
+
+        if ((t = strchr(s, ' ')) != NULL) {
+		*t++ = '\0';
+		*title = t;
+	}
+
 	while ((ap = strsep(&s, ",")) != NULL) {
 		if (*ap == '\0')
 			;
@@ -744,6 +756,7 @@ parse_session_line(char *line, uint32_t *flags)
 static void
 load_last_session(void)
 {
+	const char	*title;
 	char		*nl, *line = NULL;
 	uint32_t	 flags;
 	size_t		 linesize = 0;
@@ -760,9 +773,11 @@ load_last_session(void)
 	while ((linelen = getline(&line, &linesize, session)) != -1) {
                 if ((nl = strchr(line, '\n')) != NULL)
 			*nl = '\0';
-		parse_session_line(line, &flags);
+		parse_session_line(line, &title, &flags);
 		if ((tab = new_tab(line)) == NULL)
-                        err(1, "new_tab");
+			err(1, "new_tab");
+                strlcpy(tab->buffer.page.title, title,
+		    sizeof(tab->buffer.page.title));
 		if (flags & TAB_CURRENT)
 			curr = tab;
 	}
blob - 83e88154ac0ebc97b587a29505d6e59cd6a3c936
blob + a4bcbd09e802e5eaac68d7c62f8d9fc16bb4c735
--- telescope.h
+++ telescope.h
@@ -64,6 +64,7 @@ enum imsg_type {
 
 	IMSG_SESSION_START,
 	IMSG_SESSION_TAB,
+	IMSG_SESSION_TAB_TITLE,
 	IMSG_SESSION_END,
 };