~sircmpwn/gmni-devel

Add d[N] to download Nth link v1 APPLIED

Sebastiano Tronto: 1
 Add d[N] to download Nth link

 1 files changed, 26 insertions(+), 7 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/gmni-devel/patches/32382/mbox | git am -3
Learn more about email & git

[PATCH] Add d[N] to download Nth link Export this patch

I wanted to add an optional [N] to 'd' and '|' to download/pipe the
Nth link instead of the current page. After getting the first one done,
I found out that '|' already has this option, so I fixed the relative
help line without changing that command.

All in all I don't know how useful this patch is, considering that
'[N]|' was already there. Feel free to discard it and just keep the
documentation change.

Cheers!

---
 src/gmnlm.c | 33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/src/gmnlm.c b/src/gmnlm.c
index 68c5556..b79bb32 100644
--- a/src/gmnlm.c
+++ b/src/gmnlm.c
@@ -83,8 +83,8 @@ const char *help_msg =
	"m [title]\tSave bookmark\n"
	"M\tBrowse bookmarks\n"
	"r\tReload the page\n"
	"d [path]\tDownload page to path\n"
	"|<prog>\tPipe page into program\n"
	"d[N] [path]\tDownload page, or Nth link, to path\n"
	"[N]|<prog>\tPipe page, or Nth link, into program\n"
	"\n"
	"Other commands include:\n\n"
	"<Enter>\tread more lines\n"
@@ -679,22 +679,41 @@ do_prompts(const char *prompt, struct browser *browser)
		result = PROMPT_AGAIN;
		goto exit;
	case 'd':
		if (in[1] != '\0' && !isspace(in[1])) break;
		endptr = &in[1];
		char *d_url = browser->plain_url;
		if (in[1] != '\0' && !isspace(in[1])) {
			struct link *link = browser->links;
			int linksel = (int)strtol(in+1, &endptr, 10);
			while (linksel > 0 && link) {
				link = link->next;
				--linksel;
			}

			if (!link) {
				fprintf(stderr, "Error: no such link.\n");
				break;
			} else {
				d_url = link->url;
			}
		}
		struct gemini_response resp;
		char url[1024] = {0};
		strncpy(&url[0], browser->plain_url, sizeof(url)-1);
		char url[1024] = {0}, old_url[1024] = {0};
		strncpy(&old_url[0], browser->plain_url, sizeof(url)-1);
		strncpy(&url[0], d_url, sizeof(url)-1);
		// XXX: may affect history, do we care?
		set_url(browser, url, NULL);
		enum gemini_result res = do_requests(browser, &resp);
		if (res != GEMINI_OK) {
			fprintf(stderr, "Error: %s\n",
				gemini_strerr(res, &resp));
			result = PROMPT_AGAIN;
			set_url(browser, old_url, NULL);
			goto exit;
		}
		set_url(browser, url, NULL);
		download_resp(browser->tty, resp, trim_ws(&in[1]), url);
		download_resp(browser->tty, resp, trim_ws(endptr), url);
		gemini_response_finish(&resp);
		result = PROMPT_AGAIN;
		set_url(browser, old_url, NULL);
		goto exit;
	case '|':
		strncpy(&url[0], browser->plain_url, sizeof(url)-1);
-- 
2.36.1
Thanks!

To git@git.sr.ht:~sircmpwn/gmni
   8c62393..eb5c547  master -> master