[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:
bakkeby 2020-04-20 13:06:39 +02:00
parent 5ad2174cf9
commit b71d9f6669
5 changed files with 59 additions and 14 deletions

20
st.c
View file

@ -245,6 +245,9 @@ static CSIEscape csiescseq;
static STREscape strescseq;
static int iofd = 1;
static int cmdfd;
#if EXTERNALPIPEIN_PATCH && EXTERNALPIPE_PATCH
static int csdfd;
#endif // EXTERNALPIPEIN_PATCH
static pid_t pid;
static uchar utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0};
@ -782,16 +785,20 @@ sigchld(int a)
int stat;
pid_t p;
#if EXTERNALPIPE_SIGACTION_PATCH && EXTERNALPIPE_PATCH
#if EXTERNALPIPEIN_PATCH && EXTERNALPIPE_PATCH
if ((p = waitpid(-1, &stat, WNOHANG)) < 0)
#else
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));
if (pid != p)
return;
#if EXTERNALPIPEIN_PATCH && EXTERNALPIPE_PATCH
close(csdfd);
#endif // EXTERNALPIPEIN_PATCH
if (WIFEXITED(stat) && WEXITSTATUS(stat))
die("child exited with status %d\n", WEXITSTATUS(stat));
else if (WIFSIGNALED(stat))
@ -827,9 +834,9 @@ int
ttynew(char *line, char *cmd, char *out, char **args)
{
int m, s;
#if EXTERNALPIPE_SIGACTION_PATCH && EXTERNALPIPE_PATCH
#if EXTERNALPIPEIN_PATCH && EXTERNALPIPE_PATCH
struct sigaction sa;
#endif // EXTERNALPIPE_SIGACTION_PATCH
#endif // EXTERNALPIPEIN_PATCH
if (out) {
term.mode |= MODE_PRINT;
@ -885,14 +892,15 @@ ttynew(char *line, char *cmd, char *out, char **args)
#endif
close(s);
cmdfd = m;
#if EXTERNALPIPE_SIGACTION_PATCH && EXTERNALPIPE_PATCH
#if EXTERNALPIPEIN_PATCH && EXTERNALPIPE_PATCH
csdfd = s;
memset(&sa, 0, sizeof(sa));
sigemptyset(&sa.sa_mask);
sa.sa_handler = sigchld;
sigaction(SIGCHLD, &sa, NULL);
#else
signal(SIGCHLD, sigchld);
#endif // EXTERNALPIPE_SIGACTION_PATCH
#endif // EXTERNALPIPEIN_PATCH
break;
}
return cmdfd;