Class ANSI

java.lang.Object
org.aesh.terminal.utils.ANSI

public class ANSI extends Object
Utility class to provide ANSI codes for different operations
Author:
Ståle W. Pedersen
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    ANSI escape code to switch to alternate screen buffer.
    static final String
    ANSI escape code for black background.
    static final String
    ANSI escape code for black foreground text.
    static final String
    ANSI escape code to enable blinking text.
    static final String
    ANSI escape code to disable blinking text.
    static final String
    ANSI escape code for blue background.
    static final String
    ANSI escape code for blue foreground text.
    static final String
    ANSI escape code to enable bold text.
    static final String
    ANSI escape code to disable bold text.
    static final int[]
    ANSI escape sequence to clear the entire screen.
    static final String
    ANSI escape code to hide the cursor.
    static final String
    ANSI escape code to restore previously saved cursor position.
    static final String
    ANSI escape code to query cursor row position.
    static final String
    ANSI escape code to save current cursor position.
    static final String
    ANSI escape code to show the cursor.
    static final int[]
    ANSI escape sequence to move cursor to start of line.
    static final String
    ANSI escape code for cyan background.
    static final String
    ANSI escape code for cyan foreground text.
    static final String
    ANSI escape code to enable dark (normal) background mode.
    static final String
    ANSI escape code for default background color.
    static final String
    ANSI escape code for default foreground text color.
    static final int[]
    ANSI escape sequence to erase from cursor to end of line.
    static final int[]
    ANSI escape sequence to erase the entire current line.
    static final String
    ANSI escape code for green background.
    static final String
    ANSI escape code for green foreground text.
    static final String
    ANSI escape code to invert foreground and background colors.
    static final String
    ANSI escape code to enable light (reverse video) background mode.
    static final String
    ANSI escape code for magenta background.
    static final String
    ANSI escape code for magenta foreground text.
    static final String
    ANSI escape code to switch back to main screen buffer.
    static final int[]
    ANSI escape sequence to move cursor down one line.
    static final int[]
    ANSI escape sequence to move cursor up one line.
    static final String
    ANSI escape code to restore normal foreground and background colors.
    static final String
    ANSI escape code for red background.
    static final String
    ANSI escape code for red foreground text.
    static final String
    ANSI escape code to reset all text attributes to default.
    static final String
    ANSI escape sequence start.
    static final String
    ANSI escape code to enable underlined text.
    static final String
    ANSI escape code to disable underlined text.
    static final String
    ANSI escape code for white background.
    static final String
    ANSI escape code for white foreground text.
    static final String
    ANSI escape code for yellow background.
    static final String
    ANSI escape code for yellow foreground text.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Point
    getActualCursor(int[] input)
    Parse cursor position response and return the actual cursor position.
    static int[]
    moveColumnsLeft(int rows)
    Create ANSI escape sequence to move cursor left by specified columns.
    static int[]
    moveColumnsRight(int rows)
    Create ANSI escape sequence to move cursor right by specified columns.
    static int[]
    moveRowsDown(int rows)
    Create ANSI escape sequence to move cursor down by specified rows.
    static int[]
    moveRowsUp(int rows)
    Create ANSI escape sequence to move cursor up by specified rows.
    static int[]
    printAnsi(char... out)
    Return a ansified string based on param
    static int[]
    Return a ansified string based on param

    Methods inherited from class java.lang.Object

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

    • START

      public static final String START
      ANSI escape sequence start.
      See Also:
    • BLACK_TEXT

      public static final String BLACK_TEXT
      ANSI escape code for black foreground text.
      See Also:
    • RED_TEXT

      public static final String RED_TEXT
      ANSI escape code for red foreground text.
      See Also:
    • GREEN_TEXT

      public static final String GREEN_TEXT
      ANSI escape code for green foreground text.
      See Also:
    • YELLOW_TEXT

      public static final String YELLOW_TEXT
      ANSI escape code for yellow foreground text.
      See Also:
    • BLUE_TEXT

      public static final String BLUE_TEXT
      ANSI escape code for blue foreground text.
      See Also:
    • MAGENTA_TEXT

      public static final String MAGENTA_TEXT
      ANSI escape code for magenta foreground text.
      See Also:
    • CYAN_TEXT

      public static final String CYAN_TEXT
      ANSI escape code for cyan foreground text.
      See Also:
    • WHITE_TEXT

      public static final String WHITE_TEXT
      ANSI escape code for white foreground text.
      See Also:
    • DEFAULT_TEXT

      public static final String DEFAULT_TEXT
      ANSI escape code for default foreground text color.
      See Also:
    • BLACK_BG

      public static final String BLACK_BG
      ANSI escape code for black background.
      See Also:
    • RED_BG

      public static final String RED_BG
      ANSI escape code for red background.
      See Also:
    • GREEN_BG

      public static final String GREEN_BG
      ANSI escape code for green background.
      See Also:
    • YELLOW_BG

      public static final String YELLOW_BG
      ANSI escape code for yellow background.
      See Also:
    • BLUE_BG

      public static final String BLUE_BG
      ANSI escape code for blue background.
      See Also:
    • MAGENTA_BG

      public static final String MAGENTA_BG
      ANSI escape code for magenta background.
      See Also:
    • CYAN_BG

      public static final String CYAN_BG
      ANSI escape code for cyan background.
      See Also:
    • WHITE_BG

      public static final String WHITE_BG
      ANSI escape code for white background.
      See Also:
    • DEFAULT_BG

      public static final String DEFAULT_BG
      ANSI escape code for default background color.
      See Also:
    • ALTERNATE_BUFFER

      public static final String ALTERNATE_BUFFER
      ANSI escape code to switch to alternate screen buffer.
    • MAIN_BUFFER

      public static final String MAIN_BUFFER
      ANSI escape code to switch back to main screen buffer.
    • INVERT_BACKGROUND

      public static final String INVERT_BACKGROUND
      ANSI escape code to invert foreground and background colors.
    • NORMAL_BACKGROUND

      public static final String NORMAL_BACKGROUND
      ANSI escape code to restore normal foreground and background colors.
    • RESET

      public static final String RESET
      ANSI escape code to reset all text attributes to default.
      See Also:
    • BOLD

      public static final String BOLD
      ANSI escape code to enable bold text.
    • BOLD_OFF

      public static final String BOLD_OFF
      ANSI escape code to disable bold text.
      See Also:
    • UNDERLINE

      public static final String UNDERLINE
      ANSI escape code to enable underlined text.
    • UNDERLINE_OFF

      public static final String UNDERLINE_OFF
      ANSI escape code to disable underlined text.
    • CURSOR_START

      public static final int[] CURSOR_START
      ANSI escape sequence to move cursor to start of line.
    • ERASE_WHOLE_LINE

      public static final int[] ERASE_WHOLE_LINE
      ANSI escape sequence to erase the entire current line.
    • CURSOR_ROW

      public static final String CURSOR_ROW
      ANSI escape code to query cursor row position.
      See Also:
    • CLEAR_SCREEN

      public static final int[] CLEAR_SCREEN
      ANSI escape sequence to clear the entire screen.
    • CURSOR_SAVE

      public static final String CURSOR_SAVE
      ANSI escape code to save current cursor position.
    • CURSOR_RESTORE

      public static final String CURSOR_RESTORE
      ANSI escape code to restore previously saved cursor position.
    • CURSOR_HIDE

      public static final String CURSOR_HIDE
      ANSI escape code to hide the cursor.
      See Also:
    • CURSOR_SHOW

      public static final String CURSOR_SHOW
      ANSI escape code to show the cursor.
      See Also:
    • ERASE_LINE_FROM_CURSOR

      public static final int[] ERASE_LINE_FROM_CURSOR
      ANSI escape sequence to erase from cursor to end of line.
    • MOVE_LINE_UP

      public static final int[] MOVE_LINE_UP
      ANSI escape sequence to move cursor up one line.
    • MOVE_LINE_DOWN

      public static final int[] MOVE_LINE_DOWN
      ANSI escape sequence to move cursor down one line.
    • LIGHT_BG

      public static final String LIGHT_BG
      ANSI escape code to enable light (reverse video) background mode.
      See Also:
    • DARK_BG

      public static final String DARK_BG
      ANSI escape code to enable dark (normal) background mode.
      See Also:
  • Method Details

    • printAnsi

      public static int[] printAnsi(String out)
      Return a ansified string based on param
      Parameters:
      out - string
      Returns:
      ansified string
    • printAnsi

      public static int[] printAnsi(char... out)
      Return a ansified string based on param
      Parameters:
      out - what will be ansified
      Returns:
      ansified string
    • getActualCursor

      public static Point getActualCursor(int[] input)
      Parse cursor position response and return the actual cursor position.
      Parameters:
      input - the ANSI cursor position response sequence
      Returns:
      a Point containing the column and row of the cursor
    • moveRowsUp

      public static int[] moveRowsUp(int rows)
      Create ANSI escape sequence to move cursor up by specified rows.
      Parameters:
      rows - number of rows to move up
      Returns:
      ANSI escape sequence as int array
    • moveRowsDown

      public static int[] moveRowsDown(int rows)
      Create ANSI escape sequence to move cursor down by specified rows.
      Parameters:
      rows - number of rows to move down
      Returns:
      ANSI escape sequence as int array
    • moveColumnsRight

      public static int[] moveColumnsRight(int rows)
      Create ANSI escape sequence to move cursor right by specified columns.
      Parameters:
      rows - number of columns to move right
      Returns:
      ANSI escape sequence as int array
    • moveColumnsLeft

      public static int[] moveColumnsLeft(int rows)
      Create ANSI escape sequence to move cursor left by specified columns.
      Parameters:
      rows - number of columns to move left
      Returns:
      ANSI escape sequence as int array