t* sacc + cursorline and uri preview
       
   URI git clone git://git.codevoid.de/sacc-sdk
   DIR Log
   DIR Files
   DIR Refs
   DIR LICENSE
       ---
   DIR commit 63737b1ffb50f53932a34001c0e6cc447d6d4e86
   DIR parent 1b724721acb63d32ea730b80348b7d96a27bbe09
   URI Author: Quentin Rameau <quinq@fifth.space>
       Date:   Mon, 10 Jul 2017 15:13:58 +0200
       
       Add support for '7' search type
       
       Diffstat:
         M common.h                            |       1 +
         M sacc.c                              |      44 ++++++++++++++++++++++++++-----
         M ui_ti.c                             |      39 ++++++++++++++++++++++++++++---
         M ui_txt.c                            |      19 ++++++++++++++++++-
       
       4 files changed, 93 insertions(+), 10 deletions(-)
       ---
   DIR diff --git a/common.h b/common.h
       t@@ -24,4 +24,5 @@ void display(Item *item);
        Item *selectitem(Item *entry);
        const char *typedisplay(char t);
        void uicleanup(void);
       +char *uiprompt(char *s);
        void uisetup(void);
   DIR diff --git a/sacc.c b/sacc.c
       t@@ -109,7 +109,7 @@ typedisplay(char t)
                case '6':
                        return "UUEf|";
                case '7':
       -                return "Find|";
       +                return "Find+";
                case '8':
                        return "Tlnt|";
                case '9':
       t@@ -347,6 +347,23 @@ fetchitem(Item *item)
                return (item->raw != NULL);
        }
        
       +static char *
       +searchselector(Item *item)
       +{
       +        char *input, *selector = NULL;
       +        size_t n;
       +
       +        if (input = uiprompt("Enter search string: ")) {
       +                selector = item->selector;
       +                n = strlen(input)-1 + strlen(selector);
       +                item->selector = xmalloc(n);
       +                snprintf(item->selector, n, "%s\t%s", selector, input);
       +                free(input);
       +        }
       +
       +        return selector;
       +}
       +
        static int
        dig(Item *entry, Item *item)
        {
       t@@ -362,6 +379,7 @@ dig(Item *entry, Item *item)
                                return 0;
                        break;
                case '1':
       +        case '7':
                        if (!fetchitem(item) || !(item->dir = molddiritem(item->raw))) {
                                fputs("Couldn't parse dir item\n", stderr);
                                return 0;
       t@@ -380,23 +398,37 @@ static void
        delve(Item *hole)
        {
                Item *entry = hole;
       +        char *selector;
        
                while (hole) {
       -                switch (dig(entry, hole)) {
       +                switch (hole->type) {
                        case '0':
       -                        displaytextitem(hole);
       +                        if (dig(entry, hole))
       +                                displaytextitem(hole);
                                break;
                        case '1':
       -                        if (hole->dir)
       +                        if (dig(entry, hole) && hole->dir)
                                        entry = hole;
                                break;
       +                case '7':
       +                        if (selector = searchselector(hole)) {
       +                                free(hole->raw);
       +                                hole->raw = NULL;
       +                                hole->printoff = 0;
       +                                if (dig(entry, hole) && hole->dir)
       +                                        entry = hole;
       +                                free(hole->selector);
       +                                hole->selector = selector;
       +                        }
       +                        break;
                        case 0:
                                fprintf(stderr, "Couldn't get %s:%s/%c%s\n", hole->host,
                                                hole->port, hole->type, hole->selector);
                        }
        
       -                display(entry);
       -                hole = selectitem(entry);
       +                do {
       +                        display(entry);
       +                } while ((hole = selectitem(entry)) == entry);
                }
        }
        
   DIR diff --git a/ui_ti.c b/ui_ti.c
       t@@ -1,4 +1,5 @@
        #include <stdio.h>
       +#include <stdlib.h>
        #include <term.h>
        #include <termios.h>
        #include <unistd.h>
       t@@ -7,6 +8,7 @@
        #include "common.h"
        
        static struct termios tsave;
       +static struct termios tsacc;
        /* navigation keys */
        #define _key_lndown        'j' /* move one line down */
        #define _key_lnup        'k' /* move one line up */
       t@@ -23,8 +25,6 @@ static struct termios tsave;
        void
        uisetup(void)
        {
       -        struct termios traw;
       -
                tcgetattr(0, &tsave);
                tsacc = tsave;
                tsacc.c_lflag &= ~(ECHO|ICANON);
       t@@ -46,6 +46,39 @@ uicleanup(void)
                fflush(stdout);
        }
        
       +char *
       +uiprompt(char *s)
       +{
       +        char *input = NULL;
       +        size_t n = 0;
       +        ssize_t r;
       +
       +        putp(tparm(save_cursor));
       +
       +        putp(tparm(cursor_address, lines-1, 0));
       +        putp(tparm(clr_eol));
       +        putp(tparm(enter_standout_mode));
       +        fputs(s, stdout);
       +        putp(tparm(exit_standout_mode));
       +
       +        tsacc.c_lflag |= (ECHO|ICANON);
       +        tcsetattr(0, TCSANOW, &tsacc);
       +        fflush(stdout);
       +
       +        r = getline(&input, &n, stdin);
       +
       +        tsacc.c_lflag &= ~(ECHO|ICANON);
       +        tcsetattr(0, TCSANOW, &tsacc);
       +        putp(tparm(restore_cursor));
       +        fflush(stdout);
       +
       +        if (r > 1)
       +                return input;
       +
       +        free(input);
       +        return NULL;
       +}
       +
        static void
        printitem(Item *item)
        {
       t@@ -83,7 +116,7 @@ display(Item *entry)
                Item **items;
                size_t i, curln, lastln, nitems, printoff;
        
       -        if (entry->type != '1')
       +        if (!(entry->type == '1' || entry->type == '7'))
                        return;
        
                putp(tparm(clear_screen));
   DIR diff --git a/ui_txt.c b/ui_txt.c
       t@@ -1,6 +1,7 @@
        #include <ctype.h>
        #include <errno.h>
        #include <stdio.h>
       +#include <stdlib.h>
        #include <string.h>
        #include <termios.h>
        #include <sys/ioctl.h>
       t@@ -66,6 +67,22 @@ printstatus(Item *item, char c)
                       item->host, item->port, item->selector, c);
        }
        
       +char *
       +uiprompt(char *s)
       +{
       +        char *input = NULL;
       +        size_t n = 0;
       +
       +        fputs(s, stdout);
       +        fflush(stdout);
       +
       +        if (getline(&input, &n, stdin) > 1)
       +                return input;
       +
       +        free(input);
       +        return NULL;
       +}
       +
        void
        display(Item *entry)
        {
       t@@ -73,7 +90,7 @@ display(Item *entry)
                size_t i, lines, nitems;
                int nd;
        
       -        if (entry->type != '1' || !entry->dir)
       +        if (!(entry->type == '1' || entry->type == '7') || !entry->dir)
                        return;
        
                items = entry->dir->items;