Documentation
¶
Overview ¶
Package color provides template functions for adding color to the command line output. It automatically detects whether the terminal supports color, and it contains conventions-based approaches for allowing the user to control whether color is used
Index ¶
- Constants
- func NewTemplateFuncs(modeopt ...Mode) map[string]any
- func RegisterTemplateFuncs(modeopt ...Mode) cli.Action
- func SetMode(modeopt ...Mode) cli.Action
- func SourceAnnotation() (string, string)
- func SynopsisColor(c cli.Color) cli.Action
- func SynopsisStyle(s cli.Style) cli.Action
- type ContextFilter
- type Emoji
- type Feature
- type Mode
- type Options
Constants ¶
const ( // FlagFeature enables the flag --color={auto|never|always} for enabling color. // The flag's value is optional, in which case its value is always FlagFeature = Feature(1 << iota) // NoFlagFeature enables the flag --no-color for disabling color NoFlagFeature // ModeFeature specifies that the --color flag accepts an optional value // that corresponds to the Mode value, either "auto", "always", or "never" // indicating how to handle color. ModeFeature // TemplateFuncs enables the template funcs feature, which provides template funcs // for colors and styles TemplateFuncs // AllFeatures enables all of the features. This is the default AllFeatures = -1 )
Variables ¶
This section is empty.
Functions ¶
func NewTemplateFuncs ¶ added in v0.13.0
NewTemplateFuncs gets the template funcs that support the given mode
func RegisterTemplateFuncs ¶
RegisterTemplateFuncs sets up the template funcs which can be used to activate color and styles. The common use is to pipe to the format function which has the same name as any of the Color and Style constants:
{{ "Text to make bold" | Bold }}
func SetMode ¶
SetMode returns an action that sets the color mode. If specified on a flag or argument, it provides the action for a Boolean or Mode value that controls whether color is set. The flag or arg must have Value that is either *bool or *Mode. The initializer sets *Mode if it is unset. If the argument modeopt is specified, the value will be used; otherwise, it will be obtained from the context.
func SourceAnnotation ¶
SourceAnnotation gets the name and value of the annotation added to the Data of all flags that are initialized from this package
func SynopsisColor ¶ added in v0.17.0
SynopsisColor returns an action, typically added to the Uses pipeline of a flag, command, or expression, that causes its name to be rendered in the synopsis using the given foreground color instead of the default Bold style. It sets a private data key that the synopsis package reads.
&cli.Flag{Uses: color.SynopsisColor(cli.Red)}
func SynopsisStyle ¶ added in v0.17.0
SynopsisStyle returns an action, typically added to the Uses pipeline of a flag, command, or expression, that causes its name to be rendered in the synopsis using the given style instead of the default Bold style. It sets a private data key that the synopsis package reads.
&cli.Flag{Uses: color.SynopsisStyle(cli.Underline)}
Types ¶
type ContextFilter ¶ added in v0.12.0
type ContextFilter int
ContextFilter provides the context filters in this package
const ( // Defines provides a context filter for flags defined by this package Defines ContextFilter = 0 )
func (ContextFilter) Describe ¶ added in v0.12.0
func (f ContextFilter) Describe() string
Describe produces a representation of the context filter suitable for use in messages
func (ContextFilter) MarshalText ¶ added in v0.12.0
func (f ContextFilter) MarshalText() ([]byte, error)
MarshalText provides the textual representation
func (ContextFilter) Matches ¶ added in v0.12.0
func (f ContextFilter) Matches(ctx context.Context) bool
func (ContextFilter) String ¶ added in v0.12.0
func (f ContextFilter) String() string
String produces a textual representation of the context filter
func (*ContextFilter) UnmarshalText ¶ added in v0.12.0
func (f *ContextFilter) UnmarshalText(b []byte) error
UnmarshalText converts the textual representation