tablewriter

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2025 License: MIT Imports: 17 Imported by: 9,752

README

Here’s a polished version of your introduction with improved clarity, structure, and consistency:


TableWriter for Go

CI GoDoc Latest Release

tablewriter is a Go library for generating rich text-based tables with support for multiple output formats, including ASCII, Unicode, Markdown, HTML, and colorized terminals. Perfect for CLI tools, logs, and web applications.

Key Features
  • Multi-format rendering: ASCII, Unicode, Markdown, HTML, ANSI-colored
  • Advanced styling: Cell merging, alignment, padding, borders
  • Flexible input: CSV, structs, slices, or streaming data
  • High performance: Minimal allocations, buffer reuse
  • Modern features: Generics support, hierarchical merging, real-time streaming

Installation
Legacy Version (v0.0.5)

For use with legacy applications:

go get github.com/olekukonko/tablewriter@v0.0.5
Latest Version

The latest version (API Change)

go get github.com/olekukonko/tablewriter@latest

Version Guidance

  • Production: Use v0.0.5 (stable)
  • New Features: Use @latest (includes generics, super fast streaming APIs)
  • Legacy Docs: See README_LEGACY.md

Why TableWriter?
  • CLI Ready: Instant compatibility with terminal outputs
  • Database Friendly: Native support for sql.Null* types
  • Secure: Auto-escaping for HTML/Markdown
  • Extensible: Custom renderers and formatters

Quick Example
package main

import (
	"github.com/olekukonko/tablewriter"
	"os"
)

func main() {
	data := [][]string{
		{"Package", "Version", "Status"},
		{"tablewriter", "v0.0.5", "legacy"},
		{"tablewriter", "v1.0.0", "latest"},
	}

	table := tablewriter.NewWriter(os.Stdout)
	table.Header(data[0])
	table.Bulk(data[1:])
	table.Render()
}

Output:

┌─────────────┬─────────┬────────┐
│   PACKAGE   │ VERSION │ STATUS │
├─────────────┼─────────┼────────┤
│ tablewriter │ v0.0.5  │ legacy │
│ tablewriter │ v1.0.0  │ latest │
└─────────────┴─────────┴────────┘

Detailed Usage

Create a table with NewTable or NewWriter, configure it using options or a Config struct, add data with Append or Bulk, and render to an io.Writer. Use renderers like Blueprint (ASCII), HTML, Markdown, Colorized, or Ocean (streaming).

Examples

Basic Examples
1. Simple ASCII Table

Create a basic ASCII table with headers and rows.

package main

import (
	"fmt"
	"github.com/olekukonko/tablewriter"
	"os"
)

type Age int

func (a Age) String() string {
	return fmt.Sprintf("%d yrs", a)
}

func main() {
	data := [][]any{
		{"Alice", Age(25), "New York"},
		{"Bob", Age(30), "Boston"},
	}

	table := tablewriter.NewTable(os.Stdout)
	table.Header("Name", "Age", "City")
	table.Bulk(data)
	table.Render()
}

Output:

┌───────┬────────┬──────────┐
│ NAME  │  AGE   │   CITY   │
├───────┼────────┼──────────┤
│ Alice │ 25 yrs │ New York │
│ Bob   │ 30 yrs │ Boston   │
└───────┴────────┴──────────┘

2. Markdown Table

Generate a Markdown table for documentation.

package main

import (
	"fmt"
	"github.com/olekukonko/tablewriter"
	"github.com/olekukonko/tablewriter/renderer"
	"os"
	"strings"
	"unicode"
)

type Name struct {
	First string
	Last  string
}

// this will be ignored since  Format() is present
func (n Name) String() string {
	return fmt.Sprintf("%s %s", n.First, n.Last)
}

// Note: Format() overrides String() if both exist.
func (n Name) Format() string {
	return fmt.Sprintf("%s %s", n.clean(n.First), n.clean(n.Last))
}

