fmtc

package
v12.20.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2021 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Overview

Package fmtc provides methods similar to fmt for colored output

Index

Examples

Constants

This section is empty.

Variables

View Source
var DisableColors = false

DisableColors disables all colors and modificators in output

Functions

func Bell

func Bell()

Bell prints alert (bell) symbol

Example
// terminal bell
Bell()
Output:

func Clean

func Clean(s string) string

Clean returns string without color tags

Example
// Remove color tags from text
fmt.Println(Clean("{r}Text{!}"))
Output:

Text

func Errorf

func Errorf(f string, a ...interface{}) error

Errorf formats according to a format specifier and returns the string as a value that satisfies error.

func Fprint

func Fprint(w io.Writer, a ...interface{}) (int, error)

Fprint formats using the default formats for its operands and writes to w. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.

func Fprintf

func Fprintf(w io.Writer, f string, a ...interface{}) (int, error)

Fprintf formats according to a format specifier and writes to w. It returns the number of bytes written and any write error encountered.

func Fprintln

func Fprintln(w io.Writer, a ...interface{}) (int, error)

Fprintln formats using the default formats for its operands and writes to w. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

func Is256ColorsSupported

func Is256ColorsSupported() bool

Is256ColorsSupported returns true if 256 colors is supported

func LPrintf

func LPrintf(maxSize int, f string, a ...interface{}) (int, error)

LPrintf formats according to a format specifier and writes to standard output limited by the text size

Example
// Only "This is text" will be shown
LPrintf(12, "{r}This is %s {g} with colors{!}", "text")
Output:

func LPrintln

func LPrintln(maxSize int, a ...interface{}) (int, error)

LPrintln formats using the default formats for its operands and writes to standard output limited by the text size

func NewLine

func NewLine() (int, error)

NewLine prints a newline to standard output

Example
// just print a new line
NewLine()
Output:

func Print

func Print(a ...interface{}) (int, error)

Print formats using the default formats for its operands and writes to standard output. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.

Supported color codes: Modificators:

  • Light colors ! Default
  • Bold ^ Dim _ Underline ~ Blink @ Reverse

Foreground colors:

d Black (Dark)
r Red
g Green
y Yellow
b Blue
m Magenta
c Cyan
s Gray (Smokey)
w White

Background colors:

D Black (Dark)
R Red
G Green
Y Yellow
B Blue
M Magenta
C Cyan
S Gray (Smokey)
W White

256 colors:

#code foreground color
%code background color

func Printf

func Printf(f string, a ...interface{}) (int, error)

Printf formats according to a format specifier and writes to standard output. It returns the number of bytes written and any write error encountered.

Example
var (
	user         = "Bob"
	isUserOnline = true
)

if isUserOnline {
	Printf("User {c}%s{!} is {g}online{!}\n", user)
} else {
	Printf("User {c}%s{!} is {r}offline{!}\n", user)
}
Output:

func Println

func Println(a ...interface{}) (int, error)

Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

Example
// print colored text
// {!} is tag for style reset
Println("{d}black{!}")
Println("{r}red{!}")
Println("{y}yellow{!}")
Println("{b}blue{!}")
Println("{c}cyan{!}")
Println("{m}magenta{!}")
Println("{g}green{!}")
Println("{s}light grey{!}")

// use text modificators

// light colors
Println("{r-}light red{!}")
Println("{r-}dark grey{!}")

// bold + color
Println("{r*}red{!}")
Println("{g*}green{!}")

// dim
Println("{r^}red{!}")
Println("{g^}green{!}")

// underline
Println("{r_}red{!}")
Println("{g_}green{!}")

// blink
Println("{r~}red{!}")
Println("{g~}green{!}")

// reverse
Println("{r@}red{!}")
Println("{g@}green{!}")

// background color
Println("{D}black{!}")
Println("{R}red{!}")
Println("{Y}yellow{!}")
Println("{B}blue{!}")
Println("{C}cyan{!}")
Println("{M}magenta{!}")
Println("{G}green{!}")
Println("{S}light grey{!}")

// many tags at once
// underline, cyan text with the red background
Println("{cR_}text{!}")

// many tags in once
Println("{r}{*}red and bold{!}")

// modificator reset
Println("{r}{*}red and bold {!*}just red{!}")

// 256 colors. # for foreground, % for background
Println("{#201}pink text{!}")
Println("{%201}pink background{!}")
Output:

func Sprint

func Sprint(a ...interface{}) string

Sprint formats using the default formats for its operands and returns the resulting string. Spaces are added between operands when neither is a string.

func Sprintf

func Sprintf(f string, a ...interface{}) string

Sprintf formats according to a format specifier and returns the resulting string.

func Sprintln

func Sprintln(a ...interface{}) string

Sprintln formats using the default formats for its operands and returns the resulting string. Spaces are always added between operands and a newline is appended.

func TLPrintf

func TLPrintf(maxSize int, f string, a ...interface{}) (int, error)

TLPrintf removes all content on the current line and prints the new message limited by the text size

Example
// Power of TPrintf and LPrintf in one method
TLPrintf(22, "This is temporary text")
time.Sleep(time.Second)
TLPrintf(22, "This message replace previous message after 1 sec")
Output:

func TLPrintln

func TLPrintln(maxSize int, a ...interface{}) (int, error)

TPrintln removes all content on the current line and prints the new message limited by the text size with a new line symbol at the end

func TPrintf

func TPrintf(f string, a ...interface{}) (int, error)

TPrintf removes all content on the current line and prints the new message

Example
TPrintf("This is temporary text")
time.Sleep(time.Second)
TPrintf("This message replace previous message after 1 sec")
Output:

func TPrintln

func TPrintln(a ...interface{}) (int, error)

TPrintln removes all content on the current line and prints the new message with a new line symbol at the end

Types

This section is empty.

Directories

Path Synopsis
Package lscolors provides method for colorizing file names based on colors from dircolors
Package lscolors provides method for colorizing file names based on colors from dircolors

Jump to

Keyboard shortcuts

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