Class NaftahSystem

java.lang.Object
org.daiitech.naftah.NaftahSystem

public final class NaftahSystem extends Object
Utility class for managing system-wide settings, especially for terminal configuration and versioning in the Naftah runtime environment.

This class is non-instantiable and only provides static utility methods and constants.

Common usages include:

  • Setting up terminal output/error streams
  • Retrieving Naftah version information
  • Setting the system locale to Tunisian Arabic
  • Auto-refreshing terminal dimensions
Author:
Chakib Daii
  • Field Details

    • TERMINAL_WIDTH_PROPERTY

      public static final String TERMINAL_WIDTH_PROPERTY
      System property key used to store terminal width.
      See Also:
    • TERMINAL_HEIGHT_PROPERTY

      public static final String TERMINAL_HEIGHT_PROPERTY
      System property key used to store terminal height.
      See Also:
  • Constructor Details

    • NaftahSystem

      private NaftahSystem()
      Private constructor to prevent instantiation.
  • Method Details

    • getVersion

      public static String getVersion()
      Returns the current full version of Naftah.
      Returns:
      the full version string, e.g., "1.2.3" or "1.2.3-SNAPSHOT"
    • getShortVersion

      public static String getShortVersion()
      Returns the short form of the version string, containing only the major and minor parts.

      For example:

      • "1.2.3""1.2"
      • "2.0.1-SNAPSHOT""2.0"
      Returns:
      the short version string
      Throws:
      NaftahBugError - if the version format is invalid or unexpected
    • setupLocale

      public static void setupLocale()
      Sets the default Locale to Tunisian Arabic using predefined constants for language and region.
    • setupOutputStream

      public static void setupOutputStream()
      Redirects System.out to a custom PrintStream instance to support UTF-8 or enhanced terminal features.
    • setupErrorStream

      public static void setupErrorStream()
      Redirects System.err to a custom PrintStream instance.
    • setupRefreshTerminalWidthAndHeight

      public static void setupRefreshTerminalWidthAndHeight(org.jline.terminal.Terminal terminal)
      Sets up automatic refresh of terminal width and height properties.

      On Windows, uses a scheduled task to periodically refresh. On other systems, uses the Terminal.Signal.WINCH signal handler.

      Parameters:
      terminal - the terminal instance to monitor
    • setupTerminalWidthAndHeight

      public static void setupTerminalWidthAndHeight(Supplier<int[]> terminalWidthAndHeightSupplier)
      Updates the system properties TERMINAL_WIDTH_PROPERTY and TERMINAL_HEIGHT_PROPERTY using the values provided by the supplier.
      Parameters:
      terminalWidthAndHeightSupplier - a supplier providing an array of 2 integers: width and height
    • getTerminalWidthAndHeight

      public static int[] getTerminalWidthAndHeight(org.jline.terminal.Terminal terminal)
      Returns the terminal dimensions from the given Terminal instance.
      Parameters:
      terminal - the terminal object to query
      Returns:
      an array with two elements: [width, height]
    • getTerminalWidthAndHeight

      public static int[] getTerminalWidthAndHeight()
      Returns the terminal dimensions using a temporary Terminal instance.

      If an exception occurs during terminal initialization, returns default fallback dimensions (80x24).

      Returns:
      an array with two elements: [width, height]