Package jexer.backend

Class ECMA48Terminal

  • All Implemented Interfaces:
    java.lang.Runnable, Screen, TerminalReader

    public class ECMA48Terminal
    extends LogicalScreen
    implements TerminalReader, java.lang.Runnable
    This class reads keystrokes and mouse events and emits output to ANSI X3.64 / ECMA-48 type terminals e.g. xterm, linux, vt100, ansi.sys, etc.
    • Constructor Detail

      • ECMA48Terminal

        public ECMA48Terminal​(Backend backend,
                              java.lang.Object listener,
                              java.io.InputStream input,
                              java.io.OutputStream output,
                              int windowWidth,
                              int windowHeight)
                       throws java.io.UnsupportedEncodingException
        Constructor sets up state for getEvent(). If either windowWidth or windowHeight are less than 1, the terminal is not resized.
        Parameters:
        backend - the backend that will read from this terminal
        listener - the object this backend needs to wake up when new input comes in
        input - an InputStream connected to the remote user, or null for System.in. If System.in is used, then on non-Windows systems it will be put in raw mode; closeTerminal() will (blindly!) put System.in in cooked mode. input is always converted to a Reader with UTF-8 encoding.
        output - an OutputStream connected to the remote user, or null for System.out. output is always converted to a Writer with UTF-8 encoding.
        windowWidth - the number of text columns to start with
        windowHeight - the number of text rows to start with
        Throws:
        java.io.UnsupportedEncodingException - if an exception is thrown when creating the InputStreamReader
      • ECMA48Terminal

        public ECMA48Terminal​(Backend backend,
                              java.lang.Object listener,
                              java.io.InputStream input,
                              java.io.OutputStream output)
                       throws java.io.UnsupportedEncodingException
        Constructor sets up state for getEvent().
        Parameters:
        backend - the backend that will read from this terminal
        listener - the object this backend needs to wake up when new input comes in
        input - an InputStream connected to the remote user, or null for System.in. If System.in is used, then on non-Windows systems it will be put in raw mode; closeTerminal() will (blindly!) put System.in in cooked mode. input is always converted to a Reader with UTF-8 encoding.
        output - an OutputStream connected to the remote user, or null for System.out. output is always converted to a Writer with UTF-8 encoding.
        Throws:
        java.io.UnsupportedEncodingException - if an exception is thrown when creating the InputStreamReader
      • ECMA48Terminal

        public ECMA48Terminal​(Backend backend,
                              java.lang.Object listener,
                              java.io.InputStream input,
                              java.io.Reader reader,
                              java.io.PrintWriter writer,
                              boolean setRawMode)
        Constructor sets up state for getEvent().
        Parameters:
        backend - the backend that will read from this terminal
        listener - the object this backend needs to wake up when new input comes in
        input - the InputStream underlying 'reader'. Its available() method is used to determine if reader.read() will block or not.
        reader - a Reader connected to the remote user.
        writer - a PrintWriter connected to the remote user.
        setRawMode - if true, set System.in into raw mode with stty. This should in general not be used. It is here solely for Demo3, which uses System.in.
        Throws:
        java.lang.IllegalArgumentException - if input, reader, or writer are null.
      • ECMA48Terminal

        public ECMA48Terminal​(Backend backend,
                              java.lang.Object listener,
                              java.io.InputStream input,
                              java.io.Reader reader,
                              java.io.PrintWriter writer)
        Constructor sets up state for getEvent().
        Parameters:
        backend - the backend that will read from this terminal
        listener - the object this backend needs to wake up when new input comes in
        input - the InputStream underlying 'reader'. Its available() method is used to determine if reader.read() will block or not.
        reader - a Reader connected to the remote user.
        writer - a PrintWriter connected to the remote user.
        Throws:
        java.lang.IllegalArgumentException - if input, reader, or writer are null.
    • Method Detail

      • setTitle

        public void setTitle​(java.lang.String title)
        Set the window title.
        Specified by:
        setTitle in interface Screen
        Overrides:
        setTitle in class LogicalScreen
        Parameters:
        title - the new title
      • resizeToScreen

        public void resizeToScreen()
        Resize the physical screen to match the logical screen dimensions.
        Overrides:
        resizeToScreen in class LogicalScreen
      • hasEvents

        public boolean hasEvents()
        Check if there are events in the queue.
        Specified by:
        hasEvents in interface TerminalReader
        Returns:
        if true, getEvents() has something to return to the backend
      • getEvents

        public void getEvents​(java.util.List<TInputEvent> queue)
        Return any events in the IO queue.
        Specified by:
        getEvents in interface TerminalReader
        Parameters:
        queue - list to append new events to
      • closeTerminal

        public void closeTerminal()
        Restore terminal to normal state.
        Specified by:
        closeTerminal in interface TerminalReader
      • setListener

        public void setListener​(java.lang.Object listener)
        Set listener to a different Object.
        Specified by:
        setListener in interface TerminalReader
        Parameters:
        listener - the new listening object that run() wakes up on new input
      • reloadOptions

        public void reloadOptions()
        Reload options from System properties.
        Specified by:
        reloadOptions in interface TerminalReader
      • run

        public void run()
        Read function runs on a separate thread.
        Specified by:
        run in interface java.lang.Runnable
      • getTextWidth

        public int getTextWidth()
        Get the width of a character cell in pixels.
        Specified by:
        getTextWidth in interface Screen
        Overrides:
        getTextWidth in class LogicalScreen
        Returns:
        the width in pixels of a character cell
      • getTextHeight

        public int getTextHeight()
        Get the height of a character cell in pixels.
        Specified by:
        getTextHeight in interface Screen
        Overrides:
        getTextHeight in class LogicalScreen
        Returns:
        the height in pixels of a character cell
      • getSessionInfo

        public SessionInfo getSessionInfo()
        Getter for sessionInfo.
        Returns:
        the SessionInfo
      • getOutput

        public java.io.PrintWriter getOutput()
        Get the output writer.
        Returns:
        the Writer
      • flush

        public void flush()
        Flush output.
      • isImagesOverText

        public boolean isImagesOverText()
        Check if screen will support incomplete image fragments over text display.
        Returns:
        true if images can partially obscure text
      • isPixelMouse

        public boolean isPixelMouse()
        Check if terminal is reporting pixel-based mouse position.
        Returns:
        true if single-pixel mouse movements are reported
      • setPixelMouse

        public void setPixelMouse​(boolean pixelMouse)
        Set request for terminal to report pixel-based mouse position.
        Parameters:
        pixelMouse - if true, single-pixel mouse movements will be reported
      • setMouseStyle

        public void setMouseStyle​(java.lang.String mouseStyle)
        Set the mouse pointer (cursor) style.
        Parameters:
        mouseStyle - the pointer style string, one of: "default", "none", "hand", "text", "move", or "crosshair"
      • isWideCharImages

        public boolean isWideCharImages()
        Get the wideCharImages flag.
        Returns:
        true if fullwidth characters (e.g. CJK) are being drawn as images
      • setWideCharImages

        public void setWideCharImages​(boolean wideCharImages)
        Set the wideCharImages flag.
        Parameters:
        wideCharImages - if true, draw fullwidth characters (e.g. CJK) as images
      • isRgbColor

        public boolean isRgbColor()
        Get the rgbColor flag.
        Returns:
        true if the standard system colors will be emitted as 24-bit RGB
      • setRgbColor

        public void setRgbColor​(boolean rgbColor)
        Set the rgbColor flag.
        Parameters:
        rgbColor - if true, the standard system colors will be emitted as 24-bit RGB images
      • setHasSixel

        public void setHasSixel​(boolean sixel)
        Set sixel output support flag.
        Parameters:
        sixel - if true, then images will be emitted as sixel
      • hasSixelSharedPalette

        public boolean hasSixelSharedPalette()
        Get the sixel shared palette option.
        Returns:
        true if all sixel output is using the same palette that is set in one DCS sequence and used in later sequences
      • setSixelSharedPalette

        public void setSixelSharedPalette​(boolean sharedPalette)
        Set the sixel shared palette option.
        Parameters:
        sharedPalette - if true, then all sixel output will use the same palette that is set in one DCS sequence and used in later sequences
      • getSixelPaletteSize

        public int getSixelPaletteSize()
        Get the number of colors in the sixel palette.
        Returns:
        the palette size
      • setSixelPaletteSize

        public void setSixelPaletteSize​(int paletteSize)
        Set the number of colors in the sixel palette.
        Parameters:
        paletteSize - the new palette size
      • hasSixel

        public boolean hasSixel()
        Get the sixel support flag.
        Returns:
        true if this terminal is emitting sixel
      • hasIterm2Images

        public boolean hasIterm2Images()
        Get the iTerm2 images support flag.
        Returns:
        true if this terminal is emitting iTerm2 images
      • hasJexerImages

        public boolean hasJexerImages()
        Get the Jexer images support flag.
        Returns:
        true if this terminal is emitting Jexer images