cgmnlm

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

commit 22a28fa92755b49254cac144894be1fdb917a6a3
parent e299aec4a10ba3aaf01c50263cbcabe8d39a5214
Author: René Wagner <rwagner@rw-net.de>
Date:   Sun, 31 Jan 2021 17:41:11 +0100

jump more than one entry back or forth in history

by giving an optional number to b & f commands.
The default behaviour of b & f commands has not
been changed.

Diffstat:
MREADME.md | 19+++++++++++++------
Msrc/gmnlm.c | 33+++++++++++++++++----------------
2 files changed, 30 insertions(+), 22 deletions(-)

diff --git a/README.md b/README.md @@ -27,6 +27,8 @@ It includes the following modifications: - k command to remove the bookmark for the current page - e[N] command to open a link in default external program (requires `xdg-open`) - t[N] command to download the content behind a link to a temporary file +- b & f commands to navigate history can jump multiple entries at once +- colored headings & links The actual colors used depend on your terminal palette: - heading 1: light red @@ -39,11 +41,13 @@ The actual colors used depend on your terminal palette: Besides this rendering adjustments i'll try to keep track of upstream changes or send patches to upstream. -## Dependencies: +## Usage -- A POSIX-like system and a C11 compiler -- OpenSSL -- [scdoc](https://sr.ht/~sircmpwn/scdoc/) (optional, build only) +See `gmni(1)`, `cgmnlm(1)`. + +# Installation + +* ArchLinux and derivates: https://aur.archlinux.org/packages/cgmnlm-git/ ## Compiling @@ -54,6 +58,9 @@ $ make # make install ``` -## Usage +### Dependencies: + +- A POSIX-like system and a C11 compiler +- OpenSSL +- [scdoc](https://sr.ht/~sircmpwn/scdoc/) (optional) -See `gmni(1)`, `cgmnlm(1)`. diff --git a/src/gmnlm.c b/src/gmnlm.c @@ -84,8 +84,8 @@ const char *help_msg = "p[N]\t\tPrint URL of Nth link (where N is a number)\n" "e[N]\t\tSend URL of Nth link in external default program\n" "t[N]\t\tDownload content of Nth link to a temporary file\n" - "b\t\tBack (in the page history)\n" - "f\t\tForward (in the page history)\n" + "b[N]\t\tJump back N entries in history, N is optional, default 1\n" + "f[N]\t\tJump forward N entries in history, N is optional, default 1\n" "H\t\tView all page history\n" "m\t\tSave bookmark\n" "M\t\tBrowse bookmarks\n" @@ -546,6 +546,8 @@ do_prompts(const char *prompt, struct browser *browser) struct link *link = browser->links; char *endptr = NULL; int linksel = 0; + int historyhops = 1; + char *in = NULL; size_t l = 0; ssize_t n = getline(&in, &l, browser->tty); @@ -554,7 +556,7 @@ do_prompts(const char *prompt, struct browser *browser) goto exit; } in[n - 1] = 0; // Remove LF - + int r; switch (in[0]) { case '\0': @@ -565,25 +567,24 @@ do_prompts(const char *prompt, struct browser *browser) result = PROMPT_QUIT; goto exit; case 'b': - if (in[1]) break; - if (!browser->history->prev) { - fprintf(stderr, "At beginning of history\n"); - result = PROMPT_AGAIN; - goto exit; + if (in[1]) historyhops =(int)strtol(in+1, &endptr, 10); + while (historyhops > 0) { + if (browser->history->prev) { + browser->history = browser->history->prev; + } + historyhops--; } - if (in[1]) break; - browser->history = browser->history->prev; set_url(browser, browser->history->url, NULL); result = PROMPT_ANSWERED; goto exit; case 'f': - if (in[1]) break; - if (!browser->history->next) { - fprintf(stderr, "At end of history\n"); - result = PROMPT_AGAIN; - goto exit; + if (in[1]) historyhops =(int)strtol(in+1, &endptr, 10); + while (historyhops > 0) { + if (browser->history->next) { + browser->history = browser->history->next; + } + historyhops--; } - browser->history = browser->history->next; set_url(browser, browser->history->url, NULL); result = PROMPT_ANSWERED; goto exit;