pretty

package
v0.0.90 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

README

pretty

A Pretty-printer for Go data structures

Installation

$ go get github.com/gobs/pretty

Documentation

http://godoc.org/github.com/gobs/pretty

Example

package main

import "github.com/gobs/pretty"

func main() {
    stuff := map[string]interface{} {
      "a": 1,
      "b": "due",
      "c": []int { 1, 2, 3 },
      "d": false,
    }

    pretty.PrettyPrint(stuff)
}

Documentation

Overview

Example (TabPrint)
tp := NewTabPrinter(8)

for i := 0; i < 33; i++ {
	tp.Print(i)
}

tp.Println()

for _, v := range []string{"one", "two", "three", "four", "five", "six"} {
	tp.Print(v)
}

tp.Println()
Output:
0	1	2	3	4	5	6	7
8	9	10	11	12	13	14	15
16	17	18	19	20	21	22	23
24	25	26	27	28	29	30	31
32
one	two	three	four	five	six
Example (TabPrintTwoFullLines)
tp := NewTabPrinter(4)

for _, v := range []string{"one", "two", "three", "four", "five", "six", "seven", "eight"} {
	tp.Print(v)
}

tp.Println()
Output:
one	two	three	four
five	six	seven	eight
Example (TabPrintWider)
tp := NewTabPrinter(2)
tp.TabWidth(10)

for _, v := range []string{"one", "two", "three", "four", "five", "six", "seven", "eight", "larger", "largest", "even more", "enough"} {
	tp.Print(v)
}

tp.Println()
Output:
one       two
three     four
five      six
seven     eight
larger    largest
even more enough

Index

Examples

Constants

View Source
const (
	DEFAULT_INDENT = "  "
	DEFAULT_NIL    = "nil"
)

Variables

This section is empty.

Functions

func Bool2Integer

func Bool2Integer[T Integer](b bool) T

func DumpHex

func DumpHex[T []byte | *bytes.Buffer](buf T) (dump string)

func Format

func Format(i interface{}) string

func FormatInteger

func FormatInteger[T Integer](data T) string

func FormatIntegerHex

func FormatIntegerHex[T Integer](data T) string

func FormatIntegerHex0x

func FormatIntegerHex0x[T Integer](data T) string

func Integer2Bool

func Integer2Bool[T Integer](value T) bool

func IsASCIIAlpha

func IsASCIIAlpha(s string) bool

func IsASCIIDigit

func IsASCIIDigit(s string) bool

func IsAlphanumeric

func IsAlphanumeric(s string) bool

func IsIncludeLine

func IsIncludeLine(s string) bool

func Print

func Print(i interface{})

func PrintTo

func PrintTo(out io.Writer, i interface{}, nl bool)

func ValueIsBytesType

func ValueIsBytesType(v reflect.Value) bool

Types

type Complex

type Complex interface {
	~complex64 | ~complex128
}

type Float

type Float interface {
	~float32 | ~float64
}

type Integer

type Integer interface {
	Signed | Unsigned
}

type Ordered

type Ordered interface {
	Integer | Float | ~string
}

type Pretty

type Pretty struct {
	// indent string
	Indent string
	// output recipient
	Out io.Writer
	// string for nil
	NilString string
	// compact empty array and struct
	Compact bool
	// Maximum nesting level
	MaxLevel int
}

func (*Pretty) Print

func (p *Pretty) Print(i interface{})

func (*Pretty) PrintValue

func (p *Pretty) PrintValue(val r.Value, level int)

func (*Pretty) Println

func (p *Pretty) Println(i interface{})

type Signed

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type TabPrinter

type TabPrinter struct {
	// contains filtered or unexported fields
}

A TabPrinter is an object that allows printing tab-aligned words on multiple lines, up to a maximum number per line

func NewTabPrinter

func NewTabPrinter(max int) *TabPrinter

create a TabPrinter max specifies the maximum number of 'words' per line

func (*TabPrinter) Print

func (tp *TabPrinter) Print(arg interface{})

print a 'word' when the maximum number of words per lines is reached, this will print the formatted line

func (*TabPrinter) Println

func (tp *TabPrinter) Println()

print current line terminate current line and print - call this after all words have been printed

func (*TabPrinter) TabWidth

func (tp *TabPrinter) TabWidth(n int)

update tab width (minimal space between words)

type Unsigned

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

Jump to

Keyboard shortcuts

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