Implemented Terminal cursor methods on windows.
This commit is contained in:
@@ -55,7 +55,7 @@ Java_net_rubygrapefruit_platform_internal_jni_WindowsConsoleFunctions_getConsole
|
|||||||
CONSOLE_SCREEN_BUFFER_INFO console_info;
|
CONSOLE_SCREEN_BUFFER_INFO console_info;
|
||||||
HANDLE handle = getHandle(env, output, result);
|
HANDLE handle = getHandle(env, output, result);
|
||||||
if (handle == NULL) {
|
if (handle == NULL) {
|
||||||
mark_failed_with_message(env, "not a terminal", result);
|
mark_failed_with_message(env, "not a console", result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!GetConsoleScreenBufferInfo(handle, &console_info)) {
|
if (!GetConsoleScreenBufferInfo(handle, &console_info)) {
|
||||||
@@ -156,4 +156,81 @@ Java_net_rubygrapefruit_platform_internal_jni_WindowsConsoleFunctions_foreground
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_net_rubygrapefruit_platform_internal_jni_WindowsConsoleFunctions_left(JNIEnv *env, jclass target, jint count, jobject result) {
|
||||||
|
CONSOLE_SCREEN_BUFFER_INFO console_info;
|
||||||
|
if (!GetConsoleScreenBufferInfo(current_console, &console_info)) {
|
||||||
|
mark_failed_with_errno(env, "could not get console buffer", result);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console_info.dwCursorPosition.X -= count;
|
||||||
|
if (!SetConsoleCursorPosition(current_console, console_info.dwCursorPosition)) {
|
||||||
|
mark_failed_with_errno(env, "could not set cursor position", result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_net_rubygrapefruit_platform_internal_jni_WindowsConsoleFunctions_right(JNIEnv *env, jclass target, jint count, jobject result) {
|
||||||
|
CONSOLE_SCREEN_BUFFER_INFO console_info;
|
||||||
|
if (!GetConsoleScreenBufferInfo(current_console, &console_info)) {
|
||||||
|
mark_failed_with_errno(env, "could not get console buffer", result);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console_info.dwCursorPosition.X += count;
|
||||||
|
if (!SetConsoleCursorPosition(current_console, console_info.dwCursorPosition)) {
|
||||||
|
mark_failed_with_errno(env, "could not set cursor position", result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_net_rubygrapefruit_platform_internal_jni_WindowsConsoleFunctions_up(JNIEnv *env, jclass target, jint count, jobject result) {
|
||||||
|
CONSOLE_SCREEN_BUFFER_INFO console_info;
|
||||||
|
if (!GetConsoleScreenBufferInfo(current_console, &console_info)) {
|
||||||
|
mark_failed_with_errno(env, "could not get console buffer", result);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console_info.dwCursorPosition.Y -= count;
|
||||||
|
if (!SetConsoleCursorPosition(current_console, console_info.dwCursorPosition)) {
|
||||||
|
mark_failed_with_errno(env, "could not set cursor position", result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_net_rubygrapefruit_platform_internal_jni_WindowsConsoleFunctions_down(JNIEnv *env, jclass target, jint count, jobject result) {
|
||||||
|
CONSOLE_SCREEN_BUFFER_INFO console_info;
|
||||||
|
if (!GetConsoleScreenBufferInfo(current_console, &console_info)) {
|
||||||
|
mark_failed_with_errno(env, "could not get console buffer", result);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console_info.dwCursorPosition.Y += count;
|
||||||
|
if (!SetConsoleCursorPosition(current_console, console_info.dwCursorPosition)) {
|
||||||
|
mark_failed_with_errno(env, "could not set cursor position", result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_net_rubygrapefruit_platform_internal_jni_WindowsConsoleFunctions_startLine(JNIEnv *env, jclass target, jobject result) {
|
||||||
|
CONSOLE_SCREEN_BUFFER_INFO console_info;
|
||||||
|
if (!GetConsoleScreenBufferInfo(current_console, &console_info)) {
|
||||||
|
mark_failed_with_errno(env, "could not get console buffer", result);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console_info.dwCursorPosition.X = 0;
|
||||||
|
if (!SetConsoleCursorPosition(current_console, console_info.dwCursorPosition)) {
|
||||||
|
mark_failed_with_errno(env, "could not set cursor position", result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_net_rubygrapefruit_platform_internal_jni_WindowsConsoleFunctions_clearToEndOfLine(JNIEnv *env, jclass target, jobject result) {
|
||||||
|
CONSOLE_SCREEN_BUFFER_INFO console_info;
|
||||||
|
if (!GetConsoleScreenBufferInfo(current_console, &console_info)) {
|
||||||
|
mark_failed_with_errno(env, "could not get console buffer", result);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (int i = console_info.dwCursorPosition.X; i < console_info.dwSize.X; i++) {
|
||||||
|
WriteConsole(current_console, " ", 1, NULL, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import net.rubygrapefruit.platform.NativeException;
|
|||||||
import net.rubygrapefruit.platform.Terminal;
|
import net.rubygrapefruit.platform.Terminal;
|
||||||
import net.rubygrapefruit.platform.TerminalAccess;
|
import net.rubygrapefruit.platform.TerminalAccess;
|
||||||
import net.rubygrapefruit.platform.TerminalSize;
|
import net.rubygrapefruit.platform.TerminalSize;
|
||||||
|
import net.rubygrapefruit.platform.internal.jni.TerminfoFunctions;
|
||||||
import net.rubygrapefruit.platform.internal.jni.WindowsConsoleFunctions;
|
import net.rubygrapefruit.platform.internal.jni.WindowsConsoleFunctions;
|
||||||
|
|
||||||
public class WindowsTerminal extends AbstractTerminal {
|
public class WindowsTerminal extends AbstractTerminal {
|
||||||
@@ -80,31 +81,61 @@ public class WindowsTerminal extends AbstractTerminal {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Terminal cursorDown(int count) throws NativeException {
|
public Terminal cursorDown(int count) throws NativeException {
|
||||||
throw new UnsupportedOperationException();
|
FunctionResult result = new FunctionResult();
|
||||||
|
WindowsConsoleFunctions.down(count, result);
|
||||||
|
if (result.isFailed()) {
|
||||||
|
throw new NativeException(String.format("Could not move cursor down for %s: %s", this, result.getMessage()));
|
||||||
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Terminal cursorUp(int count) throws NativeException {
|
public Terminal cursorUp(int count) throws NativeException {
|
||||||
throw new UnsupportedOperationException();
|
FunctionResult result = new FunctionResult();
|
||||||
|
WindowsConsoleFunctions.up(count, result);
|
||||||
|
if (result.isFailed()) {
|
||||||
|
throw new NativeException(String.format("Could not move cursor up for %s: %s", this, result.getMessage()));
|
||||||
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Terminal cursorLeft(int count) throws NativeException {
|
public Terminal cursorLeft(int count) throws NativeException {
|
||||||
throw new UnsupportedOperationException();
|
FunctionResult result = new FunctionResult();
|
||||||
|
WindowsConsoleFunctions.left(count, result);
|
||||||
|
if (result.isFailed()) {
|
||||||
|
throw new NativeException(String.format("Could not move cursor left for %s: %s", this, result.getMessage()));
|
||||||
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Terminal cursorRight(int count) throws NativeException {
|
public Terminal cursorRight(int count) throws NativeException {
|
||||||
throw new UnsupportedOperationException();
|
FunctionResult result = new FunctionResult();
|
||||||
|
WindowsConsoleFunctions.right(count, result);
|
||||||
|
if (result.isFailed()) {
|
||||||
|
throw new NativeException(String.format("Could not move cursor right for %s: %s", this, result.getMessage()));
|
||||||
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Terminal cursorStartOfLine() throws NativeException {
|
public Terminal cursorStartOfLine() throws NativeException {
|
||||||
throw new UnsupportedOperationException();
|
FunctionResult result = new FunctionResult();
|
||||||
|
WindowsConsoleFunctions.startLine(result);
|
||||||
|
if (result.isFailed()) {
|
||||||
|
throw new NativeException(String.format("Could not move cursor to start of line for %s: %s", this, result.getMessage()));
|
||||||
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Terminal clearToEndOfLine() throws NativeException {
|
public Terminal clearToEndOfLine() throws NativeException {
|
||||||
throw new UnsupportedOperationException();
|
FunctionResult result = new FunctionResult();
|
||||||
|
WindowsConsoleFunctions.clearToEndOfLine(result);
|
||||||
|
if (result.isFailed()) {
|
||||||
|
throw new NativeException(String.format("Could clear to end of line for %s: %s", this, result.getMessage()));
|
||||||
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,4 +17,16 @@ public class WindowsConsoleFunctions {
|
|||||||
public static native void reset(FunctionResult result);
|
public static native void reset(FunctionResult result);
|
||||||
|
|
||||||
public static native void foreground(int ansiColor, FunctionResult result);
|
public static native void foreground(int ansiColor, FunctionResult result);
|
||||||
|
|
||||||
|
public static native void left(int count, FunctionResult result);
|
||||||
|
|
||||||
|
public static native void right(int count, FunctionResult result);
|
||||||
|
|
||||||
|
public static native void up(int count, FunctionResult result);
|
||||||
|
|
||||||
|
public static native void down(int count, FunctionResult result);
|
||||||
|
|
||||||
|
public static native void startLine(FunctionResult result);
|
||||||
|
|
||||||
|
public static native void clearToEndOfLine(FunctionResult result);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user