commit 55cbc79887669f1e1c4d97d8e979baa8f6ae60a7
parent 1da9c9fc6f98f51bc959138dab2e5a4b468b668b
Author: Arun Prakash Jana <engineerarun@gmail.com>
Date: Mon, 6 Apr 2026 17:51:06 +0530
Fix #2124
Diffstat:
1 file changed, 45 insertions(+), 46 deletions(-)
diff --git a/patches/namefirst/mainline.diff b/patches/namefirst/mainline.diff
@@ -1,52 +1,52 @@
-# Description: Prints filenames first in the detail view. Prints user/group
+]633;E;head -4 patches/namefirst/mainline.diff;15aca83b-a88c-4d34-bac5-a786145f3816]633;C# Description: Prints filenames first in the detail view. Prints user/group
# columns when a directory contains different users/groups.
#
# Author: Luuk van Baal
diff --git a/src/nnn.c b/src/nnn.c
-index 19ebc2cf..42a0a6b0 100644
+index ff05436e..bdfd4d0a 100644
--- a/src/nnn.c
+++ b/src/nnn.c
-@@ -430,6 +430,10 @@ typedef struct {
+@@ -432,6 +432,10 @@ typedef struct {
} session_header_t;
#endif
-
+
+static struct {
+ ushort_t maxnameln, maxsizeln, maxuidln, maxgidln, maxentln, uidln, gidln, printguid;
+} dtls;
+
/* GLOBALS */
-
+
/* Configuration, contexts */
-@@ -1175,10 +1179,13 @@ static char *getpwname(uid_t uid)
+@@ -1177,10 +1181,13 @@ static char *getpwname(uid_t uid)
static char *namecache;
-
+
if (uidcache != uid) {
+ if (dtls.maxuidln && !dtls.printguid)
+ dtls.printguid = 1;
struct passwd *pw = getpwuid(uid);
-
+
uidcache = uid;
namecache = pw ? pw->pw_name : NULL;
+ dtls.uidln = xstrlen(namecache ? namecache : xitoa(uid));
}
-
+
return namecache ? namecache : xitoa(uid);
-@@ -1190,10 +1197,13 @@ static char *getgrname(gid_t gid)
+@@ -1192,10 +1199,13 @@ static char *getgrname(gid_t gid)
static char *grpcache;
-
+
if (gidcache != gid) {
+ if (dtls.maxgidln && !dtls.printguid)
+ dtls.printguid = 1;
struct group *gr = getgrgid(gid);
-
+
gidcache = gid;
grpcache = gr ? gr->gr_name : NULL;
+ dtls.gidln = xstrlen(grpcache ? grpcache : xitoa(gid));
}
-
+
return grpcache ? grpcache : xitoa(gid);
-@@ -4346,14 +4356,13 @@ static void resetdircolor(int flags)
+@@ -4572,14 +4582,13 @@ static void resetdircolor(int flags)
* Max supported str length: NAME_MAX;
*/
#ifdef NOLC
@@ -64,28 +64,28 @@ index 19ebc2cf..42a0a6b0 100644
{
wchar_t * const wbuf = (wchar_t *)g_buf;
wchar_t *buf = wbuf;
-@@ -4378,7 +4387,7 @@ static wchar_t *unescape(const char *str, uint_t maxcols)
+@@ -4604,7 +4613,7 @@ static wchar_t *unescape(const char *str, uint_t maxcols)
++buf;
}
-
+
- return wbuf;
+ return len;
}
-
+
static off_t get_size(off_t size, off_t *pval, int comp)
-@@ -4627,9 +4636,10 @@ static uchar_t get_color_pair_name_ind(const struct entry *ent, char *pind, int
+@@ -4853,9 +4862,10 @@ static uchar_t get_color_pair_name_ind(const struct entry *ent, char *pind, int
}
-
+
#ifdef DIM_FILTERED
-static void printent_name(const struct entry *ent, uint_t namecols)
+static size_t printent_name(const struct entry *ent, uint_t namecols)
{
char * const fltr = g_ctx[cfg.curctx].c_fltr;
+ size_t namelen;
-
+
/* If there's a filter string, dim matching characters */
if (fltr[1]) {
-@@ -4644,15 +4654,18 @@ static void printent_name(const struct entry *ent, uint_t namecols)
+@@ -4866,15 +4876,18 @@ static void printent_name(const struct entry *ent, uint_t namecols)
if (cfg.regex) {
/* For regex, we don't dim - just print normally */
#ifndef NOLC
@@ -107,7 +107,7 @@ index 19ebc2cf..42a0a6b0 100644
uint_t col = 0;
for (wchar_t *p = wbuf; *p && col < namecols; ++p, ++col) {
if (matched[col]) {
-@@ -4665,7 +4678,8 @@ static void printent_name(const struct entry *ent, uint_t namecols)
+@@ -4887,7 +4900,8 @@ static void printent_name(const struct entry *ent, uint_t namecols)
}
#else
/* Non-wide character version for fuzzy dimming */
@@ -117,7 +117,7 @@ index 19ebc2cf..42a0a6b0 100644
for (uint_t i = 0; (i < namecols) && name[i]; ++i) {
if (matched[i]) {
attron(match_attrs);
-@@ -4680,7 +4694,8 @@ static void printent_name(const struct entry *ent, uint_t namecols)
+@@ -4902,7 +4916,8 @@ static void printent_name(const struct entry *ent, uint_t namecols)
/* String match - dim the substring */
string_match_positions(fltr + 1, ent->name, matched);
#ifndef NOLC
@@ -127,7 +127,7 @@ index 19ebc2cf..42a0a6b0 100644
uint_t col = 0;
for (wchar_t *p = wbuf; *p && col < namecols; ++p, ++col) {
if (matched[col]) {
-@@ -4693,7 +4708,8 @@ static void printent_name(const struct entry *ent, uint_t namecols)
+@@ -4915,7 +4930,8 @@ static void printent_name(const struct entry *ent, uint_t namecols)
}
#else
/* Non-wide character version for string dimming */
@@ -137,7 +137,7 @@ index 19ebc2cf..42a0a6b0 100644
for (uint_t i = 0; (i < namecols) && name[i]; ++i) {
if (matched[i]) {
attron(match_attrs);
-@@ -4708,22 +4724,30 @@ static void printent_name(const struct entry *ent, uint_t namecols)
+@@ -4930,21 +4946,29 @@ static void printent_name(const struct entry *ent, uint_t namecols)
} else {
/* No filter or filter not active - print normally */
#ifndef NOLC
@@ -158,7 +158,6 @@ index 19ebc2cf..42a0a6b0 100644
-static inline void printent_name(const struct entry *ent, uint_t namecols)
+static inline size_t printent_name(const struct entry *ent, uint_t namecols)
{
- (void)sel; /* Suppress unused parameter warning */
#ifndef NOLC
- addwstr(unescape(ent->name, namecols));
+ size_t namelen = unescape(ent->name, namecols);
@@ -172,8 +171,8 @@ index 19ebc2cf..42a0a6b0 100644
+ return namelen;
}
#endif
-
-@@ -4731,38 +4755,14 @@ static void printent(int pdents_index, uint_t namecols)
+
+@@ -4952,38 +4976,14 @@ static void printent(int pdents_index, uint_t namecols, bool sel)
{
const struct entry *ent = &pdents[pdents_index];
char ind = '\0';
@@ -203,24 +202,24 @@ index 19ebc2cf..42a0a6b0 100644
- }
+ int attrs = 0;
+ size_t namelen;
-
+
if (g_state.showlines) {
ptrdiff_t rel_num = pdents_index - cur;
printw(rel_num == 0 ? "%4td" : "%+4td", rel_num);
}
-
+
- attrs = 0;
-
uchar_t color_pair = get_color_pair_name_ind(ent, &ind, &attrs);
-
+
addch((ent->flags & FILE_SELECTED) ? '+' | A_REVERSE | A_BOLD : ' ');
-@@ -4786,12 +4786,44 @@ static void printent(int pdents_index, uint_t namecols)
+@@ -5007,12 +5007,44 @@ static void printent(int pdents_index, uint_t namecols, bool sel)
if (!ind)
++namecols;
-
+
- printent_name(ent, namecols);
+ namelen = printent_name(ent, namecols);
-
+
- if (attrs)
+ if (!sel && attrs)
attroff(attrs);
@@ -259,12 +258,12 @@ index 19ebc2cf..42a0a6b0 100644
+ if (attrs)
+ attroff(attrs);
}
-
+
/**
-@@ -7670,26 +7702,19 @@ static void statusbar(char *path)
+@@ -8047,26 +8079,19 @@ static void statusbar(char *path)
tocursor();
}
-
+
-static inline void markhovered(void)
-{
- if (cfg.showdetail && ndents) { /* Bold forward arrowhead */
@@ -289,21 +288,21 @@ index 19ebc2cf..42a0a6b0 100644
- n -= 32;
+ n -= (dtls.maxentln - 2 - dtls.maxnameln);
}
-
+
/* 2 columns for preceding space and indicator */
-@@ -7728,8 +7753,6 @@ static void draw_line(int ncols)
+@@ -8105,8 +8130,6 @@ static void draw_line(int ncols)
/* Must reset e.g. no files in dir */
if (dir)
attroff(COLOR_PAIR(cfg.curctx + 1) | A_BOLD);
-
- markhovered();
}
-
+
static void redraw(char *path)
-@@ -7837,6 +7860,26 @@ static void redraw(char *path)
+@@ -8214,6 +8237,26 @@ static void redraw(char *path)
int onscreen = MIN(ONSCREEN + curscroll, ndents);
int len = scanselforpath(path, FALSE);
-
+
+ if (cfg.showdetail) {
+ ushort_t lenbuf = dtls.maxnameln = dtls.maxsizeln = dtls.maxuidln = dtls.maxgidln = dtls.printguid = 0;
+ for (i = curscroll; i < onscreen; ++i) {
@@ -325,14 +324,14 @@ index 19ebc2cf..42a0a6b0 100644
+ }
+
ncols = adjust_cols(ncols);
-
+
/* Print listing */
-@@ -7865,7 +7908,7 @@ static void redraw(char *path)
+@@ -8242,7 +8285,7 @@ static void redraw(char *path)
#endif
}
-
+
- markhovered();
+ statusbar(path);
}
-
+
static bool cdprep(char *lastdir, char *lastname, char *path, char *newpath)