Class TerminalEnvironment

java.lang.Object
org.aesh.terminal.utils.TerminalEnvironment

public final class TerminalEnvironment extends Object
Centralized utility for detecting terminal environment.

This class parses terminal-related environment variables and provides a single source of truth for terminal detection. All terminal detection logic should use this class rather than directly checking environment variables.

The environment is parsed lazily on first access and cached for the lifetime of the JVM. Use refresh() to force re-parsing if environment variables change (rare in practice).

Thread-safe: all methods are safe to call from multiple threads.

Author:
Ståle Pedersen
  • Method Details

    • getInstance

      public static TerminalEnvironment getInstance()
      Get the singleton instance.
      Returns:
      the terminal environment instance
    • refresh

      public static void refresh()
      Force re-parsing of environment variables.

      This is rarely needed since environment variables typically don't change during JVM lifetime. Useful for testing or when environment is modified programmatically.

    • getTerm

      public String getTerm()
      Get the TERM environment variable.
      Returns:
      TERM value, or null if not set
    • getTermProgram

      public String getTermProgram()
      Get the TERM_PROGRAM environment variable.
      Returns:
      TERM_PROGRAM value, or null if not set
    • getTerminalEmulator

      public String getTerminalEmulator()
      Get the TERMINAL_EMULATOR environment variable (used by JetBrains IDEs).
      Returns:
      TERMINAL_EMULATOR value, or null if not set
    • getColorterm

      public String getColorterm()
      Get the COLORTERM environment variable.
      Returns:
      COLORTERM value, or null if not set
    • getColorFgBg

      public String getColorFgBg()
      Get the COLORFGBG environment variable (foreground/background colors).
      Returns:
      COLORFGBG value, or null if not set
    • getAppleInterfaceStyle

      public String getAppleInterfaceStyle()
      Get the APPLE_INTERFACE_STYLE environment variable (macOS dark mode).
      Returns:
      APPLE_INTERFACE_STYLE value, or null if not set
    • isKitty

      public boolean isKitty()
      Check if running in Kitty terminal.
      Returns:
      true if KITTY_WINDOW_ID is set
    • isGhostty

      public boolean isGhostty()
      Check if running in Ghostty terminal.
      Returns:
      true if GHOSTTY_RESOURCES_DIR is set
    • isWezTerm

      public boolean isWezTerm()
      Check if running in WezTerm.
      Returns:
      true if WEZTERM_PANE is set
    • isITerm2

      public boolean isITerm2()
      Check if running in iTerm2.
      Returns:
      true if ITERM_SESSION_ID is set
    • isWindowsTerminal

      public boolean isWindowsTerminal()
      Check if running in Windows Terminal.
      Returns:
      true if WT_SESSION is set
    • isConEmu

      public boolean isConEmu()
      Check if running in ConEmu or Cmder.
      Returns:
      true if ConEmuPID or ConEmuANSI is set
    • isAlacritty

      public boolean isAlacritty()
      Check if running in Alacritty.
      Returns:
      true if ALACRITTY_SOCKET is set
    • isJetBrains

      public boolean isJetBrains()
      Check if running in a JetBrains IDE terminal (IntelliJ, PyCharm, etc.).
      Returns:
      true if TERMINAL_EMULATOR contains "JetBrains" or "JediTerm"
    • isInTmux

      public boolean isInTmux()
      Check if running inside tmux.
      Returns:
      true if TMUX is set
    • isInScreen

      public boolean isInScreen()
      Check if running inside GNU Screen.
      Returns:
      true if TERM starts with "screen"
    • isInMultiplexer

      public boolean isInMultiplexer()
      Check if running inside a terminal multiplexer (tmux or screen).
      Returns:
      true if in tmux or screen
    • isTmuxPassthroughEnabled

      public boolean isTmuxPassthroughEnabled()
      Check if tmux passthrough is enabled.
      Returns:
      true if TMUX_PASSTHROUGH indicates passthrough is enabled
    • isTrueColorIndicated

      public boolean isTrueColorIndicated()
      Check if true color is explicitly indicated by COLORTERM.
      Returns:
      true if COLORTERM is "truecolor" or "24bit"
    • isMacOsDarkMode

      public boolean isMacOsDarkMode()
      Check if macOS dark mode is enabled.
      Returns:
      true if APPLE_INTERFACE_STYLE is "Dark"
    • getTerminalType

      public Device.TerminalType getTerminalType()
      Get the detected terminal type.

      This is computed once from environment variables and cached.

      Returns:
      the detected terminal type
    • getDefaultColorDepth

      public ColorDepth getDefaultColorDepth()
      Get the default color depth for this terminal.

      This is based on COLORTERM, TERM, and terminal type detection.

      Returns:
      the detected color depth
    • supportsOscQueries

      public boolean supportsOscQueries()
      Check if OSC queries are likely supported.

      This considers JetBrains terminals (which don't support OSC), multiplexers (which block OSC by default), and outer terminal detection.

      Returns:
      true if OSC queries are likely supported
    • supportsGraphemeClusterMode

      public boolean supportsGraphemeClusterMode()
      Check if Mode 2027 (grapheme cluster segmentation) is likely supported.

      This delegates to the detected terminal type's grapheme cluster mode support.

      Returns:
      true if Mode 2027 is likely supported
    • supportsSynchronizedOutput

      public boolean supportsSynchronizedOutput()
      Check if Mode 2026 (synchronized output) is likely supported.

      This delegates to the detected terminal type's synchronized output support.

      Returns:
      true if Mode 2026 is likely supported
    • supportsShellIntegration

      public boolean supportsShellIntegration()
      Check if OSC 133 shell integration is likely supported.

      This delegates to the detected terminal type's shell integration support.

      Returns:
      true if OSC 133 shell integration is likely supported
    • supportsHyperlinks

      public boolean supportsHyperlinks()
      Check if OSC 8 hyperlinks are likely supported.

      This delegates to the detected terminal type's hyperlink support.

      Returns:
      true if OSC 8 hyperlinks are likely supported
    • hasKnownOuterTerminal

      public boolean hasKnownOuterTerminal()
      Check if a known OSC-capable outer terminal is detected.

      This is useful for nested terminal sessions (e.g., tmux inside Kitty).

      Returns:
      true if a known outer terminal is detected
    • detectTerminalType

      public static Device.TerminalType detectTerminalType()
      Get the detected terminal type (convenience method).
      Returns:
      the detected terminal type
    • detectColorDepth

      public static ColorDepth detectColorDepth()
      Get the detected color depth (convenience method).
      Returns:
      the detected color depth
    • isJetBrainsTerminal

      public static boolean isJetBrainsTerminal()
      Check if running in JetBrains IDE terminal (convenience method).
      Returns:
      true if in JetBrains terminal
    • isOscSupported

      public static boolean isOscSupported()
      Check if OSC queries are supported (convenience method).
      Returns:
      true if OSC queries are likely supported
    • toString

      public String toString()
      Overrides:
      toString in class Object