iofmt

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package iofmt provides utilities for formatting and outputting structured data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatToJSON

func FormatToJSON(w io.Writer, v any, colorEnabled bool) error

FormatToJSON formats the given data in JSON format.

func FormatToTable

func FormatToTable(io *terminal.IO, l int, header, footer HeaderBuilderFunc, contentRow RowBuilderFunc) error

FormatToTable formats in Table format using the given BuilderFunc's. Header and footer builder functions are optional. The length of the slice must be given.

Types

type Format

type Format uint8

Format is an output format.

const (
	// Table formats output in tabular style.
	Table Format = iota + 1 // table
	// JSON formats output as one or more JSON objects.
	JSON // json
)

func FormatFromString

func FormatFromString(s string) (Format, error)

FormatFromString parses a supported Format from its string representation.

func Formats

func Formats() []Format

Formats returns all supported formats.

func (Format) String

func (i Format) String() string

type HeaderBuilderFunc

type HeaderBuilderFunc func(io.Writer, TableRowBuilder)

HeaderBuilderFunc allows building of a tables header by providing a TableRowBuilder and the raw io.Writer for using generic formatting functions like fmt.Fprintf().

type RowBuilderFunc

type RowBuilderFunc func(TableRowBuilder, int)

RowBuilderFunc allows building of a tables content row by providing a TableRowBuilder and the id of the record to format.

type TableRowBuilder

type TableRowBuilder interface {
	// AddField adds a field with the given string to the row. If given, the
	// ColorFunc will be used to colorize the resulting field text.
	AddField(string, terminal.ColorFunc)
}

TableRowBuilder provides methods for building table rows. It is a sub-interface of terminal.TablePrinter.

Jump to

Keyboard shortcuts

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