APIdia Launch Partner
Top Description Fields Constructors Methods
jdk.internal.org.jline.utils

public Class AnsiWriter

extends FilterWriter
Class Inheritance
Known Direct Subclasses
jdk.internal.org.jline.terminal.impl.ffm.WindowsAnsiWriter
Imports
java.io.FilterWriter, .IOException, .Writer, java.util.ArrayList, .Iterator

A ANSI writer extracts ANSI escape codes written to a Writer and calls corresponding process* methods. For more information about ANSI escape codes, see: http://en.wikipedia.org/wiki/ANSI_escape_code This class just filters out the escape codes so that they are not sent out to the underlying Writer: process* methods are empty. Subclasses should actually perform the ANSI escape behaviors by implementing active code in process* methods.
Authors
Hiram Chirino, Joris Kuipers
Since
1.0

Field Summary

Modifier and TypeField and Description
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
private static final int
protected static final int
protected static final int
private final char[]
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
private static final int
protected static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
protected static final int
private static final int
private final ArrayList<Object>
private int
protected static final int
private static final char[]
private static final int
private static final int
private static final int
private static final int
private static final int
private int
pack-priv int
protected static final int
protected static final int
Inherited from java.io.FilterWriter:
out

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.FilterWriter.close.

Implements java.io.Closeable.close.

Closes the stream, flushing it first.

private int
getNextOptionInt(Iterator<Object>
the underlying iterator
optionsIterator
)

Helper for processEscapeCommand() to iterate over integer options

private int
optionInt(ArrayList<Object> options, int index)

private int
optionInt(ArrayList<Object> options, int index, int defaultValue)

protected void
processAttributeRest()

process SGR 0 corresponding to Reset / Normal

protected void
processChangeIconName(String
the icon name
name
)

process OSC 1;text BEL corresponding to Change Icon label

protected void
processChangeIconNameAndWindowTitle(String
the label
label
)

process OSC 0;text BEL corresponding to Change Window and Icon label

protected void
processChangeWindowTitle(String
the title
title
)

process OSC 2;text BEL corresponding to Change Window title

private boolean

Returns:

true if the charcter set select command was processed.
processCharsetSelect
(ArrayList<Object> options)

Process character set sequence.

protected void
processCharsetSelect(int set, char seq)

protected void
processCursorDown(int
the count
count
)

process CSI n B corresponding to CUD – Cursor Down

protected void
processCursorDownLine(int
line count
count
)

process CSI n E corresponding to CNL – Cursor Next Line

protected void
processCursorLeft(int
the count
count
)

process CSI n D corresponding to CUB – Cursor Back

protected void
processCursorRight(int
the count
count
)

process CSI n C corresponding to CUF – Cursor Forward

protected void
processCursorTo(int
the row
row
,
int
the column
col
)

process CSI n ; m H corresponding to CUP – Cursor Position or CSI n ; m f corresponding to HVP – Horizontal and Vertical Position

protected void
processCursorToColumn(int
the column
x
)

process CSI n G corresponding to CHA – Cursor Horizontal Absolute

protected void
processCursorUp(int
the count
count
)

process CSI n A corresponding to CUU – Cursor Up

protected void
processCursorUpLine(int
line count
count
)

process CSI n F corresponding to CPL – Cursor Previous Line

protected void
processDefaultBackgroundColor()

process SGR 49 corresponding to Default background color

protected void
processDefaultTextColor()

process SGR 39 corresponding to Default text color (foreground)

protected void
processDeleteLine(int
the option
optionInt
)

Process CSI s ANSI code, corresponding to DL – Delete Line

protected void
processEraseLine(int
the erase option
eraseOption
)

Process CSI n K ANSI code, corresponding to ED – Erase in Line

protected void
processEraseScreen(int
the erase option
eraseOption
)

Process CSI n J ANSI code, corresponding to ED – Erase in Display

private boolean

Returns:

true if the escape command was processed.
processEscapeCommand
(ArrayList<Object>
the list of options
options
,
int
the command
command
)

Process escape command

protected void
processInsertLine(int
the option
optionInt
)

Process CSI s ANSI code, corresponding to IL – Insert Line

private boolean

Returns:

true if the operating system command was processed.
processOperatingSystemCommand
(ArrayList<Object>
the options list
options
)

Process operating system command.

protected void
processRestoreCursorPosition()

Process CSI u ANSI code, corresponding to RCP – Restore Cursor Position

protected void
processSaveCursorPosition()

