https://github.com/bbkane/gocolor
Tiny cross-platform terminal color library
https://github.com/bbkane/gocolor
color go golang terminal
Last synced: 11 months ago
JSON representation
Tiny cross-platform terminal color library
- Host: GitHub
- URL: https://github.com/bbkane/gocolor
- Owner: bbkane
- License: apache-2.0
- Created: 2022-02-05T06:29:43.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2025-07-17T14:25:59.000Z (11 months ago)
- Last Synced: 2025-08-06T08:58:20.226Z (11 months ago)
- Topics: color, go, golang, terminal
- Language: Go
- Homepage: https://pkg.go.dev/github.com/bbkane/gocolor
- Size: 215 KB
- Stars: 8
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# gocolor

A tiny cross-platform terminal color library that supports enabling and disabling colors.
Uses colors from https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences?redirectedfrom=MSDN#text-formatting
Tested on macOS and (occasionally) on Ubuntu 20 and Windows 10.
## Project Status (2025-06-14)
Basically complete! `gocolor` works for my simple use cases. I'm watching issues; please open one for any questions and especially BEFORE submitting a Pull request.
## Usage
```go
color, err := gocolor.Prepare(true)
if err != nil {
panic(err)
}
fmt.Println(
color.Add(color.FgRed, "FgRed"),
color.Add(color.FgCyanBright+color.Negative, "FgCyanBright+Negative"),
)
```
See [tests](./gocolor_test.go) for inspiration.
I use [mattn/go-isatty](https://github.com/mattn/go-isatty) to test my programs before enabling this.
See [Go Project Notes](https://www.bbkane.com/blog/go-project-notes/) for notes on development tooling.
## Inspirations
- https://github.com/TwiN/go-color (API inspiration)
- https://github.com/bbkane/go-color (my - now deprecated - fork of TwiN/go-color)
- https://github.com/fatih/color (color naming)
- https://github.com/jedib0t/go-pretty (Windows code)