Created
December 13, 2022 05:24
-
-
Save michael-grunder/28169ad4a3e3523499450a4f81c529e0 to your computer and use it in GitHub Desktop.
The exact same functionality, but not waiting for carriage return
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <termios.h> | |
#include <unistd.h> | |
/* If it is the carriage return thing, here is the exact same | |
* functionality, but also setting termio. | |
* NOTE: I have no idea what the performance implications of calling | |
* `tcgetaddr`/`tcsetaddr` for this little routine would be | |
* or whether it is acceptable in your situation. | |
*/ | |
void li1c( char * c) { | |
static struct termios old, new; | |
tcgetattr(STDIN_FILENO, &old); | |
new = old; | |
new.c_lflag &= ~(ICANON); | |
tcsetattr(STDIN_FILENO, TCSANOW, &new); | |
*(c++) = getc(stdin); | |
*c = '\0'; | |
tcsetattr( STDIN_FILENO, TCSANOW, &old); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment