gop

package
v0.15.2 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2021 License: MIT Imports: 15 Imported by: 0

README

Go Pretty Print Value

Make a random Go value human readable.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTheme = func(t Type) Color {
	switch t {
	case TypeName:
		return Cyan
	case Rune, Byte, String:
		return Yellow
	case Number:
		return Green
	case Chan, Func, UnsafePointer:
		return Magenta
	default:
		return None
	}
}

DefaultTheme colors for Sprint

View Source
var NoTheme = func(t Type) Color {
	return None
}

NoTheme colors for Sprint

View Source
var Stdout io.Writer = os.Stdout

Stdout is the default stdout for gop.P .

View Source
var SupportsColor = func() bool {
	b, _ := exec.Command("tput", "colors").CombinedOutput()
	n, _ := strconv.ParseInt(strings.TrimSpace(string(b)), 10, 32)
	return n > 0
}()

SupportsColor returns true if current shell supports ANSI color

Functions

func Base64

func Base64(string) []byte

Base64 from string

func ColorStr

func ColorStr(c Color, s string) string

ColorStr string

func Cyclic

func Cyclic(uintptr) interface{}

Cyclic reference

func F

func F(v interface{}) string

F is a shortcut for Format with color

func Format

func Format(ts []*Token, theme func(Type) Color) string

Format a list of tokens

func GetPrivateField

func GetPrivateField(v reflect.Value, i int) reflect.Value

GetPrivateField field value via field index TODO: we can use a LRU cache for the copy of the values, but it might be trivial for just testing.

func P

func P(vs ...interface{}) (int, error)

P pretty print the value list vs

func Plain

func Plain(v interface{}) string

Plain is a shortcut for Format with plain color

func StripColor added in v0.15.2

func StripColor(str string) string

StripColor is copied from https://github.com/acarl005/stripansi

func ToPtr

func ToPtr(interface{}) interface{}

ToPtr converts a Go value to its pointer

Types

type Color

type Color int

Color type

const (

	// Red type
	Red Color = iota + 31
	// Green type
	Green
	// Yellow type
	Yellow
	// Blue type
	Blue
	// Magenta type
	Magenta
	// Cyan type
	Cyan

	// None type
	None Color = -1
)

type Token

type Token struct {
	Type    Type
	Literal string
}

Token represents a symbol in value layout

func Tokenize

func Tokenize(v interface{}) []*Token

Tokenize a random Go value

type Type

type Type int

Type of token

const (
	// Nil type
	Nil Type = iota
	// Bool type
	Bool
	// Number type
	Number
	// Float type
	Float
	// Complex type
	Complex
	// String type
	String
	// Byte type
	Byte
	// Rune type
	Rune
	// Chan type
	Chan
	// Func type
	Func
	// UnsafePointer type
	UnsafePointer

	// TypeName type
	TypeName

	// ParenOpen type
	ParenOpen
	// ParenClose type
	ParenClose

	// PointerOpen type
	PointerOpen
	// PointerClose type
	PointerClose
	// PointerCyclic type
	PointerCyclic

	// SliceOpen type
	SliceOpen
	// SliceItem type
	SliceItem
	// InlineComma type
	InlineComma
	// Comma type
	Comma
	// SliceClose type
	SliceClose

	// MapOpen type
	MapOpen
	// MapKey type
	MapKey
	// Colon type
	Colon
	// MapClose type
	MapClose

	// StructOpen type
	StructOpen
	// StructKey type
	StructKey
	// StructField type
	StructField
	// StructClose type
	StructClose
)

Jump to

Keyboard shortcuts

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