Process CSI s ANSI code, corresponding to SCP – Save Cursor Position

protected void
processScrollDown(int
the option
optionInt
)

Process CSI n T ANSI code, corresponding to SD – Scroll Down

protected void
processScrollUp(int
the option
optionInt
)

Process CSI n U ANSI code, corresponding to SU – Scroll Up

protected void
processSetAttribute(int
the attribute to set
attribute
)

process SGR other than 0 (reset), 30-39 (foreground), 40-49 (background), 90-97 (foreground high intensity) or 100-107 (background high intensity)

protected void
processSetBackgroundColor(int
the background color
color
)

process SGR 40-47 corresponding to Set background color.

protected void
processSetBackgroundColor(int
the background color
color
,
boolean
is high intensity?
bright
)

process SGR 40-47 or SGR 100-107 corresponding to Set background color either in normal mode or high intensity.

protected void
processSetBackgroundColorExt(int
the background color in the palette
paletteIndex
)

process SGR 48 corresponding to extended set background color with a palette of 255 colors.

protected void
processSetBackgroundColorExt(int
red
r
,
int
green
g
,
int
blue
b
)

process SGR 48 corresponding to extended set background color with a 24 bits RGB definition of the color.

protected void
processSetForegroundColor(int
the text color
color
)

process SGR 30-37 corresponding to Set text color (foreground).

protected void
processSetForegroundColor(int
the text color
color
,
boolean
is high intensity?
bright
)

process SGR 30-37 or SGR 90-97 corresponding to Set text color (foreground) either in normal mode or high intensity.

protected void
processSetForegroundColorExt(int
the text color in the palette
paletteIndex
)

process SGR 38 corresponding to extended set text color (foreground) with a palette of 255 colors.

protected void
processSetForegroundColorExt(int
red
r
,
int
green
g
,
int
blue
b
)

process SGR 38 corresponding to extended set text color (foreground) with a 24 bits RGB definition of the color.

protected void
processUnknownExtension(ArrayList<Object> options, int command)

protected void
processUnknownOperatingSystemCommand(int
the command
command
,
String
the param
param
)

Process unknown OSC command.

private void
reset(boolean
if current buffer should be skipped or written to out
skipBuffer
)

Resets all state to continue with regular parsing

public synchronized void
write(int data)

Overrides java.io.FilterWriter.write.

Writes a single character.

public void
write(char[] cbuf, int off, int len)

Overrides java.io.FilterWriter.write.

Writes a portion of an array of characters.

public void
write(String str, int off, int len)

Overrides java.io.FilterWriter.write.

Writes a portion of a string.

Inherited from java.io.FilterWriter:
flush

Field Detail

ATTRIBUTE_CONCEAL_OFFback to summary
protected static final int ATTRIBUTE_CONCEAL_OFF
ATTRIBUTE_CONCEAL_ONback to summary
protected static final int ATTRIBUTE_CONCEAL_ON
ATTRIBUTE_INTENSITY_BOLDback to summary
protected static final int ATTRIBUTE_INTENSITY_BOLD
ATTRIBUTE_INTENSITY_FAINTback to summary
protected static final int ATTRIBUTE_INTENSITY_FAINT
ATTRIBUTE_INTENSITY_NORMALback to summary
protected static final int ATTRIBUTE_INTENSITY_NORMAL
ATTRIBUTE_ITALICback to summary
protected static final int ATTRIBUTE_ITALIC
ATTRIBUTE_NEGATIVE_Offback to summary
protected static final int ATTRIBUTE_NEGATIVE_Off

Deprecated