// clean ensures the first letter is capitalized and the rest are lowercase
func (n Name) clean(s string) string {
	s = strings.TrimSpace(strings.ToLower(s))
	words := strings.Fields(s)
	s = strings.Join(words, "")

	if s == "" {
		return s
	}
	// Capitalize the first letter
	runes := []rune(s)
	runes[0] = unicode.ToUpper(runes[0])
	return string(runes)
}

type Age int

// Age int will be ignore and string will be used
func (a Age) String() string {
	return fmt.Sprintf("%d yrs", a)
}

func main() {
	data := [][]any{
		{Name{"Al  i  CE", " Ma  SK"}, Age(25), "New York"},
		{Name{"bOb", "mar   le   y"}, Age(30), "Boston"},
	}

	table := tablewriter.NewTable(os.Stdout,
		tablewriter.WithRenderer(renderer.NewMarkdown()),
	)

	table.Header([]string{"Name", "Age", "City"})
	table.Bulk(data)
	table.Render()
}

Output:

|    NAME    |  AGE   |   CITY   |
|:----------:|:------:|:--------:|
| Alice Mask | 25 yrs | New York |
| Bob Marley | 30 yrs | Boston   |


3. CSV Input

Create a table from a CSV file with custom row alignment.

package main

import (
	"github.com/olekukonko/tablewriter"
	"github.com/olekukonko/tablewriter/tw"
	"log"
	"os"
)

func main() {
	// Assuming "test.csv" contains: "First Name,Last Name,SSN\nJohn,Barry,123456\nKathy,Smith,687987"
	table, err := tablewriter.NewCSV(os.Stdout, "test.csv", true)
	if err != nil {
		log.Fatalf("Error: %v", err)
	}

	table.Configure(func(config *tablewriter.Config) {
		config.Row.Formatting.Alignment = tw.AlignLeft
	})
	table.Render()
}

Output:

┌────────────┬───────────┬─────────┐
│ FIRST NAME │ LAST NAME │   SSN   │
├────────────┼───────────┼─────────┤
│ John       │ Barry     │ 123456  │
│ Kathy      │ Smith     │ 687987  │
└────────────┴───────────┴─────────┘
Advanced Examples
4. Colorized Table with Long Values

Create a colorized table with wrapped long values, per-column colors, and a styled footer (inspired by TestColorizedLongValues and TestColorizedCustomColors).

package main

import (
	"github.com/fatih/color"
	"github.com/olekukonko/tablewriter"
	"github.com/olekukonko/tablewriter/renderer"
	"github.com/olekukonko/tablewriter/tw"
	"os"
)

func main() {
	data := [][]string{
		{"1", "This is a very long description that needs wrapping for readability", "OK"},
		{"2", "Short description", "DONE"},
		{"3", "Another lengthy description requiring truncation or wrapping", "ERROR"},
	}

	// Configure colors: green headers, cyan/magenta rows, yellow footer
	colorCfg := renderer.ColorizedConfig{
		Header: renderer.Tint{
			FG: renderer.Colors{color.FgGreen, color.Bold}, // Green bold headers
			BG: renderer.Colors{color.BgHiWhite},
		},
		Column: renderer.Tint{
			FG: renderer.Colors{color.FgCyan}, // Default cyan for rows
			Columns: []renderer.Tint{
				{FG: renderer.Colors{color.FgMagenta}}, // Magenta for column 0
				{},                                     // Inherit default (cyan)
				{FG: renderer.Colors{color.FgHiRed}},   // High-intensity red for column 2
			},
		},
		Footer: renderer.Tint{
			FG: renderer.Colors{color.FgYellow, color.Bold}, // Yellow bold footer
			Columns: []renderer.Tint{
				{},                                      // Inherit default
				{FG: renderer.Colors{color.FgHiYellow}}, // High-intensity yellow for column 1
				{},                                      // Inherit default
			},
		},
		Border:    renderer.Tint{FG: renderer.Colors{color.FgWhite}}, // White borders
		Separator: renderer.Tint{FG: renderer.Colors{color.FgWhite}}, // White separators
	}

	table := tablewriter.NewTable(os.Stdout,
		tablewriter.WithRenderer(renderer.NewColorized(colorCfg)),
		tablewriter.WithConfig(tablewriter.Config{
			Row: tw.CellConfig{
				Formatting: tw.CellFormatting{
					MaxWidth:  25,            // Limit column width
					AutoWrap:  tw.WrapNormal, // Wrap long content
					Alignment: tw.AlignLeft,  // Left-align rows
				},
			},
			Footer: tw.CellConfig{
				Formatting: tw.CellFormatting{Alignment: tw.AlignRight},
			},
		}),
	)

	table.Header([]string{"ID", "Description", "Status"})
	table.Bulk(data)
	table.Footer([]string{"", "Total", "3"})
	table.Render()
}

