Documentation
¶
Overview ¶
Package show provides some formatter tools for display data.
Index ¶
- Constants
- Variables
- func AList(title string, data any, fns ...ListOpFunc)
- func Error(format string, v ...any) int
- func JSON(v any, prefixAndIndent ...string) int
- func MList(listMap any, fns ...ListOpFunc)
- func ResetOutput()
- func SetOutput(out io.Writer)
- func Success(format string, v ...any) int
- func TabWriter(rows []string) *tabwriter.Writer
- type Base
- type FormatterFace
- type Item
- type Items
- type List
- type ListOpFunc
- type ListOption
- type Lists
- func (ls *Lists) AddSublist(title string, data any) *Lists
- func (ls *Lists) Flush()
- func (ls *Lists) Format()
- func (ls *Lists) Print()
- func (ls *Lists) Println()
- func (ls *Lists) String() string
- func (ls *Lists) WithOptionFns(fns []ListOpFunc) *Lists
- func (ls *Lists) WithOptions(fns ...ListOpFunc) *Lists
- type PosFlag
- type PrettyJSON
- type ShownFace
- type Title
- type Writer
Constants ¶
View Source
const ( // OK success exit code OK = 0 // ERR error exit code ERR = 2 )
View Source
const ( // ItemMap parsed from map, struct ItemMap = "map" // ItemList parsed from array, slice ItemList = "list" )
Variables ¶
View Source
var Output io.Writer = os.Stdout
Output the global input out stream
Functions ¶
func AList ¶
func AList(title string, data any, fns ...ListOpFunc)
AList create a List instance and print.
Usage:
show.AList("some info", map[string]string{"name": "tom"})
func MList ¶
func MList(listMap any, fns ...ListOpFunc)
MList show multi list data.
Usage:
show.MList(data)
show.MList(data, func(opts *ListOption) {
opts.LeftIndent = " "
})
Types ¶
type Base ¶
type Base struct {
// contains filtered or unexported fields
}
Base formatter
type Item ¶
type Item struct {
// Val string
Key string
// contains filtered or unexported fields
}
Item definition
type Items ¶
type Items struct {
List []*Item
// contains filtered or unexported fields
}
Items definition
type List ¶
type List struct {
Base // use for internal
// options
Opts *ListOption
// contains filtered or unexported fields
}
List definition
String len:
len("你好"), len("hello"), len("hello你好") -> 6 5 11
func NewList ¶
func NewList(title string, data any, fns ...ListOpFunc) *List
NewList instance.
data allow type:
struct, slice, array, map
func (*List) WithOptionFns ¶ added in v3.1.0
func (l *List) WithOptionFns(fns []ListOpFunc) *List
WithOptionFns with options func
func (*List) WithOptions ¶
func (l *List) WithOptions(fns ...ListOpFunc) *List
WithOptions with options func
type ListOption ¶
type ListOption struct {
// IgnoreEmpty ignore empty value item
IgnoreEmpty bool
// UpperFirst upper first char for the item.value
UpperFirst bool
SepChar string // split key value
LeftIndent string
KeyWidth int // if not set, will be auto-detected.
KeyMinWidth int
KeyStyle string
ValueStyle string
TitleStyle string
}
ListOption definition
type Lists ¶
type Lists struct {
Base // use for internal
// options
Opts *ListOption
// contains filtered or unexported fields
}
Lists definition
func NewEmptyLists ¶ added in v3.2.2
func NewEmptyLists(fns ...ListOpFunc) *Lists
NewEmptyLists create empty lists
func NewLists ¶
func NewLists(mlist any, fns ...ListOpFunc) *Lists
NewLists create lists. allow: map[string]any, struct-ptr
func (*Lists) AddSublist ¶ added in v3.2.2
AddSublist with options func list
func (*Lists) WithOptionFns ¶ added in v3.1.0
func (ls *Lists) WithOptionFns(fns []ListOpFunc) *Lists
WithOptionFns with options func
func (*Lists) WithOptions ¶
func (ls *Lists) WithOptions(fns ...ListOpFunc) *Lists
WithOptions with options func list
type ShownFace ¶
type ShownFace interface {
// String data to string
String() string
// Print print current message
Print()
// Println print current message
Println()
}
ShownFace shown interface
type Title ¶
type Title struct {
Title string
Style string
Formatter func(t *Title) string
// Formatter IFormatter
Char rune
Width int
Indent int
Align PosFlag
ShowBorder bool
}
Title definition
Click to show internal directories.
Click to hide internal directories.