Module com.googlecode.lanterna
Package com.googlecode.lanterna.terminal
Class DefaultTerminalFactory
java.lang.Object
com.googlecode.lanterna.terminal.DefaultTerminalFactory
- All Implemented Interfaces:
TerminalFactory
This TerminalFactory implementation uses a simple auto-detection mechanism for figuring out which terminal
implementation to create based on characteristics of the system the program is running on.
Note that for all systems with a graphical environment present, the SwingTerminalFrame will be chosen. You can suppress this by calling setForceTextTerminal(true) on this factory.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final EnumSet
<TerminalEmulatorAutoCloseTrigger> private boolean
private final Charset
private static final Charset
private static final InputStream
private static final OutputStream
private AWTTerminalFontConfiguration
private boolean
private boolean
private TerminalSize
private final InputStream
private int
private MouseCaptureMode
private final OutputStream
private boolean
private int
private String
private UnixLikeTerminal.CtrlCBehaviour
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new DefaultTerminalFactory with all properties set to their defaultsDefaultTerminalFactory
(OutputStream outputStream, InputStream inputStream, Charset charset) Creates a new DefaultTerminalFactory with I/O and character set options customisable. -
Method Summary
Modifier and TypeMethodDescriptionaddTerminalEmulatorFrameAutoCloseTrigger
(TerminalEmulatorAutoCloseTrigger autoCloseTrigger) Adds an auto-close trigger to use on created SwingTerminalFrames created by this factoryprivate Terminal
createCygwinTerminal
(OutputStream outputStream, InputStream inputStream, Charset charset) Instantiates a Terminal according to the factory implementation with the exception thatpreferTerminalEmulator
is always ignored.Create aTerminal
and immediately wrap it up in aTerminalScreen
Creates a new TelnetTerminal Note: a telnetPort should have been set with setTelnetPort(), otherwise creation of TelnetTerminal will most likely fail.Instantiates a Terminal according to the factory implementation.Creates a new terminal emulator window which will be either Swing-based or AWT-based depending on what is available on the systemprivate Terminal
createUnixTerminal
(OutputStream outputStream, InputStream inputStream, Charset charset) private Terminal
private boolean
hasSwing()
private static boolean
private boolean
private static boolean
Detects whether the running platform is Windows* by looking at the operating system name system propertyprivate static boolean
isTerminalCheckJDK22
(Console console) private void
makeWindowVisible
(Terminal terminal) setAutoOpenTerminalEmulatorWindow
(boolean autoOpenTerminalFrame) Controls whether a SwingTerminalFrame shall be automatically shown (.setVisible(true)) immediately after creation.setForceAWTOverSwing
(boolean forceAWTOverSwing) Normally when a graphical terminal emulator is created by the factory, it will create aSwingTerminalFrame
unless Swing is not present in the system.setForceTextTerminal
(boolean forceTextTerminal) Controls whether a text-based Terminal shall be created even if the system supports a graphical environmentsetInitialTerminalSize
(TerminalSize initialTerminalSize) Sets a hint to the TerminalFactory of what size to use when creating the terminal.setInputTimeout
(int inputTimeout) Only for StreamBasedTerminals: After seeing e.g.setMouseCaptureMode
(MouseCaptureMode mouseCaptureMode) Sets the mouse capture mode the terminal should use.setPreferTerminalEmulator
(boolean preferTerminalEmulator) Controls whether a Swing or AWT TerminalFrame shall be preferred if the system has both a Console and a graphical environmentsetTelnetPort
(int telnetPort) Primarily for debugging applications with mouse interactions: If no Console is available (e.g.setTerminalEmulatorColorConfiguration
(TerminalEmulatorColorConfiguration colorConfiguration) Sets the color configuration to use on created SwingTerminalFrames created by this factorysetTerminalEmulatorDeviceConfiguration
(TerminalEmulatorDeviceConfiguration deviceConfiguration) Sets the device configuration to use on created SwingTerminalFrames created by this factorysetTerminalEmulatorFontConfiguration
(AWTTerminalFontConfiguration fontConfiguration) Sets the font configuration to use on created SwingTerminalFrames created by this factorysetTerminalEmulatorFrameAutoCloseTrigger
(TerminalEmulatorAutoCloseTrigger autoCloseTrigger) Sets the auto-close trigger to use on created SwingTerminalFrames created by this factory.setTerminalEmulatorTitle
(String title) Sets the title to use on created SwingTerminalFrames created by this factorysetUnixTerminalCtrlCBehaviour
(UnixLikeTerminal.CtrlCBehaviour unixTerminalCtrlCBehaviour) Sets the default CTRL-C behavior to use for allUnixTerminal
objects created by this factory.
-
Field Details
-
DEFAULT_OUTPUT_STREAM
-
DEFAULT_INPUT_STREAM
-
DEFAULT_CHARSET
-
outputStream
-
inputStream
-
charset
-
initialTerminalSize
-
forceTextTerminal
private boolean forceTextTerminal -
preferTerminalEmulator
private boolean preferTerminalEmulator -
forceAWTOverSwing
private boolean forceAWTOverSwing -
telnetPort
private int telnetPort -
inputTimeout
private int inputTimeout -
title
-
autoOpenTerminalFrame
private boolean autoOpenTerminalFrame -
autoCloseTriggers
-
colorConfiguration
-
deviceConfiguration
-
fontConfiguration
-
mouseCaptureMode
-
unixTerminalCtrlCBehaviour
-
-
Constructor Details
-
DefaultTerminalFactory
public DefaultTerminalFactory()Creates a new DefaultTerminalFactory with all properties set to their defaults -
DefaultTerminalFactory
Creates a new DefaultTerminalFactory with I/O and character set options customisable.- Parameters:
outputStream
- Output stream to use for text-based Terminal implementationsinputStream
- Input stream to use for text-based Terminal implementationscharset
- Character set to assume the client is using
-
-
Method Details
-
createTerminal
Description copied from interface:TerminalFactory
Instantiates a Terminal according to the factory implementation.- Specified by:
createTerminal
in interfaceTerminalFactory
- Returns:
- Terminal implementation
- Throws:
IOException
- If there was an I/O error with the underlying input/output system
-
createHeadlessTerminal
Instantiates a Terminal according to the factory implementation with the exception thatpreferTerminalEmulator
is always ignored. You may want to use this method when using tools that rely on AOT compilation such as Graal native-image to ensure AWT/Swing code paths are not hit.- Returns:
- Terminal implementation
- Throws:
IOException
- If there was an I/O error with the underlying input/output system
-
createTerminalEmulator
Creates a new terminal emulator window which will be either Swing-based or AWT-based depending on what is available on the system- Returns:
- New terminal emulator exposed as a
Terminal
interface
-
createAWTTerminal
-
createSwingTerminal
-
createTelnetTerminal
Creates a new TelnetTerminal Note: a telnetPort should have been set with setTelnetPort(), otherwise creation of TelnetTerminal will most likely fail.- Returns:
- New terminal emulator exposed as a
Terminal
interface
-
isAwtHeadless
private boolean isAwtHeadless() -
hasSwing
private boolean hasSwing() -
makeWindowVisible
-
setInitialTerminalSize
Sets a hint to the TerminalFactory of what size to use when creating the terminal. Most terminals are not created on request but for example the SwingTerminal and SwingTerminalFrame are and this value will be passed down on creation.- Parameters:
initialTerminalSize
- Size (in rows and columns) of the newly created terminal- Returns:
- Reference to itself, so multiple .set-calls can be chained
-
setForceTextTerminal
Controls whether a text-based Terminal shall be created even if the system supports a graphical environment- Parameters:
forceTextTerminal
- If true, will always create a text-based Terminal- Returns:
- Reference to itself, so multiple .set-calls can be chained
-
setPreferTerminalEmulator
Controls whether a Swing or AWT TerminalFrame shall be preferred if the system has both a Console and a graphical environment- Parameters:
preferTerminalEmulator
- If true, will prefer creating a graphical terminal emulator- Returns:
- Reference to itself, so multiple .set-calls can be chained
-
setUnixTerminalCtrlCBehaviour
public DefaultTerminalFactory setUnixTerminalCtrlCBehaviour(UnixLikeTerminal.CtrlCBehaviour unixTerminalCtrlCBehaviour) Sets the default CTRL-C behavior to use for allUnixTerminal
objects created by this factory. You can use this to tell Lanterna to trap CTRL-C instead of exiting the application. Non-UNIX terminals are not affected by this.- Parameters:
unixTerminalCtrlCBehaviour
- CTRL-C behavior to use forUnixTerminal
:s- Returns:
- Reference to itself, so multiple .set-calls can be chained
-
setTelnetPort
Primarily for debugging applications with mouse interactions: If no Console is available (e.g. from within an IDE), then fall back to TelnetTerminal on specified port. If both a non-null mouseCapture mode and a positive telnetPort are specified, then as long as Swing/AWT Terminal emulators do not support MouseCapturing, a TelnetTerminal will be preferred over the graphical Emulators.- Parameters:
telnetPort
- the TCP/IP port on which to eventually wait for a connection. A value less or equal 0 disables creation of a TelnetTerminal. Note, that ports less than 1024 typically require system privileges to listen on.- Returns:
- Reference to itself, so multiple .set-calls can be chained
-
setInputTimeout
Only for StreamBasedTerminals: After seeing e.g. an Escape (but nothing else yet), wait up to the specified number of time units for more bytes to make up a complete sequence. This may be necessary on slow channels, or if some client terminal sends each byte of a sequence in its own TCP packet.- Parameters:
inputTimeout
- how long to wait for possible completions of sequences. units are of a 1/4 second, so e.g. 12 would wait up to 3 seconds.- Returns:
- Reference to itself, so multiple .set-calls can be chained
-
setForceAWTOverSwing
Normally when a graphical terminal emulator is created by the factory, it will create aSwingTerminalFrame
unless Swing is not present in the system. Setting this property totrue
will make it create anAWTTerminalFrame
even if Swing is present- Parameters:
forceAWTOverSwing
- Iftrue
, will always create anAWTTerminalFrame
over aSwingTerminalFrame
if asked to create a graphical terminal emulator- Returns:
- Reference to itself, so multiple .set-calls can be chained
-
setAutoOpenTerminalEmulatorWindow
Controls whether a SwingTerminalFrame shall be automatically shown (.setVisible(true)) immediately after creation. Iffalse
, you will manually need to call.setVisible(true)
on the JFrame to actually see the terminal window. Default for this value istrue
.- Parameters:
autoOpenTerminalFrame
- Automatically open SwingTerminalFrame after creation- Returns:
- Itself
-
setTerminalEmulatorTitle
Sets the title to use on created SwingTerminalFrames created by this factory- Parameters:
title
- Title to use on created SwingTerminalFrames created by this factory- Returns:
- Reference to itself, so multiple .set-calls can be chained
-
setTerminalEmulatorFrameAutoCloseTrigger
public DefaultTerminalFactory setTerminalEmulatorFrameAutoCloseTrigger(TerminalEmulatorAutoCloseTrigger autoCloseTrigger) Sets the auto-close trigger to use on created SwingTerminalFrames created by this factory. This will reset any previous triggers. If called withnull
, all triggers are cleared.- Parameters:
autoCloseTrigger
- Auto-close trigger to use on created SwingTerminalFrames created by this factory, ornull
to clear all existing triggers- Returns:
- Reference to itself, so multiple .set-calls can be chained
-
addTerminalEmulatorFrameAutoCloseTrigger
public DefaultTerminalFactory addTerminalEmulatorFrameAutoCloseTrigger(TerminalEmulatorAutoCloseTrigger autoCloseTrigger) Adds an auto-close trigger to use on created SwingTerminalFrames created by this factory- Parameters:
autoCloseTrigger
- Auto-close trigger to add to the created SwingTerminalFrames created by this factory- Returns:
- Reference to itself, so multiple calls can be chained
-
setTerminalEmulatorColorConfiguration
public DefaultTerminalFactory setTerminalEmulatorColorConfiguration(TerminalEmulatorColorConfiguration colorConfiguration) Sets the color configuration to use on created SwingTerminalFrames created by this factory- Parameters:
colorConfiguration
- Color configuration to use on created SwingTerminalFrames created by this factory- Returns:
- Reference to itself, so multiple .set-calls can be chained
-
setTerminalEmulatorDeviceConfiguration
public DefaultTerminalFactory setTerminalEmulatorDeviceConfiguration(TerminalEmulatorDeviceConfiguration deviceConfiguration) Sets the device configuration to use on created SwingTerminalFrames created by this factory- Parameters:
deviceConfiguration
- Device configuration to use on created SwingTerminalFrames created by this factory- Returns:
- Reference to itself, so multiple .set-calls can be chained
-
setTerminalEmulatorFontConfiguration
public DefaultTerminalFactory setTerminalEmulatorFontConfiguration(AWTTerminalFontConfiguration fontConfiguration) Sets the font configuration to use on created SwingTerminalFrames created by this factory- Parameters:
fontConfiguration
- Font configuration to use on created SwingTerminalFrames created by this factory- Returns:
- Reference to itself, so multiple .set-calls can be chained
-
setMouseCaptureMode
Sets the mouse capture mode the terminal should use. Please note that this is an extension which isn't widely supported! If both a non-null mouseCapture mode and a positive telnetPort are specified, then as long as Swing/AWT Terminal emulators do not support MouseCapturing, a TelnetTerminal will be preferred over the graphical Emulators.- Parameters:
mouseCaptureMode
- Capture mode for mouse interactions- Returns:
- Itself
-
createScreen
Create aTerminal
and immediately wrap it up in aTerminalScreen
- Returns:
- New
TerminalScreen
created with a terminal fromcreateTerminal()
- Throws:
IOException
- In case there was an I/O error
-
createWindowsTerminal
- Throws:
IOException
-
createCygwinTerminal
private Terminal createCygwinTerminal(OutputStream outputStream, InputStream inputStream, Charset charset) throws IOException - Throws:
IOException
-
createUnixTerminal
private Terminal createUnixTerminal(OutputStream outputStream, InputStream inputStream, Charset charset) throws IOException - Throws:
IOException
-
isOperatingSystemWindows
private static boolean isOperatingSystemWindows()Detects whether the running platform is Windows* by looking at the operating system name system property -
hasTerminal
private static boolean hasTerminal() -
isTerminalCheckJDK22
-