Documentation
¶
Overview ¶
color.go: Color API and implementation
pp.go: API definitions. The core implementation is delegated to printer.go.
Package pp The actual pretty print implementation. Everything in this file should be private.
sort.go: Implementation for sorting map keys
Index ¶
- Constants
- Variables
- func Errorf(format string, a ...interface{}) error
- func Fatal(a ...interface{})
- func Fatalf(format string, a ...interface{})
- func Fatalln(a ...interface{})
- func Fprint(w io.Writer, a ...interface{}) (n int, err error)
- func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error)
- func Fprintln(w io.Writer, a ...interface{}) (n int, err error)
- func GetDefaultOutput() io.Writer
- func Print(a ...interface{}) (n int, err error)
- func Printf(format string, a ...interface{}) (n int, err error)
- func Println(a ...interface{}) (n int, err error)
- func Sprint(a ...interface{}) string
- func Sprintf(format string, a ...interface{}) string
- func Sprintln(a ...interface{}) string
- type ByteSliceMode
- type ColorScheme
- type PrettyPrinter
- func (pp *PrettyPrinter) Errorf(format string, a ...interface{}) error
- func (pp *PrettyPrinter) Fatal(a ...interface{})
- func (pp *PrettyPrinter) Fatalf(format string, a ...interface{})
- func (pp *PrettyPrinter) Fatalln(a ...interface{})
- func (pp *PrettyPrinter) Fprint(w io.Writer, a ...interface{}) (n int, err error)
- func (pp *PrettyPrinter) Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error)
- func (pp *PrettyPrinter) Fprintln(w io.Writer, a ...interface{}) (n int, err error)
- func (pp *PrettyPrinter) GetOutput() io.Writer
- func (pp *PrettyPrinter) Print(a ...interface{}) (n int, err error)
- func (pp *PrettyPrinter) Printf(format string, a ...interface{}) (n int, err error)
- func (pp *PrettyPrinter) Println(a ...interface{}) (n int, err error)
- func (pp *PrettyPrinter) ResetColorScheme() *PrettyPrinter
- func (pp *PrettyPrinter) ResetOutput() *PrettyPrinter
- func (pp *PrettyPrinter) SetByteSliceMode(mode ByteSliceMode) *PrettyPrinter
- func (pp *PrettyPrinter) SetColorScheme(scheme ColorScheme) *PrettyPrinter
- func (pp *PrettyPrinter) SetColoring(enabled bool) *PrettyPrinter
- func (pp *PrettyPrinter) SetDecimalUint(enabled bool) *PrettyPrinter
- func (pp *PrettyPrinter) SetExportedOnly(enabled bool) *PrettyPrinter
- func (pp *PrettyPrinter) SetIgnoreFields(ignoreFields ...string) *PrettyPrinter
- func (pp *PrettyPrinter) SetOmitEmpty(enabled bool) *PrettyPrinter
- func (pp *PrettyPrinter) SetOutput(o io.Writer) *PrettyPrinter
- func (pp *PrettyPrinter) SetThousandsSeparator(enabled bool) *PrettyPrinter
- func (pp *PrettyPrinter) Sprint(a ...interface{}) string
- func (pp *PrettyPrinter) Sprintf(format string, a ...interface{}) string
- func (pp *PrettyPrinter) Sprintln(a ...interface{}) string
Constants ¶
const ( Black uint16 Red Green Yellow Blue Magenta Cyan White )
const ( BackgroundBlack uint16 BackgroundRed BackgroundGreen BackgroundYellow BackgroundBlue BackgroundMagenta BackgroundCyan BackgroundWhite )
const ( // Bold flag for ColorScheme. Bold uint16 = 1<<bitsBold | NoColor )
const ( // No color NoColor uint16 = 1 << 15 )
Variables ¶
var ( // Default pretty printer. It's public so that you can modify config globally. Default = newPrettyPrinter(3) // pp.* => PrettyPrinter.* => formatAll // If the length of array or slice is larger than this, // the buffer will be shorten as {...}. BufferFoldThreshold = 1024 // PrintMapTypes when set to true will have map types will always appended to maps. PrintMapTypes = true // WithLineInfo add file name and line information to output // call this function with care, because getting stack has performance penalty WithLineInfo bool )
Global variable API see also: color.go
Functions ¶
func Fatal ¶
func Fatal(a ...interface{})
Fatal prints given arguments and finishes execution with exit status 1.
func Fatalf ¶
func Fatalf(format string, a ...interface{})
Fatalf prints a given format and finishes execution with exit status 1.
func Fatalln ¶
func Fatalln(a ...interface{})
Fatalln prints given arguments with newline and finishes execution with exit status 1.
func Sprint ¶
func Sprint(a ...interface{}) string
Sprint formats given arguments and returns the result as string.
Types ¶
type ByteSliceMode ¶
type ByteSliceMode int
const ( ByteSliceAsString ByteSliceMode ByteSliceAsHex ByteSliceAsBase64 )
type ColorScheme ¶
type ColorScheme struct { Bool uint16 Integer uint16 Float uint16 String uint16 StringQuotation uint16 EscapedChar uint16 FieldName uint16 PointerAddress uint16 Nil uint16 Time uint16 StructName uint16 ObjectLength uint16 }
To use with SetColorScheme.
type PrettyPrinter ¶
type PrettyPrinter struct { // WithLineInfo adds file name and line information to output. // Call this function with care, because getting stack has performance penalty. WithLineInfo bool // contains filtered or unexported fields }
func New ¶
func New() *PrettyPrinter
New creates a new PrettyPrinter that can be used to pretty print values
func ResetColorScheme ¶
func ResetColorScheme() *PrettyPrinter
ResetColorScheme resets colorscheme to default.
func ResetDefaultOutput ¶
func ResetDefaultOutput() *PrettyPrinter
Change Print* functions' output to default one.
func SetColorScheme ¶
func SetColorScheme(scheme ColorScheme) *PrettyPrinter
SetColorScheme takes a colorscheme used by all future Print calls.
func SetDefaultMaxDepth ¶
func SetDefaultMaxDepth(v int) *PrettyPrinter
SetMaxDepth sets the printer's Depth, -1 prints all
func SetDefaultOutput ¶
func SetDefaultOutput(o io.Writer) *PrettyPrinter
Change Print* functions' output to a given writer. For example, you can limit output by ENV.
func init() { if os.Getenv("DEBUG") == "" { pp.SetDefaultOutput(ioutil.Discard) } }
func (*PrettyPrinter) Errorf ¶
func (pp *PrettyPrinter) Errorf(format string, a ...interface{}) error
Errorf formats given arguments and returns it as error type.
func (*PrettyPrinter) Fatal ¶
func (pp *PrettyPrinter) Fatal(a ...interface{})
Fatal prints given arguments and finishes execution with exit status 1.
func (*PrettyPrinter) Fatalf ¶
func (pp *PrettyPrinter) Fatalf(format string, a ...interface{})
Fatalf prints a given format and finishes execution with exit status 1.
func (*PrettyPrinter) Fatalln ¶
func (pp *PrettyPrinter) Fatalln(a ...interface{})
Fatalln prints given arguments with newline and finishes execution with exit status 1.
func (*PrettyPrinter) Fprint ¶
func (pp *PrettyPrinter) Fprint(w io.Writer, a ...interface{}) (n int, err error)
Fprint prints given arguments to a given writer.
func (*PrettyPrinter) Fprintln ¶
func (pp *PrettyPrinter) Fprintln(w io.Writer, a ...interface{}) (n int, err error)
Fprintln prints given arguments to a given writer with newline.
func (*PrettyPrinter) GetOutput ¶
func (pp *PrettyPrinter) GetOutput() io.Writer
GetOutput returns pp's output.
func (*PrettyPrinter) Print ¶
func (pp *PrettyPrinter) Print(a ...interface{}) (n int, err error)
Print prints given arguments.
func (*PrettyPrinter) Printf ¶
func (pp *PrettyPrinter) Printf(format string, a ...interface{}) (n int, err error)
Printf prints a given format.
func (*PrettyPrinter) Println ¶
func (pp *PrettyPrinter) Println(a ...interface{}) (n int, err error)
Println prints given arguments with newline.
func (*PrettyPrinter) ResetColorScheme ¶
func (pp *PrettyPrinter) ResetColorScheme() *PrettyPrinter
ResetColorScheme resets colorscheme to default.
func (*PrettyPrinter) ResetOutput ¶
func (pp *PrettyPrinter) ResetOutput() *PrettyPrinter
ResetOutput sets pp's output back to the default output
func (*PrettyPrinter) SetByteSliceMode ¶
func (pp *PrettyPrinter) SetByteSliceMode(mode ByteSliceMode) *PrettyPrinter
func (*PrettyPrinter) SetColorScheme ¶
func (pp *PrettyPrinter) SetColorScheme(scheme ColorScheme) *PrettyPrinter
SetColorScheme takes a colorscheme used by all future Print calls.
func (*PrettyPrinter) SetColoring ¶
func (pp *PrettyPrinter) SetColoring(enabled bool) *PrettyPrinter
func (*PrettyPrinter) SetDecimalUint ¶
func (pp *PrettyPrinter) SetDecimalUint(enabled bool) *PrettyPrinter
func (*PrettyPrinter) SetExportedOnly ¶
func (pp *PrettyPrinter) SetExportedOnly(enabled bool) *PrettyPrinter
func (*PrettyPrinter) SetIgnoreFields ¶
func (pp *PrettyPrinter) SetIgnoreFields(ignoreFields ...string) *PrettyPrinter
func (*PrettyPrinter) SetOmitEmpty ¶
func (pp *PrettyPrinter) SetOmitEmpty(enabled bool) *PrettyPrinter
func (*PrettyPrinter) SetOutput ¶
func (pp *PrettyPrinter) SetOutput(o io.Writer) *PrettyPrinter
SetOutput sets pp's output
func (*PrettyPrinter) SetThousandsSeparator ¶
func (pp *PrettyPrinter) SetThousandsSeparator(enabled bool) *PrettyPrinter
func (*PrettyPrinter) Sprint ¶
func (pp *PrettyPrinter) Sprint(a ...interface{}) string
Sprint formats given arguments and returns the result as string.
func (*PrettyPrinter) Sprintf ¶
func (pp *PrettyPrinter) Sprintf(format string, a ...interface{}) string
Sprintf formats with pretty print and returns the result as string.
func (*PrettyPrinter) Sprintln ¶
func (pp *PrettyPrinter) Sprintln(a ...interface{}) string
Sprintln formats given arguments with newline and returns the result as string.