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 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 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 Style
- type Theme
- type Token
- type Type
Constants ¶
const SymbolBase64 = "gop.Base64"
SymbolBase64 for Base64
const SymbolCircular = "gop.Circular"
SymbolCircular for Circular
const SymbolDuration = "gop.Duration"
SymbolDuration for Duration
const SymbolJSONBytes = "gop.JSONBytes"
SymbolJSONBytes for JSONBytes
const SymbolJSONStr = "gop.JSONStr"
SymbolJSONStr for JSONStr
const SymbolPtr = "gop.Ptr"
SymbolPtr for Ptr
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 LongBytesLen = 16
LongBytesLen is the length of that will be treated as long bytes
var LongStringLen = 16
LongStringLen is the length of that will be treated as long string
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 Rune, 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 ¶ added in v0.17.0
func Circular(path ...interface{}) interface{}
Circular reference of the path from the root
func FixNestedStyle ¶ added in v0.24.0
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 ¶ added in v0.22.2
GetPrivateFieldByName is similar with GetPrivateField
Types ¶
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 // 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 )