uint_t dircolor : 1; /* Current status of dir color */
uint_t picker : 1; /* Write selection to user-specified file */
uint_t picked : 1; /* Plugin has picked files */
- uint_t explorer : 1; /* Explorer mode: send picked files to FIFO without exiting */
uint_t runplugin : 1; /* Choose plugin mode */
uint_t runctx : 3; /* The context in which plugin is to be run */
uint_t selmode : 1; /* Set when selecting files */
uint_t uidgid : 1; /* Show owner and group info */
uint_t prstssn : 1; /* Persistent session */
uint_t duinit : 1; /* Initialize disk usage */
- uint_t reserved : 7; /* Adjust when adding/removing a field */
+ uint_t fifobits : 2; /* b00: notify previewer, b01: notify explorer, b10: notify both */
+ uint_t reserved : 6; /* Adjust when adding/removing a field */
} runstate;
/* Contexts or workspaces */
static int ndents, cur, last, curscroll, last_curscroll, total_dents = ENTRY_INCR, scroll_lines = 1;
static int nselected;
#ifndef NOFIFO
-static int hfifofd = -1; /* FIFO used in hover (NNN_FIFO) */
-static int efifofd = -1; /* FIFO used in explorer mode (-X) */
+static int fifofd = -1;
#endif
static uint_t idletimeout, selbufpos, lastappendpos, selbuflen;
static ushort_t xlines, xcols;
static char *pnamebuf, *pselbuf;
static char *mark;
#ifndef NOFIFO
-static char *hfifopath; /* FIFO used in hover (NNN_FIFO) */
-static char *efifopath; /* FIFO used in explorer mode (-X) */
+static char *fifopath;
#endif
static ullong_t *ihashbmp;
static struct entry *pdents;
static char *load_input(int fd, const char *path);
static int set_sort_flags(int r);
#ifndef NOFIFO
-static void notify_fifo(bool force, bool explorer);
+static void notify_fifo(bool force);
#endif
/* Functions */
c = CONTROL('Q');
} else {
#ifndef NOFIFO
- /* Send hovered path to NNN_FIFO */
- notify_fifo(TRUE, FALSE);
+ if (!(g_state.fifobits & 1))
+ notify_fifo(TRUE); /* Send hovered path to NNN_FIFO */
#endif
escaped = TRUE;
settimeout();
}
#ifndef NOFIFO
-static void notify_fifo(bool force, bool explorer)
+static void notify_fifo(bool force)
{
- /* refer to the explorer fifo instead of the hover fifo if explorer is true */
- char **ppath = explorer ? &efifopath : &hfifopath;
- int *pptr = explorer ? &efifofd : &hfifofd;
-
- if (!(*ppath))
+ if (!fifopath)
return;
- if (*pptr == -1) {
- *pptr = open(*ppath, O_WRONLY|O_NONBLOCK|O_CLOEXEC);
- if (*pptr == -1) {
+ if (fifofd == -1) {
+ fifofd = open(fifopath, O_WRONLY|O_NONBLOCK|O_CLOEXEC);
+ if (fifofd == -1) {
if (errno != ENXIO)
/* Unexpected error, the FIFO file might have been removed */
/* We give up FIFO notification */
- *ppath = NULL;
+ fifopath = NULL;
return;
}
}
path[len - 1] = '\n';
- ssize_t ret = write(*pptr, path, len);
+ ssize_t ret = write(fifofd, path, len);
if (ret != (ssize_t)len && !(ret == -1 && (errno == EAGAIN || errno == EPIPE))) {
DPRINTF_S(strerror(errno));
curscroll = MAX(curscroll, MAX(cur - (onscreen - 1), 0));
#ifndef NOFIFO
- notify_fifo(FALSE, FALSE);
+ if (!(g_state.fifobits & 1))
+ notify_fifo(FALSE); /* Send hovered path to NNN_FIFO */
#endif
}
if (r != cur)
move_cursor(r, 1);
#ifndef NOFIFO
- else if (event.bstate == BUTTON1_PRESSED)
- notify_fifo(TRUE, FALSE);
+ else if ((event.bstate == BUTTON1_PRESSED) && !(g_state.fifobits & 1)) {
+ notify_fifo(TRUE); /* Send clicked path to NNN_FIFO */
+ }
#endif
/* Handle right click selection */
if (event.bstate == BUTTON3_PRESSED) {
goto nochange;
}
#ifndef NOFIFO
- if (g_state.explorer && sel == SEL_OPEN) {
- notify_fifo(TRUE, TRUE);
+ if (g_state.fifobits && sel == SEL_OPEN) {
+ notify_fifo(TRUE); /* Send opened path to NNN_FIFO */
goto nochange;
}
#endif
" -E internal edits in EDITOR\n"
#ifndef NORL
" -f use readline history file\n"
+#endif
+#ifndef NOFIFO
+ " -F val fifo mode [0:preview 1:explore 2:both]\n"
#endif
" -g regex filters\n"
" -H show hidden files\n"
" -l val set scroll lines\n"
" -n type-to-nav mode\n"
" -o open files only on Enter\n"
- " -p file selection file [stdout if '-']\n"
+ " -p file selection file [-:stdout]\n"
" -P key run plugin key\n"
" -Q no quit confirmation\n"
" -r use advcpmv patched cp, mv\n"
" -w place HW cursor on hovered\n"
#ifndef NOX11
" -x notis, selection sync, xterm title\n"
-#endif
-#ifndef NOFIFO
- " -X fifo explorer mode\n"
#endif
" -h show help\n\n"
"v%s\n%s\n", __func__, VERSION, GENERAL_INFO);
free(plug);
#ifndef NOFIFO
if (g_state.autofifo)
- unlink(hfifopath);
- if (g_state.explorer)
- unlink(efifopath);
+ unlink(fifopath);
#endif
if (g_state.pluginit)
unlink(g_pipepath);
while ((opt = (env_opts_id > 0
? env_opts[--env_opts_id]
- : getopt(argc, argv, "aAb:cCdDeEfgHJKl:nop:P:QrRs:St:T:uUVwxX:h"))) != -1) {
+ : getopt(argc, argv, "aAb:cCdDeEfF:gHJKl:nop:P:QrRs:St:T:uUVwxh"))) != -1) {
switch (opt) {
#ifndef NOFIFO
case 'a':
rlhist = TRUE;
#endif
break;
+#ifndef NOFIFO
+ case 'F':
+ if (env_opts_id < 0)
+ g_state.fifobits = atoi(optarg);
+ break;
+#endif
case 'g':
cfg.regex = 1;
filterfn = &visible_re;
case 'x':
cfg.x11 = 1;
break;
- case 'X':
-#ifndef NOFIFO
- g_state.explorer = TRUE;
- efifopath = optarg;
-#endif
- break;
case 'h':
usage();
return EXIT_SUCCESS;
setenv("NNN_FIFO", g_buf, TRUE);
}
- hfifopath = xgetenv("NNN_FIFO", NULL);
- if (hfifopath) {
- if (mkfifo(hfifopath, 0600) != 0 && !(errno == EEXIST && access(hfifopath, W_OK) == 0)) {
- xerror();
- return EXIT_FAILURE;
- }
-
- sigaction(SIGPIPE, &(struct sigaction){.sa_handler = SIG_IGN}, NULL);
- }
-
- if (g_state.explorer) {
- if (mkfifo(efifopath, 0600) != 0 && !(errno == EEXIST && access(efifopath, W_OK) == 0)) {
+ fifopath = xgetenv("NNN_FIFO", NULL);
+ if (fifopath) {
+ if (mkfifo(fifopath, 0600) != 0 && !(errno == EEXIST && access(fifopath, W_OK) == 0)) {
xerror();
return EXIT_FAILURE;
}
#endif
#ifndef NOFIFO
- notify_fifo(FALSE, FALSE);
- if (hfifofd != -1)
- close(hfifofd);
- if (efifofd != -1)
- close(efifofd);
+ notify_fifo(FALSE);
+ if (fifofd != -1)
+ close(fifofd);
#endif
return opt;