# Authors: Luuk van Baal
diff --git a/src/nnn.c b/src/nnn.c
-index 897c32f1..cf589bc8 100644
+index c7440149..8ae75614 100644
--- a/src/nnn.c
+++ b/src/nnn.c
-@@ -367,7 +367,8 @@ typedef struct {
- uint_t stayonsel : 1; /* Disable auto-proceed on select */
- uint_t trash : 2; /* Use trash to delete files 1: trash-cli, 2: gio trash */
- uint_t uidgid : 1; /* Show owner and group info */
+@@ -368,7 +368,8 @@ typedef struct {
+ uint_t stayonsel : 1; /* Disable auto-proceed on select */
+ uint_t trash : 2; /* Trash method 0: rm -rf, 1: trash-cli, 2: gio trash */
+ uint_t uidgid : 1; /* Show owner and group info */
- uint_t reserved : 7; /* Adjust when adding/removing a field */
+ uint_t previewer : 1; /* Run state of previewer */
+ uint_t reserved : 6; /* Adjust when adding/removing a field */
} runstate;
/* Contexts or workspaces */
-@@ -515,6 +516,9 @@ static char g_tmpfpath[TMP_LEN_MAX] __attribute__ ((aligned));
+@@ -516,6 +517,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));
/* Non-persistent runtime states */
static runstate g_state;
-@@ -689,12 +693,13 @@ static const char * const messages[] = {
+@@ -690,12 +694,13 @@ static const char * const messages[] = {
#define NNN_FCOLORS 5
#define NNNLVL 6
#define NNN_PIPE 7
static const char * const env_cfg[] = {
"NNN_OPTS",
-@@ -705,6 +710,7 @@ static const char * const env_cfg[] = {
+@@ -706,6 +711,7 @@ static const char * const env_cfg[] = {
"NNN_FCOLORS",
"NNNLVL",
"NNN_PIPE",
"NNN_MCLICK",
"NNN_SEL",
"NNN_ARCHIVE",
-@@ -848,7 +854,7 @@ static char *load_input(int fd, const char *path);
- static int set_sort_flags(int r);
+@@ -850,7 +856,7 @@ static int set_sort_flags(int r);
static void statusbar(char *path);
+ static bool get_output(char *file, char *arg1, char *arg2, int fdout, bool multi, bool page);
#ifndef NOFIFO
-static void notify_fifo(bool force);
+static void notify_fifo(bool force, bool closepreview);
#endif
/* Functions */
-@@ -3047,7 +3053,7 @@ try_quit:
+@@ -3065,7 +3071,7 @@ try_quit:
} else {
#ifndef NOFIFO
if (!g_state.fifomode)
#endif
escaped = TRUE;
settimeout();
-@@ -5139,15 +5145,20 @@ static bool run_cmd_as_plugin(const char *file, char *runfile, uchar_t flags)
+@@ -5164,15 +5170,20 @@ static bool run_cmd_as_plugin(const char *file, char *runfile, uchar_t flags)
static bool plctrl_init(void)
{
return EXIT_SUCCESS;
}
-@@ -5176,6 +5187,21 @@ static ssize_t read_nointr(int fd, void *buf, size_t count)
+@@ -5201,6 +5212,21 @@ static ssize_t read_nointr(int fd, void *buf, size_t count)
return len;
}
static char *readpipe(int fd, char *ctxnum, char **path)
{
char ctx, *nextpath = NULL;
-@@ -5795,7 +5821,7 @@ static void populate(char *path, char *lastname)
+@@ -5864,7 +5890,7 @@ static void populate(char *path, char *lastname)
}
#ifndef NOFIFO
{
if (!fifopath)
return;
-@@ -5811,6 +5837,12 @@ static void notify_fifo(bool force)
+@@ -5880,6 +5906,12 @@ static void notify_fifo(bool force)
}
}
static struct entry lastentry;
if (!force && !memcmp(&lastentry, &pdents[cur], sizeof(struct entry)))
-@@ -5860,7 +5892,7 @@ static void move_cursor(int target, int ignore_scrolloff)
+@@ -5912,7 +5944,7 @@ static void send_to_explorer(int *presel)
+ if (fd > 1)
+ close(fd);
+ } else
+- notify_fifo(TRUE); /* Send opened path to NNN_FIFO */
++ notify_fifo(TRUE, FALSE); /* Send opened path to NNN_FIFO */
+ }
+ #endif
+
+@@ -5945,7 +5977,7 @@ static void move_cursor(int target, int ignore_scrolloff)
#ifndef NOFIFO
if (!g_state.fifomode)
#endif
}
-@@ -6477,7 +6509,7 @@ static bool browse(char *ipath, const char *session, int pkey)
+@@ -6567,7 +6599,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;
+ bool watch = FALSE, cd = TRUE;
ino_t inode = 0;
-@@ -6743,7 +6775,7 @@ nochange:
+@@ -6821,7 +6853,7 @@ nochange:
move_cursor(r, 1);
#ifndef NOFIFO
else if ((event.bstate == BUTTON1_PRESSED) && !g_state.fifomode)
#endif
/* Handle right click selection */
if (event.bstate == BUTTON3_PRESSED) {
-@@ -6816,7 +6848,7 @@ nochange:
- }
- #ifndef NOFIFO
- if (g_state.fifomode && (sel == SEL_OPEN)) {
-- notify_fifo(TRUE); /* Send opened path to NNN_FIFO */
-+ notify_fifo(TRUE, FALSE); /* Send opened path to NNN_FIFO */
- goto nochange;
- }
- #endif
-@@ -6898,7 +6930,14 @@ nochange:
+@@ -6981,7 +7013,14 @@ nochange:
&& strstr(g_buf, "text")
#endif
) {
if (cfg.filtermode) {
presel = FILTER;
clearfilter();
-@@ -7206,8 +7245,14 @@ nochange:
+@@ -7293,8 +7332,14 @@ nochange:
copycurname();
goto nochange;
case SEL_EDIT:
continue;
default: /* SEL_LOCK */
lock_terminal();
-@@ -7567,6 +7612,7 @@ nochange:
-
+@@ -7660,6 +7705,7 @@ nochange:
+ cd = FALSE;
goto begin;
}
+run_plugin:
case SEL_PLUGIN:
/* Check if directory is accessible */
if (!xdiraccess(plgpath)) {
-@@ -7592,6 +7638,12 @@ nochange:
+@@ -7685,6 +7731,12 @@ nochange:
goto nochange;
}
if (tmp[0] == '-' && tmp[1]) {
++tmp;
r = FALSE; /* Do not refresh dir after completion */
-@@ -8185,8 +8237,10 @@ static void cleanup(void)
+@@ -8281,8 +8333,10 @@ static void cleanup(void)
if (g_state.autofifo)
unlink(fifopath);
#endif
#ifdef DEBUG
disabledbg();
#endif
-@@ -8690,7 +8744,7 @@ int main(int argc, char *argv[])
+@@ -8786,7 +8840,7 @@ int main(int argc, char *argv[])
#ifndef NOFIFO
if (!g_state.fifomode)
- notify_fifo(FALSE);
-+ notify_fifo(FALSE, FALSE);
++ notify_fifo(FALSE, TRUE);
if (fifofd != -1)
close(fifofd);
#endif