Documentation
¶
Overview ¶
Package tablewriter provides functionality for creating and formatting tables with customizable configurations.
Index ¶
- type Behavior
- type ColumnConfigBuilder
- type Config
- type ConfigBuilder
- func (b *ConfigBuilder) Build() Config
- func (b *ConfigBuilder) Footer() *FooterConfigBuilder
- func (b *ConfigBuilder) ForColumn(col int) *ColumnConfigBuilder
- func (b *ConfigBuilder) Header() *HeaderConfigBuilder
- func (b *ConfigBuilder) Row() *RowConfigBuilder
- func (b *ConfigBuilder) WithAutoHide(state tw.State) *ConfigBuilder
- func (b *ConfigBuilder) WithDebug(debug bool) *ConfigBuilder
- func (b *ConfigBuilder) WithFooterAlignment(align tw.Align) *ConfigBuilder
- func (b *ConfigBuilder) WithFooterAutoFormat(autoFormat bool) *ConfigBuilder
- func (b *ConfigBuilder) WithFooterAutoWrap(autoWrap int) *ConfigBuilder
- func (b *ConfigBuilder) WithFooterGlobalPadding(padding tw.Padding) *ConfigBuilder
- func (b *ConfigBuilder) WithFooterMaxWidth(maxWidth int) *ConfigBuilder
- func (b *ConfigBuilder) WithFooterMergeMode(mergeMode int) *ConfigBuilder
- func (b *ConfigBuilder) WithHeaderAlignment(align tw.Align) *ConfigBuilder
- func (b *ConfigBuilder) WithHeaderAutoFormat(autoFormat bool) *ConfigBuilder
- func (b *ConfigBuilder) WithHeaderAutoWrap(autoWrap int) *ConfigBuilder
- func (b *ConfigBuilder) WithHeaderGlobalPadding(padding tw.Padding) *ConfigBuilder
- func (b *ConfigBuilder) WithHeaderMaxWidth(maxWidth int) *ConfigBuilder
- func (b *ConfigBuilder) WithHeaderMergeMode(mergeMode int) *ConfigBuilder
- func (b *ConfigBuilder) WithMaxWidth(width int) *ConfigBuilder
- func (b *ConfigBuilder) WithRowAlignment(align tw.Align) *ConfigBuilder
- func (b *ConfigBuilder) WithRowAutoFormat(autoFormat bool) *ConfigBuilder
- func (b *ConfigBuilder) WithRowAutoWrap(autoWrap int) *ConfigBuilder
- func (b *ConfigBuilder) WithRowGlobalPadding(padding tw.Padding) *ConfigBuilder
- func (b *ConfigBuilder) WithRowMaxWidth(maxWidth int) *ConfigBuilder
- func (b *ConfigBuilder) WithRowMergeMode(mergeMode int) *ConfigBuilder
- func (b *ConfigBuilder) WithTrimSpace(state tw.State) *ConfigBuilder
- type FooterConfigBuilder
- type FooterFormattingBuilder
- func (ff *FooterFormattingBuilder) Build() *FooterConfigBuilder
- func (ff *FooterFormattingBuilder) WithAlignment(align tw.Align) *FooterFormattingBuilder
- func (ff *FooterFormattingBuilder) WithAutoFormat(autoFormat bool) *FooterFormattingBuilder
- func (ff *FooterFormattingBuilder) WithAutoWrap(autoWrap int) *FooterFormattingBuilder
- func (ff *FooterFormattingBuilder) WithNewarkMode(mergeMode int) *FooterFormattingBuilder
- type FooterPaddingBuilder
- func (fp *FooterPaddingBuilder) AddColumnPadding(padding tw.Padding) *FooterPaddingBuilder
- func (fp *FooterPaddingBuilder) Build() *FooterConfigBuilder
- func (fp *FooterPaddingBuilder) WithGlobal(padding tw.Padding) *FooterPaddingBuilder
- func (fp *FooterPaddingBuilder) WithPerColumn(padding []tw.Padding) *FooterPaddingBuilder
- type HeaderConfigBuilder
- type HeaderFormattingBuilder
- func (hf *HeaderFormattingBuilder) Build() *HeaderConfigBuilder
- func (hf *HeaderFormattingBuilder) WithAlignment(align tw.Align) *HeaderFormattingBuilder
- func (hf *HeaderFormattingBuilder) WithAutoFormat(autoFormat bool) *HeaderFormattingBuilder
- func (hf *HeaderFormattingBuilder) WithAutoWrap(autoWrap int) *HeaderFormattingBuilder
- func (hf *HeaderFormattingBuilder) WithMergeMode(mergeMode int) *HeaderFormattingBuilder
- type HeaderPaddingBuilder
- func (hp *HeaderPaddingBuilder) AddColumnPadding(padding tw.Padding) *HeaderPaddingBuilder
- func (hp *HeaderPaddingBuilder) Build() *HeaderConfigBuilder
- func (hp *HeaderPaddingBuilder) WithGlobal(padding tw.Padding) *HeaderPaddingBuilder
- func (hp *HeaderPaddingBuilder) WithPerColumn(padding []tw.Padding) *HeaderPaddingBuilder
- type Option
- func WithAlignment(alignment tw.Alignment) Option
- func WithAutoHide(state tw.State) Option
- func WithBorders(borders tw.Border) Option
- func WithColumnMax(width int) Option
- func WithColumnWidths(widths map[int]int) Option
- func WithConfig(cfg Config) Option
- func WithDebug(debug bool) Option
- func WithFooter(footers []string) Option
- func WithFooterConfig(config tw.CellConfig) Option
- func WithFooterMergeMode(mergeMode int) Option
- func WithHeader(headers []string) Option
- func WithHeaderAlignment(align tw.Align) Option
- func WithHeaderConfig(config tw.CellConfig) Option
- func WithLogger(logger *ll.Logger) Option
- func WithRenderer(f tw.Renderer) Option
- func WithRendererSettings(settings tw.Settings) Option
- func WithRowConfig(config tw.CellConfig) Option
- func WithRowMaxWidth(maxWidth int) Option
- func WithStreaming(c tw.StreamConfig) Option
- func WithStringer(stringer interface{}) Option
- func WithStringerCache() Option
- func WithSymbols(symbols tw.Symbols) Option
- func WithTrimSpace(state tw.State) Option
- type RowConfigBuilder
- type RowFormattingBuilder
- func (rf *RowFormattingBuilder) Build() *RowConfigBuilder
- func (rf *RowFormattingBuilder) WithAlignment(align tw.Align) *RowFormattingBuilder
- func (rf *RowFormattingBuilder) WithAutoFormat(autoFormat bool) *RowFormattingBuilder
- func (rf *RowFormattingBuilder) WithAutoWrap(autoWrap int) *RowFormattingBuilder
- func (rf *RowFormattingBuilder) WithMergeMode(mergeMode int) *RowFormattingBuilder
- type RowPaddingBuilder
- func (rp *RowPaddingBuilder) AddColumnPadding(padding tw.Padding) *RowPaddingBuilder
- func (rp *RowPaddingBuilder) Build() *RowConfigBuilder
- func (rp *RowPaddingBuilder) WithGlobal(padding tw.Padding) *RowPaddingBuilder
- func (rp *RowPaddingBuilder) WithPerColumn(padding []tw.Padding) *RowPaddingBuilder
- type Table
- func (t *Table) Append(rows ...interface{}) error
- func (t *Table) Bulk(rows interface{}) error
- func (t *Table) Caption(caption tw.Caption) *Table
- func (t *Table) Close() error
- func (t *Table) Config() Config
- func (t *Table) Configure(fn func(*Config)) *Table
- func (t *Table) Debug() *bytes.Buffer
- func (t *Table) Footer(elements ...any)
- func (t *Table) Header(elements ...any)
- func (t *Table) Logger() *ll.Logger
- func (t *Table) Render() error
- func (t *Table) Renderer() tw.Renderer
- func (t *Table) Start() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Behavior ¶ added in v1.0.1
type Behavior struct {
AutoHide tw.State // Controls whether empty columns are automatically hidden (ignored in streaming mode)
TrimSpace tw.State // Controls whether leading/trailing spaces are trimmed from cell content
}
Behavior defines table behavior settings that control features like auto-hiding columns and trimming spaces.
type ColumnConfigBuilder ¶ added in v1.0.0
type ColumnConfigBuilder struct {
// contains filtered or unexported fields
}
ColumnConfigBuilder is used to configure settings for a specific column across all table sections (header, row, footer).
func (*ColumnConfigBuilder) Build ¶ added in v1.0.0
func (c *ColumnConfigBuilder) Build() *ConfigBuilder
Build returns the parent ConfigBuilder to allow method chaining.
func (*ColumnConfigBuilder) WithAlignment ¶ added in v1.0.0
func (c *ColumnConfigBuilder) WithAlignment(align tw.Align) *ColumnConfigBuilder
WithAlignment sets the text alignment for a specific column in the header section only. Invalid alignments are ignored, and the method returns the builder for chaining.
func (*ColumnConfigBuilder) WithMaxWidth ¶ added in v1.0.0
func (c *ColumnConfigBuilder) WithMaxWidth(width int) *ColumnConfigBuilder
WithMaxWidth sets the maximum width for a specific column across all sections (header, row, footer). Negative widths are ignored, and the method returns the builder for chaining.
type Config ¶ added in v1.0.0
type Config struct {
MaxWidth int // Maximum width of the entire table (0 for unlimited)
Header tw.CellConfig // Configuration for the header section
Row tw.CellConfig // Configuration for the row section
Debug bool // Enables debug logging when true
Stream tw.StreamConfig // Configuration specific to streaming mode
Behavior Behavior // Behavioral settings like auto-hiding and trimming
}
Config represents the overall configuration for a table, including settings for header, rows, footer, and behavior.
type ConfigBuilder ¶ added in v1.0.0
type ConfigBuilder struct {
// contains filtered or unexported fields
}
ConfigBuilder provides a fluent interface for building a Config struct with both direct and nested configuration methods.
func NewConfigBuilder ¶ added in v1.0.0
func NewConfigBuilder() *ConfigBuilder
NewConfigBuilder creates a new ConfigBuilder initialized with default settings.
func (*ConfigBuilder) Build ¶ added in v1.0.0
func (b *ConfigBuilder) Build() Config
Build finalizes and returns the Config struct after all modifications.
func (*ConfigBuilder) Footer ¶ added in v1.0.0
func (b *ConfigBuilder) Footer() *FooterConfigBuilder
Footer returns a builder for advanced configuration of the footer section.
func (*ConfigBuilder) ForColumn ¶ added in v1.0.0
func (b *ConfigBuilder) ForColumn(col int) *ColumnConfigBuilder
ForColumn returns a builder for configuring a specific column across all sections.
func (*ConfigBuilder) Header ¶ added in v1.0.0
func (b *ConfigBuilder) Header() *HeaderConfigBuilder
Header returns a builder for advanced configuration of the header section.
func (*ConfigBuilder) Row ¶ added in v1.0.0
func (b *ConfigBuilder) Row() *RowConfigBuilder
Row returns a builder for advanced configuration of the row section.
func (*ConfigBuilder) WithAutoHide ¶ added in v1.0.1
func (b *ConfigBuilder) WithAutoHide(state tw.State) *ConfigBuilder
WithAutoHide enables or disables automatic hiding of empty columns (ignored in streaming mode).
func (*ConfigBuilder) WithDebug ¶ added in v1.0.0
func (b *ConfigBuilder) WithDebug(debug bool) *ConfigBuilder
WithDebug enables or disables debug logging for the table.
func (*ConfigBuilder) WithFooterAlignment ¶ added in v1.0.0
func (b *ConfigBuilder) WithFooterAlignment(align tw.Align) *ConfigBuilder
WithFooterAlignment sets the text alignment for all footer cells. Invalid alignments are ignored.
func (*ConfigBuilder) WithFooterAutoFormat ¶ added in v1.0.0
func (b *ConfigBuilder) WithFooterAutoFormat(autoFormat bool) *ConfigBuilder
WithFooterAutoFormat enables or disables automatic formatting (e.g., title case) for footer cells.
func (*ConfigBuilder) WithFooterAutoWrap ¶ added in v1.0.0
func (b *ConfigBuilder) WithFooterAutoWrap(autoWrap int) *ConfigBuilder
WithFooterAutoWrap sets the wrapping behavior for footer cells (e.g., truncate, normal, break). Invalid wrap modes are ignored.
func (*ConfigBuilder) WithFooterGlobalPadding ¶ added in v1.0.0
func (b *ConfigBuilder) WithFooterGlobalPadding(padding tw.Padding) *ConfigBuilder
WithFooterGlobalPadding sets the global padding for all footer cells.
func (*ConfigBuilder) WithFooterMaxWidth ¶ added in v1.0.0
func (b *ConfigBuilder) WithFooterMaxWidth(maxWidth int) *ConfigBuilder
WithFooterMaxWidth sets the maximum content width for footer cells. Negative values are ignored.
func (*ConfigBuilder) WithFooterMergeMode ¶ added in v1.0.0
func (b *ConfigBuilder) WithFooterMergeMode(mergeMode int) *ConfigBuilder
WithFooterMergeMode sets the merge behavior for footer cells (e.g., horizontal, hierarchical). Invalid merge modes are ignored.
func (*ConfigBuilder) WithHeaderAlignment ¶ added in v1.0.0
func (b *ConfigBuilder) WithHeaderAlignment(align tw.Align) *ConfigBuilder
WithHeaderAlignment sets the text alignment for all header cells. Invalid alignments are ignored.
func (*ConfigBuilder) WithHeaderAutoFormat ¶ added in v1.0.0
func (b *ConfigBuilder) WithHeaderAutoFormat(autoFormat bool) *ConfigBuilder
WithHeaderAutoFormat enables or disables automatic formatting (e.g., title case) for header cells.
func (*ConfigBuilder) WithHeaderAutoWrap ¶ added in v1.0.0
func (b *ConfigBuilder) WithHeaderAutoWrap(autoWrap int) *ConfigBuilder
WithHeaderAutoWrap sets the wrapping behavior for header cells (e.g., truncate, normal). Invalid wrap modes are ignored.
func (*ConfigBuilder) WithHeaderGlobalPadding ¶ added in v1.0.0
func (b *ConfigBuilder) WithHeaderGlobalPadding(padding tw.Padding) *ConfigBuilder
WithHeaderGlobalPadding sets the global padding for all header cells.
func (*ConfigBuilder) WithHeaderMaxWidth ¶ added in v1.0.0
func (b *ConfigBuilder) WithHeaderMaxWidth(maxWidth int) *ConfigBuilder
WithHeaderMaxWidth sets the maximum content width for header cells. Negative values are ignored.
func (*ConfigBuilder) WithHeaderMergeMode ¶ added in v1.0.0
func (b *ConfigBuilder) WithHeaderMergeMode(mergeMode int) *ConfigBuilder
WithHeaderMergeMode sets the merge behavior for header cells (e.g., horizontal, vertical). Invalid merge modes are ignored.
func (*ConfigBuilder) WithMaxWidth ¶ added in v1.0.0
func (b *ConfigBuilder) WithMaxWidth(width int) *ConfigBuilder
WithMaxWidth sets the maximum width for the entire table (0 means unlimited). Negative values are treated as 0.
func (*ConfigBuilder) WithRowAlignment ¶ added in v1.0.0
func (b *ConfigBuilder) WithRowAlignment(align tw.Align) *ConfigBuilder
WithRowAlignment sets the text alignment for all row cells. Invalid alignments are ignored.
func (*ConfigBuilder) WithRowAutoFormat ¶ added in v1.0.0
func (b *ConfigBuilder) WithRowAutoFormat(autoFormat bool) *ConfigBuilder
WithRowAutoFormat enables or disables automatic formatting for row cells.
func (*ConfigBuilder) WithRowAutoWrap ¶ added in v1.0.0
func (b *ConfigBuilder) WithRowAutoWrap(autoWrap int) *ConfigBuilder
WithRowAutoWrap sets the wrapping behavior for row cells (e.g., truncate, normal). Invalid wrap modes are ignored.
func (*ConfigBuilder) WithRowGlobalPadding ¶ added in v1.0.0
func (b *ConfigBuilder) WithRowGlobalPadding(padding tw.Padding) *ConfigBuilder
WithRowGlobalPadding sets the global padding for all row cells.
func (*ConfigBuilder) WithRowMaxWidth ¶ added in v1.0.0
func (b *ConfigBuilder) WithRowMaxWidth(maxWidth int) *ConfigBuilder
WithRowMaxWidth sets the maximum content width for row cells. Negative values are ignored.
func (*ConfigBuilder) WithRowMergeMode ¶ added in v1.0.0
func (b *ConfigBuilder) WithRowMergeMode(mergeMode int) *ConfigBuilder
WithRowMergeMode sets the merge behavior for row cells (e.g., horizontal, hierarchical). Invalid merge modes are ignored.
func (*ConfigBuilder) WithTrimSpace ¶ added in v1.0.1
func (b *ConfigBuilder) WithTrimSpace(state tw.State) *ConfigBuilder
WithTrimSpace enables or disables automatic trimming of leading/trailing spaces. Ignored in streaming mode.
type FooterConfigBuilder ¶ added in v1.0.0
type FooterConfigBuilder struct {
// contains filtered or unexported fields
}
FooterConfigBuilder provides advanced configuration options for the footer section.
func (*FooterConfigBuilder) Build ¶ added in v1.0.0
func (f *FooterConfigBuilder) Build() *ConfigBuilder
Build returns the parent ConfigBuilder for chaining.
func (*FooterConfigBuilder) Formatting ¶ added in v1.0.0
func (f *FooterConfigBuilder) Formatting() *FooterFormattingBuilder
Formatting returns a builder for configuring footer formatting settings.
func (*FooterConfigBuilder) Padding ¶ added in v1.0.0
func (f *FooterConfigBuilder) Padding() *FooterPaddingBuilder
Padding returns a builder for configuring footer padding settings.
type FooterFormattingBuilder ¶ added in v1.0.0
type FooterFormattingBuilder struct {
// contains filtered or unexported fields
}
FooterFormattingBuilder configures formatting options for the footer section.
func (*FooterFormattingBuilder) Build ¶ added in v1.0.0
func (ff *FooterFormattingBuilder) Build() *FooterConfigBuilder
Build returns the parent FooterConfigBuilder for chaining.
func (*FooterFormattingBuilder) WithAlignment ¶ added in v1.0.0
func (ff *FooterFormattingBuilder) WithAlignment(align tw.Align) *FooterFormattingBuilder
WithAlignment sets the text alignment for footer cells. Invalid alignments are ignored.
func (*FooterFormattingBuilder) WithAutoFormat ¶ added in v1.0.0
func (ff *FooterFormattingBuilder) WithAutoFormat(autoFormat bool) *FooterFormattingBuilder
WithAutoFormat enables or disables automatic formatting for footer cells.
func (*FooterFormattingBuilder) WithAutoWrap ¶ added in v1.0.0
func (ff *FooterFormattingBuilder) WithAutoWrap(autoWrap int) *FooterFormattingBuilder
WithAutoWrap sets the wrapping behavior for footer cells. Invalid wrap modes are ignored.
func (*FooterFormattingBuilder) WithNewarkMode ¶ added in v1.0.1
func (ff *FooterFormattingBuilder) WithNewarkMode(mergeMode int) *FooterFormattingBuilder
WithNewarkMode sets the merge behavior for footer cells (likely a typo, should be WithMergeMode). Invalid merge modes are ignored.
type FooterPaddingBuilder ¶ added in v1.0.0
type FooterPaddingBuilder struct {
// contains filtered or unexported fields
}
FooterPaddingBuilder configures padding options for the footer section.
func (*FooterPaddingBuilder) AddColumnPadding ¶ added in v1.0.0
func (fp *FooterPaddingBuilder) AddColumnPadding(padding tw.Padding) *FooterPaddingBuilder
AddColumnPadding adds padding for a specific column in the footer.
func (*FooterPaddingBuilder) Build ¶ added in v1.0.0
func (fp *FooterPaddingBuilder) Build() *FooterConfigBuilder
Build returns the parent FooterConfigBuilder for chaining.
func (*FooterPaddingBuilder) WithGlobal ¶ added in v1.0.0
func (fp *FooterPaddingBuilder) WithGlobal(padding tw.Padding) *FooterPaddingBuilder
WithGlobal sets the global padding for all footer cells.
func (*FooterPaddingBuilder) WithPerColumn ¶ added in v1.0.0
func (fp *FooterPaddingBuilder) WithPerColumn(padding []tw.Padding) *FooterPaddingBuilder
WithPerColumn sets per-column padding for the footer.
type HeaderConfigBuilder ¶ added in v1.0.0
type HeaderConfigBuilder struct {
// contains filtered or unexported fields
}
HeaderConfigBuilder provides advanced configuration options for the header section.
func (*HeaderConfigBuilder) Build ¶ added in v1.0.0
func (h *HeaderConfigBuilder) Build() *ConfigBuilder
Build returns the parent ConfigBuilder for chaining.
func (*HeaderConfigBuilder) Formatting ¶ added in v1.0.0
func (h *HeaderConfigBuilder) Formatting() *HeaderFormattingBuilder
Formatting returns a builder for configuring header formatting settings.
func (*HeaderConfigBuilder) Padding ¶ added in v1.0.0
func (h *HeaderConfigBuilder) Padding() *HeaderPaddingBuilder
Padding returns a builder for configuring header padding settings.
type HeaderFormattingBuilder ¶ added in v1.0.0
type HeaderFormattingBuilder struct {
// contains filtered or unexported fields
}
HeaderFormattingBuilder configures formatting options for the header section.
func (*HeaderFormattingBuilder) Build ¶ added in v1.0.0
func (hf *HeaderFormattingBuilder) Build() *HeaderConfigBuilder
Build returns the parent HeaderConfigBuilder for chaining.
func (*HeaderFormattingBuilder) WithAlignment ¶ added in v1.0.0
func (hf *HeaderFormattingBuilder) WithAlignment(align tw.Align) *HeaderFormattingBuilder
WithAlignment sets the text alignment for header cells. Invalid alignments are ignored.
func (*HeaderFormattingBuilder) WithAutoFormat ¶ added in v1.0.0
func (hf *HeaderFormattingBuilder) WithAutoFormat(autoFormat bool) *HeaderFormattingBuilder
WithAutoFormat enables or disables automatic formatting for header cells.
func (*HeaderFormattingBuilder) WithAutoWrap ¶ added in v1.0.0
func (hf *HeaderFormattingBuilder) WithAutoWrap(autoWrap int) *HeaderFormattingBuilder
WithAutoWrap sets the wrapping behavior for header cells. Invalid wrap modes are ignored.
func (*HeaderFormattingBuilder) WithMergeMode ¶ added in v1.0.0
func (hf *HeaderFormattingBuilder) WithMergeMode(mergeMode int) *HeaderFormattingBuilder
WithMergeMode sets the merge behavior for header cells. Invalid merge modes are ignored.
type HeaderPaddingBuilder ¶ added in v1.0.0
type HeaderPaddingBuilder struct {
// contains filtered or unexported fields
}
HeaderPaddingBuilder configures padding options for the header section.
func (*HeaderPaddingBuilder) AddColumnPadding ¶ added in v1.0.0
func (hp *HeaderPaddingBuilder) AddColumnPadding(padding tw.Padding) *HeaderPaddingBuilder
AddColumnPadding adds padding for a specific column in the header.
func (*HeaderPaddingBuilder) Build ¶ added in v1.0.0
func (hp *HeaderPaddingBuilder) Build() *HeaderConfigBuilder
Build returns the parent HeaderConfigBuilder for chaining.
func (*HeaderPaddingBuilder) WithGlobal ¶ added in v1.0.0
func (hp *HeaderPaddingBuilder) WithGlobal(padding tw.Padding) *HeaderPaddingBuilder
WithGlobal sets the global padding for all header cells.
func (*HeaderPaddingBuilder) WithPerColumn ¶ added in v1.0.0
func (hp *HeaderPaddingBuilder) WithPerColumn(padding []tw.Padding) *HeaderPaddingBuilder
WithPerColumn sets per-column padding for the header.
type Option ¶ added in v1.0.0
type Option func(target *Table)
Option defines a function type for configuring a Table instance.
func WithAlignment ¶ added in v1.0.3
WithAlignment helps to set default alignments
func WithAutoHide ¶ added in v1.0.1
WithAutoHide enables or disables automatic hiding of columns with empty data rows. Logs the change if debugging is enabled.
func WithBorders ¶ added in v1.0.1
WithBorders sets the border configuration for the table and updates the renderer's configuration. Logs the change if debugging is enabled.
func WithColumnMax ¶ added in v1.0.1
WithColumnMax sets a global maximum column width for the table in streaming mode. Negative values are ignored, and the change is logged if debugging is enabled.
func WithColumnWidths ¶ added in v1.0.1
WithColumnWidths sets per-column widths for the table in streaming mode. Negative widths are removed, and the change is logged if debugging is enabled.
func WithConfig ¶ added in v1.0.0
WithConfig applies a custom configuration to the table by merging it with the default configuration.
func WithDebug ¶ added in v1.0.0
WithDebug enables or disables debug logging and adjusts the logger level accordingly. Logs the change if debugging is enabled.
func WithFooter ¶ added in v1.0.0
WithFooter sets the table footers by calling the Footer method.
func WithFooterConfig ¶ added in v1.0.0
func WithFooterConfig(config tw.CellConfig) Option
WithFooterConfig applies a full footer configuration to the table. Logs the change if debugging is enabled.
func WithFooterMergeMode ¶ added in v1.0.0
WithFooterMergeMode sets the merge mode for footer cells. Invalid merge modes are ignored, and the change is logged if debugging is enabled.
func WithHeader ¶ added in v1.0.0
WithHeader sets the table headers by calling the Header method.
func WithHeaderAlignment ¶ added in v1.0.0
WithHeaderAlignment sets the text alignment for header cells. Invalid alignments are ignored, and the change is logged if debugging is enabled.
func WithHeaderConfig ¶ added in v1.0.0
func WithHeaderConfig(config tw.CellConfig) Option
WithHeaderConfig applies a full header configuration to the table. Logs the change if debugging is enabled.
func WithLogger ¶ added in v1.0.1
WithLogger sets a custom logger for the table and updates the renderer if present. Logs the change if debugging is enabled.
func WithRenderer ¶ added in v1.0.0
WithRenderer sets a custom renderer for the table and attaches the logger if present. Logs the change if debugging is enabled.
func WithRendererSettings ¶ added in v1.0.1
WithRendererSettings updates the renderer's settings (e.g., separators, lines). Logs the change if debugging is enabled.
func WithRowConfig ¶ added in v1.0.0
func WithRowConfig(config tw.CellConfig) Option
WithRowConfig applies a full row configuration to the table. Logs the change if debugging is enabled.
func WithRowMaxWidth ¶ added in v1.0.0
WithRowMaxWidth sets the maximum content width for row cells. Negative values are ignored, and the change is logged if debugging is enabled.
func WithStreaming ¶ added in v1.0.1
func WithStreaming(c tw.StreamConfig) Option
WithStreaming applies a streaming configuration to the table by merging it with the existing configuration. Logs the change if debugging is enabled.
func WithStringer ¶ added in v1.0.0
func WithStringer(stringer interface{}) Option
WithStringer sets a custom stringer function for converting row data and clears the stringer cache. Logs the change if debugging is enabled.
func WithStringerCache ¶ added in v1.0.1
func WithStringerCache() Option
WithStringerCache enables caching for the stringer function.
func WithSymbols ¶ added in v1.0.1
WithSymbols sets the symbols used for table drawing and updates the renderer's configuration. Logs the change if debugging is enabled.
func WithTrimSpace ¶ added in v1.0.1
WithTrimSpace enables or disables automatic trimming of leading/trailing spaces. Logs the change if debugging is enabled.
type RowConfigBuilder ¶ added in v1.0.0
type RowConfigBuilder struct {
// contains filtered or unexported fields
}
RowConfigBuilder provides advanced configuration options for the row section.
func (*RowConfigBuilder) Build ¶ added in v1.0.0
func (r *RowConfigBuilder) Build() *ConfigBuilder
Build returns the parent ConfigBuilder for chaining.
func (*RowConfigBuilder) Formatting ¶ added in v1.0.0
func (r *RowConfigBuilder) Formatting() *RowFormattingBuilder
Formatting returns a builder for configuring row formatting settings.
func (*RowConfigBuilder) Padding ¶ added in v1.0.0
func (r *RowConfigBuilder) Padding() *RowPaddingBuilder
Padding returns a builder for configuring row padding settings.
type RowFormattingBuilder ¶ added in v1.0.0
type RowFormattingBuilder struct {
// contains filtered or unexported fields
}
RowFormattingBuilder configures formatting options for the row section.
func (*RowFormattingBuilder) Build ¶ added in v1.0.0
func (rf *RowFormattingBuilder) Build() *RowConfigBuilder
Build returns the parent RowConfigBuilder for chaining.
func (*RowFormattingBuilder) WithAlignment ¶ added in v1.0.0
func (rf *RowFormattingBuilder) WithAlignment(align tw.Align) *RowFormattingBuilder
WithAlignment sets the text alignment for row cells. Invalid alignments are ignored.
func (*RowFormattingBuilder) WithAutoFormat ¶ added in v1.0.0
func (rf *RowFormattingBuilder) WithAutoFormat(autoFormat bool) *RowFormattingBuilder
WithAutoFormat enables or disables automatic formatting for row cells.
func (*RowFormattingBuilder) WithAutoWrap ¶ added in v1.0.0
func (rf *RowFormattingBuilder) WithAutoWrap(autoWrap int) *RowFormattingBuilder
WithAutoWrap sets the wrapping behavior for row cells. Invalid wrap modes are ignored.
func (*RowFormattingBuilder) WithMergeMode ¶ added in v1.0.0
func (rf *RowFormattingBuilder) WithMergeMode(mergeMode int) *RowFormattingBuilder
WithMergeMode sets the merge behavior for row cells. Invalid merge modes are ignored.
type RowPaddingBuilder ¶ added in v1.0.0
type RowPaddingBuilder struct {
// contains filtered or unexported fields
}
RowPaddingBuilder configures padding options for the row section.
func (*RowPaddingBuilder) AddColumnPadding ¶ added in v1.0.0
func (rp *RowPaddingBuilder) AddColumnPadding(padding tw.Padding) *RowPaddingBuilder
AddColumnPadding adds padding for a specific column in the rows.
func (*RowPaddingBuilder) Build ¶ added in v1.0.0
func (rp *RowPaddingBuilder) Build() *RowConfigBuilder
Build returns the parent RowConfigBuilder for chaining.
func (*RowPaddingBuilder) WithGlobal ¶ added in v1.0.0
func (rp *RowPaddingBuilder) WithGlobal(padding tw.Padding) *RowPaddingBuilder
WithGlobal sets the global padding for all row cells.
func (*RowPaddingBuilder) WithPerColumn ¶ added in v1.0.0
func (rp *RowPaddingBuilder) WithPerColumn(padding []tw.Padding) *RowPaddingBuilder
WithPerColumn sets per-column padding for the rows.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table represents a table instance with content and rendering capabilities.
func NewCSV ¶
NewCSV Start A new table by importing from a CSV file Takes io.Writer and csv File name
func NewCSVReader ¶
NewCSVReader Start a New Table Writer with csv.Reader This enables customisation such as reader.Comma = ';' See http://golang.org/src/pkg/encoding/csv/reader.go?s=3213:3671#L94
func NewTable ¶ added in v1.0.0
NewTable creates a new table instance with specified writer and options. Parameters include writer for output and optional configuration options. Returns a pointer to the initialized Table instance.
func NewWriter ¶
NewWriter creates a new table with default settings for backward compatibility. It logs the creation if debugging is enabled.
func (*Table) Append ¶
Append adds rows to the table, supporting various input types. Parameter rows accepts one or more rows, with stringer for custom types. Returns an error if any row fails to append.
func (*Table) Bulk ¶ added in v1.0.0
Bulk adds multiple rows from a slice to the table (legacy method). Parameter rows must be a slice compatible with stringer or []string. Returns an error if the input is invalid or appending fails.
func (*Table) Caption ¶ added in v1.0.4
Caption sets the table caption (legacy method). Defaults to BottomCenter alignment, wrapping to table width. Use SetCaptionOptions for more control.
func (*Table) Close ¶ added in v1.0.1
Close finalizes the table stream. It requires the stream to be started (by calling NewStreamTable). It calls the renderer's Close method to render final elements (like the bottom border) and close the stream.
func (*Table) Config ¶ added in v1.0.1
Config returns the current table configuration. No parameters are required. Returns the Config struct with current settings.
func (*Table) Configure ¶ added in v1.0.0
Configure updates the table's configuration using a provided function. Parameter fn is a function that modifies the Config struct. Returns the Table instance for method chaining.
func (*Table) Debug ¶ added in v1.0.0
Debug retrieves the accumulated debug trace logs. No parameters are required. Returns a slice of debug messages including renderer logs.
func (*Table) Footer ¶ added in v1.0.0
Footer sets the table's footer content, padding to match column count. Parameter footers is a slice of strings for footer content. No return value. Footer sets the table's footer content. Parameter footers is a slice of strings for footer content. In streaming mode, this processes and stores the footer for rendering by Close().
func (*Table) Header ¶ added in v1.0.0
Header sets the table's header content, padding to match column count. Parameter elements is a slice of strings for header content. No return value. In streaming mode, this processes and renders the header immediately.
func (*Table) Logger ¶ added in v1.0.1
Logger retrieves the table's logger instance. No parameters are required. Returns the ll.Logger instance used for debug tracing.
func (*Table) Render ¶
Render triggers the table rendering process to the configured writer. No parameters are required. Returns an error if rendering fails.
func (*Table) Renderer ¶ added in v1.0.0
Renderer retrieves the current renderer instance used by the table. No parameters are required. Returns the tw.Renderer interface instance.
func (*Table) Start ¶ added in v1.0.1
Start initializes the table stream. In this streaming model, renderer.Start() is primarily called in NewStreamTable. This method serves as a safeguard or point for adding pre-rendering logic. Start initializes the table stream. It is the entry point for streaming mode. Requires t.config.Stream.Enable to be true. Returns an error if streaming is disabled or the renderer does not support streaming, or if called multiple times on the same stream.
Directories
¶
| Path | Synopsis |
|---|---|
|
_example
|
|
|
filetable
command
|
|
|
symbols
command
|
|
|
cmd
|
|
|
csv2table
command
|
|
|
pkg
|
|
|
Package tw provides utility functions for text formatting, width calculation, and string manipulation specifically tailored for table rendering, including handling ANSI escape codes and Unicode text.
|
Package tw provides utility functions for text formatting, width calculation, and string manipulation specifically tailored for table rendering, including handling ANSI escape codes and Unicode text. |
