Categorygithub.com/jucardi/go-terminal-colors
modulepackage
1.0.2
Repository: https://github.com/jucardi/go-terminal-colors.git
Documentation: pkg.go.dev

# README

go-terminal-colors

Helpful utility to print colored output in the terminal.

Quick Start

To keep up to date with the most recent version:

go get github.com/jucardi/go-terminal-colors

To get a specific version:

go get gopkg.in/jucardi/go-terminal-colors.v1

Using the library

Supports two modalities, using the fmt function signatures with fmtc or creating a new IColorFlow which allows printing messages with chaining functions.

The fmt way

To print a message with colors using the fmt way, start by using fmtc.WithColors(colors...) which allows to pass multiple predefined terminal colors in the fmtc package, followed by the fmt function would use.

Example

fmtc.WithColors(fmtc.White, fmtc.Bold, fmtc.BgRed).Println("An error has ocurred!")

Using the color flow

The color flow allows using a custom io.Writer, or if not provided, it will generate the resulting string in memory which can then be retrieve by invoking the String() function.

Example using Stdout as the io.Writer

fmtc.New(os.Stdout).
	Print(" ERROR ", fmtc.White, fmtc.Bold, fmtc.BgRed).
	Print(" ").
	Print(timestamp, fmtc.Cyan).
	Print(" ").
	Println(err.Error)

Same example but using an in-memory writer to obtain the resulting string

result := fmtc.New().
	Print(" ERROR ", fmtc.White, fmtc.Bold, fmtc.BgRed).
	Print(" ").
	Print(timestamp, fmtc.Cyan).
	Print(" ").
	Println(err.Error).
	String()

# Functions

Fprint formats using the default formats for its operands and writes to w.
Fprintf formats according to a format specifier and writes to w.
Fprintln formats using the default formats for its operands and writes to w.
New creates a new IColorFlow - writer: (Optional) An io.Writer where the messages will be written.
Parse attempts to parse a string representing a predefined color.
WithColors is an easy way to use the same function signature presented in the 'fmt' to print color messages.

# Constants

background.
background.
background.
No description provided by the author
background.
background.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
background.
background.
No description provided by the author
background.
foreground.
foreground.
special formats.
special formats.
foreground.
No description provided by the author
special formats.
foreground.
foreground.
special formats.
special formats.
special formats.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
foreground.
foreground.
special formats.
No description provided by the author
foreground.

# Interfaces

No description provided by the author
No description provided by the author

# Type aliases

Args is an alias of []interface{}.
No description provided by the author