Documentation ¶
Index ¶
- Variables
- func CombineStyles(base lipgloss.Style, additional ...lipgloss.Style) (style lipgloss.Style)
- func MergeStyles(base lipgloss.Style, additional ...lipgloss.Style) lipgloss.Style
- type Colors
- type Flag
- type Option
- func WithBodyColor(color lipgloss.TerminalColor) Option
- func WithExtraColor(name string, color lipgloss.TerminalColor) Option
- func WithExtraColors(extras map[string]lipgloss.TerminalColor) Option
- func WithExtraStyle(name string, style lipgloss.Style) Option
- func WithExtraStyles(extras map[string]lipgloss.Style) Option
- func WithFlag(name string, setting Flag) Option
- func WithFlagOff(name string) Option
- func WithFlagOn(name string) Option
- func WithFlagUnset(name string) Option
- func WithLeadColor(color lipgloss.TerminalColor) Option
- func WithMergedExtraStyles(name string, styles ...lipgloss.Style) Option
- func WithPrimaryStyle(style lipgloss.Style) Option
- func WithSubtleColor(color lipgloss.TerminalColor) Option
- type Settings
- func (settings *Settings) AppliedExtraStyles(extras ...string) (appliedStyle lipgloss.Style)
- func (settings *Settings) ExtraColor(name string) lipgloss.TerminalColor
- func (settings *Settings) Flag(name string) Flag
- func (settings *Settings) RemoveFlag(name string)
- func (settings *Settings) SetFlag(name string, setting Flag)
- func (settings *Settings) SetFlagOff(name string)
- func (settings *Settings) SetFlagOn(name string)
- func (settings *Settings) UnsetFlag(name string)
- type Styles
Constants ¶
This section is empty.
Variables ¶
var ( // The flag is set to be on FlagOn = Flag(&on) // The flag is set to be off FlagOff = Flag(&off) // The Flag is not explicitly set FlagUnset = Flag(nil) )
Functions ¶
func CombineStyles ¶
This helper function copies the base style and inherits the remaining styles in order, extending the copied style but not overwriting any settings, before returning the combined style. The additional styles are inherited in the order they are given, so the first style to specify a setting (base or additional) wins out. Because the styles are applied to a copy of the base style, they do not modify it at all.
func MergeStyles ¶
This helper function starts with the base style and inherits the remaining styles in order, extending the base style but not overwriting any settings, before returning the merged style. The additional styles are inherited in the order they are given, so the first style to specify a setting (base or additional) wins out. Because the styles are applied to the base style, they modify it in place as well as return the merged style to the caller.
Types ¶
type Colors ¶
type Colors struct { // Use the Subtle color whenever you want to deemphasize text. Subtle lipgloss.TerminalColor // Use the Lead color for headings and other more-important text. Lead lipgloss.TerminalColor // Use the Body color as the default for general text. Body lipgloss.TerminalColor // Use extra to hold an custom list of colors by name for use. Extra map[string]lipgloss.TerminalColor }
The Colors struct provides a semantic way to access various colors for terminal settings.
type Flag ¶
type Flag *bool
Flags represent arbitrary behavior toggles for terminal settings. A Flag can be set to on, set to off, or unset. The value of a flagged setting can be checked to change behavior when dealing with the terminal.
func FlagFromBool ¶
FlagFromBool converts a boolean value into a valid Flag, returning On if true and Off if false.
type Option ¶
type Option func(settings *Settings)
An Option returns a function which modifies a Settings object. Options provide a friendlier UX for creating settings.
func WithBodyColor ¶
func WithBodyColor(color lipgloss.TerminalColor) Option
This terminal settings option sets the body color for a new instance of terminal settings.
func WithExtraColor ¶
func WithExtraColor(name string, color lipgloss.TerminalColor) Option
This terminal settings option adds an extra color to a new instance of terminal settings or updates the color if it has already been added to the map. This can be used to extend/modify the list of extra colors safely in a loop.
func WithExtraColors ¶
func WithExtraColors(extras map[string]lipgloss.TerminalColor) Option
This terminal settings option sets the extra colors for a new instance of terminal settings to exactly the map that you pass to it; if this option is applied after any others which modify the extra colors, it replaces all of them.
func WithExtraStyle ¶
This terminal settings option adds an extra style to a new instance of terminal settings or updates the style if it has already been added to the map. This can be used to extend/modify the list of extra styles safely in a loop.
func WithExtraStyles ¶
This terminal settings option sets the extra styles for a new instance of terminal settings to exactly the map that you pass to it; if this option is applied after any others which modify the extra styles, it replaces all of them.
func WithFlag ¶
A terminal settings option to add a flag by name and value to the list of flags for that setting. If the flag already exists, this option will override it.
func WithFlagOff ¶
A shorthand option for specifying that a flag should be set to off for an instance of terminal settings.
func WithFlagOn ¶
A shorthand option for specifying that a flag should be set to on for an instance of terminal settings.
func WithFlagUnset ¶
A shorthand option for specifying that a flag should be registered as unset for an instance of terminal settings.
func WithLeadColor ¶
func WithLeadColor(color lipgloss.TerminalColor) Option
This terminal settings option sets the lead color for a new instance of terminal settings.
func WithMergedExtraStyles ¶
This terminal settings option takes multiple styles and merges them into one, adding them as an extra style with the given name to a new instance of terminal settings. If the name already exists in the list of extra styles, the new styles will be inherited to it, extending the style but not overwriting it.
func WithPrimaryStyle ¶
This terminal settings option sets the primary style for a new instance of terminal settings.
func WithSubtleColor ¶
func WithSubtleColor(color lipgloss.TerminalColor) Option
This terminal settings option sets the subtle color for a new instance of terminal settings.
type Settings ¶
type Settings struct { // Provides a semantic way to retrieve lipgloss styles for use when printing to the terminal Styles Styles // Provides a semantic way to retrieve lipgloss colors for use when printing to the terminal Colors Colors // Provides a way to specify settings to change the behavior of terminal-rendering functions dynamically. Flags map[string]Flag }
Configuration for how a given object should be printed to the terminal
func New ¶
Creates a new Settings object, ensuring the maps for flags and extra colors/styles exist. Applies specified options in the order they are specified (if they conflict, last option applies).
func (*Settings) AppliedExtraStyles ¶
The AppliedExtraStyles method copies the primary style and then merges all of the specified extra styles from the map of extra styles in the Settings, creating and returning a new style made from inheriting the extra styles in the order they were specified onto a copy of the Primary style.
func (*Settings) ExtraColor ¶
func (settings *Settings) ExtraColor(name string) lipgloss.TerminalColor
Return an extra color from an instance of terminal settings by name.
func (*Settings) Flag ¶
Retrieve the current state of a flag by name from an instance of terminal settings. If the flag cannot be found, it is treated as being unset.
func (*Settings) RemoveFlag ¶
Remove a flag entirely from an existing instance of terminal settings.
func (*Settings) SetFlagOff ¶
Helper function to set a flag as Off for an existing instance of terminal settings.