pretty

package module
v0.0.0-...-09732c2 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2018 License: MIT Imports: 8 Imported by: 53

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

Pretty-print Go data structures

Index

Constants

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

Variables

This section is empty.

Functions

func PrettyFormat

func PrettyFormat(i interface{}) string

pretty print the input value (to a string)

func PrettyPrint

func PrettyPrint(i interface{})

pretty print the input value (to stdout)

func PrettyPrintTo

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

pretty print the input value (to specified writer)

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
}

The context for printing

func (*Pretty) Print

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

pretty print the input value (no newline)

func (*Pretty) PrintValue

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

recursively print the input value

func (*Pretty) Println

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

pretty print the input value (newline)

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)

Jump to

Keyboard shortcuts

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