summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--bin/man1/ptee.15
-rw-r--r--bin/ptee.c15
2 files changed, 18 insertions, 2 deletions
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 ee035e8a..94be3037 100644
--- a/bin/ptee.c
+++ b/bin/ptee.c
@@ -16,6 +16,7 @@
 
 #include <err.h>
 #include <poll.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/ioctl.h>
@@ -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;
an title='2020-02-26 17:02:49 -0500'>2020-02-26Add Fierce Femmes and Notorious LiarsJune McEnroe 2020-02-23Add This Is How You Lose the Time WarJune McEnroe 2020-02-22Add See Ya LaterJune McEnroe 2020-02-20Remove wiki scriptJune McEnroe 2020-02-19Add The Obelisk GateJune McEnroe 2020-02-17Add Four Tet — HandsJune McEnroe 2020-02-12Simplify macOS notify-sendJune McEnroe 2020-02-12Add imbox and notemap to pageJune McEnroe 2020-02-12Collapse simple linksJune McEnroe 2020-02-12Move catgirl up the pageJune McEnroe 2020-02-12Update catgirl pty grabJune McEnroe 2020-02-12Link to cgit /about pages where appropriateJune McEnroe 2020-02-11Separate LINKS from BINS for html to workJune McEnroe 2020-02-11Add margin to Bl-bullet itemsJune McEnroe 2020-02-10Match URLs inside parens or with paired parens insideJune McEnroe 2020-02-10Duplicate effective URL before passing it back to curlJune McEnroe 2020-02-09Add To Be Taught, If FortunateJune McEnroe 2020-02-04Add The Future of Another TimelineJune McEnroe 2020-01-31Reorganize the Makefile for the umpteenth timeJune McEnroe 2020-01-28Change scout sensitivity to 1.4June McEnroe 2020-01-28Import shows.txtJune McEnroe