summaryrefslogtreecommitdiffhomepage
path: root/src/blog/termios/enable-xoff-xon.diff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-10-28 02:18:06 +0100
committerThomas Voss <mail@thomasvoss.com> 2024-10-28 02:18:06 +0100
commit083b0b53e450f317ca6e99cc1d077b10a5ac7d4d (patch)
treee6d9a96901caa2abbb37644fff4311d8d1c0f572 /src/blog/termios/enable-xoff-xon.diff
parent8f2f9f53b88c451d8b8cb3aa7ee4302ef4c9278d (diff)
Add a new article on termios
Diffstat (limited to 'src/blog/termios/enable-xoff-xon.diff')
-rw-r--r--src/blog/termios/enable-xoff-xon.diff47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/blog/termios/enable-xoff-xon.diff b/src/blog/termios/enable-xoff-xon.diff
new file mode 100644
index 0000000..64841d2
--- /dev/null
+++ b/src/blog/termios/enable-xoff-xon.diff
@@ -0,0 +1,47 @@
+ #include <curses.h>
+ #include <stdio.h>
++#include <stdlib.h>
+ #include <termios.h>
+ #include <unistd.h>
+ #include <vis.h>
+
++static void restore_tcattrs(void);
++
++struct termios old_attrs;
++
+ int
+ main(void)
+ {
+ struct termios tp;
+ tcgetattr(STDIN_FILENO, &tp);
++ old_attrs = tp;
+ tp.c_iflag &= ~(IXANY | IXON | IXOFF);
+ tcsetattr(STDIN_FILENO, TCSANOW, &tp);
++ atexit(restore_tcattrs);
+
+ initscr(); /* Init screen */
+ noecho(); /* Don’t echo keypresses */
+@@ -25,19 +18,10 @@
+ for (;;) {
+ /* Read char and encode it as a string */
+ char buf[5];
++ int ch = getch();
++ if (ch == '\x11') /* ^Q */
++ break;
++ vis(buf, ch, VIS_WHITE, 0);
+- vis(buf, getch(), VIS_WHITE, 0);
+
+ clear(); /* Clear screen */
+ printw("%s\n", buf); /* Write char to screen */
+ refresh(); /* Refresh display */
+ }
+- /* unreachable */
++ endwin(); /* Destroy screen */
++ return EXIT_SUCCESS;
+ }
++
++void
++restore_tcattrs(void)
++{
++ tcsetattr(STDIN_FILENO, TCSANOW, &old_attrs);
++}