2021-12-14 16:16:56 +00:00
|
|
|
# Description: Adds preview pipe to enable closing and re-opening the preview
|
2022-04-16 12:06:07 +00:00
|
|
|
# pane when running an undetached editor. If you are using vim
|
2021-12-14 16:16:56 +00:00
|
|
|
# you might experience incorrectly resized window. Consider adding
|
|
|
|
# the following to your vimrc:
|
|
|
|
# autocmd VimEnter * :silent exec "!kill -s WINCH $PPID"
|
2021-09-22 02:13:57 +00:00
|
|
|
#
|
|
|
|
# Authors: Luuk van Baal
|
|
|
|
|
|
|
|
diff --git a/src/nnn.c b/src/nnn.c
|
2022-05-28 23:32:07 +00:00
|
|
|
index 6b0c1dc5..2aac557b 100644
|
2021-09-22 02:13:57 +00:00
|
|
|
--- a/src/nnn.c
|
|
|
|
+++ b/src/nnn.c
|
2022-05-28 23:32:07 +00:00
|
|
|
@@ -372,7 +372,8 @@ typedef struct {
|
2022-06-15 14:18:11 +00:00
|
|
|
uint_t stayonsel : 1; /* Disable auto-advance on selection */
|
2021-12-17 11:41:29 +00:00
|
|
|
uint_t trash : 2; /* Trash method 0: rm -rf, 1: trash-cli, 2: gio trash */
|
|
|
|
uint_t uidgid : 1; /* Show owner and group info */
|
2022-05-28 23:32:07 +00:00
|
|
|
- uint_t reserved : 6; /* Adjust when adding/removing a field */
|
2021-09-22 02:13:57 +00:00
|
|
|
+ uint_t previewer : 1; /* Run state of previewer */
|
2022-05-28 23:32:07 +00:00
|
|
|
+ uint_t reserved : 5; /* Adjust when adding/removing a field */
|
2021-09-22 02:13:57 +00:00
|
|
|
} runstate;
|
2021-09-29 09:33:19 +00:00
|
|
|
|
2021-09-22 02:13:57 +00:00
|
|
|
/* Contexts or workspaces */
|
2022-05-28 23:32:07 +00:00
|
|
|
@@ -521,6 +522,9 @@ static char g_tmpfpath[TMP_LEN_MAX] __attribute__ ((aligned));
|
2021-09-22 02:13:57 +00:00
|
|
|
/* Buffer to store plugins control pipe location */
|
|
|
|
static char g_pipepath[TMP_LEN_MAX] __attribute__ ((aligned));
|
2021-09-29 09:33:19 +00:00
|
|
|
|
2021-09-22 02:13:57 +00:00
|
|
|
+/* 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;
|
2021-09-29 09:33:19 +00:00
|
|
|
|
2022-05-28 23:32:07 +00:00
|
|
|
@@ -697,12 +701,13 @@ static const char * const messages[] = {
|
2021-09-22 02:13:57 +00:00
|
|
|
#define NNN_FCOLORS 5
|
|
|
|
#define NNNLVL 6
|
|
|
|
#define NNN_PIPE 7
|
|
|
|
-#define NNN_MCLICK 8
|
|
|
|
-#define NNN_SEL 9
|
|
|
|
-#define NNN_ARCHIVE 10
|
|
|
|
-#define NNN_ORDER 11
|
|
|
|
-#define NNN_HELP 12 /* strings end here */
|
|
|
|
-#define NNN_TRASH 13 /* flags begin here */
|
|
|
|
+#define NNN_PPIPE 8
|
|
|
|
+#define NNN_MCLICK 9
|
|
|
|
+#define NNN_SEL 10
|
|
|
|
+#define NNN_ARCHIVE 11
|
|
|
|
+#define NNN_ORDER 12
|
|
|
|
+#define NNN_HELP 13 /* strings end here */
|
|
|
|
+#define NNN_TRASH 14 /* flags begin here */
|
2021-09-29 09:33:19 +00:00
|
|
|
|
2021-09-22 02:13:57 +00:00
|
|
|
static const char * const env_cfg[] = {
|
|
|
|
"NNN_OPTS",
|
2022-05-28 23:32:07 +00:00
|
|
|
@@ -713,6 +718,7 @@ static const char * const env_cfg[] = {
|
2021-09-22 02:13:57 +00:00
|
|
|
"NNN_FCOLORS",
|
|
|
|
"NNNLVL",
|
|
|
|
"NNN_PIPE",
|
|
|
|
+ "NNN_PPIPE",
|
|
|
|
"NNN_MCLICK",
|
|
|
|
"NNN_SEL",
|
|
|
|
"NNN_ARCHIVE",
|
2022-05-28 23:32:07 +00:00
|
|
|
@@ -859,7 +865,7 @@ static int set_sort_flags(int r);
|
2021-09-22 02:13:57 +00:00
|
|
|
static void statusbar(char *path);
|
2021-11-09 13:52:45 +00:00
|
|
|
static bool get_output(char *file, char *arg1, char *arg2, int fdout, bool multi, bool page);
|
2021-09-22 02:13:57 +00:00
|
|
|
#ifndef NOFIFO
|
|
|
|
-static void notify_fifo(bool force);
|
|
|
|
+static void notify_fifo(bool force, bool closepreview);
|
|
|
|
#endif
|
2021-09-29 09:33:19 +00:00
|
|
|
|
2021-09-22 02:13:57 +00:00
|
|
|
/* Functions */
|
2022-05-28 23:32:07 +00:00
|
|
|
@@ -3071,7 +3077,7 @@ try_quit:
|
2021-09-22 02:13:57 +00:00
|
|
|
} else {
|
|
|
|
#ifndef NOFIFO
|
|
|
|
if (!g_state.fifomode)
|
|
|
|
- notify_fifo(TRUE); /* Send hovered path to NNN_FIFO */
|
|
|
|
+ notify_fifo(TRUE, FALSE); /* Send hovered path to NNN_FIFO */
|
|
|
|
#endif
|
|
|
|
escaped = TRUE;
|
|
|
|
settimeout();
|
2022-05-28 23:32:07 +00:00
|
|
|
@@ -5183,15 +5189,20 @@ static void run_cmd_as_plugin(const char *file, char *runfile, uchar_t flags)
|
2021-09-29 09:33:19 +00:00
|
|
|
|
2021-09-22 02:13:57 +00:00
|
|
|
static bool plctrl_init(void)
|
|
|
|
{
|
|
|
|
- size_t len;
|
|
|
|
+ size_t len, lenbuf;
|
|
|
|
+ pid_t pid = getpid();
|
2021-09-29 09:33:19 +00:00
|
|
|
|
2021-09-22 02:13:57 +00:00
|
|
|
/* g_tmpfpath is used to generate tmp file names */
|
|
|
|
g_tmpfpath[tmpfplen - 1] = '\0';
|
|
|
|
- len = xstrsncpy(g_pipepath, g_tmpfpath, TMP_LEN_MAX);
|
|
|
|
+ len = lenbuf = xstrsncpy(g_pipepath, g_tmpfpath, TMP_LEN_MAX);
|
|
|
|
g_pipepath[len - 1] = '/';
|
|
|
|
- len = xstrsncpy(g_pipepath + len, "nnn-pipe.", TMP_LEN_MAX - len) + len;
|
|
|
|
- xstrsncpy(g_pipepath + len - 1, xitoa(getpid()), TMP_LEN_MAX - len);
|
|
|
|
+ xstrsncpy(g_ppipepath, g_pipepath, TMP_LEN_MAX);
|
|
|
|
+ len += xstrsncpy(g_pipepath + len, "nnn-pipe.", TMP_LEN_MAX - len);
|
|
|
|
+ xstrsncpy(g_pipepath + len - 1, xitoa(pid), TMP_LEN_MAX - len);
|
|
|
|
+ len = xstrsncpy(g_ppipepath + lenbuf, "nnn-ppipe.", TMP_LEN_MAX - lenbuf) + lenbuf;
|
|
|
|
+ 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);
|
2021-09-29 09:33:19 +00:00
|
|
|
|
2021-09-22 02:13:57 +00:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
2022-05-28 23:32:07 +00:00
|
|
|
@@ -5220,6 +5231,21 @@ static ssize_t read_nointr(int fd, void *buf, size_t count)
|
2021-09-22 02:13:57 +00:00
|
|
|
return len;
|
|
|
|
}
|
2021-09-29 09:33:19 +00:00
|
|
|
|
2021-09-22 02:13:57 +00:00
|
|
|
+void *previewpipe(void *arg __attribute__ ((unused)))
|
|
|
|
+{
|
|
|
|
+ int fd, buf;
|
|
|
|
+
|
|
|
|
+ mkfifo(g_ppipepath, 0600);
|
|
|
|
+ fd = open(g_ppipepath, O_RDONLY);
|
|
|
|
+
|
|
|
|
+ if (read(fd, &buf, 1) == 1)
|
|
|
|
+ g_state.previewer = buf;
|
|
|
|
+
|
|
|
|
+ close(fd);
|
|
|
|
+ unlink(g_ppipepath);
|
|
|
|
+ return NULL;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
static char *readpipe(int fd, char *ctxnum, char **path)
|
|
|
|
{
|
|
|
|
char ctx, *nextpath = NULL;
|
2022-05-28 23:32:07 +00:00
|
|
|
@@ -5904,7 +5930,7 @@ static void populate(char *path, char *lastname)
|
2021-09-22 02:13:57 +00:00
|
|
|
}
|
2021-09-29 09:33:19 +00:00
|
|
|
|
2021-09-22 02:13:57 +00:00
|
|
|
#ifndef NOFIFO
|
|
|
|
-static void notify_fifo(bool force)
|
|
|
|
+static void notify_fifo(bool force, bool closepreview)
|
|
|
|
{
|
|
|
|
if (!fifopath)
|
|
|
|
return;
|
2022-05-28 23:32:07 +00:00
|
|
|
@@ -5920,6 +5946,12 @@ static void notify_fifo(bool force)
|
2021-09-22 02:13:57 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-29 09:33:19 +00:00
|
|
|
|
2021-09-22 02:13:57 +00:00
|
|
|
+ if (closepreview) {
|
|
|
|
+ if (write(fifofd, "close\n", 6) != 6)
|
|
|
|
+ xerror();
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
static struct entry lastentry;
|
2021-09-29 09:33:19 +00:00
|
|
|
|
2021-09-22 02:13:57 +00:00
|
|
|
if (!force && !memcmp(&lastentry, &pdents[cur], sizeof(struct entry)))
|
2022-05-28 23:32:07 +00:00
|
|
|
@@ -5952,7 +5984,7 @@ static void send_to_explorer(int *presel)
|
2021-12-17 11:41:29 +00:00
|
|
|
if (fd > 1)
|
|
|
|
close(fd);
|
|
|
|
} else
|
2021-11-09 13:52:45 +00:00
|
|
|
- notify_fifo(TRUE); /* Send opened path to NNN_FIFO */
|
|
|
|
+ notify_fifo(TRUE, FALSE); /* Send opened path to NNN_FIFO */
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-05-28 23:32:07 +00:00
|
|
|
@@ -5985,7 +6017,7 @@ static void move_cursor(int target, int ignore_scrolloff)
|
2021-09-29 09:33:19 +00:00
|
|
|
|
2021-09-22 02:13:57 +00:00
|
|
|
#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
|
|
|
|
}
|
2021-09-29 09:33:19 +00:00
|
|
|
|
2022-05-28 23:32:07 +00:00
|
|
|
@@ -6603,7 +6635,7 @@ static bool browse(char *ipath, const char *session, int pkey)
|
2021-09-29 09:33:19 +00:00
|
|
|
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;
|
2021-09-22 02:13:57 +00:00
|
|
|
const uchar_t opener_flags = (cfg.cliopener ? F_CLI : (F_NOTRACE | F_NOSTDIN | F_NOWAIT));
|
2021-12-17 11:41:29 +00:00
|
|
|
bool watch = FALSE, cd = TRUE;
|
2021-09-22 02:13:57 +00:00
|
|
|
ino_t inode = 0;
|
2022-05-28 23:32:07 +00:00
|
|
|
@@ -6861,7 +6893,7 @@ nochange:
|
2021-09-22 02:13:57 +00:00
|
|
|
move_cursor(r, 1);
|
|
|
|
#ifndef NOFIFO
|
|
|
|
else if ((event.bstate == BUTTON1_PRESSED) && !g_state.fifomode)
|
|
|
|
- notify_fifo(TRUE); /* Send clicked path to NNN_FIFO */
|
|
|
|
+ notify_fifo(TRUE, FALSE); /* Send clicked path to NNN_FIFO */
|
|
|
|
#endif
|
|
|
|
/* Handle right click selection */
|
|
|
|
if (event.bstate == BUTTON3_PRESSED) {
|
2022-05-28 23:32:07 +00:00
|
|
|
@@ -7030,7 +7062,14 @@ nochange:
|
2021-09-22 02:13:57 +00:00
|
|
|
&& 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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
if (cfg.filtermode) {
|
|
|
|
presel = FILTER;
|
|
|
|
clearfilter();
|
2022-05-28 23:32:07 +00:00
|
|
|
@@ -7340,8 +7379,14 @@ nochange:
|
2021-09-22 02:13:57 +00:00
|
|
|
copycurname();
|
|
|
|
goto nochange;
|
|
|
|
case SEL_EDIT:
|
|
|
|
+ if (g_state.previewer)
|
|
|
|
+ notify_fifo(FALSE, TRUE);
|
2022-06-08 19:01:03 +00:00
|
|
|
if (!(g_state.picker || g_state.fifomode))
|
2021-12-17 11:41:29 +00:00
|
|
|
spawn(editor, newpath, NULL, NULL, F_CLI);
|
2021-09-22 02:13:57 +00:00
|
|
|
+ if (g_state.previewer) {
|
|
|
|
+ pkey = previewkey;
|
|
|
|
+ goto run_plugin;
|
|
|
|
+ }
|
|
|
|
continue;
|
|
|
|
default: /* SEL_LOCK */
|
|
|
|
lock_terminal();
|
2022-05-28 23:32:07 +00:00
|
|
|
@@ -7710,6 +7755,7 @@ nochange:
|
2021-12-17 11:41:29 +00:00
|
|
|
cd = FALSE;
|
2021-09-22 02:13:57 +00:00
|
|
|
goto begin;
|
|
|
|
}
|
|
|
|
+run_plugin:
|
|
|
|
case SEL_PLUGIN:
|
|
|
|
/* Check if directory is accessible */
|
|
|
|
if (!xdiraccess(plgpath)) {
|
2022-05-28 23:32:07 +00:00
|
|
|
@@ -7735,6 +7781,12 @@ nochange:
|
2021-09-22 02:13:57 +00:00
|
|
|
goto nochange;
|
|
|
|
}
|
2021-09-29 09:33:19 +00:00
|
|
|
|
2021-09-22 02:13:57 +00:00
|
|
|
+ if (xstrcmp(tmp, "preview-tui") == 0) {
|
|
|
|
+ previewkey = r;
|
|
|
|
+ pthread_t tid;
|
|
|
|
+ pthread_create(&tid, NULL, previewpipe, NULL);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
if (tmp[0] == '-' && tmp[1]) {
|
|
|
|
++tmp;
|
|
|
|
r = FALSE; /* Do not refresh dir after completion */
|
2022-05-28 23:32:07 +00:00
|
|
|
@@ -7789,7 +7841,13 @@ nochange:
|
2021-12-17 11:41:29 +00:00
|
|
|
case SEL_SHELL: // fallthrough
|
|
|
|
case SEL_LAUNCH: // fallthrough
|
|
|
|
case SEL_PROMPT:
|
|
|
|
+ if (g_state.previewer)
|
|
|
|
+ notify_fifo(FALSE, TRUE);
|
|
|
|
r = handle_cmd(sel, newpath);
|
|
|
|
+ if (g_state.previewer) {
|
|
|
|
+ pkey = previewkey;
|
|
|
|
+ goto run_plugin;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/* Continue in type-to-nav mode, if enabled */
|
|
|
|
if (cfg.filtermode)
|
2022-05-28 23:32:07 +00:00
|
|
|
@@ -8329,8 +8387,10 @@ static void cleanup(void)
|
2021-09-22 02:13:57 +00:00
|
|
|
if (g_state.autofifo)
|
|
|
|
unlink(fifopath);
|
|
|
|
#endif
|
|
|
|
- if (g_state.pluginit)
|
|
|
|
+ if (g_state.pluginit){
|
|
|
|
unlink(g_pipepath);
|
|
|
|
+ unlink(g_ppipepath);
|
|
|
|
+ }
|
|
|
|
#ifdef DEBUG
|
|
|
|
disabledbg();
|
|
|
|
#endif
|
2022-05-28 23:32:07 +00:00
|
|
|
@@ -8828,7 +8888,7 @@ int main(int argc, char *argv[])
|
2021-09-29 09:33:19 +00:00
|
|
|
|
2021-09-22 02:13:57 +00:00
|
|
|
#ifndef NOFIFO
|
|
|
|
if (!g_state.fifomode)
|
|
|
|
- notify_fifo(FALSE);
|
2021-11-09 13:52:45 +00:00
|
|
|
+ notify_fifo(FALSE, TRUE);
|
2021-09-22 02:13:57 +00:00
|
|
|
if (fifofd != -1)
|
|
|
|
close(fifofd);
|
|
|
|
#endif
|