Commit abb2f9d978230f2208bff0af1e7107caab2b4abd

Adrian Perez de Castro 2019-08-05T15:44:33

MSVC: Provide implementations of test_{dis,en}able_stdin_echo This provides implementations of the test_enable_stdin_echo and test_disable_stdin_echo which do not require <termios.h>, which is not available on Windows.

diff --git a/test/common.c b/test/common.c
index 446ce58..15a4fe0 100644
--- a/test/common.c
+++ b/test/common.c
@@ -34,14 +34,15 @@
 
 #include <limits.h>
 #include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 #ifdef _MSC_VER
 #include <io.h>
+#include <windows.h>
 #else
 #include <unistd.h>
-#endif
-#include <sys/types.h>
-#include <sys/stat.h>
 #include <termios.h>
+#endif
 
 #include "test.h"
 #include "utils.h"
@@ -468,6 +469,25 @@ test_print_state_changes(enum xkb_state_component changed)
     printf("]\n");
 }
 
+#ifdef _MSC_VER
+void
+test_disable_stdin_echo(void)
+{
+    HANDLE stdin_handle = GetStdHandle(STD_INPUT_HANDLE);
+    DWORD mode = 0;
+    GetConsoleMode(stdin_handle, &mode);
+    SetConsoleMode(stdin_handle, mode & ~ENABLE_ECHO_INPUT);
+}
+
+void
+test_enable_stdin_echo(void)
+{
+    HANDLE stdin_handle = GetStdHandle(STD_INPUT_HANDLE);
+    DWORD mode = 0;
+    GetConsoleMode(stdin_handle, &mode);
+    SetConsoleMode(stdin_handle, mode | ENABLE_ECHO_INPUT);
+}
+#else
 void
 test_disable_stdin_echo(void)
 {
@@ -489,3 +509,4 @@ test_enable_stdin_echo(void)
         (void) tcsetattr(STDIN_FILENO, TCSADRAIN, &termios);
     }
 }
+#endif