neat

package module
v1.3.13 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2024 License: MIT Imports: 15 Imported by: 13

README

neat

License Go Report Card Tests Codecov PkgGoDev Release GitHub go.mod Go version

Go package with convenience functions to create neat strings like colored YAML output.

Documentation

Overview

Package neat provides convenience functions to create neat strings like colored YAML output (YAML Marshaller that supports true color output) or nicely spaced tables for the terminal.

The `ToYAML` function returns neat looking YAML string output using text highlighting with emphasis, colors, and indent helper guide lines to create pleasing and easy to read YAML.

The `Table` function returns a neat looking table based on a two-dimensional array which is rendered with spaces to have well aligned columns.

Index

Constants

This section is empty.

Variables

View Source
var DefaultColorSchema = map[string]colorful.Color{
	"documentStart":      bunt.LightSlateGray,
	"keyColor":           bunt.IndianRed,
	"indentLineColor":    {R: 0.14, G: 0.14, B: 0.14},
	"scalarDefaultColor": bunt.PaleGreen,
	"boolColor":          bunt.Moccasin,
	"floatColor":         bunt.Orange,
	"intColor":           bunt.MediumPurple,
	"multiLineTextColor": bunt.Aquamarine,
	"nullColor":          bunt.DarkOrange,
	"binaryColor":        bunt.Aqua,
	"emptyStructures":    bunt.PaleGoldenrod,
	"commentColor":       bunt.DimGray,
	"anchorColor":        bunt.CornflowerBlue,
}

DefaultColorSchema is a prepared usable color schema for the neat output processor which is loosly based upon the colors used by Atom

Functions

func Box added in v1.0.3

func Box(out io.Writer, headline string, content io.Reader, opts ...BoxStyle)

Box writes the provided content in a simple box shape to given writer

func ContentBox added in v1.0.2

func ContentBox(headline string, content string, opts ...BoxStyle) string

ContentBox creates a string for the terminal where content is printed inside a simple box shape.

func FprintError added in v1.0.3

func FprintError(w io.Writer, err error)

FprintError prints the provided error to the provided writer

func PrintError added in v1.0.3

func PrintError(err error)

PrintError prints the provided error to stdout

func SprintError added in v1.0.3

func SprintError(err error) string

SprintError prints the provided error as a string

func Table

func Table(table [][]string, tableOptions ...TableOption) (string, error)

Table renders a string with a well spaced and aligned table output

func ToJSONString

func ToJSONString(obj interface{}) (string, error)

ToJSONString marshals the provided object into JSON with text decorations and is basically just a convenience function to create the output processor and call its `ToJSON` function.

func ToYAMLString

func ToYAMLString(obj interface{}) (string, error)

ToYAMLString marshals the provided object into YAML with text decorations and is basically just a convenience function to create the output processor and call its `ToYAML` function.

Types

type Alignment

type Alignment int

Alignment defines the text alignment option for a table cell.

const (
	Left Alignment = iota
	Right
	Center
)

Table cells support three types of alignment: left, right, center.

type BoxStyle added in v1.0.2

type BoxStyle func(*boxOptions)

BoxStyle represents a styling option for a content box

func ContentColor added in v1.0.2

func ContentColor(color colorful.Color) BoxStyle

ContentColor sets the color of the content text

func HeadlineColor added in v1.0.2

func HeadlineColor(color colorful.Color) BoxStyle

HeadlineColor sets the color of the headline text

func HeadlineStyle added in v1.0.3

func HeadlineStyle(style bunt.StyleOption) BoxStyle

HeadlineStyle sets the style to be used for the headline text

func NoFinalEndOfLine added in v1.0.4

func NoFinalEndOfLine() BoxStyle

NoFinalEndOfLine specifies that the rendering does not add a closing linefeed

func NoLineWrap added in v1.3.0

func NoLineWrap() BoxStyle

NoLineWrap disables line wrapping in the content box

type ColumnIndexIsOutOfBoundsError

type ColumnIndexIsOutOfBoundsError struct {
	ColumnIdx int
}

ColumnIndexIsOutOfBoundsError is used to describe that a provided column index is out of bounds

func (*ColumnIndexIsOutOfBoundsError) Error

type EmptyTableError

type EmptyTableError struct {
}

EmptyTableError is used to describe that the input table was either nil, or empty.

func (*EmptyTableError) Error

func (e *EmptyTableError) Error() string

type ImbalancedTableError

type ImbalancedTableError struct {
}

ImbalancedTableError is used to describe that not all rows have the same number of columns

func (*ImbalancedTableError) Error

func (e *ImbalancedTableError) Error() string

type OutputProcessor

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

OutputProcessor provides the functionality to output neat YAML strings using colors and text emphasis

func NewOutputProcessor

func NewOutputProcessor(useIndentLines bool, boldKeys bool, colorSchema *map[string]colorful.Color) *OutputProcessor

NewOutputProcessor creates a new output processor including the required internals using the provided preferences

func (*OutputProcessor) ToCompactJSON

func (p *OutputProcessor) ToCompactJSON(obj interface{}) (string, error)

ToCompactJSON processed the provided input object and tries to create a as compact as possible output

func (*OutputProcessor) ToJSON

func (p *OutputProcessor) ToJSON(obj interface{}) (string, error)

ToJSON processes the provided input object and tries to neatly output it as human readable JSON honoring the preferences provided to the output processor

func (*OutputProcessor) ToYAML

func (p *OutputProcessor) ToYAML(obj interface{}) (string, error)

ToYAML processes the provided input object and tries to neatly output it as human readable YAML honoring the preferences provided to the output processor

type RowLengthExceedsDesiredWidthError

type RowLengthExceedsDesiredWidthError struct {
}

RowLengthExceedsDesiredWidthError is used to describe that the table cannot be rendered, because at least one row exceeds the desired width

func (*RowLengthExceedsDesiredWidthError) Error

type TableOption

type TableOption func(*options)

TableOption defines options/settings for tables.

func AlignCenter

func AlignCenter(cols ...int) TableOption

AlignCenter sets alignment to center for the given columns (referenced by index)

func AlignRight

func AlignRight(cols ...int) TableOption

AlignRight sets alignment to right for the given columns (referenced by index)

func CustomSeparator

func CustomSeparator(separator string) TableOption

CustomSeparator set a custom separator string (other than the default single space)

func DesiredWidth

func DesiredWidth(width int) TableOption

DesiredWidth sets the desired width of the table

func LimitRows added in v1.0.5

func LimitRows(limit int) TableOption

LimitRows sets a limit at which point the table is truncated

func OmitLinefeedAtTableEnd added in v1.0.5

func OmitLinefeedAtTableEnd() TableOption

OmitLinefeedAtTableEnd tells the table renderer to not add a final linefeed

func VertialBarSeparator

func VertialBarSeparator() TableOption

VertialBarSeparator sets a solid veritcal bar as the column separator.

Jump to

Keyboard shortcuts

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