mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 11:51: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
|
||||
|
||||
#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)))
|
||||
#undef MIN
|
||||
#define MIN(x, y) ((x) < (y) ? (x) : (y))
|
||||
|
@ -182,6 +180,10 @@
|
|||
#define LIST_FILES_MAX (1 << 16)
|
||||
#define SCROLLOFF 3
|
||||
|
||||
/* Time intervals */
|
||||
#define DBLCLK_INTERVAL_NS (400000000)
|
||||
#define XDELAY_INTERVAL_MS (350000) /* 350 ms delay */
|
||||
|
||||
#ifndef CTX8
|
||||
#define CTX_MAX 4
|
||||
#else
|
||||
|
@ -194,7 +196,7 @@
|
|||
#define SED "sed"
|
||||
#endif
|
||||
|
||||
#define MIN_DISPLAY_COLS (CTX_MAX * 2)
|
||||
#define MIN_DISPLAY_COL (CTX_MAX * 2)
|
||||
#define ARCHIVE_CMD_LEN 16
|
||||
#define BLK_SHIFT_512 9
|
||||
|
||||
|
@ -203,7 +205,7 @@
|
|||
#define HASH_OCTETS (HASH_BITS >> 6) /* 2^6 = 64 */
|
||||
|
||||
/* Entry flags */
|
||||
#define DIR_OR_LINK_TO_DIR 0x01
|
||||
#define DIR_OR_DIRLNK 0x01
|
||||
#define HARD_LINK 0x02
|
||||
#define SYM_ORPHAN 0x04
|
||||
#define FILE_MISSING 0x08
|
||||
|
@ -219,7 +221,7 @@
|
|||
#define F_CHKRTN 0x20 /* wait for user prompt if cmd returns failure status */
|
||||
#define F_NOSTDIN 0x40 /* suppress stdin */
|
||||
#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_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, STDERR_FILENO);
|
||||
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 (!isatty(STDOUT_FILENO)) {
|
||||
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 *pb = (pEntry)vb;
|
||||
|
||||
if ((pb->flags & DIR_OR_LINK_TO_DIR) != (pa->flags & DIR_OR_LINK_TO_DIR)) {
|
||||
if (pb->flags & DIR_OR_LINK_TO_DIR)
|
||||
if ((pb->flags & DIR_OR_DIRLNK) != (pa->flags & DIR_OR_DIRLNK)) {
|
||||
if (pb->flags & DIR_OR_DIRLNK)
|
||||
return 1;
|
||||
return -1;
|
||||
}
|
||||
|
@ -2667,7 +2669,7 @@ static int entrycmp(const void *va, const void *vb)
|
|||
return 1;
|
||||
if (pb->blocks < pa->blocks)
|
||||
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 *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)
|
||||
{
|
||||
if ((((pEntry)vb)->flags & DIR_OR_LINK_TO_DIR)
|
||||
!= (((pEntry)va)->flags & DIR_OR_LINK_TO_DIR)) {
|
||||
if (((pEntry)vb)->flags & DIR_OR_LINK_TO_DIR)
|
||||
if ((((pEntry)vb)->flags & DIR_OR_DIRLNK)
|
||||
!= (((pEntry)va)->flags & DIR_OR_DIRLNK)) {
|
||||
if (((pEntry)vb)->flags & DIR_OR_DIRLNK)
|
||||
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 (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;
|
||||
cur = 0;
|
||||
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)
|
||||
{
|
||||
/* 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);
|
||||
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)
|
||||
return &icons_name[i];
|
||||
|
||||
if (ent->flags & DIR_OR_LINK_TO_DIR)
|
||||
if (ent->flags & DIR_OR_DIRLNK)
|
||||
return &dir_icon;
|
||||
|
||||
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;
|
||||
return g_state.dirctx ? cfg.curctx + 1 : C_DIR;
|
||||
case S_IFLNK:
|
||||
if (ent->flags & DIR_OR_LINK_TO_DIR) {
|
||||
if (ent->flags & DIR_OR_DIRLNK) {
|
||||
*pind = '/';
|
||||
*pattr |= g_state.oldcolor ? A_DIM : A_BOLD;
|
||||
} else {
|
||||
|
@ -4155,7 +4157,7 @@ static bool get_output(char *file, char *arg1, char *arg2, int fdout, bool multi
|
|||
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)
|
||||
unlink(g_tmpfpath);
|
||||
|
@ -4186,7 +4188,7 @@ static bool show_stats(char *fpath)
|
|||
|
||||
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);
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -4728,7 +4730,7 @@ static void show_help(const char *path)
|
|||
dprintf(fd, "\nv%s\n%s\n", VERSION, GENERAL_INFO);
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -5358,11 +5360,11 @@ static int dentfill(char *path, struct entry **ppdents)
|
|||
}
|
||||
|
||||
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 */
|
||||
} else if (dp->d_type == DT_DIR || ((dp->d_type == DT_LNK
|
||||
|| dp->d_type == DT_UNKNOWN) && S_ISDIR(sb.st_mode))) {
|
||||
dentp->flags |= DIR_OR_LINK_TO_DIR;
|
||||
dentp->flags |= DIR_OR_DIRLNK;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -5535,7 +5537,7 @@ static void handle_screen_move(enum action sel)
|
|||
int r = (c == TOUPPER(*pdents[cur].name)) ? (cur + 1) : 0;
|
||||
|
||||
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))) {
|
||||
move_cursor((r) % ndents, 0);
|
||||
break;
|
||||
|
@ -5901,7 +5903,7 @@ static void draw_line(char *path, int 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);
|
||||
dir = TRUE;
|
||||
}
|
||||
|
@ -5909,7 +5911,7 @@ static void draw_line(char *path, int ncols)
|
|||
move(2 + last - curscroll, 0);
|
||||
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 */
|
||||
attron(COLOR_PAIR(cfg.curctx + 1) | A_BOLD);
|
||||
dir = TRUE;
|
||||
|
@ -5956,7 +5958,7 @@ static void redraw(char *path)
|
|||
move_cursor(cur, 1);
|
||||
|
||||
/* 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]);
|
||||
return;
|
||||
}
|
||||
|
@ -5982,8 +5984,8 @@ static void redraw(char *path)
|
|||
char *ptr = in_home ? &path[homelen - 1] : path;
|
||||
|
||||
i = (int)xstrlen(ptr);
|
||||
if ((i + MIN_DISPLAY_COLS) <= ncols)
|
||||
addnstr(ptr, ncols - MIN_DISPLAY_COLS);
|
||||
if ((i + MIN_DISPLAY_COL) <= ncols)
|
||||
addnstr(ptr, ncols - MIN_DISPLAY_COL);
|
||||
else {
|
||||
char *base = xmemrchr((uchar_t *)ptr, '/', i);
|
||||
|
||||
|
@ -5998,7 +6000,7 @@ static void redraw(char *path)
|
|||
while (ptr < base) {
|
||||
if (*ptr == '/') {
|
||||
i += 2; /* 2 characters added */
|
||||
if (ncols < i + MIN_DISPLAY_COLS) {
|
||||
if (ncols < i + MIN_DISPLAY_COL) {
|
||||
base = NULL; /* Can't print more characters */
|
||||
break;
|
||||
}
|
||||
|
@ -6011,7 +6013,7 @@ static void redraw(char *path)
|
|||
}
|
||||
|
||||
if (base)
|
||||
addnstr(base, ncols - (MIN_DISPLAY_COLS + i));
|
||||
addnstr(base, ncols - (MIN_DISPLAY_COL + i));
|
||||
}
|
||||
|
||||
if (in_home)
|
||||
|
@ -6371,7 +6373,7 @@ nochange:
|
|||
if ((mousedent[0] != mousedent[1]) ||
|
||||
(((_ABSSUB(mousetimings[0].tv_sec, mousetimings[1].tv_sec) << 30)
|
||||
+ (_ABSSUB(mousetimings[0].tv_nsec, mousetimings[1].tv_nsec)))
|
||||
> DOUBLECLICK_INTERVAL_NS))
|
||||
> DBLCLK_INTERVAL_NS))
|
||||
break;
|
||||
mousetimings[currentmouse].tv_sec = 0;
|
||||
mousedent[currentmouse] = -1;
|
||||
|
@ -6395,7 +6397,7 @@ nochange:
|
|||
DPRINTF_S(newpath);
|
||||
|
||||
/* Visit directory */
|
||||
if (pent->flags & DIR_OR_LINK_TO_DIR) {
|
||||
if (pent->flags & DIR_OR_DIRLNK) {
|
||||
if (chdir(newpath) == -1) {
|
||||
printwarn(&presel);
|
||||
goto nochange;
|
||||
|
|
Loading…
Reference in a new issue