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 2323
2424#ifdef __WIN32
2525#include <windows.h>
26+ #include <conio.h>
2627#else
2728#include <termios.h>
2829#include <unistd.h>
@@ -51,23 +52,17 @@ void fossil_io_trim(char *str) {
5152}
5253
5354char 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
6257#else
6358 struct termios oldt , newt ;
6459 char ch ;
65- tcgetattr (STDIN_FILENO , & oldt );
60+ tcgetattr (STDIN_FILENO , & oldt ); // Save current terminal settings
6661 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
7166 return ch ;
7267#endif
7368}
You can’t perform that action at this time.
0 commit comments