]> Sergey Matveev's repositories - nnn.git/commitdiff
Indicate when range selection and plugin picker are waiting for input (#406)
authorMaxim Baz <github@maximbaz.com>
Mon, 16 Dec 2019 23:07:48 +0000 (00:07 +0100)
committerMischievous Meerkat <engineerarun@gmail.com>
Mon, 16 Dec 2019 23:07:48 +0000 (04:37 +0530)
* Use [1:*] as indicator that range selection is in progress

* Fix review comments

* Add prompt for plugin selection

src/nnn.c

index a9fb120e4e0ac88a6bf943073cfc93f3988d38d0..d543a844f9189a5baacca7af93f5548550a01812 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -332,6 +332,7 @@ static kv plug[PLUGIN_MAX];
 static uchar g_tmpfplen;
 static uchar blk_shift = BLK_SHIFT_512;
 static bool interrupted = FALSE;
+static bool rangesel = FALSE;
 
 /* Retain old signal handlers */
 #ifdef __linux__
@@ -451,15 +452,14 @@ static char * const utils[] = {
 #define MSG_EMPTY_FILE 29
 #define MSG_UNSUPPORTED 30
 #define MSG_NOT_SET 31
-#define MSG_RANGE_SEL_ON 32
-#define MSG_DIR_CHANGED 33
-#define MSG_0_FILES 34
-#define MSG_EXISTS 35
-#define MSG_FEW_COLOUMNS 36
-#define MSG_REMOTE_OPTS 37
-#define MSG_RCLONE_DELAY 38
-#define MSG_APP_NAME 39
-#define MSG_ARCHIVE_OPTS 40
+#define MSG_DIR_CHANGED 32
+#define MSG_0_FILES 33
+#define MSG_EXISTS 34
+#define MSG_FEW_COLOUMNS 35
+#define MSG_REMOTE_OPTS 36
+#define MSG_RCLONE_DELAY 37
+#define MSG_APP_NAME 38
+#define MSG_ARCHIVE_OPTS 39
 
 static const char * const messages[] = {
        "no traversal",
@@ -494,7 +494,6 @@ static const char * const messages[] = {
        "empty: edit or open with",
        "unsupported file",
        "not set",
-       "range sel on",
        "dir changed, range sel off",
        "0 files",
        "entry exists",
@@ -3433,6 +3432,14 @@ static void printkv(kv *kvarr, FILE *fp, uchar max)
                fprintf(fp, " %c: %s\n", (char)kvarr[i].key, kvarr[i].val);
 }
 
+static void sprintkv(kv *kvarr, char *buf, uchar max)
+{
+       uchar i = 0;
+
+       for (; i < max && kvarr[i].key; ++i)
+               buf += snprintf(buf, CMD_LEN_MAX, " %c=%s", (char)kvarr[i].key, kvarr[i].val);
+}
+
 /*
  * The help string tokens (each line) start with a HEX value
  * which indicates the number of spaces to print before the
@@ -4137,7 +4144,8 @@ static void redraw(char *path)
                        c = cfg.apparentsz ? 'a' : 'd';
 
                        mvprintw(lastln, 0, "%d/%d [%d:%s] %cu:%s free:%s files:%lu %lldB %s",
-                                cur + 1, ndents, cfg.selmode, (nselected ?  xitoa(nselected) : ""),
+                                cur + 1, ndents, cfg.selmode,
+                                (rangesel ? "*" : (nselected ? xitoa(nselected) : "")),
                                 c, buf, coolsize(get_fs_info(path, FREE)), num_files,
                                 (ll)pent->blocks << blk_shift, ptr);
                } else { /* light or detail mode */
@@ -4150,7 +4158,8 @@ static void redraw(char *path)
                        buf[sizeof(buf)-1] = '\0';
 
                        mvprintw(lastln, 0, "%d/%d [%d:%s] %s%s %s %s %s [%s]",
-                                cur + 1, ndents, cfg.selmode, (nselected ?  xitoa(nselected) : ""),
+                                cur + 1, ndents, cfg.selmode,
+                                (rangesel ? "*" : (nselected ? xitoa(nselected) : "")),
                                 sort, buf, get_lsperms(pent->mode), coolsize(pent->size), ptr, base);
                }
        } else
@@ -4167,7 +4176,7 @@ static void browse(char *ipath, const char *session)
        int r = -1, fd, presel, selstartid = 0, selendid = 0;
        ino_t inode = 0;
        enum action sel;
-       bool dir_changed = FALSE, rangesel = FALSE;
+       bool dir_changed = FALSE;
        struct stat sb;
        char *path, *lastdir, *lastname, *dir, *tmp;
        MEVENT event;
@@ -4857,8 +4866,6 @@ nochange:
                        if (rangesel) { /* Range selection started */
                                inode = sb.st_ino;
                                selstartid = cur;
-                               printmsg(messages[MSG_RANGE_SEL_ON]);
-                               xdelay(XDELAY_INTERVAL_MS);
                                continue;
                        }
 
@@ -5181,10 +5188,15 @@ nochange:
                                }
 
                                if (sel == SEL_PLUGKEY) {
+                                       xstrlcpy(g_buf, "pick plugin:", CMD_LEN_MAX);
+                                       sprintkv(plug, g_buf + strlen(g_buf), PLUGIN_MAX);
+                                       printprompt(g_buf);
                                        r = get_input(NULL);
                                        tmp = get_kv_val(plug, NULL, r, PLUGIN_MAX, FALSE);
-                                       if (!tmp)
+                                       if (!tmp) {
+                                               clearprompt();
                                                goto nochange;
+                                       }
 
                                        if (tmp[0] == '_' && tmp[1]) {
                                                xstrlcpy(newpath, ++tmp, PATH_MAX);