Package picocli
Class CommandLine.Help.ColorScheme
- java.lang.Object
-
- picocli.CommandLine.Help.ColorScheme
-
- Enclosing class:
- CommandLine.Help
public static class CommandLine.Help.ColorScheme extends java.lang.ObjectAll usage help message are generated with a color scheme that assigns certain styles and colors to common parts of a usage message: the command name, options, positional parameters and option parameters. Users may customize these styles by creating Help with a custom color scheme.Note that these options and styles may not be rendered if ANSI escape codes are not enabled.
From 4.0, instances of this class are immutable.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCommandLine.Help.ColorScheme.BuilderBuilder class to createColorSchemeinstances.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CommandLine.Help.Ansiansi()Returns theAnsisetting of this color scheme.CommandLine.Help.Ansi.Textapply(java.lang.String plainText, java.util.List<CommandLine.Help.Ansi.IStyle> styles)Returns a new Text object where all the specified styles are applied to the full length of the specified plain text.java.util.List<CommandLine.Help.Ansi.IStyle>commandStyles()Returns the registered styles for commands in this color scheme.CommandLine.Help.Ansi.TextcommandText(java.lang.String command)Returns a Text with all command styles applied to the specified command string.java.util.Map<java.lang.String,CommandLine.Help.Ansi.IStyle>customMarkupMap()Returns the custom mapping from markup names (the names of theCommandLine.Help.Ansi.Styleenum constants, like bold, italic, fg_blue, bg_green, etc) toCommandLine.Help.Ansi.IStyleobjects in this color scheme.booleanequals(java.lang.Object obj)java.util.List<CommandLine.Help.Ansi.IStyle>errorStyles()Returns the registered styles for errors in this color scheme.CommandLine.Help.Ansi.TexterrorText(java.lang.String error)Returns a Text with all error styles applied to the specified error string.inthashCode()java.util.List<CommandLine.Help.Ansi.IStyle>optionParamStyles()Returns the registered styles for option parameters in this color scheme.CommandLine.Help.Ansi.TextoptionParamText(java.lang.String optionParam)Returns a Text with all optionParam styles applied to the specified optionParam string.java.util.List<CommandLine.Help.Ansi.IStyle>optionStyles()Returns the registered styles for options in this color scheme.CommandLine.Help.Ansi.TextoptionText(java.lang.String option)Returns a Text with all option styles applied to the specified option string.java.util.List<CommandLine.Help.Ansi.IStyle>parameterStyles()Returns the registered styles for positional parameters in this color scheme.CommandLine.Help.Ansi.TextparameterText(java.lang.String parameter)Returns a Text with all parameter styles applied to the specified parameter string.CommandLine.Help.Ansi.IStyle[]parse(java.lang.String commaSeparatedCodes)Converts the specified markup styles to an array ofCommandLine.Help.Ansi.IStyleobjects.CommandLine.Help.Ansi.IStyleresetStyle()Returns the style that "resets" the style state to neutral.java.lang.StringrichStackTraceString(java.lang.Throwable t)Returns a String with theerror stylesapplied to the stack trace lines showing the throwable class name and error message (including "Caused by:..." lines), and thestack trace stylesapplied to the remaining stack trace of lines the specified Throwable.java.util.List<CommandLine.Help.Ansi.IStyle>stackTraceStyles()Returns the registered styles for stack traces in this color scheme.CommandLine.Help.Ansi.TextstackTraceText(java.lang.String stackTrace)Returns a Text with all stackTrace styles applied to all lines in the specified stackTrace string.CommandLine.Help.Ansi.TextstackTraceText(java.lang.Throwable t)Returns a Text with all stackTrace styles applied to all lines in the stack trace of the specified Throwable.java.lang.Stringstring(java.lang.String stringWithMarkup)Returns a String where any markup like@|bg(red),white,underline some text|@is converted to the styles defined in this ColorScheme (if its Ansi mode is ON), or to the plain text without the markup (if this ColorScheme's Ansi mode is OFF).CommandLine.Help.Ansi.Texttext(java.lang.String stringWithMarkup)Returns a new Text object for this ColorScheme, encapsulating the specified string which may contain markup like@|bg(red),white,underline some text|@.java.lang.StringtoString()
-
-
-
Method Detail
-
commandText
public CommandLine.Help.Ansi.Text commandText(java.lang.String command)
Returns a Text with all command styles applied to the specified command string.- Parameters:
command- the command string to apply the registered command styles to- Returns:
- a Text with all command styles applied to the specified command string
-
optionText
public CommandLine.Help.Ansi.Text optionText(java.lang.String option)
Returns a Text with all option styles applied to the specified option string.- Parameters:
option- the option string to apply the registered option styles to- Returns:
- a Text with all option styles applied to the specified option string
-
parameterText
public CommandLine.Help.Ansi.Text parameterText(java.lang.String parameter)
Returns a Text with all parameter styles applied to the specified parameter string.- Parameters:
parameter- the parameter string to apply the registered parameter styles to- Returns:
- a Text with all parameter styles applied to the specified parameter string
-
optionParamText
public CommandLine.Help.Ansi.Text optionParamText(java.lang.String optionParam)
Returns a Text with all optionParam styles applied to the specified optionParam string.- Parameters:
optionParam- the option parameter string to apply the registered option parameter styles to- Returns:
- a Text with all option parameter styles applied to the specified option parameter string
-
errorText
public CommandLine.Help.Ansi.Text errorText(java.lang.String error)
Returns a Text with all error styles applied to the specified error string.- Parameters:
error- the error string to apply the registered error styles to- Returns:
- a Text with all error styles applied to the specified error string
- Since:
- 4.3
-
stackTraceText
public CommandLine.Help.Ansi.Text stackTraceText(java.lang.String stackTrace)
Returns a Text with all stackTrace styles applied to all lines in the specified stackTrace string.- Parameters:
stackTrace- the stack trace string to apply the registered stack trace styles to- Returns:
- a Text with all stack trace styles applied to the specified stack trace string
- Since:
- 4.3
-
stackTraceText
public CommandLine.Help.Ansi.Text stackTraceText(java.lang.Throwable t)
Returns a Text with all stackTrace styles applied to all lines in the stack trace of the specified Throwable.- Parameters:
t- the Throwable whose stack trace string to apply the registered stack trace styles to- Returns:
- a Text with all stack trace styles applied to the stack trace of the specified Throwable
- Since:
- 4.5
-
richStackTraceString
public java.lang.String richStackTraceString(java.lang.Throwable t)
Returns a String with theerror stylesapplied to the stack trace lines showing the throwable class name and error message (including "Caused by:..." lines), and thestack trace stylesapplied to the remaining stack trace of lines the specified Throwable.- Parameters:
t- the Throwable whose stack trace string to apply the error and stack trace styles to- Returns:
- a String with error and stack trace styles applied to the stack trace of the specified Throwable
- Since:
- 4.5
-
ansi
public CommandLine.Help.Ansi ansi()
Returns theAnsisetting of this color scheme.
-
commandStyles
public java.util.List<CommandLine.Help.Ansi.IStyle> commandStyles()
Returns the registered styles for commands in this color scheme.- Since:
- 4.0
-
optionStyles
public java.util.List<CommandLine.Help.Ansi.IStyle> optionStyles()
Returns the registered styles for options in this color scheme.- Since:
- 4.0
-
parameterStyles
public java.util.List<CommandLine.Help.Ansi.IStyle> parameterStyles()
Returns the registered styles for positional parameters in this color scheme.- Since:
- 4.0
-
optionParamStyles
public java.util.List<CommandLine.Help.Ansi.IStyle> optionParamStyles()
Returns the registered styles for option parameters in this color scheme.- Since:
- 4.0
-
errorStyles
public java.util.List<CommandLine.Help.Ansi.IStyle> errorStyles()
Returns the registered styles for errors in this color scheme.- Since:
- 4.3
-
stackTraceStyles
public java.util.List<CommandLine.Help.Ansi.IStyle> stackTraceStyles()
Returns the registered styles for stack traces in this color scheme.- Since:
- 4.3
-
customMarkupMap
public java.util.Map<java.lang.String,CommandLine.Help.Ansi.IStyle> customMarkupMap()
Returns the custom mapping from markup names (the names of theCommandLine.Help.Ansi.Styleenum constants, like bold, italic, fg_blue, bg_green, etc) toCommandLine.Help.Ansi.IStyleobjects in this color scheme. By default this returns an empty map, unless a custom map was configured.- Since:
- 4.2
-
parse
public CommandLine.Help.Ansi.IStyle[] parse(java.lang.String commaSeparatedCodes)
Converts the specified markup styles to an array ofCommandLine.Help.Ansi.IStyleobjects. If no custom markup mapping is specified, this method delegates toCommandLine.Help.Ansi.Style.parse(String), otherwise it returns the styles found in the custom mapping for the specified markup styles.- Parameters:
commaSeparatedCodes- a string with a comma-separated list of markup styles (for example,"bold,underline,bg_red"- Since:
- 4.2
-
resetStyle
public CommandLine.Help.Ansi.IStyle resetStyle()
Returns the style that "resets" the style state to neutral.- Returns:
CommandLine.Help.Ansi.Style.resetif no customMarkupMap() is defined, otherwise either the style registered with the "reset" name or an emptyIStyleif no such style is registered.- Since:
- 4.2
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
apply
public CommandLine.Help.Ansi.Text apply(java.lang.String plainText, java.util.List<CommandLine.Help.Ansi.IStyle> styles)
Returns a new Text object where all the specified styles are applied to the full length of the specified plain text.- Parameters:
plainText- the string to apply all styles to. Must not contain markup!styles- the styles to apply to the full plain text- Returns:
- a new Text object
- Since:
- 4.2
-
text
public CommandLine.Help.Ansi.Text text(java.lang.String stringWithMarkup)
Returns a new Text object for this ColorScheme, encapsulating the specified string which may contain markup like@|bg(red),white,underline some text|@.Calling
toString()on the returned Text will convert the markup to the styles defined in this ColorScheme (if its Ansi mode is ON), or to the plain text without the markup (if this ColorScheme's Ansi mode is OFF).Equivalent to
this.ansi().new Text(stringWithMarkup, this).- Since:
- 4.2
- See Also:
CommandLine.Help.Ansi.text(String)
-
string
public java.lang.String string(java.lang.String stringWithMarkup)
Returns a String where any markup like@|bg(red),white,underline some text|@is converted to the styles defined in this ColorScheme (if its Ansi mode is ON), or to the plain text without the markup (if this ColorScheme's Ansi mode is OFF).Equivalent to
this.ansi().new Text(stringWithMarkup, this).toString().- Since:
- 4.2
- See Also:
CommandLine.Help.Ansi.string(String)
-
-