Skip to content

Instantly share code, notes, and snippets.

@michael-grunder
Created December 13, 2022 05:24
Show Gist options
  • Save michael-grunder/28169ad4a3e3523499450a4f81c529e0 to your computer and use it in GitHub Desktop.
Save michael-grunder/28169ad4a3e3523499450a4f81c529e0 to your computer and use it in GitHub Desktop.
The exact same functionality, but not waiting for carriage return
#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