tablewrappers

package
v0.0.0-...-6d6105d Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package tablewrappers exposes different ways to wrap text under display width constraint.

Index

Constants

This section is empty.

Variables

View Source
var (
	BlankSplitter = unicode.IsSpace
	PunctSplitter = unicode.IsPunct
	LineSplitter  = func(r rune) bool { return r == '\n' || r == '\r' }
	WordBreaker   = func(r rune) bool { return !unicode.IsLetter(r) && !unicode.IsDigit(r) }
)

Functions

func CellWidth

func CellWidth(lines []string) int

CellWidth determines the displayed width of a multi-lines cell.

func DisplayWidth

func DisplayWidth(str string) int

DisplayWidth yields the size of a string when rendered on a terminal.

ANSI escape sequences are discared.

Types

type DefaultCellWrapper

type DefaultCellWrapper struct {
	*DefaultWrapper
	// contains filtered or unexported fields
}

DefaultCellWrapper wraps the content of a table with predefined constraints on column widths.

func NewDefaultCellWrapper

func NewDefaultCellWrapper(matrix [][]string, colMaxWidth map[int]int, opts ...Option) *DefaultCellWrapper

func (*DefaultCellWrapper) WrapCell

func (w *DefaultCellWrapper) WrapCell(row, col int) []string

type DefaultWrapper

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

func NewDefault

func NewDefault(opts ...Option) *DefaultWrapper

New builds a new default wrapper.

func (*DefaultWrapper) WrapString

func (w *DefaultWrapper) WrapString(s string, limit int) []string

Wrap input string s into a paragraph of lines of limited length, with minimal raggedness.

type Option

type Option func(*wrapOptions)

func WithWrapStrictMaxWidth

func WithWrapStrictMaxWidth(enabled bool) Option

func WithWrapWordSplitters

func WithWrapWordSplitters(splitters ...Splitter) Option

WithWrapWordSplitters defines a wrapper's word boundaries split functions.

The default is to break words on IsSpace runes and new-line/carriage return.

type RowWrapper

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

RowWrapper wraps the content of a table with a single constraint on the table width.

func NewRowWrapper

func NewRowWrapper(matrix [][]string, rowWidthLimit int, opts ...Option) *RowWrapper

TODO: introduce colMaxWidth local limits for backward-compatible layout

func (*RowWrapper) WrapCell

func (w *RowWrapper) WrapCell(row, col int) []string

type Splitter

type Splitter func(rune) bool

Jump to

Keyboard shortcuts

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