< prev index next >

src/java.base/windows/native/libjava/Console_md.c

Print this page
rev 51515 : 8209937: Enhance java.io.Console - provide methods to query console width and height
Contributed-by: christoph.langer@sap.com, matthias.baesken@sap.com

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -25,16 +25,44 @@
 
 #include "jni.h"
 #include "jni_util.h"
 #include "jvm.h"
 #include "java_io_Console.h"
-
 #include <stdlib.h>
 #include <Wincon.h>
 
 static HANDLE hStdOut = INVALID_HANDLE_VALUE;
 static HANDLE hStdIn = INVALID_HANDLE_VALUE;
+
+JNIEXPORT jint JNICALL
+Java_java_io_Console_width(JNIEnv *env, jobject this)
+{
+    CONSOLE_SCREEN_BUFFER_INFO csbi;
+
+    if (!GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)) {
+        if (!GetConsoleScreenBufferInfo(GetStdHandle(STD_ERROR_HANDLE), &csbi)) {
+            return -1;
+        }
+    }
+
+    return csbi.dwSize.X;
+}
+
+JNIEXPORT jint JNICALL
+Java_java_io_Console_height(JNIEnv *env, jobject this)
+{
+    CONSOLE_SCREEN_BUFFER_INFO csbi;
+
+    if (!GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)) {
+        if (!GetConsoleScreenBufferInfo(GetStdHandle(STD_ERROR_HANDLE), &csbi)) {
+            return -1;
+        }
+    }
+
+    return csbi.dwSize.Y;
+}
+
 JNIEXPORT jboolean JNICALL
 Java_java_io_Console_istty(JNIEnv *env, jclass cls)
 {
     if (hStdIn == INVALID_HANDLE_VALUE &&
         (hStdIn = GetStdHandle(STD_INPUT_HANDLE)) == INVALID_HANDLE_VALUE) {
< prev index next >