Package jexer.backend
Class ECMA48Terminal
- java.lang.Object
-
- jexer.backend.LogicalScreen
-
- jexer.backend.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.
-
-
Field Summary
-
Fields inherited from class jexer.backend.LogicalScreen
cursorVisible, cursorX, cursorY, height, logical, physical, reallyCleared, width
-
-
Constructor Summary
Constructors Constructor Description ECMA48Terminal(Backend backend, java.lang.Object listener, java.io.InputStream input, java.io.OutputStream output)Constructor sets up state for getEvent().ECMA48Terminal(Backend backend, java.lang.Object listener, java.io.InputStream input, java.io.OutputStream output, int windowWidth, int windowHeight)Constructor sets up state for getEvent().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().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().
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.awt.ColorattrToBackgroundColor(CellAttributes attr)Convert a CellAttributes background color to an AWT Color.java.awt.ColorattrToForegroundColor(CellAttributes attr)Convert a CellAttributes foreground color to an AWT Color.voidcloseTerminal()Restore terminal to normal state.voidflush()Flush output.voidflushPhysical()Push the logical screen to the physical device.intgetBytesPerSecond()Get the bytes per second from the last second.voidgetEvents(java.util.List<TInputEvent> queue)Return any events in the IO queue.java.io.PrintWritergetOutput()Get the output writer.SessionInfogetSessionInfo()Getter for sessionInfo.intgetSixelPaletteSize()Get the number of colors in the sixel palette.intgetTextHeight()Get the height of a character cell in pixels.intgetTextWidth()Get the width of a character cell in pixels.booleanhasEvents()Check if there are events in the queue.booleanhasIterm2Images()Get the iTerm2 images support flag.booleanhasJexerImages()Get the Jexer images support flag.booleanhasSixel()Get the sixel support flag.booleanhasSixelSharedPalette()Get the sixel shared palette option.booleanisImagesOverText()Check if screen will support incomplete image fragments over text display.booleanisPixelMouse()Check if terminal is reporting pixel-based mouse position.booleanisRgbColor()Get the rgbColor flag.booleanisWideCharImages()Get the wideCharImages flag.voidreloadOptions()Reload options from System properties.voidresizeToScreen()Resize the physical screen to match the logical screen dimensions.voidrun()Read function runs on a separate thread.voidsetHasSixel(boolean sixel)Set sixel output support flag.voidsetListener(java.lang.Object listener)Set listener to a different Object.voidsetMouseStyle(java.lang.String mouseStyle)Set the mouse pointer (cursor) style.voidsetPixelMouse(boolean pixelMouse)Set request for terminal to report pixel-based mouse position.voidsetRgbColor(boolean rgbColor)Set the rgbColor flag.voidsetSixelPaletteSize(int paletteSize)Set the number of colors in the sixel palette.voidsetSixelSharedPalette(boolean sharedPalette)Set the sixel shared palette option.voidsetTitle(java.lang.String title)Set the window title.voidsetWideCharImages(boolean wideCharImages)Set the wideCharImages flag.-
Methods inherited from class jexer.backend.LogicalScreen
blendRectangle, blendScreen, clear, clearPhysical, copyScreen, copyScreen, copySelection, drawBox, drawBox, drawBoxShadow, getAttrXY, getBackend, getCharXY, getCharXY, getClipBottom, getClipLeft, getClipRight, getClipTop, getCursorX, getCursorY, getHeight, getOffsetX, getOffsetY, getWidth, hideCursor, hLineXY, hLineXY, invertCell, invertCell, isCursorVisible, isDirty, putAll, putAttrXY, putAttrXY, putCharXY, putCharXY, putCharXY, putCursor, putFullwidthCharXY, putFullwidthCharXY, putFullwidthCharXY, putStringXY, putStringXY, reset, resetClipping, setBackend, setClipBottom, setClipLeft, setClipRight, setClipTop, setDimensions, setHeight, setOffsetX, setOffsetY, setSelection, setWidth, snapshot, snapshot, snapshotPhysical, unsetImageRow, vLineXY, vLineXY
-
-
-
-
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 terminallistener- the object this backend needs to wake up when new input comes ininput- 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 withwindowHeight- 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 terminallistener- the object this backend needs to wake up when new input comes ininput- 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 terminallistener- the object this backend needs to wake up when new input comes ininput- 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 terminallistener- the object this backend needs to wake up when new input comes ininput- 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:
setTitlein interfaceScreen- Overrides:
setTitlein classLogicalScreen- Parameters:
title- the new title
-
flushPhysical
public void flushPhysical()
Push the logical screen to the physical device.- Specified by:
flushPhysicalin interfaceScreen- Overrides:
flushPhysicalin classLogicalScreen
-
resizeToScreen
public void resizeToScreen()
Resize the physical screen to match the logical screen dimensions.- Overrides:
resizeToScreenin classLogicalScreen
-
hasEvents
public boolean hasEvents()
Check if there are events in the queue.- Specified by:
hasEventsin interfaceTerminalReader- 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:
getEventsin interfaceTerminalReader- Parameters:
queue- list to append new events to
-
closeTerminal
public void closeTerminal()
Restore terminal to normal state.- Specified by:
closeTerminalin interfaceTerminalReader
-
setListener
public void setListener(java.lang.Object listener)
Set listener to a different Object.- Specified by:
setListenerin interfaceTerminalReader- Parameters:
listener- the new listening object that run() wakes up on new input
-
reloadOptions
public void reloadOptions()
Reload options from System properties.- Specified by:
reloadOptionsin interfaceTerminalReader
-
run
public void run()
Read function runs on a separate thread.- Specified by:
runin interfacejava.lang.Runnable
-
getBytesPerSecond
public int getBytesPerSecond()
Get the bytes per second from the last second.- Returns:
- the bytes per second
-
getTextWidth
public int getTextWidth()
Get the width of a character cell in pixels.- Specified by:
getTextWidthin interfaceScreen- Overrides:
getTextWidthin classLogicalScreen- Returns:
- the width in pixels of a character cell
-
getTextHeight
public int getTextHeight()
Get the height of a character cell in pixels.- Specified by:
getTextHeightin interfaceScreen- Overrides:
getTextHeightin classLogicalScreen- 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
-
attrToForegroundColor
public java.awt.Color attrToForegroundColor(CellAttributes attr)
Convert a CellAttributes foreground color to an AWT Color.- Parameters:
attr- the text attributes- Returns:
- the AWT Color
-
attrToBackgroundColor
public java.awt.Color attrToBackgroundColor(CellAttributes attr)
Convert a CellAttributes background color to an AWT Color.- Parameters:
attr- the text attributes- Returns:
- the AWT Color
-
-