src/jdk.internal.le/windows/native/lible/WindowsTerminal.cpp
author dtitov
Wed, 06 Jun 2018 13:58:57 -0700
changeset 50437 46a5f26cb95b
parent 50338 1d5694c1aa03
permissions -rw-r--r--
8203033: [Testbug] vmTestbase/nsk/jdi/TypeComponent/isSynthetic/issynthetic002/TestDescription.java fails with nestmates Reviewed-by: sspitsyn, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31530
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
     1
/*
50338
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
     2
 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
31530
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
     4
 *
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    10
 *
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    15
 * accompanied this code).
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    16
 *
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    20
 *
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    23
 * questions.
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    24
 */
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    25
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    26
#include "jni.h"
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    27
#include "jni_util.h"
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    28
#include "jvm.h"
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    29
#include "jdk_internal_jline_WindowsTerminal.h"
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    30
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    31
#include <stdlib.h>
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    32
#include <Wincon.h>
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    33
#include <Winuser.h>
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    34
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    35
static jclass recordClass;
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    36
static jmethodID recordConstructor;
50338
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
    37
static jclass bufferStateClass;
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
    38
static jmethodID bufferStateConstructor;
31530
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    39
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    40
JNIEXPORT void JNICALL Java_jdk_internal_jline_WindowsTerminal_initIDs
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    41
  (JNIEnv *env, jclass) {
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    42
    jclass cls = env->FindClass("jdk/internal/jline/WindowsTerminal$KEY_EVENT_RECORD");
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    43
    CHECK_NULL(cls);
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    44
    recordClass = (jclass) env->NewGlobalRef(cls);
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    45
    CHECK_NULL(recordClass);
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    46
    recordConstructor = env->GetMethodID(cls, "<init>", "(ZCIII)V");
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    47
    CHECK_NULL(recordConstructor);
50338
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
    48
    cls = env->FindClass("jdk/internal/jline/extra/AnsiInterpretingOutputStream$BufferState");
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
    49
    CHECK_NULL(cls);
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
    50
    bufferStateClass = (jclass) env->NewGlobalRef(cls);
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
    51
    CHECK_NULL(bufferStateClass);
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
    52
    bufferStateConstructor = env->GetMethodID(cls, "<init>", "(IIII)V");
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
    53
    CHECK_NULL(bufferStateConstructor);
31530
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    54
}
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    55
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    56
JNIEXPORT jint JNICALL Java_jdk_internal_jline_WindowsTerminal_getConsoleMode
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    57
  (JNIEnv *, jobject) {
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    58
    HANDLE hStdIn;
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    59
    if ((hStdIn = GetStdHandle(STD_INPUT_HANDLE)) == INVALID_HANDLE_VALUE) {
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    60
        return -1;
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    61
    }
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    62
    DWORD fdwMode;
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    63
    if (! GetConsoleMode(hStdIn, &fdwMode)) {
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    64
        return -1;
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    65
    }
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    66
    return fdwMode;
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    67
}
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    68
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    69
JNIEXPORT void JNICALL Java_jdk_internal_jline_WindowsTerminal_setConsoleMode
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    70
  (JNIEnv *, jobject, jint mode) {
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    71
    HANDLE hStdIn;
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    72
    if ((hStdIn = GetStdHandle(STD_INPUT_HANDLE)) == INVALID_HANDLE_VALUE) {
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    73
        return ;
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    74
    }
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    75
    DWORD fdwMode = mode;
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    76
    SetConsoleMode(hStdIn, fdwMode);
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    77
}
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    78
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    79
JNIEXPORT jobject JNICALL Java_jdk_internal_jline_WindowsTerminal_readKeyEvent
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    80
  (JNIEnv *env, jobject) {
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    81
    HANDLE hStdIn;
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    82
    if ((hStdIn = GetStdHandle(STD_INPUT_HANDLE)) == INVALID_HANDLE_VALUE) {
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    83
        return NULL;
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    84
    }
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    85
    INPUT_RECORD record;
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    86
    DWORD n;
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    87
    while (TRUE) {
43333
958f1fb2dfd6 8166535: jshell tool: cannot handle non-ascii characters
jlahoda
parents: 43107
diff changeset
    88
        if (ReadConsoleInputW(hStdIn, &record, 1, &n) == 0) {
31530
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    89
            return NULL;
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    90
        }
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    91
        if (record.EventType == KEY_EVENT) {
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    92
            return env->NewObject(recordClass,
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    93
                                  recordConstructor,
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    94
                                  record.Event.KeyEvent.bKeyDown,
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    95
                                  record.Event.KeyEvent.uChar.UnicodeChar,
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    96
                                  record.Event.KeyEvent.dwControlKeyState,
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    97
                                  record.Event.KeyEvent.wVirtualKeyCode,
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    98
                                  record.Event.KeyEvent.wRepeatCount);
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
    99
        }
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
   100
        continue;
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
   101
    }
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
   102
}
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
   103
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
   104
