A simple package capable of adding color and styling to strings for output within seconds.
This struct stores all of the information for printing either the raw string, or the formatted form. Currently, colored strings can not be altered after creation, instead a new one must be generated.
- String() : Simply returns the unformatted, raw string of a
ColoredString
- ColorString() : Returns the fully formatted
ColoredString
A ColoredString
can be created several ways, incuding:
- NewColoredString(colorParts []ColoredPart) ColeredString : This takes an array of
ColoredPart
to manually construct aColoredString
- NewFormattedString(fStr string, formatArgs ...interface{}) ColoredString : This takes a printf-style set of arguments, however the formatArgs has several differences a user needs to be aware of:
- The format specifier used to denote a color is
$$
, rather than%$
, important to avoid errors during negation - Any color format args must be first in the formatArgs
- The format specifier used to denote a color is
- ColoredPrintf(fStr string, formatArgs ...interface{}) error : This directly prints the formatted
ColoredString
, rather than returning aColoredString
A simple structure representing a part of a ColoredString
, implements FormattedPart
Although useful when using NewColoredString
, this structure should otherwise be avoided in favor of ColoredString
methods when possible
This struct is one of the most powerful features of FyteColor, allowing for the reuse of formatting, while still allowing for customization.
Creating a TemplateString
is currently only possible by assembling a series of FormattedPart
. This is done using the NewTemplateString function.
- NewTemplateString(formatParts []FormattedPart) TemplateString : Takes an array of
FormattedPart
and returns a new TemplateString
- ToColorString(insertions ...string) ColoredString : Converts the
FormattedPart
array provided inNewTemplateString
into a fully formattedColoredString
, replacing theTemplatePart
with the provided insertions
Represents a replaceable section of a TemplateString
, implements FormattedPart
. This should be used in NewTemplateString
to add parts to the TemplateString
that should be later replaced by insertions.
Currently, the only way to create a TemplatePart
is by manually filling in the PartColor
and PartStyle
members of the struct. PartString
serves no purpose, as it will later be filled by an insertion when converting to a ColoredString
.
An interface representing important attributes for constructing ColoredString
. Types implementing this interface should contain a PartString
, PartColor
, and PartStyle
.
- Color() Color : Returns the
Color
of the currentFormattedPart
- Style() Style : Returns the
Style
of the currentFormattedPart
- RawString() string : Returns a raw, unformatted string for the
FormattedPart
I created this as just a side project for fun, and to help me learn the Go language (which is very nice). Because of this, feel free to both use and edit it.