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
|
||||
class Console {
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
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.
|
||||
*/
|
||||
@ -73,14 +69,13 @@ class Console {
|
||||
|
||||
|
||||
|
||||
// OS types supported by the input console. Default is AUTO
|
||||
public static final String AUTO = "auto";
|
||||
public static final String UNIX = "unix";
|
||||
public static final String WINDOWS = "windows";
|
||||
|
||||
public static final String NONE = "none"; // this is the same as unsupported
|
||||
|
||||
// valid are what's above
|
||||
/**
|
||||
* Valid options are:
|
||||
* AUTO - automatically determine which OS/console type to use
|
||||
* UNIX - try to control a UNIX console
|
||||
* WINDOWS - try to control a WINDOWS console
|
||||
* NONE - do not try to control anything, only line input is supported
|
||||
*/
|
||||
@Property
|
||||
public static final String INPUT_CONSOLE_TYPE = "AUTO";
|
||||
|
||||
@ -95,7 +90,6 @@ class Console {
|
||||
private static PrintStream err;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the version number.
|
||||
*/
|
||||
@ -207,7 +201,6 @@ class Console {
|
||||
public static synchronized
|
||||
void reset() {
|
||||
if (installed >= 1) {
|
||||
// TODO: make this reset readLine, etc as well?
|
||||
try {
|
||||
System.out.write(AnsiOutputStream.RESET_CODE);
|
||||
} catch (IOException e) {
|
||||
|
@ -28,6 +28,7 @@ import dorkbox.console.input.PosixTerminal;
|
||||
import dorkbox.console.input.Terminal;
|
||||
import dorkbox.console.input.UnsupportedTerminal;
|
||||
import dorkbox.console.input.WindowsTerminal;
|
||||
import dorkbox.console.output.Ansi;
|
||||
import dorkbox.console.util.CharHolder;
|
||||
import dorkbox.objectPool.ObjectPool;
|
||||
import dorkbox.objectPool.PoolableObject;
|
||||
@ -95,13 +96,13 @@ class Input {
|
||||
Throwable didFallbackE = null;
|
||||
Terminal term;
|
||||
try {
|
||||
if (type.equals(Console.UNIX)) {
|
||||
if (type.equals("UNIX")) {
|
||||
term = new PosixTerminal();
|
||||
}
|
||||
else if (type.equals(Console.WINDOWS)) {
|
||||
else if (type.equals("WINDOWS")) {
|
||||
term = new WindowsTerminal();
|
||||
}
|
||||
else if (type.equals(Console.NONE)) {
|
||||
else if (type.equals("NONE")) {
|
||||
term = new UnsupportedTerminal();
|
||||
}
|
||||
else {
|
||||
@ -320,15 +321,12 @@ class Input {
|
||||
void run() {
|
||||
Logger logger2 = logger;
|
||||
|
||||
final boolean ansiEnabled = Console.ENABLE_ANSI;
|
||||
// Ansi ansi = Ansi.ansi();
|
||||
// PrintStream out = AnsiConsole.out;
|
||||
Ansi ansi = null;
|
||||
PrintStream out = System.out;
|
||||
|
||||
int typedChar;
|
||||
char asChar;
|
||||
final char overWriteChar = ' ';
|
||||
boolean enableBackspace = Console.ENABLE_BACKSPACE;
|
||||
|
||||
|
||||
// don't type ; in a bash shell, it quits everything
|
||||
@ -355,7 +353,7 @@ class Input {
|
||||
// now to handle readLine stuff
|
||||
|
||||
// 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;
|
||||
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
|
||||
// out.print(ansi.cursorToColumn(position));
|
||||
out.print(ansi.cursorToColumn(position));
|
||||
out.print(overwrite);
|
||||
// out.print(ansi.cursorToColumn(position));
|
||||
out.print(ansi.cursorToColumn(position));
|
||||
out.flush();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user