pretty

package
v3.116.1 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

pretty is an extensible utility library to pretty-print nested structures.

Index

Constants

View Source
const (
	DefaultColumns int    = 100
	DefaultIndent  string = "  "
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Formatter

type Formatter interface {
	fmt.Stringer

	// Set the number of columns to print out.
	// This method does not mutate.
	Columns(int) Formatter
	// contains filtered or unexported methods
}

A formatter understands how to turn itself into a string while respecting a desired column target.

func FromString

func FromString(s string) Formatter

Create a new Formatter of a raw string.

func FromStringer

func FromStringer(s fmt.Stringer) Formatter

Create a new Formatter from a fmt.Stringer.

type List

type List struct {
	Elements        []Formatter
	Separator       string
	AdjoinSeparator bool
	// contains filtered or unexported fields
}

An ordered set of items displayed with a separator between them.

Items can be displayed on a single line if it fits within the column constraint. Otherwise items will be displayed across multiple lines.

func (List) Columns

func (l List) Columns(columns int) Formatter

func (*List) String

func (l *List) String() string

type Object

type Object struct {
	Properties map[string]Formatter
	// contains filtered or unexported fields
}

Object is a Formatter that prints string-Formatter pairs, respecting columns where possible.

It does this by deciding if the object should be compressed into a single line, or have one field per line.

func (*Object) Columns

func (o *Object) Columns(columns int) Formatter

func (*Object) String

func (o *Object) String() string

type Wrap

type Wrap struct {
	Prefix, Postfix string
	// Require that the Postfix is always on the same line as Value.
	PostfixSameline bool
	Value           Formatter
	// contains filtered or unexported fields
}

A Formatter that wraps an inner value with prefixes and postfixes.

Wrap attempts to respect its column target by changing if the prefix and postfix are on the same line as the inner value, or their own lines.

As an example, consider the following instance of Wrap:

Wrap {
  Prefix: "number(", Postfix: ")"
  Value: FromString("123456")
}

It could be rendered as

number(123456)

or

number(
  123456
)

depending on the column constrains.

func (Wrap) Columns

func (w Wrap) Columns(columns int) Formatter

func (*Wrap) String

func (w *Wrap) String() string

Jump to

Keyboard shortcuts

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