show

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package show provides some formatter tools for display data.

Index

Constants

View Source
const (
	// OK success exit code
	OK = 0
	// ERR error exit code
	ERR = 2
)

Variables

This section is empty.

Functions

func AList

func AList(title string, data any, fns ...ListOpFunc)

AList create a List instance and print. options see: Options

Usage:

show.AList("some info", map[string]string{"name": "tom"})

func ATitle

func ATitle(titleText string, fns ...title.OptionFunc)

ATitle create a Title instance and print. options see: TitleOption

func AnyData

func AnyData(title string, v any)

AnyData format and render any type data.

func Banner(content any, fns ...banner.OptionFunc)

Banner create a Banner instance and print. options see: banner.Options

func JSON

func JSON(v any, prefixAndIndent ...string) (int, error)

JSON print pretty JSON data.

It returns show.OK on success, or show.ERR with the marshal error when the value cannot be encoded as JSON.

func MList

func MList(listMap any, fns ...ListOpFunc)

MList show multi list data. options see: Options

Usage:

show.MList(data)
show.MList(data, func(opts *Options) {
	opts.LeftIndent = "    "
})

func NewBanner

func NewBanner(content any, fns ...banner.OptionFunc) *banner.Banner

NewBanner create a Banner instance. options see: banner.Options

func NewList

func NewList(title string, data any, fns ...ListOpFunc) *lists.List

NewList create a List instance. options see: Options

func NewLists

func NewLists(listMap any, fns ...ListOpFunc) *lists.Lists

NewLists create a Lists instance and print. options see: Options

func TabWriter

func TabWriter(rows []string) (*tabwriter.Writer, error)

TabWriter create. more please see: package text/tabwriter/example_test.go

Usage:

w := TabWriter([]string{
	"a\tb\tc\td\t.",
	"123\t12345\t1234567\t123456789\t."
})
w.Flush()

Types

type FormatterFace

type FormatterFace = showcom.Formatter

FormatterFace interface. for compatible

type ListItem added in v0.3.1

type ListItem = lists.Item

type ListItems added in v0.3.1

type ListItems = lists.Items

ListItems and item

type ListOpFunc

type ListOpFunc = lists.OptionFunc

type ListOption

type ListOption = lists.Options

ListOption alias for lists.Options. for compatible

type ListOptions added in v0.3.1

type ListOptions = lists.Options

type PrettyJSON

type PrettyJSON struct {
	showcom.Base

	Data        any
	Prefix      string
	Indent      string
	KeyStyle    string
	BoolStyle   string
	NumberStyle string
}

PrettyJSON struct

func NewPrettyJSON

func NewPrettyJSON(v ...any) *PrettyJSON

NewPrettyJSON create an instance.

func (*PrettyJSON) Format added in v0.3.1

func (pj *PrettyJSON) Format()

Format pretty format JSON with colors.

A marshal error is stored on pj.Err instead of panicking; callers such as JSON() read it back and surface it as an error.

type ShownFace

type ShownFace = showcom.ShownFace

ShownFace shown interface. for compatible

type Writer

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

Writer definition

func NewWriter

func NewWriter(output io.Writer) *Writer

NewWriter create a new writer

func (*Writer) Write

func (w *Writer) Write(p []byte) (n int, err error)

Write bytes message

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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