tarampampam / colors

🦜 One more Go library for using colors in the terminal console

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🦜 colors

go_version tests coverage docs

screenshot

One more Go library for using colors in the terminal console. The most important features are:

  • ANSI colors support (using Escape Sequences)
  • Multi-thread safe
  • Support FORCE_COLOR, NO_COLOR and TERM variables out of the box
  • Super-lightweight and extremely fast
  • Color codes are not pre-allocated, but cached (in memory) and re-used upon further usage
  • Easy to integrate with the existing code-base
  • Has no dependencies (except the standard library and golang.org/x)

Usage examples

package main

import (
  "fmt"

  "gh.tarampamp.am/colors"
)

func main() {
  fmt.Println((colors.FgGreen | colors.Bold).Wrap("green color + bold text"))

  var bg = colors.BgRed

  fmt.Printf("%s red background %s\n", bg.Start(), bg.Reset())

  colors.Enabled(false) // disable colors
  colors.Enabled(true)  // enable colors
}

For more examples see examples directory.

About

🦜 One more Go library for using colors in the terminal console

License:MIT License


Languages

Language:Go 100.0%