Annotations
@Deprecated
ATTRIBUTE_NEGATIVE_OFFback to summary
protected static final int ATTRIBUTE_NEGATIVE_OFF
ATTRIBUTE_NEGATIVE_ONback to summary
protected static final int ATTRIBUTE_NEGATIVE_ON
ATTRIBUTE_UNDERLINEback to summary
protected static final int ATTRIBUTE_UNDERLINE
ATTRIBUTE_UNDERLINE_DOUBLEback to summary
protected static final int ATTRIBUTE_UNDERLINE_DOUBLE
ATTRIBUTE_UNDERLINE_OFFback to summary
protected static final int ATTRIBUTE_UNDERLINE_OFF
BELback to summary
private static final int BEL
BLACKback to summary
protected static final int BLACK
BLUEback to summary
protected static final int BLUE
bufferback to summary
private final char[] buffer
CYANback to summary
protected static final int CYAN
ERASE_LINEback to summary
protected static final int ERASE_LINE
ERASE_LINE_TO_BEGININGback to summary
protected static final int ERASE_LINE_TO_BEGINING
ERASE_LINE_TO_ENDback to summary
protected static final int ERASE_LINE_TO_END
ERASE_SCREENback to summary
protected static final int ERASE_SCREEN
ERASE_SCREEN_TO_BEGININGback to summary
protected static final int ERASE_SCREEN_TO_BEGINING
ERASE_SCREEN_TO_ENDback to summary
protected static final int ERASE_SCREEN_TO_END
FIRST_ESC_CHARback to summary
private static final int FIRST_ESC_CHAR
GREENback to summary
protected static final int GREEN
LOOKING_FOR_CHARSETback to summary
private static final int LOOKING_FOR_CHARSET
LOOKING_FOR_FIRST_ESC_CHARback to summary
private static final int LOOKING_FOR_FIRST_ESC_CHAR
LOOKING_FOR_INT_ARG_ENDback to summary
private static final int LOOKING_FOR_INT_ARG_END
LOOKING_FOR_NEXT_ARGback to summary
private static final int LOOKING_FOR_NEXT_ARG
LOOKING_FOR_OSC_COMMANDback to summary
private static final int LOOKING_FOR_OSC_COMMAND
LOOKING_FOR_OSC_COMMAND_ENDback to summary
private static final int LOOKING_FOR_OSC_COMMAND_END
LOOKING_FOR_OSC_PARAMback to summary
private static final int LOOKING_FOR_OSC_PARAM
LOOKING_FOR_SECOND_ESC_CHARback to summary
private static final int LOOKING_FOR_SECOND_ESC_CHAR
LOOKING_FOR_STback to summary
private static final int LOOKING_FOR_ST
LOOKING_FOR_STR_ARG_ENDback to summary
private static final int LOOKING_FOR_STR_ARG_END
MAGENTAback to summary
protected static final int MAGENTA
MAX_ESCAPE_SEQUENCE_LENGTHback to summary
private static final int MAX_ESCAPE_SEQUENCE_LENGTH
optionsback to summary
private final ArrayList<Object> options
posback to summary
private int pos
REDback to summary
protected static final int RED
RESET_CODEback to summary
private static final char[] RESET_CODE
SECOND_CHARSET0_CHARback to summary
private static final int SECOND_CHARSET0_CHAR
SECOND_CHARSET1_CHARback to summary
private static final int SECOND_CHARSET1_CHAR
SECOND_ESC_CHARback to summary
private static final int SECOND_ESC_CHAR
SECOND_OSC_CHARback to summary
private static final int SECOND_OSC_CHAR
SECOND_ST_CHARback to summary
private static final int SECOND_ST_CHAR
startOfValueback to summary
private int startOfValue
stateback to summary
pack-priv int state
WHITEback to summary
protected static final int WHITE
YELLOWback to summary
protected static final int YELLOW

Constructor Detail

AnsiWriterback to summary
public AnsiWriter(Writer out)

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.FilterWriter.close.

Implements java.io.Closeable.close.

Doc from java.io.Writer.close.

Closes the stream, flushing it first. Once the stream has been closed, further write() or flush() invocations will cause an IOException to be thrown. Closing a previously closed stream has no effect.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
getNextOptionIntback to summary
private int getNextOptionInt(Iterator<Object> optionsIterator) throws IOException

Helper for processEscapeCommand() to iterate over integer options

Parameters
optionsIterator:Iterator<Object>

the underlying iterator

Exceptions
IOException:
if no more non-null values left
optionIntback to summary
private int optionInt(ArrayList<Object> options, int index)
optionIntback to summary
private int optionInt(ArrayList<Object> options, int index, int defaultValue)
processAttributeRestback to summary
protected void processAttributeRest() throws IOException

process SGR 0 corresponding to Reset / Normal

Exceptions
IOException:
if an error occurs
processChangeIconNameback to summary
protected void processChangeIconName(String name)

process OSC 1;text BEL corresponding to Change Icon label

Parameters
name:String

the icon name

processChangeIconNameAndWindowTitleback to summary
protected void processChangeIconNameAndWindowTitle(String label)

process OSC 0;text BEL corresponding to Change Window and Icon label

Parameters
label:String

the label

processChangeWindowTitleback to summary
protected void processChangeWindowTitle(String title)

process OSC 2;text BEL corresponding to Change Window title

