Skip to content

Commit 3b62115

Browse files
committed
improve deprecate documentation
1 parent 9eed19c commit 3b62115

File tree

1 file changed

+172
-18
lines changed

1 file changed

+172
-18
lines changed

deprecated.go

Lines changed: 172 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,27 @@ package tablewriter
22

33
import "github.com/olekukonko/tablewriter/tw"
44

5-
// Deprecated: WithBorders is no longer used.
6-
// Border control has been moved to the renderer, which now manages its own borders.
7-
// This Option has no effect on the Table and may be removed in future versions.
5+
// WithBorders configures the table's border settings by updating the renderer's border configuration.
6+
// This function is deprecated and will be removed in a future version.
7+
//
8+
// Deprecated: Use [WithRendition] to configure border settings for renderers that support
9+
// [tw.Renditioning], or update the renderer's [tw.RenderConfig] directly via its Config() method.
10+
// This function has no effect if no renderer is set on the table.
11+
//
12+
// Example migration:
13+
//
14+
// // Old (deprecated)
15+
// table.Options(WithBorders(tw.Border{Top: true, Bottom: true}))
16+
// // New (recommended)
17+
// table.Options(WithRendition(tw.Rendition{Borders: tw.Border{Top: true, Bottom: true}}))
18+
//
19+
// Parameters:
20+
// - borders: The [tw.Border] configuration to apply to the renderer's borders.
21+
//
22+
// Returns:
23+
//
24+
// An [Option] that updates the renderer's border settings if a renderer is set.
25+
// Logs a debug message if debugging is enabled and a renderer is present.
826
func WithBorders(borders tw.Border) Option {
927
return func(target *Table) {
1028
if target.renderer != nil {
@@ -17,16 +35,55 @@ func WithBorders(borders tw.Border) Option {
1735
}
1836
}
1937

20-
// Deprecated: WithBorders is no longer supported.
21-
// Use [tw.Behavior] directly to configure border settings.
38+
// Behavior is an alias for [tw.Behavior] to configure table behavior settings.
39+
// This type is deprecated and will be removed in a future version.
40+
//
41+
// Deprecated: Use [tw.Behavior] directly to configure settings such as auto-hiding empty
42+
// columns, trimming spaces, or controlling header/footer visibility.
43+
//
44+
// Example migration:
45+
//
46+
// // Old (deprecated)
47+
// var b tablewriter.Behavior = tablewriter.Behavior{AutoHide: tw.On}
48+
// // New (recommended)
49+
// var b tw.Behavior = tw.Behavior{AutoHide: tw.On}
2250
type Behavior tw.Behavior
2351

24-
// Deprecated: WithRendererSettings i sno longer supported.
52+
// Settings is an alias for [tw.Settings] to configure renderer settings.
53+
// This type is deprecated and will be removed in a future version.
54+
//
55+
// Deprecated: Use [tw.Settings] directly to configure renderer settings, such as
56+
// separators and line styles.
57+
//
58+
// Example migration:
59+
//
60+
// // Old (deprecated)
61+
// var s tablewriter.Settings = tablewriter.Settings{Separator: "|"}
62+
// // New (recommended)
63+
// var s tw.Settings = tw.Settings{Separator: "|"}
2564
type Settings tw.Settings
2665

27-
// WithRendererSettings updates the renderer's settings (e.g., separators, lines).
28-
// Render setting has move to renders directly
29-
// you can also use WithRendition for renders that have rendition support
66+
// WithRendererSettings updates the renderer's settings, such as separators and line styles.
67+
// This function is deprecated and will be removed in a future version.
68+
//
69+
// Deprecated: Use [WithRendition] to update renderer settings for renderers that implement
70+
// [tw.Renditioning], or configure the renderer's [tw.Settings] directly via its
71+
// [tw.Renderer.Config] method. This function has no effect if no renderer is set.
72+
//
73+
// Example migration:
74+
//
75+
// // Old (deprecated)
76+
// table.Options(WithRendererSettings(tw.Settings{Separator: "|"}))
77+
// // New (recommended)
78+
// table.Options(WithRendition(tw.Rendition{Settings: tw.Settings{Separator: "|"}}))
79+
//
80+
// Parameters:
81+
// - settings: The [tw.Settings] configuration to apply to the renderer.
82+
//
83+
// Returns:
84+
//
85+
// An [Option] that updates the renderer's settings if a renderer is set.
86+
// Logs a debug message if debugging is enabled and a renderer is present.
3087
func WithRendererSettings(settings tw.Settings) Option {
3188
return func(target *Table) {
3289
if target.renderer != nil {
@@ -39,9 +96,31 @@ func WithRendererSettings(settings tw.Settings) Option {
3996
}
4097
}
4198

42-
// Deprecated: this will remove in the next version
43-
// WithAlignment sets the text alignment for footer cells.
44-
// Invalid alignments are ignored.
99+
// WithAlignment sets the text alignment for footer cells within the formatting configuration.
100+
// This method is deprecated and will be removed in the next version.
101+
//
102+
// Deprecated: Use [FooterConfigBuilder.Alignment] with [AlignmentConfigBuilder.WithGlobal]
103+
// or [AlignmentConfigBuilder.WithPerColumn] to configure footer alignments.
104+
// Alternatively, apply a complete [tw.CellAlignment] configuration using
105+
// [WithFooterAlignmentConfig].
106+
//
107+
// Example migration:
108+
//
109+
// // Old (deprecated)
110+
// builder.Footer().Formatting().WithAlignment(tw.AlignRight)
111+
// // New (recommended)
112+
// builder.Footer().Alignment().WithGlobal(tw.AlignRight)
113+
// // Or
114+
// table.Options(WithFooterAlignmentConfig(tw.CellAlignment{Global: tw.AlignRight}))
115+
//
116+
// Parameters:
117+
// - align: The [tw.Align] value to set for footer cells. Valid values are
118+
// [tw.AlignLeft], [tw.AlignRight], [tw.AlignCenter], and [tw.AlignNone].
119+
// Invalid alignments are ignored.
120+
//
121+
// Returns:
122+
//
123+
// The [FooterFormattingBuilder] instance for method chaining.
45124
func (ff *FooterFormattingBuilder) WithAlignment(align tw.Align) *FooterFormattingBuilder {
46125
if align != tw.AlignLeft && align != tw.AlignRight && align != tw.AlignCenter && align != tw.AlignNone {
47126
return ff
@@ -50,9 +129,31 @@ func (ff *FooterFormattingBuilder) WithAlignment(align tw.Align) *FooterFormatti
50129
return ff
51130
}
52131

53-
// Deprecated: this will remove in the next version
54-
// WithAlignment sets the text alignment for header cells.
55-
// Invalid alignments are ignored.
132+
// WithAlignment sets the text alignment for header cells within the formatting configuration.
133+
// This method is deprecated and will be removed in the next version.
134+
//
135+
// Deprecated: Use [HeaderConfigBuilder.Alignment] with [AlignmentConfigBuilder.WithGlobal]
136+
// or [AlignmentConfigBuilder.WithPerColumn] to configure header alignments.
137+
// Alternatively, apply a complete [tw.CellAlignment] configuration using
138+
// [WithHeaderAlignmentConfig].
139+
//
140+
// Example migration:
141+
//
142+
// // Old (deprecated)
143+
// builder.Header().Formatting().WithAlignment(tw.AlignCenter)
144+
// // New (recommended)
145+
// builder.Header().Alignment().WithGlobal(tw.AlignCenter)
146+
// // Or
147+
// table.Options(WithHeaderAlignmentConfig(tw.CellAlignment{Global: tw.AlignCenter}))
148+
//
149+
// Parameters:
150+
// - align: The [tw.Align] value to set for header cells. Valid values are
151+
// [tw.AlignLeft], [tw.AlignRight], [tw.AlignCenter], and [tw.AlignNone].
152+
// Invalid alignments are ignored.
153+
//
154+
// Returns:
155+
//
156+
// The [HeaderFormattingBuilder] instance for method chaining.
56157
func (hf *HeaderFormattingBuilder) WithAlignment(align tw.Align) *HeaderFormattingBuilder {
57158
if align != tw.AlignLeft && align != tw.AlignRight && align != tw.AlignCenter && align != tw.AlignNone {
58159
return hf
@@ -61,13 +162,66 @@ func (hf *HeaderFormattingBuilder) WithAlignment(align tw.Align) *HeaderFormatti
61162
return hf
62163
}
63164

64-
// Deprecated: this will remove in the next version
65-
// WithAlignment sets the text alignment for row cells.
66-
// Invalid alignments are ignored.
165+
// WithAlignment sets the text alignment for row cells within the formatting configuration.
166+
// This method is deprecated and will be removed in the next version.
167+
//
168+
// Deprecated: Use [RowConfigBuilder.Alignment] with [AlignmentConfigBuilder.WithGlobal]
169+
// or [AlignmentConfigBuilder.WithPerColumn] to configure row alignments.
170+
// Alternatively, apply a complete [tw.CellAlignment] configuration using
171+
// [WithRowAlignmentConfig].
172+
//
173+
// Example migration:
174+
//
175+
// // Old (deprecated)
176+
// builder.Row().Formatting().WithAlignment(tw.AlignLeft)
177+
// // New (recommended)
178+
// builder.Row().Alignment().WithGlobal(tw.AlignLeft)
179+
// // Or
180+
// table.Options(WithRowAlignmentConfig(tw.CellAlignment{Global: tw.AlignLeft}))
181+
//
182+
// Parameters:
183+
// - align: The [tw.Align] value to set for row cells. Valid values are
184+
// [tw.AlignLeft], [tw.AlignRight], [tw.AlignCenter], and [tw.AlignNone].
185+
// Invalid alignments are ignored.
186+
//
187+
// Returns:
188+
//
189+
// The [RowFormattingBuilder] instance for method chaining.
67190
func (rf *RowFormattingBuilder) WithAlignment(align tw.Align) *RowFormattingBuilder {
68191
if align != tw.AlignLeft && align != tw.AlignRight && align != tw.AlignCenter && align != tw.AlignNone {
69192
return rf
70193
}
71194
rf.config.Alignment = align
72195
return rf
73196
}
197+
198+
// Deprecated:Use WithMaxWidth instead.
199+
// WithTableMax sets a global maximum table width for the table.
200+
// Negative values are ignored, and the change is logged if debugging is enabled.
201+
func WithTableMax(width int) Option {
202+
return func(target *Table) {
203+
if width < 0 {
204+
return
205+
}
206+
target.config.MaxWidth = width
207+
if target.logger != nil {
208+
target.logger.Debugf("Option: WithTableMax applied to Table: %v", width)
209+
}
210+
}
211+
}
212+
213+
// Deprecated:Use Rederer setting directly
214+
// not al lrenderes have symboms or support Renditions
215+
// WithSymbols sets the symbols used for table drawing and updates the renderer's configuration.
216+
// Logs the change if debugging is enabled.
217+
func WithSymbols(symbols tw.Symbols) Option {
218+
return func(target *Table) {
219+
if target.renderer != nil {
220+
cfg := target.renderer.Config()
221+
cfg.Symbols = symbols
222+
if target.logger != nil {
223+
target.logger.Debug("Option: WithSymbols applied to Table.")
224+
}
225+
}
226+
}
227+
}

0 commit comments

Comments
 (0)