Class Control

  • All Implemented Interfaces:
    Comparable<Char>, Char, Stringable
    Direct Known Subclasses:
    Color

    public class Control
    extends Object
    implements Char
    This class represents terminal control characters. These are not printable on their own, but will do stuff with the current terminal if printed out to it, and some represents non-printable keystrokes or key combinations.

    See Wikipedia on C0 and C1 control codes.

    • Field Detail

      • TERMINAL_CONTROL

        public static final Control TERMINAL_CONTROL
        Enable full terminal control. This will also clear the screen and disable scrolling, but will not move the cursor position.
      • TERMINAL_RESTORE

        public static final Control TERMINAL_RESTORE
        Restore state of terminal back to before control taken, including cursor position.
      • TERMINAL_CLEAR

        public static final Control TERMINAL_CLEAR
        Clear screen, not moving cursor or clearing scroll history.
      • TERMINAL_RESET

        public static final Control TERMINAL_RESET
        Reset terminal (will clear scroll history) and place cursor at top left. Note that resetting in the alternate screen buffer will also unset it back to default, not restore the previous state (restore will do nothing).
      • CURSOR_ERASE

        public static final Control CURSOR_ERASE
        Erase character at cursor position.
      • CURSOR_SAVE

        public static final Control CURSOR_SAVE
        Save position of cursor.
      • CURSOR_RESTORE

        public static final Control CURSOR_RESTORE
        Restore position of cursor to last saved point.
      • UP

        public static final Control UP
        The up key.
      • DOWN

        public static final Control DOWN
        The down key.
      • RIGHT

        public static final Control RIGHT
        The right key.
      • LEFT

        public static final Control LEFT
        The left key.
      • CTRL_UP

        public static final Control CTRL_UP
        The control up key combination.
      • CTRL_DOWN

        public static final Control CTRL_DOWN
        The control down key combination.
      • CTRL_RIGHT

        public static final Control CTRL_RIGHT
        The control right key combination.
      • CTRL_LEFT

        public static final Control CTRL_LEFT
        The control left key combination.
      • DPAD_MID

        public static final Control DPAD_MID
        The DPAD middle key.
      • INSERT

        public static final Control INSERT
        The insert key.
      • DELETE

        public static final Control DELETE
        The delete key.
      • HOME

        public static final Control HOME
        The home key.
      • END

        public static final Control END
        The end key.
      • PAGE_UP

        public static final Control PAGE_UP
        The page up key.
      • PAGE_DOWN

        public static final Control PAGE_DOWN
        The page down key.
      • F1

        public static final Control F1
        F1 key.
      • F2

        public static final Control F2
        F2 key.
      • F3

        public static final Control F3
        F3 key.
      • F4

        public static final Control F4
        F4 key.
      • F5

        public static final Control F5
        F5 key.
      • F6

        public static final Control F6
        F6 key.
      • F7

        public static final Control F7
        F7 key.
      • F8

        public static final Control F8
        F8 key.
      • F9

        public static final Control F9
        F9 key.
      • F10

        public static final Control F10
        F10 key.
      • F11

        public static final Control F11
        NOTE: It is common to use F11 to mean 'fullscreen', so there is a good chance this is intercepted before reaching the terminal application.
      • F12

        public static final Control F12
        F12 key.
      • ALT_W

        public static final Char ALT_W
        Delete rest of word after (right of) cursor.
      • ALT_K

        public static final Char ALT_K
        Delete rest of word before (left of) cursor.
      • ALT_U

        public static final Char ALT_U
        Delete rest of current line after (right of) cursor.
      • ALT_D

        public static final Char ALT_D
        Delete rest of current line before (left of) cursor.
    • Method Detail

      • cursorSetPos

        public static Control cursorSetPos​(int line)
        Make control sequence setting the cursor on a fixed position on the screen using line numbers from the top to the first char of that line.
        Parameters:
        line - Line number to move to.
        Returns:
        The control sequence.
      • cursorSetPos

        public static Control cursorSetPos​(int line,
                                           int col)
        Make control sequence setting the cursor on a fixed position on the screen using line numbers from the top, and column number from the left.
        Parameters:
        line - Line number to move to, 1-indexed.
        col - Column number ot move to, 1-indexed.
        Returns:
        The control sequence.
      • cursorUp

        public static Control cursorUp​(int num)
        Make control sequence moving the cursor N positions to up.
        Parameters:
        num - Number of positions to move cursor.
        Returns:
        The control sequence.
      • cursorDown

        public static Control cursorDown​(int num)
        Make control sequence moving the cursor N positions to down.
        Parameters:
        num - Number of positions to move cursor.
        Returns:
        The control sequence.
      • cursorRight

        public static Control cursorRight​(int num)
        Make control sequence moving the cursor N positions to the right.
        Parameters:
        num - Number of positions to move cursor.
        Returns:
        The control sequence.
      • cursorLeft

        public static Control cursorLeft​(int num)
        Make control sequence moving the cursor N positions to the left.
        Parameters:
        num - Number of positions to move cursor.
        Returns:
        The control sequence.
      • alt

        public static Char alt​(char c)
        Make a keystroke char for alt + key.
        Parameters:
        c - The char to get 'alt' keystroke char of.
        Returns:
        The keystroke char.
      • ctrl

        public static Char ctrl​(char c)
        Make a keystroke char for control + key, using the control char meaning in common linux terminals.
        Parameters:
        c - The char to get 'ctrl' keystroke char of.
        Returns:
        The keystroke char.
      • codepoint

        public int codepoint()
        Description copied from interface: Char
        Unicode codepoint representing this character.
        Specified by:
        codepoint in interface Char
        Returns:
        The 31 bit unsigned unicode code-point, or -1 if not representing a single unicode character.
      • asString

        public String asString()
        Description copied from interface: Stringable
        Make a string representation of the instance value.
        Specified by:
        asString in interface Stringable
        Returns:
        The string representation.
      • printableWidth

        public int printableWidth()
        Description copied from interface: Char
        The number of character spaces taken up by this symbol. Usually 1, but 0 for control sequences, control characters, and 2 for wide symbols like CJK characters.
        Specified by:
        printableWidth in interface Char
        Returns:
        The printable width of the character.
      • length

        public int length()
        Description copied from interface: Char
        Number of utf-16 characters that this character takes up if enclosed in a java string.
        Specified by:
        length in interface Char
        Returns:
        The char count of the character.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object