Package org.fusesource.jansi
Class Ansi
- java.lang.Object
-
- org.fusesource.jansi.Ansi
-
- All Implemented Interfaces:
java.lang.Appendable
- Direct Known Subclasses:
Ansi.NoAnsi
public class Ansi extends java.lang.Object implements java.lang.Appendable
Provides a fluent API for generating ANSI escape sequences.- Since:
- 1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Ansi.Attribute
Display attributes, also know as SGR (Select Graphic Rendition) parameters.static class
Ansi.Color
ANSI 8 colors for fluent APIstatic interface
Ansi.Consumer
static class
Ansi.Erase
ED (Erase in Display) / EL (Erase in Line) parameter (see CSI sequence J and K)private static class
Ansi.NoAnsi
-
Field Summary
Fields Modifier and Type Field Description private java.util.ArrayList<java.lang.Integer>
attributeOptions
private java.lang.StringBuilder
builder
private static java.util.concurrent.Callable<java.lang.Boolean>
detector
static java.lang.String
DISABLE
private static char
FIRST_ESC_CHAR
private static java.lang.InheritableThreadLocal<java.lang.Boolean>
holder
private static char
SECOND_ESC_CHAR
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private Ansi
_appendEscapeSequence(char command, java.lang.Object... options)
Ansi
a(boolean value)
Ansi
a(char value)
Ansi
a(char[] value)
Ansi
a(char[] value, int offset, int len)
Ansi
a(double value)
Ansi
a(float value)
Ansi
a(int value)
Ansi
a(long value)
Ansi
a(java.lang.CharSequence value)
Ansi
a(java.lang.CharSequence value, int start, int end)
Ansi
a(java.lang.Object value)
Ansi
a(java.lang.String value)
Ansi
a(java.lang.StringBuffer value)
Ansi
a(Ansi.Attribute attribute)
static Ansi
ansi()
static Ansi
ansi(int size)
static Ansi
ansi(java.lang.StringBuilder builder)
Ansi
append(char c)
Ansi
append(java.lang.CharSequence csq)
Ansi
append(java.lang.CharSequence csq, int start, int end)
private Ansi
appendEscapeSequence(char command)
private Ansi
appendEscapeSequence(char command, int option)
private Ansi
appendEscapeSequence(char command, java.lang.Object... options)
Ansi
apply(Ansi.Consumer fun)
Applies another function to this Ansi instance.Ansi
bg(int color)
Ansi
bg(Ansi.Color color)
Ansi
bgBright(Ansi.Color color)
Ansi
bgBrightCyan()
Ansi
bgBrightDefault()
Ansi
bgBrightGreen()
Ansi
bgBrightMagenta()
Ansi
bgBrightRed()
Ansi
bgBrightYellow()
Ansi
bgCyan()
Ansi
bgDefault()
Ansi
bgGreen()
Ansi
bgMagenta()
Ansi
bgRed()
Ansi
bgRgb(int color)
Ansi
bgRgb(int r, int g, int b)
Ansi
bgYellow()
Ansi
bold()
Ansi
boldOff()
Ansi
cursor(int row, int column)
Moves the cursor to row n, column m.Ansi
cursorDown(int y)
Moves the cursor down.Ansi
cursorDownLine()
Moves the cursor to the beginning of the line below.Ansi
cursorDownLine(int n)
Moves the cursor to the beginning of the n-th line below.Ansi
cursorLeft(int x)
Moves the cursor left.Ansi
cursorMove(int x, int y)
Moves the cursor relative to the current position.Ansi
cursorRight(int x)
Moves the cursor right.Ansi
cursorToColumn(int x)
Moves the cursor to column n.Ansi
cursorUp(int y)
Moves the cursor up.Ansi
cursorUpLine()
Moves the cursor to the beginning of the line above.Ansi
cursorUpLine(int n)
Moves the cursor to the beginning of the n-th line above.Ansi
eraseLine()
Ansi
eraseLine(Ansi.Erase kind)
Ansi
eraseScreen()
Ansi
eraseScreen(Ansi.Erase kind)
Ansi
fg(int color)
Ansi
fg(Ansi.Color color)
Ansi
fgBlack()
Ansi
fgBlue()
Ansi
fgBright(Ansi.Color color)
Ansi
fgBrightBlack()
Ansi
fgBrightBlue()
Ansi
fgBrightCyan()
Ansi
fgBrightDefault()
Ansi
fgBrightGreen()
Ansi
fgBrightMagenta()
Ansi
fgBrightRed()
Ansi
fgBrightYellow()
Ansi
fgCyan()
Ansi
fgDefault()
Ansi
fgGreen()
Ansi
fgMagenta()
Ansi
fgRed()
Ansi
fgRgb(int color)
Ansi
fgRgb(int r, int g, int b)
Ansi
fgYellow()
private void
flushAttributes()
Ansi
format(java.lang.String pattern, java.lang.Object... args)
static boolean
isDetected()
static boolean
isEnabled()
Ansi
newline()
Ansi
render(java.lang.String text)
Uses theAnsiRenderer
to generate the ANSI escape sequences for the supplied text.Ansi
render(java.lang.String text, java.lang.Object... args)
String formats and renders the supplied arguments.Ansi
reset()
Ansi
restorCursorPosition()
Deprecated.Ansi
restoreCursorPosition()
Ansi
restoreCursorPositionDEC()
Ansi
restoreCursorPositionSCO()
Ansi
saveCursorPosition()
Ansi
saveCursorPositionDEC()
Ansi
saveCursorPositionSCO()
Ansi
scrollDown(int rows)
Ansi
scrollUp(int rows)
static void
setDetector(java.util.concurrent.Callable<java.lang.Boolean> detector)
static void
setEnabled(boolean flag)
java.lang.String
toString()
-
-
-
Field Detail
-
FIRST_ESC_CHAR
private static final char FIRST_ESC_CHAR
- See Also:
- Constant Field Values
-
SECOND_ESC_CHAR
private static final char SECOND_ESC_CHAR
- See Also:
- Constant Field Values
-
DISABLE
public static final java.lang.String DISABLE
-
detector
private static java.util.concurrent.Callable<java.lang.Boolean> detector
-
holder
private static final java.lang.InheritableThreadLocal<java.lang.Boolean> holder
-
builder
private final java.lang.StringBuilder builder
-
attributeOptions
private final java.util.ArrayList<java.lang.Integer> attributeOptions
-
-
Constructor Detail
-
Ansi
public Ansi()
-
Ansi
public Ansi(Ansi parent)
-
Ansi
public Ansi(int size)
-
Ansi
public Ansi(java.lang.StringBuilder builder)
-
-
Method Detail
-
setDetector
public static void setDetector(java.util.concurrent.Callable<java.lang.Boolean> detector)
-
isDetected
public static boolean isDetected()
-
setEnabled
public static void setEnabled(boolean flag)
-
isEnabled
public static boolean isEnabled()
-
ansi
public static Ansi ansi()
-
ansi
public static Ansi ansi(java.lang.StringBuilder builder)
-
ansi
public static Ansi ansi(int size)
-
fg
public Ansi fg(Ansi.Color color)
-
fg
public Ansi fg(int color)
-
fgRgb
public Ansi fgRgb(int color)
-
fgRgb
public Ansi fgRgb(int r, int g, int b)
-
fgBlack
public Ansi fgBlack()
-
fgBlue
public Ansi fgBlue()
-
fgCyan
public Ansi fgCyan()
-
fgDefault
public Ansi fgDefault()
-
fgGreen
public Ansi fgGreen()
-
fgMagenta
public Ansi fgMagenta()
-
fgRed
public Ansi fgRed()
-
fgYellow
public Ansi fgYellow()
-
bg
public Ansi bg(Ansi.Color color)
-
bg
public Ansi bg(int color)
-
bgRgb
public Ansi bgRgb(int color)
-
bgRgb
public Ansi bgRgb(int r, int g, int b)
-
bgCyan
public Ansi bgCyan()
-
bgDefault
public Ansi bgDefault()
-
bgGreen
public Ansi bgGreen()
-
bgMagenta
public Ansi bgMagenta()
-
bgRed
public Ansi bgRed()
-
bgYellow
public Ansi bgYellow()
-
fgBright
public Ansi fgBright(Ansi.Color color)
-
fgBrightBlack
public Ansi fgBrightBlack()
-
fgBrightBlue
public Ansi fgBrightBlue()
-
fgBrightCyan
public Ansi fgBrightCyan()
-
fgBrightDefault
public Ansi fgBrightDefault()
-
fgBrightGreen
public Ansi fgBrightGreen()
-
fgBrightMagenta
public Ansi fgBrightMagenta()
-
fgBrightRed
public Ansi fgBrightRed()
-
fgBrightYellow
public Ansi fgBrightYellow()
-
bgBright
public Ansi bgBright(Ansi.Color color)
-
bgBrightCyan
public Ansi bgBrightCyan()
-
bgBrightDefault
public Ansi bgBrightDefault()
-
bgBrightGreen
public Ansi bgBrightGreen()
-
bgBrightMagenta
public Ansi bgBrightMagenta()
-
bgBrightRed
public Ansi bgBrightRed()
-
bgBrightYellow
public Ansi bgBrightYellow()
-
a
public Ansi a(Ansi.Attribute attribute)
-
cursor
public Ansi cursor(int row, int column)
Moves the cursor to row n, column m. The values are 1-based. Any values less than 1 are mapped to 1.- Parameters:
row
- row (1-based) from topcolumn
- column (1 based) from left- Returns:
- this Ansi instance
-
cursorToColumn
public Ansi cursorToColumn(int x)
Moves the cursor to column n. The parameter n is 1-based. If n is less than 1 it is moved to the first column.- Parameters:
x
- the index (1-based) of the column to move to- Returns:
- this Ansi instance
-
cursorUp
public Ansi cursorUp(int y)
Moves the cursor up. If the parameter y is negative it moves the cursor down.- Parameters:
y
- the number of lines to move up- Returns:
- this Ansi instance
-
cursorDown
public Ansi cursorDown(int y)
Moves the cursor down. If the parameter y is negative it moves the cursor up.- Parameters:
y
- the number of lines to move down- Returns:
- this Ansi instance
-
cursorRight
public Ansi cursorRight(int x)
Moves the cursor right. If the parameter x is negative it moves the cursor left.- Parameters:
x
- the number of characters to move right- Returns:
- this Ansi instance
-
cursorLeft
public Ansi cursorLeft(int x)
Moves the cursor left. If the parameter x is negative it moves the cursor right.- Parameters:
x
- the number of characters to move left- Returns:
- this Ansi instance
-
cursorMove
public Ansi cursorMove(int x, int y)
Moves the cursor relative to the current position. The cursor is moved right if x is positive, left if negative and down if y is positive and up if negative.- Parameters:
x
- the number of characters to move horizontallyy
- the number of lines to move vertically- Returns:
- this Ansi instance
- Since:
- 2.2
-
cursorDownLine
public Ansi cursorDownLine()
Moves the cursor to the beginning of the line below.- Returns:
- this Ansi instance
-
cursorDownLine
public Ansi cursorDownLine(int n)
Moves the cursor to the beginning of the n-th line below. If the parameter n is negative it moves the cursor to the beginning of the n-th line above.- Parameters:
n
- the number of lines to move the cursor- Returns:
- this Ansi instance
-
cursorUpLine
public Ansi cursorUpLine()
Moves the cursor to the beginning of the line above.- Returns:
- this Ansi instance
-
cursorUpLine
public Ansi cursorUpLine(int n)
Moves the cursor to the beginning of the n-th line above. If the parameter n is negative it moves the cursor to the beginning of the n-th line below.- Parameters:
n
- the number of lines to move the cursor- Returns:
- this Ansi instance
-
eraseScreen
public Ansi eraseScreen()
-
eraseScreen
public Ansi eraseScreen(Ansi.Erase kind)
-
eraseLine
public Ansi eraseLine()
-
eraseLine
public Ansi eraseLine(Ansi.Erase kind)
-
scrollUp
public Ansi scrollUp(int rows)
-
scrollDown
public Ansi scrollDown(int rows)
-
restorCursorPosition
@Deprecated public Ansi restorCursorPosition()
Deprecated.
-
saveCursorPosition
public Ansi saveCursorPosition()
-
saveCursorPositionSCO
public Ansi saveCursorPositionSCO()
-
saveCursorPositionDEC
public Ansi saveCursorPositionDEC()
-
restoreCursorPosition
public Ansi restoreCursorPosition()
-
restoreCursorPositionSCO
public Ansi restoreCursorPositionSCO()
-
restoreCursorPositionDEC
public Ansi restoreCursorPositionDEC()
-
reset
public Ansi reset()
-
bold
public Ansi bold()
-
boldOff
public Ansi boldOff()
-
a
public Ansi a(java.lang.String value)
-
a
public Ansi a(boolean value)
-
a
public Ansi a(char value)
-
a
public Ansi a(char[] value, int offset, int len)
-
a
public Ansi a(char[] value)
-
a
public Ansi a(java.lang.CharSequence value, int start, int end)
-
a
public Ansi a(java.lang.CharSequence value)
-
a
public Ansi a(double value)
-
a
public Ansi a(float value)
-
a
public Ansi a(int value)
-
a
public Ansi a(long value)
-
a
public Ansi a(java.lang.Object value)
-
a
public Ansi a(java.lang.StringBuffer value)
-
newline
public Ansi newline()
-
format
public Ansi format(java.lang.String pattern, java.lang.Object... args)
-
apply
public Ansi apply(Ansi.Consumer fun)
Applies another function to this Ansi instance.- Parameters:
fun
- the function to apply- Returns:
- this Ansi instance
- Since:
- 2.2
-
render
public Ansi render(java.lang.String text)
Uses theAnsiRenderer
to generate the ANSI escape sequences for the supplied text.- Parameters:
text
- text- Returns:
- this
- Since:
- 2.2
-
render
public Ansi render(java.lang.String text, java.lang.Object... args)
String formats and renders the supplied arguments. Uses theAnsiRenderer
to generate the ANSI escape sequences.- Parameters:
text
- formatargs
- arguments- Returns:
- this
- Since:
- 2.2
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
appendEscapeSequence
private Ansi appendEscapeSequence(char command)
-
appendEscapeSequence
private Ansi appendEscapeSequence(char command, int option)
-
appendEscapeSequence
private Ansi appendEscapeSequence(char command, java.lang.Object... options)
-
flushAttributes
private void flushAttributes()
-
_appendEscapeSequence
private Ansi _appendEscapeSequence(char command, java.lang.Object... options)
-
append
public Ansi append(java.lang.CharSequence csq)
- Specified by:
append
in interfacejava.lang.Appendable
-
append
public Ansi append(java.lang.CharSequence csq, int start, int end)
- Specified by:
append
in interfacejava.lang.Appendable
-
append
public Ansi append(char c)
- Specified by:
append
in interfacejava.lang.Appendable
-
-