Show prompt for bookmark selection (#409)

* Cleanup unused MSG_

* Print only plugin keys

* Speed up preparing keys prompt

* Show prompt for bookmarks

* Don't error when user interactively pressed non-existent bookmark key
This commit is contained in:
Maxim Baz 2019-12-17 02:36:40 +01:00 committed by Mischievous Meerkat
parent 75061367be
commit 99128ab5c9
1 changed files with 58 additions and 48 deletions

106
src/nnn.c
View File

@ -422,49 +422,48 @@ static char * const utils[] = {
/* Common strings */
#define MSG_NO_TRAVERSAL 0
#define MSG_INVBM_KEY 1
#define STR_DATE_ID 2
#define STR_TMPFILE 3
#define MSG_0_SELECTED 4
#define MSG_UTIL_MISSING 5
#define MSG_FAILED 6
#define MSG_SSN_NAME 7
#define MSG_CP_MV_AS 8
#define MSG_CUR_SEL_OPTS 9
#define MSG_FORCE_RM 10
#define MSG_CREATE_CTX 11
#define MSG_NEW_OPTS 12
#define MSG_CLI_MODE 13
#define MSG_OVERWRITE 14
#define MSG_SSN_OPTS 15
#define MSG_QUIT_ALL 16
#define MSG_HOSTNAME 17
#define MSG_ARCHIVE_NAME 18
#define MSG_OPEN_WITH 19
#define MSG_REL_PATH 20
#define MSG_LINK_SUFFIX 21
#define MSG_COPY_NAME 22
#define MSG_CONTINUE 23
#define MSG_SEL_MISSING 24
#define MSG_ACCESS 25
#define MSG_0_CREATED 26
#define MSG_NOT_REG_FILE 27
#define MSG_PERM_DENIED 28
#define MSG_EMPTY_FILE 29
#define MSG_UNSUPPORTED 30
#define MSG_NOT_SET 31
#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
#define STR_TMPFILE 2
#define MSG_0_SELECTED 3
#define MSG_UTIL_MISSING 4
#define MSG_FAILED 5
#define MSG_SSN_NAME 6
#define MSG_CP_MV_AS 7
#define MSG_CUR_SEL_OPTS 8
#define MSG_FORCE_RM 9
#define MSG_CREATE_CTX 10
#define MSG_NEW_OPTS 11
#define MSG_CLI_MODE 12
#define MSG_OVERWRITE 13
#define MSG_SSN_OPTS 14
#define MSG_QUIT_ALL 15
#define MSG_HOSTNAME 16
#define MSG_ARCHIVE_NAME 17
#define MSG_OPEN_WITH 18
#define MSG_REL_PATH 19
#define MSG_LINK_SUFFIX 20
#define MSG_COPY_NAME 21
#define MSG_CONTINUE 22
#define MSG_SEL_MISSING 23
#define MSG_ACCESS 24
#define MSG_0_CREATED 25
#define MSG_NOT_REG_FILE 26
#define MSG_PERM_DENIED 27
#define MSG_EMPTY_FILE 28
#define MSG_UNSUPPORTED 29
#define MSG_NOT_SET 30
#define MSG_DIR_CHANGED 31
#define MSG_EXISTS 32
#define MSG_FEW_COLUMNS 33
#define MSG_REMOTE_OPTS 34
#define MSG_RCLONE_DELAY 35
#define MSG_APP_NAME 36
#define MSG_ARCHIVE_OPTS 37
#define MSG_PLUGIN_KEYS 38
#define MSG_BOOKMARK_KEYS 39
static const char * const messages[] = {
"no traversal",
"invalid key",
"%F %T %z",
"/.nnnXXXXXX",
"0 selected",
"missing util",
@ -495,13 +494,14 @@ static const char * const messages[] = {
"unsupported file",
"not set",
"dir changed, range sel off",
"0 files",
"entry exists",
"too few columns!",
"'s'shfs / 'r'clone?",
"may take a while, try refresh",
"app name: ",
"e'x'tract / 'l'ist / 'm'ount?",
"plugin keys:",
"bookmark keys:",
};
/* Supported configuration environment variables */
@ -3434,12 +3434,17 @@ 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)
static void sprintkeys(kv *kvarr, char *buf, uchar max)
{
uchar i = 0;
uchar j = 0;
for (; i < max && kvarr[i].key; ++i)
buf += snprintf(buf, CMD_LEN_MAX, " %c=%s", (char)kvarr[i].key, kvarr[i].val);
for (; i < max && kvarr[i].key; ++i, j+=2) {
buf[j] = ' ';
buf[j+1] = kvarr[i].key;
}
buf[j] = '\0';
}
/*
@ -4034,7 +4039,7 @@ static void redraw(char *path)
/* Fail redraw if < than 10 columns, context info prints 10 chars */
if (ncols < MIN_DISPLAY_COLS) {
printmsg(messages[MSG_FEW_COLOUMNS]);
printmsg(messages[MSG_FEW_COLUMNS]);
return;
}
@ -4568,6 +4573,9 @@ nochange:
fd = sel - SEL_CTX1 + '1';
break;
default:
xstrlcpy(g_buf, messages[MSG_BOOKMARK_KEYS], CMD_LEN_MAX);
sprintkeys(bookmark, g_buf + strlen(g_buf), BM_MAX);
printprompt(g_buf);
fd = get_input(NULL);
}
@ -4628,12 +4636,14 @@ nochange:
}
if (!get_kv_val(bookmark, newpath, fd, BM_MAX, TRUE)) {
printwait(messages[MSG_INVBM_KEY], &presel);
clearprompt();
goto nochange;
}
if (!xdiraccess(newpath))
if (!xdiraccess(newpath)) {
printwait(messages[MSG_ACCESS], &presel);
goto nochange;
}
if (strcmp(path, newpath) == 0)
break;
@ -5194,8 +5204,8 @@ nochange:
}
if (sel == SEL_PLUGKEY) {
xstrlcpy(g_buf, "pick plugin:", CMD_LEN_MAX);
sprintkv(plug, g_buf + strlen(g_buf), PLUGIN_MAX);
xstrlcpy(g_buf, messages[MSG_PLUGIN_KEYS], CMD_LEN_MAX);
sprintkeys(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);