Skip to content

Commit 01bf4ac

Browse files
committed
minor cleanup and return WithSymbols
1 parent 33047f3 commit 01bf4ac

File tree

3 files changed

+42
-29
lines changed

3 files changed

+42
-29
lines changed

deprecated.go

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,16 @@ func (rf *RowFormattingBuilder) WithAlignment(align tw.Align) *RowFormattingBuil
195195
return rf
196196
}
197197

198-
// Deprecated:Use WithMaxWidth instead.
199-
// WithTableMax sets a global maximum table width for the table.
198+
// WithTableMax sets the maximum width of the entire table in characters.
200199
// Negative values are ignored, and the change is logged if debugging is enabled.
200+
// The width constrains the table's rendering, potentially causing text wrapping or truncation
201+
// based on the configuration's wrapping settings (e.g., tw.WrapTruncate).
202+
// If debug logging is enabled via WithDebug(true), the applied width is logged.
203+
//
204+
// Deprecated: Use WithMaxWidth instead, which provides the same functionality with a clearer name
205+
// and consistent naming across the package. For example:
206+
//
207+
// tablewriter.NewTable(os.Stdout, tablewriter.WithMaxWidth(80))
201208
func WithTableMax(width int) Option {
202209
return func(target *Table) {
203210
if width < 0 {
@@ -209,19 +216,3 @@ func WithTableMax(width int) Option {
209216
}
210217
}
211218
}
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-
}

option.go

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,9 @@ package tablewriter
33
import (
44
"github.com/olekukonko/ll"
55
"github.com/olekukonko/tablewriter/tw"
6-
"io"
76
"reflect"
87
)
98

10-
// NewWriter creates a new table with default settings for backward compatibility.
11-
// It logs the creation if debugging is enabled.
12-
func NewWriter(w io.Writer) *Table {
13-
t := NewTable(w)
14-
if t.logger != nil {
15-
t.logger.Debug("NewWriter created buffered Table")
16-
}
17-
return t
18-
}
19-
209
// Option defines a function type for configuring a Table instance.
2110
type Option func(target *Table)
2211

@@ -624,6 +613,29 @@ func WithRendition(rendition tw.Rendition) Option {
624613
}
625614
}
626615

616+
// WithSymbols sets the symbols used for drawing table borders and separators.
617+
// The symbols are applied to the table's renderer configuration, if a renderer is set.
618+
// If no renderer is set (target.renderer is nil), this option has no effect. .
619+
func WithSymbols(symbols tw.Symbols) Option {
620+
return func(target *Table) {
621+
if target.renderer != nil {
622+
cfg := target.renderer.Config()
623+
cfg.Symbols = symbols
624+
625+
if ru, ok := target.renderer.(tw.Renditioning); ok {
626+
ru.Rendition(cfg)
627+
if target.logger != nil {
628+
target.logger.Debugf("Option: WithRendition: Applied to renderer via Renditioning.SetRendition(): %+v", cfg)
629+
}
630+
} else {
631+
if target.logger != nil {
632+
target.logger.Warnf("Option: WithRendition: Current renderer type %T does not implement tw.Renditioning. Rendition may not be applied as expected.", target.renderer)
633+
}
634+
}
635+
}
636+
}
637+
}
638+
627639
// defaultConfig returns a default Config with sensible settings for headers, rows, footers, and behavior.
628640
func defaultConfig() Config {
629641
return Config{

tablewriter.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ func NewTable(w io.Writer, opts ...Option) *Table {
133133
return t
134134
}
135135

136+
// NewWriter creates a new table with default settings for backward compatibility.
137+
// It logs the creation if debugging is enabled.
138+
func NewWriter(w io.Writer) *Table {
139+
t := NewTable(w)
140+
if t.logger != nil {
141+
t.logger.Debug("NewWriter created buffered Table")
142+
}
143+
return t
144+
}
145+
136146
// Caption sets the table caption (legacy method).
137147
// Defaults to BottomCenter alignment, wrapping to table width.
138148
// Use SetCaptionOptions for more control.

0 commit comments

Comments
 (0)