Modified google code format
This commit is contained in:
parent
ed2a472a6f
commit
a33e62b098
@ -16,8 +16,8 @@ import java.nio.charset.Charset;
|
||||
public class Encoding {
|
||||
|
||||
/**
|
||||
* Get the default encoding. Will first look at the LC_CTYPE environment variable, then the input.encoding system
|
||||
* property, then the default charset according to the JVM.
|
||||
* Get the default encoding. Will first look at the LC_CTYPE environment variable, then the input.encoding system property, then the
|
||||
* default charset according to the JVM.
|
||||
*
|
||||
* @return The default encoding to use when none is specified.
|
||||
*/
|
||||
@ -31,8 +31,8 @@ public class Encoding {
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the LC_CTYPE value to extract the encoding according to the POSIX standard, which says that the LC_CTYPE
|
||||
* environment variable may be of the format <code>[language[_territory][.codeset][@modifier]]</code>
|
||||
* Parses the LC_CTYPE value to extract the encoding according to the POSIX standard, which says that the LC_CTYPE environment variable
|
||||
* may be of the format <code>[language[_territory][.codeset][@modifier]]</code>
|
||||
*
|
||||
* @param ctype The ctype to parse, may be null
|
||||
* @return The encoding, if one was present, otherwise null
|
||||
|
@ -15,10 +15,6 @@
|
||||
*/
|
||||
package dorkbox.util.input;
|
||||
|
||||
import org.fusesource.jansi.Ansi;
|
||||
import org.fusesource.jansi.AnsiConsole;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -29,6 +25,10 @@ import java.security.ProtectionDomain;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.fusesource.jansi.Ansi;
|
||||
import org.fusesource.jansi.AnsiConsole;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import dorkbox.util.OS;
|
||||
import dorkbox.util.bytes.ByteBuffer2;
|
||||
import dorkbox.util.bytes.ByteBuffer2Poolable;
|
||||
@ -145,9 +145,7 @@ public class InputConsole {
|
||||
private ThreadLocal<Integer> threadBufferCounter = new ThreadLocal<Integer>();
|
||||
|
||||
private ThreadLocal<ObjectPoolHolder<ByteBuffer2>> readLineBuff = new ThreadLocal<ObjectPoolHolder<ByteBuffer2>>();
|
||||
private List<ObjectPoolHolder<ByteBuffer2>>
|
||||
readLineBuffers =
|
||||
new CopyOnWriteArrayList<ObjectPoolHolder<ByteBuffer2>>();
|
||||
private List<ObjectPoolHolder<ByteBuffer2>> readLineBuffers = new CopyOnWriteArrayList<ObjectPoolHolder<ByteBuffer2>>();
|
||||
|
||||
private final Terminal terminal;
|
||||
private final Boolean enableBackspace;
|
||||
@ -188,8 +186,7 @@ public class InputConsole {
|
||||
t = new UnsupportedTerminal();
|
||||
} else {
|
||||
if (isIDEAutoDetect()) {
|
||||
logger.debug(
|
||||
"Terminal is in UNSUPPORTED (best guess). Unable to support single key input. Only line input available.");
|
||||
logger.debug("Terminal is in UNSUPPORTED (best guess). Unable to support single key input. Only line input available.");
|
||||
t = new UnsupportedTerminal();
|
||||
} else {
|
||||
if (OS.isWindows()) {
|
||||
@ -488,43 +485,43 @@ public class InputConsole {
|
||||
* Adapted from cat by Torbjorn Granlund, as repeated in stty by David MacKenzie.
|
||||
*/
|
||||
private static int getPrintableCharacters(final int ch) {
|
||||
// StringBuilder sbuff = new StringBuilder();
|
||||
// StringBuilder sbuff = new StringBuilder();
|
||||
|
||||
if (ch >= 32) {
|
||||
if (ch < 127) {
|
||||
// sbuff.append((char) ch);
|
||||
// sbuff.append((char) ch);
|
||||
return 1;
|
||||
} else if (ch == 127) {
|
||||
// sbuff.append('^');
|
||||
// sbuff.append('?');
|
||||
// sbuff.append('^');
|
||||
// sbuff.append('?');
|
||||
return 2;
|
||||
} else {
|
||||
// sbuff.append('M');
|
||||
// sbuff.append('-');
|
||||
// sbuff.append('M');
|
||||
// sbuff.append('-');
|
||||
int count = 2;
|
||||
|
||||
if (ch >= 128 + 32) {
|
||||
if (ch < 128 + 127) {
|
||||
// sbuff.append((char) (ch - 128));
|
||||
// sbuff.append((char) (ch - 128));
|
||||
count++;
|
||||
} else {
|
||||
// sbuff.append('^');
|
||||
// sbuff.append('?');
|
||||
// sbuff.append('^');
|
||||
// sbuff.append('?');
|
||||
count += 2;
|
||||
}
|
||||
} else {
|
||||
// sbuff.append('^');
|
||||
// sbuff.append((char) (ch - 128 + 64));
|
||||
// sbuff.append('^');
|
||||
// sbuff.append((char) (ch - 128 + 64));
|
||||
count += 2;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
} else {
|
||||
// sbuff.append('^');
|
||||
// sbuff.append((char) (ch + 64));
|
||||
// sbuff.append('^');
|
||||
// sbuff.append((char) (ch + 64));
|
||||
return 2;
|
||||
}
|
||||
|
||||
// return sbuff;
|
||||
// return sbuff;
|
||||
}
|
||||
}
|
||||
|
@ -27,8 +27,7 @@ public abstract class Terminal {
|
||||
|
||||
private volatile boolean echoEnabled;
|
||||
|
||||
protected Terminal() {
|
||||
}
|
||||
protected Terminal() {}
|
||||
|
||||
public abstract void init() throws IOException;
|
||||
|
||||
|
@ -16,7 +16,6 @@
|
||||
package dorkbox.util.input;
|
||||
|
||||
public class TerminalType {
|
||||
|
||||
public static final String TYPE = "input.terminal";
|
||||
public static final String READERS = "input.terminal.readers";
|
||||
public static final String ENABLE_BACKSPACE = "input.enableBackspace";
|
||||
|
@ -32,16 +32,16 @@ import java.nio.charset.UnmappableCharacterException;
|
||||
|
||||
|
||||
/**
|
||||
* NOTE for JLine: the default InputStreamReader that comes from the JRE usually read more bytes than needed from the
|
||||
* input stream, which is not usable in a character per character model used in the console. We thus use the harmony
|
||||
* code which only reads the minimal number of bytes, with a modification to ensure we can read larger characters
|
||||
* (UTF-16 has up to 4 bytes, and UTF-32, rare as it is, may have up to 8).
|
||||
* NOTE for JLine: the default InputStreamReader that comes from the JRE usually read more bytes than needed from the input stream, which is
|
||||
* not usable in a character per character model used in the console. We thus use the harmony code which only reads the minimal number of
|
||||
* bytes, with a modification to ensure we can read larger characters (UTF-16 has up to 4 bytes, and UTF-32, rare as it is, may have up to
|
||||
* 8).
|
||||
*
|
||||
*
|
||||
* A class for turning a byte stream into a character stream. Data read from the source input stream is converted into
|
||||
* characters by either a default or a provided character converter. The default encoding is taken from the
|
||||
* "file.encoding" system property. {@code InputStreamReader} contains a buffer of bytes read from the source stream and
|
||||
* converts these into characters as needed. The buffer size is 8K.
|
||||
* A class for turning a byte stream into a character stream. Data read from the source input stream is converted into characters by either
|
||||
* a default or a provided character converter. The default encoding is taken from the "file.encoding" system property.
|
||||
* {@code InputStreamReader} contains a buffer of bytes read from the source stream and converts these into characters as needed. The buffer
|
||||
* size is 8K.
|
||||
*
|
||||
* @see OutputStreamWriter
|
||||
*/
|
||||
@ -61,9 +61,8 @@ class InputStreamReader extends Reader {
|
||||
ByteBuffer bytes = ByteBuffer.allocate(BUFFER_SIZE);
|
||||
|
||||
/**
|
||||
* Constructs a new {@code InputStreamReader} on the {@link InputStream} {@code in}. This constructor sets the
|
||||
* character converter to the encoding specified in the "file.encoding" property and falls back to ISO 8859_1
|
||||
* (ISO-Latin-1) if the property doesn't exist.
|
||||
* Constructs a new {@code InputStreamReader} on the {@link InputStream} {@code in}. This constructor sets the character converter to
|
||||
* the encoding specified in the "file.encoding" property and falls back to ISO 8859_1 (ISO-Latin-1) if the property doesn't exist.
|
||||
*
|
||||
* @param in the input stream from which to read characters.
|
||||
*/
|
||||
@ -72,16 +71,15 @@ class InputStreamReader extends Reader {
|
||||
this.in = in;
|
||||
// FIXME: This should probably use Configuration.getFileEncoding()
|
||||
this.encoding = System.getProperty("file.encoding", "ISO8859_1"); //$NON-NLS-1$//$NON-NLS-2$
|
||||
this.decoder = Charset.forName(this.encoding).newDecoder().onMalformedInput(
|
||||
CodingErrorAction.REPLACE).onUnmappableCharacter(
|
||||
CodingErrorAction.REPLACE);
|
||||
this.decoder =
|
||||
Charset.forName(this.encoding).newDecoder().onMalformedInput(CodingErrorAction.REPLACE)
|
||||
.onUnmappableCharacter(CodingErrorAction.REPLACE);
|
||||
this.bytes.limit(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new InputStreamReader on the InputStream {@code in}. The character converter that is used to decode
|
||||
* bytes into characters is identified by name by {@code enc}. If the encoding cannot be found, an
|
||||
* UnsupportedEncodingException error is thrown.
|
||||
* Constructs a new InputStreamReader on the InputStream {@code in}. The character converter that is used to decode bytes into
|
||||
* characters is identified by name by {@code enc}. If the encoding cannot be found, an UnsupportedEncodingException error is thrown.
|
||||
*
|
||||
* @param in the InputStream from which to read characters.
|
||||
* @param enc identifies the character converter to use.
|
||||
@ -89,7 +87,7 @@ class InputStreamReader extends Reader {
|
||||
* @throws UnsupportedEncodingException if the encoding specified by {@code enc} cannot be found.
|
||||
*/
|
||||
public InputStreamReader(InputStream in, final String enc)
|
||||
// throws UnsupportedEncodingException
|
||||
// throws UnsupportedEncodingException
|
||||
{
|
||||
super(in);
|
||||
|
||||
@ -99,13 +97,13 @@ class InputStreamReader extends Reader {
|
||||
this.in = in;
|
||||
|
||||
try {
|
||||
this.decoder = Charset.forName(enc).newDecoder().onMalformedInput(
|
||||
CodingErrorAction.REPLACE).onUnmappableCharacter(
|
||||
CodingErrorAction.REPLACE);
|
||||
this.decoder =
|
||||
Charset.forName(enc).newDecoder().onMalformedInput(CodingErrorAction.REPLACE)
|
||||
.onUnmappableCharacter(CodingErrorAction.REPLACE);
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
// throw (UnsupportedEncodingException)
|
||||
// new UnsupportedEncodingException(enc).initCause(e);
|
||||
// throw (UnsupportedEncodingException)
|
||||
// new UnsupportedEncodingException(enc).initCause(e);
|
||||
}
|
||||
this.bytes.limit(0);
|
||||
}
|
||||
@ -133,9 +131,7 @@ class InputStreamReader extends Reader {
|
||||
public InputStreamReader(InputStream in, Charset charset) {
|
||||
super(in);
|
||||
this.in = in;
|
||||
this.decoder = charset.newDecoder().onMalformedInput(
|
||||
CodingErrorAction.REPLACE).onUnmappableCharacter(
|
||||
CodingErrorAction.REPLACE);
|
||||
this.decoder = charset.newDecoder().onMalformedInput(CodingErrorAction.REPLACE).onUnmappableCharacter(CodingErrorAction.REPLACE);
|
||||
this.bytes.limit(0);
|
||||
}
|
||||
|
||||
@ -156,8 +152,8 @@ class InputStreamReader extends Reader {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the encoding used to convert bytes into characters. The value {@code null} is returned if this
|
||||
* reader has been closed.
|
||||
* Returns the name of the encoding used to convert bytes into characters. The value {@code null} is returned if this reader has been
|
||||
* closed.
|
||||
*
|
||||
* @return the name of the character converter or {@code null} if this reader is closed.
|
||||
*/
|
||||
@ -169,9 +165,9 @@ class InputStreamReader extends Reader {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a single character from this reader and returns it as an integer with the two higher-order bytes set to 0.
|
||||
* Returns -1 if the end of the reader has been reached. The byte value is either obtained from converting bytes in
|
||||
* this reader's buffer or by first filling the buffer from the source InputStream and then reading from the buffer.
|
||||
* Reads a single character from this reader and returns it as an integer with the two higher-order bytes set to 0. Returns -1 if the
|
||||
* end of the reader has been reached. The byte value is either obtained from converting bytes in this reader's buffer or by first
|
||||
* filling the buffer from the source InputStream and then reading from the buffer.
|
||||
*
|
||||
* @return the character read or -1 if the end of the reader has been reached.
|
||||
* @throws IOException if this reader is closed or some other I/O error occurs.
|
||||
@ -189,17 +185,17 @@ class InputStreamReader extends Reader {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads at most {@code length} characters from this reader and stores them at position {@code offset} in the
|
||||
* character array {@code buf}. Returns the number of characters actually read or -1 if the end of the reader has been
|
||||
* reached. The bytes are either obtained from converting bytes in this reader's buffer or by first filling the buffer
|
||||
* from the source InputStream and then reading from the buffer.
|
||||
* Reads at most {@code length} characters from this reader and stores them at position {@code offset} in the character array
|
||||
* {@code buf}. Returns the number of characters actually read or -1 if the end of the reader has been reached. The bytes are either
|
||||
* obtained from converting bytes in this reader's buffer or by first filling the buffer from the source InputStream and then reading
|
||||
* from the buffer.
|
||||
*
|
||||
* @param buf the array to store the characters read.
|
||||
* @param offset the initial position in {@code buf} to store the characters read from this reader.
|
||||
* @param length the maximum number of characters to read.
|
||||
* @return the number of characters read or -1 if the end of the reader has been reached.
|
||||
* @throws IndexOutOfBoundsException if {@code offset < 0} or {@code length < 0}, or if {@code offset + length} is
|
||||
* greater than the length of {@code buf}.
|
||||
* @throws IndexOutOfBoundsException if {@code offset < 0} or {@code length < 0}, or if {@code offset + length} is greater than the
|
||||
* length of {@code buf}.
|
||||
* @throws IOException if this reader is closed or some other I/O error occurs.
|
||||
*/
|
||||
@Override
|
||||
@ -226,8 +222,7 @@ class InputStreamReader extends Reader {
|
||||
// fill the buffer if needed
|
||||
if (needInput) {
|
||||
try {
|
||||
if (this.in.available() == 0
|
||||
&& out.position() > offset) {
|
||||
if (this.in.available() == 0 && out.position() > offset) {
|
||||
// we could return the result without blocking read
|
||||
break;
|
||||
}
|
||||
@ -281,21 +276,18 @@ class InputStreamReader extends Reader {
|
||||
}
|
||||
|
||||
/*
|
||||
* Answer a boolean indicating whether or not this InputStreamReader is
|
||||
* open.
|
||||
* Answer a boolean indicating whether or not this InputStreamReader is open.
|
||||
*/
|
||||
private boolean isOpen() {
|
||||
return this.in != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether this reader is ready to be read without blocking. If the result is {@code true}, the next {@code
|
||||
* read()} will not block. If the result is {@code false} then this reader may or may not block when {@code read()} is
|
||||
* called. This implementation returns {@code true} if there are bytes available in the buffer or the source stream
|
||||
* has bytes available.
|
||||
* Indicates whether this reader is ready to be read without blocking. If the result is {@code true}, the next {@code read()} will not
|
||||
* block. If the result is {@code false} then this reader may or may not block when {@code read()} is called. This implementation
|
||||
* returns {@code true} if there are bytes available in the buffer or the source stream has bytes available.
|
||||
*
|
||||
* @return {@code true} if the receiver will not block when {@code read()} is called, {@code false} if unknown or
|
||||
* blocking will occur.
|
||||
* @return {@code true} if the receiver will not block when {@code read()} is called, {@code false} if unknown or blocking will occur.
|
||||
* @throws IOException if this reader is closed or some other I/O error occurs.
|
||||
*/
|
||||
@Override
|
||||
|
@ -15,10 +15,10 @@
|
||||
*/
|
||||
package dorkbox.util.input.posix;
|
||||
|
||||
import com.sun.jna.Library;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import com.sun.jna.Library;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
interface PosixTerminalControl extends Library {
|
||||
|
||||
|
@ -15,14 +15,13 @@
|
||||
*/
|
||||
package dorkbox.util.input.posix;
|
||||
|
||||
import com.sun.jna.Structure;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.jna.Structure;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
class TermiosStruct extends Structure {
|
||||
|
||||
/**
|
||||
* input mode flags
|
||||
*/
|
||||
@ -58,8 +57,7 @@ class TermiosStruct extends Structure {
|
||||
*/
|
||||
public int c_ospeed;
|
||||
|
||||
public TermiosStruct() {
|
||||
}
|
||||
public TermiosStruct() {}
|
||||
|
||||
@Override
|
||||
protected List<String> getFieldOrder() {
|
||||
@ -71,7 +69,6 @@ class TermiosStruct extends Structure {
|
||||
"c_line",
|
||||
"c_cc",
|
||||
"c_ispeed",
|
||||
"c_ospeed"
|
||||
);
|
||||
"c_ospeed");
|
||||
}
|
||||
}
|
||||
|
@ -15,18 +15,17 @@
|
||||
*/
|
||||
package dorkbox.util.input.posix;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
|
||||
import dorkbox.util.input.Encoding;
|
||||
import dorkbox.util.input.Terminal;
|
||||
|
||||
/**
|
||||
* Terminal that is used for unix platforms. Terminal initialization is handled via JNA and
|
||||
* ioctl/tcgetattr/tcsetattr/cfmakeraw.
|
||||
* Terminal that is used for unix platforms. Terminal initialization is handled via JNA and ioctl/tcgetattr/tcsetattr/cfmakeraw.
|
||||
*
|
||||
* This implementation should work for an reasonable POSIX system.
|
||||
*/
|
||||
@ -82,13 +81,14 @@ public class UnixTerminal extends Terminal {
|
||||
}
|
||||
|
||||
this.termInfo.c_iflag &= ~PosixTerminalControl.IXON; // DISABLE - flow control mediated by ^S and ^Q
|
||||
// struct.c_iflag |= PosixTerminalControl.IUTF8; // DISABLE - flow control mediated by ^S and ^Q
|
||||
// struct.c_iflag |= PosixTerminalControl.IUTF8; // DISABLE - flow control mediated by ^S and ^Q
|
||||
|
||||
this.termInfo.c_lflag &=
|
||||
~PosixTerminalControl.ICANON; // DISABLE - canonical mode (pass chars straight through to terminal)
|
||||
// struct.c_lflag &= ~PosixTerminalControl.ISIG; // DISABLE - When any of the characters INTR, QUIT, SUSP, or DSUSP are received, generate the corresponding signal.
|
||||
this.termInfo.c_lflag &= ~PosixTerminalControl.ICANON; // DISABLE - canonical mode (pass chars straight through to terminal)
|
||||
// struct.c_lflag &= ~PosixTerminalControl.ISIG; // DISABLE - When any of the characters INTR, QUIT, SUSP, or DSUSP are received,
|
||||
// generate the corresponding signal.
|
||||
|
||||
// If MIN > 0 and TIME = 0, MIN sets the number of characters to receive before the read is satisfied. As TIME is zero, the timer is not used.
|
||||
// If MIN > 0 and TIME = 0, MIN sets the number of characters to receive before the read is satisfied. As TIME is zero, the timer is
|
||||
// not used.
|
||||
this.termInfo.c_cc[PosixTerminalControl.VMIN] = 1; // Minimum number of characters for noncanonical read (MIN).
|
||||
this.termInfo.c_cc[PosixTerminalControl.VTIME] = 0; // Timeout in deciseconds for noncanonical read (TIME).
|
||||
|
||||
@ -102,8 +102,8 @@ public class UnixTerminal extends Terminal {
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the original terminal configuration, which can be used when shutting down the console reader. The
|
||||
* ConsoleReader cannot be used after calling this method.
|
||||
* Restore the original terminal configuration, which can be used when shutting down the console reader. The ConsoleReader cannot be
|
||||
* used after calling this method.
|
||||
*/
|
||||
@Override
|
||||
public final void restore() throws IOException {
|
||||
@ -133,8 +133,7 @@ public class UnixTerminal extends Terminal {
|
||||
return DEFAULT_HEIGHT;
|
||||
}
|
||||
|
||||
return
|
||||
(short) (0x000000FF & this.windowSizeBuffer.get(0) + (0x000000FF & this.windowSizeBuffer.get(1)) * 256);
|
||||
return (short) (0x000000FF & this.windowSizeBuffer.get(0) + (0x000000FF & this.windowSizeBuffer.get(1)) * 256);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -157,31 +156,31 @@ public class UnixTerminal extends Terminal {
|
||||
super.setEchoEnabled(enabled);
|
||||
}
|
||||
|
||||
// public final void disableInterruptCharacter() {
|
||||
// // have to re-get them, since flags change everything
|
||||
// if (this.term.tcgetattr(0, this.termInfo) !=0) {
|
||||
// this.logger.error("Failed to get terminal info");
|
||||
// }
|
||||
//
|
||||
// this.termInfo.c_cc[PosixTerminalControl.VINTR] = 0; // interrupt disabled
|
||||
//
|
||||
// if (this.term.tcsetattr(0, PosixTerminalControl.TCSANOW, this.termInfo) != 0) {
|
||||
// this.logger.error("Can not set terminal flags");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public final void enableInterruptCharacter() {
|
||||
// // have to re-get them, since flags change everything
|
||||
// if (this.term.tcgetattr(0, this.termInfo) !=0) {
|
||||
// this.logger.error("Failed to get terminal info");
|
||||
// }
|
||||
//
|
||||
// this.termInfo.c_cc[PosixTerminalControl.VINTR] = 3; // interrupt is ctrl-c
|
||||
//
|
||||
// if (this.term.tcsetattr(0, PosixTerminalControl.TCSANOW, this.termInfo) != 0) {
|
||||
// this.logger.error("Can not set terminal flags");
|
||||
// }
|
||||
// }
|
||||
// public final void disableInterruptCharacter() {
|
||||
// // have to re-get them, since flags change everything
|
||||
// if (this.term.tcgetattr(0, this.termInfo) !=0) {
|
||||
// this.logger.error("Failed to get terminal info");
|
||||
// }
|
||||
//
|
||||
// this.termInfo.c_cc[PosixTerminalControl.VINTR] = 0; // interrupt disabled
|
||||
//
|
||||
// if (this.term.tcsetattr(0, PosixTerminalControl.TCSANOW, this.termInfo) != 0) {
|
||||
// this.logger.error("Can not set terminal flags");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public final void enableInterruptCharacter() {
|
||||
// // have to re-get them, since flags change everything
|
||||
// if (this.term.tcgetattr(0, this.termInfo) !=0) {
|
||||
// this.logger.error("Failed to get terminal info");
|
||||
// }
|
||||
//
|
||||
// this.termInfo.c_cc[PosixTerminalControl.VINTR] = 3; // interrupt is ctrl-c
|
||||
//
|
||||
// if (this.term.tcsetattr(0, PosixTerminalControl.TCSANOW, this.termInfo) != 0) {
|
||||
// this.logger.error("Can not set terminal flags");
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
public final int read() {
|
||||
|
@ -33,12 +33,10 @@ public class UnsupportedTerminal extends Terminal {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void init() throws IOException {
|
||||
}
|
||||
public final void init() throws IOException {}
|
||||
|
||||
@Override
|
||||
public final void restore() {
|
||||
}
|
||||
public final void restore() {}
|
||||
|
||||
@Override
|
||||
public final int getWidth() {
|
||||
|
@ -12,42 +12,43 @@
|
||||
package dorkbox.util.input.windows;
|
||||
|
||||
/**
|
||||
* Console mode <p/> Constants copied <tt>wincon.h</tt>.
|
||||
* Console mode
|
||||
* <p/>
|
||||
* Constants copied <tt>wincon.h</tt>.
|
||||
*/
|
||||
public enum ConsoleMode {
|
||||
/**
|
||||
* The ReadFile or ReadConsole function returns only when a carriage return character is read. If this mode is
|
||||
* disable, the functions return when one or more characters are available.
|
||||
* The ReadFile or ReadConsole function returns only when a carriage return character is read. If this mode is disable, the functions
|
||||
* return when one or more characters are available.
|
||||
*/
|
||||
ENABLE_LINE_INPUT(2),
|
||||
|
||||
/**
|
||||
* Characters read by the ReadFile or ReadConsole function are written to the active screen buffer as they are read.
|
||||
* This mode can be used only if the ENABLE_LINE_INPUT mode is also enabled.
|
||||
* Characters read by the ReadFile or ReadConsole function are written to the active screen buffer as they are read. This mode can be
|
||||
* used only if the ENABLE_LINE_INPUT mode is also enabled.
|
||||
*/
|
||||
ENABLE_ECHO_INPUT(4),
|
||||
|
||||
/**
|
||||
* CTRL+C is processed by the system and is not placed in the input buffer. If the input buffer is being read by
|
||||
* ReadFile or ReadConsole, other control keys are processed by the system and are not returned in the ReadFile or
|
||||
* ReadConsole buffer. If the ENABLE_LINE_INPUT mode is also enabled, backspace, carriage return, and linefeed
|
||||
* characters are handled by the system.
|
||||
* CTRL+C is processed by the system and is not placed in the input buffer. If the input buffer is being read by ReadFile or
|
||||
* ReadConsole, other control keys are processed by the system and are not returned in the ReadFile or ReadConsole buffer. If the
|
||||
* ENABLE_LINE_INPUT mode is also enabled, backspace, carriage return, and linefeed characters are handled by the system.
|
||||
*/
|
||||
ENABLE_PROCESSED_INPUT(1),
|
||||
|
||||
/**
|
||||
* User interactions that change the size of the console screen buffer are reported in the console's input buffee.
|
||||
* Information about these events can be read from the input buffer by applications using theReadConsoleInput
|
||||
* function, but not by those using ReadFile orReadConsole.
|
||||
* User interactions that change the size of the console screen buffer are reported in the console's input buffee. Information about
|
||||
* these events can be read from the input buffer by applications using theReadConsoleInput function, but not by those using ReadFile
|
||||
* orReadConsole.
|
||||
*/
|
||||
ENABLE_WINDOW_INPUT(8),
|
||||
|
||||
/**
|
||||
* If the mouse pointer is within the borders of the console window and the window has the keyboard focus, mouse
|
||||
* events generated by mouse movement and button presses are placed in the input buffer. These events are discarded by
|
||||
* ReadFile or ReadConsole, even when this mode is enabled.
|
||||
* If the mouse pointer is within the borders of the console window and the window has the keyboard focus, mouse events generated by
|
||||
* mouse movement and button presses are placed in the input buffer. These events are discarded by ReadFile or ReadConsole, even when
|
||||
* this mode is enabled.
|
||||
*/
|
||||
ENABLE_MOUSE_INPUT(16),;
|
||||
ENABLE_MOUSE_INPUT(16), ;
|
||||
|
||||
|
||||
public final int code;
|
||||
|
@ -11,20 +11,21 @@
|
||||
*/
|
||||
package dorkbox.util.input.windows;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.fusesource.jansi.internal.Kernel32.INPUT_RECORD;
|
||||
import org.fusesource.jansi.internal.Kernel32.KEY_EVENT_RECORD;
|
||||
import org.fusesource.jansi.internal.WindowsSupport;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import dorkbox.util.input.Terminal;
|
||||
|
||||
/**
|
||||
* Terminal implementation for Microsoft Windows. Terminal initialization in {@link #init} is accomplished by calling
|
||||
* the Win32 APIs <a href="http://msdn.microsoft.com/library/default.asp? url=/library/en-us/dllproc/base/setconsolemode.asp">SetConsoleMode</a>
|
||||
* and <a href="http://msdn.microsoft.com/library/default.asp? url=/library/en-us/dllproc/base/getconsolemode.asp">GetConsoleMode</a>
|
||||
* to disable character echoing. <p/>
|
||||
* Terminal implementation for Microsoft Windows. Terminal initialization in {@link #init} is accomplished by calling the Win32 APIs <a
|
||||
* href="http://msdn.microsoft.com/library/default.asp? url=/library/en-us/dllproc/base/setconsolemode.asp">SetConsoleMode</a> and <a
|
||||
* href="http://msdn.microsoft.com/library/default.asp? url=/library/en-us/dllproc/base/getconsolemode.asp">GetConsoleMode</a> to disable
|
||||
* character echoing.
|
||||
* <p/>
|
||||
*
|
||||
* @since 2.0 (customized)
|
||||
*/
|
||||
@ -50,8 +51,8 @@ public class WindowsTerminal extends Terminal {
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the original terminal configuration, which can be used when shutting down the console reader. The
|
||||
* ConsoleReader cannot be used after calling this method.
|
||||
* Restore the original terminal configuration, which can be used when shutting down the console reader. The ConsoleReader cannot be
|
||||
* used after calling this method.
|
||||
*/
|
||||
@Override
|
||||
public final void restore() throws IOException {
|
||||
@ -100,7 +101,7 @@ public class WindowsTerminal extends Terminal {
|
||||
if (events != null) {
|
||||
for (int i = 0; i < events.length; i++) {
|
||||
KEY_EVENT_RECORD keyEvent = events[i].keyEvent;
|
||||
//Log.trace(keyEvent.keyDown? "KEY_DOWN" : "KEY_UP", "key code:", keyEvent.keyCode, "char:", (long)keyEvent.uchar);
|
||||
// Log.trace(keyEvent.keyDown? "KEY_DOWN" : "KEY_UP", "key code:", keyEvent.keyCode, "char:", (long)keyEvent.uchar);
|
||||
if (keyEvent.keyDown) {
|
||||
if (keyEvent.uchar > 0) {
|
||||
char uchar = keyEvent.uchar;
|
||||
|
Loading…
Reference in New Issue
Block a user