]> Sergey Matveev's repositories - nnn.git/commitdiff
Show reverse timestamp for young entries
authorArun Prakash Jana <engineerarun@gmail.com>
Sat, 2 Apr 2022 03:55:59 +0000 (09:25 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Sat, 2 Apr 2022 04:45:14 +0000 (10:15 +0530)
Show timestamps for entries modified/created within 5 minutes in
reverse.

Signed-off-by: Arun Prakash Jana <engineerarun@gmail.com>
nnn.1
src/nnn.c

diff --git a/nnn.1 b/nnn.1
index a63751558f905152f03ab735b38357f17088f4af..b9deaa6d54e198d55625ce05cf85f6df66877af1 100644 (file)
--- a/nnn.1
+++ b/nnn.1
@@ -458,6 +458,8 @@ separated by \fI;\fR:
     NOTE: Sort keys can be a/d/e/r/s/t/v (see program option -T).
           Capitalize to reverse (except 'r').
           Path must be absolute.
+
+          Timestamps for entries modified/created within 5 minutes are shown in reverse.
 .Ed
 .Pp
 \fBNNN_COLORS:\fR string of color numbers for each context, e.g.:
index 9a087916223affd24cd606e222e1624ab58dc938..2ef8a14da9f558cf2ab2e4dda3b08ec4d205cf0e 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
 #define FILE_MISSING  0x08
 #define FILE_SELECTED 0x10
 #define FILE_SCANNED  0x20
+#define FILE_YOUNG    0x40
 
 /* Macros to define process spawn behaviour as flags */
 #define F_NONE    0x00  /* no flag set */
@@ -433,6 +434,7 @@ static int nselected;
 #ifndef NOFIFO
 static int fifofd = -1;
 #endif
+static time_t gtimesecs;
 static uint_t idletimeout, selbufpos, selbuflen;
 static ushort_t xlines, xcols;
 static ushort_t idle;
@@ -4064,13 +4066,20 @@ static void print_icon(const struct entry *ent, const int attrs)
 }
 #endif
 
-static void print_time(const time_t *timep)
+static void print_time(const time_t *timep, const uchar_t flags)
 {
        struct tm t;
 
+       /* Highlight timestamp for entries 5 minutes young */
+       if (flags & FILE_YOUNG)
+               attron(A_REVERSE);
+
        localtime_r(timep, &t);
        printw("%s-%02d-%02d %02d:%02d",
                xitoa(t.tm_year + 1900), t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min);
+
+       if (flags & FILE_YOUNG)
+               attroff(A_REVERSE);
 }
 
 static char get_detail_ind(const mode_t mode)
@@ -4159,7 +4168,7 @@ static void printent(const struct entry *ent, uint_t namecols, bool sel)
                        attron(attrs);
 
                /* Print details */
-               print_time(&ent->sec);
+               print_time(&ent->sec, ent->flags);
 
                printw("%s%9s ", perms, (type == S_IFREG || type == S_IFDIR)
                        ? coolsize(cfg.blkorder ? (blkcnt_t)ent->blocks << blk_shift : ent->size)
@@ -5592,6 +5601,7 @@ static int dentfill(char *path, struct entry **ppdents)
        DIR *dirp = opendir(path);
 
        ndents = 0;
+       gtimesecs = time(NULL);
 
        DPRINTF_S(__func__);
 
@@ -5758,6 +5768,9 @@ static int dentfill(char *path, struct entry **ppdents)
 #endif
                }
 
+               if ((gtimesecs - sb.st_mtime <= 300) || (gtimesecs - sb.st_ctime <= 300))
+                       entflags |= FILE_YOUNG;
+
 #if !(defined(__sun) || defined(__HAIKU__))
                if (!flags && dp->d_type == DT_LNK) {
                         /* Do not add sizes for links */
@@ -6294,7 +6307,7 @@ static void statusbar(char *path)
                        addstr(sort);
 
                /* Timestamp */
-               print_time(&pent->sec);
+               print_time(&pent->sec, pent->flags);
 
                addch(' ');
                addstr(get_lsperms(pent->mode));