mirror of
https://github.com/jarun/nnn.git
synced 2025-02-26 03:01:32 +00:00
Add force-tty capability to spawn and set pagers to it (#1070)
Co-authored-by: Anna Arad <annagram@shards.me>
This commit is contained in:
parent
0dd76e7aec
commit
4f977ff269
1 changed files with 22 additions and 14 deletions
18
src/nnn.c
18
src/nnn.c
|
@ -219,6 +219,7 @@
|
||||||
#define F_CHKRTN 0x20 /* wait for user prompt if cmd returns failure status */
|
#define F_CHKRTN 0x20 /* wait for user prompt if cmd returns failure status */
|
||||||
#define F_NOSTDIN 0x40 /* suppress stdin */
|
#define F_NOSTDIN 0x40 /* suppress stdin */
|
||||||
#define F_PAGE 0x80 /* page output in run-cmd-as-plugin mode */
|
#define F_PAGE 0x80 /* page output in run-cmd-as-plugin mode */
|
||||||
|
#define F_FORCE_TTY 0x100 /* Force stdout to go to tty if redirected to a non-tty */
|
||||||
#define F_CLI (F_NORMAL | F_MULTI)
|
#define F_CLI (F_NORMAL | F_MULTI)
|
||||||
#define F_SILENT (F_CLI | F_NOTRACE)
|
#define F_SILENT (F_CLI | F_NOTRACE)
|
||||||
|
|
||||||
|
@ -800,7 +801,7 @@ static haiku_nm_h haiku_hnd;
|
||||||
|
|
||||||
/* Forward declarations */
|
/* Forward declarations */
|
||||||
static void redraw(char *path);
|
static void redraw(char *path);
|
||||||
static int spawn(char *file, char *arg1, char *arg2, char *arg3, uchar_t flag);
|
static int spawn(char *file, char *arg1, char *arg2, char *arg3, ushort_t flag);
|
||||||
static void move_cursor(int target, int ignore_scrolloff);
|
static void move_cursor(int target, int ignore_scrolloff);
|
||||||
static char *load_input(int fd, const char *path);
|
static char *load_input(int fd, const char *path);
|
||||||
static int set_sort_flags(int r);
|
static int set_sort_flags(int r);
|
||||||
|
@ -2039,7 +2040,7 @@ static int join(pid_t p, uchar_t flag)
|
||||||
* Spawns a child process. Behaviour can be controlled using flag.
|
* Spawns a child process. Behaviour can be controlled using flag.
|
||||||
* Limited to 3 arguments to a program, flag works on bit set.
|
* Limited to 3 arguments to a program, flag works on bit set.
|
||||||
*/
|
*/
|
||||||
static int spawn(char *file, char *arg1, char *arg2, char *arg3, uchar_t flag)
|
static int spawn(char *file, char *arg1, char *arg2, char *arg3, ushort_t flag)
|
||||||
{
|
{
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int status = 0, retstatus = 0xFFFF;
|
int status = 0, retstatus = 0xFFFF;
|
||||||
|
@ -2084,6 +2085,13 @@ static int spawn(char *file, char *arg1, char *arg2, char *arg3, uchar_t flag)
|
||||||
dup2(fd, STDOUT_FILENO);
|
dup2(fd, STDOUT_FILENO);
|
||||||
dup2(fd, STDERR_FILENO);
|
dup2(fd, STDERR_FILENO);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
} else if (flag & F_FORCE_TTY) {
|
||||||
|
/* If stdout has been redirected to a non-tty, force output to tty */
|
||||||
|
if (!isatty(STDOUT_FILENO)) {
|
||||||
|
int fd = open(ctermid(NULL), O_WRONLY, 0200);
|
||||||
|
dup2(fd, STDOUT_FILENO);
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
execvp(*argv, argv);
|
execvp(*argv, argv);
|
||||||
|
@ -4104,7 +4112,7 @@ static bool get_output(char *file, char *arg1, char *arg2, FILE *fout, bool mult
|
||||||
/* Show in pager in child */
|
/* Show in pager in child */
|
||||||
dup2(pipefd[0], STDIN_FILENO);
|
dup2(pipefd[0], STDIN_FILENO);
|
||||||
close(pipefd[0]);
|
close(pipefd[0]);
|
||||||
spawn(pager, NULL, NULL, NULL, F_CLI);
|
spawn(pager, NULL, NULL, NULL, F_CLI | F_FORCE_TTY);
|
||||||
_exit(EXIT_SUCCESS);
|
_exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4146,7 +4154,7 @@ static bool show_stats(char *fpath)
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
spawn(pager, g_tmpfpath, NULL, NULL, F_CLI);
|
spawn(pager, g_tmpfpath, NULL, NULL, F_CLI | F_FORCE_TTY);
|
||||||
unlink(g_tmpfpath);
|
unlink(g_tmpfpath);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -4669,7 +4677,7 @@ static void show_help(const char *path)
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
spawn(pager, g_tmpfpath, NULL, NULL, F_CLI);
|
spawn(pager, g_tmpfpath, NULL, NULL, F_CLI | F_FORCE_TTY);
|
||||||
unlink(g_tmpfpath);
|
unlink(g_tmpfpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue