"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "patches/restorepreview/mainline.diff" between
nnn-v4.3.tar.gz and nnn-v4.4.tar.gz

About: nnn is a full-featured terminal file manager.

mainline.diff  (nnn-v4.3):mainline.diff  (nnn-v4.4)
# Description: Adds preview pipe to enable closing and re-opening # Description: Adds preview pipe to enable closing and re-opening
# the preview pane when running an undetached editor. # the preview pane when running an undetached editor.
# #
# Authors: Luuk van Baal # Authors: Luuk van Baal
diff --git a/src/nnn.c b/src/nnn.c diff --git a/src/nnn.c b/src/nnn.c
index 88263beb..8aa24712 100644 index c7440149..8ae75614 100644
--- a/src/nnn.c --- a/src/nnn.c
+++ b/src/nnn.c +++ b/src/nnn.c
@@ -367,7 +367,8 @@ typedef struct { @@ -368,7 +368,8 @@ typedef struct {
uint_t stayonsel : 1; /* Disable auto-proceed on select */ uint_t stayonsel : 1; /* Disable auto-proceed on select */
uint_t trash : 2; /* Use trash to delete files 1: trash-cli, 2: gio uint_t trash : 2; /* Trash method 0: rm -rf, 1: trash-cli, 2: gio t
trash */ rash */
uint_t uidgid : 1; /* Show owner and group info */ uint_t uidgid : 1; /* Show owner and group info */
- uint_t reserved : 7; /* Adjust when adding/removing a field */ - uint_t reserved : 7; /* Adjust when adding/removing a field */
+ uint_t previewer : 1; /* Run state of previewer */ + uint_t previewer : 1; /* Run state of previewer */
+ uint_t reserved : 6; /* Adjust when adding/removing a field */ + uint_t reserved : 6; /* Adjust when adding/removing a field */
} runstate; } runstate;
/* Contexts or workspaces */ /* 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 */ /* Buffer to store plugins control pipe location */
static char g_pipepath[TMP_LEN_MAX] __attribute__ ((aligned)); static char g_pipepath[TMP_LEN_MAX] __attribute__ ((aligned));
+/* Buffer to store preview plugins control pipe location */ +/* Buffer to store preview plugins control pipe location */
+static char g_ppipepath[TMP_LEN_MAX] __attribute__ ((aligned)); +static char g_ppipepath[TMP_LEN_MAX] __attribute__ ((aligned));
+ +
/* Non-persistent runtime states */ /* Non-persistent runtime states */
static runstate g_state; 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 NNN_FCOLORS 5
#define NNNLVL 6 #define NNNLVL 6
#define NNN_PIPE 7 #define NNN_PIPE 7
-#define NNN_MCLICK 8 -#define NNN_MCLICK 8
-#define NNN_SEL 9 -#define NNN_SEL 9
-#define NNN_ARCHIVE 10 -#define NNN_ARCHIVE 10
-#define NNN_ORDER 11 -#define NNN_ORDER 11
-#define NNN_HELP 12 /* strings end here */ -#define NNN_HELP 12 /* strings end here */
-#define NNN_TRASH 13 /* flags begin here */ -#define NNN_TRASH 13 /* flags begin here */
+#define NNN_PPIPE 8 +#define NNN_PPIPE 8
+#define NNN_MCLICK 9 +#define NNN_MCLICK 9
+#define NNN_SEL 10 +#define NNN_SEL 10
+#define NNN_ARCHIVE 11 +#define NNN_ARCHIVE 11
+#define NNN_ORDER 12 +#define NNN_ORDER 12
+#define NNN_HELP 13 /* strings end here */ +#define NNN_HELP 13 /* strings end here */
+#define NNN_TRASH 14 /* flags begin here */ +#define NNN_TRASH 14 /* flags begin here */
static const char * const env_cfg[] = { static const char * const env_cfg[] = {
"NNN_OPTS", "NNN_OPTS",
@@ -705,6 +710,7 @@ static const char * const env_cfg[] = { @@ -706,6 +711,7 @@ static const char * const env_cfg[] = {
"NNN_FCOLORS", "NNN_FCOLORS",
"NNNLVL", "NNNLVL",
"NNN_PIPE", "NNN_PIPE",
+ "NNN_PPIPE", + "NNN_PPIPE",
"NNN_MCLICK", "NNN_MCLICK",
"NNN_SEL", "NNN_SEL",
"NNN_ARCHIVE", "NNN_ARCHIVE",
@@ -848,7 +854,7 @@ static char *load_input(int fd, const char *path); @@ -850,7 +856,7 @@ static int set_sort_flags(int r);
static int set_sort_flags(int r);
static void statusbar(char *path); static void statusbar(char *path);
static bool get_output(char *file, char *arg1, char *arg2, int fdout, bool mult i, bool page);
#ifndef NOFIFO #ifndef NOFIFO
-static void notify_fifo(bool force); -static void notify_fifo(bool force);
+static void notify_fifo(bool force, bool closepreview); +static void notify_fifo(bool force, bool closepreview);
#endif #endif
/* Functions */ /* Functions */
@@ -3047,7 +3053,7 @@ try_quit: @@ -3065,7 +3071,7 @@ try_quit:
} else { } else {
#ifndef NOFIFO #ifndef NOFIFO
if (!g_state.fifomode) if (!g_state.fifomode)
- notify_fifo(TRUE); /* Send hovered path t o NNN_FIFO */ - notify_fifo(TRUE); /* Send hovered path t o NNN_FIFO */
+ notify_fifo(TRUE, FALSE); /* Send hovered path to NNN_FIFO */ + notify_fifo(TRUE, FALSE); /* Send hovered path to NNN_FIFO */
#endif #endif
escaped = TRUE; escaped = TRUE;
settimeout(); settimeout();
@@ -5139,15 +5145,20 @@ static bool run_cmd_as_plugin(const char *file, char *ru nfile, uchar_t flags) @@ -5164,15 +5170,20 @@ static bool run_cmd_as_plugin(const char *file, char *ru nfile, uchar_t flags)
static bool plctrl_init(void) static bool plctrl_init(void)
{ {
- size_t len; - size_t len;
+ size_t len, lenbuf; + size_t len, lenbuf;
+ pid_t pid = getpid(); + pid_t pid = getpid();
/* g_tmpfpath is used to generate tmp file names */ /* g_tmpfpath is used to generate tmp file names */
g_tmpfpath[tmpfplen - 1] = '\0'; g_tmpfpath[tmpfplen - 1] = '\0';
- len = xstrsncpy(g_pipepath, g_tmpfpath, TMP_LEN_MAX); - len = xstrsncpy(g_pipepath, g_tmpfpath, TMP_LEN_MAX);
skipping to change at line 101 skipping to change at line 101
+ xstrsncpy(g_ppipepath, g_pipepath, TMP_LEN_MAX); + xstrsncpy(g_ppipepath, g_pipepath, TMP_LEN_MAX);
+ len += xstrsncpy(g_pipepath + len, "nnn-pipe.", TMP_LEN_MAX - len); + len += xstrsncpy(g_pipepath + len, "nnn-pipe.", TMP_LEN_MAX - len);
+ xstrsncpy(g_pipepath + len - 1, xitoa(pid), 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; + len = xstrsncpy(g_ppipepath + lenbuf, "nnn-ppipe.", TMP_LEN_MAX - lenbuf) + lenbuf;
+ xstrsncpy(g_ppipepath + len - 1, xitoa(pid), TMP_LEN_MAX - len); + xstrsncpy(g_ppipepath + len - 1, xitoa(pid), TMP_LEN_MAX - len);
setenv(env_cfg[NNN_PIPE], g_pipepath, TRUE); setenv(env_cfg[NNN_PIPE], g_pipepath, TRUE);
+ setenv(env_cfg[NNN_PPIPE], g_ppipepath, TRUE); + setenv(env_cfg[NNN_PPIPE], g_ppipepath, TRUE);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
@@ -5176,6 +5187,21 @@ static ssize_t read_nointr(int fd, void *buf, size_t coun t) @@ -5201,6 +5212,21 @@ static ssize_t read_nointr(int fd, void *buf, size_t coun t)
return len; return len;
} }
+void *previewpipe(void *arg __attribute__ ((unused))) +void *previewpipe(void *arg __attribute__ ((unused)))
+{ +{
+ int fd, buf; + int fd, buf;
+ +
+ mkfifo(g_ppipepath, 0600); + mkfifo(g_ppipepath, 0600);
+ fd = open(g_ppipepath, O_RDONLY); + fd = open(g_ppipepath, O_RDONLY);
+ +
skipping to change at line 123 skipping to change at line 123
+ g_state.previewer = buf; + g_state.previewer = buf;
+ +
+ close(fd); + close(fd);
+ unlink(g_ppipepath); + unlink(g_ppipepath);
+ return NULL; + return NULL;
+} +}
+ +
static char *readpipe(int fd, char *ctxnum, char **path) static char *readpipe(int fd, char *ctxnum, char **path)
{ {
char ctx, *nextpath = NULL; 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 #ifndef NOFIFO
-static void notify_fifo(bool force) -static void notify_fifo(bool force)
+static void notify_fifo(bool force, bool closepreview) +static void notify_fifo(bool force, bool closepreview)
{ {
if (!fifopath) if (!fifopath)
return; return;
@@ -5811,6 +5837,12 @@ static void notify_fifo(bool force) @@ -5880,6 +5906,12 @@ static void notify_fifo(bool force)
} }
} }
+ if (closepreview) { + if (closepreview) {
+ if (write(fifofd, "close\n", 6) != 6) + if (write(fifofd, "close\n", 6) != 6)
+ xerror(); + xerror();
+ return; + return;
+ } + }
+ +
static struct entry lastentry; static struct entry lastentry;
if (!force && !memcmp(&lastentry, &pdents[cur], sizeof(struct entry))) 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 #ifndef NOFIFO
if (!g_state.fifomode) if (!g_state.fifomode)
- notify_fifo(FALSE); /* Send hovered path to NNN_FIFO */ - notify_fifo(FALSE); /* Send hovered path to NNN_FIFO */
+ notify_fifo(FALSE, FALSE); /* Send hovered path to NNN_FIFO */ + notify_fifo(FALSE, FALSE); /* Send hovered path to NNN_FIFO */
#endif #endif
} }
@@ -6477,7 +6509,7 @@ static bool browse(char *ipath, const char *session, int p key) @@ -6567,7 +6599,7 @@ static bool browse(char *ipath, const char *session, int p key)
pEntry pent; pEntry pent;
enum action sel; enum action sel;
struct stat sb; struct stat sb;
- int r = -1, presel, selstartid = 0, selendid = 0; - int r = -1, presel, selstartid = 0, selendid = 0;
+ int r = -1, presel, selstartid = 0, selendid = 0, previewkey = 0; + int r = -1, presel, selstartid = 0, selendid = 0, previewkey = 0;
const uchar_t opener_flags = (cfg.cliopener ? F_CLI : (F_NOTRACE | F_NOST DIN | F_NOWAIT)); const uchar_t opener_flags = (cfg.cliopener ? F_CLI : (F_NOTRACE | F_NOST DIN | F_NOWAIT));
bool watch = FALSE; bool watch = FALSE, cd = TRUE;
ino_t inode = 0; ino_t inode = 0;
@@ -6743,7 +6775,7 @@ nochange: @@ -6821,7 +6853,7 @@ nochange:
move_cursor(r, 1); move_cursor(r, 1);
#ifndef NOFIFO #ifndef NOFIFO
else if ((event.bstate == BUTTON1_PRESSED) && !g_ state.fifomode) else if ((event.bstate == BUTTON1_PRESSED) && !g_ state.fifomode)
- notify_fifo(TRUE); /* Send clicked path t o NNN_FIFO */ - notify_fifo(TRUE); /* Send clicked path t o NNN_FIFO */
+ notify_fifo(TRUE, FALSE); /* Send clicked path to NNN_FIFO */ + notify_fifo(TRUE, FALSE); /* Send clicked path to NNN_FIFO */
#endif #endif
/* Handle right click selection */ /* Handle right click selection */
if (event.bstate == BUTTON3_PRESSED) { if (event.bstate == BUTTON3_PRESSED) {
@@ -6816,7 +6848,7 @@ nochange: @@ -6981,7 +7013,14 @@ nochange:
}
#ifndef NOFIFO
if (g_state.fifomode && (sel == SEL_OPEN)) {
- notify_fifo(TRUE); /* Send opened path to NNN_FIF
O */
+ notify_fifo(TRUE, FALSE); /* Send opened path to
NNN_FIFO */
goto nochange;
}
#endif
@@ -6898,7 +6930,14 @@ nochange:
&& strstr(g_buf, "text") && strstr(g_buf, "text")
#endif #endif
) { ) {
+ if (g_state.previewer) + if (g_state.previewer)
+ notify_fifo(FALSE, TRUE); + notify_fifo(FALSE, TRUE);
spawn(editor, newpath, NULL, NULL, F_CLI); spawn(editor, newpath, NULL, NULL, F_CLI);
+ if (g_state.previewer) { + if (g_state.previewer) {
+ pkey = previewkey; + pkey = previewkey;
+ goto run_plugin; + goto run_plugin;
+ } + }
+ +
if (cfg.filtermode) { if (cfg.filtermode) {
presel = FILTER; presel = FILTER;
clearfilter(); clearfilter();
@@ -7206,7 +7245,14 @@ nochange: @@ -7293,8 +7332,14 @@ nochange:
copycurname(); copycurname();
goto nochange; goto nochange;
case SEL_EDIT: case SEL_EDIT:
+ if (g_state.previewer) + if (g_state.previewer)
+ notify_fifo(FALSE, TRUE); + notify_fifo(FALSE, TRUE);
spawn(editor, newpath, NULL, NULL, F_CLI); if (!g_state.picker)
spawn(editor, newpath, NULL, NULL, F_CLI)
;
+ if (g_state.previewer) { + if (g_state.previewer) {
+ pkey = previewkey; + pkey = previewkey;
+ goto run_plugin; + goto run_plugin;
+ } + }
+
continue; continue;
default: /* SEL_LOCK */ default: /* SEL_LOCK */
lock_terminal(); lock_terminal();
@@ -7566,6 +7612,7 @@ nochange: @@ -7660,6 +7705,7 @@ nochange:
cd = FALSE;
goto begin; goto begin;
} }
+run_plugin: +run_plugin:
case SEL_PLUGIN: case SEL_PLUGIN:
/* Check if directory is accessible */ /* Check if directory is accessible */
if (!xdiraccess(plgpath)) { if (!xdiraccess(plgpath)) {
@@ -7591,6 +7638,12 @@ nochange: @@ -7685,6 +7731,12 @@ nochange:
goto nochange; goto nochange;
} }
+ if (xstrcmp(tmp, "preview-tui") == 0) { + if (xstrcmp(tmp, "preview-tui") == 0) {
+ previewkey = r; + previewkey = r;
+ pthread_t tid; + pthread_t tid;
+ pthread_create(&tid, NULL, previewpipe, N ULL); + pthread_create(&tid, NULL, previewpipe, N ULL);
+ } + }
+ +
if (tmp[0] == '-' && tmp[1]) { if (tmp[0] == '-' && tmp[1]) {
++tmp; ++tmp;
r = FALSE; /* Do not refresh dir after co mpletion */ r = FALSE; /* Do not refresh dir after co mpletion */
@@ -8189,8 +8242,10 @@ static void cleanup(void) @@ -8281,8 +8333,10 @@ static void cleanup(void)
if (g_state.autofifo) if (g_state.autofifo)
unlink(fifopath); unlink(fifopath);
#endif #endif
- if (g_state.pluginit) - if (g_state.pluginit)
+ if (g_state.pluginit){ + if (g_state.pluginit){
unlink(g_pipepath); unlink(g_pipepath);
+ unlink(g_ppipepath); + unlink(g_ppipepath);
+ } + }
#ifdef DEBUG #ifdef DEBUG
disabledbg(); disabledbg();
#endif #endif
@@ -8689,7 +8744,7 @@ int main(int argc, char *argv[]) @@ -8786,7 +8840,7 @@ int main(int argc, char *argv[])
#ifndef NOFIFO #ifndef NOFIFO
if (!g_state.fifomode) if (!g_state.fifomode)
- notify_fifo(FALSE); - notify_fifo(FALSE);
+ notify_fifo(FALSE, FALSE); + notify_fifo(FALSE, TRUE);
if (fifofd != -1) if (fifofd != -1)
close(fifofd); close(fifofd);
#endif #endif
 End of changes. 25 change blocks. 
41 lines changed or deleted 40 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)