Parameters
title:String

the title

processCharsetSelectback to summary
private boolean processCharsetSelect(ArrayList<Object> options) throws IOException

Process character set sequence.

Returns:boolean

true if the charcter set select command was processed.

processCharsetSelectback to summary
protected void processCharsetSelect(int set, char seq)
processCursorDownback to summary
protected void processCursorDown(int count) throws IOException

process CSI n B corresponding to CUD – Cursor Down

Parameters
count:int

the count

Exceptions
IOException:
if an error occurs
processCursorDownLineback to summary
protected void processCursorDownLine(int count) throws IOException

process CSI n E corresponding to CNL – Cursor Next Line

Parameters
count:int

line count

Exceptions
IOException:
if an error occurs
processCursorLeftback to summary
protected void processCursorLeft(int count) throws IOException

process CSI n D corresponding to CUB – Cursor Back

Parameters
count:int

the count

Exceptions
IOException:
if an error occurs
processCursorRightback to summary
protected void processCursorRight(int count) throws IOException

process CSI n C corresponding to CUF – Cursor Forward

Parameters
count:int

the count

Exceptions
IOException:
if an error occurs
processCursorToback to summary
protected void processCursorTo(int row, int col) throws IOException

process CSI n ; m H corresponding to CUP – Cursor Position or CSI n ; m f corresponding to HVP – Horizontal and Vertical Position

Parameters
row:int

the row

col:int

the column

Exceptions
IOException:
if an error occurs
processCursorToColumnback to summary
protected void processCursorToColumn(int x) throws IOException

process CSI n G corresponding to CHA – Cursor Horizontal Absolute

Parameters
x:int

the column

Exceptions
IOException:
if an error occurs
processCursorUpback to summary
protected void processCursorUp(int count) throws IOException

process CSI n A corresponding to CUU – Cursor Up

Parameters
count:int

the count

Exceptions
IOException:
if an error occurs
processCursorUpLineback to summary
protected void processCursorUpLine(int count) throws IOException

process CSI n F corresponding to CPL – Cursor Previous Line

Parameters
count:int

line count

Exceptions
IOException:
if an error occurs
processDefaultBackgroundColorback to summary
protected void processDefaultBackgroundColor() throws IOException

process SGR 49 corresponding to Default background color

Exceptions
IOException:
if an error occurs
processDefaultTextColorback to summary
protected void processDefaultTextColor() throws IOException

process SGR 39 corresponding to Default text color (foreground)

Exceptions
IOException:
if an error occurs
processDeleteLineback to summary
protected void processDeleteLine(int optionInt) throws IOException

Process CSI s ANSI code, corresponding to DL – Delete Line

Parameters
optionInt:int

the option

Exceptions
IOException:
if an error occurs
processEraseLineback to summary
protected void processEraseLine(int eraseOption) throws IOException

Process CSI n K ANSI code, corresponding to ED – Erase in Line

Parameters
eraseOption:int

the erase option

Exceptions
IOException:
if an error occurs
processEraseScreenback to summary
protected void processEraseScreen(int eraseOption) throws IOException

Process CSI n J ANSI code, corresponding to ED – Erase in Display

Parameters
eraseOption:int

the erase option

Exceptions
IOException:
if an error occurs
processEscapeCommandback to summary
private boolean processEscapeCommand(ArrayList<Object> options, int command) throws IOException

Process escape command

Parameters
options:ArrayList<Object>

the list of options

command:int

the command

Returns:boolean

true if the escape command was processed.

Exceptions
IOException:
if an error occurs
processInsertLineback to summary
protected void processInsertLine(int optionInt) throws IOException

Process CSI s ANSI code, corresponding to IL – Insert Line

Parameters
optionInt:int

the option

Exceptions
IOException:
if an error occurs
processOperatingSystemCommandback to summary
private boolean processOperatingSystemCommand(ArrayList<Object> options) throws IOException

Process operating system command.

Parameters
options:ArrayList<Object>

the options list

Returns:boolean

true if the operating system command was processed.

processRestoreCursorPositionback to summary
protected void processRestoreCursorPosition() throws IOException

Process CSI u ANSI code, corresponding to RCP – Restore Cursor Position

Exceptions
IOException:
if an error occurs
processSaveCursorPositionback to summary
protected void processSaveCursorPosition() throws IOException

Process CSI s ANSI code, corresponding to SCP – Save Cursor Position

