Interface Terminal

  • All Superinterfaces:
    java.lang.AutoCloseable

    public interface Terminal
    extends java.lang.AutoCloseable
    The terminal driver contract. The default implementation is JLine-backed, and any driver that satisfies these methods can replace it without touching the public API.
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default void close()  
      void enterAlternateScreen()
      Switches to the alternate screen buffer so the user's scrollback is preserved.
      void enterRawMode()
      Switches the terminal into raw (unbuffered, no-echo) mode.
      void flush()
      Flushes queued output to the terminal.
      void hideCursor()
      Hides the cursor.
      void moveCursor​(int x, int y)
      Positions the cursor at a zero-based cell coordinate.
      KeyEvent readKey​(long timeoutMillis)
      Reads and decodes the next key, blocking up to timeoutMillis.
      void restore()
      Restores the terminal to the main screen, cooked mode, and shown cursor.
      void setResizeListener​(java.lang.Runnable listener)
      Registers a callback invoked when the terminal resizes.
      void showCursor()
      Shows the cursor.
      TerminalSize size()  
      void write​(java.lang.String text)
      Queues an already-formed ANSI string for output.
    • Method Detail

      • enterRawMode

        void enterRawMode()
        Switches the terminal into raw (unbuffered, no-echo) mode.
      • enterAlternateScreen

        void enterAlternateScreen()
        Switches to the alternate screen buffer so the user's scrollback is preserved.
      • restore

        void restore()
        Restores the terminal to the main screen, cooked mode, and shown cursor. Idempotent.
      • size

        TerminalSize size()
        Returns:
        the current size in cells
      • setResizeListener

        void setResizeListener​(java.lang.Runnable listener)
        Registers a callback invoked when the terminal resizes.
        Parameters:
        listener - the callback, which may run off the UI thread
      • readKey

        KeyEvent readKey​(long timeoutMillis)
        Reads and decodes the next key, blocking up to timeoutMillis.
        Parameters:
        timeoutMillis - maximum time to wait in milliseconds
        Returns:
        the decoded key event, or null when the timeout elapses with no input
      • write

        void write​(java.lang.String text)
        Queues an already-formed ANSI string for output.
        Parameters:
        text - the raw string to write
      • flush

        void flush()
        Flushes queued output to the terminal.
      • hideCursor

        void hideCursor()
        Hides the cursor.
      • showCursor

        void showCursor()
        Shows the cursor.
      • moveCursor

        void moveCursor​(int x,
                        int y)
        Positions the cursor at a zero-based cell coordinate.
        Parameters:
        x - column in cells
        y - row in cells
      • close

        default void close()
        Specified by:
        close in interface java.lang.AutoCloseable