Output (colors visible in ANSI-compatible terminals):

Colorized Table with Long Values

5. Streaming Table with Truncation

Stream a table incrementally with truncation and a footer, simulating a real-time data feed (inspired by TestOceanStreamTruncation and TestOceanStreamSlowOutput).

package main

import (
	"github.com/olekukonko/tablewriter"
	"github.com/olekukonko/tablewriter/tw"
	"log"
	"os"
	"time"
)

func main() {
	table := tablewriter.NewTable(os.Stdout, tablewriter.WithStreaming(tw.StreamConfig{Enable: true}))

	// Start streaming
	if err := table.Start(); err != nil {
		log.Fatalf("Start failed: %v", err)
	}

	defer table.Close()

	// Stream header
	table.Header([]string{"ID", "Description", "Status"})

	// Stream rows with simulated delay
	data := [][]string{
		{"1", "This description is too long", "OK"},
		{"2", "Short desc", "DONE"},
		{"3", "Another long description here", "ERROR"},
	}
	for _, row := range data {
		table.Append(row)
		time.Sleep(500 * time.Millisecond) // Simulate real-time data feed
	}

	// Stream footer
	table.Footer([]string{"", "Total", "3"})
}

Output (appears incrementally):

┌────────┬───────────────┬──────────┐
│   ID   │  DESCRIPTION  │  STATUS  │
├────────┼───────────────┼──────────┤
│ 1      │ This          │ OK       │
│        │ description   │          │
│        │ is too long   │          │
│ 2      │ Short desc    │ DONE     │
│ 3      │ Another long  │ ERROR    │
│        │ description   │          │
│        │ here          │          │
├────────┼───────────────┼──────────┤
│        │         Total │        3 │
└────────┴───────────────┴──────────┘

Note: Long descriptions are truncated with due to fixed column widths. The output appears row-by-row, simulating a real-time feed.

6. Hierarchical Merging for Organizational Data

Show hierarchical merging for a tree-like structure, such as an organizational hierarchy (inspired by TestMergeHierarchicalUnicode).

package main

import (
	"github.com/olekukonko/tablewriter"
	"github.com/olekukonko/tablewriter/renderer"
	"github.com/olekukonko/tablewriter/tw"
	"os"
)

func main() {
	data := [][]string{
		{"Engineering", "Backend", "API Team", "Alice"},
		{"Engineering", "Backend", "Database Team", "Bob"},
		{"Engineering", "Frontend", "UI Team", "Charlie"},
		{"Marketing", "Digital", "SEO Team", "Dave"},
		{"Marketing", "Digital", "Content Team", "Eve"},
	}

	table := tablewriter.NewTable(os.Stdout,
		tablewriter.WithRenderer(renderer.NewBlueprint(tw.RendererConfig{
			Settings: tw.Settings{
				Separators: tw.Separators{BetweenRows: tw.On},
			},
		})),
		tablewriter.WithConfig(tablewriter.Config{
			Header: tw.CellConfig{
				Formatting: tw.CellFormatting{Alignment: tw.AlignCenter},
			},
			Row: tw.CellConfig{
				Formatting: tw.CellFormatting{
					MergeMode: tw.MergeHierarchical,
					Alignment: tw.AlignLeft,
				},
			},
		}),
	)
	table.Header([]string{"Department", "Division", "Team", "Lead"})
	table.Bulk(data)
	table.Render()
}

