color

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2024 License: ISC Imports: 3 Imported by: 3

README ¶

🎨 color

snapshot

A fast and lightweight color library for Go language.

📦 Usage

go get -u github.com/tsingshaner/go-pkg/color
package main

import "github.com/tsingshaner/go-pkg/color"

func main() {
  print(color.Red("Hello, World!\n"))

  // multiple styles
  print(color.Underline(color.Bold(color.Red("Hello, World!\n"))))
}

🚨 Unsafe API

The unsafeXXX func is not safe but is faster, if you ensure the text is safe, you can use it.

If you use nesting unsafeXXX func, it may close the color style unexpectedly.

func TestUnsafeWithFail(t *testing.T) {
	mixinString := UnsafeRed(" red " + Green(" green ") + " no color ")

	assert.Equal(t, "\x1b[31m red \x1b[32m green \x1b[39m no color \x1b[39m", mixinString)
}

func TestSafeFormat(t *testing.T) {
	mixinString := Red(" red " + Green(" green ") + " red ")

	assert.Equal(t, "\x1b[31m red \x1b[32m green \x1b[31m red \x1b[39m", mixinString)
}

âš¡ Benchmark

goos: windows
goarch: amd64
pkg: github.com/tsingshaner/go-pkg/color
cpu: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
BenchmarkRed-8                  32791454                34.78 ns/op
BenchmarkUnsafeMagenta-8        76925048                15.84 ns/op
BenchmarkMulti-8                 9167505               120.5 ns/op
BenchmarkUnsafeMulti-8          15919278                69.64 ns/op
PASS
ok      github.com/tsingshaner/go-pkg/color     4.878s

✨ Inspired By

picocolors

📄 License

ISC License © 2024-Present qingshaner

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

func Black ¶

func Black(text string) string

func BlackBg ¶

func BlackBg(text string) string
func Blink(text string) string

func Blue ¶

func Blue(text string) string

func BlueBg ¶

func BlueBg(text string) string

func Bold ¶

func Bold(text string) string

func Cyan ¶

func Cyan(text string) string

func CyanBg ¶

func CyanBg(text string) string

func Dim ¶

func Dim(text string) string

func Disable ¶

func Disable()

Disable color output.

func Enable ¶

func Enable()

Enable color output.

func Gray ¶

func Gray(text string) string

func GrayBg ¶

func GrayBg(text string) string

func Green ¶

func Green(text string) string

func GreenBg ¶

func GreenBg(text string) string

func Hidden ¶

func Hidden(text string) string

func IsEnabled ¶

func IsEnabled() bool

IsEnabled returns true if the color output is enabled.

func Italic ¶

func Italic(text string) string

func Magenta ¶

func Magenta(text string) string

func MagentaBg ¶

func MagentaBg(text string) string

func Red ¶

func Red(text string) string

func RedBg ¶

func RedBg(text string) string

func Reset ¶

func Reset(text string) string

func ResetEnabled ¶

func ResetEnabled()

ResetEnabled resets the color output to the default value.

func Reverse ¶

func Reverse(text string) string

func Strikethrough ¶

func Strikethrough(text string) string

func Underline ¶

func Underline(text string) string

func UnsafeBlack ¶

func UnsafeBlack(text string) string

func UnsafeBlackBg ¶

func UnsafeBlackBg(text string) string
func UnsafeBlink(text string) string

func UnsafeBlue ¶

func UnsafeBlue(text string) string

func UnsafeBlueBg ¶

func UnsafeBlueBg(text string) string

func UnsafeBold ¶

func UnsafeBold(text string) string

func UnsafeCyan ¶

func UnsafeCyan(text string) string

func UnsafeCyanBg ¶

func UnsafeCyanBg(text string) string

func UnsafeDim ¶

func UnsafeDim(text string) string

func UnsafeGray ¶

func UnsafeGray(text string) string

func UnsafeGrayBg ¶

func UnsafeGrayBg(text string) string

func UnsafeGreen ¶

func UnsafeGreen(text string) string

func UnsafeGreenBg ¶

func UnsafeGreenBg(text string) string

func UnsafeHidden ¶

func UnsafeHidden(text string) string

func UnsafeItalic ¶

func UnsafeItalic(text string) string

func UnsafeMagenta ¶

func UnsafeMagenta(text string) string

func UnsafeMagentaBg ¶

func UnsafeMagentaBg(text string) string

func UnsafeRed ¶

func UnsafeRed(text string) string

func UnsafeRedBg ¶

func UnsafeRedBg(text string) string

func UnsafeReset ¶

func UnsafeReset(text string) string

func UnsafeReverse ¶

func UnsafeReverse(text string) string

func UnsafeStrikethrough ¶

func UnsafeStrikethrough(text string) string

func UnsafeUnderline ¶

func UnsafeUnderline(text string) string

func UnsafeWhite ¶

func UnsafeWhite(text string) string

func UnsafeWhiteBg ¶

func UnsafeWhiteBg(text string) string

func UnsafeYellow ¶

func UnsafeYellow(text string) string

func UnsafeYellowBg ¶

func UnsafeYellowBg(text string) string

func White ¶

func White(text string) string

func WhiteBg ¶

func WhiteBg(text string) string

func Yellow ¶

func Yellow(text string) string

func YellowBg ¶

func YellowBg(text string) string

Types ¶

This section is empty.

Jump to

Keyboard shortcuts

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