Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class Ansi
- Object
- 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, eraseLine, …) always emit
their sequence; they are for code that has already checked
Console.isTerminal.
Nested types
class Ansi.Color | A foreground or background color: one of the 16 basic colors, an index into the 256-color palette, or a 24-bit RGB value. |
Methods
Inherited methods
Method details
ansi
public static Ansi ansi()A builder for the terminal’s
Console.colorLevel.ansi
public static Ansi ansi(Console.ColorLevel level)A builder that emits escape codes for
level whatever the terminal is.enabled
public boolean enabled()Whether this builder emits any styling.
a
public Ansi a(Object text)Appends
text.newline
public Ansi newline()Appends a line break.
fg
public Ansi fg(Ansi.Color color)Sets the foreground color.
bg
public Ansi bg(Ansi.Color color)Sets the background color.
bold
public Ansi bold()Turns on bold.
faint
public Ansi faint()Turns on faint text.
italic
public Ansi italic()Turns on italics.
underline
public Ansi underline()Turns on underlining.
inverse
public Ansi inverse()Swaps foreground and background.
strikethrough
public Ansi strikethrough()Turns on strikethrough.
reset
public Ansi reset()Clears every style and color.
fg
public Ansi fg(Ansi.Color color, Object text)Appends
text in color, then restores the default foreground.link
public Ansi link(String url, String text)Appends
text as a hyperlink to url (OSC 8), which terminals that
support it make clickable. Plain text when styling is off.toString
public String toString()The text built so far.
cursorUp
public static String cursorUp(int n)Moves the cursor up
n lines.cursorDown
public static String cursorDown(int n)Moves the cursor down
n lines.cursorForward
public static String cursorForward(int n)Moves the cursor right
n columns.cursorBack
public static String cursorBack(int n)Moves the cursor left
n columns.cursorColumn
public static String cursorColumn(int column)Moves the cursor to
column, counted from 1.cursorTo
public static String cursorTo(int row, int column)Moves the cursor to
row and column, both counted from 1.eraseLine
public static String eraseLine()Erases the whole line the cursor is on.
eraseDown
public static String eraseDown()Erases from the cursor to the end of the screen.
clearScreen
public static String clearScreen()Erases the screen and moves the cursor home.
hideCursor
public static String hideCursor()Hides the cursor.
showCursor
public static String showCursor()Shows the cursor.
enterAlternateScreen
public static String enterAlternateScreen()Switches to the alternate screen, the one full-screen programs draw on
so the shell’s scrollback is intact when they leave.
leaveAlternateScreen
public static String leaveAlternateScreen()Leaves the alternate screen.
title
public static String title(String title)Sets the terminal window’s title.