From 5fe796490718f84d20ff9c836ce75d5318d44c69 Mon Sep 17 00:00:00 2001 From: wrmr Date: Wed, 6 Nov 2024 00:04:05 -0500 Subject: add link number navigation --- nav.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'nav.c') diff --git a/nav.c b/nav.c index 83826dc..0c31bed 100644 --- a/nav.c +++ b/nav.c @@ -3,6 +3,7 @@ #include "nav.h" #include "net.h" +#include "err.h" #include "parse.h" /* history */ @@ -70,10 +71,17 @@ void nav_pg_up(struct nav_state *ns) { nav_pg_down(ns); } +#define MARGIN 8 + void nav_pg_down(struct nav_state *ns) { size_t lines = pg_lines(); while (lines--) { struct doc_line *l = nav_cur_line(ns); + int n = 0; + if (l->link != DOC_LINK_NONE) { + n = printf("[%hu]", l->link + 1); + } + while (n++ < MARGIN) putchar(' '); fwrite(l->txt, 1, l->len, stdout); putchar('\n'); if (!nav_line_down(ns)) break; @@ -111,5 +119,13 @@ int nav_to(struct nav_state *ns, const char *url) { } int nav_link_nr(struct nav_state *ns, unsigned long link_nr) { + struct doc *d = &ns->histv[ns->cur_doc]; + const char *url = doc_get_link(d, link_nr); + if (url) { + puts(url); + return nav_to(ns, url); + } else { + perr("invalid link number"); + } return 0; } -- cgit 1.4.1-2-gfad0