sgr

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: MIT Imports: 5 Imported by: 1

README

sgr GoDoc Build Status Coverage Status

A package that provides helpers for dealing with ANSI CSI/SGR sequences.

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

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

func (c Color) AsRGBColor() RGBColor

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

func (c Color) 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

func (c Color) IsBasicColor() bool

IsBasicColor returns true if c represents a BasicColor value.

func (Color) IsDefaultColor

func (c Color) IsDefaultColor() bool

IsDefaultColor returns true if c represents a DefaultColor value.

func (Color) IsPaletteColor

func (c Color) IsPaletteColor() bool

IsPaletteColor returns true if c represents a PaletteColor value.

func (Color) IsRGBColor

func (c Color) IsRGBColor() bool

IsRGBColor returns true if c represents a RGBColor value.

func (Color) IsZero

func (c Color) IsZero() bool

IsZero returns true if c is zero-initialized value that can be treated as nil.

func (Color) MarshalText

func (c Color) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler interface that allows Color to be used in any compatible marshaler like JSON, YAML, etc.

func (Color) OrDefault

func (c Color) OrDefault() Color

OrDefault returns default color if c is zero otherwise it returns c.

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

func (c Color) RGBColor() (RGBColor, bool)

RGBColor returns a RGBColor and true if c represents a RGBColor value or zero value and false otherwise.

func (Color) String

func (c Color) String() string

String returns textual description of c that can be used for debugging or logging purposes.

func (*Color) UnmarshalText

func (c *Color) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler interface that allows Color to be used in any compatible unmarshaler like JSON, YAML, etc.

func (Color) Validate

func (c Color) Validate() error

Validate check if c has a valid value. Zero value is not considered an error, checks for zero value should be done explicitly.

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

func SetBackgroundColor(color IntoColor) Command

SetBackgroundColor returns a command that will change background color when sent to a terminal in as part of a Sequence.

func SetForegroundColor

func SetForegroundColor(color IntoColor) Command

SetForegroundColor returns a command that will change foreground color when sent to a terminal in as part of a Sequence.

func SetUnderlineColor

func SetUnderlineColor(color IntoColor) Command

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.

func (Command) IsZero

func (c Command) IsZero() bool

IsZero returns true if command is zero-initialized that actually also means the command is invalid. Zero commands are excluded from sequence during its rendition.

func (Command) String

func (c Command) String() string

String returns textual description of c that can be used for debugging or logging purposes.

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.

func (DefaultColor) Validate

func (DefaultColor) Validate() error

Validate always returns true.

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

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

Error returns the error message.

func (ErrInvalidBasicColorValue) Is

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

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

Error returns the error message.

func (ErrInvalidBrightnessValue) Is

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

Error returns the error message.

func (ErrInvalidDefaultColorText) Is

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

Error returns the error message.

func (ErrInvalidPaletteColorText) Is

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

func (m Mode) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler interface that allows Mode to be used in any compatible marshaler like JSON, YAML, etc.

func (Mode) ModeList added in v0.3.0

func (m Mode) ModeList() ModeList

ModeList converts m to a ModeList containing only m.

func (Mode) ModeSet

func (m Mode) ModeSet() ModeSet

ModeSet converts m to a ModeSet containing only m.

func (Mode) String added in v0.3.0

func (m Mode) String() string

String returns textual description of m that can be used for debugging or logging purposes.

func (*Mode) UnmarshalText added in v0.3.0

func (m *Mode) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler interface that allows Mode to be used in any compatible unmarshaler like JSON, YAML, etc.

func (Mode) Validate added in v0.3.0

func (m Mode) Validate() error

Validate check that m has a valid value.

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

func NewModeList(modes ...Mode) ModeList

NewModeList constructs a new ModeList with the given modes.

func (ModeList) ModeSet added in v0.3.0

func (l ModeList) ModeSet() ModeSet

ModeSet constructs a new ModeSet with the values in l.

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