Output:

┌────────────┬──────────┬──────────────┬────────┐
│ DEPARTMENT │ DIVISION │    TEAM      │  LEAD  │
├────────────┼──────────┼──────────────┼────────┤
│ Engineering│ Backend  │ API Team     │ Alice  │
│            │          ├──────────────┼────────┤
│            │          │ Database Team│ Bob    │
│            │ Frontend ├──────────────┼────────┤
│            │          │ UI Team      │ Charlie│
├────────────┼──────────┼──────────────┼────────┤
│ Marketing  │ Digital  │ SEO Team     │ Dave   │
│            │          ├──────────────┼────────┤
│            │          │ Content Team │ Eve    │
└────────────┴──────────┴──────────────┴────────┘

Note: Hierarchical merging groups repeated values (e.g., "Engineering" spans multiple rows, "Backend" spans two teams), creating a tree-like structure.

7. Custom Padding with Merging

Showcase custom padding and combined horizontal/vertical merging (inspired by TestMergeWithPadding in merge_test.go).

package main

import (
	"github.com/olekukonko/tablewriter"
	"github.com/olekukonko/tablewriter/renderer"
	"github.com/olekukonko/tablewriter/tw"
	"os"
)

func main() {
	data := [][]string{
		{"1/1/2014", "Domain name", "Successful", "Successful"},
		{"1/1/2014", "Domain name", "Pending", "Waiting"},
		{"1/1/2014", "Domain name", "Successful", "Rejected"},
		{"", "", "TOTAL", "$145.93"},
	}

	table := tablewriter.NewTable(os.Stdout,
		tablewriter.WithRenderer(renderer.NewBlueprint(tw.RendererConfig{
			Settings: tw.Settings{
				Separators: tw.Separators{BetweenRows: tw.On},
			},
		})),
		tablewriter.WithConfig(tablewriter.Config{
			Row: tw.CellConfig{
				Formatting:   tw.CellFormatting{MergeMode: tw.MergeBoth},
				ColumnAligns: []tw.Align{tw.Skip, tw.Skip, tw.AlignRight, tw.AlignLeft},
			},
			Footer: tw.CellConfig{
				Padding: tw.CellPadding{
					Global:    tw.Padding{Left: "*", Right: "*"},
					PerColumn: []tw.Padding{{}, {}, {Bottom: "^"}, {Bottom: "^"}},
				},
				ColumnAligns: []tw.Align{tw.Skip, tw.Skip, tw.AlignRight, tw.AlignLeft},
			},
		}),
	)
	table.Header([]string{"Date", "Description", "Status", "Conclusion"})
	table.Bulk(data)
	table.Render()
}

Output:

┌──────────┬─────────────┬────────────┬────────────┐
│   DATE   │ DESCRIPTION │   STATUS   │ CONCLUSION │
├──────────┼─────────────┼────────────┴────────────┤
│ 1/1/2014 │ Domain name │              Successful │
│          │             ├────────────┬────────────┤
│          │             │    Pending │ Waiting    │
│          │             ├────────────┼────────────┤
│          │             │ Successful │ Rejected   │
├──────────┼─────────────┼────────────┼────────────┤
│          │             │      TOTAL │ $145.93    │
│          │             │^^^^^^^^^^^^│^^^^^^^^^^^^│
└──────────┴─────────────┴────────────┴────────────┘
8. Nested Tables

Create a table with nested sub-tables for complex layouts (inspired by TestMasterClass in extra_test.go).

package main

import (
	"bytes"
	"github.com/olekukonko/tablewriter"
	"github.com/olekukonko/tablewriter/renderer"
	"github.com/olekukonko/tablewriter/tw"
	"os"
)

