Scrollable
, InputProvider
, ExtendedTerminal
, Terminal
, Closeable
, AutoCloseable
TelnetTerminal
, UnixLikeTerminal
public abstract class ANSITerminal extends StreamBasedTerminal implements ExtendedTerminal
Modifier | Constructor | Description |
---|---|---|
protected |
ANSITerminal(InputStream terminalInput,
OutputStream terminalOutput,
Charset terminalCharset) |
Modifier and Type | Method | Description |
---|---|---|
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 |
deiconify() |
De-iconifies the terminal, which likely means restoring it from minimized state with most window managers
|
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. |
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.
|
protected TerminalSize |
findTerminalSize() |
|
TerminalPosition |
getCursorPosition() |
Returns the position of the cursor, as reported by the terminal.
|
protected KeyDecodingProfile |
getDefaultKeyDecodingProfile() |
This method can be overridden in a custom terminal implementation to change the default key decoders.
|
TerminalSize |
getTerminalSize() |
Returns the size of the terminal, expressed as a
TerminalSize object. |
void |
iconify() |
Iconifies the terminal, this likely means minimizing the window with most window managers
|
void |
maximize() |
Maximizes the terminal, so that it takes up all available space
|
KeyStroke |
pollInput() |
Returns the next
Key off the input queue or null if there is no more input events available. |
void |
popTitle() |
Replaces the terminal title with the top element from the title stack managed by the terminal (the element is
removed from the stack as expected)
|
void |
pushTitle() |
Saves the current window title on a stack managed internally by the terminal.
|
KeyStroke |
readInput() |
Returns the next
Key off the input queue or blocks until one is available. |
void |
resetColorAndSGR() |
Removes all currently active SGR codes and sets foreground and background colors back to default.
|
void |
scrollLines(int firstLine,
int lastLine,
int distance) |
Scroll a range of lines of this Scrollable according to given distance.
|
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.
|
void |
setMouseCaptureMode(MouseCaptureMode mouseCaptureMode) |
Enabled or disables capturing of mouse event.
|
void |
setTerminalSize(int columns,
int rows) |
Attempts to resize the terminal through dtterm extensions "CSI 8 ; rows ; columns ; t".
|
void |
setTitle(String title) |
This methods sets the title of the terminal, which is normally only visible if you are running the application
in a terminal emulator in a graphical environment.
|
void |
unmaximize() |
Restores the terminal back to its previous size, after having been maximized
|
addResizeListener, newTextGraphics, onResized, onResized, removeResizeListener
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addKeyDecodingProfile, bell, enquireTerminal, flush, getCharset, getInputDecoder, putCharacter, translateCharacter, writeToTerminal
addResizeListener, bell, enquireTerminal, flush, newTextGraphics, putCharacter, removeResizeListener
protected ANSITerminal(InputStream terminalInput, OutputStream terminalOutput, Charset terminalCharset)
protected KeyDecodingProfile getDefaultKeyDecodingProfile()
public final TerminalSize getTerminalSize() throws IOException
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 Terminal
IOException
- if there was an I/O error trying to retrieve the size of the terminalprotected TerminalSize findTerminalSize() throws IOException
IOException
public void setTerminalSize(int columns, int rows) throws IOException
ExtendedTerminal
setTerminalSize
in interface ExtendedTerminal
columns
- New size (columns)rows
- New size (rows)IOException
- If the was an underlying I/O errorpublic void setTitle(String title) throws IOException
ExtendedTerminal
setTitle
in interface ExtendedTerminal
title
- Title to set on the terminalIOException
- If the was an underlying I/O errorpublic void setForegroundColor(TextColor color) throws IOException
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 Terminal
color
- Color to use for foregroundIOException
- If there was an underlying I/O errorpublic void setBackgroundColor(TextColor color) throws IOException
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 Terminal
color
- Color to use for the backgroundIOException
- If there was an underlying I/O errorpublic void enableSGR(SGR sgr) throws IOException
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 Terminal
sgr
- SGR code to applyIOException
- If there was an underlying I/O errorSGR
,
http://www.vt100.net/docs/vt510-rm/SGRpublic void disableSGR(SGR sgr) throws IOException
Terminal
SGR
(Selected Graphic Rendition) code which has previously been activated through
enableSGR(..)
.disableSGR
in interface Terminal
sgr
- SGR code to applyIOException
- If there was an underlying I/O errorSGR
,
http://www.vt100.net/docs/vt510-rm/SGRpublic void resetColorAndSGR() throws IOException
Terminal
resetColorAndSGR
in interface Terminal
IOException
- If there was an underlying I/O errorSGR
,
http://www.vt100.net/docs/vt510-rm/SGRpublic void clearScreen() throws IOException
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 Terminal
IOException
- If there was an underlying I/O errorpublic void enterPrivateMode() throws IOException
Terminal
enterPrivateMode
in interface Terminal
IOException
- If there was an underlying I/O errorpublic void exitPrivateMode() throws IOException
Terminal
exitPrivateMode
in interface Terminal
IOException
- If there was an underlying I/O errorpublic void close() throws IOException
Terminal
close
in interface AutoCloseable
close
in interface Closeable
close
in interface Terminal
close
in class StreamBasedTerminal
IOException
- If there was an underlying I/O errorpublic void setCursorPosition(int x, int y) throws IOException
Terminal
setCursorPosition
in interface Terminal
x
- The 0-indexed column to place the cursor aty
- The 0-indexed row to place the cursor atIOException
- If there was an underlying I/O errorpublic void setCursorPosition(TerminalPosition position) throws IOException
Terminal
setCursorPosition(position.getColumn(), position.getRow())
setCursorPosition
in interface Terminal
position
- Position to place the cursor atIOException
- If there was an underlying I/O errorpublic TerminalPosition getCursorPosition() throws IOException
Terminal
getCursorPosition
in interface Terminal
IOException
- In there was an underlying I/O errorpublic void setCursorVisible(boolean visible) throws IOException
Terminal
setCursorVisible
in interface Terminal
visible
- Hides the text cursor if false
and shows it if true
IOException
- If there was an underlying I/O errorpublic KeyStroke readInput() throws IOException
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 class StreamBasedTerminal
IOException
- Propagated error if the underlying stream gave errorspublic KeyStroke pollInput() throws IOException
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 class StreamBasedTerminal
IOException
- Propagated error if the underlying stream gave errorspublic void pushTitle() throws IOException
ExtendedTerminal
pushTitle
in interface ExtendedTerminal
IOException
- If the was an underlying I/O errorpublic void popTitle() throws IOException
ExtendedTerminal
popTitle
in interface ExtendedTerminal
IOException
- If the was an underlying I/O errorpublic void iconify() throws IOException
ExtendedTerminal
iconify
in interface ExtendedTerminal
IOException
- If the was an underlying I/O errorpublic void deiconify() throws IOException
ExtendedTerminal
deiconify
in interface ExtendedTerminal
IOException
- If the was an underlying I/O errorpublic void maximize() throws IOException
ExtendedTerminal
maximize
in interface ExtendedTerminal
IOException
- If the was an underlying I/O errorpublic void unmaximize() throws IOException
ExtendedTerminal
unmaximize
in interface ExtendedTerminal
IOException
- If the was an underlying I/O errorpublic void setMouseCaptureMode(MouseCaptureMode mouseCaptureMode) throws IOException
ExtendedTerminal
setMouseCaptureMode
in interface ExtendedTerminal
mouseCaptureMode
- Which mouse events to capture, pass in null
to disable mouse input capturingIOException
- If the was an underlying I/O errorpublic void scrollLines(int firstLine, int lastLine, int distance) throws IOException
Scrollable
scrollLines
in interface Scrollable
firstLine
- first line of the range to be scrolled (top line is 0)lastLine
- last (inclusive) line of the range to be scrolleddistance
- if > 0: move lines up, else if < 0: move lines down.IOException
- If there was an I/O error when running the operationCopyright © 2020. All rights reserved.