public class Terminal extends CharReader implements Closeable, LinePrinter
| Constructor and Description |
|---|
Terminal()
Construct a default RAW terminal.
|
Terminal(STTY tty)
Construct a default RAW terminal.
|
Terminal(STTY tty,
InputStream in,
OutputStream out,
LinePrinter lp,
STTYModeSwitcher switcher)
Constructor visible for testing.
|
Terminal(STTY tty,
LinePrinter lp)
Construct a terminal with a custom line printer.
|
Terminal(STTY tty,
STTYMode mode)
Construct a terminal with given mode.
|
Terminal(STTY tty,
STTYMode mode,
LinePrinter lp)
Construct a terminal with a terminal mode and custom line printer.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
boolean |
confirm(String what)
Make a user confirmation.
|
boolean |
confirm(String what,
boolean def)
Make a user confirmation.
|
<T> T |
executeAbortable(ExecutorService exec,
Callable<T> callable)
Execute callable, which may not be interruptable by itself, but listen to
terminal input and abort the task if CTRL-C is pressed.
|
void |
executeAbortable(ExecutorService exec,
Runnable callable)
Execute runnable, which may not be interruptable by itself, but listen to
terminal input and abort the task if CTRL-C is pressed.
|
void |
finish()
Finish the current set of lines and continue below.
|
void |
format(String format,
Object... args) |
protected OutputStream |
getOutputStream() |
STTY |
getTTY() |
void |
print(Char ch) |
void |
print(String message) |
PrintStream |
printer()
Get a print stream that writes to the terminal according to the
output mode of the terminal.
|
void |
println() |
void |
println(String message)
Print a new line to the terminal.
|
protected void |
sleep(long millis) |
<T> void |
waitAbortable(Future<T> task)
Wait for future task to be done or canceled.
|
read, readIfAvailablepublic Terminal()
UncheckedIOException - If unable to set TTY mode.public Terminal(STTY tty)
tty - The terminal device.UncheckedIOException - If unable to set TTY mode.public Terminal(STTY tty, STTYMode mode)
tty - The terminal device.mode - The terminal mode.UncheckedIOException - If unable to set TTY mode.public Terminal(STTY tty, LinePrinter lp)
tty - The terminal device.lp - The line printer.UncheckedIOException - If unable to set TTY mode.public Terminal(STTY tty, STTYMode mode, LinePrinter lp)
tty - The terminal device.mode - The terminal mode.lp - The line printer.UncheckedIOException - If unable to set TTY mode.public Terminal(STTY tty, InputStream in, OutputStream out, LinePrinter lp, STTYModeSwitcher switcher)
tty - The terminal device.in - The input stream.out - The output stream.lp - The line printer or null.switcher - TTY mode switcher.UncheckedIOException - If unable to set TTY mode.public STTY getTTY()
public PrintStream printer()
public boolean confirm(String what)
boolean really = term.confirm("Do you o'Really?");
Will print out "Do you o'Really? [Y/n]: ". If the user press
'y' and 'enter' will pass (return true), if 'n', and 'backspace' will return
false. Invalid characters will print a short error message.what - What to confirm. Basically the message before '[Y/n]'.public boolean confirm(String what, boolean def)
boolean really = term.confirm("Do you o'Really?", false);
Will print out "Do you o'Really? [y/N]: ". If the user press
'y' will pass (return true), if 'n', 'enter' and 'backspace' will return
false. Invalid characters will print a short error message.what - What to confirm. Basically the message before '[Y/n]'.def - the default response on 'enter'.public <T> T executeAbortable(ExecutorService exec, Callable<T> callable) throws IOException, InterruptedException, ExecutionException
T - The return type of the callable.exec - The executor to run task on.callable - The callable function.IOException - If aborted or read failure.InterruptedException - If interrupted while waiting.ExecutionException - If execution failed.public void executeAbortable(ExecutorService exec, Runnable callable) throws IOException, InterruptedException, ExecutionException
exec - The executor to run task on.callable - The runnable function.IOException - If aborted or read failure.InterruptedException - If interrupted while waiting.ExecutionException - If execution failed.public <T> void waitAbortable(Future<T> task) throws IOException, InterruptedException
T - The task generic type.task - The task to wait for.IOException - On aborted or read failure.InterruptedException - On thread interrupted.public void print(Char ch)
public void print(String message)
public void println(String message)
LinePrinterprintln in interface LinePrintermessage - The message to write.public void println()
public void finish()
public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionprotected OutputStream getOutputStream()
protected void sleep(long millis)
throws InterruptedException
InterruptedExceptionCopyright © 2017. All rights reserved.