-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetch.h
More file actions
39 lines (34 loc) · 820 Bytes
/
Copy pathgetch.h
File metadata and controls
39 lines (34 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* UNLICENSED */
#include <sys/ioctl.h>
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
static struct termios old, current;
/* Initialize new terminal i/o settings */
void
initTermios(int echo)
{
tcgetattr(0, &old); /* grab old terminal i/o settings */
current = old; /* make new settings same as old settings */
current.c_lflag &= ~ICANON; /* disable buffered i/o */
if(echo)
current.c_lflag |= ECHO; /* set echo mode */
else
current.c_lflag &= ~ECHO; /* set no echo mode */
tcsetattr(0, TCSANOW, ¤t); /* use these new terminal i/o settings now */
}
/* Restore old terminal i/o settings */
void
resetTermios(void)
{
tcsetattr(0, TCSANOW, &old);
}
char
getch(char echo)
{
char ch;
initTermios(echo);
ch = getchar();
resetTermios();
return ch;
}