Added support for Terminal.cursorStartOfLine() and clearToEndOfLine().
This commit is contained in:
@@ -17,7 +17,8 @@ These bindings work for both the UNIX terminal and Windows console:
|
|||||||
* Query the terminal size.
|
* Query the terminal size.
|
||||||
* Switch between bold and normal mode on the terminal.
|
* Switch between bold and normal mode on the terminal.
|
||||||
* Change foreground color on the terminal.
|
* Change foreground color on the terminal.
|
||||||
* Move terminal cursor up, down, left, right.
|
* Move terminal cursor up, down, left, right, start of line.
|
||||||
|
* Clear to end of line.
|
||||||
|
|
||||||
Currently ported to OS X, Linux and Windows. Tested on:
|
Currently ported to OS X, Linux and Windows. Tested on:
|
||||||
|
|
||||||
@@ -37,7 +38,7 @@ You need to install Visual studio, and build from a Visual studio command prompt
|
|||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
|
|
||||||
* Fix TERM=dumb on linux
|
* Fix TERM=dumb
|
||||||
* Split out separate native library for terminal handling.
|
* Split out separate native library for terminal handling.
|
||||||
* String names for errno values.
|
* String names for errno values.
|
||||||
* Split into multiple projects.
|
* Split into multiple projects.
|
||||||
|
|||||||
@@ -190,5 +190,15 @@ Java_net_rubygrapefruit_platform_internal_jni_TerminfoFunctions_right(JNIEnv *en
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_net_rubygrapefruit_platform_internal_jni_TerminfoFunctions_startLine(JNIEnv *env, jclass target, jobject result) {
|
||||||
|
write_capability(env, "cr", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_net_rubygrapefruit_platform_internal_jni_TerminfoFunctions_clearToEndOfLine(JNIEnv *env, jclass target, jobject result) {
|
||||||
|
write_capability(env, "ce", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ public class Main {
|
|||||||
terminal.normal();
|
terminal.normal();
|
||||||
System.out.println(" [normal]");
|
System.out.println(" [normal]");
|
||||||
|
|
||||||
System.out.println("here are the colors:");
|
System.out.println();
|
||||||
|
System.out.println("COLORS");
|
||||||
for (Terminal.Color color : Terminal.Color.values()) {
|
for (Terminal.Color color : Terminal.Color.values()) {
|
||||||
terminal.foreground(color);
|
terminal.foreground(color);
|
||||||
System.out.print(String.format("[%s] ", color.toString().toLowerCase()));
|
System.out.print(String.format("[%s] ", color.toString().toLowerCase()));
|
||||||
@@ -42,9 +43,9 @@ public class Main {
|
|||||||
System.out.println(" ");
|
System.out.println(" ");
|
||||||
System.out.println(" ");
|
System.out.println(" ");
|
||||||
System.out.println(" ");
|
System.out.println(" ");
|
||||||
System.out.print("draw ");
|
System.out.print("[delete me]");
|
||||||
|
|
||||||
terminal.cursorLeft(10);
|
terminal.cursorLeft(11);
|
||||||
terminal.cursorUp(1);
|
terminal.cursorUp(1);
|
||||||
terminal.cursorRight(10);
|
terminal.cursorRight(10);
|
||||||
System.out.print("[4]");
|
System.out.print("[4]");
|
||||||
@@ -57,7 +58,8 @@ public class Main {
|
|||||||
terminal.cursorDown(1);
|
terminal.cursorDown(1);
|
||||||
System.out.print("[3]");
|
System.out.print("[3]");
|
||||||
terminal.cursorDown(1);
|
terminal.cursorDown(1);
|
||||||
terminal.cursorRight(10);
|
terminal.cursorStartOfLine();
|
||||||
|
terminal.clearToEndOfLine();
|
||||||
System.out.println("done!");
|
System.out.println("done!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,4 +72,18 @@ public interface Terminal {
|
|||||||
* @throws NativeException On failure.
|
* @throws NativeException On failure.
|
||||||
*/
|
*/
|
||||||
Terminal cursorDown(int count) throws NativeException;
|
Terminal cursorDown(int count) throws NativeException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves the cursor to the start of the current line.
|
||||||
|
*
|
||||||
|
* @throws NativeException On failure.
|
||||||
|
*/
|
||||||
|
Terminal cursorStartOfLine() throws NativeException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears characters from the cursor position to the end of the current line.
|
||||||
|
*
|
||||||
|
* @throws NativeException On failure.
|
||||||
|
*/
|
||||||
|
Terminal clearToEndOfLine() throws NativeException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,4 +131,26 @@ public class TerminfoTerminal extends AbstractTerminal {
|
|||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Terminal cursorStartOfLine() throws NativeException {
|
||||||
|
stream.flush();
|
||||||
|
FunctionResult result = new FunctionResult();
|
||||||
|
TerminfoFunctions.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
|
||||||
|
public Terminal clearToEndOfLine() throws NativeException {
|
||||||
|
stream.flush();
|
||||||
|
FunctionResult result = new FunctionResult();
|
||||||
|
TerminfoFunctions.clearToEndOfLine(result);
|
||||||
|
if (result.isFailed()) {
|
||||||
|
throw new NativeException(String.format("Could not clear to end of line for %s: %s", this, result.getMessage()));
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,4 +97,14 @@ public class WindowsTerminal extends AbstractTerminal {
|
|||||||
public Terminal cursorRight(int count) throws NativeException {
|
public Terminal cursorRight(int count) throws NativeException {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Terminal cursorStartOfLine() throws NativeException {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Terminal clearToEndOfLine() throws NativeException {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,4 +21,8 @@ public class TerminfoFunctions {
|
|||||||
public static native void up(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 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