-
Notifications
You must be signed in to change notification settings - Fork 0
/
pretty.go
107 lines (94 loc) · 2.67 KB
/
pretty.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
// Copyright © 2016 Pennock Tech, LLC.
// All rights reserved, except as granted under license.
// Licensed per file LICENSE.txt
package tabular // import "go.pennock.tech/tabular"
import (
"bytes"
"fmt"
)
func debugCallbackSetCount(cs *callbackSet) int {
if cs == nil {
return 0
}
return len(cs.addTime) + len(cs.preCellRenderTime) + len(cs.renderTime) + len(cs.postCellRenderTime)
}
func (t *ATable) GoString() string {
buf := &bytes.Buffer{}
errCount := 0
if t.ErrorContainer != nil {
errCount = len(t.ErrorContainer.errors_)
}
cbCount := (debugCallbackSetCount(&t.tableItselfCallbacks) +
debugCallbackSetCount(&t.tableCellCallbacks) +
debugCallbackSetCount(&t.tableRowAdditionCallbacks))
fmt.Fprintf(buf, "*ATable(%d errors, %d col, %d row, %d cbs)",
errCount, t.NColumns(), t.NRows(), cbCount)
if t.propertyImpl.properties != nil {
fmt.Fprintf(buf, ".Props{%#v}", t.propertyImpl.properties)
}
fmt.Fprint(buf, ".Columns{")
for i := 0; i < len(t.columns); i++ {
if i > 0 {
fmt.Fprint(buf, ", ")
}
fmt.Fprintf(buf, "C(%d, %q, %dcbs)", i, t.columns[i].Name,
(debugCallbackSetCount(&t.columns[i].cellCallbacks) +
debugCallbackSetCount(&t.columns[i].columnItselfCallbacks)))
if t.columns[i].propertyImpl.properties != nil {
fmt.Fprintf(buf, ".Props{%#v}", t.columns[i].propertyImpl.properties)
}
}
if t.headerRow == nil {
fmt.Fprint(buf, "}.NoHeaders.Body[\n")
} else {
fmt.Fprint(buf, "}.HeaderRow{\n")
fmt.Fprintf(buf, " %#v\n", t.headerRow)
fmt.Fprint(buf, "}.Body[\n")
}
for _, row := range t.rows {
fmt.Fprintf(buf, " %#v,\n", row)
}
fmt.Fprint(buf, "]")
el := t.Errors()
if el == nil {
fmt.Fprint(buf, ".NoErrors☺")
} else {
fmt.Fprint(buf, ".Errors[\n")
for i := range el {
fmt.Fprintf(buf, " %q,\n", el[i])
}
fmt.Fprint(buf, "]")
}
return buf.String()
}
func (row *Row) GoString() string {
buf := &bytes.Buffer{}
fmt.Fprintf(buf, "R(n%d, %d cbs)",
row.rowNum,
(debugCallbackSetCount(&row.rowCellCallbacks) +
debugCallbackSetCount(&row.rowItselfCallbacks)))
if row.propertyImpl.properties != nil {
fmt.Fprintf(buf, ".Props{%#v}", row.propertyImpl.properties)
}
if row.isSeparator {
fmt.Fprint(buf, ".SEP")
return buf.String()
}
fmt.Fprint(buf, ".Cells{")
for i := range row.cells {
if i > 0 {
fmt.Fprint(buf, ", ")
}
fmt.Fprintf(buf, "%#v", &row.cells[i])
}
fmt.Fprint(buf, "}")
return buf.String()
}
func (cell *Cell) GoString() string {
buf := &bytes.Buffer{}
fmt.Fprintf(buf, "C(%q, %d cbs)", cell.String(), debugCallbackSetCount(&cell.callbacks))
if cell.propertyImpl.properties != nil {
fmt.Fprintf(buf, ".Props{%#v}\n\t", cell.propertyImpl.properties)
}
return buf.String()
}