Use a combo to parse help string

This commit is contained in:
Arun Prakash Jana 2019-12-17 06:36:10 +05:30
parent f10481e93e
commit 75061367be
No known key found for this signature in database
GPG key ID: A75979F35C080412

View file

@ -1775,6 +1775,21 @@ static int xstrverscasecmp(const char * const s1, const char * const s2)
static int (*cmpfn)(const char * const s1, const char * const s2) = &xstricmp; static int (*cmpfn)(const char * const s1, const char * const s2) = &xstricmp;
/* Return the integer value of a char representing HEX */
static char xchartohex(char c)
{
if (xisdigit(c))
return c - '0';
if (c >= 'a' && c <= 'f')
return c - 'a' + 10;
if (c >= 'A' && c <= 'F')
return c - 'A' + 10;
return c;
}
static int setfilter(regex_t *regex, const char *filter) static int setfilter(regex_t *regex, const char *filter)
{ {
return regcomp(regex, filter, REG_NOSUB | REG_EXTENDED | REG_ICASE); return regcomp(regex, filter, REG_NOSUB | REG_EXTENDED | REG_ICASE);
@ -3441,41 +3456,41 @@ static void show_help(const char *path)
FILE *fp; FILE *fp;
const char *start, *end; const char *start, *end;
const char helpstr[] = { const char helpstr[] = {
"\n" "0\n"
" NAVIGATION\n" "1NAVIGATION\n"
"%-9cUp k Up%-20cPgUp ^U Scroll up\n" "9Up k Up%-20cPgUp ^U Scroll up\n"
"%-7cDown j Down%-18cPgDn ^D Scroll down\n" "7Down j Down%-18cPgDn ^D Scroll down\n"
"%-7cLeft h Parent%-16c~ ` @ - HOME, /, start, last\n" "7Left h Parent%-16c~ ` @ - HOME, /, start, last\n"
"%-9cg ^A Top%-15cRet Right l Open\n" "9g ^A Top%-15cRet Right l Open\n"
"%-9cG ^E Bottom%-22c' First file\n" "9G ^E Bottom%-22c' First file\n"
"%-12cb Pin CWD%-20c^B Go to pinned dir\n" "cb Pin CWD%-20c^B Go to pinned dir\n"
"%-9c, ^/ Lead key%-14cN LeadN Context N\n" "9c, ^/ Lead key%-14cN LeadN Context N\n"
"%-6c(Sh)Tab Cycle context%-15cd Detail view toggle\n" "6(Sh)Tab Cycle context%-15cd Detail view toggle\n"
"%-12c/ Filter%-17cIns ^N Nav-as-you-type toggle\n" "c/ Filter%-17cIns ^N Nav-as-you-type toggle\n"
"%-10cEsc Exit prompt%-13c^L F5 Redraw/clear prompt\n" "aEsc Exit prompt%-13c^L F5 Redraw/clear prompt\n"
"%-12c. Show/hide dots%-14c? Help, conf\n" "c. Show/hide dots%-14c? Help, conf\n"
"%-9cQ ^Q Quit%-24cq Quit context\n" "9Q ^Q Quit%-24cq Quit context\n"
"%-11c^G QuitCD%-1c\n" "b^G QuitCD%-1c\n"
" FILES\n" "1FILES\n"
"%-11c^O Open with...%-16cn Create new/link\n" "b^O Open with...%-16cn Create new/link\n"
"%-12cD File details%-12c^R F2 Rename/duplicate\n" "cD File details%-12c^R F2 Rename/duplicate\n"
"%-3cSpace ^J/a Sel toggle/all%-14cr Batch rename\n" "3Space ^J/a Sel toggle/all%-14cr Batch rename\n"
"%-9cm ^K Sel range, clear%-12cM List sel\n" "9m ^K Sel range, clear%-12cM List sel\n"
"%-12cP Copy sel here%-15cK Edit sel\n" "cP Copy sel here%-15cK Edit sel\n"
"%-12cV Move sel here%-15cw Copy/move sel as\n" "cV Move sel here%-15cw Copy/move sel as\n"
"%-12cX Delete sel%-17c^X Delete entry\n" "cX Delete sel%-17c^X Delete entry\n"
"%-12cf Archive%-18co ^F Archive ops\n" "cf Archive%-18co ^F Archive ops\n"
"%-12ce Edit in EDITOR%-14cp Open in PAGER\n" "ce Edit in EDITOR%-14cp Open in PAGER\n"
" ORDER TOGGLES\n" "1ORDER TOGGLES\n"
"%-12cA Apparent du%-17cS du\n" "cA Apparent du%-17cS du\n"
"%-12cz Size%-24ct Time\n" "cz Size%-24ct Time\n"
"%-12cE Extension%-1c\n" "cE Extension%-1c\n"
" MISC\n" "1MISC\n"
"%-9c! ^] Shell%-21c; x Plugin key\n" "9! ^] Shell%-21c; x Plugin key\n"
"%-12cC Execute file%-13ci ^V Pick plugin\n" "cC Execute file%-13ci ^V Pick plugin\n"
"%-12cs Manage session%-14c= Launch app\n" "cs Manage session%-14c= Launch app\n"
"%-12cc Connect remote%-14cu Unmount\n" "cc Connect remote%-14cu Unmount\n"
"%-9c] ^P Prompt%-22cL Lock\n" "9] ^P Prompt%-22cL Lock\n"
}; };
fd = create_tmp_file(); fd = create_tmp_file();
@ -3491,7 +3506,8 @@ static void show_help(const char *path)
start = end = helpstr; start = end = helpstr;
while (*end) { while (*end) {
if (*end == '\n') { if (*end == '\n') {
xstrlcpy(g_buf, start, end - start + 2); snprintf(g_buf, CMD_LEN_MAX, "%*c%.*s",
xchartohex(*start), ' ', (int)(end - start), start + 1);
fprintf(fp, g_buf, ' ', ' '); fprintf(fp, g_buf, ' ', ' ');
start = end + 1; start = end + 1;
} }