colorize

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 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-07 11:40:58 * @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-07 11:12:48 * @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
)

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
)

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 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 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