-
Notifications
You must be signed in to change notification settings - Fork 9
/
options.go
94 lines (75 loc) · 2.29 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package prettyslice
import (
"github.com/fatih/color"
)
var (
// ColorHeader sets the color for the header
ColorHeader = color.New(
color.BgHiBlack,
color.FgMagenta,
color.Bold)
// ColorSlice sets the color for the slice's items
ColorSlice = color.New(color.FgCyan)
// ColorBacker sets the color for the backing array's items
ColorBacker = color.New(color.FgHiBlack)
// ColorIndex sets the color for the index numbers of the elements
ColorIndex = ColorBacker
// ColorAddr sets the color for the element addresses
ColorAddr = ColorBacker
// MaxPerLine is maximum number of slice items on a line
MaxPerLine = 5
// MaxElements limits the number of elements printed
// 0 means print all the elements.
MaxElements = 0
// Width is the width of the header
// It will separate the header message and the slice details with empty spaces
Width = 45
// PrettyByteRune prints byte and rune elements as chars
PrettyByteRune = true
// PrintBacking prints the backing array if it's true
PrintBacking = false
// PrintElementAddr prints the addresses of each element
PrintElementAddr = false
// PrintHex prints the pointers in hexadecimals
//
// When it's false, only the last 4 digits of the pointers will be printed as decimals.
//
// When it's true, all the digits of the pointers will be printed as hexadecimals.
PrintHex = false
// PrintBytesHex prints byte elements as hex digits
PrintBytesHex = false
// SpaceCharacter gets printed when a space character is found.
// (only if PrettyByteRune is true)
SpaceCharacter = ' '
// NormalizePointers prints pointers as if they're contiguous.
//
// Let's say you've []int64{1, 2}
//
// Memory addresses
// 1st element: 8000
// 2nd element: 8008
//
// This option prints them like this instead:
//
// Memory addresses
// 1st element: 8000
// 2nd element: 8001
//
// So, it basically normalizes by the element type size.
NormalizePointers = false
// Writer controls where to draw the slices
Writer = color.Output
)
// Colors is used to enable/disable the color data from the output
func Colors(enabled bool) {
colors := []*color.Color{
ColorHeader, ColorSlice, ColorBacker, ColorIndex,
}
for _, color := range colors {
if enabled {
color.EnableColor()
} else {
color.DisableColor()
}
}
}