Class JniTerminalProvider
- All Implemented Interfaces:
TerminalProvider
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:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new JNI terminal provider instance and ensures the native library is loaded. -
Method Summary
Modifier and TypeMethodDescriptioncurrent(SystemStream systemStream) intRetrieve the Windows console output code page.booleanisPosixSystemStream(SystemStream stream) booleanisSystemStream(SystemStream stream) Checks if the specified system stream is available on this platform.booleanisWindowsSystemStream(SystemStream stream) name()Returns the name of this terminal provider.newTerminal(String name, String type, InputStream in, OutputStream out, Charset encoding, Charset inputEncoding, Charset outputEncoding, Terminal.SignalHandler signalHandler, boolean paused, Attributes attributes, Size size) Create a new terminal backed by a newly opened POSIX pseudo-terminal (PTY).open(Attributes attributes, Size size) posixSysTerminal(String name, String type, boolean ansiPassThrough, Charset encoding, boolean nativeSignals, Terminal.SignalHandler signalHandler, boolean paused, SystemStream systemStream) posixSysTerminal(String name, String type, boolean ansiPassThrough, Charset encoding, Charset stdinEncoding, Charset stdoutEncoding, Charset stderrEncoding, boolean nativeSignals, Terminal.SignalHandler signalHandler, boolean paused, SystemStream systemStream) Create a POSIX system terminal backed by a native PTY.systemStreamName(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.sysTerminal(String name, String type, boolean ansiPassThrough, Charset encoding, Charset inputEncoding, Charset outputEncoding, boolean nativeSignals, Terminal.SignalHandler signalHandler, boolean paused, SystemStream systemStream) Creates a terminal connected to a system stream.toString()winSysTerminal(String name, String type, boolean ansiPassThrough, Charset encoding, boolean nativeSignals, Terminal.SignalHandler signalHandler, boolean paused, SystemStream systemStream) winSysTerminal(String name, String type, boolean ansiPassThrough, Charset encoding, Charset stdinEncoding, Charset stdoutEncoding, 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, waitMethods inherited from interface org.jline.terminal.spi.TerminalProvider
registerDefaultSignal, registerSignal, sysTerminal, unregisterSignal
-
Constructor Details
-
JniTerminalProvider
public JniTerminalProvider()Creates a new JNI terminal provider instance and ensures the native library is loaded.Loading the native library via
JLineNativeLoader.initialize()callsSystem.loadLibrary(), which is a restricted operation. On JDK 24-25 this produces a JVM warning when--enable-native-accessis not set. On future JDKs where native access is denied by default, the load will fail andTerminalBuilderwill fall back to other providers.
-
-
Method Details
-
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", "exec", and "dumb".
- Specified by:
namein interfaceTerminalProvider- Returns:
- the name of this terminal provider
-
getConsoleCodepage
public int getConsoleCodepage()Description copied from interface:TerminalProviderRetrieve the Windows console output code page. On Windows this returns the console output code page; on non-Windows platforms or when the code page cannot be determined this returns-1.- Specified by:
getConsoleCodepagein interfaceTerminalProvider- Returns:
- the console output code page, or
-1if not available
-
current
- Throws:
IOException
-
open
- Throws:
IOException
-
sysTerminal
public Terminal sysTerminal(String name, String type, boolean ansiPassThrough, Charset encoding, Charset inputEncoding, Charset outputEncoding, boolean nativeSignals, Terminal.SignalHandler signalHandler, boolean paused, SystemStream systemStream) throws 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 sequences (only used on Windows)encoding- 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 state (only used on Windows)systemStream- the system stream to connect to- Returns:
- a new terminal connected to the specified system stream
- Throws:
IOException- if an I/O error occurs
-
winSysTerminal
public Terminal winSysTerminal(String name, String type, boolean ansiPassThrough, Charset encoding, boolean nativeSignals, Terminal.SignalHandler signalHandler, boolean paused, SystemStream systemStream) throws IOException - Throws:
IOException
-
winSysTerminal
public Terminal winSysTerminal(String name, String type, boolean ansiPassThrough, Charset encoding, Charset stdinEncoding, Charset stdoutEncoding, Charset stderrEncoding, boolean nativeSignals, Terminal.SignalHandler signalHandler, boolean paused, SystemStream systemStream) throws IOException - Throws:
IOException
-
posixSysTerminal
public Terminal posixSysTerminal(String name, String type, boolean ansiPassThrough, Charset encoding, boolean nativeSignals, Terminal.SignalHandler signalHandler, boolean paused, SystemStream systemStream) throws IOException - Throws:
IOException
-
posixSysTerminal
public Terminal posixSysTerminal(String name, String type, boolean ansiPassThrough, Charset encoding, Charset stdinEncoding, Charset stdoutEncoding, Charset stderrEncoding, boolean nativeSignals, Terminal.SignalHandler signalHandler, boolean paused, SystemStream systemStream) throws IOException Create a POSIX system terminal backed by a native PTY. The created terminal is configured with the provided character encodings and signal handling. The output encoding is chosen fromstdoutEncodingorstderrEncodingdepending onsystemStream.- Parameters:
name- human-readable terminal nametype- terminal type (TERM)ansiPassThrough- ignored — ANSI pass-through is only supported on Windowsencoding- primary charset used by the terminalstdinEncoding- charset for standard inputstdoutEncoding- charset for standard outputstderrEncoding- charset for standard errornativeSignals- whether native signal handling is enabledsignalHandler- handler for terminal signalspaused- ignored — paused mode is only supported on Windows and PTY-backed terminalssystemStream- which system stream the terminal represents (affects output encoding selection)- Returns:
- a POSIX system terminal
- Throws:
IOException- if the underlying PTY cannot be opened
-
newTerminal
public Terminal newTerminal(String name, String type, InputStream in, OutputStream out, Charset encoding, Charset inputEncoding, Charset outputEncoding, Terminal.SignalHandler signalHandler, boolean paused, Attributes attributes, Size size) throws IOException Create a new terminal backed by a newly opened POSIX pseudo-terminal (PTY).- Specified by:
newTerminalin interfaceTerminalProvider- Parameters:
name- the terminal name for identificationtype- the terminal type (TERM)in- the input stream connected to the PTY slaveout- the output stream connected to the PTY slaveencoding- the primary charset for the terminalinputEncoding- the charset to decode inputoutputEncoding- the charset to encode outputsignalHandler- handler for terminal signalspaused- if true, the terminal is created in a paused stateattributes- initial terminal attributes for the PTYsize- initial terminal size for the PTY- Returns:
- a Terminal instance wrapping the opened PTY and provided streams
- Throws:
IOException- if the PTY cannot be opened
-
isSystemStream
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
-
isPosixSystemStream
-
systemStreamName
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
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
-