Skip to content

Commit 8596f56

Browse files
committed
remove all debug information
1 parent 736f849 commit 8596f56

File tree

6 files changed

+54
-56
lines changed

6 files changed

+54
-56
lines changed

_example/symbols/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func main() {
2828
Alignment: tw.AlignLeft,
2929
},
3030
},
31-
Debug: true,
31+
Debug: false,
3232
}
3333

3434
// Create a custom border style

renderer/markdown.go

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -154,38 +154,33 @@ func (m *Markdown) formatCell(content string, width int, align tw.Align, padding
154154

155155
// formatSeparator generates a Markdown separator (e.g., `---`, `:--`, `:-:`) with alignment indicators.
156156
func (m *Markdown) formatSeparator(width int, align tw.Align) string {
157-
targetWidth := tw.Max(3, width)
158-
leftColon := align == tw.AlignLeft || align == tw.AlignCenter
159-
rightColon := align == tw.AlignRight || align == tw.AlignCenter
160-
161-
numDashes := targetWidth
162-
if leftColon {
163-
numDashes--
164-
}
165-
if rightColon {
166-
numDashes--
167-
}
168-
if numDashes < 1 {
169-
numDashes = 1
170-
}
171-
157+
targetWidth := tw.Max(3, width) // Minimum width of 3
172158
var sb strings.Builder
173-
if leftColon {
159+
160+
switch align {
161+
case tw.AlignLeft:
174162
sb.WriteRune(':')
175-
}
176-
sb.WriteString(strings.Repeat("-", numDashes))
177-
if rightColon {
163+
sb.WriteString(strings.Repeat("-", targetWidth-1))
164+
case tw.AlignRight:
165+
sb.WriteString(strings.Repeat("-", targetWidth-1))
178166
sb.WriteRune(':')
167+
case tw.AlignCenter:
168+
sb.WriteRune(':')
169+
sb.WriteString(strings.Repeat("-", targetWidth-2))
170+
sb.WriteRune(':')
171+
default: // Fallback to left alignment for unspecified
172+
sb.WriteRune(':')
173+
sb.WriteString(strings.Repeat("-", targetWidth-1))
179174
}
180175

181-
currentLen := sb.Len()
176+
result := sb.String()
177+
currentLen := tw.DisplayWidth(result)
182178
if currentLen < targetWidth {
183-
sb.WriteString(strings.Repeat("-", targetWidth-currentLen))
179+
result += strings.Repeat("-", targetWidth-currentLen)
184180
} else if currentLen > targetWidth {
185-
m.logger.Debug("Markdown formatSeparator: WARNING final length %d > target %d for '%s'", currentLen, targetWidth, sb.String())
181+
result = tw.TruncateString(result, targetWidth)
186182
}
187183

188-
result := sb.String()
189184
m.logger.Debug("Markdown formatSeparator: width=%d, align=%s -> '%s'", width, align, result)
190185
return result
191186
}
@@ -234,13 +229,12 @@ func (m *Markdown) renderMarkdownLine(w io.Writer, line []string, ctx tw.Formatt
234229
separatorWidth := tw.DisplayWidth(separator)
235230

236231
for colIndex < numCols {
237-
// Fetch cell context
238232
cellCtx, ok := ctx.Row.Current[colIndex]
239233
defaultPadding := tw.Padding{Left: " ", Right: " "}
240234
if !ok {
241-
defaultAlign := tw.AlignLeft
235+
defaultAlign := tw.AlignLeft // Default for rows
242236
if ctx.Row.Position == tw.Header && !isHeaderSep {
243-
defaultAlign = tw.AlignCenter
237+
defaultAlign = tw.AlignCenter // Default for headers
244238
}
245239
if ctx.Row.Position == tw.Footer {
246240
defaultAlign = tw.AlignRight
@@ -258,8 +252,6 @@ func (m *Markdown) renderMarkdownLine(w io.Writer, line []string, ctx tw.Formatt
258252
if colIndex > 0 && !isContinuation {
259253
output.WriteString(separator)
260254
m.logger.Debug("renderMarkdownLine: Added separator '%s' before col %d", separator, colIndex)
261-
} else if colIndex > 0 {
262-
m.logger.Debug("renderMarkdownLine: Skipped separator before col %d due to HMerge continuation", colIndex)
263255
}
264256

265257
// Calculate width and span
@@ -273,7 +265,7 @@ func (m *Markdown) renderMarkdownLine(w io.Writer, line []string, ctx tw.Formatt
273265
} else {
274266
align = tw.AlignLeft
275267
}
276-
m.logger.Debug("renderMarkdownLine: Col %d using renderer default align '%s'", colIndex, align)
268+
m.logger.Debug("renderMarkdownLine: Col %d using default align '%s'", colIndex, align)
277269
}
278270

279271
visualWidth := 0
@@ -292,7 +284,7 @@ func (m *Markdown) renderMarkdownLine(w io.Writer, line []string, ctx tw.Formatt
292284
}
293285
}
294286
visualWidth = totalWidth
295-
m.logger.Debug("renderMarkdownLine: HMerge col %d, span %d, calculated visualWidth %d from normalized widths", colIndex, span, visualWidth)
287+
m.logger.Debug("renderMarkdownLine: HMerge col %d, span %d, visualWidth %d", colIndex, span, visualWidth)
296288
} else {
297289
visualWidth = ctx.Row.Widths.Get(colIndex)
298290
m.logger.Debug("renderMarkdownLine: Regular col %d, visualWidth %d", colIndex, visualWidth)
@@ -303,16 +295,22 @@ func (m *Markdown) renderMarkdownLine(w io.Writer, line []string, ctx tw.Formatt
303295

304296
// Render segment
305297
if isContinuation {
306-
m.logger.Debug("renderMarkdownLine: Skipping col %d rendering (part of HMerge)", colIndex)
298+
m.logger.Debug("renderMarkdownLine: Skipping col %d (HMerge continuation)", colIndex)
307299
} else {
308300
var formattedSegment string
309301
if isHeaderSep {
310-
headerAlign := tw.AlignCenter
302+
// Use the header's alignment from ctx.Row.Previous (header row)
303+
headerAlign := tw.AlignCenter // Default for headers
311304
if headerCellCtx, headerOK := ctx.Row.Previous[colIndex]; headerOK {
312305
headerAlign = headerCellCtx.Align
313306
if headerAlign == tw.AlignNone || headerAlign == "" {
314307
headerAlign = tw.AlignCenter
315308
}
309+
} else if cellCtx, ok := ctx.Row.Current[colIndex]; ok {
310+
headerAlign = cellCtx.Align
311+
if headerAlign == tw.AlignNone || headerAlign == "" {
312+
headerAlign = tw.AlignCenter
313+
}
316314
}
317315
formattedSegment = m.formatSeparator(visualWidth, headerAlign)
318316
} else {
@@ -323,7 +321,7 @@ func (m *Markdown) renderMarkdownLine(w io.Writer, line []string, ctx tw.Formatt
323321
formattedSegment = m.formatCell(content, visualWidth, align, cellCtx.Padding)
324322
}
325323
output.WriteString(formattedSegment)
326-
m.logger.Debug("renderMarkdownLine: Wrote segment for col %d (span %d, visualWidth %d): '%s'", colIndex, span, visualWidth, formattedSegment)
324+
m.logger.Debug("renderMarkdownLine: Wrote col %d (span %d, width %d): '%s'", colIndex, span, visualWidth, formattedSegment)
327325
}
328326

329327
colIndex += span
@@ -332,7 +330,7 @@ func (m *Markdown) renderMarkdownLine(w io.Writer, line []string, ctx tw.Formatt
332330
output.WriteString(suffix)
333331
output.WriteString(tw.NewLine)
334332
fmt.Fprint(w, output.String())
335-
m.logger.Debug("renderMarkdownLine: Final rendered line: %s", strings.TrimSuffix(output.String(), tw.NewLine))
333+
m.logger.Debug("renderMarkdownLine: Final line: %s", strings.TrimSuffix(output.String(), tw.NewLine))
336334
}
337335

338336
// Header renders the Markdown table header and its separator line.

tests/basic_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,10 @@ func TestLongHeaders(t *testing.T) {
357357
Header: tw.CellConfig{Formatting: tw.CellFormatting{
358358
AutoWrap: tw.WrapTruncate,
359359
}},
360-
Debug: true,
360+
Debug: false,
361361
}
362362
buf.Reset()
363-
table := tablewriter.NewTable(&buf, tablewriter.WithConfig(c), tablewriter.WithDebug(true))
363+
table := tablewriter.NewTable(&buf, tablewriter.WithConfig(c), tablewriter.WithDebug(false))
364364
table.Header([]string{"Name", "Age", "This is a very long header, let see if this will be properly wrapped"})
365365
table.Append([]string{"Alice", "25", "New York"})
366366
table.Append([]string{"Bob", "30", "Boston"})
@@ -661,7 +661,7 @@ C │ D
661661
st := tablewriter.NewTable(&buf,
662662
tablewriter.WithConfig(tablewriter.Config{Row: tw.CellConfig{Formatting: tw.CellFormatting{Alignment: tw.AlignLeft}}}),
663663
tablewriter.WithRenderer(r),
664-
tablewriter.WithDebug(true),
664+
tablewriter.WithDebug(false),
665665
tablewriter.WithStreaming(tw.StreamConfig{Enable: true, Widths: tw.CellWidth{PerColumn: widths}}),
666666
)
667667
err := st.Start()

tests/extra_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func TestAutoHideFeature(t *testing.T) {
222222
var buf bytes.Buffer
223223
table := tablewriter.NewTable(&buf,
224224
tablewriter.WithAutoHide(tw.On), // Enable the feature
225-
tablewriter.WithDebug(true),
225+
tablewriter.WithDebug(false),
226226
)
227227
table.Header([]string{"Name", "Sign", "Rating"}) // Header IS included
228228

@@ -416,7 +416,7 @@ func TestSpaces(t *testing.T) {
416416
}
417417
t.Run("Trim", func(t *testing.T) {
418418
buf.Reset()
419-
table := tablewriter.NewTable(&buf, tablewriter.WithDebug(true), tablewriter.WithTrimSpace(tw.On))
419+
table := tablewriter.NewTable(&buf, tablewriter.WithDebug(false), tablewriter.WithTrimSpace(tw.On))
420420
table.Header(data[0])
421421
table.Bulk(data[1:])
422422
table.Render()

tests/ocean_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func TestOceanTableDefault(t *testing.T) { // You already have this, keep it
1212
var buf bytes.Buffer
1313

1414
// Using Ocean renderer in BATCH mode here via table.Render()
15-
table := tablewriter.NewTable(&buf, tablewriter.WithRenderer(renderer.NewOcean()), tablewriter.WithDebug(true))
15+
table := tablewriter.NewTable(&buf, tablewriter.WithRenderer(renderer.NewOcean()), tablewriter.WithDebug(false))
1616
table.Header([]string{"Name", "Age", "City"})
1717
table.Append([]string{"Alice", "25", "New York"})
1818
table.Append([]string{"Bob", "30", "Boston"})
@@ -47,7 +47,7 @@ func TestOceanTableStreaming_Simple(t *testing.T) {
4747

4848
tbl := tablewriter.NewTable(&buf,
4949
tablewriter.WithRenderer(renderer.NewOcean()),
50-
tablewriter.WithDebug(true),
50+
tablewriter.WithDebug(false),
5151
tablewriter.WithStreaming(tw.StreamConfig{Enable: true, Widths: tw.CellWidth{PerColumn: widths}}),
5252
)
5353

@@ -92,7 +92,7 @@ func TestOceanTableStreaming_NoHeader(t *testing.T) {
9292

9393
tbl := tablewriter.NewTable(&buf,
9494
tablewriter.WithRenderer(renderer.NewOcean()),
95-
tablewriter.WithDebug(true),
95+
tablewriter.WithDebug(false),
9696
tablewriter.WithStreaming(tw.StreamConfig{Enable: true, Widths: tw.CellWidth{PerColumn: widths}}),
9797
)
9898

@@ -176,7 +176,7 @@ func TestOceanTableStreaming_WithFooter(t *testing.T) {
176176

177177
tbl := tablewriter.NewTable(&buf,
178178
tablewriter.WithRenderer(renderer.NewOcean()), // Uses default Ocean config initially
179-
tablewriter.WithDebug(true),
179+
tablewriter.WithDebug(false),
180180
tablewriter.WithStreaming(tw.StreamConfig{Enable: true, Widths: tw.CellWidth{PerColumn: widths}}),
181181
)
182182

@@ -225,7 +225,7 @@ func TestOceanTableStreaming_VaryingWidthsFromConfig(t *testing.T) {
225225

226226
tbl := tablewriter.NewTable(&buf,
227227
tablewriter.WithRenderer(renderer.NewOcean()),
228-
tablewriter.WithDebug(true),
228+
tablewriter.WithDebug(false),
229229
tablewriter.WithStreaming(tw.StreamConfig{Enable: true, Widths: tw.CellWidth{PerColumn: widths}}),
230230
)
231231

@@ -276,7 +276,7 @@ func TestOceanTableStreaming_MultiLineCells(t *testing.T) {
276276

277277
tbl := tablewriter.NewTable(&buf,
278278
tablewriter.WithRenderer(renderer.NewOcean()),
279-
tablewriter.WithDebug(true),
279+
tablewriter.WithDebug(false),
280280
tablewriter.WithStreaming(tw.StreamConfig{Enable: true, Widths: tw.CellWidth{PerColumn: widths}}),
281281
)
282282

@@ -318,7 +318,7 @@ func TestOceanTableStreaming_OnlyHeader(t *testing.T) {
318318

319319
tbl := tablewriter.NewTable(&buf,
320320
tablewriter.WithRenderer(renderer.NewOcean()),
321-
tablewriter.WithDebug(true),
321+
tablewriter.WithDebug(false),
322322
tablewriter.WithStreaming(tw.StreamConfig{Enable: true, Widths: tw.CellWidth{PerColumn: widths}}),
323323
)
324324

@@ -360,7 +360,7 @@ func TestOceanTableStreaming_HorizontalMerge(t *testing.T) {
360360

361361
tbl := tablewriter.NewTable(&buf,
362362
tablewriter.WithRenderer(renderer.NewOcean()),
363-
tablewriter.WithDebug(true),
363+
tablewriter.WithDebug(false),
364364
tablewriter.WithStreaming(tw.StreamConfig{Enable: true, Widths: tw.CellWidth{PerColumn: widths}}),
365365
)
366366

tests/streamer_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func TestStreamNoHeaderASCII(t *testing.T) {
237237
st := tablewriter.NewTable(&buf,
238238
tablewriter.WithConfig(tablewriter.Config{Row: tw.CellConfig{Formatting: tw.CellFormatting{Alignment: tw.AlignLeft}}}),
239239
tablewriter.WithRenderer(renderer.NewBlueprint(tw.Rendition{Symbols: tw.NewSymbols(tw.StyleASCII)})),
240-
tablewriter.WithDebug(true),
240+
tablewriter.WithDebug(false),
241241
tablewriter.WithStreaming(tw.StreamConfig{Enable: true}),
242242
)
243243
err := st.Start()
@@ -331,7 +331,7 @@ C │ D
331331
st := tablewriter.NewTable(&buf,
332332
tablewriter.WithConfig(tablewriter.Config{Row: tw.CellConfig{Formatting: tw.CellFormatting{Alignment: tw.AlignLeft}}}),
333333
tablewriter.WithRenderer(r),
334-
tablewriter.WithDebug(true),
334+
tablewriter.WithDebug(false),
335335
)
336336

337337
st.Append(data[0])
@@ -415,7 +415,7 @@ func TestStreamCustomPadding(t *testing.T) {
415415
},
416416
},
417417
}),
418-
tablewriter.WithDebug(true))
418+
tablewriter.WithDebug(false))
419419

420420
err := st.Start()
421421
if err != nil {
@@ -454,7 +454,7 @@ func TestStreamEmptyCells(t *testing.T) {
454454
Global: 20,
455455
}},
456456
}),
457-
tablewriter.WithDebug(true))
457+
tablewriter.WithDebug(false))
458458

459459
err := st.Start()
460460
if err != nil {
@@ -492,7 +492,7 @@ func TestStreamOnlyHeader(t *testing.T) {
492492
st := createStreamTable(t, &buf, tablewriter.WithConfig(tablewriter.Config{
493493
Header: tw.CellConfig{Formatting: tw.CellFormatting{Alignment: tw.AlignCenter}},
494494
}),
495-
tablewriter.WithDebug(true),
495+
tablewriter.WithDebug(false),
496496
tablewriter.WithStreaming(tw.StreamConfig{Enable: true}))
497497

498498
err := st.Start()
@@ -593,8 +593,8 @@ func TestStreamSlowOutput(t *testing.T) {
593593

594594
t.Log("Slow stream test completed. Observe terminal output.")
595595
if st.Logger().Len() > 0 {
596-
fmt.Println("--- DEBUG LOG ---")
597-
fmt.Println(st.Debug().String())
596+
//fmt.Println("--- DEBUG LOG ---")
597+
//fmt.Println(st.Debug().String())
598598
}
599599
}
600600

@@ -643,7 +643,7 @@ func TestStreamFormating(t *testing.T) {
643643
Header: tw.CellConfig{Formatting: tw.CellFormatting{Alignment: tw.AlignCenter}},
644644
Row: tw.CellConfig{Formatting: tw.CellFormatting{Alignment: tw.AlignLeft}},
645645
Footer: tw.CellConfig{Formatting: tw.CellFormatting{Alignment: tw.AlignLeft}}}),
646-
tablewriter.WithDebug(true),
646+
tablewriter.WithDebug(false),
647647
tablewriter.WithStreaming(tw.StreamConfig{
648648
Enable: true,
649649
Widths: tw.CellWidth{PerColumn: map[int]int{0: 12, 1: 8, 2: 10}},

0 commit comments

Comments
 (0)