[st][PATCH] externalpipe and externalpipein
This patch must be applied on the externalpipe patch. It adds the function externalpipein to redirect the standard output of the external command to the slave size of the pty, that is, as if the external program had been manually executed on the terminal. It can be used to send desired escape sequences to the terminal with a shortcut. I created the patch to make use of the dynamic-colors program (https://github.com/sos4nt/dynamic-colors) that uses the OSC escape sequences to change the colors of the terminal. The program keeps the last colorscheme selected in a file, so you can use it to select the colorscheme for all newly opened terminals from that moment on. If you want to change the color of the background and foreground independently from the palette, you have to merge in the patch for the OSC escape sequences 10, 11, and 12. This patch includes the changes of the externalpipe sigaction patch to prevent reseting the signal handler for SIGCHLD when the proces of the external command exits.
This commit is contained in:
parent
5ad2174cf9
commit
b71d9f6669
|
@ -15,7 +15,7 @@ Refer to [https://st.suckless.org/](https://st.suckless.org/) for details on the
|
||||||
|
|
||||||
### Changelog:
|
### Changelog:
|
||||||
|
|
||||||
2020-04-20 - Added the force redraw on pselect after key is pressed patch and the externalpipe sigaction patch
|
2020-04-20 - Upgrade to c279f5, 2020-04-19, and added the force redraw on pselect after key is pressed patch and the externalpipein patch
|
||||||
|
|
||||||
2020-03-29 - Added invert and workingdir patches
|
2020-03-29 - Added invert and workingdir patches
|
||||||
|
|
||||||
|
@ -60,8 +60,10 @@ Refer to [https://st.suckless.org/](https://st.suckless.org/) for details on the
|
||||||
- [externalpipe](https://st.suckless.org/patches/externalpipe/)
|
- [externalpipe](https://st.suckless.org/patches/externalpipe/)
|
||||||
- this patch allows for eading and writing st's screen through a pipe, e.g. to pass info to dmenu
|
- this patch allows for eading and writing st's screen through a pipe, e.g. to pass info to dmenu
|
||||||
|
|
||||||
- [externalpipe-sigaction](https://lists.suckless.org/hackers/2004/17216.html)
|
- [externalpipein](https://lists.suckless.org/hackers/2004/17218.html)
|
||||||
- this patch prevents the reset of the signal handler set on SIGCHILD, when the forked process that executes the external process exits
|
- this patch prevents the reset of the signal handler set on SIGCHILD, when the forked process that executes the external process exits
|
||||||
|
- it adds the externalpipein function to redirect the standard output of the external command to the slave size of the pty, that is, as if the external program had been manually executed on the terminal
|
||||||
|
- this can be used to send desired escape sequences to the terminal with a shortcut (e.g. to change colors)
|
||||||
|
|
||||||
- [~fixime~](https://st.suckless.org/patches/fix_ime/)
|
- [~fixime~](https://st.suckless.org/patches/fix_ime/)
|
||||||
- adds better Input Method Editor (IME) support
|
- adds better Input Method Editor (IME) support
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
void
|
void
|
||||||
|
#if EXTERNALPIPEIN_PATCH
|
||||||
|
extpipe(const Arg *arg, int in)
|
||||||
|
#else
|
||||||
externalpipe(const Arg *arg)
|
externalpipe(const Arg *arg)
|
||||||
|
#endif // EXTERNALPIPEIN_PATCH
|
||||||
{
|
{
|
||||||
int to[2];
|
int to[2];
|
||||||
char buf[UTF_SIZ];
|
char buf[UTF_SIZ];
|
||||||
|
@ -19,6 +23,11 @@ externalpipe(const Arg *arg)
|
||||||
dup2(to[0], STDIN_FILENO);
|
dup2(to[0], STDIN_FILENO);
|
||||||
close(to[0]);
|
close(to[0]);
|
||||||
close(to[1]);
|
close(to[1]);
|
||||||
|
#if EXTERNALPIPEIN_PATCH
|
||||||
|
if (in)
|
||||||
|
dup2(csdfd, STDOUT_FILENO);
|
||||||
|
close(csdfd);
|
||||||
|
#endif // EXTERNALPIPEIN_PATCH
|
||||||
execvp(((char **)arg->v)[0], (char **)arg->v);
|
execvp(((char **)arg->v)[0], (char **)arg->v);
|
||||||
fprintf(stderr, "st: execvp %s\n", ((char **)arg->v)[0]);
|
fprintf(stderr, "st: execvp %s\n", ((char **)arg->v)[0]);
|
||||||
perror("failed");
|
perror("failed");
|
||||||
|
@ -50,3 +59,15 @@ externalpipe(const Arg *arg)
|
||||||
/* restore */
|
/* restore */
|
||||||
signal(SIGPIPE, oldsigpipe);
|
signal(SIGPIPE, oldsigpipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if EXTERNALPIPEIN_PATCH
|
||||||
|
void
|
||||||
|
externalpipe(const Arg *arg) {
|
||||||
|
extpipe(arg, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
externalpipein(const Arg *arg) {
|
||||||
|
extpipe(arg, 1);
|
||||||
|
}
|
||||||
|
#endif // EXTERNALPIPEIN_PATCH
|
|
@ -1 +1,4 @@
|
||||||
void externalpipe(const Arg *);
|
void externalpipe(const Arg *);
|
||||||
|
#if EXTERNALPIPEIN_PATCH
|
||||||
|
void externalpipein(const Arg *);
|
||||||
|
#endif // EXTERNALPIPEIN_PATCH
|
|
@ -68,12 +68,23 @@
|
||||||
*/
|
*/
|
||||||
#define EXTERNALPIPE_PATCH 0
|
#define EXTERNALPIPE_PATCH 0
|
||||||
|
|
||||||
/* This patch prevents the reset of the signal handler set on SIGCHILD, when
|
/* This patch improves and extends the externalpipe patch in two ways:
|
||||||
* the forked process that executes the external process exits.
|
* - it prevents the reset of the signal handler set on SIGCHILD, when
|
||||||
|
* the forked process that executes the external process exits and
|
||||||
|
* - it adds the externalpipein function to redirect the standard output
|
||||||
|
* of the external command to the slave size of the pty, that is, as if
|
||||||
|
* the external program had been manually executed on the terminal
|
||||||
|
*
|
||||||
|
* It can be used to send desired escape sequences to the terminal with a
|
||||||
|
* keyboard shortcut. The patch was created to make use of the dynamic-colors
|
||||||
|
* tool that uses the OSC escape sequences to change the colors of the terminal.
|
||||||
|
*
|
||||||
* This patch depends on EXTERNALPIPE_PATCH being enabled.
|
* This patch depends on EXTERNALPIPE_PATCH being enabled.
|
||||||
* https://lists.suckless.org/hackers/2004/17216.html
|
*
|
||||||
|
* https://github.com/sos4nt/dynamic-colors
|
||||||
|
* https://lists.suckless.org/hackers/2004/17218.html
|
||||||
*/
|
*/
|
||||||
#define EXTERNALPIPE_SIGACTION_PATCH 0
|
#define EXTERNALPIPEIN_PATCH 0
|
||||||
|
|
||||||
/* This patch allows command line applications to use all the fancy key combinations
|
/* This patch allows command line applications to use all the fancy key combinations
|
||||||
* that are available to GUI applications.
|
* that are available to GUI applications.
|
||||||
|
|
20
st.c
20
st.c
|
@ -245,6 +245,9 @@ static CSIEscape csiescseq;
|
||||||
static STREscape strescseq;
|
static STREscape strescseq;
|
||||||
static int iofd = 1;
|
static int iofd = 1;
|
||||||
static int cmdfd;
|
static int cmdfd;
|
||||||
|
#if EXTERNALPIPEIN_PATCH && EXTERNALPIPE_PATCH
|
||||||
|
static int csdfd;
|
||||||
|
#endif // EXTERNALPIPEIN_PATCH
|
||||||
static pid_t pid;
|
static pid_t pid;
|
||||||
|
|
||||||
static uchar utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0};
|
static uchar utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0};
|
||||||
|
@ -782,16 +785,20 @@ sigchld(int a)
|
||||||
int stat;
|
int stat;
|
||||||
pid_t p;
|
pid_t p;
|
||||||
|
|
||||||
#if EXTERNALPIPE_SIGACTION_PATCH && EXTERNALPIPE_PATCH
|
#if EXTERNALPIPEIN_PATCH && EXTERNALPIPE_PATCH
|
||||||
if ((p = waitpid(-1, &stat, WNOHANG)) < 0)
|
if ((p = waitpid(-1, &stat, WNOHANG)) < 0)
|
||||||
#else
|
#else
|
||||||
if ((p = waitpid(pid, &stat, WNOHANG)) < 0)
|
if ((p = waitpid(pid, &stat, WNOHANG)) < 0)
|
||||||
#endif // EXTERNALPIPE_SIGACTION_PATCH
|
#endif // EXTERNALPIPEIN_PATCH
|
||||||
die("waiting for pid %hd failed: %s\n", pid, strerror(errno));
|
die("waiting for pid %hd failed: %s\n", pid, strerror(errno));
|
||||||
|
|
||||||
if (pid != p)
|
if (pid != p)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
#if EXTERNALPIPEIN_PATCH && EXTERNALPIPE_PATCH
|
||||||
|
close(csdfd);
|
||||||
|
#endif // EXTERNALPIPEIN_PATCH
|
||||||
|
|
||||||
if (WIFEXITED(stat) && WEXITSTATUS(stat))
|
if (WIFEXITED(stat) && WEXITSTATUS(stat))
|
||||||
die("child exited with status %d\n", WEXITSTATUS(stat));
|
die("child exited with status %d\n", WEXITSTATUS(stat));
|
||||||
else if (WIFSIGNALED(stat))
|
else if (WIFSIGNALED(stat))
|
||||||
|
@ -827,9 +834,9 @@ int
|
||||||
ttynew(char *line, char *cmd, char *out, char **args)
|
ttynew(char *line, char *cmd, char *out, char **args)
|
||||||
{
|
{
|
||||||
int m, s;
|
int m, s;
|
||||||
#if EXTERNALPIPE_SIGACTION_PATCH && EXTERNALPIPE_PATCH
|
#if EXTERNALPIPEIN_PATCH && EXTERNALPIPE_PATCH
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
#endif // EXTERNALPIPE_SIGACTION_PATCH
|
#endif // EXTERNALPIPEIN_PATCH
|
||||||
|
|
||||||
if (out) {
|
if (out) {
|
||||||
term.mode |= MODE_PRINT;
|
term.mode |= MODE_PRINT;
|
||||||
|
@ -885,14 +892,15 @@ ttynew(char *line, char *cmd, char *out, char **args)
|
||||||
#endif
|
#endif
|
||||||
close(s);
|
close(s);
|
||||||
cmdfd = m;
|
cmdfd = m;
|
||||||
#if EXTERNALPIPE_SIGACTION_PATCH && EXTERNALPIPE_PATCH
|
#if EXTERNALPIPEIN_PATCH && EXTERNALPIPE_PATCH
|
||||||
|
csdfd = s;
|
||||||
memset(&sa, 0, sizeof(sa));
|
memset(&sa, 0, sizeof(sa));
|
||||||
sigemptyset(&sa.sa_mask);
|
sigemptyset(&sa.sa_mask);
|
||||||
sa.sa_handler = sigchld;
|
sa.sa_handler = sigchld;
|
||||||
sigaction(SIGCHLD, &sa, NULL);
|
sigaction(SIGCHLD, &sa, NULL);
|
||||||
#else
|
#else
|
||||||
signal(SIGCHLD, sigchld);
|
signal(SIGCHLD, sigchld);
|
||||||
#endif // EXTERNALPIPE_SIGACTION_PATCH
|
#endif // EXTERNALPIPEIN_PATCH
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return cmdfd;
|
return cmdfd;
|
||||||
|
|
Loading…
Reference in New Issue