Documentation
¶
Overview ¶
Package fmtc provides methods similar to fmt for colored output
Index ¶
- Variables
- func Bell()
- func Clean(s string) string
- func Errorf(f string, a ...interface{}) error
- func Fprint(w io.Writer, a ...interface{}) (int, error)
- func Fprintf(w io.Writer, f string, a ...interface{}) (int, error)
- func Fprintln(w io.Writer, a ...interface{}) (int, error)
- func Is256ColorsSupported() bool
- func IsTrueColorSupported() bool
- func LPrintf(maxSize int, f string, a ...interface{}) (int, error)
- func LPrintln(maxSize int, a ...interface{}) (int, error)
- func NewLine() (int, error)
- func Print(a ...interface{}) (int, error)
- func Printf(f string, a ...interface{}) (int, error)
- func Println(a ...interface{}) (int, error)
- func Sprint(a ...interface{}) string
- func Sprintf(f string, a ...interface{}) string
- func Sprintln(a ...interface{}) string
- func TLPrintf(maxSize int, f string, a ...interface{}) (int, error)
- func TLPrintln(maxSize int, a ...interface{}) (int, error)
- func TPrintf(f string, a ...interface{}) (int, error)
- func TPrintln(a ...interface{}) (int, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var DisableColors = os.Getenv("NO_COLOR") != ""
DisableColors disables all colors and modificators in output
Functions ¶
func Clean ¶
Clean returns string without color tags
Example ¶
// Remove color tags from text fmt.Println(Clean("{r}Text{!}"))
Output: Text
func Errorf ¶
Errorf formats according to a format specifier and returns the string as a value that satisfies error.
func Fprint ¶
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 ¶
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 ¶
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 by terminal
Example ¶
fmt.Printf("256 Colors Supported: %t\n", Is256ColorsSupported())
Output:
func IsTrueColorSupported ¶
func IsTrueColorSupported() bool
IsTrueColorSupported returns true if TrueColor (24-bit colors) is supported by terminal
Example ¶
fmt.Printf("TrueColor Supported: %t\n", IsTrueColorSupported())
Output:
func LPrintf ¶
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 ¶
LPrintln formats using the default formats for its operands and writes to standard output limited by the text size
func NewLine ¶
NewLine prints a newline to standard output
Example ¶
// just print a new line NewLine()
Output:
func Print ¶
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 24-bit colors (TrueColor): #hex foreground color %hex background color
func Printf ¶
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 ¶
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{!}") // 24-bit colors (# for foreground, % for background) Println("{#7cfc00}lawngreen text{!}") Println("{%6a5acd}slateblue 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 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 ¶
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 will replace previous message after 1 sec")
Output:
func TLPrintln ¶
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
Types ¶
This section is empty.