From ce088cbf9c3a73e9f9ed3012d31dd6e989d86052 Mon Sep 17 00:00:00 2001 From: wrmr Date: Sun, 3 Nov 2024 12:12:20 -0500 Subject: file:// plaintext reading complete, add nav_next/nav_prev --- nav.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'nav.c') 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; } -- cgit 1.4.1-2-gfad0