Package de.mhus.lib.core.console
Class Console
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- java.io.PrintStream
-
- de.mhus.lib.core.console.Console
-
- All Implemented Interfaces:
Adaptable,IBase,Closeable,Flushable,Appendable,AutoCloseable
- Direct Known Subclasses:
ANSIConsole,SimpleConsole,VirtualConsole
public abstract class Console extends PrintStream implements IBase, Adaptable
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classConsole.COLOR
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_HEIGHTstatic intDEFAULT_WIDTHprotected LinkedList<String>history-
Fields inherited from class java.io.FilterOutputStream
out
-
-
Constructor Summary
Constructors Constructor Description Console()Console(PrintStream out)Console(PrintStream out, boolean flush, String charset)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <T> TadaptTo(Class<? extends T> clazz)static charaskQuestion(String question, char[] answers, boolean toLower, boolean acceptEnter)abstract voidcleanup()voidcr()static Consolecreate()Factory to return the correct implementation of console.ConsoleProgressBarcreateProgressBar()static Consoleget()abstract Console.COLORgetBackgroundColor()abstract intgetCursorX()abstract intgetCursorY()abstract Console.COLORgetForegroundColor()abstract intgetHeight()abstract intgetWidth()booleanisAnsi()abstract booleanisBlink()abstract booleanisBold()static booleanisInitialized()abstract booleanisSupportBlink()abstract booleanisSupportBold()abstract booleanisSupportColor()abstract booleanisSupportCursor()abstract booleanisSupportSize()Return true if the console knows about the current size of the terminal.voidprintLine()voidprintLine(char c)abstract intread()Returns the next character from input stream of the console.abstract ConsoleKeyreadKey()StringreadLine()abstract StringreadLine(LinkedList<String> history)StringreadPassword()static voidresetConsole()voidresetTerminal()static voidset(Console console)abstract voidsetBlink(boolean blink)abstract voidsetBold(boolean bold)abstract voidsetColor(Console.COLOR foreground, Console.COLOR background)abstract voidsetCursor(int x, int y)voidsetHeight(int h)voidsetWidth(int w)-
Methods inherited from class java.io.PrintStream
append, append, append, checkError, clearError, close, flush, format, format, print, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, println, setError, write, write
-
Methods inherited from class java.io.FilterOutputStream
write
-
Methods inherited from class java.io.OutputStream
nullOutputStream
-
-
-
-
Field Detail
-
DEFAULT_WIDTH
public static int DEFAULT_WIDTH
-
DEFAULT_HEIGHT
public static int DEFAULT_HEIGHT
-
history
protected LinkedList<String> history
-
-
Constructor Detail
-
Console
public Console()
-
Console
public Console(PrintStream out)
-
Console
public Console(PrintStream out, boolean flush, String charset) throws UnsupportedEncodingException
- Throws:
UnsupportedEncodingException
-
-
Method Detail
-
create
public static Console create()
Factory to return the correct implementation of console.- Returns:
- a new console object
-
readLine
public String readLine()
-
readLine
public abstract String readLine(LinkedList<String> history)
-
read
public abstract int read()
Returns the next character from input stream of the console. In some cases check for ALT key pressed and return character + 1000, see JLine ConsoleReader In case of error a value lesser 0 will be returned.- Returns:
- pressed key
-
readKey
public abstract ConsoleKey readKey()
-
readPassword
public String readPassword() throws IOException
- Throws:
IOException
-
cr
public void cr()
-
isSupportSize
public abstract boolean isSupportSize()
Return true if the console knows about the current size of the terminal.- Returns:
- True if support size
-
getWidth
public abstract int getWidth()
-
getHeight
public abstract int getHeight()
-
isSupportCursor
public abstract boolean isSupportCursor()
-
setCursor
public abstract void setCursor(int x, int y)
-
getCursorX
public abstract int getCursorX()
-
getCursorY
public abstract int getCursorY()
-
createProgressBar
public ConsoleProgressBar createProgressBar()
-
isSupportColor
public abstract boolean isSupportColor()
-
setColor
public abstract void setColor(Console.COLOR foreground, Console.COLOR background)
-
getForegroundColor
public abstract Console.COLOR getForegroundColor()
-
getBackgroundColor
public abstract Console.COLOR getBackgroundColor()
-
isSupportBlink
public abstract boolean isSupportBlink()
-
setBlink
public abstract void setBlink(boolean blink)
-
isBlink
public abstract boolean isBlink()
-
isSupportBold
public abstract boolean isSupportBold()
-
setBold
public abstract void setBold(boolean bold)
-
isBold
public abstract boolean isBold()
-
cleanup
public abstract void cleanup()
-
printLine
public void printLine()
-
adaptTo
public <T> T adaptTo(Class<? extends T> clazz)
-
printLine
public void printLine(char c)
-
resetTerminal
public void resetTerminal()
-
resetConsole
public static void resetConsole()
-
get
public static Console get()
-
set
public static void set(Console console)
-
isInitialized
public static boolean isInitialized()
-
isAnsi
public boolean isAnsi()
-
setWidth
public void setWidth(int w)
-
setHeight
public void setHeight(int h)
-
askQuestion
public static char askQuestion(String question, char[] answers, boolean toLower, boolean acceptEnter) throws IOException
- Throws:
IOException
-
-