1 #include "jline_WindowsTerminal.h"
2 #include <windows.h>
3
Java_jline_WindowsTerminal_getConsoleMode(JNIEnv * env,jobject ob)4 JNIEXPORT jint JNICALL Java_jline_WindowsTerminal_getConsoleMode
5 (JNIEnv *env, jobject ob)
6 {
7 DWORD mode;
8 HANDLE hConsole = GetStdHandle (STD_INPUT_HANDLE);
9
10 if (hConsole == INVALID_HANDLE_VALUE)
11 return -1;
12
13 if (!GetConsoleMode (hConsole, &mode))
14 return -1;
15
16 // CloseHandle (hConsole);
17
18 // printf ("JNI get mode=%d\n", mode);
19 return mode;
20 }
21
Java_jline_WindowsTerminal_setConsoleMode(JNIEnv * env,jobject ob,jint mode)22 JNIEXPORT void JNICALL Java_jline_WindowsTerminal_setConsoleMode
23 (JNIEnv *env, jobject ob, jint mode)
24 {
25 DWORD m = (DWORD)mode;
26 HANDLE hConsole = GetStdHandle (STD_INPUT_HANDLE);
27
28 if (hConsole == INVALID_HANDLE_VALUE)
29 return;
30
31 // printf ("JNI set mode=%d\n", m);
32 SetConsoleMode (hConsole, m);
33 // CloseHandle (hConsole);
34 }
35
Java_jline_WindowsTerminal_readByte(JNIEnv * env,jclass class)36 JNIEXPORT jint JNICALL Java_jline_WindowsTerminal_readByte (JNIEnv * env, jclass class)
37 {
38 return getch ();
39 }
40
Java_jline_WindowsTerminal_getWindowsTerminalWidth(JNIEnv * env,jclass class)41 JNIEXPORT jint JNICALL Java_jline_WindowsTerminal_getWindowsTerminalWidth (JNIEnv * env, jclass class)
42 {
43 HANDLE inputHandle = GetStdHandle (STD_INPUT_HANDLE);
44 HANDLE outputHandle = GetStdHandle (STD_OUTPUT_HANDLE);
45 PCONSOLE_SCREEN_BUFFER_INFO info = malloc (sizeof (CONSOLE_SCREEN_BUFFER_INFO));
46 GetConsoleScreenBufferInfo (outputHandle, info);
47 return info->srWindow.Right - info->srWindow.Left+1;
48 }
49
Java_jline_WindowsTerminal_getWindowsTerminalHeight(JNIEnv * env,jclass class)50 JNIEXPORT jint JNICALL Java_jline_WindowsTerminal_getWindowsTerminalHeight (JNIEnv * env, jclass class)
51 {
52 HANDLE inputHandle = GetStdHandle (STD_INPUT_HANDLE);
53 HANDLE outputHandle = GetStdHandle (STD_OUTPUT_HANDLE);
54 PCONSOLE_SCREEN_BUFFER_INFO info = malloc (sizeof (CONSOLE_SCREEN_BUFFER_INFO));
55 GetConsoleScreenBufferInfo (outputHandle, info);
56 return info->srWindow.Bottom - info->srWindow.Top+1;
57 }
58