cgmnlm

colorful gemini line mode browser
git clone https://git.clttr.info/cgmnlm.git
Log (Feed) | Files | Refs (Tags) | README | LICENSE

commit 58aa37983670caf6736535790d4bf53f766032d6
parent c9fa82e9921722c4cf908c11e765c83bc42fed0a
Author: Ondřej Fiala <fiala.ondrej@volny.cz>
Date:   Fri, 10 Nov 2023 22:01:48 +0100

gmnlm: calculate number of rows available for text correctly

Diffstat:
Msrc/gmnlm.c | 49++++++++++++++++++++++++++++++++-----------------
1 file changed, 32 insertions(+), 17 deletions(-)

diff --git a/src/gmnlm.c b/src/gmnlm.c @@ -1100,12 +1100,40 @@ display_gemini(struct browser *browser, struct gemini_response *resp) int row = 0, col = 0; struct gemini_token tok; struct link **next = &browser->links; - // When your screen is too narrow, more lines will be used for helptext and URL. - // 87 is the maximum width of the prompt. - int info_rows = (ws.ws_col >= 87) ? 4 : 6; + char prompt[4096]; + char *end = NULL; + int info_rows = 0; + bool first_screen = 1; while (text != NULL || gemini_parser_next(&p, &tok) == 0) { repeat: + if (!row) { + if (browser->meta && (end = strchr(resp->meta, ';')) != NULL) { + *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" + "(more) => ", resp->meta, browser->plain_url, + browser->searching ? "[n]ext result; " : "", + browser->history->prev ? "[b]ack; " : "", + browser->history->next ? "[f]orward; " : ""); + if (end != NULL) { + *end = ';'; + } + + info_rows = 0; + for (char *ln = prompt; (end = strchr(ln, '\n')); ln = end + 1) { + *end = '\0'; + int len = strlen(ln); + info_rows += len / ws.ws_col + (len % ws.ws_col != 0); + if (!*ln) info_rows++; // empty line + *end = '\n'; + } + // if not first screen, text is preceded by an empty line, + // and help text is followed by a prompt line + info_rows += !first_screen + 1; + } + switch (tok.token) { case GEMINI_TEXT: col += fprintf(out, " "); @@ -1218,20 +1246,7 @@ repeat: ++row; col = 0; if (browser->pagination && row >= ws.ws_row - info_rows) { - char prompt[4096]; - char *end = NULL; - if (browser->meta && (end = strchr(resp->meta, ';')) != NULL) { - *end = 0; - } - snprintf(prompt, sizeof(prompt), "%s at %s\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; " : "", - browser->history->next ? "[f]orward; " : ""); - if (end != NULL) { - *end = ';'; - } + first_screen = 0; enum prompt_result result = PROMPT_AGAIN; while (result == PROMPT_AGAIN) { result = do_prompts(prompt, browser);