aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nnn.c66
1 files changed, 43 insertions, 23 deletions
diff --git a/src/nnn.c b/src/nnn.c
index 881b349..5f06843 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -133,7 +133,7 @@
#define DOT_FILTER_LEN 7
#define ASCII_MAX 128
#define EXEC_ARGS_MAX 8
-#define SCROLLOFF 5
+#define SCROLLOFF 3
#define LONG_SIZE sizeof(ulong)
/* Program return codes */
@@ -145,14 +145,13 @@
#define FILE_COPIED 0x10
/* Macros to define process spawn behaviour as flags */
-#define F_NONE 0x00 /* no flag set */
-#define F_MULTI 0x01 /* first arg can be combination of args; to be used with F_NORMAL */
-#define F_NOWAIT 0x02 /* don't wait for child process (e.g. file manager) */
-#define F_NOTRACE 0x04 /* suppress stdout and strerr (no traces) */
-#define F_NORMAL 0x08 /* spawn child process in non-curses regular CLI mode */
-#define F_CMD 0x10 /* run command - show results before exit (must have F_NORMAL) */
-
-#define F_CLI (F_NORMAL | F_MULTI)
+#define F_NONE 0x00 /* no flag set */
+#define F_MULTI 0x01 /* first arg can be combination of args; to be used with F_NORMAL */
+#define F_NOWAIT 0x02 /* don't wait for child process (e.g. file manager) */
+#define F_NOTRACE 0x04 /* suppress stdout and strerr (no traces) */
+#define F_NORMAL 0x08 /* spawn child process in non-curses regular CLI mode */
+#define F_CMD 0x10 /* run command - show results before exit (must have F_NORMAL) */
+#define F_CLI (F_NORMAL | F_MULTI)
/* CRC8 macros */
#define UCHAR_BIT_WIDTH (sizeof(unsigned char) << 3)
@@ -165,14 +164,14 @@
* states: S_N: normal, S_I: comparing integral part, S_F: comparing
* fractional parts, S_Z: idem but with leading Zeroes only
*/
-#define S_N 0x0
-#define S_I 0x3
-#define S_F 0x6
-#define S_Z 0x9
+#define S_N 0x0
+#define S_I 0x3
+#define S_F 0x6
+#define S_Z 0x9
/* result_type: VCMP: return diff; VLEN: compare using len_diff/diff */
-#define VCMP 2
-#define VLEN 3
+#define VCMP 2
+#define VLEN 3
/* Volume info */
#define FREE 0
@@ -666,7 +665,6 @@ static size_t xstrlcpy(char *dest, const char *src, size_t n)
size_t len = strlen(src) + 1, blocks;
const uint _WSHIFT = (LONG_SIZE == 8) ? 3 : 2;
-
if (n > len)
n = len;
else if (len > n)
@@ -893,6 +891,7 @@ static bool initcurses(void)
//intrflush(stdscr, FALSE);
keypad(stdscr, TRUE);
mousemask(BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED | BUTTON2_CLICKED, NULL);
+ mouseinterval(400);
curs_set(FALSE); /* Hide cursor */
start_color();
use_default_colors();
@@ -2133,6 +2132,7 @@ static char *coolsize(off_t size)
const char * const U = "BKMGTPEZY";
static char size_buf[12]; /* Buffer to hold human readable size */
off_t rem = 0;
+ size_t ret;
int i = 0;
while (size >= 1024) {
@@ -2177,10 +2177,28 @@ static char *coolsize(off_t size)
rem /= 10;
}
- if (i > 0 && i < 6)
- snprintf(size_buf, 12, "%u.%0*u%c", (uint)size, i & 0b11, (uint)rem, U[i]);
- else
- snprintf(size_buf, 12, "%u%c", (uint)size, U[i]);
+ if (i > 0 && i < 6 && rem) {
+ ret = xstrlcpy(size_buf, xitoa(size), 11);
+ size_buf[ret - 1] = '.';
+
+ char *frac = xitoa(rem);
+ size_t toprint = i > 3 ? 3 : i;
+ size_t len = strlen(frac);
+
+ if (len < toprint) {
+ size_buf[ret] = size_buf[ret + 1] = size_buf[ret + 2] = '0';
+ xstrlcpy(size_buf + ret + (toprint - len), frac, (toprint - len) + 1);
+ } else
+ xstrlcpy(size_buf + ret, frac, toprint + 1);
+
+ ret += toprint;
+ } else {
+ ret = xstrlcpy(size_buf, size ? xitoa(size) : "0", 10);
+ --ret;
+ }
+
+ size_buf[ret] = U[i];
+ size_buf[ret + 1] = '\0';
return size_buf;
}
@@ -2401,7 +2419,9 @@ static char *get_output(char *buf, const size_t bytes, const char *file,
static bool getutil(const char *util)
{
- if (!get_output(g_buf, CMD_LEN_MAX, "which", util, NULL, FALSE))
+ char buf[8];
+
+ if (!get_output(buf, 8, "which", util, NULL, FALSE))
return FALSE;
return TRUE;
@@ -2421,9 +2441,9 @@ static bool show_stats(const char *fpath, const char *fname, const struct stat *
if (fd == -1)
return FALSE;
- r = xstrlcpy(g_buf, "stat \'", PATH_MAX);
+ r = xstrlcpy(g_buf, "stat \"", PATH_MAX);
r += xstrlcpy(g_buf + r - 1, fpath, PATH_MAX);
- g_buf[r - 2] = '\'';
+ g_buf[r - 2] = '\"';
g_buf[r - 1] = '\0';
DPRINTF_S(g_buf);