summary refs log tree commit diff
path: root/nav.c
diff options
context:
space:
mode:
authorwrmr2024-11-03 12:12:20 -0500
committerwrmr2024-11-03 12:12:20 -0500
commitce088cbf9c3a73e9f9ed3012d31dd6e989d86052 (patch)
tree2fdc9ca366f8a42f919ca8e3577c8079dd102965 /nav.c
parent3e9c75318b0eb1114fb7361dbc467990674804b6 (diff)
file:// plaintext reading complete, add nav_next/nav_prev
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;
 }