colorize

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2025 License: Apache-2.0 Imports: 2 Imported by: 3

README

Colorize

A Golang package to add colors to your terminal output.

Installation

go get -u github.com/noa-log/colorize

Quick Start

package main

import (
    "fmt"
    "github.com/noa-log/colorize"
)

func main() {
    // Add color to text
    fmt.Println(colorize.BlueText("This is blue text"))

    // Add background color to text
    fmt.Println(colorize.BlueBackground("This is text with a blue background"))

    // Set custom text color, background color, and style
    fmt.Println(colorize.Set("This is custom styled text", colorize.ConfigBold, colorize.BackgroundBlue, colorize.TextWhite))
}

Features

  • All available colors and styles are defined as constants.
  • Provides methods to quickly set text color and background color.
  • Supports custom combinations of colors and styles.
  • Uses ANSI escape sequences, compatible with most terminals.
  • 100% unit test coverage.

License

This project is open-sourced under the Apache License 2.0. Please comply with the terms when using it.

Documentation

Overview

* @Author: nijineko * @Date: 2025-06-07 11:13:20 * @LastEditTime: 2025-06-07 11:13:26 * @LastEditors: nijineko * @Description: quick method for set background color * @FilePath: \colorize\background.go

* @Author: nijineko * @Date: 2025-06-07 10:44:04 * @LastEditTime: 2025-06-08 11:42:11 * @LastEditors: nijineko * @Description: define color constants * @FilePath: \colorize\color.go

* @Author: nijineko * @Date: 2025-06-07 10:59:07 * @LastEditTime: 2025-06-07 12:09:24 * @LastEditors: nijineko * @Description: remove color from text * @FilePath: \colorize\remove.go

* @Author: nijineko * @Date: 2025-06-07 10:53:28 * @LastEditTime: 2025-06-07 11:00:21 * @LastEditors: nijineko * @Description: set color for text * @FilePath: \colorize\set.go

* @Author: nijineko * @Date: 2025-06-07 11:05:59 * @LastEditTime: 2025-06-08 11:45:47 * @LastEditors: nijineko * @Description: quick method for set text color * @FilePath: \colorize\text.go

Index

Constants

View Source
const (
	DEFAULT_CONFIG     = 0         // Default configuration
	DEFAULT_BACKGROUND = 0         // Default background color
	DEFAULT_TEXT       = TextWhite // Default text color
)

define default constants

View Source
const (
	ConfigDefault   = iota     // Default configuration
	ConfigBold                 // Bold text
	ConfigDim                  // Dim text
	ConfigItalic               // Italic text
	ConfigUnderline            // Underlined text
	ConfigBlinking             // Blinking text
	ConfigReverse   = iota + 1 // Reversed colors
	ConfigHidden               // Hidden text
)

define color constants

View Source
const (
	BackgroundBlack         = iota + 40 // Black background
	BackgroundRed                       // Red background
	BackgroundGreen                     // Green background
	BackgroundYellow                    // Yellow background
	BackgroundBlue                      // Blue background
	BackgroundMagenta                   // Magenta background
	BackgroundCyan                      // Cyan background
	BackgroundWhite                     // White background
	BackgroundGray          = iota + 92 // Gray background (bright black)
	BackgroundBrightRed                 // Bright red background
	BackgroundBrightGreen               // Bright green background
	BackgroundBrightYellow              // Bright yellow background
	BackgroundBrightBlue                // Bright blue background
	BackgroundBrightMagenta             // Bright magenta background
	BackgroundBrightCyan                // Bright cyan background
	BackgroundBrightWhite               // Bright white background
)

define background color constants

View Source
const (
	TextBlack         = iota + 30 // Black text
	TextRed                       // Red text
	TextGreen                     // Green text
	TextYellow                    // Yellow text
	TextBlue                      // Blue text
	TextMagenta                   // Magenta text
	TextCyan                      // Cyan text
	TextWhite                     // White text
	TextGray          = iota + 82 // Gray text (bright black)
	TextBrightRed                 // Bright red text
	TextBrightGreen               // Bright green text
	TextBrightYellow              // Bright yellow text
	TextBrightBlue                // Bright blue text
	TextBrightMagenta             // Bright magenta text
	TextBrightCyan                // Bright cyan text
	TextBrightWhite               // Bright white text
)

define text color constants

Variables

This section is empty.

Functions

func BlackBackground

func BlackBackground(Text string) string

*

  • @description: Set background color to black
  • @param {string} Text
  • @return {string} formatted text with black background

func BlackText

func BlackText(Text string) string

*

  • @description: Set text color to black
  • @param {string} Text
  • @return {string} formatted text with black color

func BlueBackground

func BlueBackground(Text string) string

*

  • @description: Set background color to blue
  • @param {string} Text
  • @return {string} formatted text with black background

func BlueText

func BlueText(Text string) string

*

  • @description: Set text color to blue
  • @param {string} Text
  • @return {string} formatted text with black color

func BrightBlueBackground added in v1.0.1

func BrightBlueBackground(Text string) string

*

  • @description: Set background color to bright blue
  • @param {string} Text
  • @return {string} formatted text with black background

