diff options
author | wrmr | 2024-11-06 00:04:05 -0500 |
---|---|---|
committer | wrmr | 2024-11-06 00:04:05 -0500 |
commit | 5fe796490718f84d20ff9c836ce75d5318d44c69 (patch) | |
tree | 87abe322bee07ff6d4f4231bb7e79f81be63094f /nav.c | |
parent | 837a9067c0ef2e0b3affbf7035788cd0e80ce7ba (diff) |
add link number navigation
Diffstat (limited to 'nav.c')
-rw-r--r-- | nav.c | 16 |
1 files changed, 16 insertions, 0 deletions
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; } |