转:
https://blog.csdn.net/liuqz2009/article/details/51967763
https://www.cnblogs.com/einstein-2014731/p/6922977.html
struct termios new_settings;
struct termios stored_settings;
tcgetattr(0,&stored_settings);
new_settings = stored_settings;
new_settings.c_lflag &= (~ICANON);
new_settings.c_cc[VTIME] = 0;
tcgetattr(0,&stored_settings);
new_settings.c_cc[VMIN] = 1;
tcsetattr(0,TCSANOW,&new_settings);
tcsetattr(0,TCSANOW,&stored_settings);