Package org.jline.builtins
Class WebTerminal
java.lang.Object
org.jline.terminal.impl.AbstractTerminal
org.jline.terminal.impl.LineDisciplineTerminal
org.jline.builtins.WebTerminal
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable,Sized,TerminalExt,Terminal
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 ClassesModifier and TypeClassDescriptionstatic classThe inner WebTerminalComponent that contains the original ScreenTerminal-based implementation.Nested classes/interfaces inherited from interface org.jline.terminal.Terminal
Terminal.MouseTracking, Terminal.Signal, Terminal.SignalHandler -
Field Summary
Fields inherited from class org.jline.terminal.impl.LineDisciplineTerminal
attributes, masterOutput, size, skipNextLf, slaveInput, slaveInputPipe, slaveOutput, slaveReader, slaveWriterFields inherited from class org.jline.terminal.impl.AbstractTerminal
bools, closed, currentMouseTracking, encoding, handlers, inputEncoding, ints, name, onClose, outputEncoding, palette, status, strings, typeFields inherited from interface org.jline.terminal.Terminal
TYPE_DUMB, TYPE_DUMB_COLOR -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new WebTerminal with default settings (localhost:8080).WebTerminal(String host, int port) Creates a new WebTerminal with specified host and port.WebTerminal(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
Modifier and TypeMethodDescriptionprotected voiddoClose()dump(long timeout, boolean forceUpdate) Dumps the terminal content as HTML.Gets the web terminal component.getUrl()Gets the URL where the web terminal is accessible.booleanReturns whether the web terminal is currently running.Reads and processes input through the terminal.read()booleansetSize(int columns, int rows) Deprecated.voidRequests that the terminal adopt the specified window dimensions.voidstart()Starts the HTTP server and begins serving the web terminal.voidstop()Stops the HTTP server.booleanWrites 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, writerMethods inherited from class org.jline.terminal.impl.AbstractTerminal
canPauseResume, checkClosed, checkInterrupted, close, detectTrueColorSupport, echo, echo, echoSignal, encoding, enterRawMode, flush, getBooleanCapability, getCurrentMouseTracking, getCursorPosition, getDefaultBackgroundColor, getDefaultForegroundColor, getGraphemeClusterMode, getKind, getName, getNumericCapability, getPalette, getStatus, getStatus, getStringCapability, getType, handle, hasFocusSupport, hasMouseSupport, inputEncoding, isClusterGrouped, outputEncoding, parseInfoCmp, pause, pause, paused, puts, readMouseEvent, readMouseEvent, readMouseEvent, readMouseEvent, resume, setGraphemeClusterMode, setOnClose, supportsGraphemeClusterMode, toString, trackFocus, trackMouseMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.jline.terminal.Terminal
getBufferSize, getColumns, getHeight, getRows, getWidth, setSize
-
Constructor Details
-
WebTerminal
Creates a new WebTerminal with default settings (localhost:8080).- Throws:
IOException
-
WebTerminal
Creates a new WebTerminal with specified host and port.- Parameters:
host- the host to bind toport- the port to bind to- Throws:
IOException
-
WebTerminal
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 toport- the preferred port for the embedded HTTP server (use 0 to select an ephemeral port)columns- the initial number of terminal columnsrows- the initial number of terminal rows- Throws:
IOException- if an I/O error occurs while initializing terminal resources
-
-
Method Details
-
getComponent
Gets the web terminal component.- Returns:
- the WebTerminalComponent instance
-
getUrl
Gets the URL where the web terminal is accessible.- Returns:
- the web terminal URL
-
start
Starts the HTTP server and begins serving the web terminal.- Throws:
IOException- if the server cannot be started
-
doClose
- Overrides:
doClosein classLineDisciplineTerminal- Throws:
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
Writes text to the terminal.- Parameters:
text- the text to write- Returns:
- true if successful
-
pipe
-
read
-
dump
Dumps the terminal content as HTML.- Parameters:
timeout- maximum time to wait for changes in millisecondsforceUpdate- whether to force an update even if screen is not dirty- Returns:
- the terminal content as HTML, or null if no update
- Throws:
InterruptedException- if interrupted
-
setSize
Description copied from interface:TerminalRequests that the terminal adopt the specified window dimensions. Implementations may apply constraints or ignore the request if resizing is unsupported; callers should useTerminal.getSize()to observe the effective size after calling this method.- Specified by:
setSizein interfaceTerminal- Overrides:
setSizein classLineDisciplineTerminal- Parameters:
sz- the desired terminal size (columns and rows)- See Also:
-
setSize
Deprecated.UsesetSize(Sized)instead.Set the terminal dimensions in columns and rows.- Parameters:
columns- the new number of columnsrows- the new number of rows- Returns:
- `true` if the terminal was resized, `false` otherwise
-
setSize(Sized)instead.