Class MessageUtils


  • public class MessageUtils
    extends java.lang.Object
    Colorized message support. Maven only needs ANSI colors in its log output, so there is no terminal library here: styles are emitted as plain SGR escape sequences, and only when color is enabled.
    • Constructor Summary

      Constructors 
      Constructor Description
      MessageUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static org.apache.maven.api.services.MessageBuilder builder()  
      static int getTerminalWidth()
      Returns the terminal width in columns, or -1 if unknown.
      static boolean isColorEnabled()  
      static boolean isTty()
      Returns true if systemInstall() detected an ANSI capable terminal on standard output.
      static void setColorEnabled​(boolean enabled)  
      static java.lang.String stripAnsiCodes​(java.lang.String msg)
      Remove any ANSI code from a message (colors or other escape sequences).
      static void systemInstall()
      Detects whether standard output is an ANSI capable terminal and enables color accordingly.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MessageUtils

        public MessageUtils()
    • Method Detail

      • systemInstall

        public static void systemInstall()
        Detects whether standard output is an ANSI capable terminal and enables color accordingly. Only the CLI calls this; embedded use never does, so "auto" color stays off there.
      • isTty

        public static boolean isTty()
        Returns true if systemInstall() detected an ANSI capable terminal on standard output.
      • setColorEnabled

        public static void setColorEnabled​(boolean enabled)
      • isColorEnabled

        public static boolean isColorEnabled()
      • getTerminalWidth

        public static int getTerminalWidth()
        Returns the terminal width in columns, or -1 if unknown. Taken from the COLUMNS environment variable if set, otherwise (on a detected non-Windows terminal) from stty size. Computed once.
      • builder

        public static org.apache.maven.api.services.MessageBuilder builder()
      • stripAnsiCodes

        public static java.lang.String stripAnsiCodes​(java.lang.String msg)
        Remove any ANSI code from a message (colors or other escape sequences).
        Parameters:
        msg - message eventually containing ANSI codes
        Returns:
        the message with ANSI codes removed