func ModeSetWith(modes ...Mode) ModeSet

ModeSetWith constructs a new ModeSet with the given Mode values.

func NewModeSet

func NewModeSet() ModeSet

NewModeSet constructs a new empty ModeSet.

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) Has

func (s ModeSet) Has(mode Mode) bool

Has returns true if s includes mode.

func (ModeSet) IsEmpty added in v0.3.0

func (s ModeSet) IsEmpty() bool

IsEmpty returns true if s is empty.

func (ModeSet) IsZero added in v0.3.0

func (s ModeSet) IsZero() bool

IsZero returns true if s is empty.

func (ModeSet) ModeList added in v0.3.0

func (s ModeSet) ModeList() ModeList

ModeList converts ModeSet to ModeList.

func (ModeSet) With

func (s ModeSet) With(mode Mode) ModeSet

With returns a copy of ModeSet with specified mode bit set to 1.

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

func (s ModeSet) WithToggled(mode Mode) ModeSet

WithToggled returns a copy of ModeSet with specified mode bit changed to the opposite value.

func (ModeSet) Without

func (s ModeSet) Without(mode Mode) ModeSet

Without returns a copy of ModeSet with specified mode bit reset to 0.

type ModeSetDiff added in v0.2.0

type ModeSetDiff struct {
	Old ModeSet
	New ModeSet
}

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.

func (PaletteColor) Validate

func (PaletteColor) Validate() error

Validate always returns true.

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 RGB

func RGB(red, green, blue uint8) RGBColor

RGB constructs a RGBColor with the given red, green and blue values.

func (RGBColor) B

func (c RGBColor) B() uint8

B returns blue component brightness value.

func (RGBColor) Color

func (c RGBColor) 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 (RGBColor) G

func (c RGBColor) G() uint8

G returns green component brightness value.

func (RGBColor) MarshalText

func (c RGBColor) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler interface that allows RGBColor to be used in any compatible marshaler like JSON, YAML, etc.

func (RGBColor) R

func (c RGBColor) R() uint8

R returns red component brightness value.

func (RGBColor) String

func (c RGBColor) String() string

String returns textual description of c that can be used for debugging or logging purposes.

func (*RGBColor) UnmarshalText

func (c *RGBColor) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler interface that allows RGBColor to be used in any compatible unmarshaler like JSON, YAML, etc.

func (RGBColor) Validate

func (RGBColor) Validate() error

Validate returns nil.

type Sequence

type Sequence []Command

Sequence is a sequence of commands.

func (Sequence) Bytes

func (s Sequence) Bytes() []byte

Bytes returns binary string with the serialized sequence, the same as produces by Render but collected into a new byte slice.

func (Sequence) Render

func (s Sequence) Render(buf []byte) []byte

Render produces binary string corresponding to the contained commands starting with "\x1b[" (ESC/CSI) and ending with 'm'.

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 NewWriter

func NewWriter(target io.Writer) *Writer

NewWriter constructs a new Writer over the given target writer.

func (*Writer) Flush

func (w *Writer) Flush() error

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

func (w *Writer) PushBackgroundColor(color IntoColor)

PushBackgroundColor changes background color and pushes old value to a stack so that it can be restored using PopBackgroundColor method.

func (*Writer) PushForegroundColor

func (w *Writer) PushForegroundColor(color IntoColor)

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

func (w *Writer) PushUnderlineColor(color IntoColor)

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

func (w *Writer) SetBackgroundColor(color IntoColor)

SetBackgroundColor changes current background color.

func (*Writer) SetForegroundColor

func (w *Writer) SetForegroundColor(color IntoColor)

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

func (w *Writer) SetUnderlineColor(color IntoColor)

SetUnderlineColor changes current underline color.

func (*Writer) Write

func (w *Writer) Write(data []byte) (n int, err error)

Write flushes current style changes by generating CSI/SGR sequence and writing it to the target writer and then finally writes the given data to it.

Jump to

Keyboard shortcuts

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