func main() {
	// Helper to create a sub-table
	createSubTable := func(s string) string {
		var buf bytes.Buffer
		table := tablewriter.NewTable(&buf,
			tablewriter.WithRenderer(renderer.NewBlueprint(tw.RendererConfig{
				Borders: tw.BorderNone,
				Symbols: tw.NewSymbols(tw.StyleASCII),
				Settings: tw.Settings{
					Separators: tw.Separators{BetweenRows: tw.On},
					Lines:      tw.Lines{ShowFooterLine: tw.On},
				},
			})),
			tablewriter.WithConfig(tablewriter.Config{
				MaxWidth: 10,
				Row: tw.CellConfig{
					Formatting: tw.CellFormatting{Alignment: tw.AlignCenter},
				},
			}),
		)
		table.Append([]string{s, s})
		table.Append([]string{s, s})
		table.Render()
		return buf.String()
	}

	// Main table
	table := tablewriter.NewTable(os.Stdout,
		tablewriter.WithRenderer(renderer.NewBlueprint(tw.RendererConfig{
			Borders: tw.BorderNone,
			Settings: tw.Settings{
				Separators: tw.Separators{BetweenColumns: tw.On},
			},
		})),
		tablewriter.WithConfig(tablewriter.Config{
			MaxWidth: 30,
			Row: tw.CellConfig{
				Formatting: tw.CellFormatting{Alignment: tw.AlignCenter},
			},
		}),
	)
	table.Append([]string{createSubTable("A"), createSubTable("B")})
	table.Append([]string{createSubTable("C"), createSubTable("D")})
	table.Render()
}

Output:

  A | A  │  B | B  
 ---+--- │ ---+--- 
  A | A  │  B | B  
 ---+--- │ ---+--- 
         │         
  C | C  │  D | D  
 ---+--- │ ---+--- 
  C | C  │  D | D  
 ---+--- │ ---+--- 
         │         
9. Structs with Database

Render a table from a slice of structs, simulating a database query (inspired by TestStructTableWithDB in struct_test.go).

package main

import (
	"fmt"
	"github.com/olekukonko/tablewriter"
	"github.com/olekukonko/tablewriter/renderer"
	"github.com/olekukonko/tablewriter/tw"
	"os"
)

type Employee struct {
	ID         int
	Name       string
	Age        int
	Department string
	Salary     float64
}

func employeeStringer(e interface{}) []string {
	emp, ok := e.(Employee)
	if !ok {
		return []string{"Error: Invalid type"}
	}
	return []string{
		fmt.Sprintf("%d", emp.ID),
		emp.Name,
		fmt.Sprintf("%d", emp.Age),
		emp.Department,
		fmt.Sprintf("%.2f", emp.Salary),
	}
}

func main() {
	employees := []Employee{
		{ID: 1, Name: "Alice Smith", Age: 28, Department: "Engineering", Salary: 75000.50},
		{ID: 2, Name: "Bob Johnson", Age: 34, Department: "Marketing", Salary: 62000.00},
		{ID: 3, Name: "Charlie Brown", Age: 45, Department: "HR", Salary: 80000.75},
	}

	table := tablewriter.NewTable(os.Stdout,
		tablewriter.WithRenderer(renderer.NewBlueprint(tw.RendererConfig{
			Symbols: tw.NewSymbols(tw.StyleRounded),
		})),
		tablewriter.WithStringer(employeeStringer),
		tablewriter.WithConfig(tablewriter.Config{
			Header: tw.CellConfig{
				Formatting: tw.CellFormatting{Alignment: tw.AlignCenter, AutoFormat: true},
			},
			Row: tw.CellConfig{
				Formatting: tw.CellFormatting{Alignment: tw.AlignLeft},
			},
			Footer: tw.CellConfig{
				Formatting: tw.CellFormatting{Alignment: tw.AlignRight},
			},
		}),
	)
	table.Header([]string{"ID", "Name", "Age", "Department", "Salary"})

	for _, emp := range employees {
		table.Append(emp)
	}

	totalSalary := 0.0
	for _, emp := range employees {
		totalSalary += emp.Salary
	}
	table.Footer([]string{"", "", "", "Total", fmt.Sprintf("%.2f", totalSalary)})
	table.Render()
}

