Code polish, threading fixes for checking variables
This commit is contained in:
parent
1118f6932e
commit
0d7cbc57c4
@ -36,7 +36,6 @@ import dorkbox.util.Property;
|
|||||||
public
|
public
|
||||||
class Console {
|
class Console {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If true, allows an ANSI output stream to be created, otherwise a NO-OP stream is created instead
|
* If true, allows an ANSI output stream to be created, otherwise a NO-OP stream is created instead
|
||||||
*/
|
*/
|
||||||
@ -62,9 +61,6 @@ class Console {
|
|||||||
@Property
|
@Property
|
||||||
public static volatile boolean ENABLE_INTERRUPT = false;
|
public static volatile boolean ENABLE_INTERRUPT = false;
|
||||||
|
|
||||||
@Property
|
|
||||||
public static char PASSWORD_ECHO_CHAR = '*';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables the backspace key to delete characters in the line buffer and (if ANSI is enabled) from the screen.
|
* Enables the backspace key to delete characters in the line buffer and (if ANSI is enabled) from the screen.
|
||||||
*/
|
*/
|
||||||
@ -73,14 +69,13 @@ class Console {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// OS types supported by the input console. Default is AUTO
|
/**
|
||||||
public static final String AUTO = "auto";
|
* Valid options are:
|
||||||
public static final String UNIX = "unix";
|
* AUTO - automatically determine which OS/console type to use
|
||||||
public static final String WINDOWS = "windows";
|
* UNIX - try to control a UNIX console
|
||||||
|
* WINDOWS - try to control a WINDOWS console
|
||||||
public static final String NONE = "none"; // this is the same as unsupported
|
* NONE - do not try to control anything, only line input is supported
|
||||||
|
*/
|
||||||
// valid are what's above
|
|
||||||
@Property
|
@Property
|
||||||
public static final String INPUT_CONSOLE_TYPE = "AUTO";
|
public static final String INPUT_CONSOLE_TYPE = "AUTO";
|
||||||
|
|
||||||
@ -95,7 +90,6 @@ class Console {
|
|||||||
private static PrintStream err;
|
private static PrintStream err;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the version number.
|
* Gets the version number.
|
||||||
*/
|
*/
|
||||||
@ -207,7 +201,6 @@ class Console {
|
|||||||
public static synchronized
|
public static synchronized
|
||||||
void reset() {
|
void reset() {
|
||||||
if (installed >= 1) {
|
if (installed >= 1) {
|
||||||
// TODO: make this reset readLine, etc as well?
|
|
||||||
try {
|
try {
|
||||||
System.out.write(AnsiOutputStream.RESET_CODE);
|
System.out.write(AnsiOutputStream.RESET_CODE);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -28,6 +28,7 @@ import dorkbox.console.input.PosixTerminal;
|
|||||||
import dorkbox.console.input.Terminal;
|
import dorkbox.console.input.Terminal;
|
||||||
import dorkbox.console.input.UnsupportedTerminal;
|
import dorkbox.console.input.UnsupportedTerminal;
|
||||||
import dorkbox.console.input.WindowsTerminal;
|
import dorkbox.console.input.WindowsTerminal;
|
||||||
|
import dorkbox.console.output.Ansi;
|
||||||
import dorkbox.console.util.CharHolder;
|
import dorkbox.console.util.CharHolder;
|
||||||
import dorkbox.objectPool.ObjectPool;
|
import dorkbox.objectPool.ObjectPool;
|
||||||
import dorkbox.objectPool.PoolableObject;
|
import dorkbox.objectPool.PoolableObject;
|
||||||
@ -95,13 +96,13 @@ class Input {
|
|||||||
Throwable didFallbackE = null;
|
Throwable didFallbackE = null;
|
||||||
Terminal term;
|
Terminal term;
|
||||||
try {
|
try {
|
||||||
if (type.equals(Console.UNIX)) {
|
if (type.equals("UNIX")) {
|
||||||
term = new PosixTerminal();
|
term = new PosixTerminal();
|
||||||
}
|
}
|
||||||
else if (type.equals(Console.WINDOWS)) {
|
else if (type.equals("WINDOWS")) {
|
||||||
term = new WindowsTerminal();
|
term = new WindowsTerminal();
|
||||||
}
|
}
|
||||||
else if (type.equals(Console.NONE)) {
|
else if (type.equals("NONE")) {
|
||||||
term = new UnsupportedTerminal();
|
term = new UnsupportedTerminal();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -320,15 +321,12 @@ class Input {
|
|||||||
void run() {
|
void run() {
|
||||||
Logger logger2 = logger;
|
Logger logger2 = logger;
|
||||||
|
|
||||||
final boolean ansiEnabled = Console.ENABLE_ANSI;
|
Ansi ansi = null;
|
||||||
// Ansi ansi = Ansi.ansi();
|
|
||||||
// PrintStream out = AnsiConsole.out;
|
|
||||||
PrintStream out = System.out;
|
PrintStream out = System.out;
|
||||||
|
|
||||||
int typedChar;
|
int typedChar;
|
||||||
char asChar;
|
char asChar;
|
||||||
final char overWriteChar = ' ';
|
final char overWriteChar = ' ';
|
||||||
boolean enableBackspace = Console.ENABLE_BACKSPACE;
|
|
||||||
|
|
||||||
|
|
||||||
// don't type ; in a bash shell, it quits everything
|
// don't type ; in a bash shell, it quits everything
|
||||||
@ -355,7 +353,7 @@ class Input {
|
|||||||
// now to handle readLine stuff
|
// now to handle readLine stuff
|
||||||
|
|
||||||
// if we type a backspace key, swallow it + previous in READLINE. READCHAR will have it passed anyways.
|
// if we type a backspace key, swallow it + previous in READLINE. READCHAR will have it passed anyways.
|
||||||
if (enableBackspace && asChar == '\b') {
|
if (Console.ENABLE_BACKSPACE && asChar == '\b') {
|
||||||
int position = 0;
|
int position = 0;
|
||||||
char[] overwrite = null;
|
char[] overwrite = null;
|
||||||
|
|
||||||
@ -389,11 +387,15 @@ class Input {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ansiEnabled && overwrite != null) {
|
if (Console.ENABLE_ANSI && overwrite != null) {
|
||||||
|
if (ansi == null) {
|
||||||
|
ansi = Ansi.ansi();
|
||||||
|
}
|
||||||
|
|
||||||
// move back however many, over write, then go back again
|
// move back however many, over write, then go back again
|
||||||
// out.print(ansi.cursorToColumn(position));
|
out.print(ansi.cursorToColumn(position));
|
||||||
out.print(overwrite);
|
out.print(overwrite);
|
||||||
// out.print(ansi.cursorToColumn(position));
|
out.print(ansi.cursorToColumn(position));
|
||||||
out.flush();
|
out.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user