table

package module
v0.0.0-...-96acc7f Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2025 License: MIT Imports: 7 Imported by: 1

README

since debian stable's version of column(1) doesn't handle successive delimiters

$ go install go.senan.xyz/table/cmd/table@master

$ printf '%s\t%s\t%s\n' '' b c aaaa b c a bbbbbb c '' '' c | table
     b      c
aaaa b      c
a    bbbbbb c
            c

$ printf '%s\t%s\t%s\n' '' b c aaaa b c a bbbbbb c '' '' c | table ' | '
     | b      | c
aaaa | b      | c
a    | bbbbbb | c
     |        | c

# works for streams with a flush interval
$ tail -f logs | pick-cols | table " : " 3
2023 : event one   : event param           : 53f1a74226358c8c7
2023 : event two   : event name is longer  : 53f1a74226358c8c7
2023 : event three : event                 : 53f1a74226358c8c7
2023 : event longer one   : event longer param           : 53f1a74226358c8c7
2023 : event longer two   : event longer name is longer  : 53f1a74226358c8c7
2023 : event longer three : event longer                 : 53f1a74226358c8c7

Documentation

Overview

Package table provides a Writer that formats tab-separated data into aligned columns. Column widths account for ANSI escape sequences and grapheme cluster widths (via uniseg).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatLines

func FormatLines(lines []string)

FormatLines formats the provided lines in-place. Lines with a mismatched column count (relative to the first line) are ignored, matching the behavior of the original code (they remain unchanged).

func FormatReader

func FormatReader(r io.Reader) ([]string, error)

FormatReader reads tab-separated data and returns formatted lines in one pass

Types

type RowError

type RowError struct {
	Want, Got int
	Line      int
}

func (*RowError) Error

func (re *RowError) Error() string

type Writer

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

func New

func New(out io.Writer) *Writer

New constructs a new Writer that will emit formatted rows to out on Flush.

func (*Writer) Flush

func (w *Writer) Flush() error

Flush formats all buffered rows and writes them to out, then resets rows/widths. Returns the first error encountered during Write/addLine or any write error.

func (*Writer) SetFormat

func (w *Writer) SetFormat(pre, sep, suff string)

SetFormat controls formatting for the output including prefix, column separator, and suffix.

func (*Writer) Write

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

Write ingests bytes, splitting on '\n' (handles optional trailing '\r'). Parsed lines are buffered; call Flush to write formatted output to out. Column-count errors are recorded and surfaced on Flush; subsequent lines are still processed.

Directories

Path Synopsis
cmd
table command

Jump to

Keyboard shortcuts

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