Skip to content

Commit 4876204

Browse files
committed
added caption support #97, clarify max width #247
1 parent 9374103 commit 4876204

19 files changed

+716
-167
lines changed

README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ go get github.com/olekukonko/[email protected]
2828
#### Latest Version
2929
The latest stable version
3030
```bash
31-
go get github.com/olekukonko/[email protected].3
31+
go get github.com/olekukonko/[email protected].4
3232
```
3333

3434
**Warning:** Version `v1.0.0` contains missing functionality and should not be used.
@@ -77,7 +77,7 @@ func main() {
7777
│ PACKAGE │ VERSION │ STATUS │
7878
├─────────────┼─────────┼────────┤
7979
│ tablewriter │ v0.0.5 │ legacy │
80-
│ tablewriter │ v1.0.3 │ latest │
80+
│ tablewriter │ v1.0.4 │ latest │
8181
└─────────────┴─────────┴────────┘
8282
```
8383

@@ -369,10 +369,10 @@ func main() {
369369
tablewriter.WithConfig(tablewriter.Config{
370370
Row: tw.CellConfig{
371371
Formatting: tw.CellFormatting{
372-
MaxWidth: 25, // Limit column width
373372
AutoWrap: tw.WrapNormal, // Wrap long content
374373
Alignment: tw.AlignLeft, // Left-align rows
375374
},
375+
ColMaxWidths: tw.CellWidth{Global: 25},
376376
},
377377
Footer: tw.CellConfig{
378378
Formatting: tw.CellFormatting{Alignment: tw.AlignRight},
@@ -655,13 +655,9 @@ func main() {
655655
A | A │ B | B
656656
---+--- │ ---+---
657657
A | A │ B | B
658-
---+--- │ ---+---
659-
660-
C | C │ D | D
661-
---+--- │ ---+---
662658
C | C │ D | D
663659
---+--- │ ---+---
664-
660+
C | C D | D
665661
```
666662

667663
#### 9. Structs with Database

config.go

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func (b *ConfigBuilder) WithFooterMaxWidth(maxWidth int) *ConfigBuilder {
165165
if maxWidth < 0 {
166166
return b
167167
}
168-
b.config.Footer.Formatting.MaxWidth = maxWidth
168+
b.config.Footer.ColMaxWidths.Global = maxWidth
169169
return b
170170
}
171171

@@ -217,7 +217,7 @@ func (b *ConfigBuilder) WithHeaderMaxWidth(maxWidth int) *ConfigBuilder {
217217
if maxWidth < 0 {
218218
return b
219219
}
220-
b.config.Header.Formatting.MaxWidth = maxWidth
220+
b.config.Header.ColMaxWidths.Global = maxWidth
221221
return b
222222
}
223223

@@ -280,7 +280,7 @@ func (b *ConfigBuilder) WithRowMaxWidth(maxWidth int) *ConfigBuilder {
280280
if maxWidth < 0 {
281281
return b
282282
}
283-
b.config.Row.Formatting.MaxWidth = maxWidth
283+
b.config.Row.ColMaxWidths.Global = maxWidth
284284
return b
285285
}
286286

@@ -371,13 +371,13 @@ func (ff *FooterFormattingBuilder) WithAutoWrap(autoWrap int) *FooterFormattingB
371371

372372
// WithMaxWidth sets the maximum content width for footer cells.
373373
// Negative values are ignored.
374-
func (ff *FooterFormattingBuilder) WithMaxWidth(maxWidth int) *FooterFormattingBuilder {
375-
if maxWidth < 0 {
376-
return ff
377-
}
378-
ff.config.MaxWidth = maxWidth
379-
return ff
380-
}
374+
//func (ff *FooterFormattingBuilder) WithMaxWidth(maxWidth int) *FooterFormattingBuilder {
375+
// if maxWidth < 0 {
376+
// return ff
377+
// }
378+
// ff.config.Foo = maxWidth
379+
// return ff
380+
//}
381381

382382
// WithNewarkMode sets the merge behavior for footer cells (likely a typo, should be WithMergeMode).
383383
// Invalid merge modes are ignored.
@@ -489,13 +489,13 @@ func (hf *HeaderFormattingBuilder) WithAutoWrap(autoWrap int) *HeaderFormattingB
489489

490490
// WithMaxWidth sets the maximum content width for header cells.
491491
// Negative values are ignored.
492-
func (hf *HeaderFormattingBuilder) WithMaxWidth(maxWidth int) *HeaderFormattingBuilder {
493-
if maxWidth < 0 {
494-
return hf
495-
}
496-
hf.config.MaxWidth = maxWidth
497-
return hf
498-
}
492+
//func (hf *HeaderFormattingBuilder) WithMaxWidth(maxWidth int) *HeaderFormattingBuilder {
493+
// if maxWidth < 0 {
494+
// return hf
495+
// }
496+
// hf.config.MaxWidth = maxWidth
497+
// return hf
498+
//}
499499

500500
// WithMergeMode sets the merge behavior for header cells.
501501
// Invalid merge modes are ignored.
@@ -610,13 +610,13 @@ func (rf *RowFormattingBuilder) WithAutoWrap(autoWrap int) *RowFormattingBuilder
610610

611611
// WithMaxWidth sets the maximum content width for row cells.
612612
// Negative values are ignored.
613-
func (rf *RowFormattingBuilder) WithMaxWidth(maxWidth int) *RowFormattingBuilder {
614-
if maxWidth < 0 {
615-
return rf
616-
}
617-
rf.config.MaxWidth = maxWidth
618-
return rf
619-
}
613+
//func (rf *RowFormattingBuilder) WithMaxWidth(maxWidth int) *RowFormattingBuilder {
614+
// if maxWidth < 0 {
615+
// return rf
616+
// }
617+
// rf.config.MaxWidth = maxWidth
618+
// return rf
619+
//}
620620

621621
// WithMergeMode sets the merge behavior for row cells.
622622
// Invalid merge modes are ignored.
@@ -867,7 +867,7 @@ func WithRowMaxWidth(maxWidth int) Option {
867867
if maxWidth < 0 {
868868
return
869869
}
870-
target.config.Row.Formatting.MaxWidth = maxWidth
870+
target.config.Row.ColMaxWidths.Global = maxWidth
871871
if target.logger != nil {
872872
target.logger.Debug("Option: WithRowMaxWidth applied to Table: %v", maxWidth)
873873
}
@@ -945,7 +945,6 @@ func defaultConfig() Config {
945945
MaxWidth: 0,
946946
Header: tw.CellConfig{
947947
Formatting: tw.CellFormatting{
948-
MaxWidth: 0,
949948
AutoWrap: tw.WrapTruncate,
950949
Alignment: tw.AlignCenter,
951950
AutoFormat: true,
@@ -957,7 +956,6 @@ func defaultConfig() Config {
957956
},
958957
Row: tw.CellConfig{
959958
Formatting: tw.CellFormatting{
960-
MaxWidth: 0,
961959
AutoWrap: tw.WrapNormal,
962960
Alignment: tw.AlignLeft,
963961
AutoFormat: false,
@@ -969,7 +967,6 @@ func defaultConfig() Config {
969967
},
970968
Footer: tw.CellConfig{
971969
Formatting: tw.CellFormatting{
972-
MaxWidth: 0,
973970
AutoWrap: tw.WrapNormal,
974971
Alignment: tw.AlignRight,
975972
AutoFormat: false,
@@ -997,8 +994,8 @@ func mergeCellConfig(dst, src tw.CellConfig) tw.CellConfig {
997994
if src.Formatting.AutoWrap != 0 {
998995
dst.Formatting.AutoWrap = src.Formatting.AutoWrap
999996
}
1000-
if src.Formatting.MaxWidth != 0 {
1001-
dst.Formatting.MaxWidth = src.Formatting.MaxWidth
997+
if src.ColMaxWidths.Global != 0 {
998+
dst.ColMaxWidths.Global = src.ColMaxWidths.Global
1002999
}
10031000
if src.Formatting.MergeMode != 0 {
10041001
dst.Formatting.MergeMode = src.Formatting.MergeMode

renderer/markdown.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func (m *Markdown) resolveAlignment(ctx tw.Formatting) tw.Alignment {
149149
m.alignment[i] = ctx.Row.Current[i].Align
150150
}
151151

152-
m.logger.Debug(" → Alignment Resolved %s", m.alignment)
152+
m.logger.Debug(" → Align Resolved %s", m.alignment)
153153
return m.alignment
154154
}
155155

stream.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ func (t *Table) Close() error {
8080
func (t *Table) Start() error {
8181
t.ensureInitialized() // Ensures basic setup like loggers
8282

83-
// --- MODIFIED LOGIC START ---
8483
if !t.config.Stream.Enable {
8584
// Start() should only be called when streaming is explicitly enabled.
8685
// Otherwise, the user should call Render() for batch mode.
@@ -761,7 +760,7 @@ func (t *Table) streamRenderFooter(processedFooterLines [][]string) error {
761760
f := t.renderer
762761
cfg := t.renderer.Config()
763762

764-
// --- Render Row/Footer or Header/Footer Separator Line ---
763+
// Render Row/Footer or Header/Footer Separator Line
765764
// This separator is drawn if ShowFooterLine is enabled AND there was content before the footer.
766765
// The last rendered position (t.lastRenderedPosition) should be Row or Header or "separator".
767766
if (t.lastRenderedPosition == tw.Row || t.lastRenderedPosition == tw.Header || t.lastRenderedPosition == tw.Position("separator")) &&
@@ -819,7 +818,7 @@ func (t *Table) streamRenderFooter(processedFooterLines [][]string) error {
819818
t.lastRenderedMergeState = nil
820819
t.logger.Debug("streamRenderFooter: Footer separator line rendered.")
821820
}
822-
// --- End Render Separator Line ---
821+
// End Render Separator Line
823822

824823
// Detect horizontal merges for the footer section based on its (assumed stored) raw input.
825824
// This is tricky because streamStoreFooter gets []string, but prepareWithMerges expects [][]string.

0 commit comments

Comments
 (0)