Package jexer
Class TTerminalWidget
- java.lang.Object
-
- jexer.TWidget
-
- jexer.TScrollableWidget
-
- jexer.TTerminalWidget
-
- All Implemented Interfaces:
java.lang.Comparable<TWidget>
,EditMenuUser
,Scrollable
,DisplayListener
public class TTerminalWidget extends TScrollableWidget implements DisplayListener, EditMenuUser
TTerminalWidget exposes a ECMA-48 / ANSI X3.64 style terminal in a widget.
-
-
Field Summary
-
Fields inherited from class jexer.TScrollableWidget
hScroller, vScroller
-
-
Constructor Summary
Constructors Constructor Description TTerminalWidget(TWidget parent, int x, int y)
Public constructor spawns a shell.TTerminalWidget(TWidget parent, int x, int y, int width, int height, java.lang.String[] command, TAction closeAction)
Public constructor spawns a custom command line.TTerminalWidget(TWidget parent, int x, int y, int width, int height, TAction closeAction)
Public constructor spawns a shell.TTerminalWidget(TWidget parent, int x, int y, java.lang.String commandLine)
Public constructor spawns a custom command line.TTerminalWidget(TWidget parent, int x, int y, java.lang.String[] command)
Public constructor spawns a custom command line.TTerminalWidget(TWidget parent, int x, int y, java.lang.String[] command, TAction closeAction)
Public constructor spawns a custom command line.TTerminalWidget(TWidget parent, int x, int y, TAction closeAction)
Public constructor spawns a shell.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
bigVerticalDecrement()
Perform a big step change up.void
bigVerticalIncrement()
Perform a big step change down.void
close()
Handle widget close.void
displayChanged()
Called by emulator when fresh data has come in.void
draw()
Draw the display buffer.java.lang.String[]
getCommandLine()
Get the full command line that spawned the shell.java.util.List<DisplayLine>
getDisplayBuffer()
Get the display buffer from the emulator.int
getDisplayHeight()
Function to call to obtain the display height.int
getDisplayWidth()
Function to call to obtain the display width.int
getExitValue()
Get the exit value for the emulator.long
getPid()
Get the PID of the child process.java.util.List<DisplayLine>
getScrollbackBuffer()
Get the scrollback buffer from the emulator.java.lang.String
getTitle()
Get the desired window title.boolean
hasHiddenMouse()
Returns true if this widget does not want the application-wide mouse cursor drawn over it.boolean
isEditMenuClear()
Check if the clear menu item should be enabled.boolean
isEditMenuCopy()
Check if the copy menu item should be enabled.boolean
isEditMenuCut()
Check if the cut menu item should be enabled.boolean
isEditMenuPaste()
Check if the paste menu item should be enabled.boolean
isPixelMouse()
Check if per-pixel mouse events are requested.boolean
isReading()
See if the terminal is still running.void
onCommand(TCommandEvent command)
Handle posted command events.void
onKeypress(TKeypressEvent keypress)
Handle keystrokes.void
onMouseDown(TMouseEvent mouse)
Handle mouse press events.void
onMouseMotion(TMouseEvent mouse)
Handle mouse motion events.void
onMouseUp(TMouseEvent mouse)
Handle mouse release events.void
onResize(TResizeEvent resize)
Handle window/screen resize events.void
onShellExit()
Hook for subclasses to be notified of the shell termination.void
reflowData()
Resize scrollbars for a new width/height.void
setDirty()
Set the dirty flag.void
setVerticalValue(int value)
Set current value of the vertical scroll.void
signalShellChildProcess(int signal)
Send a signal to the the child of the 'script' or 'ptypipe' process used on POSIX.void
signalShellChildProcess(java.lang.String signal)
Send a signal to the the child of the 'script' or 'ptypipe' process used on POSIX.void
toBottom()
Go to the bottom edge of the vertical scroller.void
toTop()
Go to the top edge of the vertical scroller.void
verticalDecrement()
Perform a small step change up.void
verticalIncrement()
Perform a small step change down.boolean
waitForOutput(int millis)
Wait for a period of time to get output from the launched process.void
writeSessionAsHtml(java.io.Writer writer)
Write the entire session (scrollback and display buffers) as colorized HTML to a writer.void
writeSessionAsText(java.io.Writer writer)
Write the entire session (scrollback and display buffers) as plain text to a writer.-
Methods inherited from class jexer.TScrollableWidget
bigHorizontalDecrement, bigHorizontalIncrement, getBottomValue, getHorizontalBigChange, getHorizontalScroller, getHorizontalSmallChange, getHorizontalValue, getLeftValue, getRightValue, getTopValue, getVerticalBigChange, getVerticalScroller, getVerticalSmallChange, getVerticalValue, horizontalDecrement, horizontalIncrement, placeScrollbars, setBottomValue, setHorizontalBigChange, setHorizontalSmallChange, setHorizontalValue, setLeftValue, setRightValue, setTopValue, setVerticalBigChange, setVerticalSmallChange, toEnd, toHome, toLeft, toRight
-
Methods inherited from class jexer.TWidget
activate, activate, activate, activateAll, addButton, addCalendar, addCheckBox, addCheckBox, addComboBox, addDirectoryList, addDirectoryList, addDirectoryList, addDirectoryList, addEditor, addField, addField, addField, addField, addImage, addImage, addLabel, addLabel, addLabel, addLabel, addLabel, addLabel, addList, addList, addList, addList, addPanel, addPasswordField, addPasswordField, addPasswordField, addProgressBar, addRadioGroup, addRadioGroup, addSpinner, addSplitPane, addTable, addTable, addText, addText, addTreeViewWidget, addTreeViewWidget, compareTo, doRepaint, drawBox, drawBox, drawBoxShadow, drawChildren, fileOpenBox, fileOpenBox, fileOpenBox, fileOpenBox, fileSaveBox, getAbsoluteX, getAbsoluteY, getActiveChild, getApplication, getAttrXY, getChildren, getClipboard, getCursorAbsoluteX, getCursorAbsoluteY, getCursorX, getCursorY, getCustomMousePointer, getHeight, getLayoutManager, getMouseStyle, getParent, getScreen, getTheme, getWidgetUnderMouse, getWidth, getWindow, getX, getY, handleEvent, hasChild, hLineXY, inputBox, inputBox, inputBox, isAbsoluteActive, isActive, isCursorVisible, isDrawable, isEchoKeystrokes, isEnabled, isVisible, messageBox, messageBox, mouseWouldHit, onIdle, onMenu, onMouseDoubleClick, putAll, putAttrXY, putAttrXY, putCharXY, putCharXY, putCharXY, putStringXY, putStringXY, remove, remove, remove, remove, removeAll, resetTabOrder, setActive, setCursorVisible, setCursorX, setCursorY, setCustomMousePointer, setDimensions, setEchoKeystrokes, setEchoKeystrokes, setEnabled, setHeight, setLayoutManager, setMouseStyle, setParent, setupForTWindow, setVisible, setWidth, setWindow, setX, setY, splitHorizontal, splitVertical, switchWidget, toPrettyString, toPrettyString, toString, vLineXY
-
-
-
-
Constructor Detail
-
TTerminalWidget
public TTerminalWidget(TWidget parent, int x, int y, java.lang.String commandLine)
Public constructor spawns a custom command line.- Parameters:
parent
- parent widgetx
- column relative to parenty
- row relative to parentcommandLine
- the command line to execute
-
TTerminalWidget
public TTerminalWidget(TWidget parent, int x, int y, java.lang.String[] command)
Public constructor spawns a custom command line.- Parameters:
parent
- parent widgetx
- column relative to parenty
- row relative to parentcommand
- the command line to execute
-
TTerminalWidget
public TTerminalWidget(TWidget parent, int x, int y, java.lang.String[] command, TAction closeAction)
Public constructor spawns a custom command line.- Parameters:
parent
- parent widgetx
- column relative to parenty
- row relative to parentcommand
- the command line to executecloseAction
- action to perform when the shell exits
-
TTerminalWidget
public TTerminalWidget(TWidget parent, int x, int y, int width, int height, java.lang.String[] command, TAction closeAction)
Public constructor spawns a custom command line.- Parameters:
parent
- parent widgetx
- column relative to parenty
- row relative to parentwidth
- width of widgetheight
- height of widgetcommand
- the command line to executecloseAction
- action to perform when the shell exits
-
TTerminalWidget
public TTerminalWidget(TWidget parent, int x, int y)
Public constructor spawns a shell.- Parameters:
parent
- parent widgetx
- column relative to parenty
- row relative to parent
-
TTerminalWidget
public TTerminalWidget(TWidget parent, int x, int y, TAction closeAction)
Public constructor spawns a shell.- Parameters:
parent
- parent widgetx
- column relative to parenty
- row relative to parentcloseAction
- action to perform when the shell exits
-
TTerminalWidget
public TTerminalWidget(TWidget parent, int x, int y, int width, int height, TAction closeAction)
Public constructor spawns a shell.- Parameters:
parent
- parent widgetx
- column relative to parenty
- row relative to parentwidth
- width of widgetheight
- height of widgetcloseAction
- action to perform when the shell exits
-
-
Method Detail
-
onResize
public void onResize(TResizeEvent resize)
Handle window/screen resize events.- Overrides:
onResize
in classTScrollableWidget
- Parameters:
resize
- resize event
-
onKeypress
public void onKeypress(TKeypressEvent keypress)
Handle keystrokes.- Overrides:
onKeypress
in classTWidget
- Parameters:
keypress
- keystroke event
-
onMouseDown
public void onMouseDown(TMouseEvent mouse)
Handle mouse press events.- Overrides:
onMouseDown
in classTWidget
- Parameters:
mouse
- mouse button press event
-
onMouseUp
public void onMouseUp(TMouseEvent mouse)
Handle mouse release events.
-
onMouseMotion
public void onMouseMotion(TMouseEvent mouse)
Handle mouse motion events.- Overrides:
onMouseMotion
in classTWidget
- Parameters:
mouse
- mouse motion event
-
onCommand
public void onCommand(TCommandEvent command)
Handle posted command events.
-
setVerticalValue
public void setVerticalValue(int value)
Set current value of the vertical scroll.- Specified by:
setVerticalValue
in interfaceScrollable
- Overrides:
setVerticalValue
in classTScrollableWidget
- Parameters:
value
- the new scroll value
-
verticalDecrement
public void verticalDecrement()
Perform a small step change up.- Specified by:
verticalDecrement
in interfaceScrollable
- Overrides:
verticalDecrement
in classTScrollableWidget
-
verticalIncrement
public void verticalIncrement()
Perform a small step change down.- Specified by:
verticalIncrement
in interfaceScrollable
- Overrides:
verticalIncrement
in classTScrollableWidget
-
bigVerticalDecrement
public void bigVerticalDecrement()
Perform a big step change up.- Specified by:
bigVerticalDecrement
in interfaceScrollable
- Overrides:
bigVerticalDecrement
in classTScrollableWidget
-
bigVerticalIncrement
public void bigVerticalIncrement()
Perform a big step change down.- Specified by:
bigVerticalIncrement
in interfaceScrollable
- Overrides:
bigVerticalIncrement
in classTScrollableWidget
-
toTop
public void toTop()
Go to the top edge of the vertical scroller.- Specified by:
toTop
in interfaceScrollable
- Overrides:
toTop
in classTScrollableWidget
-
toBottom
public void toBottom()
Go to the bottom edge of the vertical scroller.- Specified by:
toBottom
in interfaceScrollable
- Overrides:
toBottom
in classTScrollableWidget
-
reflowData
public void reflowData()
Resize scrollbars for a new width/height.- Overrides:
reflowData
in classTScrollableWidget
-
setDirty
public void setDirty()
Set the dirty flag.
-
getTitle
public java.lang.String getTitle()
Get the desired window title.- Returns:
- the title
-
getCommandLine
public java.lang.String[] getCommandLine()
Get the full command line that spawned the shell.- Returns:
- the command line
-
hasHiddenMouse
public boolean hasHiddenMouse()
Returns true if this widget does not want the application-wide mouse cursor drawn over it.- Returns:
- true if this widget does not want the application-wide mouse cursor drawn over it
-
isPixelMouse
public boolean isPixelMouse()
Check if per-pixel mouse events are requested.- Overrides:
isPixelMouse
in classTWidget
- Returns:
- true if per-pixel mouse events are requested
-
isReading
public boolean isReading()
See if the terminal is still running.- Returns:
- if true, we are still connected to / reading from the remote side
-
getPid
public long getPid()
Get the PID of the child process.- Returns:
- the pid, or -1 if it cannot be determined
-
signalShellChildProcess
public void signalShellChildProcess(int signal)
Send a signal to the the child of the 'script' or 'ptypipe' process used on POSIX. This may or may not work.- Parameters:
signal
- the signal number
-
signalShellChildProcess
public void signalShellChildProcess(java.lang.String signal)
Send a signal to the the child of the 'script' or 'ptypipe' process used on POSIX. This may or may not work.- Parameters:
signal
- the signal name
-
onShellExit
public void onShellExit()
Hook for subclasses to be notified of the shell termination.
-
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
-
getExitValue
public int getExitValue()
Get the exit value for the emulator.- Returns:
- exit value
-
getScrollbackBuffer
public final java.util.List<DisplayLine> getScrollbackBuffer()
Get the scrollback buffer from the emulator.- Returns:
- the scrollback buffer, all the lines that have scrolled off screen
-
getDisplayBuffer
public final java.util.List<DisplayLine> getDisplayBuffer()
Get the display buffer from the emulator.- Returns:
- the display buffer, the lines that are on the visible screen
-
writeSessionAsText
public void writeSessionAsText(java.io.Writer writer) throws java.io.IOException
Write the entire session (scrollback and display buffers) as plain text to a writer.- Parameters:
writer
- the output writer- Throws:
java.io.IOException
- of a java.io operation throws
-
writeSessionAsHtml
public void writeSessionAsHtml(java.io.Writer writer) throws java.io.IOException
Write the entire session (scrollback and display buffers) as colorized HTML to a writer. This method does not write the HTML header/body tags.- Parameters:
writer
- the output writer- Throws:
java.io.IOException
- of a java.io operation throws
-
displayChanged
public void displayChanged()
Called by emulator when fresh data has come in.- Specified by:
displayChanged
in interfaceDisplayListener
-
getDisplayWidth
public int getDisplayWidth()
Function to call to obtain the display width.- Specified by:
getDisplayWidth
in interfaceDisplayListener
- Returns:
- the number of columns in the display
-
getDisplayHeight
public int getDisplayHeight()
Function to call to obtain the display height.- Specified by:
getDisplayHeight
in interfaceDisplayListener
- Returns:
- the number of rows in the display
-
isEditMenuCut
public boolean isEditMenuCut()
Check if the cut menu item should be enabled.- Specified by:
isEditMenuCut
in interfaceEditMenuUser
- Returns:
- true if the cut menu item should be enabled
-
isEditMenuCopy
public boolean isEditMenuCopy()
Check if the copy menu item should be enabled.- Specified by:
isEditMenuCopy
in interfaceEditMenuUser
- Returns:
- true if the copy menu item should be enabled
-
isEditMenuPaste
public boolean isEditMenuPaste()
Check if the paste menu item should be enabled.- Specified by:
isEditMenuPaste
in interfaceEditMenuUser
- Returns:
- true if the paste menu item should be enabled
-
isEditMenuClear
public boolean isEditMenuClear()
Check if the clear menu item should be enabled.- Specified by:
isEditMenuClear
in interfaceEditMenuUser
- Returns:
- true if the clear menu item should be enabled
-
-