-
Notifications
You must be signed in to change notification settings - Fork 2
/
options.go
132 lines (113 loc) · 3.76 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package tada
import (
"strings"
"sync"
"time"
)
var optionLevelSeparator = "|"
var optionMaxRows = 50
var optionMaxColumns = 20
var optionMaxCellWidth = 30
var optionsNullPrinter = "(null)"
var optionMergeRepeats = true
var optionWrapLines = false
var optionWarnings = true
var optionNullStrings = &nullStrings{list: map[string]bool{optionsNullPrinter: true}}
var optionNaNIsNull = true
var optionPrefix = "*"
var optionDateTimeFormats = []string{
"2006-01-02", "01-02-2006", "01/02/2006", "1/2/06", "1/2/2006", "2006-01-02 15:04:05 -0700 MST",
time.Kitchen, strings.ToLower(time.Kitchen),
time.RFC3339, time.RFC3339Nano, time.RFC822}
type nullStrings struct {
list map[string]bool
mu sync.RWMutex
}
func (opt *nullStrings) Toggle(s string) {
opt.mu.Lock()
if _, ok := opt.list[s]; !ok {
opt.list[s] = true
} else {
delete(opt.list, s)
}
opt.mu.Unlock()
}
func (opt *nullStrings) Read() map[string]bool {
opt.mu.RLock()
defer opt.mu.RUnlock()
return opt.list
}
// SetOptionDefaultSeparator changes the separator used in group names and multi-level column names to sep
// (default: "|").
func SetOptionDefaultSeparator(sep string) {
optionLevelSeparator = sep
}
// SetOptionAddTimeFormat adds format to the list of time formats that
// can be parsed when converting values from string to time.Time.
func SetOptionAddTimeFormat(format string) {
optionDateTimeFormats = append(optionDateTimeFormats, format)
}
// GetOptionDefaultNullStrings returns the default list of strings that tada considers null.
func GetOptionDefaultNullStrings() []string {
return []string{optionsNullPrinter}
}
// SetOptionAddNullString appends a value to the set of strings that tada considers null.
func SetOptionAddNullString(s string) {
if _, ok := optionNullStrings.Read()[s]; !ok {
optionNullStrings.Toggle(s)
}
}
// SetOptionEmptyStringAsNull changes whether tada considers "" to be a null value when reading in data (default: false).
func SetOptionEmptyStringAsNull(set bool) {
if set {
if _, ok := optionNullStrings.Read()[""]; !ok {
optionNullStrings.Toggle("")
}
}
if !set {
if _, ok := optionNullStrings.Read()[""]; ok {
optionNullStrings.Toggle("")
}
}
}
// SetOptionNaNStatus sets whether math.NaN() is considered a null value or not (default: true).
func SetOptionNaNStatus(set bool) {
optionNaNIsNull = set
}
// PrintOptionMaxRows changes the max number of rows displayed when printing a Series or DataFrame to n
// (default: 50).
func PrintOptionMaxRows(n int) {
optionMaxRows = n
}
// PrintOptionMaxColumns changes the max number of columns displayed when printing a Series or DataFrame to n
// (default: 20).
func PrintOptionMaxColumns(n int) {
optionMaxColumns = n
}
// PrintOptionMaxCellWidth changes the max rune width of any cell displayed when printing a Series or DataFrame to n
// (default: 30).
func PrintOptionMaxCellWidth(n int) {
optionMaxCellWidth = n
}
// defaultMaxCellWidth returns the default max rune width of any cell displayed when printing a Series or DataFrame.
func defaultMaxCellWidth() int {
return 30
}
// PrintOptionMergeRepeats (if true) instructs the String() function to merge repeated non-header values
// when printing a Series or DataFrame (default: true).
func PrintOptionMergeRepeats(set bool) {
optionMergeRepeats = set
}
// PrintOptionWrapLines (if true) instructs the String() function to wrap overly-wide rows onto new lines instead of truncating them
// when printing a Series or DataFrame (default: truncate).
func PrintOptionWrapLines(set bool) {
optionWrapLines = set
}
// DisableWarnings prevents tada from writing warning messages to the default log writer.
func DisableWarnings() {
optionWarnings = false
}
// EnableWarnings allows tada to write warning messages to the default log writer.
func EnableWarnings() {
optionWarnings = true
}