JNIEXPORT jint JNICALL Java_jdk_internal_jline_WindowsTerminal_getConsoleOutputCodepage
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
   105
  (JNIEnv *, jobject) {
43333
958f1fb2dfd6 8166535: jshell tool: cannot handle non-ascii characters
jlahoda
parents: 43107
diff changeset
   106
    return GetConsoleOutputCP();
31530
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
   107
}
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
   108
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
   109
JNIEXPORT jint JNICALL Java_jdk_internal_jline_WindowsTerminal_getWindowsTerminalWidth
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
   110
  (JNIEnv *, jobject) {
43107
b232ec246f2b 8171386: jshell tool: paging of javadoc output broken on Windows
jlahoda
parents: 31530
diff changeset
   111
    HANDLE hStdOut;
b232ec246f2b 8171386: jshell tool: paging of javadoc output broken on Windows
jlahoda
parents: 31530
diff changeset
   112
    if ((hStdOut = GetStdHandle(STD_OUTPUT_HANDLE)) == INVALID_HANDLE_VALUE) {
31530
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
   113
        return -1;
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
   114
    }
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
   115
    CONSOLE_SCREEN_BUFFER_INFO info;
43107
b232ec246f2b 8171386: jshell tool: paging of javadoc output broken on Windows
jlahoda
parents: 31530
diff changeset
   116
    if (! GetConsoleScreenBufferInfo(hStdOut, &info)) {
31530
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
   117
        return -1;
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
   118
    }
43107
b232ec246f2b 8171386: jshell tool: paging of javadoc output broken on Windows
jlahoda
parents: 31530
diff changeset
   119
    return info.srWindow.Right - info.srWindow.Left;
31530
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
   120
}
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
   121
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
   122
JNIEXPORT jint JNICALL Java_jdk_internal_jline_WindowsTerminal_getWindowsTerminalHeight
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
   123
  (JNIEnv *, jobject) {
43107
b232ec246f2b 8171386: jshell tool: paging of javadoc output broken on Windows
jlahoda
parents: 31530
diff changeset
   124
    HANDLE hStdOut;
b232ec246f2b 8171386: jshell tool: paging of javadoc output broken on Windows
jlahoda
parents: 31530
diff changeset
   125
    if ((hStdOut = GetStdHandle(STD_OUTPUT_HANDLE)) == INVALID_HANDLE_VALUE) {
31530
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
   126
        return -1;
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
   127
    }
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
   128
    CONSOLE_SCREEN_BUFFER_INFO info;
43107
b232ec246f2b 8171386: jshell tool: paging of javadoc output broken on Windows
jlahoda
parents: 31530
diff changeset
   129
    if (! GetConsoleScreenBufferInfo(hStdOut, &info)) {
31530
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
   130
        return -1;
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
   131
    }
43107
b232ec246f2b 8171386: jshell tool: paging of javadoc output broken on Windows
jlahoda
parents: 31530
diff changeset
   132
    return info.srWindow.Bottom - info.srWindow.Top + 1;
31530
aa87d96a02b1 8080679: Include jline in JDK for Java and JavaScript REPLs
jlahoda
parents:
diff changeset
   133
}
50338
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
   134
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
   135
JNIEXPORT jobject JNICALL Java_jdk_internal_jline_WindowsTerminal_getBufferState
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
   136
  (JNIEnv *env, jobject) {
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
   137
    HANDLE hStdOut;
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
   138
    if ((hStdOut = GetStdHandle(STD_OUTPUT_HANDLE)) == INVALID_HANDLE_VALUE) {
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
   139
        return NULL;
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
   140
    }
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
   141
    CONSOLE_SCREEN_BUFFER_INFO info;
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
   142
    if (! GetConsoleScreenBufferInfo(hStdOut, &info)) {
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
   143
        return NULL;
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
   144
    }
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
   145
    return env->NewObject(bufferStateClass,
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
   146
                          bufferStateConstructor,
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
   147
                          info.dwCursorPosition.X,
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
   148
                          info.dwCursorPosition.Y,
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
   149
                          info.dwSize.X,
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
   150
                          info.dwSize.Y);
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
   151
}
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
   152
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
   153
JNIEXPORT void JNICALL Java_jdk_internal_jline_WindowsTerminal_setCursorPosition
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
   154
  (JNIEnv *, jobject, jint x, jint y) {
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
   155
    HANDLE hStdOut;
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
   156
    if ((hStdOut = GetStdHandle(STD_OUTPUT_HANDLE)) == INVALID_HANDLE_VALUE) {
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
   157
        return ;
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
   158
    }
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
   159
    COORD coord = {(SHORT) x, (SHORT) y};
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
   160
    SetConsoleCursorPosition(hStdOut, coord);
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 47216
diff changeset
   161
}