summary refs log tree commit diff
path: root/nav.c
diff options
context:
space:
mode:
Diffstat (limited to 'nav.c')
-rw-r--r--nav.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/nav.c b/nav.c
index 3a1d095..59fdca6 100644
--- a/nav.c
+++ b/nav.c
@@ -3,6 +3,7 @@
 
 #include "nav.h"
 #include "net.h"
+#include "parse.h"
 
 /* history */
 
@@ -20,12 +21,27 @@ void nav_fini(struct nav_state *ns) {
 	}
 }
 
-void nav_new(struct nav_state *ns) {
+void nav_push(struct nav_state *ns, struct doc d) {
+	while (ns->histc > ns->cur_doc + 1) {
+		doc_fini(&ns->histv[--ns->histc]);
+	}
 	if (ns->histc == HIST_MAX) {
 		doc_fini(ns->histv);
 		memmove(ns->histv, &ns->histv[1], sizeof(struct doc) * (HIST_MAX - 1));
 		ns->histc--;
 	}
+	ns->histv[ns->histc++] = d;
+	ns->cur_doc = ns->histc - 1;
+}
+
+void nav_prev(struct nav_state *ns) {
+	if (ns->cur_doc > 0) ns->cur_doc--;
+	nav_redraw(ns);
+}
+
+void nav_next(struct nav_state *ns) {
+	if (ns->cur_doc + 1 < ns->histc) ns->cur_doc++;
+	nav_redraw(ns);
 }
 
 /* paging */
@@ -91,7 +107,14 @@ int nav_to(struct nav_state *ns, const char *url) {
 	if (net_fetch(&adr, &buf)) {
 		return -1;
 	}
+	struct doc d;
+	if (parse_doc(adr.type, &d, &buf)) {
+		buf_free(&buf);
+		return -1;
+	}
+	nav_push(ns, d);
 	buf_free(&buf);
+	nav_redraw(ns);
 	return 0;
 }