Package org.apache.maven.cli.jansi
Class MessageUtils
java.lang.Object
org.apache.maven.cli.jansi.MessageUtils
Colored message utils, to manage colors. This is the core implementation of the
JansiMessageBuilderFactory and JansiMessageBuilder classes.
This class should not be used outside of maven-embedder and the public
MessageBuilderFactory should be used instead.
Internally, Jansi is used to render ANSI colors on any platform.
- Since:
- 4.0.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic MessageBuilderbuilder()Create a default message buffer.static MessageBuilderbuilder(int size) Create a message buffer with an internal buffer of defined size.static MessageBuilderbuilder(StringBuilder builder) Create a message buffer with defined String builder.static intGet the terminal width or -1 if the width cannot be determined.static booleanIs message color enabled: requires Jansi available (through Maven) and the color has not been disabled.static voidRegister a shutdown hook with the JVM runtime, uninstalling Ansi support on JVM shutdown unless is has already been uninstalled at that time.static voidsetColorEnabled(boolean flag) Enables message color (if Jansi is available).static StringstripAnsiCodes(String msg) Remove any ANSI code from a message (colors or other escape sequences).static voidInstall color support.static voidUndo a previoussystemInstall().
-
Constructor Details
-
MessageUtils
public MessageUtils()
-
-
Method Details
-
systemInstall
public static void systemInstall()Install color support. This method is called by Maven core, and calling it is not necessary in plugins. -
systemUninstall
public static void systemUninstall()Undo a previoussystemInstall(). IfsystemInstall()was called multiple times,systemUninstall()must be called call the same number of times before it is actually uninstalled. -
setColorEnabled
public static void setColorEnabled(boolean flag) Enables message color (if Jansi is available).- Parameters:
flag- to enable Jansi
-
isColorEnabled
public static boolean isColorEnabled()Is message color enabled: requires Jansi available (through Maven) and the color has not been disabled.- Returns:
- whether colored messages are enabled
-
builder
Create a default message buffer.- Returns:
- a new buffer
-
builder
Create a message buffer with an internal buffer of defined size.- Parameters:
size- size of the buffer- Returns:
- a new buffer
-
builder
Create a message buffer with defined String builder.- Parameters:
builder- initial content of the message buffer- Returns:
- a new buffer
-
stripAnsiCodes
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
-
registerShutdownHook
public static void registerShutdownHook()Register a shutdown hook with the JVM runtime, uninstalling Ansi support on JVM shutdown unless is has already been uninstalled at that time.Delegates to
doSystemUninstall()for the actual uninstall procedure- See Also:
-
Runtime.addShutdownHook(Thread)systemUninstall()doSystemUninstall()
-
getTerminalWidth
public static int getTerminalWidth()Get the terminal width or -1 if the width cannot be determined.- Returns:
- the terminal width
-