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 ¶
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
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 ¶
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 ¶
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 ¶
Write implements io.Writer by buffering input. Newlines trigger line finalization.
func (*Writer) WriteCells ¶
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 ¶
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.