From 0cf9bedd250bd983c05c3d319d9cf2516af531ea Mon Sep 17 00:00:00 2001 From: June 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 ee035e8a..94be3037 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 w=1'>diff
Commit message (Expand)Author
2022-02-26Only add available commands to completeJune McEnroe
2022-02-26Factor out commandAvailableJune McEnroe
2022-02-23Give examples of "general events" 2.1June McEnroe
2022-02-23Add missing unistd.h include in input.cJune McEnroe
2022-02-22Document the interfaceJune McEnroe
2022-02-20Clean up unimplemented editing mode stuffJune McEnroe
2022-02-20Save input buffer contentsJune McEnroe
2022-02-20Share a cut buffer between all edit buffersJune McEnroe
2022-02-20Assert return values in edit testsJune McEnroe
2022-02-20Move mbs out of struct Edit, use a global bufferJune McEnroe
2022-02-20Clear edit buffer before running commandJune McEnroe
2022-02-20Show indicator in status when window has pending inputJune McEnroe
2022-02-20Use separate edit buffers for each IDJune McEnroe
2022-02-20Make sure new cap is actually larger than new lengthJune McEnroe
2022-02-20Remove unused mbs.len field from struct EditJune McEnroe
2022-02-19Remove unneeded includes in ui.cJune McEnroe
2022-02-19Reimplement tab completeJune McEnroe
2022-02-19Handle errors from editFn, etc.June McEnroe
2022-02-19Reimplement text macrosJune McEnroe
2022-02-19Factor out input handling to input.cJune McEnroe
2022-02-19Factor out window management to window.cJune McEnroe
2022-02-19Enable -Wmissing-prototypesJune McEnroe
2022-02-19Fix edit.[ch] license notice additional permissionsJune McEnroe
2022-02-19Run line editing testsJune McEnroe
2022-02-18Implement new line editing "library"June McEnroe
2022-02-18Simplify cursor positioning in inputJune McEnroe
2022-02-18Fix M-f orderingJune McEnroe
2022-02-12Move sandman build to scripts/MakefileJune McEnroe
2022-02-12Use compat_readpassphrase.c on LinuxJune McEnroe
2022-02-12Copy RPP defines from oconfigureJune McEnroe