|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectohmm.ConsoleNonblocking
public class ConsoleNonblocking
Example of doing non-blocking console input on Unix.
Tested on Linux and OSX.
Based on ideas from Here.
Field Summary | |
---|---|
private static boolean |
configDone
whether we've configured the TTY yet |
static int |
ESC
ASCII escape character |
Constructor Summary | |
---|---|
ConsoleNonblocking()
|
Method Summary | |
---|---|
static int |
getChar()
getChar(int) with no timeout |
static int |
getChar(int timeoutMS)
Like System.in.read() but nonblocking. |
static void |
main(java.lang.String[] args)
Demo program, reads input until user hits ESC. |
static java.lang.String |
stty(java.lang.String cfg)
Run stty with the given options. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int ESC
private static boolean configDone
Constructor Detail |
---|
public ConsoleNonblocking()
Method Detail |
---|
public static int getChar(int timeoutMS) throws java.io.IOException, java.lang.InterruptedException
timeoutMS
- max milliseconds to wait, or 0 to wait forever
Configures terminal for nonblocking input on first call; registers shutdown hook to restore it.
java.io.IOException
java.lang.InterruptedException
public static int getChar() throws java.io.IOException, java.lang.InterruptedException
getChar(int)
with no timeout
java.io.IOException
java.lang.InterruptedException
public static java.lang.String stty(java.lang.String cfg) throws java.io.IOException, java.lang.InterruptedException
cfg
- the stty options
java.io.IOException
java.lang.InterruptedException
public static void main(java.lang.String[] args) throws java.io.IOException, java.lang.InterruptedException
java.io.IOException
java.lang.InterruptedException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |