File tree Expand file tree Collapse file tree 1 file changed +8
-13
lines changed Expand file tree Collapse file tree 1 file changed +8
-13
lines changed Original file line number Diff line number Diff line change 23
23
24
24
#ifdef __WIN32
25
25
#include <windows.h>
26
+ #include <conio.h>
26
27
#else
27
28
#include <termios.h>
28
29
#include <unistd.h>
@@ -51,23 +52,17 @@ void fossil_io_trim(char *str) {
51
52
}
52
53
53
54
char fossil_io_getch (void ) {
54
- #ifdef __WIN32
55
- DWORD mode ;
56
- HANDLE hCon = GetStdHandle (STD_INPUT_HANDLE );
57
- GetConsoleMode (hCon , & mode );
58
- SetConsoleMode (hCon , mode & ~ENABLE_ECHO_INPUT );
59
- char ch = _getch ();
60
- SetConsoleMode (hCon , mode );
61
- return ch ;
55
+ #ifdef _WIN32
56
+ return _getch (); // Windows version
62
57
#else
63
58
struct termios oldt , newt ;
64
59
char ch ;
65
- tcgetattr (STDIN_FILENO , & oldt );
60
+ tcgetattr (STDIN_FILENO , & oldt ); // Save current terminal settings
66
61
newt = oldt ;
67
- newt .c_lflag &= ~(ICANON | ECHO ); // Disable echo and canonical mode
68
- tcsetattr (STDIN_FILENO , TCSANOW , & newt );
69
- ch = getchar ();
70
- tcsetattr (STDIN_FILENO , TCSANOW , & oldt ); // Restore terminal settings
62
+ newt .c_lflag &= ~(ICANON | ECHO ); // Disable canonical mode and echo
63
+ tcsetattr (STDIN_FILENO , TCSANOW , & newt ); // Apply the new settings
64
+ ch = getchar (); // Read the character
65
+ tcsetattr (STDIN_FILENO , TCSANOW , & oldt ); // Restore the original settings
71
66
return ch ;
72
67
#endif
73
68
}
You can’t perform that action at this time.
0 commit comments