Class JniTerminalProvider

  • All Implemented Interfaces:
    org.jline.terminal.spi.TerminalProvider

    public class JniTerminalProvider
    extends java.lang.Object
    implements org.jline.terminal.spi.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 
      Modifier and Type Method Description
      org.jline.terminal.spi.Pty current​(org.jline.terminal.spi.SystemStream systemStream)  
      int getConsoleCodepage()  
      boolean isPosixSystemStream​(org.jline.terminal.spi.SystemStream stream)  
      boolean isSystemStream​(org.jline.terminal.spi.SystemStream stream)  
      boolean isWindowsSystemStream​(org.jline.terminal.spi.SystemStream stream)  
      java.lang.String name()  
      org.jline.terminal.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, org.jline.terminal.Terminal.SignalHandler signalHandler, boolean paused, org.jline.terminal.Attributes attributes, org.jline.terminal.Size size)
      Create a new terminal backed by a newly opened POSIX pseudo-terminal (PTY).
      org.jline.terminal.spi.Pty open​(org.jline.terminal.Attributes attributes, org.jline.terminal.Size size)  
      org.jline.terminal.Terminal posixSysTerminal​(java.lang.String name, java.lang.String type, boolean ansiPassThrough, java.nio.charset.Charset encoding, boolean nativeSignals, org.jline.terminal.Terminal.SignalHandler signalHandler, boolean paused, org.jline.terminal.spi.SystemStream systemStream)  
      org.jline.terminal.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, org.jline.terminal.Terminal.SignalHandler signalHandler, boolean paused, org.jline.terminal.spi.SystemStream systemStream)
      Create a POSIX system terminal backed by a native PTY.
      java.lang.String systemStreamName​(org.jline.terminal.spi.SystemStream stream)  
      int systemStreamWidth​(org.jline.terminal.spi.SystemStream stream)  
      org.jline.terminal.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, org.jline.terminal.Terminal.SignalHandler signalHandler, boolean paused, org.jline.terminal.spi.SystemStream systemStream)  
      java.lang.String toString()  
      org.jline.terminal.Terminal winSysTerminal​(java.lang.String name, java.lang.String type, boolean ansiPassThrough, java.nio.charset.Charset encoding, boolean nativeSignals, org.jline.terminal.Terminal.SignalHandler signalHandler, boolean paused, org.jline.terminal.spi.SystemStream systemStream)  
      org.jline.terminal.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, org.jline.terminal.Terminal.SignalHandler signalHandler, boolean paused, org.jline.terminal.spi.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

        registerDefaultSignal, registerSignal, sysTerminal, unregisterSignal
    • Constructor Detail

      • JniTerminalProvider

        public JniTerminalProvider()
        Creates a new JNI terminal provider instance and ensures the native library is loaded.

        Loading the native library via JLineNativeLoader.initialize() calls System.loadLibrary(), which is a restricted operation. On JDK 24-25 this produces a JVM warning when --enable-native-access is not set. On future JDKs where native access is denied by default, the load will fail and TerminalBuilder will fall back to other providers.

    • Method Detail

      • name

        public java.lang.String name()
        Specified by:
        name in interface org.jline.terminal.spi.TerminalProvider
      • getConsoleCodepage

        public int getConsoleCodepage()
        Specified by:
        getConsoleCodepage in interface org.jline.terminal.spi.TerminalProvider
      • current

        public org.jline.terminal.spi.Pty current​(org.jline.terminal.spi.SystemStream systemStream)
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • open

        public org.jline.terminal.spi.Pty open​(org.jline.terminal.Attributes attributes,
                                               org.jline.terminal.Size size)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • sysTerminal

        public org.jline.terminal.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,
                                                       org.jline.terminal.Terminal.SignalHandler signalHandler,
                                                       boolean paused,
                                                       org.jline.terminal.spi.SystemStream systemStream)
                                                throws java.io.IOException
        Specified by:
        sysTerminal in interface org.jline.terminal.spi.TerminalProvider
        Throws:
        java.io.IOException
      • winSysTerminal

        public org.jline.terminal.Terminal winSysTerminal​(java.lang.String name,
                                                          java.lang.String type,
                                                          boolean ansiPassThrough,
                                                          java.nio.charset.Charset encoding,
                                                          boolean nativeSignals,
                                                          org.jline.terminal.Terminal.SignalHandler signalHandler,
                                                          boolean paused,
                                                          org.jline.terminal.spi.SystemStream systemStream)
                                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • winSysTerminal

        public org.jline.terminal.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,
                                                          org.jline.terminal.Terminal.SignalHandler signalHandler,
                                                          boolean paused,
                                                          org.jline.terminal.spi.SystemStream systemStream)
                                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • posixSysTerminal

        public org.jline.terminal.Terminal posixSysTerminal​(java.lang.String name,
                                                            java.lang.String type,
                                                            boolean ansiPassThrough,
                                                            java.nio.charset.Charset encoding,
                                                            boolean nativeSignals,
                                                            org.jline.terminal.Terminal.SignalHandler signalHandler,
                                                            boolean paused,
                                                            org.jline.terminal.spi.SystemStream systemStream)
                                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • posixSysTerminal

        public org.jline.terminal.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,
                                                            org.jline.terminal.Terminal.SignalHandler signalHandler,
                                                            boolean paused,
                                                            org.jline.terminal.spi.SystemStream systemStream)
                                                     throws java.io.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 from stdoutEncoding or stderrEncoding depending on systemStream.
        Parameters:
        name - human-readable terminal name
        type - terminal type (TERM)
        ansiPassThrough - ignored ? ANSI pass-through is only supported on Windows
        encoding - primary charset used by the terminal
        stdinEncoding - charset for standard input
        stdoutEncoding - charset for standard output
        stderrEncoding - charset for standard error
        nativeSignals - whether native signal handling is enabled
        signalHandler - handler for terminal signals
        paused - ignored ? paused mode is only supported on Windows and PTY-backed terminals
        systemStream - which system stream the terminal represents (affects output encoding selection)
        Returns:
        a POSIX system terminal
        Throws:
        java.io.IOException - if the underlying PTY cannot be opened
      • newTerminal

        public org.jline.terminal.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,
                                                       org.jline.terminal.Terminal.SignalHandler signalHandler,
                                                       boolean paused,
                                                       org.jline.terminal.Attributes attributes,
                                                       org.jline.terminal.Size size)
                                                throws java.io.IOException
        Create a new terminal backed by a newly opened POSIX pseudo-terminal (PTY).
        Specified by:
        newTerminal in interface org.jline.terminal.spi.TerminalProvider
        Parameters:
        name - the terminal name for identification
        type - the terminal type (TERM)
        in - the input stream connected to the PTY slave
        out - the output stream connected to the PTY slave
        encoding - the primary charset for the terminal
        inputEncoding - the charset to decode input
        outputEncoding - the charset to encode output
        signalHandler - handler for terminal signals
        paused - if true, the terminal is created in a paused state
        attributes - initial terminal attributes for the PTY
        size - initial terminal size for the PTY
        Returns:
        a Terminal instance wrapping the opened PTY and provided streams
        Throws:
        java.io.IOException - if the PTY cannot be opened
      • isSystemStream

        public boolean isSystemStream​(org.jline.terminal.spi.SystemStream stream)
        Specified by:
        isSystemStream in interface org.jline.terminal.spi.TerminalProvider
      • isWindowsSystemStream

        public boolean isWindowsSystemStream​(org.jline.terminal.spi.SystemStream stream)
      • isPosixSystemStream

        public boolean isPosixSystemStream​(org.jline.terminal.spi.SystemStream stream)
      • systemStreamName

        public java.lang.String systemStreamName​(org.jline.terminal.spi.SystemStream stream)
        Specified by:
        systemStreamName in interface org.jline.terminal.spi.TerminalProvider
      • systemStreamWidth

        public int systemStreamWidth​(org.jline.terminal.spi.SystemStream stream)
        Specified by:
        systemStreamWidth in interface org.jline.terminal.spi.TerminalProvider
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object