zygo

ncurses gopher client
Log | Files | Refs

commit d86b6196fff98338983c69c8ca0b259dd1283a34
parent 8987db32c62489dbd4f94e947862762aac027252
Author: hhvn <dev@hhvn.uk>
Date:   Sat, 22 Jan 2022 23:01:10 +0000

zygo.c zygo.h zygo.1 config.def.h: yanking

Diffstat:
M.config.hhvn.h | 1+
Mconfig.def.h | 1+
Mzygo.1 | 6++++++
Mzygo.c | 57++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Mzygo.h | 1+
5 files changed, 61 insertions(+), 5 deletions(-)

diff --git a/.config.hhvn.h b/.config.hhvn.h @@ -1,4 +1,5 @@ static char *plumber = "plumb"; +static char *yanker = "xclip"; static int parallelplumb = 1; static int stimeout = 5; static int regexflags = REG_ICASE|REG_EXTENDED; diff --git a/config.def.h b/config.def.h @@ -1,4 +1,5 @@ static char *plumber = "xdg-open"; +static char *yanker = "xclip"; static int parallelplumb = 0; static int stimeout = 5; static int regexflags = REG_ICASE|REG_EXTENDED; diff --git a/zygo.1 b/zygo.1 @@ -80,6 +80,8 @@ Set the plumber to Do not wait for the plumber to exit. .It Fl u Automatically upgrade connections to TLS. +.It Fl y Ar yanker +Program to use for yanking URIs. .El .Sh INPUT .Nm @@ -130,6 +132,10 @@ Go to bottom of page. Go to root selector of current gopherhole. .It + Print uri of link where the bar normally is. +.It y +Yank URI of link. +.It Y +Yank current URI. .El .Sh SEE OTHER .Xr cgo 1 diff --git a/zygo.c b/zygo.c @@ -829,6 +829,35 @@ end: return ui.arg; } +Elem * +strtolink(char *str) { + if (atoi(str) >= page->lastid || atoi(str) < 0) { + error("no such link: %s", str); + return NULL; + } + + return list_idget(&page, atoi(str)); +} + +void +yank(Elem *e) { + FILE *hand; + char *uri; + + uri = elemtouri(e); + + /* TODO: fork and close stdout/stderr, + * whilst checking for error */ + if (!(hand = popen(yanker, "w"))) { + error("could not run %s for yanking", yanker); + return; + } + fwrite(uri, strlen(uri), sizeof(char), hand); + pclose(hand); + + free(uri); +} + /* * Main loop */ @@ -872,9 +901,7 @@ run(void) { elem_free(e); break; case '+': - if (atoi(ui.arg) >= page->lastid || atoi(ui.arg) < 0) { - error("no suck link: %s", ui.arg); - } else { + if (e = strtolink(ui.arg)) { move(LINES - 1, 0); attroff(A_COLOR); clrtoeol(); @@ -908,6 +935,10 @@ run(void) { go(e, 1, 0); elem_free(e); break; + case 'y': + if (e = strtolink(ui.arg)) + yank(e); + break; } ui.wantinput = 0; draw_page(); @@ -1024,6 +1055,10 @@ run(void) { case 'h': manpage(); break; + case 'Y': + checkcurrent(); + yank(current); + break; /* link numbers */ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': @@ -1041,8 +1076,10 @@ run(void) { case '+': case '/': case 'a': - if (c == 'a' || c == '+') + case 'y': + if (c == 'a' || c == '+' || c == 'y') { checkcurrent(); + } ui.cmd = (char)c; ui.wantinput = 1; ui.input[0] = '\0'; @@ -1086,7 +1123,7 @@ sighandler(int signal) { void usage(char *argv0) { - fprintf(stderr, "usage: %s [-kPvu] [-p plumber] [uri]\n", basename(argv0)); + fprintf(stderr, "usage: %s [-kPvu] [-p plumber] [-y yanker] [uri]\n", basename(argv0)); exit(EXIT_FAILURE); } @@ -1132,6 +1169,16 @@ main(int argc, char *argv[]) { usage(argv[0]); } break; + case 'y': + if (*(s+1)) { + yanker = s + 1; + s += strlen(s) - 1; + } else if (i + 1 != argc) { + yanker = argv[++i]; + } else { + usage(argv[0]); + } + break; case 'P': parallelplumb = 1; break; diff --git a/zygo.h b/zygo.h @@ -102,6 +102,7 @@ void draw_page(void); void draw_bar(void); void syncinput(void); char *prompt(char *prompt, size_t count); +Elem *strtolink(char *str); /* Main loop */ void run(void);