@@ -72,7 +72,7 @@ const (
72
72
73
73
// Zero or more lines in the tabular output.
74
74
type tableContents interface {
75
- Emit (t * table , buf io.Writer , indent int )
75
+ Emit (t * table , buf io.Writer )
76
76
}
77
77
78
78
// A section of lines in the tabular output, consisting of a header
@@ -91,16 +91,17 @@ func newSection(name string, contents ...tableContents) *section {
91
91
}
92
92
}
93
93
94
- func (s * section ) Emit (t * table , buf io.Writer , indent int ) {
94
+ func (s * section ) Emit (t * table , buf io.Writer ) {
95
95
var linesBuf bytes.Buffer
96
96
for _ , c := range s .contents {
97
+ subTable := t .subTable ()
97
98
var cBuf bytes.Buffer
98
- c .Emit (t , & cBuf , indent + 1 )
99
+ c .Emit (subTable , & cBuf )
99
100
100
- if indent == - 1 && linesBuf .Len () > 0 && cBuf .Len () > 0 {
101
+ if t . indent == - 1 && linesBuf .Len () > 0 && cBuf .Len () > 0 {
101
102
// The top-level section emits blank lines between its
102
103
// subsections:
103
- t .emitBlankRow (& linesBuf )
104
+ subTable .emitBlankRow (& linesBuf )
104
105
}
105
106
106
107
fmt .Fprint (& linesBuf , cBuf .String ())
@@ -112,7 +113,7 @@ func (s *section) Emit(t *table, buf io.Writer, indent int) {
112
113
113
114
// There's output, so emit the section header first:
114
115
if s .name != "" {
115
- t .formatSectionHeader (buf , indent , s .name )
116
+ t .formatSectionHeader (buf , s .name )
116
117
}
117
118
118
119
fmt .Fprint (buf , linesBuf .String ())
@@ -146,14 +147,14 @@ func newItem(
146
147
}
147
148
}
148
149
149
- func (l * item ) Emit (t * table , buf io.Writer , indent int ) {
150
+ func (l * item ) Emit (t * table , buf io.Writer ) {
150
151
levelOfConcern , interesting := l .levelOfConcern (t .threshold )
151
152
if ! interesting {
152
153
return
153
154
}
154
155
valueString , unitString := l .value .Human (l .prefixes , l .unit )
155
156
t .formatRow (
156
- buf , indent ,
157
+ buf ,
157
158
l .name , t .footnotes .CreateCitation (l .Footnote (t .nameStyle )),
158
159
valueString , unitString ,
159
160
levelOfConcern ,
@@ -312,17 +313,19 @@ type table struct {
312
313
threshold Threshold
313
314
nameStyle NameStyle
314
315
footnotes * Footnotes
316
+ indent int
315
317
}
316
318
317
319
func TableString (contents tableContents , threshold Threshold , nameStyle NameStyle ) string {
318
320
t := table {
319
321
threshold : threshold ,
320
322
nameStyle : nameStyle ,
321
323
footnotes : NewFootnotes (),
324
+ indent : - 1 ,
322
325
}
323
326
324
327
buf := & bytes.Buffer {}
325
- contents .Emit (& t , buf , - 1 )
328
+ contents .Emit (& t , buf )
326
329
327
330
if buf .Len () == 0 {
328
331
return "No problems above the current threshold were found\n "
@@ -331,6 +334,15 @@ func TableString(contents tableContents, threshold Threshold, nameStyle NameStyl
331
334
return t .generateHeader () + buf .String () + t .footnotes .String ()
332
335
}
333
336
337
+ func (t * table ) subTable () * table {
338
+ return & table {
339
+ threshold : t .threshold ,
340
+ nameStyle : t .nameStyle ,
341
+ footnotes : t .footnotes ,
342
+ indent : t .indent + 1 ,
343
+ }
344
+ }
345
+
334
346
func (t * table ) generateHeader () string {
335
347
buf := & bytes.Buffer {}
336
348
fmt .Fprintln (buf , "| Name | Value | Level of concern |" )
@@ -339,20 +351,20 @@ func (t *table) generateHeader() string {
339
351
}
340
352
341
353
func (t * table ) emitBlankRow (buf io.Writer ) {
342
- t . formatRow (buf , 0 , "" , "" , "" , "" , " " )
354
+ fmt . Fprintln (buf , "| | | | " )
343
355
}
344
356
345
- func (t * table ) formatSectionHeader (buf io.Writer , indent int , name string ) {
346
- t .formatRow (buf , indent , name , "" , "" , "" , "" )
357
+ func (t * table ) formatSectionHeader (buf io.Writer , name string ) {
358
+ t .formatRow (buf , name , "" , "" , "" , "" )
347
359
}
348
360
349
361
func (t * table ) formatRow (
350
- buf io.Writer , indent int ,
362
+ buf io.Writer ,
351
363
name , citation , valueString , unitString , levelOfConcern string ,
352
364
) {
353
365
prefix := ""
354
- if indent != 0 {
355
- prefix = spaces [:2 * (indent - 1 )] + "* "
366
+ if t . indent != 0 {
367
+ prefix = spaces [:2 * (t . indent - 1 )] + "* "
356
368
}
357
369
spacer := ""
358
370
l := len (prefix ) + len (name ) + len (citation )
0 commit comments