Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/ color Public

Color is a zero-dependency ANSI styling package for Go, providing fast helpers for text colors, bright variants, backgrounds, styles, 256-color mode, and full RGB/HEX support. Designed for CLIs, loggers, and developer tools that need clean, expressive terminal output with minimal overhead.

License

Notifications You must be signed in to change notification settings

nyxstack/color

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

2 Commits

Repository files navigation

🎨 NYX Color

Go Reference Go Report Card License: MIT

A simple, zero-dependency ANSI color library for Go terminals.

Demo

This package helps you makes terminal output beautiful with support for 16/256/RGB colors, text styling, and background colors. Perfect for CLIs, logging systems, debugging tools, and any application that needs colorful terminal output.

Installation

go get github.com/nyxstack/color

✨ Features

  • 🌈 Full Color Support: Standard 16 colors, bright variants, 256-color palette, and 24-bit RGB
  • 🎯 HEX Colors: Direct hex color support (#FF0000, FF0000)
  • 🎨 Text Styling: Bold, italic, underline, strikethrough, dim, reverse, and more
  • πŸ–ΌοΈ Background Colors: All color variants available as backgrounds
  • ⚑ Zero Dependencies: Pure Go, no external dependencies
  • πŸš€ High Performance: Pre-computed ANSI codes, zero allocations
  • πŸ› οΈ Easy to Use: Simple string concatenation API

πŸ“¦ Installation

go get github.com/nyxstack/color

πŸš€ Quick Start

package main
import (
 "fmt"
 "github.com/nyxstack/color"
)
func main() {
 // Basic colors
 fmt.Println(color.Red + "Error: Something went wrong!" + color.Reset)
 fmt.Println(color.Green + "Success: Operation completed!" + color.Reset)
 
 // Styled text
 fmt.Println(color.Bold + color.Blue + "Important Information" + color.Reset)
 
 // Background colors
 fmt.Println(color.BgYellow + color.Black + " WARNING " + color.Reset)
 
 // RGB colors
 fmt.Println(color.RGB(255, 165, 0) + "Custom orange text" + color.Reset)
 
 // HEX colors
 fmt.Println(color.Hex("#FF69B4") + "Hot pink text" + color.Reset)
}

πŸ“š Documentation

Standard Colors

// Basic colors
color.Black, color.Red, color.Green, color.Yellow
color.Blue, color.Magenta, color.Cyan, color.White
// Bright variants
color.BrightBlack, color.BrightRed, color.BrightGreen
color.BrightYellow, color.BrightBlue, color.BrightMagenta
color.BrightCyan, color.BrightWhite
// Always reset after coloring
fmt.Println(color.Red + "Red text" + color.Reset)

Background Colors

// Standard backgrounds
color.BgRed, color.BgGreen, color.BgBlue, color.BgYellow
color.BgMagenta, color.BgCyan, color.BgWhite, color.BgBlack
// Bright backgrounds
color.BgBrightRed, color.BgBrightGreen, color.BgBrightBlue
// ... and more
// Example usage
fmt.Println(color.BgRed + color.White + " Error " + color.Reset)

Text Styling

// Available styles
color.Bold // Bold text
color.Dim // Dimmed text
color.Italic // Italic text
color.Underline // Underlined text
color.Blink // Blinking text
color.Reverse // Reverse video
color.Hidden // Hidden text
color.Strikethrough // Strikethrough text
// Combine styles
fmt.Println(color.Bold + color.Underline + color.Red + "Important!" + color.Reset)

256-Color Mode

×ば぀6 color cube // 232-255: Grayscale">
// Use any of the 256 ANSI colors
fmt.Println(color.Color256(196) + "Bright red" + color.Reset) // Color 196
fmt.Println(color.Color256(46) + "Bright green" + color.Reset) // Color 46
fmt.Println(color.Color256(21) + "Bright blue" + color.Reset) // Color 21
// Color ranges:
// 0-15: Standard colors
// 16-231: ×ば぀6 color cube
// 232-255: Grayscale

RGB Colors (24-bit)

// True color support with RGB values (0-255)
fmt.Println(color.RGB(255, 99, 71) + "Tomato color" + color.Reset)
fmt.Println(color.RGB(64, 224, 208) + "Turquoise" + color.Reset)
fmt.Println(color.RGB(255, 215, 0) + "Gold" + color.Reset)

HEX Colors

// Support for hex colors with or without #
fmt.Println(color.Hex("#FF6B6B") + "Coral red" + color.Reset)
fmt.Println(color.Hex("4ECDC4") + "Mint green" + color.Reset)
fmt.Println(color.Hex("#FFE66D") + "Sunny yellow" + color.Reset)

πŸ’‘ Examples

Simple Logger

package main
import (
 "fmt"
 "time"
 "github.com/nyxstack/color"
)
func logInfo(msg string) {
 timestamp := time.Now().Format("15:04:05")
 fmt.Printf("%s[%s]%s %s[INFO]%s %s\n", 
 color.Dim, timestamp, color.Reset,
 color.Blue, color.Reset, msg)
}
func logError(msg string) {
 timestamp := time.Now().Format("15:04:05")
 fmt.Printf("%s[%s]%s %s[ERROR]%s %s\n", 
 color.Dim, timestamp, color.Reset,
 color.Red, color.Reset, msg)
}
func main() {
 logInfo("Server started successfully")
 logError("Database connection failed")
}

Progress Bar

func showProgress() {
 fmt.Print("Progress: [")
 for i := 0; i < 50; i++ {
 if i < 25 {
 fmt.Print(color.Green + "β–ˆ" + color.Reset)
 } else {
 fmt.Print(color.Dim + "β–‘" + color.Reset)
 }
 }
 fmt.Println("] 50%")
}

Color Palette

func showPalette() {
 colors := []string{"#FF6B6B", "#4ECDC4", "#45B7D1", "#96CEB4", "#FFEAA7", "#DDA0DD"}
 names := []string{"Coral", "Mint", "Sky", "Sage", "Cream", "Plum"}
 
 for i, hex := range colors {
 fmt.Printf("%s%-10s%s %sβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ%s\n", 
 color.Bold, names[i], color.Reset,
 color.Hex(hex), color.Reset)
 }
}

πŸ§ͺ Running Examples

The package includes several example files:

# Basic usage examples
go run examples/basic.go
# 256-color demonstrations
go run examples/color_256.go
# Advanced RGB/HEX features
go run examples/advanced.go
# Demo for screenshots
go run examples/demo.go

🎯 Use Cases

  • CLI Applications: Colorful command-line interfaces
  • Logging Systems: Color-coded log levels and categories
  • Debug Output: Highlight important information
  • Data Visualization: Terminal-based charts and graphs
  • Status Indicators: Progress bars, success/error states
  • Development Tools: Enhanced terminal output for dev tools

πŸš€ Performance

NYX Color is designed for performance:

  • Pre-computed ANSI escape sequences
  • Zero memory allocations during normal usage
  • No reflection or complex parsing
  • Direct string concatenation
  • Minimal overhead

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Inspired by the need for a simple, fast color library
  • Thanks to the Go community for feedback and suggestions
  • ANSI escape sequence standards

Made with ❀️ by NYX Stack

About

Color is a zero-dependency ANSI styling package for Go, providing fast helpers for text colors, bright variants, backgrounds, styles, 256-color mode, and full RGB/HEX support. Designed for CLIs, loggers, and developer tools that need clean, expressive terminal output with minimal overhead.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /