pretty

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 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 := range 33 {
	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 Format

func Format(i any) string

func Print

func Print(i any)

func PrintTo

func PrintTo(out io.Writer, i any, nl bool)

Types

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 any)

func (*Pretty) PrintValue

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

func (*Pretty) Println

func (p *Pretty) Println(i any)

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 any)

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)

Jump to

Keyboard shortcuts

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