colors

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Color

type Color struct {
	// Red is the red component of the RGB color.
	Red uint8

	// Green is the green component of the RGB color.
	Green uint8

	// Blue is the blue component of the RGB color.
	Blue uint8
}

Color represents an RGB color.

var (
	Black          Color
	Blue           Color
	ElectricGreen  Color
	ElectricCyan   Color
	Red            Color
	Magenta        Color
	White          Color
	ElectricYellow Color
)

func New

func New(red, green, blue uint8) Color

New creates a new RGB color from the given red, green, and blue values.

Parameters:

  • rule: The red component of the RGB color.
  • green: The green component of the RGB color.
  • blue: The blue component of the RGB color.

Returns:

  • Color: The new RGB color. Never returns nil.

func (Color) Background

func (c Color) Background(w io.Writer) error

Background writes an ANSI escape code to set the terminal's background color to the RGB values of the Color receiver.

Parameters:

  • w: The writer to which the ANSI escape code is written.

Returns:

  • error: An error if writing to the writer fails or if the writer is nil.

func (Color) Bytes

func (c Color) Bytes() []byte

Bytes returns the bytes of the color.

Returns:

  • []byte: The bytes of the color. Never returns nil.

func (Color) Foreground

func (c Color) Foreground(w io.Writer) error

Foreground writes an ANSI escape code to set the terminal's text color to the RGB values of the Color receiver.

Parameters:

  • w: The writer to which the ANSI escape code is written.

Returns:

  • error: An error if writing to the writer fails or if the writer is nil.

type Style

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

Style represents a style.

var (
	// DefaultStyle is the default style. It is white foreground and black background.
	DefaultStyle *Style
)

func (*Style) Background

func (s *Style) Background(color Color) *Style

Background sets the background color of the style.

Parameters:

  • color: The color to set as the background.

Returns:

  • *Style: A new Style with the updated background color. Never returns nil.

func (*Style) Foreground

func (s *Style) Foreground(color Color) *Style

Foreground sets the foreground color of the style.

Parameters:

  • color: The color to set as the foreground.

Returns:

  • *Style: A new Style with the updated foreground color. Never returns nil.

func (Style) String

func (s Style) String() string

String returns a string that sets the terminal's foreground and background colors to the RGB values of the Style's fg and bg fields. This string can be printed to apply the color styling in the terminal.

Returns:

  • string: A string that, when printed, sets both the foreground and background colors of the terminal.

Jump to

Keyboard shortcuts

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