Skip to content

Commit f03f0bf

Browse files
committed
Add reference link
1 parent 6304d0a commit f03f0bf

1 file changed

Lines changed: 15 additions & 17 deletions

File tree

‎c/getch/include/getch.h‎

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <stdio.h>
2+
// https://sourceforge.net/p/predef/wiki/OperatingSystems/
23
#if defined(_WIN16) || defined(_WIN32) || defined(_WIN64)
34

45
#include <conio.h>
@@ -13,25 +14,24 @@
1314
* 得到用户输入的一个字符
1415
* : 返回得到字符
1516
*/
16-
int sh_getch(void)
17-
{
18-
int cr;
19-
struct termios nts, ots;
17+
int sh_getch(void) {
18+
int cr;
19+
struct termios nts, ots;
2020

21-
if (tcgetattr(0, &ots) < 0) // 得到当前终端(0表示标准输入)的设置
22-
return EOF;
21+
if (tcgetattr(0, &ots) < 0) // 得到当前终端(0表示标准输入)的设置
22+
return EOF;
2323

24-
nts = ots;
25-
cfmakeraw(&nts);
26-
// 设置终端为Raw原始模式,该模式下所有的输入数据以字节为单位被处理
27-
if (tcsetattr(0, TCSANOW, &nts) < 0) // 设置上更改之后的设置
28-
return EOF;
24+
nts = ots;
25+
cfmakeraw(&nts);
26+
// 设置终端为Raw原始模式,该模式下所有的输入数据以字节为单位被处理
27+
if (tcsetattr(0, TCSANOW, &nts) < 0) // 设置上更改之后的设置
28+
return EOF;
2929

30-
cr = getchar();
31-
if (tcsetattr(0, TCSANOW, &ots) < 0) // 设置还原成老的模式
32-
return EOF;
30+
cr = getchar();
31+
if (tcsetattr(0, TCSANOW, &ots) < 0) // 设置还原成老的模式
32+
return EOF;
3333

34-
return cr;
34+
return cr;
3535
}
3636

3737
#elif defined(__APPLE__)
@@ -41,8 +41,6 @@ int sh_getch(void)
4141

4242
#endif
4343

44-
45-
4644
// https://www.cnblogs.com/life2refuel/p/5720043.html
4745
// /*
4846
// * error => 以后再说

0 commit comments

Comments
 (0)