Skip to content

Commit 4637216

Browse files
committed
Update #261
1 parent 64ce70b commit 4637216

12 files changed

+382
-306
lines changed

cmd/csv2table/csv2table.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func process(r io.Reader) error {
158158
case "none":
159159
selectedSymbols = tw.NewSymbols(tw.StyleNone)
160160
default:
161-
logger.Warnf("Unknown symbol style '%s', using default (Light).", *symbolStyle)
161+
logger.Warnf("Default symbol style '%s', using default (Light).", *symbolStyle)
162162
selectedSymbols = tw.NewSymbols(tw.StyleLight)
163163
}
164164

@@ -226,7 +226,7 @@ func process(r io.Reader) error {
226226
fallthrough
227227
default:
228228
if *rendererType != "" && strings.ToLower(*rendererType) != "blueprint" {
229-
logger.Warnf("Unknown renderer type '%s', using Blueprint.", *rendererType)
229+
logger.Warnf("Default renderer type '%s', using Blueprint.", *rendererType)
230230
}
231231
selectedRenderer = renderer.NewBlueprint(baseRendition)
232232
}
@@ -414,7 +414,7 @@ func process(r io.Reader) error {
414414
}
415415

416416
func getHeaderConfig(alignFlag string, wrapFlag string) tw.CellConfig {
417-
cfgFmt := tw.CellFormatting{Alignment: tw.AlignCenter, AutoFormat: true}
417+
cfgFmt := tw.CellFormatting{Alignment: tw.AlignCenter, AutoFormat: tw.On}
418418
switch strings.ToLower(alignFlag) {
419419
case "left":
420420
cfgFmt.Alignment = tw.AlignLeft

config.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (b *ConfigBuilder) WithFooterAlignment(align tw.Align) *ConfigBuilder {
132132
}
133133

134134
// WithFooterAutoFormat enables or disables automatic formatting (e.g., title case) for footer cells.
135-
func (b *ConfigBuilder) WithFooterAutoFormat(autoFormat bool) *ConfigBuilder {
135+
func (b *ConfigBuilder) WithFooterAutoFormat(autoFormat tw.State) *ConfigBuilder {
136136
b.config.Footer.Formatting.AutoFormat = autoFormat
137137
return b
138138
}
@@ -184,7 +184,7 @@ func (b *ConfigBuilder) WithHeaderAlignment(align tw.Align) *ConfigBuilder {
184184
}
185185

186186
// WithHeaderAutoFormat enables or disables automatic formatting (e.g., title case) for header cells.
187-
func (b *ConfigBuilder) WithHeaderAutoFormat(autoFormat bool) *ConfigBuilder {
187+
func (b *ConfigBuilder) WithHeaderAutoFormat(autoFormat tw.State) *ConfigBuilder {
188188
b.config.Header.Formatting.AutoFormat = autoFormat
189189
return b
190190
}
@@ -247,7 +247,7 @@ func (b *ConfigBuilder) WithRowAlignment(align tw.Align) *ConfigBuilder {
247247
}
248248

249249
// WithRowAutoFormat enables or disables automatic formatting for row cells.
250-
func (b *ConfigBuilder) WithRowAutoFormat(autoFormat bool) *ConfigBuilder {
250+
func (b *ConfigBuilder) WithRowAutoFormat(autoFormat tw.State) *ConfigBuilder {
251251
b.config.Row.Formatting.AutoFormat = autoFormat
252252
return b
253253
}
@@ -348,7 +348,7 @@ func (ff *FooterFormattingBuilder) WithAlignment(align tw.Align) *FooterFormatti
348348
}
349349

350350
// WithAutoFormat enables or disables automatic formatting for footer cells.
351-
func (ff *FooterFormattingBuilder) WithAutoFormat(autoFormat bool) *FooterFormattingBuilder {
351+
func (ff *FooterFormattingBuilder) WithAutoFormat(autoFormat tw.State) *FooterFormattingBuilder {
352352
ff.config.AutoFormat = autoFormat
353353
return ff
354354
}
@@ -466,7 +466,7 @@ func (hf *HeaderFormattingBuilder) WithAlignment(align tw.Align) *HeaderFormatti
466466
}
467467

468468
// WithAutoFormat enables or disables automatic formatting for header cells.
469-
func (hf *HeaderFormattingBuilder) WithAutoFormat(autoFormat bool) *HeaderFormattingBuilder {
469+
func (hf *HeaderFormattingBuilder) WithAutoFormat(autoFormat tw.State) *HeaderFormattingBuilder {
470470
hf.config.AutoFormat = autoFormat
471471
return hf
472472
}
@@ -587,7 +587,7 @@ func (rf *RowFormattingBuilder) WithAlignment(align tw.Align) *RowFormattingBuil
587587
}
588588

589589
// WithAutoFormat enables or disables automatic formatting for row cells.
590-
func (rf *RowFormattingBuilder) WithAutoFormat(autoFormat bool) *RowFormattingBuilder {
590+
func (rf *RowFormattingBuilder) WithAutoFormat(autoFormat tw.State) *RowFormattingBuilder {
591591
rf.config.AutoFormat = autoFormat
592592
return rf
593593
}
@@ -981,7 +981,7 @@ func defaultConfig() Config {
981981
Formatting: tw.CellFormatting{
982982
AutoWrap: tw.WrapTruncate,
983983
Alignment: tw.AlignCenter,
984-
AutoFormat: true,
984+
AutoFormat: tw.On,
985985
MergeMode: tw.MergeNone,
986986
},
987987
Padding: tw.CellPadding{
@@ -992,7 +992,7 @@ func defaultConfig() Config {
992992
Formatting: tw.CellFormatting{
993993
AutoWrap: tw.WrapNormal,
994994
Alignment: tw.AlignLeft,
995-
AutoFormat: false,
995+
AutoFormat: tw.Off,
996996
MergeMode: tw.MergeNone,
997997
},
998998
Padding: tw.CellPadding{
@@ -1003,7 +1003,7 @@ func defaultConfig() Config {
10031003
Formatting: tw.CellFormatting{
10041004
AutoWrap: tw.WrapNormal,
10051005
Alignment: tw.AlignRight,
1006-
AutoFormat: false,
1006+
AutoFormat: tw.Off,
10071007
MergeMode: tw.MergeNone,
10081008
},
10091009
Padding: tw.CellPadding{
@@ -1034,6 +1034,7 @@ func mergeCellConfig(dst, src tw.CellConfig) tw.CellConfig {
10341034
if src.Formatting.MergeMode != 0 {
10351035
dst.Formatting.MergeMode = src.Formatting.MergeMode
10361036
}
1037+
10371038
dst.Formatting.AutoFormat = src.Formatting.AutoFormat
10381039

10391040
if src.Padding.Global != (tw.Padding{}) {
@@ -1119,6 +1120,7 @@ func mergeConfig(dst, src Config) Config {
11191120
dst.Row = mergeCellConfig(dst.Row, src.Row)
11201121
dst.Footer = mergeCellConfig(dst.Footer, src.Footer)
11211122
dst.Stream = mergeStreamConfig(dst.Stream, src.Stream)
1123+
11221124
return dst
11231125
}
11241126

tablewriter.go

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,11 @@ func (t *Table) Header(elements ...any) {
273273
return
274274
}
275275

276+
// add come common default
277+
if t.config.Header.Formatting.AutoFormat == tw.Unknown {
278+
t.config.Header.Formatting.AutoFormat = tw.On
279+
}
280+
276281
if t.config.Stream.Enable && t.hasPrinted {
277282
// Streaming Path
278283
actualCellsToProcess := t.processVariadic(elements)
@@ -462,6 +467,19 @@ func (t *Table) Render() error {
462467
return t.render()
463468
}
464469

470+
// Trimmer trims whitespace from a string based on the Table’s configuration.
471+
// It conditionally applies strings.TrimSpace to the input string if the TrimSpace behavior
472+
// is enabled in t.config.Behavior, otherwise returning the string unchanged. This method
473+
// is used in the logging library to format strings for tabular output, ensuring consistent
474+
// display in log messages. Thread-safe as it only reads configuration and operates on the
475+
// input string.
476+
func (t *Table) Trimmer(str string) string {
477+
if t.config.Behavior.TrimSpace.Enabled() {
478+
return strings.TrimSpace(str)
479+
}
480+
return str
481+
}
482+
465483
// appendSingle adds a single row to the table's row data.
466484
// Parameter row is the data to append, converted via stringer if needed.
467485
// Returns an error if conversion or appending fails.
@@ -832,7 +850,7 @@ func (t *Table) prepareContent(cells []string, config tw.CellConfig) [][]string
832850

833851
effectiveContentMaxWidth := t.calculateContentMaxWidth(i, config, padLeftWidth, padRightWidth, isStreaming)
834852

835-
if config.Formatting.AutoFormat {
853+
if config.Formatting.AutoFormat.Enabled() {
836854
cellContent = tw.Title(strings.Join(tw.SplitCamelCase(cellContent), tw.Space))
837855
}
838856

@@ -2120,16 +2138,3 @@ func (t *Table) renderRow(ctx *renderContext, mctx *mergeContext) error {
21202138
}
21212139
return nil
21222140
}
2123-
2124-
// Trimmer trims whitespace from a string based on the Table’s configuration.
2125-
// It conditionally applies strings.TrimSpace to the input string if the TrimSpace behavior
2126-
// is enabled in t.config.Behavior, otherwise returning the string unchanged. This method
2127-
// is used in the logging library to format strings for tabular output, ensuring consistent
2128-
// display in log messages. Thread-safe as it only reads configuration and operates on the
2129-
// input string.
2130-
func (t *Table) Trimmer(str string) string {
2131-
if t.config.Behavior.TrimSpace.Enabled() {
2132-
return strings.TrimSpace(str)
2133-
}
2134-
return str
2135-
}

0 commit comments

Comments
 (0)