tAdd yank feature to sacc - sacc - sacc (saccomys): simple gopher client.
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
 (DIR) commit c2e060c906af4fd970cb2b9ee2e3c05c83db1582
 (DIR) parent e80d8bfc3241d197f387a7cbe40ec924853bdc83
 (HTM) Author: Quentin Rameau <quinq@fifth.space>
       Date:   Sat, 13 Nov 2021 12:34:01 +0100
       
       Add yank feature to sacc
       
       Thanks to adc (Anders Damsgaard <anders@adamsgaard.dk>) and
       Evil_Bob (Hiltjo Posthuma <hiltjo@codemadness.org>) for
       ttheir suggestions, patches, and peer pressure.
       
       Diffstat:
         M LICENSE                             |       1 +
         M common.h                            |       1 +
         M config.def.h                        |       5 +++++
         M sacc.1                              |       6 ++++++
         M sacc.c                              |      23 +++++++++++++++++++++++
         M ui_ti.c                             |      10 ++++++++++
         M ui_txt.c                            |       8 ++++++++
       
       7 files changed, 54 insertions(+), 0 deletions(-)
       ---
 (DIR) diff --git a/LICENSE b/LICENSE
       t@@ -8,6 +8,7 @@ Copyright (c) 2018 Ivan J. <parazyd@dyne.org>
        Copyright (c) 2018 Leonardo Taccari <iamleot@gmail.com>
        Copyright (c) 2018 Stefan Hagen <sh+git@codevoid.de>
        Copyright (c) 2021 escapeinsert <ben@0x1bi.net>
       +Copyright (c) 2021 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/common.h b/common.h
       t@@ -53,6 +53,7 @@ extern char *strcasestr(const char *, const char *);
        #endif /* NEED_STRCASESTR */
        extern const char *typedisplay(char);
        extern int itemuri(Item *, char *, size_t);
       +extern void yankitem(Item *);
        extern void uicleanup(void);
        extern void uidisplay(Item *);
        extern char *uiprompt(char *, ...);
 (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 */
       +#define _key_yanksel        'y' /* yank item uri */
        #define _key_fetch        'L' /* refetch current item */
        #define _key_help        '?' /* display help */
        #define _key_quit        'q' /* exit sacc */
       t@@ -22,6 +24,9 @@
        
        #ifdef NEED_CONF
        
       +/* default yanker */
       +static char *yanker = "xclip";
       +
        /* default plumber */
        static char *plumber = "xdg-open";
        
 (DIR) diff --git a/sacc.1 b/sacc.1
       t@@ -65,6 +65,12 @@ Print the URI of the current page.
        .B u
        Print the URI of the highlighted item.
        .TP
       +.B Y
       +Yank the current page URI to an external program.
       +.TP
       +.B y
       +Yank the highlighted item URI to an external program.
       +.TP
        .B ?
        Show the help message of shortcuts.
        .TP
 (DIR) diff --git a/sacc.c b/sacc.c
       t@@ -28,6 +28,7 @@ void (*diag)(char *, ...);
        
        static const char *ident = "@(#) sacc(omys): " VERSION;
        
       +static char intbuf[256]; /* 256B ought to be enough for any URI */
        static char *mainurl;
        static Item *mainentry;
        static int devnullfd;
       t@@ -679,6 +680,21 @@ fetchitem(Item *item)
        }
        
        static void
       +pipeuri(char *cmd, char *msg, char *uri)
       +{
       +        FILE *sel;
       +
       +        if ((sel = popen(cmd, "w")) == NULL) {
       +                diag("URI not %s\n", msg);
       +                return;
       +        }
       +
       +        fputs(uri, sel);
       +        pclose(sel);
       +        diag("%s \"%s\"", msg, uri);
       +}
       +
       +static void
        execuri(char *cmd, char *msg, char *uri)
        {
                switch (fork()) {
       t@@ -757,6 +773,13 @@ cleanup:
                return;
        }
        
       +void
       +yankitem(Item *item)
       +{
       +        itemuri(item, intbuf, sizeof(intbuf));
       +        pipeuri(yanker, "Yanked", intbuf);
       +}
       +
        static int
        dig(Item *entry, Item *item)
        {
 (DIR) diff --git a/ui_ti.c b/ui_ti.c
       t@@ -138,6 +138,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 external program.\n"
       +                       S(_key_yanksel) ": yank item URI to external program.\n"
                               S(_key_help) ": show this help.\n"
                               "^D, " S(_key_quit) ": exit sacc.\n"
                };
       t@@ -533,6 +535,14 @@ uiselectitem(Item *entry)
                                if (dir)
                                        displayuri(&dir->items[dir->curline]);
                                continue;
       +                case _key_yankcur:
       +                        if (dir)
       +                                yankitem(entry);
       +                        continue;
       +                case _key_yanksel:
       +                        if (dir)
       +                                yankitem(&dir->items[dir->curline]);
       +                        continue;
                        case _key_help: /* FALLTHROUGH */
                                return help(entry);
                        default:
 (DIR) diff --git a/ui_txt.c b/ui_txt.c
       t@@ -55,6 +55,8 @@ help(void)
                     "p: show previous page.\n"
                     "t: go to the top of the page\n"
                     "b: go to the bottom of the page\n"
       +             "Y: yank page URI.\n"
       +             "y#: yank item number # URI.\n"
                     "/str: search for string \"str\"\n"
                     "!: refetch failed item.\n"
                     "^D, q: quit.\n"
       t@@ -271,6 +273,12 @@ uiselectitem(Item *entry)
                                if (item > 0 && item <= nitems)
                                        printuri(&dir->items[item-1], item);
                                continue;
       +                case 'Y':
       +                        yankitem(entry);
       +                        continue;
       +                case 'y':
       +                        if (item > 0 && item <= nitems)
       +                                yankitem(&dir->items[item-1]);
                        case '/':
                                if (*sstr)
                                        searchinline(sstr, entry);