Color
A simple Go library for adding ANSI color codes to terminal output.
Installation
go get git.quad4.io/Go-Libs/Color
Usage
package main
import (
"fmt"
"git.quad4.io/Go-Libs/Color"
)
func main() {
// Basic colors
fmt.Println(color.Red("This is red text"))
fmt.Println(color.Green("This is green text"))
fmt.Println(color.Blue("This is blue text"))
// Text styles
fmt.Println(color.Bold("This is bold text"))
fmt.Println(color.Underline("This is underlined text"))
// Combinations
fmt.Println(color.Red(color.Bold("This is bold red text")))
// Background colors
fmt.Println(color.BgBlue(color.Yellow("Yellow text on blue background")))
}
Available Functions
Foreground Colors
Black(s string) stringRed(s string) stringGreen(s string) stringYellow(s string) stringBlue(s string) stringMagenta(s string) stringCyan(s string) stringWhite(s string) string
Bright Foreground Colors
BrightBlack(s string) stringBrightRed(s string) stringBrightGreen(s string) stringBrightYellow(s string) stringBrightBlue(s string) stringBrightMagenta(s string) stringBrightCyan(s string) stringBrightWhite(s string) string
Background Colors
BgBlack(s string) stringBgRed(s string) stringBgGreen(s string) stringBgYellow(s string) stringBgBlue(s string) stringBgMagenta(s string) stringBgCyan(s string) stringBgWhite(s string) string
Bright Background Colors
BgBrightBlack(s string) stringBgBrightRed(s string) stringBgBrightGreen(s string) stringBgBrightYellow(s string) stringBgBrightBlue(s string) stringBgBrightMagenta(s string) stringBgBrightCyan(s string) stringBgBrightWhite(s string) string
Text Styles
Bold(s string) stringDim(s string) stringItalic(s string) stringUnderline(s string) stringBlink(s string) stringReverse(s string) stringHidden(s string) stringStrike(s string) string
Utility Functions
Reset(s string) string- Removes all color and style formatting
Print Functions
The library also provides print functions that work like fmt.Print, fmt.Println, and fmt.Printf:
Print(a ...interface{}) (int, error)Println(a ...interface{}) (int, error)Printf(format string, a ...interface{}) (int, error)Sprint(a ...interface{}) stringSprintln(a ...interface{}) stringSprintf(format string, a ...interface{}) string
Examples
Run the included example:
go run examples/example.go
License
This library is released under the MIT License.
Languages
Go
100%