Package org.fusesource.jansi
Class AnsiPrintStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- java.io.PrintStream
-
- org.fusesource.jansi.FilterPrintStream
-
- org.fusesource.jansi.AnsiPrintStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.Appendable,java.lang.AutoCloseable
- Direct Known Subclasses:
WindowsAnsiPrintStream
public class AnsiPrintStream extends FilterPrintStream
A ANSI print stream extracts ANSI escape codes written to a print stream and calls correspondingprocess*methods.For more information about ANSI escape codes, see Wikipedia article
This class just filters out the escape codes so that they are not sent out to the underlying OutputStream:
process*methods are empty. Subclasses should actually perform the ANSI escape behaviors by implementing active code inprocess*methods.- Since:
- 1.7
- Author:
- Hiram Chirino, Joris Kuipers
- See Also:
AnsiOutputStream
-
-
Field Summary
Fields Modifier and Type Field Description protected static intATTRIBUTE_BLINK_FASTprotected static intATTRIBUTE_BLINK_OFFprotected static intATTRIBUTE_BLINK_SLOWprotected static intATTRIBUTE_CONCEAL_OFFprotected static intATTRIBUTE_CONCEAL_ONprotected static intATTRIBUTE_INTENSITY_BOLDprotected static intATTRIBUTE_INTENSITY_FAINTprotected static intATTRIBUTE_INTENSITY_NORMALprotected static intATTRIBUTE_ITALICprotected static intATTRIBUTE_NEGATIVE_OffDeprecated.protected static intATTRIBUTE_NEGATIVE_OFFprotected static intATTRIBUTE_NEGATIVE_ONprotected static intATTRIBUTE_UNDERLINEprotected static intATTRIBUTE_UNDERLINE_DOUBLEprotected static intATTRIBUTE_UNDERLINE_OFFprotected static intBLACKprotected static intBLUEprotected static intCYANprotected static intERASE_LINEprotected static intERASE_LINE_TO_BEGININGprotected static intERASE_LINE_TO_ENDprotected static intERASE_SCREENprotected static intERASE_SCREEN_TO_BEGININGprotected static intERASE_SCREEN_TO_ENDprotected static intGREENprotected static intMAGENTAprotected static intREDstatic java.lang.StringRESET_CODEprotected static intWHITEprotected static intYELLOW-
Fields inherited from class org.fusesource.jansi.FilterPrintStream
ps
-
-
Constructor Summary
Constructors Constructor Description AnsiPrintStream(java.io.PrintStream ps)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()protected booleanfilter(int data)Filter the contentprotected voidprocessAttributeRest()processSGR 0corresponding toReset / Normalprotected voidprocessChangeIconName(java.lang.String label)processOSC 1;text BELcorresponding toChange Icon labelprotected voidprocessChangeIconNameAndWindowTitle(java.lang.String label)processOSC 0;text BELcorresponding toChange Window and Icon labelprotected voidprocessChangeWindowTitle(java.lang.String label)processOSC 2;text BELcorresponding toChange Window titleprotected voidprocessCharsetSelect(int set, char seq)protected voidprocessCursorDown(int count)processCSI n Bcorresponding toCUD – Cursor Downprotected voidprocessCursorDownLine(int count)processCSI n Ecorresponding toCNL – Cursor Next Lineprotected voidprocessCursorLeft(int count)processCSI n Dcorresponding toCUB – Cursor Backprotected voidprocessCursorRight(int count)processCSI n Ccorresponding toCUF – Cursor Forwardprotected voidprocessCursorTo(int row, int col)processCSI n ; m Hcorresponding toCUP – Cursor PositionorCSI n ; m fcorresponding toHVP – Horizontal and Vertical Positionprotected voidprocessCursorToColumn(int x)processCSI n Gcorresponding toCHA – Cursor Horizontal Absoluteprotected voidprocessCursorUp(int count)processCSI n Acorresponding toCUU – Cursor Upprotected voidprocessCursorUpLine(int count)processCSI n Fcorresponding toCPL – Cursor Previous Lineprotected voidprocessDefaultBackgroundColor()processSGR 49corresponding toDefault background colorprotected voidprocessDefaultTextColor()processSGR 39corresponding toDefault text color (foreground)protected voidprocessDeleteLine(int optionInt)ProcessCSI MANSI code, corresponding toDL – Delete Lineprotected voidprocessEraseLine(int eraseOption)ProcessCSI n KANSI code, corresponding toED – Erase in Lineprotected voidprocessEraseScreen(int eraseOption)ProcessCSI n JANSI code, corresponding toED – Erase in Displayprotected voidprocessInsertLine(int optionInt)ProcessCSI LANSI code, corresponding toIL – Insert Lineprotected voidprocessRestoreCursorPosition()ProcessCSI uANSI code, corresponding toRCP – Restore Cursor Positionprotected voidprocessSaveCursorPosition()ProcessCSI sANSI code, corresponding toSCP – Save Cursor Positionprotected voidprocessScrollDown(int optionInt)ProcessCSI n TANSI code, corresponding toSD – Scroll Downprotected voidprocessScrollUp(int optionInt)ProcessCSI n UANSI code, corresponding toSU – Scroll Upprotected voidprocessSetAttribute(int attribute)processSGRother than0(reset),30-39(foreground),40-49(background),90-97(foreground high intensity) or100-107(background high intensity)protected voidprocessSetBackgroundColor(int color)processSGR 40-47corresponding toSet background color.protected voidprocessSetBackgroundColor(int color, boolean bright)processSGR 40-47orSGR 100-107corresponding toSet background coloreither in normal mode or high intensity.protected voidprocessSetBackgroundColorExt(int paletteIndex)processSGR 48corresponding toextended set background colorwith a palette of 255 colors.protected voidprocessSetBackgroundColorExt(int r, int g, int b)processSGR 48corresponding toextended set background colorwith a 24 bits RGB definition of the color.protected voidprocessSetForegroundColor(int color)processSGR 30-37corresponding toSet text color (foreground).protected voidprocessSetForegroundColor(int color, boolean bright)processSGR 30-37orSGR 90-97corresponding toSet text color (foreground)either in normal mode or high intensity.protected voidprocessSetForegroundColorExt(int paletteIndex)processSGR 38corresponding toextended set text color (foreground)with a palette of 255 colors.protected voidprocessSetForegroundColorExt(int r, int g, int b)processSGR 38corresponding toextended set text color (foreground)with a 24 bits RGB definition of the color.protected voidprocessUnknownExtension(java.util.ArrayList<java.lang.Object> options, int command)Process Unknown Extensionprotected voidprocessUnknownOperatingSystemCommand(int command, java.lang.String param)Process unknownOSCcommand.-
Methods inherited from class org.fusesource.jansi.FilterPrintStream
checkError, flush, print, print, print, print, print, print, print, print, print, println, println, println, println, println, println, println, println, println, println, write, write
-
-
-
-
Field Detail
-
RESET_CODE
public static final java.lang.String RESET_CODE
- See Also:
- Constant Field Values
-
ERASE_SCREEN_TO_END
protected static final int ERASE_SCREEN_TO_END
- See Also:
- Constant Field Values
-
ERASE_SCREEN_TO_BEGINING
protected static final int ERASE_SCREEN_TO_BEGINING
- See Also:
- Constant Field Values
-
ERASE_SCREEN
protected static final int ERASE_SCREEN
- See Also:
- Constant Field Values
-
ERASE_LINE_TO_END
protected static final int ERASE_LINE_TO_END
- See Also:
- Constant Field Values
-
ERASE_LINE_TO_BEGINING
protected static final int ERASE_LINE_TO_BEGINING
- See Also:
- Constant Field Values
-
ERASE_LINE
protected static final int ERASE_LINE
- See Also:
- Constant Field Values
-
ATTRIBUTE_INTENSITY_BOLD
protected static final int ATTRIBUTE_INTENSITY_BOLD
- See Also:
- Constant Field Values
-
ATTRIBUTE_INTENSITY_FAINT
protected static final int ATTRIBUTE_INTENSITY_FAINT
- See Also:
- Constant Field Values
-
ATTRIBUTE_ITALIC
protected static final int ATTRIBUTE_ITALIC
- See Also:
- Constant Field Values
-
ATTRIBUTE_UNDERLINE
protected static final int ATTRIBUTE_UNDERLINE
- See Also:
- Constant Field Values
-
ATTRIBUTE_BLINK_SLOW
protected static final int ATTRIBUTE_BLINK_SLOW
- See Also:
- Constant Field Values
-
ATTRIBUTE_BLINK_FAST
protected static final int ATTRIBUTE_BLINK_FAST
- See Also:
- Constant Field Values
-
ATTRIBUTE_NEGATIVE_ON
protected static final int ATTRIBUTE_NEGATIVE_ON
- See Also:
- Constant Field Values
-
ATTRIBUTE_CONCEAL_ON
protected static final int ATTRIBUTE_CONCEAL_ON
- See Also:
- Constant Field Values
-
ATTRIBUTE_UNDERLINE_DOUBLE
protected static final int ATTRIBUTE_UNDERLINE_DOUBLE
- See Also:
- Constant Field Values
-
ATTRIBUTE_INTENSITY_NORMAL
protected static final int ATTRIBUTE_INTENSITY_NORMAL
- See Also:
- Constant Field Values
-
ATTRIBUTE_UNDERLINE_OFF
protected static final int ATTRIBUTE_UNDERLINE_OFF
- See Also:
- Constant Field Values
-
ATTRIBUTE_BLINK_OFF
protected static final int ATTRIBUTE_BLINK_OFF
- See Also:
- Constant Field Values
-
ATTRIBUTE_NEGATIVE_Off
@Deprecated protected static final int ATTRIBUTE_NEGATIVE_Off
Deprecated.- See Also:
- Constant Field Values
-
ATTRIBUTE_NEGATIVE_OFF
protected static final int ATTRIBUTE_NEGATIVE_OFF
- See Also:
- Constant Field Values
-
ATTRIBUTE_CONCEAL_OFF
protected static final int ATTRIBUTE_CONCEAL_OFF
- See Also:
- Constant Field Values
-
BLACK
protected static final int BLACK
- See Also:
- Constant Field Values
-
RED
protected static final int RED
- See Also:
- Constant Field Values
-
GREEN
protected static final int GREEN
- See Also:
- Constant Field Values
-
YELLOW
protected static final int YELLOW
- See Also:
- Constant Field Values
-
BLUE
protected static final int BLUE
- See Also:
- Constant Field Values
-
MAGENTA
protected static final int MAGENTA
- See Also:
- Constant Field Values
-
CYAN
protected static final int CYAN
- See Also:
- Constant Field Values
-
WHITE
protected static final int WHITE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AnsiPrintStream
public AnsiPrintStream(java.io.PrintStream ps)
-
-
Method Detail
-
filter
protected boolean filter(int data)
Description copied from class:FilterPrintStreamFilter the content- Overrides:
filterin classFilterPrintStream- Parameters:
data- character to filter- Returns:
trueif the data is not filtered then has to be printed to delegate PrintStream
-
processRestoreCursorPosition
protected void processRestoreCursorPosition() throws java.io.IOException
ProcessCSI uANSI code, corresponding toRCP – Restore Cursor Position- Throws:
java.io.IOException- IOException
-
processSaveCursorPosition
protected void processSaveCursorPosition() throws java.io.IOException
ProcessCSI sANSI code, corresponding toSCP – Save Cursor Position- Throws:
java.io.IOException- IOException
-
processInsertLine
protected void processInsertLine(int optionInt) throws java.io.IOException
ProcessCSI LANSI code, corresponding toIL – Insert Line- Parameters:
optionInt- option- Throws:
java.io.IOException- IOException- Since:
- 1.16
-
processDeleteLine
protected void processDeleteLine(int optionInt) throws java.io.IOException
ProcessCSI MANSI code, corresponding toDL – Delete Line- Parameters:
optionInt- option- Throws:
java.io.IOException- IOException- Since:
- 1.16
-
processScrollDown
protected void processScrollDown(int optionInt) throws java.io.IOException
ProcessCSI n TANSI code, corresponding toSD – Scroll Down- Parameters:
optionInt- option- Throws:
java.io.IOException- IOException
-
processScrollUp
protected void processScrollUp(int optionInt) throws java.io.IOException
ProcessCSI n UANSI code, corresponding toSU – Scroll Up- Parameters:
optionInt- option- Throws:
java.io.IOException- IOException
-
processEraseScreen
protected void processEraseScreen(int eraseOption) throws java.io.IOException
ProcessCSI n JANSI code, corresponding toED – Erase in Display- Parameters:
eraseOption- eraseOption- Throws:
java.io.IOException- IOException
-
processEraseLine
protected void processEraseLine(int eraseOption) throws java.io.IOException
ProcessCSI n KANSI code, corresponding toED – Erase in Line- Parameters:
eraseOption- eraseOption- Throws:
java.io.IOException- IOException
-
processSetAttribute
protected void processSetAttribute(int attribute) throws java.io.IOException
processSGRother than0(reset),30-39(foreground),40-49(background),90-97(foreground high intensity) or100-107(background high intensity)- Parameters:
attribute- attribute- Throws:
java.io.IOException- IOException- See Also:
processAttributeRest(),processSetForegroundColor(int),processSetForegroundColor(int, boolean),processSetForegroundColorExt(int),processSetForegroundColorExt(int, int, int),processDefaultTextColor(),processDefaultBackgroundColor()
-
processSetForegroundColor
protected void processSetForegroundColor(int color) throws java.io.IOException
processSGR 30-37corresponding toSet text color (foreground).- Parameters:
color- the text color- Throws:
java.io.IOException- IOException
-
processSetForegroundColor
protected void processSetForegroundColor(int color, boolean bright) throws java.io.IOException
processSGR 30-37orSGR 90-97corresponding toSet text color (foreground)either in normal mode or high intensity.- Parameters:
color- the text colorbright- is high intensity?- Throws:
java.io.IOException- IOException
-
processSetForegroundColorExt
protected void processSetForegroundColorExt(int paletteIndex) throws java.io.IOException
processSGR 38corresponding toextended set text color (foreground)with a palette of 255 colors.- Parameters:
paletteIndex- the text color in the palette- Throws:
java.io.IOException- IOException
-
processSetForegroundColorExt
protected void processSetForegroundColorExt(int r, int g, int b) throws java.io.IOException
processSGR 38corresponding toextended set text color (foreground)with a 24 bits RGB definition of the color.- Parameters:
r- redg- greenb- blue- Throws:
java.io.IOException- IOException
-
processSetBackgroundColor
protected void processSetBackgroundColor(int color) throws java.io.IOException
processSGR 40-47corresponding toSet background color.- Parameters:
color- the background color- Throws:
java.io.IOException- IOException
-
processSetBackgroundColor
protected void processSetBackgroundColor(int color, boolean bright) throws java.io.IOException
processSGR 40-47orSGR 100-107corresponding toSet background coloreither in normal mode or high intensity.- Parameters:
color- the background colorbright- is high intensity?- Throws:
java.io.IOException- IOException
-
processSetBackgroundColorExt
protected void processSetBackgroundColorExt(int paletteIndex) throws java.io.IOException
processSGR 48corresponding toextended set background colorwith a palette of 255 colors.- Parameters:
paletteIndex- the background color in the palette- Throws:
java.io.IOException- IOException
-
processSetBackgroundColorExt
protected void processSetBackgroundColorExt(int r, int g, int b) throws java.io.IOException
processSGR 48corresponding toextended set background colorwith a 24 bits RGB definition of the color.- Parameters:
r- redg- greenb- blue- Throws:
java.io.IOException- IOException
-
processDefaultTextColor
protected void processDefaultTextColor() throws java.io.IOException
processSGR 39corresponding toDefault text color (foreground)- Throws:
java.io.IOException- IOException
-
processDefaultBackgroundColor
protected void processDefaultBackgroundColor() throws java.io.IOException
processSGR 49corresponding toDefault background color- Throws:
java.io.IOException- IOException
-
processAttributeRest
protected void processAttributeRest() throws java.io.IOException
processSGR 0corresponding toReset / Normal- Throws:
java.io.IOException- IOException
-
processCursorTo
protected void processCursorTo(int row, int col) throws java.io.IOException
processCSI n ; m Hcorresponding toCUP – Cursor PositionorCSI n ; m fcorresponding toHVP – Horizontal and Vertical Position- Parameters:
row- rowcol- col- Throws:
java.io.IOException- IOException
-
processCursorToColumn
protected void processCursorToColumn(int x) throws java.io.IOException
processCSI n Gcorresponding toCHA – Cursor Horizontal Absolute- Parameters:
x- the column- Throws:
java.io.IOException- IOException
-
processCursorUpLine
protected void processCursorUpLine(int count) throws java.io.IOException
processCSI n Fcorresponding toCPL – Cursor Previous Line- Parameters:
count- line count- Throws:
java.io.IOException- IOException
-
processCursorDownLine
protected void processCursorDownLine(int count) throws java.io.IOException
processCSI n Ecorresponding toCNL – Cursor Next Line- Parameters:
count- line count- Throws:
java.io.IOException- IOException
-
processCursorLeft
protected void processCursorLeft(int count) throws java.io.IOException
processCSI n Dcorresponding toCUB – Cursor Back- Parameters:
count- count- Throws:
java.io.IOException- IOException
-
processCursorRight
protected void processCursorRight(int count) throws java.io.IOException
processCSI n Ccorresponding toCUF – Cursor Forward- Parameters:
count- count- Throws:
java.io.IOException- IOException
-
processCursorDown
protected void processCursorDown(int count) throws java.io.IOException
processCSI n Bcorresponding toCUD – Cursor Down- Parameters:
count- count- Throws:
java.io.IOException- IOException
-
processCursorUp
protected void processCursorUp(int count) throws java.io.IOException
processCSI n Acorresponding toCUU – Cursor Up- Parameters:
count- count- Throws:
java.io.IOException- IOException
-
processUnknownExtension
protected void processUnknownExtension(java.util.ArrayList<java.lang.Object> options, int command)
Process Unknown Extension- Parameters:
options- optionscommand- command
-
processChangeIconNameAndWindowTitle
protected void processChangeIconNameAndWindowTitle(java.lang.String label)
processOSC 0;text BELcorresponding toChange Window and Icon label- Parameters:
label- window title name
-
processChangeIconName
protected void processChangeIconName(java.lang.String label)
processOSC 1;text BELcorresponding toChange Icon label- Parameters:
label- icon label
-
processChangeWindowTitle
protected void processChangeWindowTitle(java.lang.String label)
processOSC 2;text BELcorresponding toChange Window title- Parameters:
label- window title text
-
processUnknownOperatingSystemCommand
protected void processUnknownOperatingSystemCommand(int command, java.lang.String param)
Process unknownOSCcommand.- Parameters:
command- commandparam- param
-
processCharsetSelect
protected void processCharsetSelect(int set, char seq)
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classFilterPrintStream
-
-