printer

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2021 License: CC0-1.0, CC0-1.0, CC0-1.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ColorNone = Color(iota)
	ColorBold
	ColorUnderline
	ColorError
	ColorNil
	ColorInt
	ColorFloat
	ColorBool
	ColorString
	ColorTable
	ColorClosure
	ColorThread
	ColorUserData
	ColorCircular
	ColorEmptyItem
	ColorTruncatedArray
	ColorUnknown
)

The valid colours.

View Source
const (
	NilItem         = nilItem(0)
	CircularItem    = circularItem(0)
	TrueItem        = boolItem(true)
	FalseItem       = boolItem(false)
	EmptyStringItem = stringItem("")
	EmptyKeyItem    = keyItem("")
)

Standard constant values.

View Source
const ErrRetryNoInline = printerError(0)

ErrRetryNoInline indicates that printing failed because an object was printed inline and failed to fit. This is a temporary error: printing should be retried until no more ErrRetryNoInline are returned.

Variables

View Source
var NoColor = color.New()

NoColor is the default lack of a color returned by getColor. Treat this value as a constant.

Functions

This section is empty.

Types

type Color

type Color int

Color is used to represent a colour constant.

type Item

type Item interface {
	fmt.Stringer
	// IsInline returns true iff the item will be printed inline.
	IsInline() bool
	// ForceInline forces the item to be printed inline.
	ForceInline()
	// WriteItem writes the item to w, with initial cursor location cur, using the printer p. Returns the new cursor location.
	WriteItem(w io.Writer, cur int, p *Printer) (int, error)
	// Height returns the maximum depth of an item in the tree, rooted at the given item.
	Height() int
}

Item is the interface satisfied by an object that can be pretty-printed.

type KeyValueItem

type KeyValueItem struct {
	Key   string // The key
	Value Item   // The item for the value
}

KeyValueItem represents a key-value item for printing.

func (*KeyValueItem) ForceInline

func (v *KeyValueItem) ForceInline()

ForceInline forces the item to be printed inline.

func (*KeyValueItem) GetKey

func (v *KeyValueItem) GetKey() Item

GetKey returns the key for this key-value item, as an item.

func (*KeyValueItem) GetValue

func (v *KeyValueItem) GetValue() Item

GetValue returns the value for this key-value item.

func (*KeyValueItem) Height

func (v *KeyValueItem) Height() int

Height returns the maximum depth of an item in the tree, rooted at the given item.

func (*KeyValueItem) IsInline

func (v *KeyValueItem) IsInline() bool

IsInline returns true iff the item will be printed inline.

func (*KeyValueItem) String

func (v *KeyValueItem) String() string

String returns a string representation of the item.

func (*KeyValueItem) WriteItem

func (v *KeyValueItem) WriteItem(w io.Writer, cur int, p *Printer) (int, error)

WriteItem writes the item to w, with initial cursor location cur, using the printer p. Returns the new cursor location.

type Printer

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

Printer provides a way to print values to a io.Writer.

func New

func New(vm *rt.Runtime) *Printer

New returns a new printer for the given vm.

func (*Printer) Depth

func (p *Printer) Depth() int

Depth returns the current depth.

func (*Printer) GetColor

func (p *Printer) GetColor(t Color) *color.Color

GetColor returns the colour for the given class.

func (*Printer) GetScreenWidth

func (p *Printer) GetScreenWidth() int

GetScreenWidth returns the target display width (in characters). This will be used for line-wrapping. A width <= 0 indicates an "infinitely" wide target display.

func (*Printer) HaveVisited

func (p *Printer) HaveVisited(v rt.Value) bool

HaveVisited returns true iff the given value is currently in the visited stack.

func (*Printer) Indent

func (p *Printer) Indent() string

Indent returns the current indent.

func (*Printer) MainThread

func (p *Printer) MainThread() *rt.Thread

MainThread returns the main thread in the runtime.

func (*Printer) NewItem

func (p *Printer) NewItem(v rt.Value) Item

NewItem returns a new item that prints the given value.

func (*Printer) PopDepth

func (p *Printer) PopDepth() int

PopDepth decreases the depth. Returns the new depth.

func (*Printer) PopIndent

func (p *Printer) PopIndent() string

PopIndent decreases the indentation depth. Returns the new indent.

func (*Printer) PopVisited

func (p *Printer) PopVisited()

PopVisited pops a value off the visited stack.

func (*Printer) PushDepth

func (p *Printer) PushDepth() int

PushDepth increases the recursion depth. Every call to PushDepth should be balanced by a call to PopDepth. Returns the new depth.

func (*Printer) PushIndent

func (p *Printer) PushIndent() string

PushIndent increases the indentation depth. Every call to PushIndent should be balanced by a call to PopIndent. Returns the new indent.

func (*Printer) PushVisited

func (p *Printer) PushVisited(v rt.Value)

PushVisited pushes the value onto the visited stack. Every call to PushVisited should be balanced by a call to PopVisited.

func (*Printer) SetColor

func (p *Printer) SetColor(enable bool)

SetColor enables (true) or disables (false) colourised output.

func (*Printer) SetScreenWidth

func (p *Printer) SetScreenWidth(w int)

SetScreenWidth sets the target display width (in characters). This will be used for line-wrapping. A width <= 0 indicates an :infinitely" wide target display.

func (*Printer) WriteTo

func (p *Printer) WriteTo(w io.Writer, x Item) (int64, error)

WriteTo writes the item to w. It returns the number of bytes written and any write error encountered.

Jump to

Keyboard shortcuts

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