terminal

package
v0.0.0-...-8b058bf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func CombineStyles(base lipgloss.Style, additional ...lipgloss.Style) (style lipgloss.Style)

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

func MergeStyles(base lipgloss.Style, additional ...lipgloss.Style) lipgloss.Style

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

func FlagFromBool(value bool) (flag Flag)

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

func WithExtraStyle(name string, style lipgloss.Style) Option

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

func WithExtraStyles(extras map[string]lipgloss.Style) Option

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

func WithFlag(name string, setting Flag) Option

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

func WithFlagOff(name string) Option

A shorthand option for specifying that a flag should be set to off for an instance of terminal settings.

func WithFlagOn

func WithFlagOn(name string) Option

A shorthand option for specifying that a flag should be set to on for an instance of terminal settings.

func WithFlagUnset

func WithFlagUnset(name string) Option

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

func WithMergedExtraStyles(name string, styles ...lipgloss.Style) Option

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

func WithPrimaryStyle(style lipgloss.Style) Option

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

func New(options ...Option) (settings *Settings)

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

func (settings *Settings) AppliedExtraStyles(extras ...string) (appliedStyle lipgloss.Style)

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

func (settings *Settings) Flag(name string) 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

func (settings *Settings) RemoveFlag(name string)

Remove a flag entirely from an existing instance of terminal settings.

func (*Settings) SetFlag

func (settings *Settings) SetFlag(name string, setting Flag)

Sets a flag on an existing instance of terminal settings.

func (*Settings) SetFlagOff

func (settings *Settings) SetFlagOff(name string)

Helper function to set a flag as Off for an existing instance of terminal settings.

func (*Settings) SetFlagOn

func (settings *Settings) SetFlagOn(name string)

Helper function to set a flag as On for an existing instance of terminal settings.

func (*Settings) UnsetFlag

func (settings *Settings) UnsetFlag(name string)

Helper function to mark a flag as Unset for an existing instance of terminal settings.

type Styles

type Styles struct {
	// Use the primary style as your default
	Primary lipgloss.Style
	// Use extra styles to hold a named set of styles to apply
	Extra map[string]lipgloss.Style
}

The Colors struct provides a semantic way to access various colors for terminal settings.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL