InputProvider
, IOSafeTerminal
, Terminal
, ImageObserver
, MenuContainer
, Closeable
, Serializable
, AutoCloseable
public class ScrollingSwingTerminal extends JComponent implements IOSafeTerminal
SwingTerminal
with a scrollbar, effectively implementing a
pseudo-terminal with scrollback history. You can choose the same parameters are for SwingTerminal
, they are
forwarded, this class mostly deals with linking the SwingTerminal
with the scrollbar and having them update
each other.Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Container.AccessibleAWTContainer
JComponent.AccessibleJComponent
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Constructor | Description |
---|---|
ScrollingSwingTerminal() |
Creates a new
ScrollingSwingTerminal with all default options |
ScrollingSwingTerminal(TerminalEmulatorDeviceConfiguration deviceConfiguration,
SwingTerminalFontConfiguration fontConfiguration,
TerminalEmulatorColorConfiguration colorConfiguration) |
Creates a new
ScrollingSwingTerminal with customizable settings. |
Modifier and Type | Method | Description |
---|---|---|
void |
addInput(KeyStroke keyStroke) |
Takes a KeyStroke and puts it on the input queue of the terminal emulator.
|
void |
addResizeListener(TerminalResizeListener listener) |
Adds a
TerminalResizeListener to be called when the terminal has changed size. |
void |
bell() |
Prints 0x7 to the terminal, which will make the terminal (emulator) ring a bell (or more likely beep).
|
void |
clearScreen() |
Removes all the characters, colors and graphics from the screen and leaves you with a big empty space.
|
void |
close() |
Closes the terminal, if applicable.
|
void |
disableSGR(SGR sgr) |
Deactivates an
SGR (Selected Graphic Rendition) code which has previously been activated through
enableSGR(..) . |
void |
enableSGR(SGR sgr) |
Activates an
SGR (Selected Graphic Rendition) code. |
byte[] |
enquireTerminal(int timeout,
TimeUnit timeoutUnit) |
Retrieves optional information from the terminal by printing the ENQ (\u005) character.
|
void |
enterPrivateMode() |
Calling this method will, where supported, give your terminal a private area to use, separate from what was there
before.
|
void |
exitPrivateMode() |
If you have previously entered private mode, this method will exit this and, depending on implementation, maybe
restore what the terminal looked like before private mode was entered.
|
void |
flush() |
Calls
flush() on the underlying OutputStream object, or whatever other implementation this
terminal is built around. |
TerminalPosition |
getCursorPosition() |
Returns the position of the cursor, as reported by the terminal.
|
TerminalSize |
getTerminalSize() |
Returns the size of the terminal, expressed as a
TerminalSize object. |
TextGraphics |
newTextGraphics() |
Creates a new TextGraphics object that uses this Terminal directly when outputting.
|
KeyStroke |
pollInput() |
Returns the next
Key off the input queue or null if there is no more input events available. |
void |
putCharacter(char c) |
Prints one character to the terminal at the current cursor location.
|
KeyStroke |
readInput() |
Returns the next
Key off the input queue or blocks until one is available. |
void |
removeResizeListener(TerminalResizeListener listener) |
Removes a
TerminalResizeListener from the list of listeners to be notified when the terminal has changed
size |
void |
resetColorAndSGR() |
Removes all currently active SGR codes and sets foreground and background colors back to default.
|
void |
setBackgroundColor(TextColor color) |
Changes the background color for all the following characters put to the terminal.
|
void |
setCursorPosition(int x,
int y) |
Moves the text cursor to a new location on the terminal.
|
void |
setCursorPosition(TerminalPosition position) |
Same as calling
setCursorPosition(position.getColumn(), position.getRow()) |
void |
setCursorVisible(boolean visible) |
Hides or shows the text cursor, but not all terminal (-emulators) supports this.
|
void |
setForegroundColor(TextColor color) |
Changes the foreground color for all the following characters put to the terminal.
|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUI, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getWidth, getVisibleRect, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
public ScrollingSwingTerminal()
ScrollingSwingTerminal
with all default optionspublic ScrollingSwingTerminal(TerminalEmulatorDeviceConfiguration deviceConfiguration, SwingTerminalFontConfiguration fontConfiguration, TerminalEmulatorColorConfiguration colorConfiguration)
ScrollingSwingTerminal
with customizable settings.deviceConfiguration
- How to configure the terminal virtual devicefontConfiguration
- What kind of fonts to usecolorConfiguration
- Which color schema to use for ANSI colorspublic void addInput(KeyStroke keyStroke)
keyStroke
- Key stroke input event to put on the queuepublic KeyStroke pollInput()
InputProvider
Key
off the input queue or null if there is no more input events available. Note, this
method call is not blocking, it returns null immediately if there is nothing on the input stream.pollInput
in interface InputProvider
pollInput
in interface IOSafeTerminal
public KeyStroke readInput()
InputProvider
Key
off the input queue or blocks until one is available. NOTE: In previous
versions of Lanterna, this method was not blocking. From lanterna 3, it is blocking and you can call
pollInput()
for the non-blocking version.readInput
in interface InputProvider
readInput
in interface IOSafeTerminal
public void enterPrivateMode()
Terminal
enterPrivateMode
in interface IOSafeTerminal
enterPrivateMode
in interface Terminal
public void exitPrivateMode()
Terminal
exitPrivateMode
in interface IOSafeTerminal
exitPrivateMode
in interface Terminal
public void clearScreen()
Terminal
moveCursor
next. Some terminal implementations doesn't reset color and modifier state so it's also good
practise to call resetColorAndSGR()
after this.clearScreen
in interface IOSafeTerminal
clearScreen
in interface Terminal
public void setCursorPosition(int x, int y)
Terminal
setCursorPosition
in interface IOSafeTerminal
setCursorPosition
in interface Terminal
x
- The 0-indexed column to place the cursor aty
- The 0-indexed row to place the cursor atpublic void setCursorPosition(TerminalPosition position)
Terminal
setCursorPosition(position.getColumn(), position.getRow())
setCursorPosition
in interface IOSafeTerminal
setCursorPosition
in interface Terminal
position
- Position to place the cursor atpublic TerminalPosition getCursorPosition()
Terminal
getCursorPosition
in interface IOSafeTerminal
getCursorPosition
in interface Terminal
public void setCursorVisible(boolean visible)
Terminal
setCursorVisible
in interface IOSafeTerminal
setCursorVisible
in interface Terminal
visible
- Hides the text cursor if false
and shows it if true
public void putCharacter(char c)
Terminal
putCharacter
will print out a text string without the need
to reposition the text cursor. If you reach the end of the line while putting characters using this method, you
can expect the text cursor to move to the beginning of the next line.
You can output CJK (Chinese, Japanese, Korean) characters (as well as other regional scripts) but remember that
the terminal that the user is using might not have the required font to render it. Also worth noticing is that
CJK (and some others) characters tend to take up 2 columns per character, simply because they are a square in
their construction as opposed to the somewhat rectangular shape we fit latin characters in. As it's very
difficult to create a monospace font for CJK with a 2:1 height-width proportion, it seems like the implementers
back in the days simply gave up and made each character take 2 column. It causes issues for the random terminal
programmer because you can't really trust 1 character = 1 column, but I suppose it's "しょうがない".
If you try to print non-printable control characters, the terminal is likely to ignore them (all Terminal
implementations bundled with Lanterna will).
putCharacter
in interface IOSafeTerminal
putCharacter
in interface Terminal
c
- Character to place on the terminalpublic TextGraphics newTextGraphics()
Terminal
.flush()
after any operation, so you'll need to do that on your own.newTextGraphics
in interface Terminal
public void enableSGR(SGR sgr)
Terminal
SGR
(Selected Graphic Rendition) code. This code modifies a state inside the terminal
that will apply to all characters written afterwards, such as bold, italic, blinking code and so on.enableSGR
in interface IOSafeTerminal
enableSGR
in interface Terminal
sgr
- SGR code to applySGR
,
http://www.vt100.net/docs/vt510-rm/SGRpublic void disableSGR(SGR sgr)
Terminal
SGR
(Selected Graphic Rendition) code which has previously been activated through
enableSGR(..)
.disableSGR
in interface IOSafeTerminal
disableSGR
in interface Terminal
sgr
- SGR code to applySGR
,
http://www.vt100.net/docs/vt510-rm/SGRpublic void resetColorAndSGR()
Terminal
resetColorAndSGR
in interface IOSafeTerminal
resetColorAndSGR
in interface Terminal
SGR
,
http://www.vt100.net/docs/vt510-rm/SGRpublic void setForegroundColor(TextColor color)
Terminal
This overload is using the TextColor class to define a color, which is a layer of abstraction above the three different color formats supported (ANSI, indexed and RGB). The other setForegroundColor(..) overloads gives you direct access to set one of those three.
Note to implementers of this interface, just make this method call color.applyAsForeground(this);
setForegroundColor
in interface IOSafeTerminal
setForegroundColor
in interface Terminal
color
- Color to use for foregroundpublic void setBackgroundColor(TextColor color)
Terminal
This overload is using the TextColor class to define a color, which is a layer of abstraction above the three different color formats supported (ANSI, indexed and RGB). The other setBackgroundColor(..) overloads gives you direct access to set one of those three.
Note to implementers of this interface, just make this method call color.applyAsBackground(this);
setBackgroundColor
in interface IOSafeTerminal
setBackgroundColor
in interface Terminal
color
- Color to use for the backgroundpublic TerminalSize getTerminalSize()
Terminal
TerminalSize
object. Please bear in mind that depending
on the Terminal
implementation, this may or may not be accurate. See the implementing classes for more
information. Most commonly, calling getTerminalSize() will involve some kind of hack to retrieve the size of the
terminal, like moving the cursor to position 5000x5000 and then read back the location, unless the terminal
implementation has a more smooth way of getting this data. Keep this in mind and see if you can avoid calling
this method too often. There is a helper class, SimpleTerminalResizeListener, that you can use to cache the size
and update it only when resize events are received (which depends on if a resize is detectable, which they are not
on all platforms).getTerminalSize
in interface IOSafeTerminal
getTerminalSize
in interface Terminal
public byte[] enquireTerminal(int timeout, TimeUnit timeoutUnit)
Terminal
enquireTerminal
in interface IOSafeTerminal
enquireTerminal
in interface Terminal
timeout
- How long to wait for the talk-back message, if there's nothing immediately available on the input
stream, you should probably set this to a somewhat small value to prevent unnecessary blockage on the input stream
but large enough to accommodate a round-trip to the user's terminal (~300 ms if you are connection across the globe).timeoutUnit
- What unit to use when interpreting the timeout
parameterpublic void bell()
Terminal
bell
in interface IOSafeTerminal
bell
in interface Terminal
public void flush()
Terminal
flush()
on the underlying OutputStream
object, or whatever other implementation this
terminal is built around. Some implementing classes of this interface (like SwingTerminal) doesn't do anything
as it doesn't really apply to them.flush
in interface IOSafeTerminal
flush
in interface Terminal
public void close()
Terminal
close
in interface AutoCloseable
close
in interface Closeable
close
in interface IOSafeTerminal
close
in interface Terminal
public void addResizeListener(TerminalResizeListener listener)
Terminal
TerminalResizeListener
to be called when the terminal has changed size. There is no guarantee that
this listener will really be invoked when the terminal has changed size, at all depends on the terminal emulator
implementation. Normally on Unix systems the WINCH signal will be sent to the process and lanterna can intercept
this.
There are no guarantees on what thread the call will be made on, so please be careful with what kind of operation you perform in this callback. You should probably not take too long to return.
addResizeListener
in interface Terminal
listener
- Listener object to be called when the terminal has been changedTerminalResizeListener
public void removeResizeListener(TerminalResizeListener listener)
Terminal
TerminalResizeListener
from the list of listeners to be notified when the terminal has changed
sizeremoveResizeListener
in interface Terminal
listener
- Listener object to removeTerminalResizeListener
Copyright © 2020. All rights reserved.