- java.lang.Object
-
- org.jline.terminal.TerminalBuilder
-
public final class TerminalBuilder extends Object
Builder class to create terminals.
-
-
Field Summary
Fields Modifier and Type Field Description static StringPROP_CODEPAGEstatic StringPROP_COLOR_DISTANCEstatic StringPROP_DISABLE_ALTERNATE_CHARSETstatic StringPROP_DUMBstatic StringPROP_DUMB_COLORstatic StringPROP_ENCODINGstatic StringPROP_EXECstatic StringPROP_JANSIstatic StringPROP_JNAstatic StringPROP_NON_BLOCKING_READSstatic StringPROP_TYPE
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description TerminalBuilderattributes(Attributes attributes)Attributes to use when creating a non system terminal, i.e.Terminalbuild()static TerminalBuilderbuilder()Creates a new terminal builder instance.TerminalBuildercodepage(int codepage)Deprecated.JLine now writes Unicode output independently from the selected code page.TerminalBuildercolor(boolean color)TerminalBuilderdumb(boolean dumb)TerminalBuilderencoding(String encoding)Set the encoding to use for reading/writing from the console.TerminalBuilderencoding(Charset encoding)Set theCharsetto use for reading/writing from the console.TerminalBuilderexec(boolean exec)TerminalBuilderjansi(boolean jansi)TerminalBuilderjna(boolean jna)TerminalBuildername(String name)TerminalBuildernativeSignals(boolean nativeSignals)TerminalBuilderpaused(boolean paused)Initial paused state of the terminal (defaults to false).static voidsetTerminalOverride(Terminal terminal)Deprecated.TerminalBuildersignalHandler(Terminal.SignalHandler signalHandler)TerminalBuildersize(Size size)Initial size to use when creating a non system terminal, i.e.TerminalBuilderstreams(InputStream in, OutputStream out)TerminalBuildersystem(boolean system)static Terminalterminal()Returns the default system terminal.TerminalBuildertype(String type)
-
-
-
Field Detail
-
PROP_ENCODING
public static final String PROP_ENCODING
- See Also:
- Constant Field Values
-
PROP_CODEPAGE
public static final String PROP_CODEPAGE
- See Also:
- Constant Field Values
-
PROP_TYPE
public static final String PROP_TYPE
- See Also:
- Constant Field Values
-
PROP_JNA
public static final String PROP_JNA
- See Also:
- Constant Field Values
-
PROP_JANSI
public static final String PROP_JANSI
- See Also:
- Constant Field Values
-
PROP_EXEC
public static final String PROP_EXEC
- See Also:
- Constant Field Values
-
PROP_DUMB
public static final String PROP_DUMB
- See Also:
- Constant Field Values
-
PROP_DUMB_COLOR
public static final String PROP_DUMB_COLOR
- See Also:
- Constant Field Values
-
PROP_NON_BLOCKING_READS
public static final String PROP_NON_BLOCKING_READS
- See Also:
- Constant Field Values
-
PROP_COLOR_DISTANCE
public static final String PROP_COLOR_DISTANCE
- See Also:
- Constant Field Values
-
PROP_DISABLE_ALTERNATE_CHARSET
public static final String PROP_DISABLE_ALTERNATE_CHARSET
- See Also:
- Constant Field Values
-
-
Method Detail
-
terminal
public static Terminal terminal() throws IOException
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
public static TerminalBuilder builder()
Creates a new terminal builder instance.- Returns:
- a builder
-
name
public TerminalBuilder name(String name)
-
streams
public TerminalBuilder streams(InputStream in, OutputStream out)
-
system
public TerminalBuilder system(boolean system)
-
jna
public TerminalBuilder jna(boolean jna)
-
jansi
public TerminalBuilder jansi(boolean jansi)
-
exec
public TerminalBuilder exec(boolean exec)
-
dumb
public TerminalBuilder dumb(boolean dumb)
-
type
public TerminalBuilder type(String type)
-
color
public TerminalBuilder color(boolean color)
-
encoding
public TerminalBuilder encoding(String encoding) throws UnsupportedCharsetException
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 theTerminalimplementation.Use
Terminal.encoding()to get theCharsetthat 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:
Terminal.encoding()
-
encoding
public TerminalBuilder encoding(Charset encoding)
Set theCharsetto 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 theTerminalimplementation.Use
Terminal.encoding()to get theCharsetthat 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:
Terminal.encoding()
-
codepage
@Deprecated public TerminalBuilder codepage(int 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
public TerminalBuilder attributes(Attributes 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(Size),system(boolean)
-
size
public TerminalBuilder size(Size 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:
attributes(Attributes),system(boolean)
-
nativeSignals
public TerminalBuilder nativeSignals(boolean nativeSignals)
-
signalHandler
public TerminalBuilder signalHandler(Terminal.SignalHandler signalHandler)
-
paused
public TerminalBuilder paused(boolean 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:
Terminal.pause()
-
build
public Terminal build() throws IOException
- Throws:
IOException
-
setTerminalOverride
@Deprecated public static void setTerminalOverride(Terminal terminal)
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 theLineReaderof theTerminal. For example, the sbt build tool uses aLineReaderto implement an interactive shell. One of its supported commands isconsolewhich invokes the scala REPL. The scala REPL also uses aLineReaderand it is necessary to override theTerminalused by the the REPL to share the sameTerminalinstance used by sbt.When this method is called with a non-null
Terminal, all subsequent calls tobuild()will return the providedTerminalregardless of how theTerminalBuilderwas constructed. The default behavior ofTerminalBuildercan be restored by calling setTerminalOverride with a nullTerminalUsage 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- theTerminalto globally override
-
-