Package org.jline.terminal
Class TerminalBuilder
java.lang.Object
org.jline.terminal.TerminalBuilder
Builder class to create terminals.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Attributes
private int
private Boolean
private Boolean
private Charset
private Boolean
private InputStream
private Boolean
private Boolean
private String
private boolean
private OutputStream
private boolean
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
private Terminal.SignalHandler
private Size
private Boolean
private static final AtomicReference<Terminal>
private TerminalBuilder.SystemOutput
private static final AtomicReference<Terminal>
private String
private static final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionattributes
(Attributes attributes) Attributes to use when creating a non system terminal, i.e.build()
static TerminalBuilder
builder()
Creates a new terminal builder instance.codepage
(int codepage) Deprecated.JLine now writes Unicode output independently from the selected code page.color
(boolean color) private Terminal
doBuild()
dumb
(boolean dumb) Set the encoding to use for reading/writing from the console.Set theCharset
to use for reading/writing from the console.exec
(boolean exec) private static Boolean
getBoolean
(String name, Boolean def) private static Charset
getCodepageCharset
(int codepage) private static String
jansi
(boolean jansi) jna
(boolean jna) private static <S> S
nativeSignals
(boolean nativeSignals) paused
(boolean paused) Initial paused state of the terminal (defaults to false).private static TerminalProvider.Stream
select
(Map<TerminalProvider.Stream, Boolean> system, TerminalProvider.Stream... streams) private TerminalProvider.Stream
select
(Map<TerminalProvider.Stream, Boolean> system, TerminalBuilder.SystemOutput systemOutput) static void
setTerminalOverride
(Terminal terminal) Deprecated.signalHandler
(Terminal.SignalHandler signalHandler) Initial size to use when creating a non system terminal, i.e.streams
(InputStream in, OutputStream out) system
(boolean system) systemOutput
(TerminalBuilder.SystemOutput systemOutput) Indicates which standard stream should be used when displaying to the terminal.static Terminal
terminal()
Returns the default system terminal.
-
Field Details
-
PROP_ENCODING
- See Also:
-
PROP_CODEPAGE
- See Also:
-
PROP_TYPE
- See Also:
-
PROP_PROVIDERS
- See Also:
-
PROP_PROVIDERS_DEFAULT
- See Also:
-
PROP_JNA
- See Also:
-
PROP_JANSI
- See Also:
-
PROP_EXEC
- See Also:
-
PROP_DUMB
- See Also:
-
PROP_DUMB_COLOR
- See Also:
-
PROP_OUTPUT
- See Also:
-
PROP_OUTPUT_OUT
- See Also:
-
PROP_OUTPUT_ERR
- See Also:
-
PROP_OUTPUT_OUT_ERR
- See Also:
-
PROP_OUTPUT_ERR_OUT
- See Also:
-
PROP_NON_BLOCKING_READS
- See Also:
-
PROP_COLOR_DISTANCE
- See Also:
-
PROP_DISABLE_ALTERNATE_CHARSET
- See Also:
-
PROP_FILE_DESCRIPTOR_CREATION_MODE
- See Also:
-
PROP_FILE_DESCRIPTOR_CREATION_MODE_NATIVE
- See Also:
-
PROP_FILE_DESCRIPTOR_CREATION_MODE_REFLECTION
- See Also:
-
PROP_FILE_DESCRIPTOR_CREATION_MODE_DEFAULT
- See Also:
-
SYSTEM_TERMINAL
-
TERMINAL_OVERRIDE
-
name
-
in
-
out
-
type
-
encoding
-
codepage
private int codepage -
system
-
systemOutput
-
jna
-
jansi
-
exec
-
dumb
-
color
-
attributes
-
size
-
nativeSignals
private boolean nativeSignals -
signalHandler
-
paused
private boolean paused -
UTF8_CODE_PAGE
private static final int UTF8_CODE_PAGE- See Also:
-
-
Constructor Details
-
TerminalBuilder
private TerminalBuilder()
-
-
Method Details
-
terminal
Returns the default system terminal. Terminals should be closed properly using theCloseable.close()
method in order to restore the original terminal state.This call is equivalent to:
builder().build()
- Returns:
- the default system terminal
- Throws:
IOException
- if an error occurs
-
builder
Creates a new terminal builder instance.- Returns:
- a builder
-
name
-
streams
-
system
-
systemOutput
Indicates which standard stream should be used when displaying to the terminal. The default is to use the system output stream. Building a system terminal will fail if one of the stream specified is not linked to the controlling terminal.- Parameters:
systemOutput
- The mode to choose the output stream.- Returns:
- The builder.
-
jna
-
jansi
-
exec
-
dumb
-
type
-
color
-
encoding
Set the encoding to use for reading/writing from the console. Ifnull
(the default value), JLine will automatically select aCharset
, usually the default system encoding. However, on some platforms (e.g. Windows) it may use a different one depending on theTerminal
implementation.Use
Terminal.encoding()
to get theCharset
that should be used for aTerminal
.- Parameters:
encoding
- The encoding to use or null to automatically select one- Returns:
- The builder
- Throws:
UnsupportedCharsetException
- If the given encoding is not supported- See Also:
-
encoding
Set theCharset
to use for reading/writing from the console. Ifnull
(the default value), JLine will automatically select aCharset
, usually the default system encoding. However, on some platforms (e.g. Windows) it may use a different one depending on theTerminal
implementation.Use
Terminal.encoding()
to get theCharset
that should be used to read/write from aTerminal
.- Parameters:
encoding
- The encoding to use or null to automatically select one- Returns:
- The builder
- See Also:
-
codepage
Deprecated.JLine now writes Unicode output independently from the selected code page. Using this option will only make it emulate the selected code page forTerminal.input()
andTerminal.output()
.- Parameters:
codepage
- the codepage- Returns:
- The builder
-
attributes
Attributes to use when creating a non system terminal, i.e. when the builder has been given the input and output streams using thestreams(InputStream, OutputStream)
method or whensystem(boolean)
has been explicitly called withfalse
.- Parameters:
attributes
- the attributes to use- Returns:
- The builder
- See Also:
-
size
Initial size to use when creating a non system terminal, i.e. when the builder has been given the input and output streams using thestreams(InputStream, OutputStream)
method or whensystem(boolean)
has been explicitly called withfalse
.- Parameters:
size
- the initial size- Returns:
- The builder
- See Also:
-
nativeSignals
-
signalHandler
-
paused
Initial paused state of the terminal (defaults to false). By default, the terminal is started, but in some cases, one might want to make sure the input stream is not consumed before needed, in which case the terminal needs to be created in a paused state.- Parameters:
paused
- the initial paused state- Returns:
- The builder
- See Also:
-
build
- Throws:
IOException
-
doBuild
- Throws:
IOException
-
select
private TerminalProvider.Stream select(Map<TerminalProvider.Stream, Boolean> system, TerminalBuilder.SystemOutput systemOutput) -
select
private static TerminalProvider.Stream select(Map<TerminalProvider.Stream, Boolean> system, TerminalProvider.Stream... streams) -
getParentProcessCommand
-
getBoolean
-
load
-
getCodepageCharset
-
setTerminalOverride
Deprecated.Allows an application to override the result ofbuild()
. The intended use case is to allow a container or server application to control an embedded application that uses a LineReader that uses Terminal constructed with TerminalBuilder.build but provides no public api for setting theLineReader
of theTerminal
. For example, the sbt build tool uses aLineReader
to implement an interactive shell. One of its supported commands isconsole
which invokes the scala REPL. The scala REPL also uses aLineReader
and it is necessary to override theTerminal
used by the the REPL to share the sameTerminal
instance used by sbt.When this method is called with a non-null
Terminal
, all subsequent calls tobuild()
will return the providedTerminal
regardless of how theTerminalBuilder
was constructed. The default behavior ofTerminalBuilder
can be restored by calling setTerminalOverride with a nullTerminal
Usage of setTerminalOverride should be restricted to cases where it isn't possible to update the api of the nested application to accept a
instance
.- Parameters:
terminal
- theTerminal
to globally override
-