commit afd762fabb08a2afc1230bec321756d7c2946764
Author:     Tom Schwindl <[email protected]>
AuthorDate: Sat Sep 17 16:07:48 2022 +0200
Commit:     Jan Klemkow <[email protected]>
CommitDate: Tue Oct 4 08:04:22 2022 +0200

    lchat: clean up terminal preparation
    
    - reuse the value of `origin_term' instead of calling tcgetattr(3) twice
    - change the following termios flags:
      IMAXBEL - is an extension and does not provide much "real" value
      OPOST - is mostly IB and thus not very useful
      ECHONL - only has an effect if ICANON is set, which isn't the case for us

diff --git a/lchat.c b/lchat.c
index 9f505f1..7e95c8c 100644
--- a/lchat.c
+++ b/lchat.c
@@ -25,7 +25,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <term.h>
 #include <termios.h>
 #include <unistd.h>
 
@@ -248,21 +247,18 @@ main(int argc, char *argv[])
        else
                printf("\033]0;%s\a", title);
 
-       /* preprate terminal reset on exit */
+       /* prepare terminal reset on exit */
        if (tcgetattr(fd, &origin_term) == -1)
                die("tcgetattr:");
 
+       term = origin_term;
+
        if (atexit(exit_handler) == -1)
                die("atexit:");
 
-       /* prepare terminal */
-       if (tcgetattr(fd, &term) == -1)
-               die("tcgetattr:");
-
-       /* TODO: clean up this block.  copied from cfmakeraw(3) */
-       term.c_iflag &= ~(IMAXBEL|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
-//        term.c_oflag &= ~OPOST;
-       term.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN);
+       term.c_iflag &= ~(BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
+       term.c_oflag &= ~OPOST;
+       term.c_lflag &= ~(ECHO|ICANON|IEXTEN);
        term.c_cflag &= ~(CSIZE|PARENB);
        term.c_cflag |= CS8;
        term.c_cc[VMIN] = 1;

Reply via email to