Package org.daiitech.naftah
Class NaftahSystem
java.lang.Object
org.daiitech.naftah.NaftahSystem
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 Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePrivate constructor to prevent instantiation. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringReturns the short form of the version string, containing only the major and minor parts.static int[]Returns the terminal dimensions using a temporaryTerminalinstance.static int[]getTerminalWidthAndHeight(org.jline.terminal.Terminal terminal) Returns the terminal dimensions from the givenTerminalinstance.static StringReturns the current full version of Naftah.static voidRedirectsSystem.errto a customPrintStreaminstance.static voidSets the defaultLocaleto Tunisian Arabic using predefined constants for language and region.static voidRedirectsSystem.outto a customPrintStreaminstance to support UTF-8 or enhanced terminal features.static voidsetupRefreshTerminalWidthAndHeight(org.jline.terminal.Terminal terminal) Sets up automatic refresh of terminal width and height properties.static voidsetupTerminalWidthAndHeight(Supplier<int[]> terminalWidthAndHeightSupplier) Updates the system propertiesTERMINAL_WIDTH_PROPERTYandTERMINAL_HEIGHT_PROPERTYusing the values provided by the supplier.
-
Field Details
-
TERMINAL_WIDTH_PROPERTY
System property key used to store terminal width.- See Also:
-
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
Returns the current full version of Naftah.- Returns:
- the full version string, e.g.,
"1.2.3"or"1.2.3-SNAPSHOT"
-
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 defaultLocaleto Tunisian Arabic using predefined constants for language and region. -
setupOutputStream
public static void setupOutputStream()RedirectsSystem.outto a customPrintStreaminstance to support UTF-8 or enhanced terminal features. -
setupErrorStream
public static void setupErrorStream()RedirectsSystem.errto a customPrintStreaminstance. -
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.WINCHsignal handler.- Parameters:
terminal- the terminal instance to monitor
-
setupTerminalWidthAndHeight
Updates the system propertiesTERMINAL_WIDTH_PROPERTYandTERMINAL_HEIGHT_PROPERTYusing 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 givenTerminalinstance.- 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 temporaryTerminalinstance.If an exception occurs during terminal initialization, returns default fallback dimensions (80x24).
- Returns:
- an array with two elements: [width, height]
-