mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 20:01:27 +00:00
Improve alignment
This commit is contained in:
parent
c597f3be9b
commit
983babc5f6
64
src/nnn.c
64
src/nnn.c
|
@ -152,8 +152,6 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define _ABSSUB(N, M) (((N) <= (M)) ? ((M) - (N)) : ((N) - (M)))
|
#define _ABSSUB(N, M) (((N) <= (M)) ? ((M) - (N)) : ((N) - (M)))
|
||||||
#define DOUBLECLICK_INTERVAL_NS (400000000)
|
|
||||||
#define XDELAY_INTERVAL_MS (350000) /* 350 ms delay */
|
|
||||||
#define ELEMENTS(x) (sizeof(x) / sizeof(*(x)))
|
#define ELEMENTS(x) (sizeof(x) / sizeof(*(x)))
|
||||||
#undef MIN
|
#undef MIN
|
||||||
#define MIN(x, y) ((x) < (y) ? (x) : (y))
|
#define MIN(x, y) ((x) < (y) ? (x) : (y))
|
||||||
|
@ -182,6 +180,10 @@
|
||||||
#define LIST_FILES_MAX (1 << 16)
|
#define LIST_FILES_MAX (1 << 16)
|
||||||
#define SCROLLOFF 3
|
#define SCROLLOFF 3
|
||||||
|
|
||||||
|
/* Time intervals */
|
||||||
|
#define DBLCLK_INTERVAL_NS (400000000)
|
||||||
|
#define XDELAY_INTERVAL_MS (350000) /* 350 ms delay */
|
||||||
|
|
||||||
#ifndef CTX8
|
#ifndef CTX8
|
||||||
#define CTX_MAX 4
|
#define CTX_MAX 4
|
||||||
#else
|
#else
|
||||||
|
@ -194,7 +196,7 @@
|
||||||
#define SED "sed"
|
#define SED "sed"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MIN_DISPLAY_COLS (CTX_MAX * 2)
|
#define MIN_DISPLAY_COL (CTX_MAX * 2)
|
||||||
#define ARCHIVE_CMD_LEN 16
|
#define ARCHIVE_CMD_LEN 16
|
||||||
#define BLK_SHIFT_512 9
|
#define BLK_SHIFT_512 9
|
||||||
|
|
||||||
|
@ -203,7 +205,7 @@
|
||||||
#define HASH_OCTETS (HASH_BITS >> 6) /* 2^6 = 64 */
|
#define HASH_OCTETS (HASH_BITS >> 6) /* 2^6 = 64 */
|
||||||
|
|
||||||
/* Entry flags */
|
/* Entry flags */
|
||||||
#define DIR_OR_LINK_TO_DIR 0x01
|
#define DIR_OR_DIRLNK 0x01
|
||||||
#define HARD_LINK 0x02
|
#define HARD_LINK 0x02
|
||||||
#define SYM_ORPHAN 0x04
|
#define SYM_ORPHAN 0x04
|
||||||
#define FILE_MISSING 0x08
|
#define FILE_MISSING 0x08
|
||||||
|
@ -219,7 +221,7 @@
|
||||||
#define F_CHKRTN 0x20 /* wait for user prompt if cmd returns failure status */
|
#define F_CHKRTN 0x20 /* wait for user prompt if cmd returns failure status */
|
||||||
#define F_NOSTDIN 0x40 /* suppress stdin */
|
#define F_NOSTDIN 0x40 /* suppress stdin */
|
||||||
#define F_PAGE 0x80 /* page output in run-cmd-as-plugin mode */
|
#define F_PAGE 0x80 /* page output in run-cmd-as-plugin mode */
|
||||||
#define F_FORCE_TTY 0x100 /* Force stdout to go to tty if redirected to a non-tty */
|
#define F_TTY 0x100 /* Force stdout to go to tty if redirected to a non-tty */
|
||||||
#define F_CLI (F_NORMAL | F_MULTI)
|
#define F_CLI (F_NORMAL | F_MULTI)
|
||||||
#define F_SILENT (F_CLI | F_NOTRACE)
|
#define F_SILENT (F_CLI | F_NOTRACE)
|
||||||
|
|
||||||
|
@ -2108,7 +2110,7 @@ static int spawn(char *file, char *arg1, char *arg2, char *arg3, ushort_t flag)
|
||||||
dup2(fd, STDOUT_FILENO);
|
dup2(fd, STDOUT_FILENO);
|
||||||
dup2(fd, STDERR_FILENO);
|
dup2(fd, STDERR_FILENO);
|
||||||
close(fd);
|
close(fd);
|
||||||
} else if (flag & F_FORCE_TTY) {
|
} else if (flag & F_TTY) {
|
||||||
/* If stdout has been redirected to a non-tty, force output to tty */
|
/* If stdout has been redirected to a non-tty, force output to tty */
|
||||||
if (!isatty(STDOUT_FILENO)) {
|
if (!isatty(STDOUT_FILENO)) {
|
||||||
int fd = open(ctermid(NULL), O_WRONLY, 0200);
|
int fd = open(ctermid(NULL), O_WRONLY, 0200);
|
||||||
|
@ -2640,8 +2642,8 @@ static int entrycmp(const void *va, const void *vb)
|
||||||
const struct entry *pa = (pEntry)va;
|
const struct entry *pa = (pEntry)va;
|
||||||
const struct entry *pb = (pEntry)vb;
|
const struct entry *pb = (pEntry)vb;
|
||||||
|
|
||||||
if ((pb->flags & DIR_OR_LINK_TO_DIR) != (pa->flags & DIR_OR_LINK_TO_DIR)) {
|
if ((pb->flags & DIR_OR_DIRLNK) != (pa->flags & DIR_OR_DIRLNK)) {
|
||||||
if (pb->flags & DIR_OR_LINK_TO_DIR)
|
if (pb->flags & DIR_OR_DIRLNK)
|
||||||
return 1;
|
return 1;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -2667,7 +2669,7 @@ static int entrycmp(const void *va, const void *vb)
|
||||||
return 1;
|
return 1;
|
||||||
if (pb->blocks < pa->blocks)
|
if (pb->blocks < pa->blocks)
|
||||||
return -1;
|
return -1;
|
||||||
} else if (cfg.extnorder && !(pb->flags & DIR_OR_LINK_TO_DIR)) {
|
} else if (cfg.extnorder && !(pb->flags & DIR_OR_DIRLNK)) {
|
||||||
char *extna = xextension(pa->name, pa->nlen - 1);
|
char *extna = xextension(pa->name, pa->nlen - 1);
|
||||||
char *extnb = xextension(pb->name, pb->nlen - 1);
|
char *extnb = xextension(pb->name, pb->nlen - 1);
|
||||||
|
|
||||||
|
@ -2690,9 +2692,9 @@ static int entrycmp(const void *va, const void *vb)
|
||||||
|
|
||||||
static int reventrycmp(const void *va, const void *vb)
|
static int reventrycmp(const void *va, const void *vb)
|
||||||
{
|
{
|
||||||
if ((((pEntry)vb)->flags & DIR_OR_LINK_TO_DIR)
|
if ((((pEntry)vb)->flags & DIR_OR_DIRLNK)
|
||||||
!= (((pEntry)va)->flags & DIR_OR_LINK_TO_DIR)) {
|
!= (((pEntry)va)->flags & DIR_OR_DIRLNK)) {
|
||||||
if (((pEntry)vb)->flags & DIR_OR_LINK_TO_DIR)
|
if (((pEntry)vb)->flags & DIR_OR_DIRLNK)
|
||||||
return 1;
|
return 1;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -3127,7 +3129,7 @@ static int filterentries(char *path, char *lastname)
|
||||||
|
|
||||||
/* If the only match is a dir, auto-select and cd into it */
|
/* If the only match is a dir, auto-select and cd into it */
|
||||||
if (ndents == 1 && cfg.filtermode
|
if (ndents == 1 && cfg.filtermode
|
||||||
&& cfg.autoselect && (pdents[0].flags & DIR_OR_LINK_TO_DIR)) {
|
&& cfg.autoselect && (pdents[0].flags & DIR_OR_DIRLNK)) {
|
||||||
*ch = KEY_ENTER;
|
*ch = KEY_ENTER;
|
||||||
cur = 0;
|
cur = 0;
|
||||||
goto end;
|
goto end;
|
||||||
|
@ -3508,7 +3510,7 @@ static char *get_kv_val(kv *kvarr, char *buf, int key, uchar_t max, uchar_t id)
|
||||||
static void resetdircolor(int flags)
|
static void resetdircolor(int flags)
|
||||||
{
|
{
|
||||||
/* Directories are always shown on top, clear the color when moving to first file */
|
/* Directories are always shown on top, clear the color when moving to first file */
|
||||||
if (g_state.dircolor && !(flags & DIR_OR_LINK_TO_DIR)) {
|
if (g_state.dircolor && !(flags & DIR_OR_DIRLNK)) {
|
||||||
attroff(COLOR_PAIR(cfg.curctx + 1) | A_BOLD);
|
attroff(COLOR_PAIR(cfg.curctx + 1) | A_BOLD);
|
||||||
g_state.dircolor = 0;
|
g_state.dircolor = 0;
|
||||||
}
|
}
|
||||||
|
@ -3681,7 +3683,7 @@ static const struct icon_pair *get_icon(const struct entry *ent)
|
||||||
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_DIRLNK)
|
||||||
return &dir_icon;
|
return &dir_icon;
|
||||||
|
|
||||||
char *tmp = xextension(ent->name, ent->nlen);
|
char *tmp = xextension(ent->name, ent->nlen);
|
||||||
|
@ -3783,7 +3785,7 @@ static uchar_t get_color_pair_name_ind(const struct entry *ent, char *pind, int
|
||||||
*pattr |= A_BOLD;
|
*pattr |= A_BOLD;
|
||||||
return g_state.dirctx ? cfg.curctx + 1 : C_DIR;
|
return g_state.dirctx ? cfg.curctx + 1 : C_DIR;
|
||||||
case S_IFLNK:
|
case S_IFLNK:
|
||||||
if (ent->flags & DIR_OR_LINK_TO_DIR) {
|
if (ent->flags & DIR_OR_DIRLNK) {
|
||||||
*pind = '/';
|
*pind = '/';
|
||||||
*pattr |= g_state.oldcolor ? A_DIM : A_BOLD;
|
*pattr |= g_state.oldcolor ? A_DIM : A_BOLD;
|
||||||
} else {
|
} else {
|
||||||
|
@ -4155,7 +4157,7 @@ static bool get_output(char *file, char *arg1, char *arg2, int fdout, bool multi
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
spawn(pager, g_tmpfpath, NULL, NULL, F_CLI | F_FORCE_TTY);
|
spawn(pager, g_tmpfpath, NULL, NULL, F_CLI | F_TTY);
|
||||||
|
|
||||||
if (tmpfile)
|
if (tmpfile)
|
||||||
unlink(g_tmpfpath);
|
unlink(g_tmpfpath);
|
||||||
|
@ -4186,7 +4188,7 @@ static bool show_stats(char *fpath)
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
spawn(pager, g_tmpfpath, NULL, NULL, F_CLI | F_FORCE_TTY);
|
spawn(pager, g_tmpfpath, NULL, NULL, F_CLI | F_TTY);
|
||||||
unlink(g_tmpfpath);
|
unlink(g_tmpfpath);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -4728,7 +4730,7 @@ static void show_help(const char *path)
|
||||||
dprintf(fd, "\nv%s\n%s\n", VERSION, GENERAL_INFO);
|
dprintf(fd, "\nv%s\n%s\n", VERSION, GENERAL_INFO);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
spawn(pager, g_tmpfpath, NULL, NULL, F_CLI | F_FORCE_TTY);
|
spawn(pager, g_tmpfpath, NULL, NULL, F_CLI | F_TTY);
|
||||||
unlink(g_tmpfpath);
|
unlink(g_tmpfpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5358,11 +5360,11 @@ static int dentfill(char *path, struct entry **ppdents)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (S_ISDIR(sb.st_mode))
|
if (S_ISDIR(sb.st_mode))
|
||||||
dentp->flags |= DIR_OR_LINK_TO_DIR;
|
dentp->flags |= DIR_OR_DIRLNK;
|
||||||
#if !(defined(__sun) || defined(__HAIKU__)) /* no d_type */
|
#if !(defined(__sun) || defined(__HAIKU__)) /* no d_type */
|
||||||
} else if (dp->d_type == DT_DIR || ((dp->d_type == DT_LNK
|
} else if (dp->d_type == DT_DIR || ((dp->d_type == DT_LNK
|
||||||
|| dp->d_type == DT_UNKNOWN) && S_ISDIR(sb.st_mode))) {
|
|| dp->d_type == DT_UNKNOWN) && S_ISDIR(sb.st_mode))) {
|
||||||
dentp->flags |= DIR_OR_LINK_TO_DIR;
|
dentp->flags |= DIR_OR_DIRLNK;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5535,7 +5537,7 @@ static void handle_screen_move(enum action sel)
|
||||||
int r = (c == TOUPPER(*pdents[cur].name)) ? (cur + 1) : 0;
|
int r = (c == TOUPPER(*pdents[cur].name)) ? (cur + 1) : 0;
|
||||||
|
|
||||||
for (; r < ndents; ++r) {
|
for (; r < ndents; ++r) {
|
||||||
if (((c == '\'') && !(pdents[r].flags & DIR_OR_LINK_TO_DIR))
|
if (((c == '\'') && !(pdents[r].flags & DIR_OR_DIRLNK))
|
||||||
|| (c == TOUPPER(*pdents[r].name))) {
|
|| (c == TOUPPER(*pdents[r].name))) {
|
||||||
move_cursor((r) % ndents, 0);
|
move_cursor((r) % ndents, 0);
|
||||||
break;
|
break;
|
||||||
|
@ -5901,7 +5903,7 @@ static void draw_line(char *path, int ncols)
|
||||||
|
|
||||||
ncols = adjust_cols(ncols);
|
ncols = adjust_cols(ncols);
|
||||||
|
|
||||||
if (g_state.oldcolor && (pdents[last].flags & DIR_OR_LINK_TO_DIR)) {
|
if (g_state.oldcolor && (pdents[last].flags & DIR_OR_DIRLNK)) {
|
||||||
attron(COLOR_PAIR(cfg.curctx + 1) | A_BOLD);
|
attron(COLOR_PAIR(cfg.curctx + 1) | A_BOLD);
|
||||||
dir = TRUE;
|
dir = TRUE;
|
||||||
}
|
}
|
||||||
|
@ -5909,7 +5911,7 @@ static void draw_line(char *path, int ncols)
|
||||||
move(2 + last - curscroll, 0);
|
move(2 + last - curscroll, 0);
|
||||||
printent(&pdents[last], ncols, FALSE);
|
printent(&pdents[last], ncols, FALSE);
|
||||||
|
|
||||||
if (g_state.oldcolor && (pdents[cur].flags & DIR_OR_LINK_TO_DIR)) {
|
if (g_state.oldcolor && (pdents[cur].flags & DIR_OR_DIRLNK)) {
|
||||||
if (!dir) {/* First file is not a directory */
|
if (!dir) {/* First file is not a directory */
|
||||||
attron(COLOR_PAIR(cfg.curctx + 1) | A_BOLD);
|
attron(COLOR_PAIR(cfg.curctx + 1) | A_BOLD);
|
||||||
dir = TRUE;
|
dir = TRUE;
|
||||||
|
@ -5956,7 +5958,7 @@ static void redraw(char *path)
|
||||||
move_cursor(cur, 1);
|
move_cursor(cur, 1);
|
||||||
|
|
||||||
/* Fail redraw if < than 10 columns, context info prints 10 chars */
|
/* Fail redraw if < than 10 columns, context info prints 10 chars */
|
||||||
if (ncols <= MIN_DISPLAY_COLS) {
|
if (ncols <= MIN_DISPLAY_COL) {
|
||||||
printmsg(messages[MSG_FEW_COLUMNS]);
|
printmsg(messages[MSG_FEW_COLUMNS]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -5982,8 +5984,8 @@ static void redraw(char *path)
|
||||||
char *ptr = in_home ? &path[homelen - 1] : path;
|
char *ptr = in_home ? &path[homelen - 1] : path;
|
||||||
|
|
||||||
i = (int)xstrlen(ptr);
|
i = (int)xstrlen(ptr);
|
||||||
if ((i + MIN_DISPLAY_COLS) <= ncols)
|
if ((i + MIN_DISPLAY_COL) <= ncols)
|
||||||
addnstr(ptr, ncols - MIN_DISPLAY_COLS);
|
addnstr(ptr, ncols - MIN_DISPLAY_COL);
|
||||||
else {
|
else {
|
||||||
char *base = xmemrchr((uchar_t *)ptr, '/', i);
|
char *base = xmemrchr((uchar_t *)ptr, '/', i);
|
||||||
|
|
||||||
|
@ -5998,7 +6000,7 @@ static void redraw(char *path)
|
||||||
while (ptr < base) {
|
while (ptr < base) {
|
||||||
if (*ptr == '/') {
|
if (*ptr == '/') {
|
||||||
i += 2; /* 2 characters added */
|
i += 2; /* 2 characters added */
|
||||||
if (ncols < i + MIN_DISPLAY_COLS) {
|
if (ncols < i + MIN_DISPLAY_COL) {
|
||||||
base = NULL; /* Can't print more characters */
|
base = NULL; /* Can't print more characters */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -6011,7 +6013,7 @@ static void redraw(char *path)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (base)
|
if (base)
|
||||||
addnstr(base, ncols - (MIN_DISPLAY_COLS + i));
|
addnstr(base, ncols - (MIN_DISPLAY_COL + i));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_home)
|
if (in_home)
|
||||||
|
@ -6371,7 +6373,7 @@ nochange:
|
||||||
if ((mousedent[0] != mousedent[1]) ||
|
if ((mousedent[0] != mousedent[1]) ||
|
||||||
(((_ABSSUB(mousetimings[0].tv_sec, mousetimings[1].tv_sec) << 30)
|
(((_ABSSUB(mousetimings[0].tv_sec, mousetimings[1].tv_sec) << 30)
|
||||||
+ (_ABSSUB(mousetimings[0].tv_nsec, mousetimings[1].tv_nsec)))
|
+ (_ABSSUB(mousetimings[0].tv_nsec, mousetimings[1].tv_nsec)))
|
||||||
> DOUBLECLICK_INTERVAL_NS))
|
> DBLCLK_INTERVAL_NS))
|
||||||
break;
|
break;
|
||||||
mousetimings[currentmouse].tv_sec = 0;
|
mousetimings[currentmouse].tv_sec = 0;
|
||||||
mousedent[currentmouse] = -1;
|
mousedent[currentmouse] = -1;
|
||||||
|
@ -6395,7 +6397,7 @@ nochange:
|
||||||
DPRINTF_S(newpath);
|
DPRINTF_S(newpath);
|
||||||
|
|
||||||
/* Visit directory */
|
/* Visit directory */
|
||||||
if (pent->flags & DIR_OR_LINK_TO_DIR) {
|
if (pent->flags & DIR_OR_DIRLNK) {
|
||||||
if (chdir(newpath) == -1) {
|
if (chdir(newpath) == -1) {
|
||||||
printwarn(&presel);
|
printwarn(&presel);
|
||||||
goto nochange;
|
goto nochange;
|
||||||
|
|
Loading…
Reference in a new issue