Output:

╭────┬───────────────┬─────┬─────────────┬───────────╮
│ ID │     NAME      │ AGE │ DEPARTMENT  │  SALARY   │
├────┼───────────────┼─────┼─────────────┼───────────┤
│ 1  │ Alice Smith   │ 28  │ Engineering │ 75000.50  │
│ 2  │ Bob Johnson   │ 34  │ Marketing   │ 62000.00  │
│ 3  │ Charlie Brown │ 45  │ HR          │ 80000.75  │
├────┼───────────────┼─────┼─────────────┼───────────┤
│    │               │     │       Total │ 217001.25 │
╰────┴───────────────┴─────┴─────────────┴───────────╯
10. Simple Html Table
package main

import (
	"github.com/olekukonko/tablewriter"
	"github.com/olekukonko/tablewriter/renderer"
	"github.com/olekukonko/tablewriter/tw"
	"os"
)

func main() {
	data := [][]string{
		{"North", "Q1 & Q2", "Q1 & Q2", "$2200.00"},
		{"South", "Q1", "Q1", "$1000.00"},
		{"South", "Q2", "Q2", "$1200.00"},
	}

	// Configure HTML with custom CSS classes and content escaping
	htmlCfg := renderer.HTMLConfig{
		TableClass:     "sales-table",
		HeaderClass:    "table-header",
		BodyClass:      "table-body",
		FooterClass:    "table-footer",
		RowClass:       "table-row",
		HeaderRowClass: "header-row",
		FooterRowClass: "footer-row",
		EscapeContent:  true, // Escape HTML characters (e.g., "&" to "&")
	}

	table := tablewriter.NewTable(os.Stdout,
		tablewriter.WithRenderer(renderer.NewHTML(os.Stdout, false, htmlCfg)),
		tablewriter.WithConfig(tablewriter.Config{
			Header: tw.CellConfig{
				Formatting: tw.CellFormatting{
					Alignment: tw.AlignCenter,
					MergeMode: tw.MergeHorizontal, // Merge identical header cells
				},
			},
			Row: tw.CellConfig{
				Formatting: tw.CellFormatting{
					MergeMode: tw.MergeHorizontal, // Merge identical row cells
					Alignment: tw.AlignLeft,
				},
			},
			Footer: tw.CellConfig{
				Formatting: tw.CellFormatting{Alignment: tw.AlignRight},
			},
		}),
	)

	table.Header([]string{"Region", "Quarter", "Quarter", "Sales"})
	table.Bulk(data)
	table.Footer([]string{"", "", "Total", "$4400.00"})
	table.Render()
}

Output:

<table class="sales-table">
    <thead class="table-header">
        <tr class="header-row">
            <th style="text-align: center;">REGION</th>
            <th colspan="2" style="text-align: center;">QUARTER</th>
            <th style="text-align: center;">SALES</th>
        </tr>
    </thead>
    <tbody class="table-body">
        <tr class="table-row">
            <td style="text-align: left;">North</td>
            <td colspan="2" style="text-align: left;">Q1 &amp; Q2</td>
            <td style="text-align: left;">$2200.00</td>
        </tr>
        <tr class="table-row">
            <td style="text-align: left;">South</td>
            <td colspan="2" style="text-align: left;">Q1</td>
            <td style="text-align: left;">$1000.00</td>
        </tr>
        <tr class="table-row">
            <td style="text-align: left;">South</td>
            <td colspan="2" style="text-align: left;">Q2</td>
            <td style="text-align: left;">$1200.00</td>
        </tr>
    </tbody>
    <tfoot class="table-footer">
        <tr class="footer-row">
            <td style="text-align: right;"></td>
            <td style="text-align: right;"></td>
            <td style="text-align: right;">Total</td>
            <td style="text-align: right;">$4400.00</td>
        </tr>
    </tfoot>
</table>

Command-Line Tool

The csv2table tool converts CSV files to ASCII tables. See cmd/csv2table/csv2table.go for details.

Example usage:

csv2table -f test.csv -h true -a left

Contributing

Contributions are welcome! Submit issues or pull requests to the GitHub repository.

License

MIT License. See the LICENSE file for details.

Documentation

Overview

Package tablewriter provides functionality for creating and formatting tables with customizable configurations.

Index

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
	Footer   tw.CellConfig   // Configuration for the footer 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

Formatting returns a builder for configuring footer formatting settings.

func (*FooterConfigBuilder) Padding added in v1.0.0

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

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) WithMaxWidth added in v1.0.0

func (ff *FooterFormattingBuilder) WithMaxWidth(maxWidth int) *FooterFormattingBuilder

WithMaxWidth sets the maximum content width for footer cells. Negative values 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

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

Formatting returns a builder for configuring header formatting settings.

func (*HeaderConfigBuilder) Padding added in v1.0.0

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

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) WithMaxWidth added in v1.0.0

func (hf *HeaderFormattingBuilder) WithMaxWidth(maxWidth int) *HeaderFormattingBuilder

WithMaxWidth sets the maximum content width for header cells. Negative values 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

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 WithAutoHide added in v1.0.1

func WithAutoHide(state tw.State) Option

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

func WithBorders(borders tw.Border) Option

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

func WithColumnMax(width int) Option

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

func WithColumnWidths(widths map[int]int) Option

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

func WithConfig(cfg Config) Option

WithConfig applies a custom configuration to the table by merging it with the default configuration.

func WithDebug added in v1.0.0

func WithDebug(debug bool) Option

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

func WithFooter(footers []string) Option

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

func WithFooterMergeMode(mergeMode int) Option

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

func WithHeader(headers []string) Option

WithHeader sets the table headers by calling the Header method.

func WithHeaderAlignment added in v1.0.0

func WithHeaderAlignment(align tw.Align) Option

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

func WithLogger(logger *ll.Logger) Option

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

func WithRenderer(f tw.Renderer) Option

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

func WithRendererSettings(settings tw.Settings) Option

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

func WithRowMaxWidth(maxWidth int) Option

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

func WithSymbols(symbols tw.Symbols) Option

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

func WithTrimSpace(state tw.State) Option

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

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) WithMaxWidth added in v1.0.0

func (rf *RowFormattingBuilder) WithMaxWidth(maxWidth int) *RowFormattingBuilder

WithMaxWidth sets the maximum content width for row cells. Negative values 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

func NewCSV(writer io.Writer, fileName string, hasHeader bool) (*Table, error)

NewCSV Start A new table by importing from a CSV file Takes io.Writer and csv File name

func NewCSVReader

func NewCSVReader(writer io.Writer, csvReader *csv.Reader, hasHeader bool) (*Table, error)

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

func NewTable(w io.Writer, opts ...Option) *Table

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

func NewWriter(w io.Writer) *Table

NewWriter creates a new table with default settings for backward compatibility. It logs the creation if debugging is enabled.

func (*Table) Append

func (t *Table) Append(rows ...interface{}) error

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

func (t *Table) Bulk(rows interface{}) error

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) Close added in v1.0.1

func (t *Table) Close() error

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

func (t *Table) Config() Config

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

func (t *Table) Configure(fn func(*Config)) *Table

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

func (t *Table) Debug() *bytes.Buffer

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

func (t *Table) Footer(elements ...any)

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

func (t *Table) Header(elements ...any)

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

func (t *Table) Logger() *ll.Logger

Logger retrieves the table's logger instance. No parameters are required. Returns the ll.Logger instance used for debug tracing.

func (*Table) Render

func (t *Table) Render() error

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

func (t *Table) Renderer() tw.Renderer

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

func (t *Table) Start() error

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
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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL