ansi

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ANSIColorCode

type ANSIColorCode uint8

ANSIColorCode represents one of the 8 standard ANSI color codes

const (
	Black   ANSIColorCode = 30
	Red     ANSIColorCode = 31
	Green   ANSIColorCode = 32
	Yellow  ANSIColorCode = 33
	Blue    ANSIColorCode = 34
	Purple  ANSIColorCode = 35
	Cyan    ANSIColorCode = 36
	White   ANSIColorCode = 37
	Default ANSIColorCode = 0
)

type ColorModifier

type ColorModifier uint8

ColorModifier changes whether the color is for the foreground or background and whether or not it's the intense variant

const (
	Foreground ColorModifier = 0
	Background ColorModifier = 10
	Intense    ColorModifier = 60
)

type Style

type Style struct {
	// contains filtered or unexported fields
}

Style represents a set of print modifications

func (Style) Color

func (c Style) Color() ANSIColorCode

Return the current color, or Default if nil

func (Style) ColorModifiers

func (c Style) ColorModifiers() []ColorModifier

ColorModifiers returns the normalized (sorted, deduplicated) list of color modifiers

func (*Style) SetColor

func (c *Style) SetColor(color ANSIColorCode)

SetColor sets the color. The underlying color is a pointer, and is set to nil if the passed color is Default

func (*Style) SetColorModifiers

func (c *Style) SetColorModifiers(cm ...ColorModifier)

SetColorModifiers sorts and deduplicates the list of color modifiers before setting it

func (*Style) SetStyleModifiers

func (c *Style) SetStyleModifiers(sm ...StyleModifier)

SetStyleModifiers sorts and deduplicates the list of style modifiers before setting it

func (Style) String

func (c Style) String() string

String implements fmt.Stringer and outputs the ANSI control code for this style

func (Style) StyleModifiers

func (c Style) StyleModifiers() []StyleModifier

StyleModifiers returns the normalized (sorted, deduplicated) list of style modifiers

type StyleModifier

type StyleModifier uint8

StyleModifier set things like bold, italic, etc. Not all StyleModifiers are supported by all systems

const (
	Normal        StyleModifier = 0
	Bold          StyleModifier = 1
	Italic        StyleModifier = 3
	Underline     StyleModifier = 4
	Strikethrough StyleModifier = 9
)

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer implements io.Writer.

func NewWriter

func NewWriter(target io.Writer) *Writer

NewColorize returns a new io.Writer that can style text

func (Writer) CurrentStyle

func (c Writer) CurrentStyle() Style

func (*Writer) Reset

func (c *Writer) Reset() (int, error)

Reset sends the reset control code and resets all modifications

func (*Writer) SetCurrentStyle

func (c *Writer) SetCurrentStyle(ps Style)

func (*Writer) Write

func (c *Writer) Write(p []byte) (int, error)

Write implements io.Writer

Jump to

Keyboard shortcuts

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