summary refs log tree commit diff
path: root/bin/ptee.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-07-08 20:17:58 -0400
committerJune McEnroe <june@causal.agency>2019-07-08 20:17:58 -0400
commit0cf9bedd250bd983c05c3d319d9cf2516af531ea (patch)
tree37fa3043db76cfa3e7f56944df1501d0881ff0f1 /bin/ptee.c
parentDocument lack of window size propagation (diff)
downloadsrc-0cf9bedd250bd983c05c3d319d9cf2516af531ea.tar.gz
src-0cf9bedd250bd983c05c3d319d9cf2516af531ea.zip
Add ^S toggle to ptee
Diffstat (limited to '')
-rw-r--r--bin/ptee.c15
1 files changed, 13 insertions, 2 deletions
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;