Documentation
¶
Overview ¶
Package gop ...
Index ¶
- Constants
- Variables
- func Base64(s string) []byte
- func Circular(path ...interface{}) interface{}
- func Duration(s string) time.Duration
- func F(v interface{}) string
- func FixNestedStyle(s string) string
- func Format(ts []Token, theme Theme) string
- func GetPrivateField(v reflect.Value, i int) reflect.Value
- func GetPrivateFieldByName(v reflect.Value, name string) reflect.Value
- func GopError(msg string) error
- func JSONBytes(v interface{}, raw string) []byte
- func JSONStr(v interface{}, raw string) string
- func P(values ...interface{}) error
- func Plain(v interface{}) string
- func Ptr(v interface{}) interface{}
- func Render(sb *strings.Builder, str string, styles []Style)
- func Rune(i int32, r rune) rune
- func S(str string, styles ...Style) string
- func StripANSI(str string) string
- func Stylize(str string, styles []Style) string
- func Time(s string, monotonic int) time.Time
- func VisualizeANSI(str string) string
- type ByteTok
- type CommentPtrTok
- type ComplexTok
- type Float64Tok
- type FloatTok
- type IntTok
- type Lit
- type Options
- type PtrTok
- type RuneTok
- type Style
- type Styled
- type Theme
- type Token
- type Type
- type UintTok
Constants ¶
const SymbolBase64 = "gop.Base64"
SymbolBase64 for Base64
const SymbolCircular = "gop.Circular"
SymbolCircular for Circular
const SymbolDuration = "gop.Duration"
SymbolDuration for Duration
const SymbolGopError = "gop.GopError"
const SymbolJSONBytes = "gop.JSONBytes"
SymbolJSONBytes for JSONBytes
const SymbolJSONStr = "gop.JSONStr"
SymbolJSONStr for JSONStr
const SymbolPtr = "gop.Ptr"
SymbolPtr for Ptr
const SymbolRune = "gop.Rune"
SymbolRune for Rune
const SymbolTime = "gop.Time"
SymbolTime for Time
Variables ¶
var ( // Bold style Bold = addStyle(1, 22) // Faint style Faint = addStyle(2, 22) // Italic style Italic = addStyle(3, 23) // Underline style Underline = addStyle(4, 24) // Blink style Blink = addStyle(5, 25) // RapidBlink style RapidBlink = addStyle(6, 26) // Invert style Invert = addStyle(7, 27) // Hide style Hide = addStyle(8, 28) // Strike style Strike = addStyle(9, 29) // Black color Black = addStyle(30, 39) // Red color Red = addStyle(31, 39) // Green color Green = addStyle(32, 39) // Yellow color Yellow = addStyle(33, 39) // Blue color Blue = addStyle(34, 39) // Magenta color Magenta = addStyle(35, 39) // Cyan color Cyan = addStyle(36, 39) // White color White = addStyle(37, 39) // BgBlack color BgBlack = addStyle(40, 49) // BgRed color BgRed = addStyle(41, 49) // BgGreen color BgGreen = addStyle(42, 49) // BgYellow color BgYellow = addStyle(43, 49) // BgBlue color BgBlue = addStyle(44, 49) // BgMagenta color BgMagenta = addStyle(45, 49) // BgCyan color BgCyan = addStyle(46, 49) // BgWhite color BgWhite = addStyle(47, 49) // None type None = Style{} )
var DefaultOptions = Options{
MaxDepth: 15,
}
DefaultOptions for Tokenize.
var NoStyle = func() bool { _, noColor := os.LookupEnv("NO_COLOR") b, _ := exec.Command("tput", "colors").CombinedOutput() n, _ := strconv.ParseInt(strings.TrimSpace(string(b)), 10, 32) return noColor || n == 0 }()
NoStyle respects https://no-color.org/ and "tput colors"
var RegANSI = regexp.MustCompile(`\x1b\[\d+m`)
RegANSI token
var Stdout io.Writer = os.Stdout
Stdout is the default stdout for gop.P .
var ThemeDefault = func(t Type) []Style { switch t { case TypeName: return []Style{Cyan} case Bool, Chan: return []Style{Blue} case RuneInt32, Byte, String: return []Style{Yellow} case Number: return []Style{Green} case Func: return []Style{Magenta} case Comment: return []Style{White} case Nil: return []Style{Red} case Error: return []Style{Underline, Red} default: return []Style{None} } }
ThemeDefault colors for Sprint
var ThemeNone = func(t Type) []Style { return []Style{None} }
ThemeNone colors for Sprint
Functions ¶
func Circular ¶
func Circular(path ...interface{}) interface{}
Circular reference of the path from the root
func FixNestedStyle ¶
FixNestedStyle like
<d><a>1<b>2<c>3</d></>4</>5</>
into
<d><a>1</><b>2</><c>3</d></><b>4</><a>5</>
func GetPrivateField ¶
GetPrivateField 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 GetPrivateFieldByName ¶
GetPrivateFieldByName is similar with GetPrivateField
func GopError ¶ added in v0.3.0
GopError returns an error with the given message, it represents an error occurred during tokenization or formatting.
func Render ¶ added in v0.4.0
Render writes the stylized form of str to sb without allocating intermediate strings: both the single-line and multi-line paths stream directly into sb.
Types ¶
type ByteTok ¶ added in v0.4.0
type ByteTok byte
ByteTok lazily renders a byte as a Byte token, quoted when graphic else as 0xHEX.
type CommentPtrTok ¶ added in v0.4.0
type CommentPtrTok uintptr
CommentPtrTok lazily renders a uintptr as a Comment token in /* 0xHEX */ form.
func (CommentPtrTok) Build ¶ added in v0.4.0
func (p CommentPtrTok) Build(sb *strings.Builder)
Build appends the wrapped hex representation to sb.
type ComplexTok ¶ added in v0.4.0
type ComplexTok struct {
V complex128
Bits int
}
ComplexTok lazily renders a complex value at the given bit size as a Number token, stripping the parentheses that strconv.FormatComplex adds.
func (ComplexTok) Build ¶ added in v0.4.0
func (c ComplexTok) Build(sb *strings.Builder)
Build appends the formatted value to sb.
type Float64Tok ¶ added in v0.4.0
type Float64Tok float64
Float64Tok lazily renders a float64 as a Number token, appending ".0" when the value is integral.
func (Float64Tok) Build ¶ added in v0.4.0
func (f Float64Tok) Build(sb *strings.Builder)
Build appends the formatted value to sb.
type FloatTok ¶ added in v0.4.0
FloatTok lazily renders a float at the given bit size as a Number token.
type IntTok ¶ added in v0.4.0
type IntTok int64
IntTok lazily renders a signed integer as a Number token.
type Lit ¶ added in v0.4.0
Lit is a token with a fixed literal string.
type Options ¶ added in v0.3.0
type Options struct {
// MaxDepth limits the depth of tokenization for nested structures.
// If less than 1 there is no limit.
MaxDepth int
}
Options controls tokenization.
type PtrTok ¶ added in v0.4.0
type PtrTok uintptr
PtrTok lazily renders a uintptr as a Number token in 0xHEX form.
type RuneTok ¶ added in v0.4.0
type RuneTok rune
RuneTok lazily renders a rune as a RuneInt32 token (quoted).
type Styled ¶ added in v0.4.0
Styled wraps an inner Token and applies the given Styles when built. It is the token form of the legacy Stylize helper.
type Token ¶
Token represents a symbol in value layout. Build appends the token's rendered form to sb so the literal can be computed lazily and avoid allocating intermediate strings.
func Tokenize ¶
func Tokenize(v interface{}) []Token
Tokenize a random Go value with DefaultOptions.
func TokenizeWithOptions ¶ added in v0.3.0
TokenizeWithOptions tokenizes v with the given Options.
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 // RuneInt32 type RuneInt32 // Chan type Chan // Func type Func // Error type Error // Comment type Comment // TypeName type TypeName // ParenOpen type ParenOpen // ParenClose type ParenClose // Dot type Dot // And type And // 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 )