From 80d5dee9a86ac8ec52d0b9c2b5a56498ed2d7988 Mon Sep 17 00:00:00 2001 From: JacobBarthelmeh Date: Tue, 7 Nov 2023 23:33:36 -0800 Subject: [PATCH] update example client shell settings --- examples/client/common.c | 55 +++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/examples/client/common.c b/examples/client/common.c index 671532a4d..3ae6a7316 100644 --- a/examples/client/common.c +++ b/examples/client/common.c @@ -542,27 +542,46 @@ int ClientSetEcho(int type) } echoInit = 1; } - if (type == 1) { - if (tcsetattr(STDIN_FILENO, TCSANOW, &originalTerm) != 0) { - printf("Couldn't restore the terminal settings.\n"); - return -1; - } - } - else { - struct termios newTerm; - memcpy(&newTerm, &originalTerm, sizeof(struct termios)); - - newTerm.c_lflag &= ~ECHO; - if (type == 2) { - newTerm.c_lflag &= ~(ICANON | ECHOE | ECHOK | ECHONL | ISIG); + if (echoInit) { + if (type == 1) { + if (tcsetattr(STDIN_FILENO, TCSANOW, &originalTerm) != 0) { + printf("Couldn't restore the terminal settings.\n"); + return -1; + } } else { - newTerm.c_lflag |= (ICANON | ECHONL); - } + struct termios newTerm; + memcpy(&newTerm, &originalTerm, sizeof(struct termios)); + + newTerm.c_lflag &= ~ECHO; + if (type == 2) { + newTerm.c_lflag &= ~(ICANON | ISIG | IEXTEN | ECHO | ECHOE + | ECHOK | ECHONL | ECHOPRT | NOFLSH | TOSTOP | FLUSHO + | PENDIN | EXTPROC); + + newTerm.c_iflag &= ~(ISTRIP | INLCR | ICRNL | IGNCR | IXON + | IXOFF | IXANY | IGNBRK | INPCK | PARMRK); + #ifdef IUCLC + newTerm.c_iflag &= ~IUCLC; + #endif + newTerm.c_iflag |= IGNPAR; - if (tcsetattr(STDIN_FILENO, TCSANOW, &newTerm) != 0) { - printf("Couldn't turn off echo.\n"); - return -1; + newTerm.c_oflag &= ~(OPOST | ONOCR | ONLRET); + #ifdef OUCLC + newTerm.c_oflag &= ~OLCUC; + #endif + + newTerm.c_cflag &= ~(CSTOPB | PARENB | PARODD | CLOCAL + | CRTSCTS); + } + else { + newTerm.c_lflag |= (ICANON | ECHONL); + } + + if (tcsetattr(STDIN_FILENO, TCSANOW, &newTerm) != 0) { + printf("Couldn't turn off echo.\n"); + return -1; + } } } #else