Skip to content

Commit ca4e3ac

Browse files
committed
clearer environment debugging information
1 parent b31b038 commit ca4e3ac

2 files changed

Lines changed: 29 additions & 14 deletions

File tree

tablewriter.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"io"
66
"math"
7-
"os"
87
"reflect"
98
"runtime"
109
"strings"
@@ -419,7 +418,6 @@ func (t *Table) Options(opts ...Option) *Table {
419418
}
420419

421420
// force debugging mode if set
422-
// This should be move away form WithDebug
423421
if t.config.Debug {
424422
t.logger.Enable()
425423
t.logger.Resume()
@@ -434,11 +432,28 @@ func (t *Table) Options(opts ...Option) *Table {
434432
goArch := runtime.GOARCH
435433
numCPU := runtime.NumCPU()
436434

437-
t.logger.Infof("Environment: LC_CTYPE=%s, LANG=%s, TERM=%s", os.Getenv("LC_CTYPE"), os.Getenv("LANG"), os.Getenv("TERM"))
438-
t.logger.Infof("Go Runtime: Version=%s, OS=%s, Arch=%s, CPUs=%d", goVersion, goOS, goArch, numCPU)
435+
// Use the new struct-based info.
436+
// No type assertions or magic strings needed.
437+
info := twwidth.Debugging()
438+
439+
t.logger.Infof("Go Runtime: Version=%s, OS=%s, Arch=%s, CPUs=%d",
440+
goVersion, goOS, goArch, numCPU)
441+
442+
t.logger.Infof("Environment: LC_CTYPE=%s, LANG=%s, TERM=%s, TERM_PROGRAM=%s",
443+
info.Raw.LC_CTYPE,
444+
info.Raw.LANG,
445+
info.Raw.TERM,
446+
info.Raw.TERM_PROGRAM,
447+
)
448+
449+
t.logger.Infof("East Asian Detection: Auto=%v, Mode=%s, ModernEnv=%v, CJKLocale=%v",
450+
info.AutoUseEastAsian,
451+
info.DetectionMode,
452+
info.Derived.IsModernEnv,
453+
info.Derived.IsCJKLocale,
454+
)
439455

440456
// send logger to renderer
441-
// this will overwrite the default logger
442457
t.renderer.Logger(t.logger)
443458
return t
444459
}

zoo.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ func (t *Table) calculateContentMaxWidth(colIdx int, config tw.CellConfig, padLe
991991
constraintTotalCellWidth := 0
992992
hasConstraint := false
993993

994-
// 1. Check new Widths.PerColumn (highest priority)
994+
// Check new Widths.PerColumn (highest priority)
995995
if t.config.Widths.Constrained() {
996996

997997
if colWidth, ok := t.config.Widths.PerColumn.OK(colIdx); ok && colWidth > 0 {
@@ -1001,15 +1001,15 @@ func (t *Table) calculateContentMaxWidth(colIdx int, config tw.CellConfig, padLe
10011001
colIdx, constraintTotalCellWidth)
10021002
}
10031003

1004-
// 2. Check new Widths.Global
1004+
// Check new Widths.Global
10051005
if !hasConstraint && t.config.Widths.Global > 0 {
10061006
constraintTotalCellWidth = t.config.Widths.Global
10071007
hasConstraint = true
10081008
t.logger.Debugf("calculateContentMaxWidth: Using Widths.Global = %d", constraintTotalCellWidth)
10091009
}
10101010
}
10111011

1012-
// 3. Fall back to legacy ColMaxWidths.PerColumn (backward compatibility)
1012+
// Fall back to legacy ColMaxWidths.PerColumn (backward compatibility)
10131013
if !hasConstraint && config.ColMaxWidths.PerColumn != nil {
10141014
if colMax, ok := config.ColMaxWidths.PerColumn.OK(colIdx); ok && colMax > 0 {
10151015
constraintTotalCellWidth = colMax
@@ -1019,15 +1019,15 @@ func (t *Table) calculateContentMaxWidth(colIdx int, config tw.CellConfig, padLe
10191019
}
10201020
}
10211021

1022-
// 4. Fall back to legacy ColMaxWidths.Global
1022+
// Fall back to legacy ColMaxWidths.Global
10231023
if !hasConstraint && config.ColMaxWidths.Global > 0 {
10241024
constraintTotalCellWidth = config.ColMaxWidths.Global
10251025
hasConstraint = true
10261026
t.logger.Debugf("calculateContentMaxWidth: Using legacy ColMaxWidths.Global = %d",
10271027
constraintTotalCellWidth)
10281028
}
10291029

1030-
// 5. Fall back to table MaxWidth if auto-wrapping
1030+
// Fall back to table MaxWidth if auto-wrapping
10311031
if !hasConstraint && t.config.MaxWidth > 0 && config.Formatting.AutoWrap != tw.WrapNone {
10321032
constraintTotalCellWidth = t.config.MaxWidth
10331033
hasConstraint = true
@@ -1224,7 +1224,7 @@ func (t *Table) convertToString(value interface{}) string {
12241224
func (t *Table) convertItemToCells(item interface{}) ([]string, error) {
12251225
t.logger.Debugf("convertItemToCells: Converting item of type %T", item)
12261226

1227-
// 1. User-defined table-wide stringer (t.stringer) takes highest precedence.
1227+
// User-defined table-wide stringer (t.stringer) takes highest precedence.
12281228
if t.stringer != nil {
12291229
res, err := t.convertToStringer(item)
12301230
if err == nil {
@@ -1234,21 +1234,21 @@ func (t *Table) convertItemToCells(item interface{}) ([]string, error) {
12341234
t.logger.Warnf("convertItemToCells: Custom table stringer was set but incompatible for type %T: %v. Will attempt other methods.", item, err)
12351235
}
12361236

1237-
// 2. Handle untyped nil directly.
1237+
// Handle untyped nil directly.
12381238
if item == nil {
12391239
t.logger.Debugf("convertItemToCells: Item is untyped nil. Returning single empty cell.")
12401240
return []string{""}, nil
12411241
}
12421242

1243-
// 3. Use the new unified struct parser. It handles pointers and embedding.
1243+
// Use the new unified struct parser. It handles pointers and embedding.
12441244
// We only care about the values it returns.
12451245
_, values := t.extractFieldsAndValuesFromStruct(item)
12461246
if values != nil {
12471247
t.logger.Debugf("convertItemToCells: Structs %T reflected into %d cells: %v", item, len(values), values)
12481248
return values, nil
12491249
}
12501250

1251-
// 4. Fallback for any other single item (e.g., basic types, or types that implement Stringer/Formatter).
1251+
// Fallback for any other single item (e.g., basic types, or types that implement Stringer/Formatter).
12521252
// This code path is now for non-struct types.
12531253
if formatter, ok := item.(tw.Formatter); ok {
12541254
t.logger.Debugf("convertItemToCells: Item (non-struct, type %T) is tw.Formatter. Using Format().", item)

0 commit comments

Comments
 (0)