Add a key to display an entry uri - sacc - sacc(omys), simple console gopher client
git clone git://bitreich.org/sacc/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/sacc/
Log
Files
Refs
Tags
LICENSE
---
commit 3eabb27085c4725068d843aed2168af1e6834964
parent 078d0408656082f0cff4dd7f2b39dc988bc2391e
Author: Quentin Rameau 
Date:   Wed, 30 Aug 2017 17:37:19 +0200

Add a key to display an entry uri

Thanks to Nick  for the suggestion and work he did on it!

Diffstat:
  M config.def.h                        |       1 +
  M ui_ti.c                             |      28 ++++++++++++++++++++++++++++
  M ui_txt.c                            |      47 +++++++++++++++++++++++++------

3 files changed, 68 insertions(+), 8 deletions(-)
---
diff --git a/config.def.h b/config.def.h
@@ -9,6 +9,7 @@
 #define _key_end        'G' /* move to the bottom of page */
 #define _key_pgnext        'l' /* view highlighted item */
 #define _key_pgprev        'h' /* view previous item */
+#define _key_uri        'u' /* print item uri */
 #define _key_fetch        'L' /* refetch current item */
 #define _key_help        '?' /* display help */
 #define _key_quit        'q' /* exit sacc */
diff --git a/ui_ti.c b/ui_ti.c
@@ -152,6 +152,30 @@ displaystatus(Item *item)
         fflush(stdout);
 }
 
+static void
+displayuri(Item *item)
+{
+        putp(tparm(save_cursor));
+
+        putp(tparm(cursor_address, lines-1, 0));
+        putp(tparm(enter_standout_mode));
+        switch (item->type) {
+        case 'i':
+                break;
+        case 'h':
+                printf("%s: %s", item->username, item->selector);
+                break;
+        default:
+                printf("%s: %s:%s%s",
+                       item->username, item->host, item->port, item->selector);
+                break;
+        }
+        putp(tparm(exit_standout_mode));
+
+        putp(tparm(restore_cursor));
+        fflush(stdout);
+}
+
 void
 uidisplay(Item *entry)
 {
@@ -377,6 +401,10 @@ uiselectitem(Item *entry)
                         if (entry->raw)
                                 continue;
                         return entry;
+                case _key_uri:
+                        if (dir)
+                                displayuri(dir->items[dir->curline]);
+                        continue;
                 case _key_help: /* FALLTHROUGH */
                         return help(entry);
                 default:
diff --git a/ui_txt.c b/ui_txt.c
@@ -132,6 +132,24 @@ uidisplay(Item *entry)
         fflush(stdout);
 }
 
+void
+printuri(Item *item, size_t i)
+{
+        if (!item)
+                return;
+        switch (item->type) {
+        case 'i':
+                break;
+        case 'h':
+                printf("%zu: %s: %s\n", i, item->username, item->selector);
+                break;
+        default:
+                printf("%zu: %s: %s:%s%s\n", i, item->username,
+                       item->host, item->port, item->selector);
+                break;
+        }
+}
+
 Item *
 uiselectitem(Item *entry)
 {
@@ -147,8 +165,7 @@ uiselectitem(Item *entry)
         if (!c)
                 c = 'h';
 
-        do {
-                item = -1;
+        for (;;) {
                 printstatus(entry, c);
                 fflush(stdout);
 
@@ -156,10 +173,21 @@ uiselectitem(Item *entry)
                         putchar('\n');
                         return NULL;
                 }
-                if (isdigit(*buf))
+                if (isdigit(*buf)) {
                         c = '\0';
-                else if (!strcmp(buf+1, "\n"))
+                        nl = '\0';
+                        if (sscanf(buf, "%d%c", &item, &nl) != 2 || nl != '\n')
+                                item = -1;
+                } else if (!strcmp(buf+1, "\n")) {
+                        item = -1;
                         c = *buf;
+                } else if (isdigit(*(buf+1))) {
+                        nl = '\0';
+                        if (sscanf(buf+1, "%d%c", &item, &nl) != 2 || nl != '\n')
+                                item = -1;
+                        else
+                                c = *buf;
+                }
 
                 switch (c) {
                 case '\0':
@@ -193,6 +221,10 @@ uiselectitem(Item *entry)
                         if (entry->raw)
                                 continue;
                         return entry;
+                case 'u':
+                        if (item > 0 && item <= nitems)
+                                printuri(dir->items[item-1], item);
+                        continue;
                 case 'h':
                 case '?':
                         help();
@@ -205,10 +237,9 @@ uiselectitem(Item *entry)
                 if (*buf < '0' || *buf > '9')
                         continue;
 
-                nl = '\0';
-                if (sscanf(buf, "%d%c", &item, &nl) != 2 || nl != '\n')
-                        item = -1;
-        } while (item < 0 || item > nitems);
+                if (item > 0 && item <= nitems);
+                        break;
+        }
 
         if (item > 0)
                 return dir->items[item-1];