cgmnlm

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

commit c8041a15ac7d36ecc2e1c34dcaa14c51e62de788
parent 4c0f931d6688d06df2e22d001182f6fa1b776fab
Author: René Wagner <rwagner@rw-net.de>
Date:   Wed,  6 Jan 2021 19:36:39 +0100

t[N] command

t[N] downloads the content behind Nth link to
a tempfile in /tmp/

closes #2

Diffstat:
Msrc/cgmnlm.c | 56+++++++++++++++++++++++++++++++++++++-------------------
1 file changed, 37 insertions(+), 19 deletions(-)

diff --git a/src/cgmnlm.c b/src/cgmnlm.c @@ -67,11 +67,9 @@ enum prompt_result { }; const char *default_bookmarks = - "# Welcome to gmni\n\n" + "# Welcome to cgmnlm\n\n" "Links:\n\n" - // TODO: sub out the URL for the appropriate geminispace version once - // sr.ht supports gemini - "=> https://sr.ht/~sircmpwn/gmni The gmni browser\n" + "=> https://src.clttr.info/rwa/cgmnlm The cgmnlm browser\n" "=> gemini://gemini.circumlunar.space The gemini protocol\n\n" "This file can be found at %s and may be edited at your pleasure.\n\n" "Bookmarks:\n" @@ -79,24 +77,25 @@ const char *default_bookmarks = const char *help_msg = "The following commands are available:\n\n" - "q\tQuit\n" - "[N]\tFollow Nth link (where N is a number)\n" - "u[N]\tShow URL of Nth link (where N is a number)\n" - "e[N]\tSend URL of Nth link in external default program\n" - "b\tBack (in the page history)\n" - "f\tForward (in the page history)\n" - "H\tView all page history\n" - "a\tSave bookmark\n" - "B\tBrowse bookmarks\n" - "r\tReload the page\n" + "<Enter>\t\tread more lines (if available)\n" + "<url>\t\tgo to url\n" + "[N]\t\tFollow Nth link (where N is a number)\n" + "u[N]\t\tShow 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" + "H\t\tView all page history\n" + "a\t\tSave bookmark\n" + "B\t\tBrowse bookmarks\n" + "r\t\tReload the page\n" + "/<text>\t\tsearch for text (POSIX regular expression)\n" + "n\t\tjump to next search match\n" "d <path>\tDownload page to <path>\n" - "|<prog>\tPipe page into program\n" + "|<prog>\t\tPipe page into program\n" "[N]|<prog>\tPipe content of Nth link into program\n" + "q\t\tQuit\n" "\n" - "Other commands include:\n\n" - "<Enter>\tread more lines\n" - "<url>\tgo to url\n" - "/<text>\tsearch for text (POSIX regular expression)\n" ; static void @@ -598,6 +597,7 @@ do_prompts(const char *prompt, struct browser *browser) } case 'e': case 'u': + case 't': if (!in[1]) break; linksel = (int)strtol(in+1, &endptr, 10); if (!endptr[0] && linksel >= 0) { @@ -615,6 +615,24 @@ do_prompts(const char *prompt, struct browser *browser) snprintf(xdgopen, sizeof(xdgopen), "xdg-open %s", link->url); if ( !system(xdgopen) ) fprintf(browser->tty, "Link send to xdg-open\n"); } + if (in[0] == 't') { + struct gemini_response resp; + char url[1024] = {0}; + strncpy(&url[0], browser->plain_url, sizeof(link->url)-1); + set_url(browser, link->url, &browser->history); + // XXX: may affect history, do we care? + enum gemini_result res = do_requests(browser, &resp); + if (res != GEMINI_OK) { + fprintf(stderr, "Error: %s\n", + gemini_strerr(res, &resp)); + } else { + char tempfile[] = "/tmp/cgmnlm_XXXXXX"; + mkstemp(tempfile); + download_resp(browser->tty, resp, tempfile, link->url); + } + gemini_response_finish(&resp); + set_url(browser, url, NULL); + } fprintf(browser->tty, "\n"); } } else {