Class Ansi
java.lang.Object
com.codename1.cli.Ansi
Styled terminal text, built fluently:
Console.println(Ansi.ansi().fg(Ansi.Color.GREEN).bold().a("OK").reset()
.a(" deployed to ").link("https://example.com", "example.com").toString());
A builder emits escape codes for the Console.colorLevel() it was made with
and converts colors down to it, so a 24-bit color becomes the nearest of
256 or of 16, and on Console.ColorLevel.NONE the text comes out plain.
The cursor and erase helpers (cursorUp(int), eraseLine(), ...) always emit
their sequence; they are for code that has already checked
Console.isTerminal().
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA foreground or background color: one of the 16 basic colors, an index into the 256-color palette, or a 24-bit RGB value. -
Method Summary
Modifier and TypeMethodDescriptionAppendstext.static Ansiansi()A builder for the terminal'sConsole.colorLevel().static Ansiansi(Console.ColorLevel level) A builder that emits escape codes forlevelwhatever the terminal is.bg(Ansi.Color color) Sets the background color.bold()Turns on bold.static StringErases the screen and moves the cursor home.static StringcursorBack(int n) Moves the cursor leftncolumns.static StringcursorColumn(int column) Moves the cursor tocolumn, counted from 1.static StringcursorDown(int n) Moves the cursor downnlines.static StringcursorForward(int n) Moves the cursor rightncolumns.static StringcursorTo(int row, int column) Moves the cursor torowandcolumn, both counted from 1.static StringcursorUp(int n) Moves the cursor upnlines.booleanenabled()Whether this builder emits any styling.static StringSwitches to the alternate screen, the one full-screen programs draw on so the shell's scrollback is intact when they leave.static StringErases from the cursor to the end of the screen.static StringErases the whole line the cursor is on.faint()Turns on faint text.fg(Ansi.Color color) Sets the foreground color.fg(Ansi.Color color, Object text) Appendstextincolor, then restores the default foreground.static StringHides the cursor.inverse()Swaps foreground and background.italic()Turns on italics.static StringLeaves the alternate screen.Appendstextas a hyperlink tourl(OSC 8), which terminals that support it make clickable.newline()Appends a line break.reset()Clears every style and color.static StringShows the cursor.Turns on strikethrough.static StringSets the terminal window's title.toString()The text built so far.Turns on underlining.
-
Method Details
-
ansi
A builder for the terminal'sConsole.colorLevel(). -
ansi
A builder that emits escape codes forlevelwhatever the terminal is. -
enabled
public boolean enabled()Whether this builder emits any styling. -
a
-
newline
Appends a line break. -
fg
Sets the foreground color. -
bg
Sets the background color. -
bold
Turns on bold. -
faint
Turns on faint text. -
italic
Turns on italics. -
underline
Turns on underlining. -
inverse
Swaps foreground and background. -
strikethrough
Turns on strikethrough. -
reset
Clears every style and color. -
fg
Appendstextincolor, then restores the default foreground. -
link
-
toString
-
cursorUp
Moves the cursor upnlines. -
cursorDown
Moves the cursor downnlines. -
cursorForward
Moves the cursor rightncolumns. -
cursorBack
Moves the cursor leftncolumns. -
cursorColumn
Moves the cursor tocolumn, counted from 1. -
cursorTo
Moves the cursor torowandcolumn, both counted from 1. -
eraseLine
Erases the whole line the cursor is on. -
eraseDown
Erases from the cursor to the end of the screen. -
clearScreen
Erases the screen and moves the cursor home. -
hideCursor
Hides the cursor. -
showCursor
Shows the cursor. -
enterAlternateScreen
Switches to the alternate screen, the one full-screen programs draw on so the shell's scrollback is intact when they leave. -
leaveAlternateScreen
Leaves the alternate screen. -
title
-