Added support for Terminal.up(), down(), left(), right() for the terminal.
This commit is contained in:
@@ -1,41 +1,66 @@
|
||||
package net.rubygrapefruit.platform;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
System.out.println();
|
||||
System.out.println("* OS: " + System.getProperty("os.name") + ' ' + System.getProperty("os.version") + ' ' + System.getProperty("os.arch"));
|
||||
|
||||
Process process = Native.get(Process.class);
|
||||
System.out.println("* PID: " + process.getProcessId());
|
||||
|
||||
TerminalAccess terminalAccess = Native.get(TerminalAccess.class);
|
||||
boolean stdoutIsTerminal = terminalAccess.isTerminal(TerminalAccess.Output.Stdout);
|
||||
boolean stderrIsTerminal = terminalAccess.isTerminal(TerminalAccess.Output.Stderr);
|
||||
System.out.println("* stdout: " + (stdoutIsTerminal ? "terminal" : "not a terminal"));
|
||||
System.out.println("* stderr: " + (stderrIsTerminal ? "terminal" : "not a terminal"));
|
||||
if (stdoutIsTerminal) {
|
||||
Terminal terminal = terminalAccess.getTerminal(TerminalAccess.Output.Stdout);
|
||||
TerminalSize terminalSize = terminal.getTerminalSize();
|
||||
System.out.println("* terminal size: " + terminalSize.getCols() + " cols x " + terminalSize.getRows() + " rows");
|
||||
System.out.println();
|
||||
System.out.println("TERMINAL OUTPUT");
|
||||
System.out.print("[normal] ");
|
||||
terminal.bold();
|
||||
System.out.print("[bold]");
|
||||
terminal.normal();
|
||||
System.out.println(" [normal]");
|
||||
|
||||
System.out.println("here are the colors:");
|
||||
for (Terminal.Color color : Terminal.Color.values()) {
|
||||
terminal.foreground(color);
|
||||
System.out.print(String.format("[%s] ", color.toString().toLowerCase()));
|
||||
terminal.bold();
|
||||
System.out.print(String.format("[%s]", color.toString().toLowerCase()));
|
||||
terminal.normal();
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
package net.rubygrapefruit.platform;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
System.out.println();
|
||||
System.out.println("* OS: " + System.getProperty("os.name") + ' ' + System.getProperty("os.version") + ' ' + System.getProperty("os.arch"));
|
||||
|
||||
Process process = Native.get(Process.class);
|
||||
System.out.println("* PID: " + process.getProcessId());
|
||||
|
||||
TerminalAccess terminalAccess = Native.get(TerminalAccess.class);
|
||||
boolean stdoutIsTerminal = terminalAccess.isTerminal(TerminalAccess.Output.Stdout);
|
||||
boolean stderrIsTerminal = terminalAccess.isTerminal(TerminalAccess.Output.Stderr);
|
||||
System.out.println("* stdout: " + (stdoutIsTerminal ? "terminal" : "not a terminal"));
|
||||
System.out.println("* stderr: " + (stderrIsTerminal ? "terminal" : "not a terminal"));
|
||||
if (stdoutIsTerminal) {
|
||||
Terminal terminal = terminalAccess.getTerminal(TerminalAccess.Output.Stdout);
|
||||
TerminalSize terminalSize = terminal.getTerminalSize();
|
||||
System.out.println("* terminal size: " + terminalSize.getCols() + " cols x " + terminalSize.getRows() + " rows");
|
||||
System.out.println();
|
||||
System.out.println("TERMINAL OUTPUT");
|
||||
System.out.print("[normal] ");
|
||||
terminal.bold();
|
||||
System.out.print("[bold]");
|
||||
terminal.normal();
|
||||
System.out.println(" [normal]");
|
||||
|
||||
System.out.println("here are the colors:");
|
||||
for (Terminal.Color color : Terminal.Color.values()) {
|
||||
terminal.foreground(color);
|
||||
System.out.print(String.format("[%s] ", color.toString().toLowerCase()));
|
||||
terminal.bold();
|
||||
System.out.print(String.format("[%s]", color.toString().toLowerCase()));
|
||||
terminal.normal();
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
terminal.reset();
|
||||
|
||||
System.out.println("CURSOR MOVEMENT");
|
||||
System.out.println(" ");
|
||||
System.out.println(" ");
|
||||
System.out.println(" ");
|
||||
System.out.print("draw ");
|
||||
|
||||
terminal.cursorLeft(10);
|
||||
terminal.cursorUp(1);
|
||||
terminal.cursorRight(10);
|
||||
System.out.print("[4]");
|
||||
terminal.cursorUp(1);
|
||||
terminal.cursorLeft(3);
|
||||
System.out.print("[2]");
|
||||
terminal.cursorLeft(13);
|
||||
System.out.print("[1]");
|
||||
terminal.cursorLeft(3);
|
||||
terminal.cursorDown(1);
|
||||
System.out.print("[3]");
|
||||
terminal.cursorDown(1);
|
||||
terminal.cursorRight(10);
|
||||
System.out.println("done!");
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,21 @@ import java.io.File;
|
||||
|
||||
/**
|
||||
* Functions to query and modify a file's POSIX meta-data.
|
||||
*
|
||||
* Supported on Linux, OS X
|
||||
*/
|
||||
public interface PosixFile extends NativeIntegration {
|
||||
/**
|
||||
* Sets the mode for the given file.
|
||||
*
|
||||
* @throws NativeException On failure.
|
||||
*/
|
||||
void setMode(File path, int perms) throws NativeException;
|
||||
|
||||
/**
|
||||
* Gets the mode for the given file.
|
||||
*
|
||||
* @throws NativeException On failure.
|
||||
*/
|
||||
int getMode(File path) throws NativeException;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
package net.rubygrapefruit.platform;
|
||||
|
||||
/**
|
||||
* Functions to query and modify a process' meta-data
|
||||
*/
|
||||
public interface Process extends NativeIntegration {
|
||||
int getProcessId() throws NativeException;
|
||||
}
|
||||
package net.rubygrapefruit.platform;
|
||||
|
||||
/**
|
||||
* Functions to query and modify a process' meta-data
|
||||
*
|
||||
* Supported on Linux, OS X, Windows.
|
||||
*/
|
||||
public interface Process extends NativeIntegration {
|
||||
/**
|
||||
* Returns the process identifier.
|
||||
*
|
||||
* @throws NativeException On failure.
|
||||
*/
|
||||
int getProcessId() throws NativeException;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package net.rubygrapefruit.platform;
|
||||
|
||||
/**
|
||||
* Allows the terminal/console to be manipulated.
|
||||
*
|
||||
* Supported on Linux, OS X, Windows.
|
||||
*/
|
||||
public interface Terminal {
|
||||
enum Color {
|
||||
Black, Red, Green, Yellow, Blue, Magenta, Cyan, White
|
||||
@@ -7,26 +12,64 @@ public interface Terminal {
|
||||
|
||||
/**
|
||||
* Returns the size of the terminal.
|
||||
*
|
||||
* @throws NativeException On failure.
|
||||
*/
|
||||
TerminalSize getTerminalSize();
|
||||
TerminalSize getTerminalSize() throws NativeException;
|
||||
|
||||
/**
|
||||
* Sets the terminal foreground color.
|
||||
*
|
||||
* @throws NativeException On failure.
|
||||
*/
|
||||
Terminal foreground(Color color);
|
||||
Terminal foreground(Color color) throws NativeException;
|
||||
|
||||
/**
|
||||
* Switches the terminal to bold mode.
|
||||
*
|
||||
* @throws NativeException On failure.
|
||||
*/
|
||||
Terminal bold();
|
||||
Terminal bold() throws NativeException;
|
||||
|
||||
/**
|
||||
* Switches the terminal to normal mode.
|
||||
*
|
||||
* @throws NativeException On failure.
|
||||
*/
|
||||
Terminal normal();
|
||||
Terminal normal() throws NativeException;
|
||||
|
||||
/**
|
||||
* Switches the terminal to normal mode and restores default colors.
|
||||
*
|
||||
* @throws NativeException On failure.
|
||||
*/
|
||||
Terminal reset();
|
||||
Terminal reset() throws NativeException;
|
||||
|
||||
/**
|
||||
* Moves the cursor the given number of characters to the left.
|
||||
*
|
||||
* @throws NativeException On failure.
|
||||
*/
|
||||
Terminal cursorLeft(int count) throws NativeException;
|
||||
|
||||
/**
|
||||
* Moves the cursor the given number of characters to the right.
|
||||
*
|
||||
* @throws NativeException On failure.
|
||||
*/
|
||||
Terminal cursorRight(int count) throws NativeException;
|
||||
|
||||
/**
|
||||
* Moves the cursor the given number of characters up.
|
||||
*
|
||||
* @throws NativeException On failure.
|
||||
*/
|
||||
Terminal cursorUp(int count) throws NativeException;
|
||||
|
||||
/**
|
||||
* Moves the cursor the given number of characters down.
|
||||
*
|
||||
* @throws NativeException On failure.
|
||||
*/
|
||||
Terminal cursorDown(int count) throws NativeException;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,24 @@
|
||||
package net.rubygrapefruit.platform;
|
||||
|
||||
/**
|
||||
* Provides access to the terminal/console.
|
||||
*
|
||||
* Supported on Linux, OS X, Windows.
|
||||
*/
|
||||
public interface TerminalAccess extends NativeIntegration {
|
||||
enum Output {Stdout, Stderr}
|
||||
|
||||
boolean isTerminal(Output output);
|
||||
/**
|
||||
* Returns true if the given output is attached to a terminal.
|
||||
*
|
||||
* @throws NativeException On failure.
|
||||
*/
|
||||
boolean isTerminal(Output output) throws NativeException;
|
||||
|
||||
Terminal getTerminal(Output output);
|
||||
/**
|
||||
* Returns the terminal attached to the given output.
|
||||
*
|
||||
* @throws NativeException When the output is not attached to a terminal.
|
||||
*/
|
||||
Terminal getTerminal(Output output) throws NativeException;
|
||||
}
|
||||
|
||||
@@ -1,90 +1,134 @@
|
||||
package net.rubygrapefruit.platform.internal;
|
||||
|
||||
import net.rubygrapefruit.platform.NativeException;
|
||||
import net.rubygrapefruit.platform.Terminal;
|
||||
import net.rubygrapefruit.platform.TerminalAccess;
|
||||
import net.rubygrapefruit.platform.TerminalSize;
|
||||
import net.rubygrapefruit.platform.internal.jni.PosixTerminalFunctions;
|
||||
import net.rubygrapefruit.platform.internal.jni.TerminfoFunctions;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class TerminfoTerminal extends AbstractTerminal {
|
||||
private final TerminalAccess.Output output;
|
||||
private final PrintStream stream;
|
||||
private Color foreground;
|
||||
|
||||
public TerminfoTerminal(TerminalAccess.Output output) {
|
||||
this.output = output;
|
||||
stream = output == TerminalAccess.Output.Stdout ? System.out : System.err;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return output.toString().toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doInit() {
|
||||
stream.flush();
|
||||
FunctionResult result = new FunctionResult();
|
||||
TerminfoFunctions.initTerminal(output.ordinal(), result);
|
||||
if (result.isFailed()) {
|
||||
throw new NativeException(String.format("Could not open terminal for %s: %s", this, result.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerminalSize getTerminalSize() {
|
||||
MutableTerminalSize terminalSize = new MutableTerminalSize();
|
||||
FunctionResult result = new FunctionResult();
|
||||
PosixTerminalFunctions.getTerminalSize(output.ordinal(), terminalSize, result);
|
||||
if (result.isFailed()) {
|
||||
throw new NativeException(String.format("Could not get terminal size for %s: %s", this, result.getMessage()));
|
||||
}
|
||||
return terminalSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Terminal foreground(Color color) {
|
||||
stream.flush();
|
||||
FunctionResult result = new FunctionResult();
|
||||
TerminfoFunctions.foreground(color.ordinal(), result);
|
||||
if (result.isFailed()) {
|
||||
throw new NativeException(String.format("Could not switch foreground color for %s: %s", this, result.getMessage()));
|
||||
}
|
||||
foreground = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Terminal bold() {
|
||||
stream.flush();
|
||||
FunctionResult result = new FunctionResult();
|
||||
TerminfoFunctions.bold(result);
|
||||
if (result.isFailed()) {
|
||||
throw new NativeException(String.format("Could not switch to bold mode for %s: %s", this, result.getMessage()));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Terminal normal() {
|
||||
reset();
|
||||
if (foreground != null) {
|
||||
foreground(foreground);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Terminal reset() {
|
||||
stream.flush();
|
||||
FunctionResult result = new FunctionResult();
|
||||
TerminfoFunctions.reset(result);
|
||||
if (result.isFailed()) {
|
||||
throw new NativeException(String.format("Could not reset terminal for %s: %s", this, result.getMessage()));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
package net.rubygrapefruit.platform.internal;
|
||||
|
||||
import net.rubygrapefruit.platform.NativeException;
|
||||
import net.rubygrapefruit.platform.Terminal;
|
||||
import net.rubygrapefruit.platform.TerminalAccess;
|
||||
import net.rubygrapefruit.platform.TerminalSize;
|
||||
import net.rubygrapefruit.platform.internal.jni.PosixTerminalFunctions;
|
||||
import net.rubygrapefruit.platform.internal.jni.TerminfoFunctions;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class TerminfoTerminal extends AbstractTerminal {
|
||||
private final TerminalAccess.Output output;
|
||||
private final PrintStream stream;
|
||||
private Color foreground;
|
||||
|
||||
public TerminfoTerminal(TerminalAccess.Output output) {
|
||||
this.output = output;
|
||||
stream = output == TerminalAccess.Output.Stdout ? System.out : System.err;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return output.toString().toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doInit() {
|
||||
stream.flush();
|
||||
FunctionResult result = new FunctionResult();
|
||||
TerminfoFunctions.initTerminal(output.ordinal(), result);
|
||||
if (result.isFailed()) {
|
||||
throw new NativeException(String.format("Could not open terminal for %s: %s", this, result.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerminalSize getTerminalSize() {
|
||||
MutableTerminalSize terminalSize = new MutableTerminalSize();
|
||||
FunctionResult result = new FunctionResult();
|
||||
PosixTerminalFunctions.getTerminalSize(output.ordinal(), terminalSize, result);
|
||||
if (result.isFailed()) {
|
||||
throw new NativeException(String.format("Could not get terminal size for %s: %s", this, result.getMessage()));
|
||||
}
|
||||
return terminalSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Terminal foreground(Color color) {
|
||||
stream.flush();
|
||||
FunctionResult result = new FunctionResult();
|
||||
TerminfoFunctions.foreground(color.ordinal(), result);
|
||||
if (result.isFailed()) {
|
||||
throw new NativeException(String.format("Could not switch foreground color for %s: %s", this, result.getMessage()));
|
||||
}
|
||||
foreground = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Terminal bold() {
|
||||
stream.flush();
|
||||
FunctionResult result = new FunctionResult();
|
||||
TerminfoFunctions.bold(result);
|
||||
if (result.isFailed()) {
|
||||
throw new NativeException(String.format("Could not switch to bold mode for %s: %s", this, result.getMessage()));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Terminal normal() {
|
||||
reset();
|
||||
if (foreground != null) {
|
||||
foreground(foreground);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Terminal reset() {
|
||||
stream.flush();
|
||||
FunctionResult result = new FunctionResult();
|
||||
TerminfoFunctions.reset(result);
|
||||
if (result.isFailed()) {
|
||||
throw new NativeException(String.format("Could not reset terminal for %s: %s", this, result.getMessage()));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Terminal cursorDown(int count) {
|
||||
stream.flush();
|
||||
FunctionResult result = new FunctionResult();
|
||||
TerminfoFunctions.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
|
||||
public Terminal cursorUp(int count) {
|
||||
stream.flush();
|
||||
FunctionResult result = new FunctionResult();
|
||||
TerminfoFunctions.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
|
||||
public Terminal cursorLeft(int count) {
|
||||
stream.flush();
|
||||
FunctionResult result = new FunctionResult();
|
||||
TerminfoFunctions.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
|
||||
public Terminal cursorRight(int count) {
|
||||
stream.flush();
|
||||
FunctionResult result = new FunctionResult();
|
||||
TerminfoFunctions.right(count, result);
|
||||
if (result.isFailed()) {
|
||||
throw new NativeException(String.format("Could not move cursor right for %s: %s", this, result.getMessage()));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,80 +1,100 @@
|
||||
package net.rubygrapefruit.platform.internal;
|
||||
|
||||
import net.rubygrapefruit.platform.NativeException;
|
||||
import net.rubygrapefruit.platform.Terminal;
|
||||
import net.rubygrapefruit.platform.TerminalAccess;
|
||||
import net.rubygrapefruit.platform.TerminalSize;
|
||||
import net.rubygrapefruit.platform.internal.jni.WindowsConsoleFunctions;
|
||||
|
||||
public class WindowsTerminal extends AbstractTerminal {
|
||||
private final TerminalAccess.Output output;
|
||||
|
||||
public WindowsTerminal(TerminalAccess.Output output) {
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return output.toString().toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doInit() {
|
||||
FunctionResult result = new FunctionResult();
|
||||
WindowsConsoleFunctions.initConsole(output.ordinal(), result);
|
||||
if (result.isFailed()) {
|
||||
throw new NativeException(String.format("Could not open console for %s: %s", this, result.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerminalSize getTerminalSize() {
|
||||
FunctionResult result = new FunctionResult();
|
||||
MutableTerminalSize size = new MutableTerminalSize();
|
||||
WindowsConsoleFunctions.getConsoleSize(output.ordinal(), size, result);
|
||||
if (result.isFailed()) {
|
||||
throw new NativeException(String.format("Could not determine console size for %s: %s", this, result.getMessage()));
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Terminal bold() {
|
||||
FunctionResult result = new FunctionResult();
|
||||
WindowsConsoleFunctions.bold(result);
|
||||
if (result.isFailed()) {
|
||||
throw new NativeException(String.format("Could not switch console to bold mode for %s: %s", this, result.getMessage()));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Terminal foreground(Color color) {
|
||||
FunctionResult result = new FunctionResult();
|
||||
WindowsConsoleFunctions.foreground(color.ordinal(), result);
|
||||
if (result.isFailed()) {
|
||||
throw new NativeException(String.format("Could not change console foreground color for %s: %s", this, result.getMessage()));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Terminal normal() {
|
||||
FunctionResult result = new FunctionResult();
|
||||
WindowsConsoleFunctions.normal(result);
|
||||
if (result.isFailed()) {
|
||||
throw new NativeException(String.format("Could not switch console to normal mode for %s: %s", this, result.getMessage()));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Terminal reset() {
|
||||
FunctionResult result = new FunctionResult();
|
||||
WindowsConsoleFunctions.reset(result);
|
||||
if (result.isFailed()) {
|
||||
throw new NativeException(String.format("Could not reset console for %s: %s", this, result.getMessage()));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
package net.rubygrapefruit.platform.internal;
|
||||
|
||||
import net.rubygrapefruit.platform.NativeException;
|
||||
import net.rubygrapefruit.platform.Terminal;
|
||||
import net.rubygrapefruit.platform.TerminalAccess;
|
||||
import net.rubygrapefruit.platform.TerminalSize;
|
||||
import net.rubygrapefruit.platform.internal.jni.WindowsConsoleFunctions;
|
||||
|
||||
public class WindowsTerminal extends AbstractTerminal {
|
||||
private final TerminalAccess.Output output;
|
||||
|
||||
public WindowsTerminal(TerminalAccess.Output output) {
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return output.toString().toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doInit() {
|
||||
FunctionResult result = new FunctionResult();
|
||||
WindowsConsoleFunctions.initConsole(output.ordinal(), result);
|
||||
if (result.isFailed()) {
|
||||
throw new NativeException(String.format("Could not open console for %s: %s", this, result.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerminalSize getTerminalSize() {
|
||||
FunctionResult result = new FunctionResult();
|
||||
MutableTerminalSize size = new MutableTerminalSize();
|
||||
WindowsConsoleFunctions.getConsoleSize(output.ordinal(), size, result);
|
||||
if (result.isFailed()) {
|
||||
throw new NativeException(String.format("Could not determine console size for %s: %s", this, result.getMessage()));
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Terminal bold() {
|
||||
FunctionResult result = new FunctionResult();
|
||||
WindowsConsoleFunctions.bold(result);
|
||||
if (result.isFailed()) {
|
||||
throw new NativeException(String.format("Could not switch console to bold mode for %s: %s", this, result.getMessage()));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Terminal foreground(Color color) {
|
||||
FunctionResult result = new FunctionResult();
|
||||
WindowsConsoleFunctions.foreground(color.ordinal(), result);
|
||||
if (result.isFailed()) {
|
||||
throw new NativeException(String.format("Could not change console foreground color for %s: %s", this, result.getMessage()));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Terminal normal() {
|
||||
FunctionResult result = new FunctionResult();
|
||||
WindowsConsoleFunctions.normal(result);
|
||||
if (result.isFailed()) {
|
||||
throw new NativeException(String.format("Could not switch console to normal mode for %s: %s", this, result.getMessage()));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Terminal reset() {
|
||||
FunctionResult result = new FunctionResult();
|
||||
WindowsConsoleFunctions.reset(result);
|
||||
if (result.isFailed()) {
|
||||
throw new NativeException(String.format("Could not reset console for %s: %s", this, result.getMessage()));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Terminal cursorDown(int count) throws NativeException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Terminal cursorUp(int count) throws NativeException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Terminal cursorLeft(int count) throws NativeException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Terminal cursorRight(int count) throws NativeException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.rubygrapefruit.platform.internal.jni;
|
||||
|
||||
public class NativeLibraryFunctions {
|
||||
public static final int VERSION = 2;
|
||||
|
||||
public static native int getVersion();
|
||||
}
|
||||
package net.rubygrapefruit.platform.internal.jni;
|
||||
|
||||
public class NativeLibraryFunctions {
|
||||
public static final int VERSION = 3;
|
||||
|
||||
public static native int getVersion();
|
||||
}
|
||||
|
||||
@@ -1,19 +1,24 @@
|
||||
package net.rubygrapefruit.platform.internal.jni;
|
||||
|
||||
import net.rubygrapefruit.platform.internal.FunctionResult;
|
||||
|
||||
public class TerminfoFunctions {
|
||||
/**
|
||||
* Sets up terminal info and switches output to normal mode.
|
||||
*/
|
||||
public static native void initTerminal(int filedes, FunctionResult result);
|
||||
|
||||
public static native void bold(FunctionResult result);
|
||||
|
||||
public static native void reset(FunctionResult result);
|
||||
|
||||
/**
|
||||
* Set the foreground color to the given ansi color.
|
||||
*/
|
||||
public static native void foreground(int ansiColor, FunctionResult result);
|
||||
}
|
||||
package net.rubygrapefruit.platform.internal.jni;
|
||||
|
||||
import net.rubygrapefruit.platform.internal.FunctionResult;
|
||||
|
||||
public class TerminfoFunctions {
|
||||
/**
|
||||
* Sets up terminal info and switches output to normal mode.
|
||||
*/
|
||||
public static native void initTerminal(int filedes, FunctionResult result);
|
||||
|
||||
public static native void bold(FunctionResult result);
|
||||
|
||||
public static native void reset(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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user