fwt

package
v0.40.4 Latest Latest
Warning

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

Go to latest
Published: May 19, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrColumnTooLong = errors.New("column width exceeded maximum width for column and TooLongBehavior is ErrorWhenTooLong")

ErrColumnTooLong is returned when the width exceeds the maximum

View Source
var ErrRowCountMismatch = errors.New("number of columns passed to formatter does not match expected count")

ErrRowCountMismatch is returned when the number of columns does not match the expected count

Functions

func StringWidth

func StringWidth(text string) (width int)

StringWidth returns the number of horizontal cells needed to print the given text. It splits the text into its grapheme clusters, calculates each cluster's width, and adds them up to a total.

Types

type AutoSizingFWTTransformer

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

AutoSizingFWTTransformer samples rows to automatically determine maximum column widths to provide to FWTTransformer.

func NewAutoSizingFWTTransformer

func NewAutoSizingFWTTransformer(sch schema.Schema, tooLngBhv TooLongBehavior, numSamples int) *AutoSizingFWTTransformer

func (*AutoSizingFWTTransformer) TransformToFWT

func (asTr *AutoSizingFWTTransformer) TransformToFWT(inChan <-chan pipeline.RowWithProps, outChan chan<- pipeline.RowWithProps, badRowChan chan<- *pipeline.TransformRowFailure, stopChan <-chan struct{})

type FWTTransformer

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

FWTTransformer transforms columns to be of fixed width.

func NewFWTTransformer

func NewFWTTransformer(sch schema.Schema, fwf FixedWidthFormatter) *FWTTransformer

NewFWTTransform creates a new FWTTransformer from a FWTSchema and a TooLongBehavior

func (*FWTTransformer) Transform

func (fwtTr *FWTTransformer) Transform(r row.Row, props pipeline.ReadableMap) ([]*pipeline.TransformedRowResult, string)

Transform takes in a row and transforms it so that it's columns are of the correct width.

type FixedWidthFormatter

type FixedWidthFormatter struct {
	Widths []int

	TotalWidth int
	// contains filtered or unexported fields
}

FixedWidthFormatter is a utility class for taking a row and generating fixed with output

func FixedWidthFormatterForSchema

func FixedWidthFormatterForSchema(sch schema.Schema, tooLongBhv TooLongBehavior, tagToPrintWidth map[uint64]int, tagToMaxRunes map[uint64]int) FixedWidthFormatter

FixedWidthFormatterForSchema takes a schema and creates a FixedWidthFormatter based on the columns within that schema

func NewFixedWidthFormatter

func NewFixedWidthFormatter(tooLongBhv TooLongBehavior, printWidths []int, maxRunes []int) FixedWidthFormatter

NewFixedWidthFormatter returns a new fixed width formatter

func (FixedWidthFormatter) Format

func (fwf FixedWidthFormatter) Format(cols []string) ([]string, error)

Format takes an array of columns strings and makes each column the approriate width

func (FixedWidthFormatter) FormatColumn

func (fwf FixedWidthFormatter) FormatColumn(colStr string, colIdx int) (string, error)

FormatColumn takes a column string and a column index and returns a column string that is the appropriate width for that column

func (FixedWidthFormatter) FormatRow

func (fwf FixedWidthFormatter) FormatRow(r row.Row, sch schema.Schema) (row.Row, error)

FormatRow takes a row and converts it so that the columns are appropriately sized

type TooLongBehavior

type TooLongBehavior int

TooLongBehavior determines how the FWTTransformer should behave when it encounters a column that is longer than what it expected

const (
	// ErrorWhenTooLong treats each row containing a column that is longer than expected as a bad row
	ErrorWhenTooLong TooLongBehavior = iota
	//SkipRowWhenTooLong caller can use ErrorWhenTooLong and ignore rows that return ErrColumnTooLong
	// TruncateWhenTooLong will cut off the end of columns that are too long
	TruncateWhenTooLong
	// HashFillWhenTooLong will result in ######### being printed in place of the columns that are longer than expected.
	HashFillWhenTooLong
	// PrintAllWhenTooLong will print the entire column for every row.  When this happens results will not be valid
	// fixed width text files
	PrintAllWhenTooLong
)

Jump to

Keyboard shortcuts

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