Documentation ¶
Overview ¶
Package sgr provides facilities for dealing with CSI/SGR ANSI Escape Sequences in a convenient way.
ANSI Escape Sequences are defined in ECMA-48 standard and then extended in ISO 8613-6 [CCITT Recommendation T.416]).
Index ¶
- Constants
- type BasicColor
- func (c BasicColor) Bright() BasicColor
- func (c BasicColor) Color() Color
- func (c BasicColor) MarshalText() ([]byte, error)
- func (c BasicColor) Normal() BasicColor
- func (c BasicColor) PaletteColor() PaletteColor
- func (c BasicColor) String() string
- func (c *BasicColor) UnmarshalText(data []byte) error
- func (c BasicColor) Validate() error
- func (c BasicColor) WithBrightness(b Brightness) BasicColor
- type Brightness
- type Color
- func (c Color) AsBasicColor() BasicColor
- func (c Color) AsDefaultColor() DefaultColor
- func (c Color) AsPaletteColor() PaletteColor
- func (c Color) AsRGBColor() RGBColor
- func (c Color) BasicColor() (BasicColor, bool)
- func (c Color) Color() Color
- func (c Color) DefaultColor() (DefaultColor, bool)
- func (c Color) IsBasicColor() bool
- func (c Color) IsDefaultColor() bool
- func (c Color) IsPaletteColor() bool
- func (c Color) IsRGBColor() bool
- func (c Color) IsZero() bool
- func (c Color) MarshalText() ([]byte, error)
- func (c Color) OrDefault() Color
- func (c Color) PaletteColor() (PaletteColor, bool)
- func (c Color) RGBColor() (RGBColor, bool)
- func (c Color) String() string
- func (c *Color) UnmarshalText(data []byte) error
- func (c Color) Validate() error
- type Command
- type CommandCode
- type DefaultColor
- type ErrInvalidBasicColorText
- type ErrInvalidBasicColorValue
- type ErrInvalidBrightnessText
- type ErrInvalidBrightnessValue
- type ErrInvalidColorText
- type ErrInvalidColorValue
- type ErrInvalidDefaultColorText
- type ErrInvalidModeText
- type ErrInvalidModeValue
- type ErrInvalidPaletteColorText
- type ErrInvalidRGBColorText
- type IntoColor
- type Mode
- type ModeAction
- type ModeList
- type ModeSet
- func (s ModeSet) Diff(other ModeSet) ModeSetDiff
- func (s ModeSet) Has(mode Mode) bool
- func (s ModeSet) IsEmpty() bool
- func (s ModeSet) IsZero() bool
- func (s ModeSet) ModeList() ModeList
- func (s ModeSet) With(mode Mode) ModeSet
- func (s ModeSet) WithOther(other ModeSet, action ModeAction) ModeSet
- func (s ModeSet) WithToggled(mode Mode) ModeSet
- func (s ModeSet) Without(mode Mode) ModeSet
- type ModeSetDiff
- type PaletteColor
- type RGBColor
- type Sequence
- type Writer
- func (w *Writer) Flush() error
- func (w *Writer) PopBackgroundColor()
- func (w *Writer) PopForegroundColor()
- func (w *Writer) PopModes()
- func (w *Writer) PopUnderlineColor()
- func (w *Writer) PushBackgroundColor(color IntoColor)
- func (w *Writer) PushForegroundColor(color IntoColor)
- func (w *Writer) PushModes(modes ModeSet, action ModeAction)
- func (w *Writer) PushUnderlineColor(color IntoColor)
- func (w *Writer) Reset()
- func (w *Writer) SetBackgroundColor(color IntoColor)
- func (w *Writer) SetForegroundColor(color IntoColor)
- func (w *Writer) SetModes(modes ModeSet, action ModeAction)
- func (w *Writer) SetUnderlineColor(color IntoColor)
- func (w *Writer) Write(data []byte) (n int, err error)
Constants ¶
const ( ResetAll = commandValid | Command(CodeResetAll) SetBold = commandValid | Command(CodeSetBold) SetFaint = commandValid | Command(CodeSetFaint) SetItalic = commandValid | Command(CodeSetItalic) SetUnderlined = commandValid | Command(CodeSetUnderlined) SetSlowBlink = commandValid | Command(CodeSetSlowBlink) SetRapidBlink = commandValid | Command(CodeSetRapidBlink) SetReversed = commandValid | Command(CodeSetReversed) SetConcealed = commandValid | Command(CodeSetConcealed) SetCrossedOut = commandValid | Command(CodeSetCrossedOut) SetDoublyUnderlined = commandValid | Command(CodeSetDoublyUnderlined) ResetBoldAndFaint = commandValid | Command(CodeResetBoldAndFaint) ResetItalic = commandValid | Command(CodeResetItalic) ResetAllUnderlines = commandValid | Command(CodeResetAllUnderlines) ResetAllBlinks = commandValid | Command(CodeResetAllBlinks) ResetReversed = commandValid | Command(CodeResetReversed) ResetConcealed = commandValid | Command(CodeResetConcealed) ResetCrossedOut = commandValid | Command(CodeResetCrossedOut) SetForegroundColorBlack = commandValid | Command(CodeSetForegroundColorBlack) SetForegroundColorRed = commandValid | Command(CodeSetForegroundColorRed) SetForegroundColorGreen = commandValid | Command(CodeSetForegroundColorGreen) SetForegroundColorYellow = commandValid | Command(CodeSetForegroundColorYellow) SetForegroundColorBlue = commandValid | Command(CodeSetForegroundColorBlue) SetForegroundColorMagenta = commandValid | Command(CodeSetForegroundColorMagenta) SetForegroundColorCyan = commandValid | Command(CodeSetForegroundColorCyan) SetForegroundColorWhite = commandValid | Command(CodeSetForegroundColorWhite) ResetForegroundColor = commandValid | Command(CodeResetForegroundColor) SetBackgroundColorBlack = commandValid | Command(CodeSetBackgroundColorBlack) SetBackgroundColorRed = commandValid | Command(CodeSetBackgroundColorRed) SetBackgroundColorGreen = commandValid | Command(CodeSetBackgroundColorGreen) SetBackgroundColorYellow = commandValid | Command(CodeSetBackgroundColorYellow) SetBackgroundColorBlue = commandValid | Command(CodeSetBackgroundColorBlue) SetBackgroundColorMagenta = commandValid | Command(CodeSetBackgroundColorMagenta) SetBackgroundColorCyan = commandValid | Command(CodeSetBackgroundColorCyan) SetBackgroundColorWhite = commandValid | Command(CodeSetBackgroundColorWhite) ResetBackgroundColor = commandValid | Command(CodeResetBackgroundColor) SetFramed = commandValid | Command(CodeSetFramed) SetEncircled = commandValid | Command(CodeSetEncircled) SetOverlined = commandValid | Command(CodeSetOverlined) ResetFramedAndEncircled = commandValid | Command(CodeResetFramedAndEncircled) ResetOverlined = commandValid | Command(CodeResetOverlined) ResetUnderlineColor = commandValid | Command(CodeResetUnderlineColor) SetSuperscript = commandValid | Command(CodeSetSuperscript) SetSubscript = commandValid | Command(CodeSetSubscript) ResetSuperscriptAndSubscript = commandValid | Command(CodeResetSuperscriptAndSubscript) SetForegroundColorBrightBlack = commandValid | Command(CodeSetForegroundColorBrightBlack) SetForegroundColorBrightRed = commandValid | Command(CodeSetForegroundColorBrightRed) SetForegroundColorBrightGreen = commandValid | Command(CodeSetForegroundColorBrightGreen) SetForegroundColorBrightYellow = commandValid | Command(CodeSetForegroundColorBrightYellow) SetForegroundColorBrightBlue = commandValid | Command(CodeSetForegroundColorBrightBlue) SetForegroundColorBrightMagenta = commandValid | Command(CodeSetForegroundColorBrightMagenta) SetForegroundColorBrightCyan = commandValid | Command(CodeSetForegroundColorBrightCyan) SetForegroundColorBrightWhite = commandValid | Command(CodeSetForegroundColorBrightWhite) SetBackgroundColorBrightBlack = commandValid | Command(CodeSetBackgroundColorBrightBlack) SetBackgroundColorBrightRed = commandValid | Command(CodeSetBackgroundColorBrightRed) SetBackgroundColorBrightGreen = commandValid | Command(CodeSetBackgroundColorBrightGreen) SetBackgroundColorBrightYellow = commandValid | Command(CodeSetBackgroundColorBrightYellow) SetBackgroundColorBrightBlue = commandValid | Command(CodeSetBackgroundColorBrightBlue) SetBackgroundColorBrightMagenta = commandValid | Command(CodeSetBackgroundColorBrightMagenta) SetBackgroundColorBrightCyan = commandValid | Command(CodeSetBackgroundColorBrightCyan) SetBackgroundColorBrightWhite = commandValid | Command(CodeSetBackgroundColorBrightWhite) )
Complete set of simple SGR commands without arguments.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BasicColor ¶
type BasicColor uint8
BasicColor is a value from the most widely supported color set that was originally defined in ECMA-48 standard.
const ( Black BasicColor = 0 Red BasicColor = 1 Green BasicColor = 2 Yellow BasicColor = 3 Blue BasicColor = 4 Magenta BasicColor = 5 Cyan BasicColor = 6 White BasicColor = 7 BrightBlack BasicColor = 8 BrightRed BasicColor = 9 BrightGreen BasicColor = 10 BrightYellow BasicColor = 11 BrightBlue BasicColor = 12 BrightMagenta BasicColor = 13 BrightCyan BasicColor = 14 BrightWhite BasicColor = 15 )
Complete set of valid BasicColor values.
func (BasicColor) Bright ¶
func (c BasicColor) Bright() BasicColor
Bright returns a counter-part color that has Bright brightness or just c if it already has Bright brightness.
func (BasicColor) Color ¶
func (c BasicColor) Color() Color
Color converts c to a uniform Color value that can be used in all functions dealing with colors.
func (BasicColor) MarshalText ¶
func (c BasicColor) MarshalText() ([]byte, error)
MarshalText implements encoding.TextMarshaler interface that allows BasicColor to be used in any compatible marshaler like JSON, YAML, etc.
func (BasicColor) Normal ¶
func (c BasicColor) Normal() BasicColor
Normal returns a counter-part color that has Normal brightness or just c if it already has Normal brightness.
func (BasicColor) PaletteColor ¶
func (c BasicColor) PaletteColor() PaletteColor
PaletteColor converts c to PaletteColor. Palette colors are backward-compatible with basic color because its first 16 colors have the same codes and meaning.
func (BasicColor) String ¶
func (c BasicColor) String() string
String returns textual description of c that can be used for debugging or logging purposes.
func (*BasicColor) UnmarshalText ¶
func (c *BasicColor) UnmarshalText(data []byte) error
UnmarshalText implements encoding.TextUnmarshaler interface that allows BasicColor to be used in any compatible unmarshaler like JSON, YAML, etc.
func (BasicColor) Validate ¶
func (c BasicColor) Validate() error
Validate check that c has a valid value that is one of the values defined by the ECMA-48 standard.
func (BasicColor) WithBrightness ¶
func (c BasicColor) WithBrightness(b Brightness) BasicColor
WithBrightness ensures c has requested brightness and returns it or returns a counter-part color that has the requested brightness.
type Brightness ¶
type Brightness uint8
Brightness defines brightness of a BasicColor value.
const ( Normal Brightness = iota Bright )
Complete set of valid Brightness values .
func (Brightness) MarshalText ¶
func (b Brightness) MarshalText() ([]byte, error)
MarshalText implements encoding.TextMarshaler interface that allows Brightness to be used in any compatible marshaler like JSON, YAML, etc.
func (Brightness) String ¶
func (b Brightness) String() string
String returns textual description of b that can be used for debugging or logging purposes.
func (*Brightness) UnmarshalText ¶
func (b *Brightness) UnmarshalText(text []byte) error
UnmarshalText implements encoding.TextUnmarshaler interface that allows Brightness to be used in any compatible unmarshaler like JSON, YAML, etc.
func (Brightness) Validate ¶
func (b Brightness) Validate() error
Validate check that b has a valid value that is one of the valid values.
type Color ¶
type Color uint32
Color is a uniform color value that can represent a BasicColor, DefaultColor, PaletteColor or RGBColor.
func (Color) AsBasicColor ¶
func (c Color) AsBasicColor() BasicColor
AsBasicColor converts c to BasicColor or panics if c does not represent a BasicColor.
func (Color) AsDefaultColor ¶
func (c Color) AsDefaultColor() DefaultColor
AsDefaultColor converts c to DefaultColor or panics if c does not represent a DefaultColor.
func (Color) AsPaletteColor ¶
func (c Color) AsPaletteColor() PaletteColor
AsPaletteColor converts c to PaletteColor or panics if c does not represent a PaletteColor.
func (Color) AsRGBColor ¶
AsRGBColor converts c to RGBColor or panics if c does not represent a RGBColor.
func (Color) BasicColor ¶
func (c Color) BasicColor() (BasicColor, bool)
BasicColor returns a BasicColor and true if c represents a BasicColor value or zero value and false otherwise.
func (Color) Color ¶
Color implements IntoColor interface that is needed to avoid explicit type conversions.
func (Color) DefaultColor ¶
func (c Color) DefaultColor() (DefaultColor, bool)
DefaultColor returns a DefaultColor and true if c represents a DefaultColor value or zero value and false otherwise.
func (Color) IsBasicColor ¶
IsBasicColor returns true if c represents a BasicColor value.
func (Color) IsDefaultColor ¶
IsDefaultColor returns true if c represents a DefaultColor value.
func (Color) IsPaletteColor ¶
IsPaletteColor returns true if c represents a PaletteColor value.
func (Color) IsRGBColor ¶
IsRGBColor returns true if c represents a RGBColor value.
func (Color) IsZero ¶
IsZero returns true if c is zero-initialized value that can be treated as nil.
func (Color) MarshalText ¶
MarshalText implements encoding.TextMarshaler interface that allows Color to be used in any compatible marshaler like JSON, YAML, etc.
func (Color) PaletteColor ¶
func (c Color) PaletteColor() (PaletteColor, bool)
PaletteColor returns a PaletteColor and true if c represents a PaletteColor value or zero value and false otherwise.
func (Color) RGBColor ¶
RGBColor returns a RGBColor and true if c represents a RGBColor value or zero value and false otherwise.
func (Color) String ¶
String returns textual description of c that can be used for debugging or logging purposes.
func (*Color) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler interface that allows Color to be used in any compatible unmarshaler like JSON, YAML, etc.
type Command ¶
type Command uint64
Command is an SGR command that can be used to control terminal's SGR (Select Graphic Rendition) parameters.
func SetBackgroundColor ¶
SetBackgroundColor returns a command that will change background color when sent to a terminal in as part of a Sequence.
func SetForegroundColor ¶
SetForegroundColor returns a command that will change foreground color when sent to a terminal in as part of a Sequence.
func SetUnderlineColor ¶
SetUnderlineColor returns a command that will change underline color when sent to a terminal in as part of a Sequence.
func (Command) Code ¶
func (c Command) Code() CommandCode
Code returns the code of the command leaving aside its possible arguments.
type CommandCode ¶
type CommandCode uint8
CommandCode is the value of first octet of an SGR command.
const ( CodeResetAll CommandCode = 0 CodeSetBold CommandCode = 1 CodeSetFaint CommandCode = 2 CodeSetItalic CommandCode = 3 CodeSetUnderlined CommandCode = 4 CodeSetSlowBlink CommandCode = 5 CodeSetRapidBlink CommandCode = 6 CodeSetReversed CommandCode = 7 CodeSetConcealed CommandCode = 8 CodeSetCrossedOut CommandCode = 9 CodeSetDoublyUnderlined CommandCode = 21 CodeResetBoldAndFaint CommandCode = 22 CodeResetItalic CommandCode = 23 CodeResetAllUnderlines CommandCode = 24 CodeResetAllBlinks CommandCode = 25 CodeResetReversed CommandCode = 27 CodeResetConcealed CommandCode = 28 CodeResetCrossedOut CommandCode = 29 CodeSetForegroundColorBlack CommandCode = 30 CodeSetForegroundColorRed CommandCode = 31 CodeSetForegroundColorGreen CommandCode = 32 CodeSetForegroundColorYellow CommandCode = 33 CodeSetForegroundColorBlue CommandCode = 34 CodeSetForegroundColorMagenta CommandCode = 35 CodeSetForegroundColorCyan CommandCode = 36 CodeSetForegroundColorWhite CommandCode = 37 CodeSetForegroundColor CommandCode = 38 CodeResetForegroundColor CommandCode = 39 CodeSetBackgroundColorBlack CommandCode = 40 CodeSetBackgroundColorRed CommandCode = 41 CodeSetBackgroundColorGreen CommandCode = 42 CodeSetBackgroundColorYellow CommandCode = 43 CodeSetBackgroundColorBlue CommandCode = 44 CodeSetBackgroundColorMagenta CommandCode = 45 CodeSetBackgroundColorCyan CommandCode = 46 CodeSetBackgroundColorWhite CommandCode = 47 CodeSetBackgroundColor CommandCode = 48 CodeResetBackgroundColor CommandCode = 49 CodeSetFramed CommandCode = 51 CodeSetEncircled CommandCode = 52 CodeSetOverlined CommandCode = 53 CodeResetFramedAndEncircled CommandCode = 54 CodeResetOverlined CommandCode = 55 CodeSetUnderlineColor CommandCode = 58 CodeResetUnderlineColor CommandCode = 59 CodeSetSuperscript CommandCode = 73 CodeSetSubscript CommandCode = 74 CodeResetSuperscriptAndSubscript CommandCode = 75 CodeSetForegroundColorBrightBlack CommandCode = 90 CodeSetForegroundColorBrightRed CommandCode = 91 CodeSetForegroundColorBrightGreen CommandCode = 92 CodeSetForegroundColorBrightYellow CommandCode = 93 CodeSetForegroundColorBrightBlue CommandCode = 94 CodeSetForegroundColorBrightMagenta CommandCode = 95 CodeSetForegroundColorBrightCyan CommandCode = 96 CodeSetForegroundColorBrightWhite CommandCode = 97 CodeSetBackgroundColorBrightBlack CommandCode = 100 CodeSetBackgroundColorBrightRed CommandCode = 101 CodeSetBackgroundColorBrightGreen CommandCode = 102 CodeSetBackgroundColorBrightYellow CommandCode = 103 CodeSetBackgroundColorBrightBlue CommandCode = 104 CodeSetBackgroundColorBrightMagenta CommandCode = 105 CodeSetBackgroundColorBrightCyan CommandCode = 106 CodeSetBackgroundColorBrightWhite CommandCode = 107 )
Complete set of supported CommandCode values.
func (CommandCode) String ¶
func (c CommandCode) String() string
String returns textual description of c that can be used for debugging or logging purposes.
type DefaultColor ¶
type DefaultColor struct{}
DefaultColor is the default color defined by the terminal.
var Default DefaultColor
Default is a value of DefaultColor type. It can be used to reset color to the default color defined by the terminal.
func (DefaultColor) Color ¶
func (DefaultColor) Color() Color
Color returns a uniform Color value having the same meaning that can be used in all functions dealing with colors.
func (DefaultColor) MarshalText ¶
func (DefaultColor) MarshalText() ([]byte, error)
MarshalText implements encoding.TextMarshaler interface that allows DefaultColor to be used in any compatible marshaler like JSON, YAML, etc.
func (DefaultColor) String ¶
func (DefaultColor) String() string
String returns textual description of c that can be used for debugging or logging purposes.
func (DefaultColor) UnmarshalText ¶
func (DefaultColor) UnmarshalText(data []byte) error
UnmarshalText implements encoding.TextUnmarshaler interface that allows DefaultColor to be used in any compatible unmarshaler like JSON, YAML, etc.
type ErrInvalidBasicColorText ¶
type ErrInvalidBasicColorText struct {
Value string
}
ErrInvalidBasicColorText is an error that occurs in case of parsing an invalid textual representation of BasicColor.
func (ErrInvalidBasicColorText) Error ¶
func (e ErrInvalidBasicColorText) Error() string
Error returns the error message.
func (ErrInvalidBasicColorText) Is ¶
func (e ErrInvalidBasicColorText) Is(err error) bool
Is returns true if e is a sub-class of err.
type ErrInvalidBasicColorValue ¶
type ErrInvalidBasicColorValue struct {
Value BasicColor
}
ErrInvalidBasicColorValue is an error that occurs in case explicit validation or marshaling discovers an invalid value.
func (ErrInvalidBasicColorValue) Error ¶
func (e ErrInvalidBasicColorValue) Error() string
Error returns the error message.
func (ErrInvalidBasicColorValue) Is ¶
func (e ErrInvalidBasicColorValue) Is(err error) bool
Is returns true if e is a sub-class of err.
type ErrInvalidBrightnessText ¶
type ErrInvalidBrightnessText struct {
Value string
}
ErrInvalidBrightnessText is an error that occurs in case of parsing an invalid textual representation of Brightness.
func (ErrInvalidBrightnessText) Error ¶
func (e ErrInvalidBrightnessText) Error() string
Error returns the error message.
func (ErrInvalidBrightnessText) Is ¶
func (e ErrInvalidBrightnessText) Is(err error) bool
Is returns true if e is a sub-class of err.
type ErrInvalidBrightnessValue ¶
type ErrInvalidBrightnessValue struct {
Value Brightness
}
ErrInvalidBrightnessValue is an error that occurs in case explicit validation or marshaling discovers an invalid value.
func (ErrInvalidBrightnessValue) Error ¶
func (e ErrInvalidBrightnessValue) Error() string
Error returns the error message.
func (ErrInvalidBrightnessValue) Is ¶
func (e ErrInvalidBrightnessValue) Is(err error) bool
Is returns true if e is a sub-class of err.
type ErrInvalidColorText ¶
type ErrInvalidColorText struct { Value string // contains filtered or unexported fields }
ErrInvalidColorText is an error that occurs in case of parsing an invalid textual color representation.
func (ErrInvalidColorText) Error ¶
func (e ErrInvalidColorText) Error() string
Error returns the error message.
func (ErrInvalidColorText) Is ¶
func (e ErrInvalidColorText) Is(err error) bool
Is returns true if e is a sub-class of err.
func (ErrInvalidColorText) Unwrap ¶
func (e ErrInvalidColorText) Unwrap() error
Unwrap returns the underlying error.
type ErrInvalidColorValue ¶
type ErrInvalidColorValue struct {
Value Color
}
ErrInvalidColorValue is an error that occurs in case explicit validation or marshaling discovers an invalid value.
func (ErrInvalidColorValue) Error ¶
func (e ErrInvalidColorValue) Error() string
Error returns the error message.
func (ErrInvalidColorValue) Is ¶
func (e ErrInvalidColorValue) Is(err error) bool
Is returns true if e is a sub-class of err.
type ErrInvalidDefaultColorText ¶
type ErrInvalidDefaultColorText struct {
Value string
}
ErrInvalidDefaultColorText is an error that occurs in case of parsing an invalid textual representation of DefaultColor.
func (ErrInvalidDefaultColorText) Error ¶
func (e ErrInvalidDefaultColorText) Error() string
Error returns the error message.
func (ErrInvalidDefaultColorText) Is ¶
func (e ErrInvalidDefaultColorText) Is(err error) bool
Is returns true if e is a sub-class of err.
type ErrInvalidModeText ¶ added in v0.3.0
type ErrInvalidModeText struct {
Value string
}
ErrInvalidModeText is an error that occurs in case of parsing an invalid textual representation of Mode.
func (ErrInvalidModeText) Error ¶ added in v0.3.0
func (e ErrInvalidModeText) Error() string
Error returns the error message.
func (ErrInvalidModeText) Is ¶ added in v0.3.0
func (e ErrInvalidModeText) Is(err error) bool
Is returns true if e is a sub-class of err.
type ErrInvalidModeValue ¶ added in v0.3.0
type ErrInvalidModeValue struct {
Value Mode
}
ErrInvalidModeValue is an error that occurs in case explicit validation or marshaling discovers an invalid value.
func (ErrInvalidModeValue) Error ¶ added in v0.3.0
func (e ErrInvalidModeValue) Error() string
Error returns the error message.
func (ErrInvalidModeValue) Is ¶ added in v0.3.0
func (e ErrInvalidModeValue) Is(err error) bool
Is returns true if e is a sub-class of err.
type ErrInvalidPaletteColorText ¶
type ErrInvalidPaletteColorText struct {
Value string
}
ErrInvalidPaletteColorText is an error that occurs in case of parsing an invalid textual representation of PaletteColor.
func (ErrInvalidPaletteColorText) Error ¶
func (e ErrInvalidPaletteColorText) Error() string
Error returns the error message.
func (ErrInvalidPaletteColorText) Is ¶
func (e ErrInvalidPaletteColorText) Is(err error) bool
Is returns true if e is a sub-class of err.
type ErrInvalidRGBColorText ¶
type ErrInvalidRGBColorText struct {
Value string
}
ErrInvalidRGBColorText is an error that occurs in case of parsing an invalid textual representation of RGBColor.
func (ErrInvalidRGBColorText) Error ¶
func (e ErrInvalidRGBColorText) Error() string
Error returns the error message.
func (ErrInvalidRGBColorText) Is ¶
func (e ErrInvalidRGBColorText) Is(err error) bool
Is returns true if e is a sub-class of err.
type IntoColor ¶
type IntoColor interface {
Color() Color
}
IntoColor is an interface that can be used to uniformly accessing any color type.
type Mode ¶
type Mode uint8
Mode is flag number describing one of terminal modes supported by CSI/SGR sequences.
const ( Bold Mode = iota Faint Italic SlowBlink RapidBlink Reversed Concealed CrossedOut Underlined DoublyUnderlined Framed Encircled Overlined Superscript Subscript )
All supported Mode values.
func (Mode) MarshalText ¶ added in v0.3.0
MarshalText implements encoding.TextMarshaler interface that allows Mode to be used in any compatible marshaler like JSON, YAML, etc.
func (Mode) String ¶ added in v0.3.0
String returns textual description of m that can be used for debugging or logging purposes.
func (*Mode) UnmarshalText ¶ added in v0.3.0
UnmarshalText implements encoding.TextUnmarshaler interface that allows Mode to be used in any compatible unmarshaler like JSON, YAML, etc.
type ModeAction ¶
type ModeAction uint
ModeAction is an operation that can be applied to mode bits of a ModeSet when combining two ModeSet values.
const ( ModeReplace ModeAction = iota ModeAdd ModeRemove ModeToggle )
Valid values for ModeAction.
type ModeList ¶ added in v0.3.0
type ModeList []Mode
ModeList is a slice of Mode values.
func NewModeList ¶ added in v0.3.0
NewModeList constructs a new ModeList with the given modes.
type ModeSet ¶
type ModeSet uint16
ModeSet is a bit mask containing values for all Mode values.
func EmptyModeSet ¶ added in v0.3.0
func EmptyModeSet() ModeSet
EmptyModeSet constructs a new empty ModeSet.
func ModeSetWith ¶ added in v0.3.0
ModeSetWith constructs a new ModeSet with the given Mode values.
func (ModeSet) Diff ¶ added in v0.2.0
func (s ModeSet) Diff(other ModeSet) ModeSetDiff
Diff returns a ModeSetDiff with Old set to s and New set to other.
func (ModeSet) WithOther ¶
func (s ModeSet) WithOther(other ModeSet, action ModeAction) ModeSet
WithOther returns a new ModeSet that is combined with s according to the specified action.
func (ModeSet) WithToggled ¶
WithToggled returns a copy of ModeSet with specified mode bit changed to the opposite value.
type ModeSetDiff ¶ added in v0.2.0
ModeSetDiff contains Old and New mode sets and allows to generate a command sequence based on them.
func (ModeSetDiff) Added ¶ added in v0.3.0
func (d ModeSetDiff) Added() ModeSet
Added returns modes that present in New but are not present in Old.
func (ModeSetDiff) Changed ¶ added in v0.3.0
func (d ModeSetDiff) Changed() ModeSet
Changed returns modes that differ in Old and New.
func (ModeSetDiff) Removed ¶ added in v0.3.0
func (d ModeSetDiff) Removed() ModeSet
Removed returns modes that present in Old but are not present in New.
func (ModeSetDiff) Reversed ¶ added in v0.3.0
func (d ModeSetDiff) Reversed() ModeSetDiff
Reversed returns a reversed mode set where New and Old are swapped.
func (ModeSetDiff) ToCommands ¶ added in v0.2.0
func (d ModeSetDiff) ToCommands(seq Sequence) Sequence
ToCommands appends commands needed to bring old mode set to new mode set to seq and returns modified seq.
type PaletteColor ¶
type PaletteColor uint8
PaletteColor is a 256-color palette color code. First 16 colors a compatible with BasicColor codes.
func (PaletteColor) Color ¶
func (c PaletteColor) Color() Color
Color converts c to a uniform Color value having the same meaning that can be used in all functions dealing with colors.
func (PaletteColor) MarshalText ¶
func (c PaletteColor) MarshalText() ([]byte, error)
MarshalText implements encoding.TextMarshaler interface that allows PaletteColor to be used in any compatible marshaler like JSON, YAML, etc.
func (PaletteColor) String ¶
func (c PaletteColor) String() string
String returns textual description of c that can be used for debugging or logging purposes.
func (*PaletteColor) UnmarshalText ¶
func (c *PaletteColor) UnmarshalText(data []byte) error
UnmarshalText implements encoding.TextUnmarshaler interface that allows PaletteColor to be used in any compatible unmarshaler like JSON, YAML, etc.
type RGBColor ¶
type RGBColor uint32
RGBColor is a color represented by a combination of 8-bit brightness values of red, green and blue components.
func (RGBColor) Color ¶
Color converts c to a uniform Color value having the same meaning that can be used in all functions dealing with colors.
func (RGBColor) MarshalText ¶
MarshalText implements encoding.TextMarshaler interface that allows RGBColor to be used in any compatible marshaler like JSON, YAML, etc.
func (RGBColor) String ¶
String returns textual description of c that can be used for debugging or logging purposes.
func (*RGBColor) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler interface that allows RGBColor to be used in any compatible unmarshaler like JSON, YAML, etc.
type Sequence ¶
type Sequence []Command
Sequence is a sequence of commands.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer extends functionality of the target writer by adding methods for changing color and style using SGR commands.
Writer is using lazy approach for rendering SGR sequences that means it calculates an renders needed sequence only when its Write or Flush method is called. Until that only current values are remembered.
func (*Writer) Flush ¶
Flush just flushes current style changes by generating CSI/SGR sequence and writing it to the target writer. It is recommended to call Flush at the end of writing a line or a stream.
func (*Writer) PopBackgroundColor ¶
func (w *Writer) PopBackgroundColor()
PopBackgroundColor restores old background color that was saved at last PushBackgroundColor call.
func (*Writer) PopForegroundColor ¶
func (w *Writer) PopForegroundColor()
PopForegroundColor restores old foreground color that was saved at last PushForegroundColor call.
func (*Writer) PopModes ¶
func (w *Writer) PopModes()
PopModes restores old modes that were saved at last PushModes call.
func (*Writer) PopUnderlineColor ¶
func (w *Writer) PopUnderlineColor()
PopUnderlineColor restores old underline color that was saved at last PushUnderlineColor call.
func (*Writer) PushBackgroundColor ¶
PushBackgroundColor changes background color and pushes old value to a stack so that it can be restored using PopBackgroundColor method.
func (*Writer) PushForegroundColor ¶
PushForegroundColor changes foreground color and pushes old value to a stack so that it can be restored using PopForegroundColor method.
func (*Writer) PushModes ¶
func (w *Writer) PushModes(modes ModeSet, action ModeAction)
PushModes changes current modes using specified modes and action to calculate new modes and pushes old value to a stack so that it can be restored using PopModes method.
func (*Writer) PushUnderlineColor ¶
PushUnderlineColor changes underline color and pushes old value to a stack so that it can be restored using PopUnderlineColor method.
func (*Writer) Reset ¶
func (w *Writer) Reset()
Reset resets current SGR state to terminal defaults.
func (*Writer) SetBackgroundColor ¶
SetBackgroundColor changes current background color.
func (*Writer) SetForegroundColor ¶
SetForegroundColor changes current foreground color.
func (*Writer) SetModes ¶
func (w *Writer) SetModes(modes ModeSet, action ModeAction)
SetModes changes current modes using specified modes and action to calculate new modes.
func (*Writer) SetUnderlineColor ¶
SetUnderlineColor changes current underline color.