Module com.googlecode.lanterna
Package com.googlecode.lanterna.terminal
Class DefaultTerminalFactory
- java.lang.Object
-
- com.googlecode.lanterna.terminal.DefaultTerminalFactory
-
- All Implemented Interfaces:
TerminalFactory
public class DefaultTerminalFactory extends java.lang.Object implements 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
Fields Modifier and Type Field Description private java.util.EnumSet<TerminalEmulatorAutoCloseTrigger>
autoCloseTriggers
private boolean
autoOpenTerminalFrame
private java.nio.charset.Charset
charset
private TerminalEmulatorColorConfiguration
colorConfiguration
private static java.nio.charset.Charset
DEFAULT_CHARSET
private static java.io.InputStream
DEFAULT_INPUT_STREAM
private static java.io.OutputStream
DEFAULT_OUTPUT_STREAM
private TerminalEmulatorDeviceConfiguration
deviceConfiguration
private AWTTerminalFontConfiguration
fontConfiguration
private boolean
forceAWTOverSwing
private boolean
forceTextTerminal
private TerminalSize
initialTerminalSize
private java.io.InputStream
inputStream
private int
inputTimeout
private MouseCaptureMode
mouseCaptureMode
private java.io.OutputStream
outputStream
private boolean
preferTerminalEmulator
private int
telnetPort
private java.lang.String
title
private UnixLikeTerminal.CtrlCBehaviour
unixTerminalCtrlCBehaviour
-
Constructor Summary
Constructors Constructor Description DefaultTerminalFactory()
Creates a new DefaultTerminalFactory with all properties set to their defaultsDefaultTerminalFactory(java.io.OutputStream outputStream, java.io.InputStream inputStream, java.nio.charset.Charset charset)
Creates a new DefaultTerminalFactory with I/O and character set options customisable.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description DefaultTerminalFactory
addTerminalEmulatorFrameAutoCloseTrigger(TerminalEmulatorAutoCloseTrigger autoCloseTrigger)
Adds an auto-close trigger to use on created SwingTerminalFrames created by this factoryAWTTerminalFrame
createAWTTerminal()
private Terminal
createCygwinTerminal(java.io.OutputStream outputStream, java.io.InputStream inputStream, java.nio.charset.Charset charset)
Terminal
createHeadlessTerminal()
Instantiates a Terminal according to the factory implementation with the exception thatpreferTerminalEmulator
is always ignored.TerminalScreen
createScreen()
Create aTerminal
and immediately wrap it up in aTerminalScreen
SwingTerminalFrame
createSwingTerminal()
TelnetTerminal
createTelnetTerminal()
Creates a new TelnetTerminal Note: a telnetPort should have been set with setTelnetPort(), otherwise creation of TelnetTerminal will most likely fail.Terminal
createTerminal()
Instantiates a Terminal according to the factory implementation.Terminal
createTerminalEmulator()
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(java.io.OutputStream outputStream, java.io.InputStream inputStream, java.nio.charset.Charset charset)
private Terminal
createWindowsTerminal()
private boolean
hasSwing()
private boolean
isAwtHeadless()
private static boolean
isOperatingSystemWindows()
Detects whether the running platform is Windows* by looking at the operating system name system propertyprivate void
makeWindowVisible(Terminal terminal)
DefaultTerminalFactory
setAutoOpenTerminalEmulatorWindow(boolean autoOpenTerminalFrame)
Controls whether a SwingTerminalFrame shall be automatically shown (.setVisible(true)) immediately after creation.DefaultTerminalFactory
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.DefaultTerminalFactory
setForceTextTerminal(boolean forceTextTerminal)
Controls whether a text-based Terminal shall be created even if the system supports a graphical environmentDefaultTerminalFactory
setInitialTerminalSize(TerminalSize initialTerminalSize)
Sets a hint to the TerminalFactory of what size to use when creating the terminal.DefaultTerminalFactory
setInputTimeout(int inputTimeout)
Only for StreamBasedTerminals: After seeing e.g.DefaultTerminalFactory
setMouseCaptureMode(MouseCaptureMode mouseCaptureMode)
Sets the mouse capture mode the terminal should use.DefaultTerminalFactory
setPreferTerminalEmulator(boolean preferTerminalEmulator)
Controls whether a Swing or AWT TerminalFrame shall be preferred if the system has both a Console and a graphical environmentDefaultTerminalFactory
setTelnetPort(int telnetPort)
Primarily for debugging applications with mouse interactions: If no Console is available (e.g.DefaultTerminalFactory
setTerminalEmulatorColorConfiguration(TerminalEmulatorColorConfiguration colorConfiguration)
Sets the color configuration to use on created SwingTerminalFrames created by this factoryDefaultTerminalFactory
setTerminalEmulatorDeviceConfiguration(TerminalEmulatorDeviceConfiguration deviceConfiguration)
Sets the device configuration to use on created SwingTerminalFrames created by this factoryDefaultTerminalFactory
setTerminalEmulatorFontConfiguration(AWTTerminalFontConfiguration fontConfiguration)
Sets the font configuration to use on created SwingTerminalFrames created by this factoryDefaultTerminalFactory
setTerminalEmulatorFrameAutoCloseTrigger(TerminalEmulatorAutoCloseTrigger autoCloseTrigger)
Sets the auto-close trigger to use on created SwingTerminalFrames created by this factory.DefaultTerminalFactory
setTerminalEmulatorTitle(java.lang.String title)
Sets the title to use on created SwingTerminalFrames created by this factoryDefaultTerminalFactory
setUnixTerminalCtrlCBehaviour(UnixLikeTerminal.CtrlCBehaviour unixTerminalCtrlCBehaviour)
Sets the default CTRL-C behavior to use for allUnixTerminal
objects created by this factory.
-
-
-
Field Detail
-
DEFAULT_OUTPUT_STREAM
private static final java.io.OutputStream DEFAULT_OUTPUT_STREAM
-
DEFAULT_INPUT_STREAM
private static final java.io.InputStream DEFAULT_INPUT_STREAM
-
DEFAULT_CHARSET
private static final java.nio.charset.Charset DEFAULT_CHARSET
-
outputStream
private final java.io.OutputStream outputStream
-
inputStream
private final java.io.InputStream inputStream
-
charset
private final java.nio.charset.Charset charset
-
initialTerminalSize
private TerminalSize initialTerminalSize
-
forceTextTerminal
private boolean forceTextTerminal
-
preferTerminalEmulator
private boolean preferTerminalEmulator
-
forceAWTOverSwing
private boolean forceAWTOverSwing
-
telnetPort
private int telnetPort
-
inputTimeout
private int inputTimeout
-
title
private java.lang.String title
-
autoOpenTerminalFrame
private boolean autoOpenTerminalFrame
-
autoCloseTriggers
private final java.util.EnumSet<TerminalEmulatorAutoCloseTrigger> autoCloseTriggers
-
colorConfiguration
private TerminalEmulatorColorConfiguration colorConfiguration
-
deviceConfiguration
private TerminalEmulatorDeviceConfiguration deviceConfiguration
-
fontConfiguration
private AWTTerminalFontConfiguration fontConfiguration
-
mouseCaptureMode
private MouseCaptureMode mouseCaptureMode
-
unixTerminalCtrlCBehaviour
private UnixLikeTerminal.CtrlCBehaviour unixTerminalCtrlCBehaviour
-
-
Constructor Detail
-
DefaultTerminalFactory
public DefaultTerminalFactory()
Creates a new DefaultTerminalFactory with all properties set to their defaults
-
DefaultTerminalFactory
public DefaultTerminalFactory(java.io.OutputStream outputStream, java.io.InputStream inputStream, java.nio.charset.Charset charset)
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 Detail
-
createTerminal
public Terminal createTerminal() throws java.io.IOException
Description copied from interface:TerminalFactory
Instantiates a Terminal according to the factory implementation.- Specified by:
createTerminal
in interfaceTerminalFactory
- Returns:
- Terminal implementation
- Throws:
java.io.IOException
- If there was an I/O error with the underlying input/output system
-
createHeadlessTerminal
public Terminal createHeadlessTerminal() throws java.io.IOException
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:
java.io.IOException
- If there was an I/O error with the underlying input/output system
-
createTerminalEmulator
public Terminal 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
public AWTTerminalFrame createAWTTerminal()
-
createSwingTerminal
public SwingTerminalFrame createSwingTerminal()
-
createTelnetTerminal
public TelnetTerminal 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
private void makeWindowVisible(Terminal terminal)
-
setInitialTerminalSize
public DefaultTerminalFactory setInitialTerminalSize(TerminalSize initialTerminalSize)
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
public DefaultTerminalFactory setForceTextTerminal(boolean forceTextTerminal)
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
public DefaultTerminalFactory setPreferTerminalEmulator(boolean preferTerminalEmulator)
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
public DefaultTerminalFactory setTelnetPort(int telnetPort)
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
public DefaultTerminalFactory setInputTimeout(int inputTimeout)
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
public DefaultTerminalFactory 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. 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
public DefaultTerminalFactory setAutoOpenTerminalEmulatorWindow(boolean autoOpenTerminalFrame)
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
public DefaultTerminalFactory setTerminalEmulatorTitle(java.lang.String title)
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
public DefaultTerminalFactory setMouseCaptureMode(MouseCaptureMode mouseCaptureMode)
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
public TerminalScreen createScreen() throws java.io.IOException
Create aTerminal
and immediately wrap it up in aTerminalScreen
- Returns:
- New
TerminalScreen
created with a terminal fromcreateTerminal()
- Throws:
java.io.IOException
- In case there was an I/O error
-
createWindowsTerminal
private Terminal createWindowsTerminal() throws java.io.IOException
- Throws:
java.io.IOException
-
createCygwinTerminal
private Terminal createCygwinTerminal(java.io.OutputStream outputStream, java.io.InputStream inputStream, java.nio.charset.Charset charset) throws java.io.IOException
- Throws:
java.io.IOException
-
createUnixTerminal
private Terminal createUnixTerminal(java.io.OutputStream outputStream, java.io.InputStream inputStream, java.nio.charset.Charset charset) throws java.io.IOException
- Throws:
java.io.IOException
-
isOperatingSystemWindows
private static boolean isOperatingSystemWindows()
Detects whether the running platform is Windows* by looking at the operating system name system property
-
-