Documentation
¶
Overview ¶
Package misc provides short helpers for ANSI colouring and numeric formatting
Package misc are just short snippets of functions
Index ¶
- Constants
- func AddToSlice(sl []string, str string) []string
- func Boldf(format string, args ...interface{}) string
- func FormatFloat(num float64, prc int, trim bool) string
- func Greenf(format string, args ...interface{}) string
- func LightBluef(format string, args ...interface{}) string
- func Purplef(format string, args ...interface{}) string
- func Redf(format string, args ...interface{}) string
- func RemoveFromSlice(sl []string, str string) []string
- func ShowError(e error, msg string, errType ErrorType)
- func Yellowf(format string, args ...interface{}) string
- type ErrorType
Constants ¶
const ( ErrPanic = iota MsgPanic ErrMsgPanic ErrFatal MsgFatal ErrMsgFatal ErrPrint MsgPrint ErrMsgPrint )
const ( Green = "\033[92m%s\033[0m" Red = "\033[91m%s\033[0m" Purple = "\033[95m%s\033[0m" Yellow = "\033[96m%s\033[0m" LightBlue = "\033[94m%s\033[0m" )
Colour helpers
const Bold = "\033[1m%s\033[0m"
ANSI colour codes Bold text
const BoldRightSize = "\033[1m%*s\033[0m"
BoldRightSize formats a string right-aligned in a field of width w
const BoldSize = "\033[1m%-*s\033[0m"
BoldSize formats a string left-aligned in a field of width w
Variables ¶
This section is empty.
Functions ¶
func AddToSlice ¶
AddToSlice adds a string to a slice if it doesn't already exists.
func FormatFloat ¶
FormatFloat renders a float64 with a fixed precision If trim is true, trailing zeroes and a dangling decimal point are removed
Example:
FormatFloat(1.2300, 4, true) // "1.23" FormatFloat(1.2, 4, false) // "1.2000"
func LightBluef ¶
func RemoveFromSlice ¶
RemoveFromSlice removes a string from a slice if it exists.
func ShowError ¶
ShowError Displays errors depending on the type of error Error types: ErrPanic - display error and panic MsgPanic - display message and panic ErrMsgPanic - display error and message and panic ErrFatal - display error and exit MsgFatal - display message and exit ErrMsgFatal - display error and message and exit ErrPrint - display error MsgPrint - display message ErrMsgPrint - display error and message