colorize

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2025 License: MIT Imports: 4 Imported by: 4

README

CircleCI godoc license

colorize

Simple golang command line colorize for outputs highlight.

Install

go get -u github.com/dolab/colorize

Usage

  • Standard
import "github.com/dolab/colorize"

func main() {
    brush := colorize.New("yellow+bBuih:black+h")
    brush.Paint("Hello, colorize!")
}
  • Customize
import "github.com/dolab/colorize"

func main() {
    brush := colorize.New("yellow+bBuih:black+h")

    // gain colors
    colorDraw, colorClean := brush.Colour()

    // custom output
    buf := bytes.NewBufferString(colorDraw)
    buf.WriteString("Hello, colorize!")
    buf.WriteString(colorClean)

    buf.WriteTo(os.Stdout)
}

Format

foreground_color+color_attributes:background_color+color_attributes

buildin colors

  • ColorRed
  • ColorGreen
  • ColorYellow
  • ColorBlue
  • ColorMagenta
  • ColorCyan
  • ColorWhite
  • ColorGray
  • ColorBlack

available attributes

  • b = bold foreground
  • B = blink foreground
  • u = underline foreground
  • i = inverse
  • h = high intensity (bright) foreground, background

Windows support?

see go-colorable

License

MIT

Author

Spring MC

Documentation

Index

Constants

View Source
const (
	ColorDraw  = "\x1b["
	ColorClean = "\x1b[0m"
)
View Source
const (
	ColorNone = iota
	ColorRed
	ColorGreen
	ColorYellow
	ColorBlue
	ColorMagenta
	ColorCyan
	ColorWhite
	ColorGray
	ColorBlack Color = -1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Color

type Color int

Color can be used for foreground and background

func (Color) HasColor

func (c Color) HasColor() bool

type Colorize

type Colorize struct {
	Values []any
	Fg     Color
	Bg     Color
	Prop   Property
	// contains filtered or unexported fields
}

Colorize for term magic happens

func New

func New(style string) Colorize

func (*Colorize) Colour

func (c *Colorize) Colour() (begin, end string)

func (*Colorize) Format

func (c *Colorize) Format(fs fmt.State, r rune)

Format allows Colorize to satisfy the fmt.Formatter interface.

func (*Colorize) Paint

func (c *Colorize) Paint(args ...any) string

Paint returns colored string

func (*Colorize) SetBgColor

func (c *Colorize) SetBgColor(bc Color)

func (*Colorize) SetFgColor

func (c *Colorize) SetFgColor(fc Color)

func (*Colorize) SetPlain

func (c *Colorize) SetPlain(plain bool)

func (*Colorize) ToggleBgIntensity

func (c *Colorize) ToggleBgIntensity()
func (c *Colorize) ToggleBlink()

func (*Colorize) ToggleBold

func (c *Colorize) ToggleBold()

func (*Colorize) ToggleFgIntensity

func (c *Colorize) ToggleFgIntensity()

func (*Colorize) ToggleInverse

func (c *Colorize) ToggleInverse()

func (*Colorize) TogglePlain

func (c *Colorize) TogglePlain()

func (*Colorize) ToggleUnderline

func (c *Colorize) ToggleUnderline()

type Property

type Property struct {
	Bold      bool
	Blink     bool
	Underline bool
	Inverse   bool
	Fgi       bool
	Bgi       bool
}

Property set 1 or more of these properties This struct holds the state

func (Property) String

func (p Property) String() string

Jump to

Keyboard shortcuts

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