Skip to content

Commit

Permalink
update example client shell settings
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobBarthelmeh committed Dec 11, 2023
1 parent c382240 commit 80d5dee
Showing 1 changed file with 37 additions and 18 deletions.
55 changes: 37 additions & 18 deletions examples/client/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 80d5dee

Please sign in to comment.