gmni

a gemini line mode client
git clone https://git.clttr.info/gmni.git
Log (Feed) | Files | Refs (Tags) | README | LICENSE

commit af1f6baf5e7f8f08a48e22fa48b1320d72c6b132
parent d0eb06405db6ac117f9d3b18d3790f01c370c2db
Author: Ondřej Fiala <ofiala@airmail.cc>
Date:   Tue, 26 Dec 2023 23:37:17 +0100

gmnlm: allow following links that haven't been printed yet

Diffstat:
Msrc/gmnlm.c | 28++++++++++++++++++----------
1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/src/gmnlm.c b/src/gmnlm.c @@ -856,16 +856,27 @@ display_document(struct browser *browser, struct gemini_response *resp, free(browser->page_title); browser->page_title = NULL; - FILE *out = browser->tty; - bool searching = browser->searching; - if (searching) { - out = fopen("/dev/null", "w+"); + struct gemini_token tok; + struct link **next = &browser->links; + FILE *out = fopen("/dev/null", "w"); + while (parser_next(&p, &tok) == 0) { + if (tok.token != GEMINI_LINK) goto skip; + *next = calloc(1, sizeof(struct link)); + (*next)->url = strdup(trim_ws(tok.link.url)); + next = &(*next)->next; +skip: + gemini_token_finish(&tok); } + fclose(out); + out = browser->tty; + gemini_parser_init(&p, resp->body); char *text = NULL; int row = 0, col = 0; - struct gemini_token tok; - struct link **next = &browser->links; + bool searching = browser->searching; + if (searching) { + out = fopen("/dev/null", "w+"); + } char prompt[4096]; int info_rows = 0; @@ -884,7 +895,7 @@ repeat: *end = 0; } snprintf(prompt, sizeof(prompt), "\n%s at %s\n" - "[Enter]: read more; %s[N]: =follow Nth link; %s%s[q]uit; [?]; or type a URL\n" + "[Enter]: read more; %s[N]: follow Nth link; %s%s[q]uit; [?]; or type a URL\n" "(more) => ", resp->meta, browser->plain_url, browser->searching ? "[n]ext result; " : "", browser->history->prev ? "[b]ack; " : "", @@ -917,9 +928,6 @@ repeat: if (text == NULL) { col += fprintf(out, "%d) ", nlinks++); text = trim_ws(tok.link.text ? tok.link.text : tok.link.url); - *next = calloc(1, sizeof(struct link)); - (*next)->url = strdup(trim_ws(tok.link.url)); - next = &(*next)->next; } else { col += fprintf(out, " "); }