From a81588b1f7cc00cb18a243feb04fba96c7031e1f Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Mon, 8 Jul 2019 20:17:58 -0400 Subject: Add ^S toggle to ptee --- bin/man1/ptee.1 | 5 +++++ bin/ptee.c | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'bin') diff --git a/bin/man1/ptee.1 b/bin/man1/ptee.1 index 3c9ab568..a38d61c7 100644 --- a/bin/man1/ptee.1 +++ b/bin/man1/ptee.1 @@ -23,6 +23,11 @@ and standard output. Standard output must be redirected to a file or pipe. . +.Pp +Type +.Ic ^S +to toggle writing to standard output. +. .Sh SEE ALSO .Xr tee 1 . diff --git a/bin/ptee.c b/bin/ptee.c index c187ba92..a5f9d954 100644 --- a/bin/ptee.c +++ b/bin/ptee.c @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -65,6 +66,8 @@ int main(int argc, char *argv[]) { err(EX_NOINPUT, "%s", argv[1]); } + bool stop = false; + byte buf[4096]; struct pollfd fds[2] = { { .events = POLLIN, .fd = STDIN_FILENO }, @@ -74,6 +77,12 @@ int main(int argc, char *argv[]) { if (fds[0].revents & POLLIN) { ssize_t rlen = read(STDIN_FILENO, buf, sizeof(buf)); if (rlen < 0) err(EX_IOERR, "read"); + + if (rlen == 1 && buf[0] == CTRL('S')) { + stop ^= true; + continue; + } + ssize_t wlen = write(pty, buf, rlen); if (wlen < 0) err(EX_IOERR, "write"); } @@ -85,8 +94,10 @@ int main(int argc, char *argv[]) { ssize_t wlen = write(STDIN_FILENO, buf, rlen); if (wlen < 0) err(EX_IOERR, "write"); - wlen = write(STDOUT_FILENO, buf, rlen); - if (wlen < 0) err(EX_IOERR, "write"); + if (!stop) { + wlen = write(STDOUT_FILENO, buf, rlen); + if (wlen < 0) err(EX_IOERR, "write"); + } } int status; -- cgit 1.4.1