@@ -13,6 +13,7 @@ import (
13
13
type Blueprint struct {
14
14
config tw.Rendition // Rendering configuration for table borders and symbols
15
15
logger * ll.Logger // Logger for debug trace messages
16
+ w io.Writer
16
17
}
17
18
18
19
// NewBlueprint creates a new Blueprint instance with optional custom configurations.
@@ -46,7 +47,7 @@ func NewBlueprint(configs ...tw.Rendition) *Blueprint {
46
47
}
47
48
48
49
// Close performs cleanup (no-op in this implementation).
49
- func (f * Blueprint ) Close (w io. Writer ) error {
50
+ func (f * Blueprint ) Close () error {
50
51
f .logger .Debug ("Blueprint.Close() called (no-op)." )
51
52
return nil
52
53
}
@@ -57,24 +58,24 @@ func (f *Blueprint) Config() tw.Rendition {
57
58
}
58
59
59
60
// Footer renders the table footer section with configured formatting.
60
- func (f * Blueprint ) Footer (w io. Writer , footers [][]string , ctx tw.Formatting ) {
61
+ func (f * Blueprint ) Footer (footers [][]string , ctx tw.Formatting ) {
61
62
f .logger .Debugf ("Starting Footer render: IsSubRow=%v, Location=%v, Pos=%s" , ctx .IsSubRow , ctx .Row .Location , ctx .Row .Position )
62
63
// Render the footer line
63
- f .renderLine (w , ctx )
64
+ f .renderLine (ctx )
64
65
f .logger .Debug ("Completed Footer render" )
65
66
}
66
67
67
68
// Header renders the table header section with configured formatting.
68
- func (f * Blueprint ) Header (w io. Writer , headers [][]string , ctx tw.Formatting ) {
69
+ func (f * Blueprint ) Header (headers [][]string , ctx tw.Formatting ) {
69
70
f .logger .Debugf ("Starting Header render: IsSubRow=%v, Location=%v, Pos=%s, lines=%d, widths=%v" ,
70
71
ctx .IsSubRow , ctx .Row .Location , ctx .Row .Position , len (ctx .Row .Current ), ctx .Row .Widths )
71
72
// Render the header line
72
- f .renderLine (w , ctx )
73
+ f .renderLine (ctx )
73
74
f .logger .Debug ("Completed Header render" )
74
75
}
75
76
76
77
// Line renders a full horizontal row line with junctions and segments.
77
- func (f * Blueprint ) Line (w io. Writer , ctx tw.Formatting ) {
78
+ func (f * Blueprint ) Line (ctx tw.Formatting ) {
78
79
// Initialize junction renderer
79
80
jr := NewJunction (JunctionContext {
80
81
Symbols : f .config .Symbols ,
@@ -107,7 +108,7 @@ func (f *Blueprint) Line(w io.Writer, ctx tw.Formatting) {
107
108
if prefix != "" || suffix != "" {
108
109
line .WriteString (prefix + suffix + tw .NewLine )
109
110
totalLineWidth = tw .DisplayWidth (prefix ) + tw .DisplayWidth (suffix )
110
- fmt .Fprint (w , line .String ())
111
+ fmt .Fprint (f . w , line .String ())
111
112
}
112
113
f .logger .Debugf ("Line: Handled empty row/widths case (total width %d)" , totalLineWidth )
113
114
return
@@ -135,7 +136,7 @@ func (f *Blueprint) Line(w io.Writer, ctx tw.Formatting) {
135
136
line .WriteString (leftBorder )
136
137
leftBorderWidth = tw .DisplayWidth (leftBorder )
137
138
totalLineWidth += leftBorderWidth
138
- f .logger .Debugf ("Line: Left border='%s' (width %d)" , leftBorder , leftBorderWidth )
139
+ f .logger .Debugf ("Line: Left border='%s' (f. width %d)" , leftBorder , leftBorderWidth )
139
140
}
140
141
141
142
visibleColIndices := make ([]int , 0 )
@@ -156,7 +157,7 @@ func (f *Blueprint) Line(w io.Writer, ctx tw.Formatting) {
156
157
// Adjust colWidth to account for wider borders
157
158
adjustedColWidth := colWidth
158
159
if f .config .Borders .Left .Enabled () && keyIndex == 0 {
159
- adjustedColWidth -= ( leftBorderWidth - tw .DisplayWidth (f .config .Symbols .Column () ))
160
+ adjustedColWidth -= leftBorderWidth - tw .DisplayWidth (f .config .Symbols .Column ())
160
161
}
161
162
if f .config .Borders .Right .Enabled () && keyIndex == len (visibleColIndices )- 1 {
162
163
rightBorderWidth := tw .DisplayWidth (jr .RenderRight (currentColIdx ))
@@ -170,7 +171,7 @@ func (f *Blueprint) Line(w io.Writer, ctx tw.Formatting) {
170
171
spaces := strings .Repeat (" " , adjustedColWidth )
171
172
line .WriteString (spaces )
172
173
totalLineWidth += adjustedColWidth
173
- f .logger .Debugf ("Line: Rendered spaces='%s' (width %d) for col %d" , spaces , adjustedColWidth , currentColIdx )
174
+ f .logger .Debugf ("Line: Rendered spaces='%s' (f. width %d) for col %d" , spaces , adjustedColWidth , currentColIdx )
174
175
} else {
175
176
segmentWidth := tw .DisplayWidth (segment )
176
177
if segmentWidth == 0 {
@@ -205,7 +206,7 @@ func (f *Blueprint) Line(w io.Writer, ctx tw.Formatting) {
205
206
}
206
207
line .WriteString (repeatedSegment )
207
208
totalLineWidth += actualWidth
208
- f .logger .Debugf ("Line: Rendered segment='%s' (width %d) for col %d" , repeatedSegment , actualWidth , currentColIdx )
209
+ f .logger .Debugf ("Line: Rendered segment='%s' (f. width %d) for col %d" , repeatedSegment , actualWidth , currentColIdx )
209
210
}
210
211
211
212
// Add junction between columns if not the last column
@@ -223,7 +224,7 @@ func (f *Blueprint) Line(w io.Writer, ctx tw.Formatting) {
223
224
junctionWidth := tw .DisplayWidth (junction )
224
225
line .WriteString (junction )
225
226
totalLineWidth += junctionWidth
226
- f .logger .Debugf ("Line: Junction between %d and %d: '%s' (width %d)" , currentColIdx , nextColIdx , junction , junctionWidth )
227
+ f .logger .Debugf ("Line: Junction between %d and %d: '%s' (f. width %d)" , currentColIdx , nextColIdx , junction , junctionWidth )
227
228
}
228
229
}
229
230
@@ -235,12 +236,12 @@ func (f *Blueprint) Line(w io.Writer, ctx tw.Formatting) {
235
236
rightBorderWidth = tw .DisplayWidth (rightBorder )
236
237
line .WriteString (rightBorder )
237
238
totalLineWidth += rightBorderWidth
238
- f .logger .Debugf ("Line: Right border='%s' (width %d)" , rightBorder , rightBorderWidth )
239
+ f .logger .Debugf ("Line: Right border='%s' (f. width %d)" , rightBorder , rightBorderWidth )
239
240
}
240
241
241
242
// Write the final line
242
243
line .WriteString (tw .NewLine )
243
- fmt .Fprint (w , line .String ())
244
+ fmt .Fprint (f . w , line .String ())
244
245
f .logger .Debugf ("Line rendered: '%s' (total width %d, target %d)" , strings .TrimSuffix (line .String (), tw .NewLine ), totalLineWidth , targetTotalWidth )
245
246
}
246
247
@@ -250,17 +251,18 @@ func (f *Blueprint) Logger(logger *ll.Logger) {
250
251
}
251
252
252
253
// Row renders a table data row with configured formatting.
253
- func (f * Blueprint ) Row (w io. Writer , row []string , ctx tw.Formatting ) {
254
+ func (f * Blueprint ) Row (row []string , ctx tw.Formatting ) {
254
255
f .logger .Debugf ("Starting Row render: IsSubRow=%v, Location=%v, Pos=%s, hasFooter=%v" ,
255
256
ctx .IsSubRow , ctx .Row .Location , ctx .Row .Position , ctx .HasFooter )
256
257
257
258
// Render the row line
258
- f .renderLine (w , ctx )
259
+ f .renderLine (ctx )
259
260
f .logger .Debug ("Completed Row render" )
260
261
}
261
262
262
263
// Start initializes the rendering process (no-op in this implementation).
263
264
func (f * Blueprint ) Start (w io.Writer ) error {
265
+ f .w = w
264
266
f .logger .Debug ("Blueprint.Start() called (no-op)." )
265
267
return nil
266
268
}
@@ -380,7 +382,7 @@ func (f *Blueprint) formatCell(content string, width int, padding tw.Padding, al
380
382
}
381
383
382
384
// renderLine renders a single line (header, row, or footer) with borders, separators, and merge handling.
383
- func (f * Blueprint ) renderLine (w io. Writer , ctx tw.Formatting ) {
385
+ func (f * Blueprint ) renderLine (ctx tw.Formatting ) {
384
386
// Get sorted column indices
385
387
sortedKeys := ctx .Row .Widths .SortedKeys ()
386
388
numCols := 0
@@ -404,7 +406,7 @@ func (f *Blueprint) renderLine(w io.Writer, ctx tw.Formatting) {
404
406
if prefix != "" {
405
407
output .WriteString (prefix )
406
408
totalLineWidth += tw .DisplayWidth (prefix )
407
- f .logger .Debugf ("renderLine: Prefix='%s' (width %d)" , prefix , tw .DisplayWidth (prefix ))
409
+ f .logger .Debugf ("renderLine: Prefix='%s' (f. width %d)" , prefix , tw .DisplayWidth (prefix ))
408
410
}
409
411
410
412
colIndex := 0
@@ -437,7 +439,7 @@ func (f *Blueprint) renderLine(w io.Writer, ctx tw.Formatting) {
437
439
if shouldAddSeparator {
438
440
output .WriteString (columnSeparator )
439
441
totalLineWidth += separatorDisplayWidth
440
- f .logger .Debugf ("renderLine: Added separator '%s' before col %d (width %d)" , columnSeparator , colIndex , separatorDisplayWidth )
442
+ f .logger .Debugf ("renderLine: Added separator '%s' before col %d (f. width %d)" , columnSeparator , colIndex , separatorDisplayWidth )
441
443
} else if colIndex > 0 {
442
444
f .logger .Debugf ("renderLine: Skipped separator before col %d due to zero-width prev col or HMerge continuation" , colIndex )
443
445
}
@@ -485,7 +487,7 @@ func (f *Blueprint) renderLine(w io.Writer, ctx tw.Formatting) {
485
487
spaces := strings .Repeat (" " , visualWidth )
486
488
output .WriteString (spaces )
487
489
totalLineWidth += visualWidth
488
- f .logger .Debugf ("renderLine: No cell context for col %d, writing %d spaces (width %d)" , colIndex , visualWidth , visualWidth )
490
+ f .logger .Debugf ("renderLine: No cell context for col %d, writing %d spaces (f. width %d)" , colIndex , visualWidth , visualWidth )
489
491
} else {
490
492
f .logger .Debugf ("renderLine: No cell context for col %d, visualWidth is 0, writing nothing" , colIndex )
491
493
}
@@ -540,7 +542,7 @@ func (f *Blueprint) renderLine(w io.Writer, ctx tw.Formatting) {
540
542
output .WriteString (formattedCell )
541
543
cellWidth := tw .DisplayWidth (formattedCell )
542
544
totalLineWidth += cellWidth
543
- f .logger .Debugf ("renderLine: Rendered col %d, formattedCell='%s' (width %d), totalLineWidth=%d" , colIndex , formattedCell , cellWidth , totalLineWidth )
545
+ f .logger .Debugf ("renderLine: Rendered col %d, formattedCell='%s' (f. width %d), totalLineWidth=%d" , colIndex , formattedCell , cellWidth , totalLineWidth )
544
546
}
545
547
546
548
// Log rendering details
@@ -558,10 +560,10 @@ func (f *Blueprint) renderLine(w io.Writer, ctx tw.Formatting) {
558
560
if output .Len () > len (prefix ) || f .config .Borders .Right .Enabled () {
559
561
output .WriteString (suffix )
560
562
totalLineWidth += tw .DisplayWidth (suffix )
561
- f .logger .Debugf ("renderLine: Suffix='%s' (width %d)" , suffix , tw .DisplayWidth (suffix ))
563
+ f .logger .Debugf ("renderLine: Suffix='%s' (f. width %d)" , suffix , tw .DisplayWidth (suffix ))
562
564
}
563
565
output .WriteString (tw .NewLine )
564
- fmt .Fprint (w , output .String ())
566
+ fmt .Fprint (f . w , output .String ())
565
567
f .logger .Debugf ("renderLine: Final rendered line: '%s' (total width %d)" , strings .TrimSuffix (output .String (), tw .NewLine ), totalLineWidth )
566
568
}
567
569
0 commit comments