summary refs log tree commit diff
path: root/main.c
diff options
context:
space:
mode:
authorwrmr2024-11-02 19:33:08 -0500
committerwrmr2024-11-02 19:33:08 -0500
commit610808a5902adad751a4acdbcc310803a51fed5d (patch)
tree76599dc60cccf6a3765f484dfa1b19e1af88efa1 /main.c
parent58214ec5f982c1b97aadce254c958a5f922c9724 (diff)
very different document data structure
Diffstat (limited to 'main.c')
-rw-r--r--main.c45
1 files changed, 9 insertions, 36 deletions
diff --git a/main.c b/main.c
index adc488a..64343bc 100644
--- a/main.c
+++ b/main.c
@@ -7,30 +7,10 @@
 #include "doc.h"
 #include "net.h"
 #include "err.h"
+#include "nav.h"
 
 /* pagination */
 
-size_t pg_lines() {
-	return 24;
-}
-
-void pg_down(void) {
-	size_t lines = pg_lines();
-	while (lines--) doc_print_line();
-}
-
-void pg_up(void) {
-	size_t lines = pg_lines() << 1;
-	while (lines--) doc_back_line();
-	pg_down();
-}
-
-void pg_redraw(void) {
-	size_t lines = pg_lines();
-	while (lines--) doc_back_line();
-	pg_down();
-}
-
 /* navigation */
 
 int nav_to(const char *url) {
@@ -56,7 +36,7 @@ struct cmd {
 
 /* cmd is mutated when trimming strings
  * returns whether to quit */
-int cmd_do(char *cmd) {
+int cmd_do(char *cmd, struct nav_state *ns) {
 	switch (*cmd) {
 	case 'q':
 		puts("goodbye!");
@@ -74,13 +54,13 @@ int cmd_do(char *cmd) {
 		}
 		break;
 	case 'b':
-		pg_up();
+		nav_pg_up(ns);
 		break;
 	case '\0':
-		pg_down();
+		nav_pg_down(ns);
 		break;
 	case 'r':
-		pg_redraw();
+		nav_redraw(ns);
 		break;
 	case 'g':
 		if (nav_to(cmd + 1)) perr("navigation failure");
@@ -108,23 +88,16 @@ int cmd_get(char *buf, size_t n) {
 	return !!fgets(buf, n, stdin);
 }
 
-void init(void) {
-	doc_init();
-}
-
-void fini(void) {
-	doc_fini();
-}
-
 int main(void) {
+	struct nav_state ns;
 	char cmd_buf[1024];
-	init();
-	atexit(fini);
+	nav_init(&ns);
 	while (cmd_get(cmd_buf, sizeof cmd_buf)) {
 		cmd_trim(cmd_buf, sizeof cmd_buf);
-		if (cmd_do(cmd_buf)) {
+		if (cmd_do(cmd_buf, &ns)) {
 			break;
 		}
 	}
+	nav_fini(&ns);
 	return 0;
 }