co

package module
v0.0.0-...-d7cddf5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2025 License: Unlicense Imports: 1 Imported by: 0

README

go-color

go-color demo-one

A simple Go package for adding colors and formatting to terminal output.

Features

  • Easy-to-use API for styling terminal text.
  • Supports text and background colors.
  • Allows bold and combined styles.

Installation

go get github.com/idarkssj/go-color

Usage

package main

import (
    "fmt"
    "github.com/idarkssj/go-color"
)

func main() {
    // Create an Instance of Color
    title := co.BgBBlack.Join(co.White).Bold()
    fmt.Println(title.Paint("Title"))

    // Format as Function
    fmt.Println(co.Bold().Paint("Bold Text"))

    // Format as Method
    fmt.Println(co.Red.Bold().Paint("Make this text bold and red"))

    // Use the Join method to combine Background and Text Colors
    fmt.Println(co.Green.Join(co.BgWhite).Paint("Green text with white background"))
    fmt.Println(co.BgGreen.Join(co.White).Paint("Green text with white background"))

    fmt.Println(co.Blue.Paint("This is blue text"))
    fmt.Println(co.Blue.Bold().Paint("This is bold blue text"))
    fmt.Println(co.Green.Join(co.BgWhite).Paint("Green text with white background"))

    // Nested Formats
    fmt.Println(co.Underline().Italic().Paint("This is underlined and italic text"))
}
Output Example

go-color demo-two

Available Colors

Text Colors
Standard Bright
co.Black co.BBlack
co.Red co.BRed
co.Green co.BGreen
co.Yellow co.BYellow
co.Blue co.BBlue
co.Magenta co.BMagenta
co.Cyan co.BCyan
co.White co.BWhite
Background Colors
Standard Bright
co.BgBlack co.BgBBlack
co.BgRed co.BgBRed
co.BgGreen co.BgBGreen
co.BgYellow co.BgBYellow
co.BgBlue co.BgBBlue
co.BgMagenta co.BgBMagenta
co.BgCyan co.BgBCyan
co.BgWhite co.BgBWhite
Formats
Function
co.Bold()
co.Dim()
co.Italic()
co.Underline()
co.St()

Contributing

Feel free to submit issues or pull requests on GitHub.

License

This is free and unencumbered software released into the public domain.
For more details, see the LICENSE file or visit unlicense.org.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Black   = Color{/* contains filtered or unexported fields */} // Text Black
	Red     = Color{/* contains filtered or unexported fields */} // Text Red
	Green   = Color{/* contains filtered or unexported fields */} // Text Green
	Yellow  = Color{/* contains filtered or unexported fields */} // Text Yellow
	Blue    = Color{/* contains filtered or unexported fields */} // Text Blue
	Magenta = Color{/* contains filtered or unexported fields */} // Text Magenta
	Cyan    = Color{/* contains filtered or unexported fields */} // Text Cyan
	White   = Color{/* contains filtered or unexported fields */} // Text White

	BBlack   = Color{/* contains filtered or unexported fields */} // Text Bright Black
	BRed     = Color{/* contains filtered or unexported fields */} // Text Bright Red
	BGreen   = Color{/* contains filtered or unexported fields */} // Text Bright Green
	BYellow  = Color{/* contains filtered or unexported fields */} // Text Bright Yellow
	BBlue    = Color{/* contains filtered or unexported fields */} // Text Bright Blue
	BMagenta = Color{/* contains filtered or unexported fields */} // Text Bright Magenta
	BCyan    = Color{/* contains filtered or unexported fields */} // Text Bright Cyan
	BWhite   = Color{/* contains filtered or unexported fields */} // Text Bright White

	BgBlack   = Color{/* contains filtered or unexported fields */} // Background Black
	BgRed     = Color{/* contains filtered or unexported fields */} // Background Red
	BgGreen   = Color{/* contains filtered or unexported fields */} // Background Green
	BgYellow  = Color{/* contains filtered or unexported fields */} // Background Yellow
	BgBlue    = Color{/* contains filtered or unexported fields */} // Background Blue
	BgMagenta = Color{/* contains filtered or unexported fields */} // Background Magenta
	BgCyan    = Color{/* contains filtered or unexported fields */} // Background Cyan
	BgWhite   = Color{/* contains filtered or unexported fields */} // Background White

	BgBBlack   = Color{/* contains filtered or unexported fields */} // Background Bright Black
	BgBRed     = Color{/* contains filtered or unexported fields */} // Background Bright Red
	BgBGreen   = Color{/* contains filtered or unexported fields */} // Background Bright Green
	BgBYellow  = Color{/* contains filtered or unexported fields */} // Background Bright Yellow
	BgBBlue    = Color{/* contains filtered or unexported fields */} // Background Bright Blue
	BgBMagenta = Color{/* contains filtered or unexported fields */} // Background Bright Magenta
	BgBCyan    = Color{/* contains filtered or unexported fields */} // Background Bright Cyan
	BgBWhite   = Color{/* contains filtered or unexported fields */} // Background Bright White
)

Functions

This section is empty.

Types

type Color

type Color struct {
	// contains filtered or unexported fields
}

func Bold

func Bold() Color

Returns a new color with the format bold.

func Dim

func Dim() Color

Returns a new color with the format dim.

func Italic

func Italic() Color

Returns a new color with the format italic.

func St

func St() Color

Returns a new color with the format strikethrough.

func Underline

func Underline() Color

Returns a new color with the format underline.

func (Color) Bold

func (c Color) Bold() Color

Returns a new color with the format bold.

func (Color) Dim

func (c Color) Dim() Color

Returns a new color with the format dim.

func (Color) Italic

func (c Color) Italic() Color

Returns a new color with the format italic.

func (Color) Join

func (c Color) Join(cc Color) Color

Returns a new color with the format of the first color and the format of the second color.

func (Color) Paint

func (c Color) Paint(s string) string

Returns a string with the color and the text.

func (Color) St

func (c Color) St() Color

Returns a new color with the format strikethrough.

func (Color) Underline

func (c Color) Underline() Color

Returns a new color with the format underline.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL