Interface TerminalProvider


public interface TerminalProvider
Service Provider Interface for terminal implementations.

Providers are discovered via ServiceLoader and selected based on isSupported() and priority(). The provider with the highest priority that reports itself as supported is used first. If it fails to create a terminal, the next provider is tried.

Built-in providers include:

  • FFM-based PTY (Java 22+, POSIX) — priority 100
  • Windows system console (JNI/FFM) — priority 100
  • Cygwin PTY — priority 75
  • Exec-based PTY (POSIX) — priority 50
  • External terminal (fallback) — priority 10

Third-party implementations can provide custom terminal backends by implementing this interface and registering via META-INF/services/org.aesh.terminal.provider.TerminalProvider.

  • Method Summary

    Modifier and Type
    Method
    Description
    createTerminal(String name, String type, boolean nativeSignals)
    Creates a system terminal.
    boolean
    Whether this provider is supported in the current environment.
    Returns the name of this provider, for logging and diagnostics.
    int
    The priority of this provider.
  • Method Details

    • name

      String name()
      Returns the name of this provider, for logging and diagnostics.
      Returns:
      the provider name
    • isSupported

      boolean isSupported()
      Whether this provider is supported in the current environment.

      This should be a fast check based on OS detection, Java version, available classes, etc. It should NOT attempt to open a terminal.

      Returns:
      true if this provider can potentially create a terminal
    • priority

      int priority()
      The priority of this provider. Higher values are preferred.

      When multiple providers are supported, the one with the highest priority is tried first. If it fails, the next is tried.

      Recommended ranges:

      • 100+ — native/FFM providers (best performance)
      • 50-99 — process-based providers (exec/JNI)
      • 1-49 — fallback providers (dumb terminals, external)
      Returns:
      the priority (higher = preferred)
    • createTerminal

      Terminal createTerminal(String name, String type, boolean nativeSignals) throws IOException
      Creates a system terminal.

      This is called for terminals connected to the local console (stdin/stdout). The provider should create and return a fully initialized terminal, or throw IOException if it cannot.

      Parameters:
      name - the terminal name (for display/logging)
      type - the terminal type (e.g., "xterm-256color"), or null to auto-detect
      nativeSignals - whether to enable native signal handling
      Returns:
      a new Terminal instance
      Throws:
      IOException - if the terminal cannot be created