Class WebTerminal

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable, org.jline.terminal.Sized, org.jline.terminal.spi.TerminalExt, org.jline.terminal.Terminal

    public class WebTerminal
    extends org.jline.terminal.impl.LineDisciplineTerminal
    A web-based terminal implementation that extends LineDisciplineTerminal.

    This class provides a web interface for terminal interaction using an embedded HTTP server. It serves an HTML page with JavaScript that communicates with the terminal via HTTP requests. The terminal supports ANSI escape sequences and renders them as HTML with CSS styling.

    Features:

    • HTTP server using JDK's built-in HttpServer
    • Real-time terminal updates via AJAX polling
    • ANSI escape sequence rendering in HTML/CSS
    • Keyboard input handling via JavaScript
    • GZIP compression support
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  WebTerminal.WebTerminalComponent
      The inner WebTerminalComponent that contains the original ScreenTerminal-based implementation.
      • Nested classes/interfaces inherited from interface org.jline.terminal.Terminal

        org.jline.terminal.Terminal.KittyKeyboardMode, org.jline.terminal.Terminal.Mode, org.jline.terminal.Terminal.MouseTracking, org.jline.terminal.Terminal.Signal, org.jline.terminal.Terminal.SignalHandler
    • Field Summary

      • Fields inherited from class org.jline.terminal.impl.LineDisciplineTerminal

        attributes, masterOutput, size, skipNextLf, slaveInput, slaveInputPipe, slaveOutput, slaveReader, slaveWriter
      • Fields inherited from class org.jline.terminal.impl.AbstractTerminal

        bools, closed, currentMouseTracking, encoding, envProvider, handlers, inputEncoding, ints, name, onClose, outputEncoding, palette, status, strings, type
      • Fields inherited from interface org.jline.terminal.Terminal

        TYPE_DUMB, TYPE_DUMB_COLOR
    • Constructor Summary

      Constructors 
      Constructor Description
      WebTerminal()
      Creates a new WebTerminal with default settings (localhost:8080).
      WebTerminal​(java.lang.String host, int port)
      Creates a new WebTerminal with specified host and port.
      WebTerminal​(java.lang.String host, int port, int columns, int rows)
      Initialize a WebTerminal bound to the given host and port and configured with the specified columns and rows.
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      protected void doClose()  
      java.lang.String dump​(long timeout, boolean forceUpdate)
      Dumps the terminal content as HTML.
      WebTerminal.WebTerminalComponent getComponent()
      Gets the web terminal component.
      java.lang.String getUrl()
      Gets the URL where the web terminal is accessible.
      boolean isRunning()
      Returns whether the web terminal is currently running.
      java.lang.String pipe​(java.lang.String input)
      Reads and processes input through the terminal.
      java.lang.String read()  
      boolean setSize​(int columns, int rows)
      Deprecated.
      Use setSize(Sized) instead.
      void setSize​(org.jline.terminal.Sized sz)  
      void start()
      Starts the HTTP server and begins serving the web terminal.
      void stop()
      Stops the HTTP server.
      boolean write​(java.lang.String text)
      Writes text to the terminal.
      • Methods inherited from class org.jline.terminal.impl.LineDisciplineTerminal

        doProcessInputByte, getAttributes, getProvider, getSize, getSystemStream, input, output, processInputByte, processInputBytes, processInputBytes, processIOException, processOutputByte, raise, reader, setAttributes, writer
      • Methods inherited from class org.jline.terminal.impl.AbstractTerminal

        canPauseResume, checkClosed, checkInterrupted, close, detectTrueColorSupport, echo, echo, echoSignal, encoding, enterRawMode, flush, getBooleanCapability, getCurrentMouseTracking, getCursorPosition, getDefaultBackgroundColor, getDefaultForegroundColor, getenv, getGraphemeClusterMode, getKind, getName, getNumericCapability, getPalette, getStatus, getStatus, getStringCapability, getType, handle, hasFocusSupport, hasInBandResizeSupport, hasKittyKeyboardSupport, hasMouseSupport, hasPollSupport, inputEncoding, isClusterGrouped, isModeSupported, outputEncoding, parseInfoCmp, pause, pause, paused, puts, readMouseEvent, readMouseEvent, readMouseEvent, readMouseEvent, resetKittyKeyboardMode, resume, setEnv, setGraphemeClusterMode, setKittyKeyboardMode, setOnClose, supportsGraphemeClusterMode, toString, trackFocus, trackInBandResize, trackMouse
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface org.jline.terminal.Terminal

        beginSynchronizedUpdate, endSynchronizedUpdate, getBufferSize, getColumns, getHeight, getRows, getWidth, setSize, synchronizedUpdate
    • Constructor Detail

      • WebTerminal

        public WebTerminal()
                    throws java.io.IOException
        Creates a new WebTerminal with default settings (localhost:8080).
        Throws:
        java.io.IOException
      • WebTerminal

        public WebTerminal​(java.lang.String host,
                           int port)
                    throws java.io.IOException
        Creates a new WebTerminal with specified host and port.
        Parameters:
        host - the host to bind to
        port - the port to bind to
        Throws:
        java.io.IOException
      • WebTerminal

        public WebTerminal​(java.lang.String host,
                           int port,
                           int columns,
                           int rows)
                    throws java.io.IOException
        Initialize a WebTerminal bound to the given host and port and configured with the specified columns and rows.
        Parameters:
        host - the host address to bind the embedded HTTP server to
        port - the preferred port for the embedded HTTP server (use 0 to select an ephemeral port)
        columns - the initial number of terminal columns
        rows - the initial number of terminal rows
        Throws:
        java.io.IOException - if an I/O error occurs while initializing terminal resources
    • Method Detail

      • getUrl

        public java.lang.String getUrl()
        Gets the URL where the web terminal is accessible.
        Returns:
        the web terminal URL
      • start

        public void start()
                   throws java.io.IOException
        Starts the HTTP server and begins serving the web terminal.
        Throws:
        java.io.IOException - if the server cannot be started
      • doClose

        protected void doClose()
                        throws java.io.IOException
        Overrides:
        doClose in class org.jline.terminal.impl.LineDisciplineTerminal
        Throws:
        java.io.IOException
      • stop

        public void stop()
        Stops the HTTP server.
      • isRunning

        public boolean isRunning()
        Returns whether the web terminal is currently running.
        Returns:
        true if running, false otherwise
      • write

        public boolean write​(java.lang.String text)
        Writes text to the terminal.
        Parameters:
        text - the text to write
        Returns:
        true if successful
      • pipe

        public java.lang.String pipe​(java.lang.String input)
        Reads and processes input through the terminal.
        Parameters:
        input - the input to process
        Returns:
        the processed input
      • read

        public java.lang.String read()
      • dump

        public java.lang.String dump​(long timeout,
                                     boolean forceUpdate)
                              throws java.lang.InterruptedException
        Dumps the terminal content as HTML.
        Parameters:
        timeout - maximum time to wait for changes in milliseconds
        forceUpdate - whether to force an update even if screen is not dirty
        Returns:
        the terminal content as HTML, or null if no update
        Throws:
        java.lang.InterruptedException - if interrupted
      • setSize

        public void setSize​(org.jline.terminal.Sized sz)
        Specified by:
        setSize in interface org.jline.terminal.Terminal
        Overrides:
        setSize in class org.jline.terminal.impl.LineDisciplineTerminal
      • setSize

        @Deprecated
        public boolean setSize​(int columns,
                               int rows)
        Deprecated.
        Use setSize(Sized) instead.
        Set the terminal dimensions in columns and rows.
        Parameters:
        columns - the new number of columns
        rows - the new number of rows
        Returns:
        `true` if the terminal was resized, `false` otherwise