Terminal Providers
JLine supports multiple terminal providers, each with its own characteristics and capabilities. This allows JLine to work across different platforms and environments.
Provider Selection
JLine can automatically select the best terminal provider for your environment, or you can explicitly specify which provider to use:
Loading snippet: ProviderSelectionExample...
JNA Provider
The JNA (Java Native Access) provider uses JNA to access native terminal functionality:
Loading snippet: JnaTerminalExample...
Jansi Provider
The Jansi provider uses the Jansi library to provide ANSI support on Windows:
Loading snippet: JansiTerminalExample...
FFM Provider
The FFM (Foreign Function & Memory) provider uses Java's FFM API (available in Java 22+) to access native terminal functionality:
Loading snippet: FfmTerminalExample...
JNI Provider
The JNI (Java Native Interface) provider uses JNI to access native terminal functionality:
Loading snippet: JniTerminalExample...
Exec Provider
The Exec provider uses external commands to access terminal functionality:
Loading snippet: ExecTerminalExample...
Dumb Terminal
The Dumb terminal is a fallback option that provides basic terminal functionality without advanced features:
Loading snippet: DumbTerminalExample...
Best Practices
When working with terminal providers in JLine, consider these best practices:
-
Auto-Selection: Let JLine automatically select the best provider for your environment when possible.
-
Fallback Strategy: Implement a fallback strategy if a specific provider is not available.
-
Feature Detection: Check for terminal capabilities before using advanced features.
-
Cross-Platform Testing: Test your application on different platforms to ensure it works with different providers.
-
Error Handling: Handle terminal-related errors gracefully.
-
Terminal Cleanup: Always close the terminal when your application exits.
-
Signal Handling: Handle terminal signals (like SIGINT) appropriately.
-
Terminal Size: Be aware of terminal size and adapt your UI accordingly.
-
Color Support: Check for color support before using colors.
-
Documentation: Document which terminal providers your application supports.