func (m *SpanWriter) Print(s Span) {
	m.contents = append(m.contents, s)
}
Print adds a new span to this SpanWriter.
package pretty
import (
	"bytes"
	"fmt"
	"io"
	"github.com/fatih/color"
)
type Span interface {
	VisualLength() int
	WriteTo(io.Writer) error
}
type Table struct {
	Sizing *TableCalculator
	cellsByRow [][]Span
	colSizes   []int
}
func (t *Table) StartRow() {
	t.cellsByRow = append(t.cellsByRow, []Span(nil))
}
func (t *Table) EndRow() {
	lastRow := t.cellsByRow[len(t.cellsByRow)-1]
	sizes := make([]int, len(lastRow))
	for i, cell := range lastRow {
		sizes[i] = cell.VisualLength()
	}
	t.Sizing.AddRowSizes(sizes...)
}
func (t *Table) Column(contents Span) {
	currentRowInd := len(t.cellsByRow) - 1
	t.cellsByRow[currentRowInd] = append(t.cellsByRow[currentRowInd], contents)
}
func (t *Table) SkipRow(contents Span) {
	t.cellsByRow = append(t.cellsByRow, []Span{contents})
}
func (t *Table) WriteTo(out io.Writer) error {
	if t.colSizes == nil {
		t.colSizes = t.Sizing.ColumnWidths()
	}
	for _, cells := range t.cellsByRow {
		currentPosition := 0
		for colInd, cell := range cells {
			colSize := t.colSizes[colInd]
			diff := colSize - cell.VisualLength()
			if err := cell.WriteTo(out); err != nil {
				return err
			}
			if diff > 0 {
				if err := writePadding(out, columnPadding, diff); err != nil {
					return err
				}
			}
			currentPosition += colSize
		}
		if _, err := fmt.Fprint(out, "\n"); err != nil {
			return err
		}
	}
	return nil
}
func (t *Table) VisualLength() int {
	if t.colSizes == nil {
		t.colSizes = t.Sizing.ColumnWidths()
	}
	res := 0
	for _, colSize := range t.colSizes {
		res += colSize
	}
	return res
}
type Text string
func (t Text) VisualLength() int { return len(t) }
func (t Text) WriteTo(w io.Writer) error {
	_, err := w.Write([]byte(t))
	return err
}
type indented struct {
	Amount  int
	Content Span
}
func (i *indented) VisualLength() int { return i.Content.VisualLength() }
func (i *indented) WriteTo(w io.Writer) error {
	var out bytes.Buffer
	if err := i.Content.WriteTo(&out); err != nil {
		return err
	}
	lines := bytes.Split(out.Bytes(), []byte("\n"))
	for lineInd, line := range lines {
		if lineInd != 0 {
			if _, err := w.Write([]byte("\n")); err != nil {
				return err
			}
		}
		if len(line) == 0 {
			continue
		}
		if err := writePadding(w, indentPadding, i.Amount); err != nil {
			return err
		}
		if _, err := w.Write(line); err != nil {
			return err
		}
	}
	return nil
}
func Indented(amt int, content Span) Span {
	return &indented{Amount: amt, Content: content}
}
type fromWriter struct {
	cache      []byte
	cacheError error
	run        func(io.Writer) error
}
func (f *fromWriter) VisualLength() int {
	if f.cache == nil {
		var buf bytes.Buffer
		if err := f.run(&buf); err != nil {
			f.cacheError = err
		}
		f.cache = buf.Bytes()
	}
	return len(f.cache)
}
func (f *fromWriter) WriteTo(w io.Writer) error {
	if f.cache != nil {
		if f.cacheError != nil {
			return f.cacheError
		}
		_, err := w.Write(f.cache)
		return err
	}
	return f.run(w)
}
func FromWriter(run func(io.Writer) error) Span {
	return &fromWriter{run: run}
}
type Decoration color.Color
func (d Decoration) Containing(contents Span) Span {
	return &decorated{
		Contents:   contents,
		Attributes: color.Color(d),
	}
}
type decorated struct {
	Contents   Span
	Attributes color.Color
}
func (d *decorated) VisualLength() int { return d.Contents.VisualLength() }
func (d *decorated) WriteTo(w io.Writer) error {
	oldOut := color.Output
	color.Output = w
	defer func() { color.Output = oldOut }()
	d.Attributes.Set()
	defer color.Unset()
	return d.Contents.WriteTo(w)
}
type SpanWriter struct {
	contents []Span
}
func (m *SpanWriter) VisualLength() int {
	res := 0
	for _, span := range m.contents {
		res += span.VisualLength()
	}
	return res
}
func (m *SpanWriter) WriteTo(w io.Writer) error {
	for _, span := range m.contents {
		if err := span.WriteTo(w); err != nil {
			return err
		}
	}
	return nil
}