diff options
Diffstat (limited to 'patches/restorepreview/mainline.diff')
-rw-r--r-- | patches/restorepreview/mainline.diff | 89 |
1 files changed, 42 insertions, 47 deletions
diff --git a/patches/restorepreview/mainline.diff b/patches/restorepreview/mainline.diff index 0e35e6f2..65ed9890 100644 --- a/patches/restorepreview/mainline.diff +++ b/patches/restorepreview/mainline.diff @@ -4,7 +4,7 @@ # Authors: Luuk van Baal diff --git a/src/nnn.c b/src/nnn.c -index 44f297f4..f15b3bc1 100644 +index 88263beb..8aa24712 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -367,7 +367,8 @@ typedef struct { @@ -15,19 +15,19 @@ index 44f297f4..f15b3bc1 100644 + uint_t previewer : 1; /* Run state of previewer */ + uint_t reserved : 6; /* Adjust when adding/removing a field */ } runstate; - + /* Contexts or workspaces */ -@@ -513,6 +514,9 @@ static char g_tmpfpath[TMP_LEN_MAX] __attribute__ ((aligned)); +@@ -515,6 +516,9 @@ static char g_tmpfpath[TMP_LEN_MAX] __attribute__ ((aligned)); /* Buffer to store plugins control pipe location */ static char g_pipepath[TMP_LEN_MAX] __attribute__ ((aligned)); - + +/* Buffer to store preview plugins control pipe location */ +static char g_ppipepath[TMP_LEN_MAX] __attribute__ ((aligned)); + /* Non-persistent runtime states */ static runstate g_state; - -@@ -687,12 +691,13 @@ static const char * const messages[] = { + +@@ -689,12 +693,13 @@ static const char * const messages[] = { #define NNN_FCOLORS 5 #define NNNLVL 6 #define NNN_PIPE 7 @@ -44,10 +44,10 @@ index 44f297f4..f15b3bc1 100644 +#define NNN_ORDER 12 +#define NNN_HELP 13 /* strings end here */ +#define NNN_TRASH 14 /* flags begin here */ - + static const char * const env_cfg[] = { "NNN_OPTS", -@@ -703,6 +708,7 @@ static const char * const env_cfg[] = { +@@ -705,6 +710,7 @@ static const char * const env_cfg[] = { "NNN_FCOLORS", "NNNLVL", "NNN_PIPE", @@ -55,16 +55,16 @@ index 44f297f4..f15b3bc1 100644 "NNN_MCLICK", "NNN_SEL", "NNN_ARCHIVE", -@@ -846,7 +852,7 @@ static char *load_input(int fd, const char *path); +@@ -848,7 +854,7 @@ static char *load_input(int fd, const char *path); static int set_sort_flags(int r); static void statusbar(char *path); #ifndef NOFIFO -static void notify_fifo(bool force); +static void notify_fifo(bool force, bool closepreview); #endif - + /* Functions */ -@@ -3045,7 +3051,7 @@ try_quit: +@@ -3047,7 +3053,7 @@ try_quit: } else { #ifndef NOFIFO if (!g_state.fifomode) @@ -73,14 +73,14 @@ index 44f297f4..f15b3bc1 100644 #endif escaped = TRUE; settimeout(); -@@ -5131,15 +5137,20 @@ static bool run_cmd_as_plugin(const char *file, uchar_t flags) - +@@ -5139,15 +5145,20 @@ static bool run_cmd_as_plugin(const char *file, char *runfile, uchar_t flags) + static bool plctrl_init(void) { - size_t len; + size_t len, lenbuf; + pid_t pid = getpid(); - + /* g_tmpfpath is used to generate tmp file names */ g_tmpfpath[tmpfplen - 1] = '\0'; - len = xstrsncpy(g_pipepath, g_tmpfpath, TMP_LEN_MAX); @@ -95,13 +95,13 @@ index 44f297f4..f15b3bc1 100644 + xstrsncpy(g_ppipepath + len - 1, xitoa(pid), TMP_LEN_MAX - len); setenv(env_cfg[NNN_PIPE], g_pipepath, TRUE); + setenv(env_cfg[NNN_PPIPE], g_ppipepath, TRUE); - + return EXIT_SUCCESS; } -@@ -5168,6 +5179,21 @@ static ssize_t read_nointr(int fd, void *buf, size_t count) +@@ -5176,6 +5187,21 @@ static ssize_t read_nointr(int fd, void *buf, size_t count) return len; } - + +void *previewpipe(void *arg __attribute__ ((unused))) +{ + int fd, buf; @@ -120,19 +120,19 @@ index 44f297f4..f15b3bc1 100644 static char *readpipe(int fd, char *ctxnum, char **path) { char ctx, *nextpath = NULL; -@@ -5787,7 +5813,7 @@ static void populate(char *path, char *lastname) +@@ -5795,7 +5821,7 @@ static void populate(char *path, char *lastname) } - + #ifndef NOFIFO -static void notify_fifo(bool force) +static void notify_fifo(bool force, bool closepreview) { if (!fifopath) return; -@@ -5803,6 +5829,12 @@ static void notify_fifo(bool force) +@@ -5811,6 +5837,12 @@ static void notify_fifo(bool force) } } - + + if (closepreview) { + if (write(fifofd, "close\n", 6) != 6) + xerror(); @@ -140,26 +140,27 @@ index 44f297f4..f15b3bc1 100644 + } + static struct entry lastentry; - + if (!force && !memcmp(&lastentry, &pdents[cur], sizeof(struct entry))) -@@ -5852,7 +5884,7 @@ static void move_cursor(int target, int ignore_scrolloff) - +@@ -5860,7 +5892,7 @@ static void move_cursor(int target, int ignore_scrolloff) + #ifndef NOFIFO if (!g_state.fifomode) - notify_fifo(FALSE); /* Send hovered path to NNN_FIFO */ + notify_fifo(FALSE, FALSE); /* Send hovered path to NNN_FIFO */ #endif } - -@@ -6473,6 +6505,7 @@ static bool browse(char *ipath, const char *session, int pkey) + +@@ -6477,7 +6509,7 @@ static bool browse(char *ipath, const char *session, int pkey) + pEntry pent; + enum action sel; + struct stat sb; +- int r = -1, presel, selstartid = 0, selendid = 0; ++ int r = -1, presel, selstartid = 0, selendid = 0, previewkey = 0; const uchar_t opener_flags = (cfg.cliopener ? F_CLI : (F_NOTRACE | F_NOSTDIN | F_NOWAIT)); bool watch = FALSE; ino_t inode = 0; -+ static int previewkey; - - #ifndef NOMOUSE - MEVENT event = {0}; -@@ -6735,7 +6768,7 @@ nochange: +@@ -6743,7 +6775,7 @@ nochange: move_cursor(r, 1); #ifndef NOFIFO else if ((event.bstate == BUTTON1_PRESSED) && !g_state.fifomode) @@ -168,7 +169,7 @@ index 44f297f4..f15b3bc1 100644 #endif /* Handle right click selection */ if (event.bstate == BUTTON3_PRESSED) { -@@ -6808,7 +6841,7 @@ nochange: +@@ -6816,7 +6848,7 @@ nochange: } #ifndef NOFIFO if (g_state.fifomode && (sel == SEL_OPEN)) { @@ -177,16 +178,13 @@ index 44f297f4..f15b3bc1 100644 goto nochange; } #endif -@@ -6890,7 +6923,17 @@ nochange: +@@ -6898,7 +6930,14 @@ nochange: && strstr(g_buf, "text") #endif ) { -+ + if (g_state.previewer) + notify_fifo(FALSE, TRUE); -+ spawn(editor, newpath, NULL, NULL, F_CLI); -+ + if (g_state.previewer) { + pkey = previewkey; + goto run_plugin; @@ -195,16 +193,13 @@ index 44f297f4..f15b3bc1 100644 if (cfg.filtermode) { presel = FILTER; clearfilter(); -@@ -7198,7 +7241,17 @@ nochange: +@@ -7206,7 +7245,14 @@ nochange: copycurname(); goto nochange; case SEL_EDIT: -+ + if (g_state.previewer) + notify_fifo(FALSE, TRUE); -+ spawn(editor, newpath, NULL, NULL, F_CLI); -+ + if (g_state.previewer) { + pkey = previewkey; + goto run_plugin; @@ -213,18 +208,18 @@ index 44f297f4..f15b3bc1 100644 continue; default: /* SEL_LOCK */ lock_terminal(); -@@ -7558,6 +7611,7 @@ nochange: - +@@ -7566,6 +7612,7 @@ nochange: + goto begin; } +run_plugin: case SEL_PLUGIN: /* Check if directory is accessible */ if (!xdiraccess(plgpath)) { -@@ -7583,6 +7637,12 @@ nochange: +@@ -7591,6 +7638,12 @@ nochange: goto nochange; } - + + if (xstrcmp(tmp, "preview-tui") == 0) { + previewkey = r; + pthread_t tid; @@ -234,7 +229,7 @@ index 44f297f4..f15b3bc1 100644 if (tmp[0] == '-' && tmp[1]) { ++tmp; r = FALSE; /* Do not refresh dir after completion */ -@@ -8181,8 +8241,10 @@ static void cleanup(void) +@@ -8189,8 +8242,10 @@ static void cleanup(void) if (g_state.autofifo) unlink(fifopath); #endif @@ -246,8 +241,8 @@ index 44f297f4..f15b3bc1 100644 #ifdef DEBUG disabledbg(); #endif -@@ -8681,7 +8743,7 @@ int main(int argc, char *argv[]) - +@@ -8689,7 +8744,7 @@ int main(int argc, char *argv[]) + #ifndef NOFIFO if (!g_state.fifomode) - notify_fifo(FALSE); |