Class AnsiOutputStream
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
org.fusesource.jansi.AnsiOutputStream
- All Implemented Interfaces:
Closeable, Flushable, AutoCloseable
- Direct Known Subclasses:
HtmlAnsiOutputStream, WindowsAnsiOutputStream
A ANSI output stream extracts ANSI escape codes written to
an output stream and calls corresponding
process* 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 in process* methods.
- Since:
- 1.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intDeprecated.protected static final intprotected static final intprotected static final intprotected static final intprotected static final intprivate static final intprotected static final intprotected static final intprivate final byte[]protected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprivate static final intprotected static final intprivate static final intprivate static final intprivate static final intprivate static final intprivate static final intprivate static final intprivate static final intprivate static final intprivate static final intprivate static final intprotected static final intprivate static final intprivate intprotected static final intstatic final byte[]static final byte[]Deprecated.private static final intprivate static final intprivate static final intprivate static final intprivate static final intprivate int(package private) intprotected static final intprotected static final intFields inherited from class FilterOutputStream
out -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()private intgetNextOptionInt(Iterator<Object> optionsIterator) Helper for processEscapeCommand() to iterate over integer optionsprivate intprivate intprotected voidprocessSGR 0corresponding toReset / Normalprotected voidprocessChangeIconName(String label) processOSC 1;text BELcorresponding toChange Icon labelprotected voidprocessOSC 0;text BELcorresponding toChange Window and Icon labelprotected voidprocessChangeWindowTitle(String label) processOSC 2;text BELcorresponding toChange Window titleprotected voidprocessCharsetSelect(int set, char seq) private booleanprocessCharsetSelect(ArrayList<Object> options) Process character set sequence.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 voidprocessSGR 49corresponding toDefault background colorprotected voidprocessSGR 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 Displayprivate booleanprocessEscapeCommand(ArrayList<Object> options, int command) protected voidprocessInsertLine(int optionInt) ProcessCSI LANSI code, corresponding toIL – Insert Lineprivate booleanprocessOperatingSystemCommand(ArrayList<Object> options) protected voidProcessCSI uANSI code, corresponding toRCP – Restore Cursor Positionprotected voidProcessCSI 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(ArrayList<Object> options, int command) protected voidprocessUnknownOperatingSystemCommand(int command, String param) Process unknownOSCcommand.private voidreset(boolean skipBuffer) Resets all state to continue with regular parsingvoidwrite(int data) Methods inherited from class FilterOutputStream
flush, write, writeMethods inherited from class OutputStream
nullOutputStream
-
Field Details
-
RESET_CODE
public static final byte[] RESET_CODE -
REST_CODE
Deprecated. -
MAX_ESCAPE_SEQUENCE_LENGTH
private static final int MAX_ESCAPE_SEQUENCE_LENGTH- See Also:
-
buffer
private final byte[] buffer -
pos
private int pos -
startOfValue
private int startOfValue -
options
-
LOOKING_FOR_FIRST_ESC_CHAR
private static final int LOOKING_FOR_FIRST_ESC_CHAR- See Also:
-
LOOKING_FOR_SECOND_ESC_CHAR
private static final int LOOKING_FOR_SECOND_ESC_CHAR- See Also:
-
LOOKING_FOR_NEXT_ARG
private static final int LOOKING_FOR_NEXT_ARG- See Also:
-
LOOKING_FOR_STR_ARG_END
private static final int LOOKING_FOR_STR_ARG_END- See Also:
-
LOOKING_FOR_INT_ARG_END
private static final int LOOKING_FOR_INT_ARG_END- See Also:
-
LOOKING_FOR_OSC_COMMAND
private static final int LOOKING_FOR_OSC_COMMAND- See Also:
-
LOOKING_FOR_OSC_COMMAND_END
private static final int LOOKING_FOR_OSC_COMMAND_END- See Also:
-
LOOKING_FOR_OSC_PARAM
private static final int LOOKING_FOR_OSC_PARAM- See Also:
-
LOOKING_FOR_ST
private static final int LOOKING_FOR_ST- See Also:
-
LOOKING_FOR_CHARSET
private static final int LOOKING_FOR_CHARSET- See Also:
-
state
int state -
FIRST_ESC_CHAR
private static final int FIRST_ESC_CHAR- See Also:
-
SECOND_ESC_CHAR
private static final int SECOND_ESC_CHAR- See Also:
-
SECOND_OSC_CHAR
private static final int SECOND_OSC_CHAR- See Also:
-
BEL
private static final int BEL- See Also:
-
SECOND_ST_CHAR
private static final int SECOND_ST_CHAR- See Also:
-
SECOND_CHARSET0_CHAR
private static final int SECOND_CHARSET0_CHAR- See Also:
-
SECOND_CHARSET1_CHAR
private static final int SECOND_CHARSET1_CHAR- See Also:
-
ERASE_SCREEN_TO_END
protected static final int ERASE_SCREEN_TO_END- See Also:
-
ERASE_SCREEN_TO_BEGINING
protected static final int ERASE_SCREEN_TO_BEGINING- See Also:
-
ERASE_SCREEN
protected static final int ERASE_SCREEN- See Also:
-
ERASE_LINE_TO_END
protected static final int ERASE_LINE_TO_END- See Also:
-
ERASE_LINE_TO_BEGINING
protected static final int ERASE_LINE_TO_BEGINING- See Also:
-
ERASE_LINE
protected static final int ERASE_LINE- See Also:
-
ATTRIBUTE_INTENSITY_BOLD
protected static final int ATTRIBUTE_INTENSITY_BOLD- See Also:
-
ATTRIBUTE_INTENSITY_FAINT
protected static final int ATTRIBUTE_INTENSITY_FAINT- See Also:
-
ATTRIBUTE_ITALIC
protected static final int ATTRIBUTE_ITALIC- See Also:
-
ATTRIBUTE_UNDERLINE
protected static final int ATTRIBUTE_UNDERLINE- See Also:
-
ATTRIBUTE_BLINK_SLOW
protected static final int ATTRIBUTE_BLINK_SLOW- See Also:
-
ATTRIBUTE_BLINK_FAST
protected static final int ATTRIBUTE_BLINK_FAST- See Also:
-
ATTRIBUTE_NEGATIVE_ON
protected static final int ATTRIBUTE_NEGATIVE_ON- See Also:
-
ATTRIBUTE_CONCEAL_ON
protected static final int ATTRIBUTE_CONCEAL_ON- See Also:
-
ATTRIBUTE_UNDERLINE_DOUBLE
protected static final int ATTRIBUTE_UNDERLINE_DOUBLE- See Also:
-
ATTRIBUTE_INTENSITY_NORMAL
protected static final int ATTRIBUTE_INTENSITY_NORMAL- See Also:
-
ATTRIBUTE_UNDERLINE_OFF
protected static final int ATTRIBUTE_UNDERLINE_OFF- See Also:
-
ATTRIBUTE_BLINK_OFF
protected static final int ATTRIBUTE_BLINK_OFF- See Also:
-
ATTRIBUTE_NEGATIVE_Off
-
ATTRIBUTE_NEGATIVE_OFF
protected static final int ATTRIBUTE_NEGATIVE_OFF- See Also:
-
ATTRIBUTE_CONCEAL_OFF
protected static final int ATTRIBUTE_CONCEAL_OFF- See Also:
-
BLACK
protected static final int BLACK- See Also:
-
RED
protected static final int RED- See Also:
-
GREEN
protected static final int GREEN- See Also:
-
YELLOW
protected static final int YELLOW- See Also:
-
BLUE
protected static final int BLUE- See Also:
-
MAGENTA
protected static final int MAGENTA- See Also:
-
CYAN
protected static final int CYAN- See Also:
-
WHITE
protected static final int WHITE- See Also:
-
-
Constructor Details
-
AnsiOutputStream
-
-
Method Details
-
write
- Overrides:
writein classFilterOutputStream- Throws:
IOException
-
reset
Resets all state to continue with regular parsing- Parameters:
skipBuffer- if current buffer should be skipped or written to out- Throws:
IOException
-
getNextOptionInt
Helper for processEscapeCommand() to iterate over integer options- Parameters:
optionsIterator- the underlying iterator- Throws:
IOException- if no more non-null values left
-
processEscapeCommand
- Parameters:
options-command-- Returns:
- true if the escape command was processed.
- Throws:
IOException
-
processOperatingSystemCommand
- Parameters:
options-- Returns:
- true if the operating system command was processed.
- Throws:
IOException
-
processRestoreCursorPosition
ProcessCSI uANSI code, corresponding toRCP – Restore Cursor Position- Throws:
IOException- IOException
-
processSaveCursorPosition
ProcessCSI sANSI code, corresponding toSCP – Save Cursor Position- Throws:
IOException- IOException
-
processInsertLine
ProcessCSI LANSI code, corresponding toIL – Insert Line- Parameters:
optionInt- option- Throws:
IOException- IOException- Since:
- 1.16
-
processDeleteLine
ProcessCSI MANSI code, corresponding toDL – Delete Line- Parameters:
optionInt- option- Throws:
IOException- IOException- Since:
- 1.16
-
processScrollDown
ProcessCSI n TANSI code, corresponding toSD – Scroll Down- Parameters:
optionInt- option- Throws:
IOException- IOException
-
processScrollUp
ProcessCSI n UANSI code, corresponding toSU – Scroll Up- Parameters:
optionInt- option- Throws:
IOException- IOException
-
processEraseScreen
ProcessCSI n JANSI code, corresponding toED – Erase in Display- Parameters:
eraseOption- eraseOption- Throws:
IOException- IOException
-
processEraseLine
ProcessCSI n KANSI code, corresponding toED – Erase in Line- Parameters:
eraseOption- eraseOption- Throws:
IOException- IOException
-
processSetAttribute
processSGRother than0(reset),30-39(foreground),40-49(background),90-97(foreground high intensity) or100-107(background high intensity)- Parameters:
attribute- attribute- Throws:
IOException- IOException- See Also:
-
processSetForegroundColor
processSGR 30-37corresponding toSet text color (foreground).- Parameters:
color- the text color- Throws:
IOException- IOException
-
processSetForegroundColor
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:
IOException- IOException
-
processSetForegroundColorExt
processSGR 38corresponding toextended set text color (foreground)with a palette of 255 colors.- Parameters:
paletteIndex- the text color in the palette- Throws:
IOException- IOException
-
processSetForegroundColorExt
processSGR 38corresponding toextended set text color (foreground)with a 24 bits RGB definition of the color.- Parameters:
r- redg- greenb- blue- Throws:
IOException- IOException
-
processSetBackgroundColor
processSGR 40-47corresponding toSet background color.- Parameters:
color- the background color- Throws:
IOException- IOException
-
processSetBackgroundColor
processSGR 40-47orSGR 100-107corresponding toSet background coloreither in normal mode or high intensity.- Parameters:
color- the background colorbright- is high intensity?- Throws:
IOException- IOException
-
processSetBackgroundColorExt
processSGR 48corresponding toextended set background colorwith a palette of 255 colors.- Parameters:
paletteIndex- the background color in the palette- Throws:
IOException- IOException
-
processSetBackgroundColorExt
processSGR 48corresponding toextended set background colorwith a 24 bits RGB definition of the color.- Parameters:
r- redg- greenb- blue- Throws:
IOException- IOException
-
processDefaultTextColor
processSGR 39corresponding toDefault text color (foreground)- Throws:
IOException- IOException
-
processDefaultBackgroundColor
processSGR 49corresponding toDefault background color- Throws:
IOException- IOException
-
processAttributeRest
processSGR 0corresponding toReset / Normal- Throws:
IOException- IOException
-
processCursorTo
processCSI n ; m Hcorresponding toCUP – Cursor PositionorCSI n ; m fcorresponding toHVP – Horizontal and Vertical Position- Parameters:
row- rowcol- column- Throws:
IOException- IOException
-
processCursorToColumn
processCSI n Gcorresponding toCHA – Cursor Horizontal Absolute- Parameters:
x- the column- Throws:
IOException- IOException
-
processCursorUpLine
processCSI n Fcorresponding toCPL – Cursor Previous Line- Parameters:
count- line count- Throws:
IOException- IOException
-
processCursorDownLine
processCSI n Ecorresponding toCNL – Cursor Next Line- Parameters:
count- line count- Throws:
IOException- IOException
-
processCursorLeft
processCSI n Dcorresponding toCUB – Cursor Back- Parameters:
count- numer of characters to move left- Throws:
IOException- IOException
-
processCursorRight
processCSI n Ccorresponding toCUF – Cursor Forward- Parameters:
count- number of characters to move on- Throws:
IOException- IOException
-
processCursorDown
processCSI n Bcorresponding toCUD – Cursor Down- Parameters:
count- numer of line- Throws:
IOException- IOException
-
processCursorUp
processCSI n Acorresponding toCUU – Cursor Up- Parameters:
count- number of lines- Throws:
IOException- IOException
-
processUnknownExtension
-
processChangeIconNameAndWindowTitle
processOSC 0;text BELcorresponding toChange Window and Icon label- Parameters:
label- window label
-
processChangeIconName
processOSC 1;text BELcorresponding toChange Icon label- Parameters:
label- icon label name
-
processChangeWindowTitle
processOSC 2;text BELcorresponding toChange Window title- Parameters:
label- window label
-
processUnknownOperatingSystemCommand
Process unknownOSCcommand.- Parameters:
command- commandparam- command param
-
processCharsetSelect
-
processCharsetSelect
protected void processCharsetSelect(int set, char seq) -
optionInt
-
optionInt
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterOutputStream- Throws:
IOException
-