--- a/src/jdk.internal.le/windows/native/lible/WindowsTerminal.cpp Fri Jun 01 11:34:13 2018 +0200
+++ b/src/jdk.internal.le/windows/native/lible/WindowsTerminal.cpp Fri Jun 01 13:04:30 2018 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -34,6 +34,8 @@
static jclass recordClass;
static jmethodID recordConstructor;
+static jclass bufferStateClass;
+static jmethodID bufferStateConstructor;
JNIEXPORT void JNICALL Java_jdk_internal_jline_WindowsTerminal_initIDs
(JNIEnv *env, jclass) {
@@ -43,6 +45,12 @@
CHECK_NULL(recordClass);
recordConstructor = env->GetMethodID(cls, "<init>", "(ZCIII)V");
CHECK_NULL(recordConstructor);
+ cls = env->FindClass("jdk/internal/jline/extra/AnsiInterpretingOutputStream$BufferState");
+ CHECK_NULL(cls);
+ bufferStateClass = (jclass) env->NewGlobalRef(cls);
+ CHECK_NULL(bufferStateClass);
+ bufferStateConstructor = env->GetMethodID(cls, "<init>", "(IIII)V");
+ CHECK_NULL(bufferStateConstructor);
}
JNIEXPORT jint JNICALL Java_jdk_internal_jline_WindowsTerminal_getConsoleMode
@@ -81,8 +89,6 @@
return NULL;
}
if (record.EventType == KEY_EVENT) {
- jclass clazz = env->FindClass("jdk/internal/jline/WindowsTerminal$KEY_EVENT_RECORD");
- jmethodID constr = env->GetMethodID(clazz, "<init>", "(ZCIII)V");
return env->NewObject(recordClass,
recordConstructor,
record.Event.KeyEvent.bKeyDown,
@@ -125,3 +131,31 @@
}
return info.srWindow.Bottom - info.srWindow.Top + 1;
}
+
+JNIEXPORT jobject JNICALL Java_jdk_internal_jline_WindowsTerminal_getBufferState
+ (JNIEnv *env, jobject) {
+ HANDLE hStdOut;
+ if ((hStdOut = GetStdHandle(STD_OUTPUT_HANDLE)) == INVALID_HANDLE_VALUE) {
+ return NULL;
+ }
+ CONSOLE_SCREEN_BUFFER_INFO info;
+ if (! GetConsoleScreenBufferInfo(hStdOut, &info)) {
+ return NULL;
+ }
+ return env->NewObject(bufferStateClass,
+ bufferStateConstructor,
+ info.dwCursorPosition.X,
+ info.dwCursorPosition.Y,
+ info.dwSize.X,
+ info.dwSize.Y);
+}
+
+JNIEXPORT void JNICALL Java_jdk_internal_jline_WindowsTerminal_setCursorPosition
+ (JNIEnv *, jobject, jint x, jint y) {
+ HANDLE hStdOut;
+ if ((hStdOut = GetStdHandle(STD_OUTPUT_HANDLE)) == INVALID_HANDLE_VALUE) {
+ return ;
+ }
+ COORD coord = {(SHORT) x, (SHORT) y};
+ SetConsoleCursorPosition(hStdOut, coord);
+}