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 ¶
- Variables
- func Box(out io.Writer, headline string, content io.Reader, opts ...BoxStyle)
- func ContentBox(headline string, content string, opts ...BoxStyle) string
- func FprintError(w io.Writer, err error)
- func PrintError(err error)
- func SprintError(err error) string
- func Table(table [][]string, tableOptions ...TableOption) (string, error)
- func ToJSONString(obj interface{}) (string, error)
- func ToYAMLString(obj interface{}) (string, error)
- type Alignment
- type BoxStyle
- type ColumnIndexIsOutOfBoundsError
- type EmptyTableError
- type ImbalancedTableError
- type OutputProcessor
- type RowLengthExceedsDesiredWidthError
- type TableOption
Constants ¶
This section is empty.
Variables ¶
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 ContentBox ¶ added in v1.0.2
ContentBox creates a string for the terminal where content is printed inside a simple box shape.
func FprintError ¶ added in v1.0.3
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
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 ¶
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 ¶
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 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
ContentColor sets the color of the content text
func HeadlineColor ¶ added in v1.0.2
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 ¶
func (e *ColumnIndexIsOutOfBoundsError) Error() string
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 ¶
func (e *RowLengthExceedsDesiredWidthError) Error() string
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.