Package ansi

Class ANSI

java.lang.Object
ansi.ANSI

public class ANSI
extends java.lang.Object
Make quick ANSI formats to beautify terminal output
Since:
January 2022
Version:
1.0
Author:
Bruno Castro
See Also:
https://github.com/bruneo32/ANSI-Project, https://en.wikipedia.org/wiki/ANSI_escape_code
  • Field Summary

    Fields
    Modifier and Type Field Description
    static java.lang.String AUX_PORT_OFF
    Enable aux serial port usually for local serial printer
    static java.lang.String AUX_PORT_ON
    Enable aux serial port usually for local serial printer
    static java.lang.String BK_BLACK  
    static java.lang.String BK_BLACK_HI  
    static java.lang.String BK_BLUE  
    static java.lang.String BK_BLUE_HI  
    static java.lang.String BK_CYAN  
    static java.lang.String BK_CYAN_HI  
    static java.lang.String BK_DEFAULT  
    static java.lang.String BK_GREEN  
    static java.lang.String BK_GREEN_HI  
    static java.lang.String BK_PURPLE  
    static java.lang.String BK_PURPLE_HI  
    static java.lang.String BK_RED  
    static java.lang.String BK_RED_HI  
    static java.lang.String BK_WHITE  
    static java.lang.String BK_WHITE_HI  
    static java.lang.String BK_YELLOW  
    static java.lang.String BK_YELLOW_HI  
    static java.lang.String BLACK  
    static java.lang.String BLACK_HI  
    static java.lang.String BLINK_OFF  
    static java.lang.String BLUE  
    static java.lang.String BLUE_HI  
    static java.lang.String BOLD  
    static java.lang.String BOLD_OFF  
    static java.lang.String C0
    Place the cursor in top-left corner Same as CUP(1,1)
    static java.lang.String CNL1
    Moves cursor to beginning of the next line
    static java.lang.String CPL1
    Moves cursor to beginning of the previous line
    static java.lang.String CSI  
    static java.lang.String CUB1
    Move the cursor 1 cell backwards
    static java.lang.String CUD1
    Move the cursor 1 row down
    static java.lang.String CUF1
    Move the cursor 1 cell forwards
    static java.lang.String CUU1
    Move the cursor 1 row up
    static java.lang.String CYAN  
    static java.lang.String CYAN_HI  
    static java.lang.String DEF_FONT
    Default font
    static java.lang.String DEFAULT  
    static java.lang.String DSC  
    static java.lang.String DSR
    Reports the cursor position (CPR) by transmitting ESC[n;mR, where n is the row and m is the column.
    static java.lang.String ED0
    Clear from cursor to end of screen.
    static java.lang.String ED1
    Clear from cursor to beginning of the screen
    static java.lang.String ED2
    Clear entire screen (and moves cursor to upper left on DOS ANSI.SYS)
    static java.lang.String ED3
    Clear entire screen and delete all lines saved in the scrollback buffer (this feature was added for xterm and is supported by other terminal applications)
    static java.lang.String EL0
    Clear from cursor to the end of the line
    static java.lang.String EL1
    Clear from cursor to beginning of the line
    static java.lang.String EL2
    Clear entire line.
    static java.lang.String ESC  
    static java.lang.String FAINT  
    static java.lang.String Franktur
    Rarely supported font
    static java.lang.String GREEN  
    static java.lang.String GREEN_HI  
    static java.lang.String HI_OFF  
    static java.lang.String HIDE  
    static java.lang.String ITALIC  
    static java.lang.String ITALIC_OFF  
    static java.lang.String OSC  
    static java.lang.String PURPLE  
    static java.lang.String PURPLE_HI  
    static java.lang.String RBLINK  
    static java.lang.String RCP
    Restores the cursor position/state in SCO console mode.
    static java.lang.String RED  
    static java.lang.String RED_HI  
    static java.lang.String RESET  
    static java.lang.String REVEAL  
    static java.lang.String REVERSE  
    static java.lang.String REVERSE_OFF  
    static java.lang.String SBLINK  
    static java.lang.String SCP
    Saves the cursor position/state in SCO console mode In vertical split screen mode, instead used to set (as CSI n ; n s) or reset left and right margins.
    static java.lang.String SD1
    Scroll whole page down by 1 line
    static java.lang.String STRIKE  
    static java.lang.String STRIKE_OFF  
    static java.lang.String SU1
    Scroll whole page up by 1 line
    static java.lang.String UNDER  
    static java.lang.String UNDER_OFF  
    static java.lang.String WHITE  
    static java.lang.String WHITE_HI  
    static java.lang.String YELLOW  
    static java.lang.String YELLOW_HI  
  • Constructor Summary

    Constructors
    Constructor Description
    ANSI()  
  • Method Summary

    Modifier and Type Method Description
    static java.lang.String BK_RGB​(int r, int g, int b)
    Specify the Background color in RGB
    static java.lang.String CHA​(int n)
    Moves the cursor to column n (default 1)
    static java.lang.String CNL​(int n)
    Moves cursor to beginning of the line n (default 1) lines down.
    static java.lang.String CPL​(int n)
    Moves cursor to beginning of the line n (default 1) lines up.
    static java.lang.String CUB​(int n)
    Moves the cursor n (default 1) cells backwards
    static java.lang.String CUD​(int n)
    Moves the cursor n (default 1) cells down
    static java.lang.String CUF​(int n)
    Moves the cursor n (default 1) cells forwards
    static java.lang.String CUP​(int row, int col)
    Moves the cursor to [row, column].
    static java.lang.String custom​(java.lang.String str)
    Returns a custom ANSI ESCAPE SEQUENCE
    static java.lang.String CUU​(int n)
    Moves the cursor n (default 1) cells up
    static java.lang.String ED​(int n)
    Clears part of the screen.
    static java.lang.String EL​(int n)
    Erases part of the line If n is 0 (or missing), clear from cursor to the end of the line If n is 1, clear from cursor to beginning of the line If n is 2, clear entire line.
    static java.lang.String HVP​(int row, int col)
    Same as CUP, but counts as a format effector function (like CR or LF) rather than an editor function (like CUD or CNL) This can lead to different handling in certain terminal modes
    static java.lang.String RGB​(int r, int g, int b)
    Specify the Foreground color in RGB
    static java.lang.String SD​(int n)
    Scroll whole page down by n (default 1) lines.
    static java.lang.String SGR​(java.lang.String str)
    Sets colors and style of the characters following this code Example: ANSI.SGR("40;91") makes RED_HI over BK_BLACK
    static java.lang.String SU​(int n)
    Scroll whole page up by n (default 1) lines.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ESC

      public static java.lang.String ESC
    • CSI

      public static java.lang.String CSI
    • DSC

      public static java.lang.String DSC
    • OSC

      public static java.lang.String OSC
    • RESET

      public static java.lang.String RESET
    • BOLD

      public static java.lang.String BOLD
    • FAINT

      public static java.lang.String FAINT
    • ITALIC

      public static java.lang.String ITALIC
    • UNDER

      public static java.lang.String UNDER
    • REVERSE

      public static java.lang.String REVERSE
    • HIDE

      public static java.lang.String HIDE
    • STRIKE

      public static java.lang.String STRIKE
    • DEF_FONT

      public static java.lang.String DEF_FONT
      Default font
    • Franktur

      public static java.lang.String Franktur
      Rarely supported font
    • BOLD_OFF

      public static java.lang.String BOLD_OFF
    • HI_OFF

      public static java.lang.String HI_OFF
    • ITALIC_OFF

      public static java.lang.String ITALIC_OFF
    • UNDER_OFF

      public static java.lang.String UNDER_OFF
    • REVERSE_OFF

      public static java.lang.String REVERSE_OFF
    • REVEAL

      public static java.lang.String REVEAL
    • STRIKE_OFF

      public static java.lang.String STRIKE_OFF
    • BLACK

      public static java.lang.String BLACK
    • RED

      public static java.lang.String RED
    • GREEN

      public static java.lang.String GREEN
    • YELLOW

      public static java.lang.String YELLOW
    • BLUE

      public static java.lang.String BLUE
    • PURPLE

      public static java.lang.String PURPLE
    • CYAN

      public static java.lang.String CYAN
    • WHITE

      public static java.lang.String WHITE
    • DEFAULT

      public static java.lang.String DEFAULT
    • BK_BLACK

      public static java.lang.String BK_BLACK
    • BK_RED

      public static java.lang.String BK_RED
    • BK_GREEN

      public static java.lang.String BK_GREEN
    • BK_YELLOW

      public static java.lang.String BK_YELLOW
    • BK_BLUE

      public static java.lang.String BK_BLUE
    • BK_PURPLE

      public static java.lang.String BK_PURPLE
    • BK_CYAN

      public static java.lang.String BK_CYAN
    • BK_WHITE

      public static java.lang.String BK_WHITE
    • BK_DEFAULT

      public static java.lang.String BK_DEFAULT
    • BLACK_HI

      public static java.lang.String BLACK_HI
    • RED_HI

      public static java.lang.String RED_HI
    • GREEN_HI

      public static java.lang.String GREEN_HI
    • YELLOW_HI

      public static java.lang.String YELLOW_HI
    • BLUE_HI

      public static java.lang.String BLUE_HI
    • PURPLE_HI

      public static java.lang.String PURPLE_HI
    • CYAN_HI

      public static java.lang.String CYAN_HI
    • WHITE_HI

      public static java.lang.String WHITE_HI
    • BK_BLACK_HI

      public static java.lang.String BK_BLACK_HI
    • BK_RED_HI

      public static java.lang.String BK_RED_HI
    • BK_GREEN_HI

      public static java.lang.String BK_GREEN_HI
    • BK_YELLOW_HI

      public static java.lang.String BK_YELLOW_HI
    • BK_BLUE_HI

      public static java.lang.String BK_BLUE_HI
    • BK_PURPLE_HI

      public static java.lang.String BK_PURPLE_HI
    • BK_CYAN_HI

      public static java.lang.String BK_CYAN_HI
    • BK_WHITE_HI

      public static java.lang.String BK_WHITE_HI
    • C0

      public static java.lang.String C0
      Place the cursor in top-left corner Same as CUP(1,1)
    • CUU1

      public static java.lang.String CUU1
      Move the cursor 1 row up
    • CUD1

      public static java.lang.String CUD1
      Move the cursor 1 row down
    • CUF1

      public static java.lang.String CUF1
      Move the cursor 1 cell forwards
    • CUB1

      public static java.lang.String CUB1
      Move the cursor 1 cell backwards
    • CNL1

      public static java.lang.String CNL1
      Moves cursor to beginning of the next line
    • CPL1

      public static java.lang.String CPL1
      Moves cursor to beginning of the previous line
    • SU1

      public static java.lang.String SU1
      Scroll whole page up by 1 line
    • SD1

      public static java.lang.String SD1
      Scroll whole page down by 1 line
    • ED0

      public static java.lang.String ED0
      Clear from cursor to end of screen.
    • ED1

      public static java.lang.String ED1
      Clear from cursor to beginning of the screen
    • ED2

      public static java.lang.String ED2
      Clear entire screen (and moves cursor to upper left on DOS ANSI.SYS)
    • ED3

      public static java.lang.String ED3
      Clear entire screen and delete all lines saved in the scrollback buffer (this feature was added for xterm and is supported by other terminal applications)
    • EL0

      public static java.lang.String EL0
      Clear from cursor to the end of the line
    • EL1

      public static java.lang.String EL1
      Clear from cursor to beginning of the line
    • EL2

      public static java.lang.String EL2
      Clear entire line. Cursor position does not change.
    • AUX_PORT_ON

      public static java.lang.String AUX_PORT_ON
      Enable aux serial port usually for local serial printer
    • AUX_PORT_OFF

      public static java.lang.String AUX_PORT_OFF
      Enable aux serial port usually for local serial printer
    • DSR

      public static java.lang.String DSR
      Reports the cursor position (CPR) by transmitting ESC[n;mR, where n is the row and m is the column.
    • SCP

      public static java.lang.String SCP
      Saves the cursor position/state in SCO console mode In vertical split screen mode, instead used to set (as CSI n ; n s) or reset left and right margins.
    • RCP

      public static java.lang.String RCP
      Restores the cursor position/state in SCO console mode.
  • Constructor Details

    • ANSI

      public ANSI()
  • Method Details

    • SGR

      public static java.lang.String SGR​(java.lang.String str)
      Sets colors and style of the characters following this code Example: ANSI.SGR("40;91") makes RED_HI over BK_BLACK
      Parameters:
      str -
      Returns:
      String to be printed
    • RGB

      public static java.lang.String RGB​(int r, int g, int b)
      Specify the Foreground color in RGB
      Parameters:
      r - Red value
      g - Green value
      b - Blue value
      Returns:
      String to be printed
    • BK_RGB

      public static java.lang.String BK_RGB​(int r, int g, int b)
      Specify the Background color in RGB
      Parameters:
      r - Red value
      g - Green value
      b - Blue value
      Returns:
      String to be printed
    • CUU

      public static java.lang.String CUU​(int n)
      Moves the cursor n (default 1) cells up
      Parameters:
      n -
      Returns:
      String to be printed
    • CUD

      public static java.lang.String CUD​(int n)
      Moves the cursor n (default 1) cells down
      Parameters:
      n -
      Returns:
      String to be printed
    • CUF

      public static java.lang.String CUF​(int n)
      Moves the cursor n (default 1) cells forwards
      Parameters:
      n -
      Returns:
      String to be printed
    • CUB

      public static java.lang.String CUB​(int n)
      Moves the cursor n (default 1) cells backwards
      Parameters:
      n -
      Returns:
      String to be printed
    • CNL

      public static java.lang.String CNL​(int n)
      Moves cursor to beginning of the line n (default 1) lines down.
      Parameters:
      n -
      Returns:
      String to be printed
    • CPL

      public static java.lang.String CPL​(int n)
      Moves cursor to beginning of the line n (default 1) lines up.
      Parameters:
      n -
      Returns:
      String to be printed
    • CHA

      public static java.lang.String CHA​(int n)
      Moves the cursor to column n (default 1)
      Parameters:
      n -
      Returns:
      String to be printed
    • CUP

      public static java.lang.String CUP​(int row, int col)
      Moves the cursor to [row, column]. The values are 1-based.
      Parameters:
      row -
      col -
      Returns:
      String to be printed
    • ED

      public static java.lang.String ED​(int n)
      Clears part of the screen. If n is 0 (or missing), clear from cursor to end of screen. If n is 1, clear from cursor to beginning of the screen. If n is 2, clear entire screen (and moves cursor to upper left on DOS ANSI.SYS). If n is 3, clear entire screen and delete all lines saved in the scrollback buffer (this feature was added for xterm and is supported by other terminal applications).
      Parameters:
      n -
      Returns:
      String to be printed
    • EL

      public static java.lang.String EL​(int n)
      Erases part of the line If n is 0 (or missing), clear from cursor to the end of the line If n is 1, clear from cursor to beginning of the line If n is 2, clear entire line. Cursor position does not change.
      Parameters:
      n -
      Returns:
      String to be printed
    • SU

      public static java.lang.String SU​(int n)
      Scroll whole page up by n (default 1) lines. New lines are added at the bottom. (not ANSI.SYS)
      Parameters:
      n -
      Returns:
      String to be printed
    • SD

      public static java.lang.String SD​(int n)
      Scroll whole page down by n (default 1) lines. New lines are added at the top. (not ANSI.SYS)
      Parameters:
      n -
      Returns:
      String to be printed
    • HVP

      public static java.lang.String HVP​(int row, int col)
      Same as CUP, but counts as a format effector function (like CR or LF) rather than an editor function (like CUD or CNL) This can lead to different handling in certain terminal modes
      Parameters:
      row -
      col -
      Returns:
      String to be printed
    • custom

      public static java.lang.String custom​(java.lang.String str)
      Returns a custom ANSI ESCAPE SEQUENCE
      Parameters:
      str -
      Returns:
      ESC + "[" + str