tAllow yanking URIs to X selection - sacc - simple console gopher client
(HTM) git clone git://src.adamsgaard.dk/sacc
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
(DIR) commit 21c069de24d57e2604f34b96d0f74b7cbf86b8fb
(DIR) parent 8f16ceadb2844a207ef67d2ff4d6664e74a5248f
(HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Wed, 4 Mar 2020 16:30:12 +0100
Allow yanking URIs to X selection
Diffstat:
M LICENSE | 1 +
M config.def.h | 5 +++++
M sacc.1 | 14 ++++++++++++++
M ui_ti.c | 53 +++++++++++++++++++++++++------
4 files changed, 63 insertions(+), 10 deletions(-)
---
(DIR) diff --git a/LICENSE b/LICENSE
t@@ -6,6 +6,7 @@ Copyright (c) 2017 sin <sin@2f30.org>
Copyright (c) 2017 trqx@goat.si <trqx@goat.si>
Copyright (c) 2017 kroovy <me@kroovy.de>
Copyright (c) 2018 Ivan J. <parazyd@dyne.org>
+Copyright (c) 2020 Anders Damsgaard <anders@adamsgaard.dk>
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
(DIR) diff --git a/config.def.h b/config.def.h
t@@ -13,6 +13,8 @@
#define _key_pgprev 'h' /* view previous item */
#define _key_cururi 'U' /* print page uri */
#define _key_seluri 'u' /* print item uri */
+#define _key_yankcur 'Y' /* yank page uri to clipboard */
+#define _key_yanksel 'y' /* yank item uri to clipboard */
#define _key_fetch 'L' /* refetch current item */
#define _key_help '?' /* display help */
#define _key_quit 'q' /* exit sacc */
t@@ -25,3 +27,6 @@ static char *plumber = "xdg-open";
/* temporary directory */
static char *tmpdir = "/tmp/sacc";
+
+/* command for writing to X selection (clipboard) */
+static char *xselwrite = "xclip -i";
(DIR) diff --git a/sacc.1 b/sacc.1
t@@ -64,6 +64,12 @@ Print the URI of the current page.
.B u
Print the URI of the highlighted item.
.TP
+.B Y
+Yank the URI of the current page to X selection.
+.TP
+.B y
+Yank the URI of the highlighted item to X selection.
+.TP
.B ?
Show the help message of shortcuts.
.TP
t@@ -77,6 +83,14 @@ cannot open natively, it will run
This can be configured in the
.I config.h
to run some other plumber.
+.SH X SELECTION
+The yank commands require an external helper program for writing to the primary X selection.
+By default,
+.I sacc
+will run
+.I xclip -i.
+This can be configured to another program in
+.I config.h.
.SH CUSTOMIZATION
.B sacc
can be customized by creating a custom config.h and (re)compiling the source
(DIR) diff --git a/ui_ti.c b/ui_ti.c
t@@ -122,6 +122,8 @@ help(Item *entry)
S(_key_searchprev) ": search string backward.\n"
S(_key_cururi) ": print page URI.\n"
S(_key_seluri) ": print item URI.\n"
+ S(_key_yankcur) ": yank page URI to X selection.\n"
+ S(_key_yanksel) ": yank item URI to X selection.\n"
S(_key_help) ": show this help.\n"
"^D, " S(_key_quit) ": exit sacc.\n"
};
t@@ -194,25 +196,18 @@ displaystatus(Item *item)
}
static void
-displayuri(Item *item)
+itemuri(Item *item)
{
size_t n;
- if (item->type == 0 || item->type == 'i')
- return;
-
- putp(tparm(save_cursor, 0, 0, 0, 0, 0, 0, 0, 0, 0));
-
- putp(tparm(cursor_address, lines-1, 0, 0, 0, 0, 0, 0, 0, 0));
- putp(tparm(enter_standout_mode, 0, 0, 0, 0, 0, 0, 0, 0, 0));
switch (item->type) {
case '8':
n = snprintf(bufout, sizeof(bufout), "telnet://%s@%s:%s",
item->selector, item->host, item->port);
break;
case 'h':
- n = snprintf(bufout, sizeof(bufout), "%s: %s",
- item->username, item->selector);
+ n = snprintf(bufout, sizeof(bufout), "%s",
+ item->selector+4);
break;
case 'T':
n = snprintf(bufout, sizeof(bufout), "tn3270://%s@%s:%s",
t@@ -238,7 +233,22 @@ displayuri(Item *item)
if (n >= sizeof(bufout))
bufout[sizeof(bufout)-1] = '\0';
+}
+
+static void
+displayuri(Item *item)
+{
+ size_t n;
+
+ if (item->type == 0 || item->type == 'i')
+ return;
+ putp(tparm(save_cursor, 0, 0, 0, 0, 0, 0, 0, 0, 0));
+
+ putp(tparm(cursor_address, lines-1, 0, 0, 0, 0, 0, 0, 0, 0));
+ putp(tparm(enter_standout_mode, 0, 0, 0, 0, 0, 0, 0, 0, 0));
+
+ itemuri(item);
n = mbsprint(bufout, columns);
putp(tparm(exit_standout_mode, 0, 0, 0, 0, 0, 0, 0, 0, 0));
if (n < columns)
t@@ -248,6 +258,21 @@ displayuri(Item *item)
fflush(stdout);
}
+static void
+yankuri(Item *item)
+{
+ FILE *clip;
+ char xselcmd[128];
+ snprintf(xselcmd, sizeof(xselcmd), "%s 2>/dev/null", xselwrite);
+
+ itemuri(item);
+
+ if ((clip = popen(xselcmd, "w"))) {
+ fprintf(clip, "%s", bufout);
+ pclose(clip);
+ }
+}
+
void
uidisplay(Item *entry)
{
t@@ -554,6 +579,14 @@ uiselectitem(Item *entry)
if (dir)
displayuri(&dir->items[dir->curline]);
continue;
+ case _key_yankcur:
+ if (dir)
+ yankuri(entry);
+ continue;
+ case _key_yanksel:
+ if (dir)
+ yankuri(&dir->items[dir->curline]);
+ continue;
case _key_help: /* FALLTHROUGH */
return help(entry);
default: