Skip to content

Commit 43b9bb8

Browse files
Update input.c
1 parent 5fc2d68 commit 43b9bb8

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

code/logic/input.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
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

5354
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
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
}

0 commit comments

Comments
 (0)