From 610808a5902adad751a4acdbcc310803a51fed5d Mon Sep 17 00:00:00 2001 From: wrmr Date: Sat, 2 Nov 2024 19:33:08 -0500 Subject: very different document data structure --- nav.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 nav.c (limited to 'nav.c') diff --git a/nav.c b/nav.c new file mode 100644 index 0000000..82cf71a --- /dev/null +++ b/nav.c @@ -0,0 +1,62 @@ +#include +#include +#include "nav.h" + +void nav_init(struct nav_state *ns) { + memset(ns, 0, sizeof *ns); + ns->histc = 1; + doc_init(&ns->histv[0]); + doc_add_text(&ns->histv[0], "Type ? for command help."); +} + +void nav_fini(struct nav_state *ns) { + for (size_t i = 0; i < ns->histc; i++) { + doc_fini(&ns->histv[i]); + } +} + +size_t pg_lines(void) { + return 24; +} + +struct doc_line *nav_cur_line(struct nav_state *ns) { + return (struct doc_line *)&ns->histv[ns->cur_doc].txt.buf[ns->cur_ofs[ns->cur_doc]]; +} + +int nav_line_up(struct nav_state *ns) { + if (ns->cur_ofs[ns->cur_doc] > 0) { + ns->cur_ofs[ns->cur_doc] -= nav_cur_line(ns)->prev; + return 1; + } else { + return 0; + } +} + +int nav_line_down(struct nav_state *ns) { + struct doc_line *l = nav_cur_line(ns); + if (ns->cur_ofs[ns->cur_doc] + sizeof(struct doc_line) + l->len < ns->histv[ns->cur_doc].txt.sz) { + ns->cur_ofs[ns->cur_doc] += l->len + sizeof(struct doc_line); + return 1; + } else { + return 0; + } +} + +void nav_pg_up(struct nav_state *ns) { + size_t lines = pg_lines() << 1; + while (lines-- && nav_line_up(ns)); + nav_pg_down(ns); +} + +void nav_pg_down(struct nav_state *ns) { + size_t lines = pg_lines(); + while (lines--) { + struct doc_line *l = nav_cur_line(ns); + fwrite(l->txt, 1, l->len, stdout); + putchar('\n'); + if (!nav_line_down(ns)) break; + } +} + +void nav_redraw(struct nav_state *ns) { +} -- cgit 1.4.1-2-gfad0