colorful

package module
v2.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2023 License: MIT Imports: 1 Imported by: 0

README

image description

go version license version

colorful

colorful is a lightweight package for rendering colorful text in terminal with Go . You can use this instead of fmt package for having many features. For seeing usages check this.

Documentation

Install

go get github.com/erfanmomeniii/colorful/v2

Next, include it in your application:

import "github.com/erfanmomeniii/colorful/v2"

Quick Start

The following example demonstrates how to print text in desired format and color:

package main

import (
	"github.com/erfanmomeniii/colorful/v2"
)

func main() {
	colorful.WithColor(colorful.RedColor).
		WithBackgroundColor(colorful.BlueBackgroundColor).
		Println("RedColorBlueBackground")

	colorful.WithColor(colorful.GreenColor).
		Println("GreenColor")

	colorful.WithBackgroundColor(colorful.YellowBackgroundColor).
		Println("YellowBackground")
}

You can also print many texts with different colors and background colors only in one operation like below:

package main

import (
	"github.com/erfanmomeniii/colorful/v2"
)

func main() {
	colorful.WithColor(colorful.RedColor).
		Print("Hi ").
		WithColor(colorful.BlueColor).
		Print("Erfan")
}

output:

Supported Colors
red color
green color
yellow color
blue color
magenta color
cyan color
white color
black color
brightBlack color
brightRed color
brightGreen color
brightYellow color
brightBlue color
brightMagenta color
brightCyan color
brightWhite color

You can use the following color codes :

color code

Supported Background Colors
black background
red background
green background
yellow background
blue background
magenta background
cyan background
white background
brightBlack background
brightRed background
brightGreen background
brightYellow background
brightBlue background
brightMagenta background
brightCyan background
brightWhite background

You can use the following background codes :

color code

Contributing

Pull requests are welcome. For changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.

Documentation

Index

Constants

View Source
const (
	DefaultColor       = ""
	BlackColor         = "\u001b[30m"
	RedColor           = "\u001b[31m"
	GreenColor         = "\u001b[32m"
	YellowColor        = "\u001b[33m"
	BlueColor          = "\u001b[34m"
	MagentaColor       = "\u001b[35m"
	CyanColor          = "\u001b[36m"
	WhiteColor         = "\u001b[37m"
	BrightBlackColor   = "\u001b[30;1m"
	BrightRedColor     = "\u001b[31;1m"
	BrightGreenColor   = "\u001b[32;1m"
	BrightYellowColor  = "\u001b[33;1m"
	BrightBlueColor    = "\u001b[34;1m"
	BrightMagentaColor = "\u001b[35;1m"
	BrightCyanColor    = "\u001b[36;1m"
	BrightWhiteColor   = "\u001b[37;1m"
	ResetColor         = "\u001b[0m"
)

Colors

View Source
const (
	DefaultBackgroundColor       = ""
	BlackBackgroundColor         = "\u001b[40m"
	RedBackgroundColor           = "\u001b[41m"
	GreenBackgroundColor         = "\u001b[42m"
	YellowBackgroundColor        = "\u001b[43m"
	BlueBackgroundColor          = "\u001b[44m"
	MagentaBackgroundColor       = "\u001b[45m"
	CyanBackgroundColor          = "\u001b[46m"
	WhiteBackgroundColor         = "\u001b[47m"
	BrightBlackBackgroundColor   = "\u001b[40;1m"
	BrightRedBackgroundColor     = "\u001b[41;1m"
	BrightGreenBackgroundColor   = "\u001b[42;1m"
	BrightYellowBackgroundColor  = "\u001b[43;1m"
	BrightBlueBackgroundColor    = "\u001b[44;1m"
	BrightMagentaBackgroundColor = "\u001b[45;1m"
	BrightCyanBackgroundColor    = "\u001b[46;1m"
	BrightWhiteBackgroundColor   = "\u001b[47;1m"
)

Background colors

Variables

This section is empty.

Functions

func BackgroundColor

func BackgroundColor(backgroundcolorCode int) string

BackgroundColor returns background color with the inputted code.

func Color

func Color(colorCode int) string

Color returns color with the inputted code.

func Sprint

func Sprint(text ...any) string

Sprint returns string .

func Sprintf

func Sprintf(format string, params ...any) string

Sprintf returns string that formats with the inputted format.

func Sprintln

func Sprintln(text ...any) string

Sprintln returns string that formats with the inputted format and ends with new line.

Types

type Pattern

type Pattern struct {
	Color           string
	BackgroundColor string
}

Pattern is an instantiation that defines color and background color.

func Print

func Print(text ...any) *Pattern

Print prints inputted text.

func Printf

func Printf(format string, params ...any) *Pattern

Printf prints text formats with the inputted format.

func Println

func Println(text ...any) *Pattern

Println prints text and ends with newline.

func WithBackgroundColor

func WithBackgroundColor(backgroundColor string) *Pattern

WithBackgroundColor returns pattern with inputted background color.

func WithColor

func WithColor(color string) *Pattern

WithColor returns pattern with inputted color

func (*Pattern) Print

func (p *Pattern) Print(text ...any) *Pattern

Print prints inputted text formats with the color and background that set in the pattern.

func (*Pattern) Printf

func (p *Pattern) Printf(format string, params ...any) *Pattern

Printf prints text formats with the inputted format ,color and background that set in the pattern.

func (*Pattern) Println

func (p *Pattern) Println(text ...any) *Pattern

Println prints text formats with the color and background that set in the pattern and ends with newline.

func (*Pattern) Sprint

func (p *Pattern) Sprint(text ...any) string

Sprint returns string that formats with color and background color that set in the pattern.

func (*Pattern) Sprintf

func (p *Pattern) Sprintf(format string, params ...any) string

Sprintf returns string that formats with the inputted format and color and background that set in the pattern.

func (*Pattern) Sprintln

func (p *Pattern) Sprintln(text ...any) string

Sprintln returns string that formats with the inputted format and color and background color set in the pattern and ends with new line.

func (*Pattern) WithBackgroundColor

func (p *Pattern) WithBackgroundColor(backgroundColor string) *Pattern

WithBackgroundColor returns patterns that changed color with inputted background color.

func (*Pattern) WithColor

func (p *Pattern) WithColor(color string) *Pattern

WithColor returns patterns that changed color with inputted color.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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