Class WindowsAnsiPrintStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.Appendable, java.lang.AutoCloseable

    public final class WindowsAnsiPrintStream
    extends AnsiPrintStream
    A Windows ANSI escape processor, that uses JNA to access native platform API's to change the console attributes (see Jansi native Kernel32).

    The native library used is named jansi and is loaded using HawtJNI Runtime Library

    Since:
    1.7
    See Also:
    WindowsAnsiOutputStream
    • Field Detail

      • stdout_handle

        private static final long stdout_handle
      • stderr_handle

        private static final long stderr_handle
      • console

        private final long console
      • FOREGROUND_YELLOW

        private static final short FOREGROUND_YELLOW
      • FOREGROUND_MAGENTA

        private static final short FOREGROUND_MAGENTA
      • FOREGROUND_CYAN

        private static final short FOREGROUND_CYAN
      • FOREGROUND_WHITE

        private static final short FOREGROUND_WHITE
      • BACKGROUND_YELLOW

        private static final short BACKGROUND_YELLOW
      • BACKGROUND_MAGENTA

        private static final short BACKGROUND_MAGENTA
      • BACKGROUND_CYAN

        private static final short BACKGROUND_CYAN
      • BACKGROUND_WHITE

        private static final short BACKGROUND_WHITE
      • ANSI_FOREGROUND_COLOR_MAP

        private static final short[] ANSI_FOREGROUND_COLOR_MAP
      • ANSI_BACKGROUND_COLOR_MAP

        private static final short[] ANSI_BACKGROUND_COLOR_MAP
      • info

        private final org.fusesource.jansi.internal.Kernel32.CONSOLE_SCREEN_BUFFER_INFO info
      • originalColors

        private final short originalColors
      • negative

        private boolean negative
      • savedX

        private short savedX
      • savedY

        private short savedY
    • Constructor Detail

      • WindowsAnsiPrintStream

        public WindowsAnsiPrintStream​(java.io.PrintStream ps,
                                      boolean stdout)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • WindowsAnsiPrintStream

        public WindowsAnsiPrintStream​(java.io.PrintStream ps)
                               throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • getConsoleInfo

        private void getConsoleInfo()
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • applyAttribute

        private void applyAttribute()
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • invertAttributeColors

        private short invertAttributeColors​(short attributes)
      • applyCursorPosition

        private void applyCursorPosition()
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • processEraseScreen

        protected void processEraseScreen​(int eraseOption)
                                   throws java.io.IOException
        Description copied from class: AnsiPrintStream
        Process CSI n J ANSI code, corresponding to ED – Erase in Display
        Overrides:
        processEraseScreen in class AnsiPrintStream
        Parameters:
        eraseOption - eraseOption
        Throws:
        java.io.IOException - IOException
      • processEraseLine

        protected void processEraseLine​(int eraseOption)
                                 throws java.io.IOException
        Description copied from class: AnsiPrintStream
        Process CSI n K ANSI code, corresponding to ED – Erase in Line
        Overrides:
        processEraseLine in class AnsiPrintStream
        Parameters:
        eraseOption - eraseOption
        Throws:
        java.io.IOException - IOException
      • processCursorLeft

        protected void processCursorLeft​(int count)
                                  throws java.io.IOException
        Description copied from class: AnsiPrintStream
        process CSI n D corresponding to CUB – Cursor Back
        Overrides:
        processCursorLeft in class AnsiPrintStream
        Parameters:
        count - count
        Throws:
        java.io.IOException - IOException
      • processCursorRight

        protected void processCursorRight​(int count)
                                   throws java.io.IOException
        Description copied from class: AnsiPrintStream
        process CSI n C corresponding to CUF – Cursor Forward
        Overrides:
        processCursorRight in class AnsiPrintStream
        Parameters:
        count - count
        Throws:
        java.io.IOException - IOException
      • processCursorDown

        protected void processCursorDown​(int count)
                                  throws java.io.IOException
        Description copied from class: AnsiPrintStream
        process CSI n B corresponding to CUD – Cursor Down
        Overrides:
        processCursorDown in class AnsiPrintStream
        Parameters:
        count - count
        Throws:
        java.io.IOException - IOException
      • processCursorUp

        protected void processCursorUp​(int count)
                                throws java.io.IOException
        Description copied from class: AnsiPrintStream
        process CSI n A corresponding to CUU – Cursor Up
        Overrides:
        processCursorUp in class AnsiPrintStream
        Parameters:
        count - count
        Throws:
        java.io.IOException - IOException
      • processCursorTo

        protected void processCursorTo​(int row,
                                       int col)
                                throws java.io.IOException
        Description copied from class: AnsiPrintStream
        process CSI n ; m H corresponding to CUP – Cursor Position or CSI n ; m f corresponding to HVP – Horizontal and Vertical Position
        Overrides:
        processCursorTo in class AnsiPrintStream
        Parameters:
        row - row
        col - col
        Throws:
        java.io.IOException - IOException
      • processCursorToColumn

        protected void processCursorToColumn​(int x)
                                      throws java.io.IOException
        Description copied from class: AnsiPrintStream
        process CSI n G corresponding to CHA – Cursor Horizontal Absolute
        Overrides:
        processCursorToColumn in class AnsiPrintStream
        Parameters:
        x - the column
        Throws:
        java.io.IOException - IOException
      • processSetForegroundColor

        protected void processSetForegroundColor​(int color,
                                                 boolean bright)
                                          throws java.io.IOException
        Description copied from class: AnsiPrintStream
        process SGR 30-37 or SGR 90-97 corresponding to Set text color (foreground) either in normal mode or high intensity.
        Overrides:
        processSetForegroundColor in class AnsiPrintStream
        Parameters:
        color - the text color
        bright - is high intensity?
        Throws:
        java.io.IOException - IOException
      • processSetBackgroundColor

        protected void processSetBackgroundColor​(int color,
                                                 boolean bright)
                                          throws java.io.IOException
        Description copied from class: AnsiPrintStream
        process SGR 40-47 or SGR 100-107 corresponding to Set background color either in normal mode or high intensity.
        Overrides:
        processSetBackgroundColor in class AnsiPrintStream
        Parameters:
        color - the background color
        bright - is high intensity?
        Throws:
        java.io.IOException - IOException
      • processDefaultTextColor

        protected void processDefaultTextColor()
                                        throws java.io.IOException
        Description copied from class: AnsiPrintStream
        process SGR 39 corresponding to Default text color (foreground)
        Overrides:
        processDefaultTextColor in class AnsiPrintStream
        Throws:
        java.io.IOException - IOException
      • processDefaultBackgroundColor

        protected void processDefaultBackgroundColor()
                                              throws java.io.IOException
        Description copied from class: AnsiPrintStream
        process SGR 49 corresponding to Default background color
        Overrides:
        processDefaultBackgroundColor in class AnsiPrintStream
        Throws:
        java.io.IOException - IOException
      • processAttributeRest

        protected void processAttributeRest()
                                     throws java.io.IOException
        Description copied from class: AnsiPrintStream
        process SGR 0 corresponding to Reset / Normal
        Overrides:
        processAttributeRest in class AnsiPrintStream
        Throws:
        java.io.IOException - IOException
      • processSaveCursorPosition

        protected void processSaveCursorPosition()
                                          throws java.io.IOException
        Description copied from class: AnsiPrintStream
        Process CSI s ANSI code, corresponding to SCP – Save Cursor Position
        Overrides:
        processSaveCursorPosition in class AnsiPrintStream
        Throws:
        java.io.IOException - IOException
      • processRestoreCursorPosition

        protected void processRestoreCursorPosition()
                                             throws java.io.IOException
        Description copied from class: AnsiPrintStream
        Process CSI u ANSI code, corresponding to RCP – Restore Cursor Position
        Overrides:
        processRestoreCursorPosition in class AnsiPrintStream
        Throws:
        java.io.IOException - IOException
      • processInsertLine

        protected void processInsertLine​(int optionInt)
                                  throws java.io.IOException
        Description copied from class: AnsiPrintStream
        Process CSI L ANSI code, corresponding to IL – Insert Line
        Overrides:
        processInsertLine in class AnsiPrintStream
        Parameters:
        optionInt - option
        Throws:
        java.io.IOException - IOException
      • processDeleteLine

        protected void processDeleteLine​(int optionInt)
                                  throws java.io.IOException
        Description copied from class: AnsiPrintStream
        Process CSI M ANSI code, corresponding to DL – Delete Line
        Overrides:
        processDeleteLine in class AnsiPrintStream
        Parameters:
        optionInt - option
        Throws:
        java.io.IOException - IOException
      • processChangeWindowTitle

        protected void processChangeWindowTitle​(java.lang.String label)
        Description copied from class: AnsiPrintStream
        process OSC 2;text BEL corresponding to Change Window title
        Overrides:
        processChangeWindowTitle in class AnsiPrintStream
        Parameters:
        label - window title text