Exceptions
IOException:
if an error occurs
processScrollDownback to summary
protected void processScrollDown(int optionInt) throws IOException

Process CSI n T ANSI code, corresponding to SD – Scroll Down

Parameters
optionInt:int

the option

Exceptions
IOException:
if an error occurs
processScrollUpback to summary
protected void processScrollUp(int optionInt) throws IOException

Process CSI n U ANSI code, corresponding to SU – Scroll Up

Parameters
optionInt:int

the option

Exceptions
IOException:
if an error occurs
processSetAttributeback to summary
protected void processSetAttribute(int attribute) throws IOException

process SGR other than 0 (reset), 30-39 (foreground), 40-49 (background), 90-97 (foreground high intensity) or 100-107 (background high intensity)

Parameters
attribute:int

the attribute to set

Exceptions
IOException:
if an error occurs
See Also
processAttributeRest(), processSetForegroundColor(int), processSetForegroundColor(int, boolean), processSetForegroundColorExt(int), processSetForegroundColorExt(int, int, int), processDefaultTextColor(), processDefaultBackgroundColor()
processSetBackgroundColorback to summary
protected void processSetBackgroundColor(int color) throws IOException

process SGR 40-47 corresponding to Set background color.

Parameters
color:int

the background color

Exceptions
IOException:
if an error occurs
processSetBackgroundColorback to summary
protected void processSetBackgroundColor(int color, boolean bright) throws IOException

process SGR 40-47 or SGR 100-107 corresponding to Set background color either in normal mode or high intensity.

Parameters
color:int

the background color

bright:boolean

is high intensity?

Exceptions
IOException:
if an error occurs
processSetBackgroundColorExtback to summary
protected void processSetBackgroundColorExt(int paletteIndex) throws IOException

process SGR 48 corresponding to extended set background color with a palette of 255 colors.

Parameters
paletteIndex:int

the background color in the palette

Exceptions
IOException:
if an error occurs
processSetBackgroundColorExtback to summary
protected void processSetBackgroundColorExt(int r, int g, int b) throws IOException

process SGR 48 corresponding to extended set background color with a 24 bits RGB definition of the color.

Parameters
r:int

red

g:int

green

b:int

blue

Exceptions
IOException:
if an error occurs
processSetForegroundColorback to summary
protected void processSetForegroundColor(int color) throws IOException

process SGR 30-37 corresponding to Set text color (foreground).

Parameters
color:int

the text color

Exceptions
IOException:
if an error occurs
processSetForegroundColorback to summary
protected void processSetForegroundColor(int color, boolean bright) throws IOException

process SGR 30-37 or SGR 90-97 corresponding to Set text color (foreground) either in normal mode or high intensity.

Parameters
color:int

the text color

bright:boolean

is high intensity?

Exceptions
IOException:
if an error occurs
processSetForegroundColorExtback to summary
protected void processSetForegroundColorExt(int paletteIndex) throws IOException

process SGR 38 corresponding to extended set text color (foreground) with a palette of 255 colors.

Parameters
paletteIndex:int

the text color in the palette

Exceptions
IOException:
if an error occurs
processSetForegroundColorExtback to summary
protected void processSetForegroundColorExt(int r, int g, int b) throws IOException

process SGR 38 corresponding to extended set text color (foreground) with a 24 bits RGB definition of the color.

Parameters
r:int

red

g:int

green

b:int

blue

Exceptions
IOException:
if an error occurs
processUnknownExtensionback to summary
protected void processUnknownExtension(ArrayList<Object> options, int command)
processUnknownOperatingSystemCommandback to summary
protected void processUnknownOperatingSystemCommand(int command, String param)

Process unknown OSC command.

Parameters
command:int

the command

param:String

the param

resetback to summary
private void reset(boolean skipBuffer) throws IOException

Resets all state to continue with regular parsing

Parameters
skipBuffer:boolean

if current buffer should be skipped or written to out

Exceptions
IOException:
if an error occurs
writeback to summary
public synchronized void write(int data) throws IOException

Overrides java.io.FilterWriter.write.

Doc from java.io.FilterWriter.write.

Writes a single character.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
writeback to summary
public void write(char[] cbuf, int off, int len) throws IOException

Overrides java.io.FilterWriter.write.

Doc from java.io.FilterWriter.write.

Writes a portion of an array of characters.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
writeback to summary
public void write(String str, int off, int len) throws IOException

Overrides java.io.FilterWriter.write.

Doc from java.io.FilterWriter.write.

Writes a portion of a string.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs