tabwriter

package
v3.0.0-rc67 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package tabwriter preserves ANSI color codes and aligns columns based on visible width (excluding ANSI escape sequences).

Key features:

  • NewWriter: API-compatible with text/tabwriter.NewWriter
  • Cell type: supports arbitrary number of color.Attribute values
  • WriteColored/WriteCells: convenience methods for colored tabular data
  • Preserves ANSI codes in output while excluding them from width calculations
  • Thread-safe implementation

Index

Constants

View Source
const (
	Debug = tabwriter.Debug
)

Format helper constants for compatibility with text/tabwriter

Variables

This section is empty.

Functions

This section is empty.

Types

type Cell

type Cell struct {
	// contains filtered or unexported fields
}

Cell represents a single tabular cell with color support

func NewCell

func NewCell(content string, attrs ...color.Attribute) Cell

NewCell creates a new cell with the given content and color attributes

func (Cell) String

func (c Cell) String() string

String returns the cell content with ANSI color codes applied

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer is a tabwriter that preserves ANSI color codes. It aligns columns based on visible width (excluding ANSI escape sequences).

func NewWriter

func NewWriter(w io.Writer, minwidth, tabwidth, padding int, padchar byte, flags uint) *Writer

NewWriter creates a new tabwriter that preserves ANSI color codes. Parameters match text/tabwriter.NewWriter:

  • w: the underlying writer
  • minwidth: minimum cell width (in visible characters, excluding ANSI codes)
  • tabwidth: unused (kept for API compatibility)
  • padding: padding added to each cell
  • padchar: ASCII character used for padding
  • flags: unused (kept for API compatibility)

This writer properly handles ANSI escape sequences from github.com/fatih/color, aligning columns based on visible width while preserving color codes in output.

func (*Writer) Flush

func (w *Writer) Flush() error

Flush writes all buffered data to the underlying writer. This must be called to ensure all data is written.

func (*Writer) NewLine

func (w *Writer) NewLine()

NewLine finishes the current line and starts a new one

func (*Writer) Write

func (w *Writer) Write(p []byte) (n int, err error)

Write implements io.Writer by buffering input. Newlines trigger line finalization.

func (*Writer) WriteCells

func (w *Writer) WriteCells(cells []Cell)

WriteCells writes multiple cells (columns) as a tab-separated line with their own colors. Each cell is a string-content pair with color attributes. This is the primary method for writing colored tabular data.

func (*Writer) WriteColored

func (w *Writer) WriteColored(cells ...Cell)

WriteColored writes a line of cells where each cell can have its own color. This is a convenience method for writing a complete row with colored cells.

func (*Writer) WriteLine

func (w *Writer) WriteLine(cells ...string)

WriteLine writes a complete line of cells (tab-separated values). If cells contain ANSI codes, they are preserved and not counted for alignment.

Jump to

Keyboard shortcuts

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