Class JniTerminalProvider
- java.lang.Object
-
- org.jline.terminal.impl.jni.JniTerminalProvider
-
- All Implemented Interfaces:
TerminalProvider
public class JniTerminalProvider extends java.lang.Object implements TerminalProvider
Terminal provider implementation that uses JNI (Java Native Interface) to access native terminal functionality.This provider requires the JLine native library to be loaded, which is handled by
JLineNativeLoader. The native library provides access to low-level terminal operations that are not available through standard Java APIs.The native library is automatically loaded when this provider is used. If the library cannot be loaded, the provider will not be available and JLine will fall back to other available providers.
The native library loading can be configured using system properties as documented in
JLineNativeLoader.- See Also:
JLineNativeLoader,TerminalBuilder
-
-
Constructor Summary
Constructors Constructor Description JniTerminalProvider()Creates a new JNI terminal provider instance and ensures the native library is loaded.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Ptycurrent(SystemStream systemStream)intgetConsoleCodepage()Returns the Windows console output codepage.booleanisPosixSystemStream(SystemStream stream)booleanisSystemStream(SystemStream stream)Checks if the specified system stream is available on this platform.booleanisWindowsSystemStream(SystemStream stream)java.lang.Stringname()Returns the name of this terminal provider.TerminalnewTerminal(java.lang.String name, java.lang.String type, java.io.InputStream in, java.io.OutputStream out, java.nio.charset.Charset encoding, java.nio.charset.Charset stdinEncoding, java.nio.charset.Charset stdoutEncoding, java.nio.charset.Charset stderrEncoding, Terminal.SignalHandler signalHandler, boolean paused, Attributes attributes, Size size)Deprecated.TerminalnewTerminal(java.lang.String name, java.lang.String type, java.io.InputStream in, java.io.OutputStream out, java.nio.charset.Charset encoding, java.nio.charset.Charset inputEncoding, java.nio.charset.Charset outputEncoding, Terminal.SignalHandler signalHandler, boolean paused, Attributes attributes, Size size)Creates a new terminal with custom input and output streams.Ptyopen(Attributes attributes, Size size)TerminalposixSysTerminal(java.lang.String name, java.lang.String type, boolean ansiPassThrough, java.nio.charset.Charset encoding, boolean nativeSignals, Terminal.SignalHandler signalHandler, boolean paused, SystemStream systemStream)TerminalposixSysTerminal(java.lang.String name, java.lang.String type, boolean ansiPassThrough, java.nio.charset.Charset encoding, java.nio.charset.Charset stdinEncoding, java.nio.charset.Charset stdoutEncoding, java.nio.charset.Charset stderrEncoding, boolean nativeSignals, Terminal.SignalHandler signalHandler, boolean paused, SystemStream systemStream)java.lang.StringsystemStreamName(SystemStream stream)Returns the name of the specified system stream on this platform.intsystemStreamWidth(SystemStream stream)Returns the width (number of columns) of the specified system stream.TerminalsysTerminal(java.lang.String name, java.lang.String type, boolean ansiPassThrough, java.nio.charset.Charset encoding, java.nio.charset.Charset inputEncoding, java.nio.charset.Charset outputEncoding, boolean nativeSignals, Terminal.SignalHandler signalHandler, boolean paused, SystemStream systemStream)Creates a terminal connected to a system stream.TerminalsysTerminal(java.lang.String name, java.lang.String type, boolean ansiPassThrough, java.nio.charset.Charset encoding, java.nio.charset.Charset stdinEncoding, java.nio.charset.Charset stdoutEncoding, java.nio.charset.Charset stderrEncoding, boolean nativeSignals, Terminal.SignalHandler signalHandler, boolean paused, SystemStream systemStream)Deprecated.java.lang.StringtoString()TerminalwinSysTerminal(java.lang.String name, java.lang.String type, boolean ansiPassThrough, java.nio.charset.Charset encoding, boolean nativeSignals, Terminal.SignalHandler signalHandler, boolean paused, SystemStream systemStream)TerminalwinSysTerminal(java.lang.String name, java.lang.String type, boolean ansiPassThrough, java.nio.charset.Charset encoding, java.nio.charset.Charset stdinEncoding, java.nio.charset.Charset stdoutEncoding, java.nio.charset.Charset stderrEncoding, boolean nativeSignals, Terminal.SignalHandler signalHandler, boolean paused, SystemStream systemStream)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jline.terminal.spi.TerminalProvider
newTerminal, sysTerminal
-
-
-
-
Constructor Detail
-
JniTerminalProvider
public JniTerminalProvider()
Creates a new JNI terminal provider instance and ensures the native library is loaded.The constructor first checks that native access is enabled for this module. On JDK 22+, calling
System.load()without--enable-native-accessproduces a warning (JDK 24+) or throwsIllegalCallerException(JDK 26+). By checking upfront, this provider fails cleanly and allowsTerminalBuilderto fall back to other providers.- Throws:
java.lang.UnsupportedOperationException- if native access is not enabled for this module
-
-
Method Detail
-
name
public java.lang.String name()
Description copied from interface:TerminalProviderReturns the name of this terminal provider.The provider name is a unique identifier that can be used to request this specific provider when creating terminals. Common provider names include "ffm", "jni", "jansi", "jna", "exec", and "dumb".
- Specified by:
namein interfaceTerminalProvider- Returns:
- the name of this terminal provider
-
getConsoleCodepage
public int getConsoleCodepage()
Description copied from interface:TerminalProviderReturns the Windows console output codepage.On Windows, this method returns the console output codepage (equivalent to
GetConsoleOutputCP()). On non-Windows platforms, or if the codepage cannot be determined, this method returns-1.- Specified by:
getConsoleCodepagein interfaceTerminalProvider- Returns:
- the console output codepage, or
-1if not available
-
current
public Pty current(SystemStream systemStream) throws java.io.IOException
- Throws:
java.io.IOException
-
open
public Pty open(Attributes attributes, Size size) throws java.io.IOException
- Throws:
java.io.IOException
-
sysTerminal
public Terminal sysTerminal(java.lang.String name, java.lang.String type, boolean ansiPassThrough, java.nio.charset.Charset encoding, java.nio.charset.Charset inputEncoding, java.nio.charset.Charset outputEncoding, boolean nativeSignals, Terminal.SignalHandler signalHandler, boolean paused, SystemStream systemStream) throws java.io.IOException
Description copied from interface:TerminalProviderCreates a terminal connected to a system stream.This method creates a terminal that is connected to one of the standard system streams (standard input, standard output, or standard error). Such terminals typically represent the actual terminal window or console that the application is running in.
- Specified by:
sysTerminalin interfaceTerminalProvider- Parameters:
name- the name of the terminaltype- the terminal type (e.g., "xterm", "dumb")ansiPassThrough- whether to pass through ANSI escape sequencesencoding- the general character encoding to useinputEncoding- the character encoding to use for inputoutputEncoding- the character encoding to use for outputnativeSignals- whether to use native signal handlingsignalHandler- the signal handler to usepaused- whether the terminal should start in a paused statesystemStream- the system stream to connect to- Returns:
- a new terminal connected to the specified system stream
- Throws:
java.io.IOException- if an I/O error occurs
-
sysTerminal
@Deprecated public Terminal sysTerminal(java.lang.String name, java.lang.String type, boolean ansiPassThrough, java.nio.charset.Charset encoding, java.nio.charset.Charset stdinEncoding, java.nio.charset.Charset stdoutEncoding, java.nio.charset.Charset stderrEncoding, boolean nativeSignals, Terminal.SignalHandler signalHandler, boolean paused, SystemStream systemStream) throws java.io.IOException
Deprecated.Description copied from interface:TerminalProviderCreates a terminal connected to a system stream.This method creates a terminal that is connected to one of the standard system streams (standard input, standard output, or standard error). Such terminals typically represent the actual terminal window or console that the application is running in.
- Specified by:
sysTerminalin interfaceTerminalProvider- Parameters:
name- the name of the terminaltype- the terminal type (e.g., "xterm", "dumb")ansiPassThrough- whether to pass through ANSI escape sequencesencoding- the general character encoding to usestdinEncoding- the character encoding to use for standard inputstdoutEncoding- the character encoding to use for standard outputstderrEncoding- the character encoding to use for standard errornativeSignals- whether to use native signal handlingsignalHandler- the signal handler to usepaused- whether the terminal should start in a paused statesystemStream- the system stream to connect to- Returns:
- a new terminal connected to the specified system stream
- Throws:
java.io.IOException- if an I/O error occurs
-
winSysTerminal
public Terminal winSysTerminal(java.lang.String name, java.lang.String type, boolean ansiPassThrough, java.nio.charset.Charset encoding, boolean nativeSignals, Terminal.SignalHandler signalHandler, boolean paused, SystemStream systemStream) throws java.io.IOException
- Throws:
java.io.IOException
-
winSysTerminal
public Terminal winSysTerminal(java.lang.String name, java.lang.String type, boolean ansiPassThrough, java.nio.charset.Charset encoding, java.nio.charset.Charset stdinEncoding, java.nio.charset.Charset stdoutEncoding, java.nio.charset.Charset stderrEncoding, boolean nativeSignals, Terminal.SignalHandler signalHandler, boolean paused, SystemStream systemStream) throws java.io.IOException
- Throws:
java.io.IOException
-
posixSysTerminal
public Terminal posixSysTerminal(java.lang.String name, java.lang.String type, boolean ansiPassThrough, java.nio.charset.Charset encoding, boolean nativeSignals, Terminal.SignalHandler signalHandler, boolean paused, SystemStream systemStream) throws java.io.IOException
- Throws:
java.io.IOException
-
posixSysTerminal
public Terminal posixSysTerminal(java.lang.String name, java.lang.String type, boolean ansiPassThrough, java.nio.charset.Charset encoding, java.nio.charset.Charset stdinEncoding, java.nio.charset.Charset stdoutEncoding, java.nio.charset.Charset stderrEncoding, boolean nativeSignals, Terminal.SignalHandler signalHandler, boolean paused, SystemStream systemStream) throws java.io.IOException
- Throws:
java.io.IOException
-
newTerminal
public Terminal newTerminal(java.lang.String name, java.lang.String type, java.io.InputStream in, java.io.OutputStream out, java.nio.charset.Charset encoding, java.nio.charset.Charset inputEncoding, java.nio.charset.Charset outputEncoding, Terminal.SignalHandler signalHandler, boolean paused, Attributes attributes, Size size) throws java.io.IOException
Description copied from interface:TerminalProviderCreates a new terminal with custom input and output streams.This method creates a terminal that is connected to the specified input and output streams. Such terminals can be used for various purposes, such as connecting to remote terminals over network connections or creating virtual terminals for testing.
- Specified by:
newTerminalin interfaceTerminalProvider- Parameters:
name- the name of the terminaltype- the terminal type (e.g., "xterm", "dumb")in- the input stream to read fromout- the output stream to write toencoding- the general character encoding to useinputEncoding- the character encoding to use for inputoutputEncoding- the character encoding to use for outputsignalHandler- the signal handler to usepaused- whether the terminal should start in a paused stateattributes- the initial terminal attributessize- the initial terminal size- Returns:
- a new terminal connected to the specified streams
- Throws:
java.io.IOException- if an I/O error occurs
-
newTerminal
@Deprecated public Terminal newTerminal(java.lang.String name, java.lang.String type, java.io.InputStream in, java.io.OutputStream out, java.nio.charset.Charset encoding, java.nio.charset.Charset stdinEncoding, java.nio.charset.Charset stdoutEncoding, java.nio.charset.Charset stderrEncoding, Terminal.SignalHandler signalHandler, boolean paused, Attributes attributes, Size size) throws java.io.IOException
Deprecated.Description copied from interface:TerminalProviderCreates a new terminal with custom input and output streams.This method creates a terminal that is connected to the specified input and output streams. Such terminals can be used for various purposes, such as connecting to remote terminals over network connections or creating virtual terminals for testing.
- Specified by:
newTerminalin interfaceTerminalProvider- Parameters:
name- the name of the terminaltype- the terminal type (e.g., "xterm", "dumb")in- the input stream to read fromout- the output stream to write toencoding- the general character encoding to usestdinEncoding- the character encoding to use for standard inputstdoutEncoding- the character encoding to use for standard outputstderrEncoding- the character encoding to use for standard errorsignalHandler- the signal handler to usepaused- whether the terminal should start in a paused stateattributes- the initial terminal attributessize- the initial terminal size- Returns:
- a new terminal connected to the specified streams
- Throws:
java.io.IOException- if an I/O error occurs
-
isSystemStream
public boolean isSystemStream(SystemStream stream)
Description copied from interface:TerminalProviderChecks if the specified system stream is available on this platform.This method determines whether the specified system stream (standard input, standard output, or standard error) is available for use on the current platform. Some platforms or environments may restrict access to certain system streams.
- Specified by:
isSystemStreamin interfaceTerminalProvider- Parameters:
stream- the system stream to check- Returns:
trueif the system stream is available,falseotherwise
-
isWindowsSystemStream
public boolean isWindowsSystemStream(SystemStream stream)
-
isPosixSystemStream
public boolean isPosixSystemStream(SystemStream stream)
-
systemStreamName
public java.lang.String systemStreamName(SystemStream stream)
Description copied from interface:TerminalProviderReturns the name of the specified system stream on this platform.This method returns a platform-specific name or identifier for the specified system stream. The name may be used for display purposes or for accessing the stream through platform-specific APIs.
- Specified by:
systemStreamNamein interfaceTerminalProvider- Parameters:
stream- the system stream- Returns:
- the name of the system stream on this platform
-
systemStreamWidth
public int systemStreamWidth(SystemStream stream)
Description copied from interface:TerminalProviderReturns the width (number of columns) of the specified system stream.This method determines the width of the terminal associated with the specified system stream. The width is measured in character cells and represents the number of columns available for display.
- Specified by:
systemStreamWidthin interfaceTerminalProvider- Parameters:
stream- the system stream- Returns:
- the width of the system stream in character columns
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-