mirror of
https://github.com/jarun/nnn.git
synced 2024-12-01 02:49:44 +00:00
Minor refactor
This commit is contained in:
parent
ba2040afec
commit
faea2915f4
10
README.md
10
README.md
|
@ -9,12 +9,9 @@
|
||||||
<a href="https://github.com/jarun/nnn/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-BSD%202--Clause-yellowgreen.svg?maxAge=2592000" alt="License" /></a>
|
<a href="https://github.com/jarun/nnn/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-BSD%202--Clause-yellowgreen.svg?maxAge=2592000" alt="License" /></a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center"><a href="https://asciinema.org/a/353811"><img src="https://i.imgur.com/InHB5DB.png" /></a></p>
|
<p align="center"><a href="https://asciinema.org/a/353811"><img src="https://i.imgur.com/InHB5DB.png" /><br></a></p>
|
||||||
<p align="center"><i>icons and colors (click for asciicast) </i></p>
|
<p align="center"><i>icons and colors (click for asciicast) </i></p>
|
||||||
|
|
||||||
<p align="center"><a href="https://www.youtube.com/watch?v=U2n5aGqou9E"><img src="https://i.imgur.com/MPWpmos.png" /></a></p>
|
|
||||||
<p align="center"><i>type-to-nav & du (click for demo video)</i></p>
|
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
|
|
||||||
<img align="left" src="misc/logo/logo-128x128.png">
|
<img align="left" src="misc/logo/logo-128x128.png">
|
||||||
|
@ -29,6 +26,11 @@ It runs smoothly on the Pi, [Termux](https://www.youtube.com/watch?v=AbaauM7gUJw
|
||||||
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RMLTQ76JSXJ4Q"><img src="https://img.shields.io/badge/donate-PayPal-1eb0fc.svg" alt="Donate via PayPal!" /></a>
|
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RMLTQ76JSXJ4Q"><img src="https://img.shields.io/badge/donate-PayPal-1eb0fc.svg" alt="Donate via PayPal!" /></a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<p align="center"><a href="https://www.youtube.com/watch?v=U2n5aGqou9E"><img src="https://i.imgur.com/MPWpmos.png" /></a></p>
|
||||||
|
<p align="center"><i>type-to-nav & du (click for demo video)</i></p>
|
||||||
|
|
||||||
## Black magic! :dark_sunglasses:
|
## Black magic! :dark_sunglasses:
|
||||||
|
|
||||||
- Instantly load, sort, filter thousands of files
|
- Instantly load, sort, filter thousands of files
|
||||||
|
|
44
src/nnn.c
44
src/nnn.c
|
@ -686,7 +686,7 @@ static const char * const patterns[] = {
|
||||||
#define C_UND (C_SOC + 1) /* Unknown OR 0B regular/exe file: Red1 */
|
#define C_UND (C_SOC + 1) /* Unknown OR 0B regular/exe file: Red1 */
|
||||||
|
|
||||||
#ifdef ICONS
|
#ifdef ICONS
|
||||||
/* NUMBERS, A-Z, OTHER = 28. */
|
/* 0-9, A-Z, OTHER = 36. */
|
||||||
static ushort icon_positions[37];
|
static ushort icon_positions[37];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1234,7 +1234,7 @@ static char confirm_force(bool selection)
|
||||||
|
|
||||||
int r = get_input(str);
|
int r = get_input(str);
|
||||||
|
|
||||||
if (r == 27)
|
if (r == ESC)
|
||||||
return '\0'; /* cancel */
|
return '\0'; /* cancel */
|
||||||
if (r == 'y' || r == 'Y')
|
if (r == 'y' || r == 'Y')
|
||||||
return 'f'; /* forceful */
|
return 'f'; /* forceful */
|
||||||
|
@ -1740,10 +1740,8 @@ static bool initcurses(void *oldmask)
|
||||||
} else if (c >= '0' && c <= '9') {
|
} else if (c >= '0' && c <= '9') {
|
||||||
if (icon_positions[c - '0'] == 0x7f7f)
|
if (icon_positions[c - '0'] == 0x7f7f)
|
||||||
icon_positions[c - '0'] = i;
|
icon_positions[c - '0'] = i;
|
||||||
} else {
|
} else if (icon_positions[36] == 0x7f7f)
|
||||||
if (icon_positions[36] == 0x7f7f)
|
icon_positions[36] = i;
|
||||||
icon_positions[36] = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (icons_ext[i].color && !icolors[icons_ext[i].color]) {
|
if (icons_ext[i].color && !icolors[icons_ext[i].color]) {
|
||||||
init_pair(C_UND + 1 + icons_ext[i].color, icons_ext[i].color, -1);
|
init_pair(C_UND + 1 + icons_ext[i].color, icons_ext[i].color, -1);
|
||||||
|
@ -2502,7 +2500,7 @@ static int handle_alt_key(wint_t *wch)
|
||||||
timeout(0);
|
timeout(0);
|
||||||
int r = get_wch(wch);
|
int r = get_wch(wch);
|
||||||
if (r == ERR)
|
if (r == ERR)
|
||||||
*wch = 27;
|
*wch = ESC;
|
||||||
cleartimeout();
|
cleartimeout();
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
|
@ -2524,18 +2522,18 @@ static int nextsel(int presel)
|
||||||
//DPRINTF_S(keyname(c));
|
//DPRINTF_S(keyname(c));
|
||||||
|
|
||||||
/* Handle Alt+key */
|
/* Handle Alt+key */
|
||||||
if (c == 27) {
|
if (c == ESC) {
|
||||||
timeout(0);
|
timeout(0);
|
||||||
c = getch();
|
c = getch();
|
||||||
if (c != ERR) {
|
if (c != ERR) {
|
||||||
if (c == 27)
|
if (c == ESC)
|
||||||
c = CONTROL('L');
|
c = CONTROL('L');
|
||||||
else {
|
else {
|
||||||
ungetch(c);
|
ungetch(c);
|
||||||
c = ';';
|
c = ';';
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
c = 27;
|
c = ESC;
|
||||||
settimeout();
|
settimeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2775,7 +2773,7 @@ static int filterentries(char *path, char *lastname)
|
||||||
case KEY_DC: // fallthrough
|
case KEY_DC: // fallthrough
|
||||||
case KEY_BACKSPACE: // fallthrough
|
case KEY_BACKSPACE: // fallthrough
|
||||||
case '\b': // fallthrough
|
case '\b': // fallthrough
|
||||||
case 127: /* handle DEL */
|
case DEL: /* handle DEL */
|
||||||
if (len != 1) {
|
if (len != 1) {
|
||||||
wln[--len] = '\0';
|
wln[--len] = '\0';
|
||||||
wcstombs(ln, wln, REGEX_MAX);
|
wcstombs(ln, wln, REGEX_MAX);
|
||||||
|
@ -2809,9 +2807,9 @@ static int filterentries(char *path, char *lastname)
|
||||||
case KEY_MOUSE:
|
case KEY_MOUSE:
|
||||||
goto end;
|
goto end;
|
||||||
#endif
|
#endif
|
||||||
case 27: /* Exit filter mode on Escape and Alt+key */
|
case ESC: /* Exit filter mode on Escape and Alt+key */
|
||||||
if (handle_alt_key(ch) != ERR) {
|
if (handle_alt_key(ch) != ERR) {
|
||||||
if (*ch == 27) { /* Handle Alt + Esc */
|
if (*ch == ESC) { /* Handle Alt + Esc */
|
||||||
if (wln[1]) {
|
if (wln[1]) {
|
||||||
ln[REGEX_MAX - 1] = ln[1];
|
ln[REGEX_MAX - 1] = ln[1];
|
||||||
ln[1] = wln[1] = '\0';
|
ln[1] = wln[1] = '\0';
|
||||||
|
@ -2987,7 +2985,7 @@ static char *xreadline(const char *prefill, const char *prompt)
|
||||||
} else
|
} else
|
||||||
continue;
|
continue;
|
||||||
// fallthrough
|
// fallthrough
|
||||||
case 127: // fallthrough
|
case DEL: // fallthrough
|
||||||
case '\b': /* rhel25 sends '\b' for backspace */
|
case '\b': /* rhel25 sends '\b' for backspace */
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
memmove(buf + pos - 1, buf + pos,
|
memmove(buf + pos - 1, buf + pos,
|
||||||
|
@ -3034,7 +3032,7 @@ static char *xreadline(const char *prefill, const char *prompt)
|
||||||
len -= pos;
|
len -= pos;
|
||||||
pos = 0;
|
pos = 0;
|
||||||
continue;
|
continue;
|
||||||
case 27: /* Exit prompt on Escape, but just filter out Alt+key */
|
case ESC: /* Exit prompt on Escape, but just filter out Alt+key */
|
||||||
if (handle_alt_key(ch) != ERR)
|
if (handle_alt_key(ch) != ERR)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -3467,17 +3465,17 @@ static char *get_lsperms(mode_t mode)
|
||||||
|
|
||||||
#ifdef ICONS
|
#ifdef ICONS
|
||||||
static const struct icon_pair * get_icon(const struct entry *ent){
|
static const struct icon_pair * get_icon(const struct entry *ent){
|
||||||
ushort i, j;
|
ushort i = 0;
|
||||||
char *tmp;
|
|
||||||
|
|
||||||
for (i = 0; i < sizeof(icons_name)/sizeof(struct icon_pair); ++i)
|
for (; i < sizeof(icons_name)/sizeof(struct icon_pair); ++i)
|
||||||
if (strcasecmp(ent->name, icons_name[i].match) == 0)
|
if (strcasecmp(ent->name, icons_name[i].match) == 0)
|
||||||
return &icons_name[i];
|
return &icons_name[i];
|
||||||
|
|
||||||
if (ent->flags & DIR_OR_LINK_TO_DIR)
|
if (ent->flags & DIR_OR_LINK_TO_DIR)
|
||||||
return &dir_icon;
|
return &dir_icon;
|
||||||
|
|
||||||
tmp = xextension(ent->name, ent->nlen);
|
char *tmp = xextension(ent->name, ent->nlen);
|
||||||
|
|
||||||
if (!tmp) {
|
if (!tmp) {
|
||||||
if (ent->mode & 0100)
|
if (ent->mode & 0100)
|
||||||
return &exec_icon;
|
return &exec_icon;
|
||||||
|
@ -3489,14 +3487,14 @@ static const struct icon_pair * get_icon(const struct entry *ent){
|
||||||
++tmp;
|
++tmp;
|
||||||
|
|
||||||
if (*tmp >= '0' && *tmp <= '9')
|
if (*tmp >= '0' && *tmp <= '9')
|
||||||
i = *tmp - '0'; /* NUMBER */
|
i = *tmp - '0'; /* NUMBER 0-9 */
|
||||||
else if (TOUPPER(*tmp) >= 'A' && TOUPPER(*tmp) <= 'Z')
|
else if (TOUPPER(*tmp) >= 'A' && TOUPPER(*tmp) <= 'Z')
|
||||||
i = TOUPPER(*tmp) - 'A' + 10; /* LETTER A-Z */
|
i = TOUPPER(*tmp) - 'A' + 10; /* LETTER A-Z */
|
||||||
else
|
else
|
||||||
i = 36; /* OTHER */
|
i = 36; /* OTHER */
|
||||||
|
|
||||||
for (j = icon_positions[i]; j < sizeof(icons_ext)/sizeof(struct icon_pair) &&
|
for (ushort j = icon_positions[i]; j < sizeof(icons_ext)/sizeof(struct icon_pair) &&
|
||||||
icons_ext[j].match[0] == icons_ext[icon_positions[i]].match[0]; ++j)
|
icons_ext[j].match[0] == icons_ext[icon_positions[i]].match[0]; ++j)
|
||||||
if (strcasecmp(tmp, icons_ext[j].match) == 0)
|
if (strcasecmp(tmp, icons_ext[j].match) == 0)
|
||||||
return &icons_ext[j];
|
return &icons_ext[j];
|
||||||
|
|
||||||
|
@ -6268,7 +6266,7 @@ nochange:
|
||||||
#endif
|
#endif
|
||||||
presel = filterentries(path, lastname);
|
presel = filterentries(path, lastname);
|
||||||
|
|
||||||
if (presel == 27) {
|
if (presel == ESC) {
|
||||||
presel = 0;
|
presel = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
10
src/nnn.h
10
src/nnn.h
|
@ -34,6 +34,14 @@
|
||||||
|
|
||||||
#define CONTROL(c) ((c) & 0x1f)
|
#define CONTROL(c) ((c) & 0x1f)
|
||||||
|
|
||||||
|
#ifndef ESC
|
||||||
|
#define ESC (27)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef DEL
|
||||||
|
#define DEL (127)
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Supported actions */
|
/* Supported actions */
|
||||||
enum action {
|
enum action {
|
||||||
SEL_BACK = 1,
|
SEL_BACK = 1,
|
||||||
|
@ -268,7 +276,7 @@ static struct key bindings[] = {
|
||||||
{ 'Q', SEL_QUITFAIL },
|
{ 'Q', SEL_QUITFAIL },
|
||||||
#ifndef NOFIFO
|
#ifndef NOFIFO
|
||||||
/* Send hovered path to NNN_FIFO */
|
/* Send hovered path to NNN_FIFO */
|
||||||
{ 27, SEL_FIFO },
|
{ ESC, SEL_FIFO },
|
||||||
#endif
|
#endif
|
||||||
#ifndef NOMOUSE
|
#ifndef NOMOUSE
|
||||||
{ KEY_MOUSE, SEL_CLICK },
|
{ KEY_MOUSE, SEL_CLICK },
|
||||||
|
|
Loading…
Reference in a new issue