add key to insert text selected with dmenu as terminal input
This commit is contained in:
46
st.c
46
st.c
@@ -2117,9 +2117,9 @@ strparse(void)
|
||||
}
|
||||
|
||||
void
|
||||
externalpipe(const Arg *arg)
|
||||
externalpipeinout(const Arg *arg, void (*processout)(int fildes))
|
||||
{
|
||||
int to[2];
|
||||
int to[2], from[2];
|
||||
char buf[UTF_SIZ];
|
||||
void (*oldsigpipe)(int);
|
||||
Glyph *bp, *end;
|
||||
@@ -2127,16 +2127,27 @@ externalpipe(const Arg *arg)
|
||||
|
||||
if (pipe(to) == -1)
|
||||
return;
|
||||
if (processout != NULL && pipe(from) == -1)
|
||||
return;
|
||||
|
||||
switch (fork()) {
|
||||
case -1:
|
||||
close(to[0]);
|
||||
close(to[1]);
|
||||
if (processout != NULL) {
|
||||
close(from[0]);
|
||||
close(from[1]);
|
||||
}
|
||||
return;
|
||||
case 0:
|
||||
dup2(to[0], STDIN_FILENO);
|
||||
close(to[0]);
|
||||
close(to[1]);
|
||||
if (processout != NULL) {
|
||||
dup2(from[1], STDOUT_FILENO);
|
||||
close(from[0]);
|
||||
close(from[1]);
|
||||
}
|
||||
execvp(((char **)arg->v)[0], (char **)arg->v);
|
||||
fprintf(stderr, "st: execvp %s\n", ((char **)arg->v)[0]);
|
||||
perror("failed");
|
||||
@@ -2144,6 +2155,8 @@ externalpipe(const Arg *arg)
|
||||
}
|
||||
|
||||
close(to[0]);
|
||||
if (processout != NULL)
|
||||
close(from[1]);
|
||||
/* ignore sigpipe for now, in case child exists early */
|
||||
oldsigpipe = signal(SIGPIPE, SIG_IGN);
|
||||
newline = 0;
|
||||
@@ -2165,10 +2178,39 @@ externalpipe(const Arg *arg)
|
||||
if (newline)
|
||||
(void)xwrite(to[1], "\n", 1);
|
||||
close(to[1]);
|
||||
if (processout != NULL) {
|
||||
processout(from[0]);
|
||||
close(from[0]);
|
||||
}
|
||||
/* restore */
|
||||
signal(SIGPIPE, oldsigpipe);
|
||||
}
|
||||
|
||||
void
|
||||
externalpipe(const Arg *arg)
|
||||
{
|
||||
externalpipeinout(arg, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
ttycopy(int fildes)
|
||||
{
|
||||
char buf[256];
|
||||
int len;
|
||||
|
||||
len = read(fildes, buf, sizeof(buf));
|
||||
if (len > 0 && len < sizeof(buf)) {
|
||||
buf[len] = '\0';
|
||||
ttywrite(buf, len, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
externalpipettycopy(const Arg *arg)
|
||||
{
|
||||
externalpipeinout(arg, ttycopy);
|
||||
}
|
||||
|
||||
void
|
||||
strdump(void)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user