func BrightBlueText added in v1.0.1

func BrightBlueText(Text string) string

*

  • @description: Set text color to bright blue
  • @param {string} Text
  • @return {string} formatted text with black color

func BrightCyanBackground added in v1.0.1

func BrightCyanBackground(Text string) string

*

  • @description: Set background color to bright cyan
  • @param {string} Text
  • @return {string} formatted text with black background

func BrightCyanText added in v1.0.1

func BrightCyanText(Text string) string

*

  • @description: Set text color to bright cyan
  • @param {string} Text
  • @return {string} formatted text with black color

func BrightGreenBackground added in v1.0.1

func BrightGreenBackground(Text string) string

*

  • @description: Set background color to bright green
  • @param {string} Text
  • @return {string} formatted text with black background

func BrightGreenText added in v1.0.1

func BrightGreenText(Text string) string

*

  • @description: Set text color to bright green
  • @param {string} Text
  • @return {string} formatted text with black color

func BrightMagentaBackground added in v1.0.1

func BrightMagentaBackground(Text string) string

*

  • @description: Set background color to bright magenta
  • @param {string} Text
  • @return {string} formatted text with black background

func BrightMagentaText added in v1.0.1

func BrightMagentaText(Text string) string

*

  • @description: Set text color to bright magenta
  • @param {string} Text
  • @return {string} formatted text with black color

func BrightRedBackground added in v1.0.1

func BrightRedBackground(Text string) string

*

  • @description: Set background color to bright red
  • @param {string} Text
  • @return {string} formatted text with black background

func BrightRedText added in v1.0.1

func BrightRedText(Text string) string

*

  • @description: Set text color to bright red
  • @param {string} Text
  • @return {string} formatted text with black color

func BrightWhiteBackground added in v1.0.1

func BrightWhiteBackground(Text string) string

*

  • @description: Set background color to bright white
  • @param {string} Text
  • @return {string} formatted text with black background

func BrightWhiteText added in v1.0.1

func BrightWhiteText(Text string) string

*

  • @description: Set text color to bright white
  • @param {string} Text
  • @return {string} formatted text with black color

func BrightYellowBackground added in v1.0.1

func BrightYellowBackground(Text string) string

*

  • @description: Set background color to bright yellow
  • @param {string} Text
  • @return {string} formatted text with black background

func BrightYellowText added in v1.0.1

func BrightYellowText(Text string) string

*

  • @description: Set text color to bright yellow
  • @param {string} Text
  • @return {string} formatted text with black color

func CyanBackground

func CyanBackground(Text string) string

*

  • @description: Set background color to cyan
  • @param {string} Text
  • @return {string} formatted text with black background

func CyanText

func CyanText(Text string) string

*

  • @description: Set text color to cyan
  • @param {string} Text
  • @return {string} formatted text with black color

func GrayBackground added in v1.0.1

func GrayBackground(Text string) string

*

  • @description: Set background color to gray
  • @param {string} Text
  • @return {string} formatted text with black background

func GrayText added in v1.0.1

func GrayText(Text string) string

*

  • @description: Set text color to gray
  • @param {string} Text
  • @return {string} formatted text with black color

func GreenBackground

func GreenBackground(Text string) string

*

  • @description: Set background color to green
  • @param {string} Text
  • @return {string} formatted text with black background

func GreenText

func GreenText(Text string) string

*

  • @description: Set text color to green
  • @param {string} Text
  • @return {string} formatted text with black color

func MagentaBackground

func MagentaBackground(Text string) string

*

  • @description: Set background color to magenta
  • @param {string} Text
  • @return {string} formatted text with black background

func MagentaText

func MagentaText(Text string) string

*

  • @description: Set text color to magenta
  • @param {string} Text
  • @return {string} formatted text with black color

func RedBackground

func RedBackground(Text string) string

*

  • @description: Set background color to red
  • @param {string} Text
  • @return {string} formatted text with black background

func RedText

func RedText(Text string) string

*

  • @description: Set text color to red
  • @param {string} Text
  • @return {string} formatted text with red color

func Remove

func Remove(Text string) string

*

  • @description: remove color from text
  • @param {string} Text colorized text that needs to be cleaned
  • @return {string} cleaned text without color codes

func Set

func Set(Text string, Config int, BackgroundColor int, TextColor int) string

*

  • @description: set color for text
  • @param {string} Text Text that needs color added
  • @param {int} Config
  • @param {int} BackgroundColor
  • @param {int} TextColor
  • @return {string} formatted text with color

func WhiteBackground

func WhiteBackground(Text string) string

*

  • @description: Set background color to white
  • @param {string} Text
  • @return {string} formatted text with black background

func WhiteText

func WhiteText(Text string) string

*

  • @description: Set text color to white
  • @param {string} Text
  • @return {string} formatted text with black color

func YellowBackground

func YellowBackground(Text string) string

*

  • @description: Set background color to yellow
  • @param {string} Text
  • @return {string} formatted text with black background

func YellowText

func YellowText(Text string) string

*

  • @description: Set text color to yellow
  • @param {string} Text
  • @return {string} formatted text with black color

Types

This section is empty.

Jump to

Keyboard shortcuts

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