colors

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(data []byte) ([]byte, error)

Format JSON string with default options.

func GetBackground

func GetBackground(s string) ui.Attribute

GetBackground sets the background color for the ui.

func Marshal

func Marshal(v interface{}) ([]byte, error)

Marshal JSON data with default options.

Types

type Colorer

type Colorer func(string) string

Colorer wraps a string with ansi color escape codes.

func Get

func Get(s string) Colorer

Get fetches the colorer func for the given color

type Formatter

type Formatter struct {
	// JSON key color. Default is `color.New(color.FgBlue, color.Bold)`.
	KeyColor *color.Color

	// JSON string value color. Default is `color.New(color.FgGreen, color.Bold)`.
	StringColor *color.Color

	// JSON boolean value color. Default is `color.New(color.FgYellow, color.Bold)`.
	BoolColor *color.Color

	// JSON number value color. Default is `color.New(color.FgCyan, color.Bold)`.
	NumberColor *color.Color

	// JSON null value color. Default is `color.New(color.FgBlack, color.Bold)`.
	NullColor *color.Color

	// Max length of JSON string value. When the value is 1 and over, string is truncated to length of the value. Default is 0 (not truncated).
	StringMaxLength int

	// Boolean to disable color. Default is false.
	DisabledColor bool

	// Indent space number. Default is 2.
	Indent int
}

Formatter is a struct to format JSON data. `color` is github.com/fatih/color: https://github.com/fatih/color

func NewFormatter

func NewFormatter() *Formatter

NewFormatter returns a new formatter with following default values.

func (*Formatter) Format

func (f *Formatter) Format(data []byte) ([]byte, error)

Format creates a colorful JSON string.

func (*Formatter) Marshal

func (f *Formatter) Marshal(v interface{}) ([]byte, error)

Marshal marshals and formats JSON data.

Jump to

Keyboard shortcuts

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