https://github.com/thepatrik/strcolor
Golang library for printing with standard ANSI colors.
https://github.com/thepatrik/strcolor
ansi-colors golang printf sprintf
Last synced: 25 days ago
JSON representation
Golang library for printing with standard ANSI colors.
- Host: GitHub
- URL: https://github.com/thepatrik/strcolor
- Owner: thepatrik
- License: mit
- Created: 2019-07-23T07:06:29.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-09-14T12:48:48.000Z (over 6 years ago)
- Last Synced: 2023-08-09T14:29:55.974Z (over 2 years ago)
- Topics: ansi-colors, golang, printf, sprintf
- Language: Go
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# strcolor
[](https://travis-ci.org/thepatrik/strcolor) [](https://goreportcard.com/report/github.com/thepatrik/strcolor) [](https://godoc.org/github.com/thepatrik/strcolor)
Golang library for printing with standard ANSI colors.
#### install
```Golang
import "github.com/thepatrik/strcolor"
```
## Usage
Colorize fmt/log prints:
```Golang
package main
import (
"bytes"
"fmt"
"github.com/thepatrik/strcolor"
)
func main() {
// colorize a print...
fmt.Println("Hello ", strcolor.Magenta("World"))
// with formatting...
fmt.Printf("%s %s %s %s %s %s %s %s.\n",
strcolor.Black("Life"),
strcolor.Red("is"),
strcolor.Green("like"),
strcolor.Yellow("a"),
strcolor.Blue("box"),
strcolor.Magenta("of"),
strcolor.Cyan(8), // and not only strings.
strcolor.White("crayons"))
// or with a buffer...
var buffer bytes.Buffer
quote := "\"Color is a power which directly influences the soul.\""
author := "Wassily Kandinsky"
buffer.WriteString(strcolor.Cyan(quote).String() + " /" + author)
fmt.Println(buffer.String())
// coloring can be programmatically enabled/disabled (enabled by default on TTY character devices)...
strcolor.SetEnabled(false)
defer strcolor.SetEnabled(true)
fmt.Println(strcolor.Magenta("I prefer living in color."))
}
```