Class ECMA48
- java.lang.Object
-
- jexer.tterminal.ECMA48
-
- All Implemented Interfaces:
java.lang.Runnable
public class ECMA48 extends java.lang.Object implements java.lang.Runnable
This implements a complex ECMA-48/ISO 6429/ANSI X3.64 type console, including a scrollback buffer.It currently implements VT100, VT102, VT220, and XTERM with the following caveats:
- The vttest scenario for VT220 8-bit controls (11.1.2.3) reports a failure with XTERM. This is due to vttest failing to decode the UTF-8 stream.
- Smooth scrolling, printing, keyboard locking, keyboard leds, and tests from VT100 are not supported.
- User-defined keys (DECUDK), downloadable fonts (DECDLD), and VT100/ANSI compatibility mode (DECSCL) from VT220 are not supported. (Also, because DECSCL is not supported, it will fail the last part of the vttest "Test of VT52 mode" if DeviceType is set to VT220.)
- Numeric/application keys from the number pad are not supported because they are not exposed from the TKeypress API.
- VT52 HOLD SCREEN mode is not supported.
- In VT52 graphics mode, the 3/, 5/, and 7/ characters (fraction numerators) are not rendered correctly.
- All data meant for the 'printer' (CSI Pc ? i) is discarded.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ECMA48.DeviceType
The emulator can emulate several kinds of terminals.static class
ECMA48.MouseProtocol
XTERM mouse reporting protocols.
-
Constructor Summary
Constructors Constructor Description ECMA48(ECMA48.DeviceType type, java.io.InputStream inputStream, java.io.OutputStream outputStream, DisplayListener displayListener)
Public constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addUserEvent(TInputEvent event)
Add a keyboard and mouse event from the user to the queue.void
close()
Close the input and output streams and stop the reader thread.static java.lang.String
deviceTypeLang(ECMA48.DeviceType deviceType, java.lang.String baseLang)
Return the proper LANG for this device type.static java.lang.String
deviceTypeTerm(ECMA48.DeviceType deviceType)
Return the proper TERM environment variable for this device type.DisplayLine
getBlankDisplayLine()
Obtain a new blank display line for an external user (e.g.int
getCursorX()
Expose current cursor X to outside world.int
getCursorY()
Expose current cursor Y to outside world.java.util.List<DisplayLine>
getDisplayBuffer()
Get the display buffer.int
getHeight()
Get the display height.ECMA48.MouseProtocol
getMouseProtocol()
Get the mouse protocol.java.lang.String
getScreenTitle()
Get the screen title as set by the xterm OSC sequence.java.util.List<DisplayLine>
getScrollbackBuffer()
Get the scrollback buffer.int
getScrollbackMax()
Get the maximum number of lines in the scrollback buffer.java.util.List<DisplayLine>
getVisibleDisplay(int visibleHeight, int scrollBottom)
Get the visible display + scrollback buffer, offset by a specified number of rows from the bottom.int
getWidth()
Get the display width.boolean
hasHiddenMousePointer()
Returns true if this terminal has requested the mouse pointer be hidden.boolean
isColumns132()
Get 132 columns value.boolean
isCursorVisible()
Get visible cursor flag.boolean
isPixelMouse()
Check if terminal is reporting pixel-based mouse position.boolean
isReading()
See if the reader thread is still running.void
run()
Read function runs on a separate thread.void
setBackend(Backend backend)
Set the backend to enable querying uncommon rendering features.void
setHeight(int height)
Set the display height.void
setScrollbackMax(int scrollbackMax)
Set the maximum number of lines for the scrollback buffer.void
setTextHeight(int textHeight)
Set the height of a character cell in pixels.void
setTextWidth(int textWidth)
Set the width of a character cell in pixels.void
setWidth(int width)
Set the display width.boolean
waitForOutput(int millis)
Wait for a period of time to get output from the launched process.void
writeRemote(java.lang.String str)
Write a string directly to the remote side.
-
-
-
Constructor Detail
-
ECMA48
public ECMA48(ECMA48.DeviceType type, java.io.InputStream inputStream, java.io.OutputStream outputStream, DisplayListener displayListener) throws java.io.UnsupportedEncodingException
Public constructor.- Parameters:
type
- one of the DeviceType constants to select VT100, VT102, VT220, or XTERMinputStream
- an InputStream connected to the remote side. For type == XTERM, inputStream is converted to a Reader with UTF-8 encoding.outputStream
- an OutputStream connected to the remote user. For type == XTERM, outputStream is converted to a Writer with UTF-8 encoding.displayListener
- a callback to the outer display, or null for default VT100 behavior- Throws:
java.io.UnsupportedEncodingException
- if an exception is thrown when creating the InputStreamReader
-
-
Method Detail
-
run
public final void run()
Read function runs on a separate thread.- Specified by:
run
in interfacejava.lang.Runnable
-
setBackend
public void setBackend(Backend backend)
Set the backend to enable querying uncommon rendering features.- Parameters:
backend
- the backend
-
waitForOutput
public boolean waitForOutput(int millis)
Wait for a period of time to get output from the launched process.- Parameters:
millis
- millis to wait for, or 0 to wait forever- Returns:
- true if the launched process has emitted something
-
addUserEvent
public void addUserEvent(TInputEvent event)
Add a keyboard and mouse event from the user to the queue.- Parameters:
event
- the input event to consume
-
deviceTypeTerm
public static java.lang.String deviceTypeTerm(ECMA48.DeviceType deviceType)
Return the proper TERM environment variable for this device type.- Parameters:
deviceType
- DeviceType.VT100, DeviceType, XTERM, etc.- Returns:
- "vt100", "xterm", etc.
-
deviceTypeLang
public static java.lang.String deviceTypeLang(ECMA48.DeviceType deviceType, java.lang.String baseLang)
Return the proper LANG for this device type. Only XTERM devices know about UTF-8, the others are defined by their standard to be either 7-bit or 8-bit characters only.- Parameters:
deviceType
- DeviceType.VT100, DeviceType, XTERM, etc.baseLang
- a base language without UTF-8 flag such as "C" or "en_US"- Returns:
- "en_US", "en_US.UTF-8", etc.
-
writeRemote
public void writeRemote(java.lang.String str)
Write a string directly to the remote side.- Parameters:
str
- string to send
-
close
public final void close()
Close the input and output streams and stop the reader thread. Note that it is safe to call this multiple times.
-
isReading
public final boolean isReading()
See if the reader thread is still running.- Returns:
- if true, we are still connected to / reading from the remote side
-
getBlankDisplayLine
public final DisplayLine getBlankDisplayLine()
Obtain a new blank display line for an external user (e.g. TTerminalWindow).- Returns:
- new blank line
-
getScrollbackBuffer
public final java.util.List<DisplayLine> getScrollbackBuffer()
Get the scrollback buffer.- Returns:
- the scrollback buffer
-
getDisplayBuffer
public final java.util.List<DisplayLine> getDisplayBuffer()
Get the display buffer.- Returns:
- the display buffer
-
getVisibleDisplay
public final java.util.List<DisplayLine> getVisibleDisplay(int visibleHeight, int scrollBottom)
Get the visible display + scrollback buffer, offset by a specified number of rows from the bottom.- Parameters:
visibleHeight
- the total height of the display to showscrollBottom
- the number of rows from the bottom to scroll back- Returns:
- a copy of the display + scrollback buffers
-
getWidth
public final int getWidth()
Get the display width.- Returns:
- the width (usually 80 or 132)
-
setWidth
public final void setWidth(int width)
Set the display width.- Parameters:
width
- the new width
-
getHeight
public final int getHeight()
Get the display height.- Returns:
- the height (usually 24)
-
setHeight
public final void setHeight(int height)
Set the display height.- Parameters:
height
- the new height
-
getScrollbackMax
public int getScrollbackMax()
Get the maximum number of lines in the scrollback buffer.- Returns:
- the maximum number of lines in the scrollback buffer
-
setScrollbackMax
public final void setScrollbackMax(int scrollbackMax)
Set the maximum number of lines for the scrollback buffer.- Parameters:
scrollbackMax
- the maximum number of lines for the scrollback buffer
-
isCursorVisible
public final boolean isCursorVisible()
Get visible cursor flag.- Returns:
- if true, the cursor is visible
-
getScreenTitle
public final java.lang.String getScreenTitle()
Get the screen title as set by the xterm OSC sequence. Lots of applications send a screenTitle regardless of whether it is an xterm client or not.- Returns:
- screen title
-
isColumns132
public final boolean isColumns132()
Get 132 columns value.- Returns:
- if true, the terminal is in 132 column mode
-
getCursorX
public final int getCursorX()
Expose current cursor X to outside world.- Returns:
- current cursor X
-
getCursorY
public final int getCursorY()
Expose current cursor Y to outside world.- Returns:
- current cursor Y
-
hasHiddenMousePointer
public final boolean hasHiddenMousePointer()
Returns true if this terminal has requested the mouse pointer be hidden.- Returns:
- true if this terminal has requested the mouse pointer be hidden
-
isPixelMouse
public final boolean isPixelMouse()
Check if terminal is reporting pixel-based mouse position.- Returns:
- true if single-pixel mouse movements are reported
-
getMouseProtocol
public ECMA48.MouseProtocol getMouseProtocol()
Get the mouse protocol.- Returns:
- MouseProtocol.OFF, MouseProtocol.X10, etc.
-
setTextWidth
public void setTextWidth(int textWidth)
Set the width of a character cell in pixels.- Parameters:
textWidth
- the width in pixels of a character cell
-
setTextHeight
public void setTextHeight(int textHeight)
Set the height of a character cell in pixels.- Parameters:
textHeight
- the height in pixels of a character cell
-
-