Documentation
¶
Overview ¶
Package show provides some formatter tools for display data.
Index ¶
- Constants
- func AList(title string, data interface{}, fn func(opts *ListOption))
- func Error(format string, v ...interface{}) int
- func JSON(v interface{}, settings ...string) int
- func MList(listMap map[string]interface{}, fn func(opts *ListOption))
- func Success(format string, v ...interface{}) int
- func TabWriter(outTo io.Writer, rows []string) *tabwriter.Writer
- type Base
- type FormatterFace
- type Item
- type Items
- type List
- type ListOption
- type Lists
- type ShownFace
- type Table
- 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" )
View Source
const ( // position Left = iota Middle Right )
some constants
Variables ¶
This section is empty.
Functions ¶
func AList ¶
func AList(title string, data interface{}, fn func(opts *ListOption))
AList create a List instance and print. Usage:
show.AList("some info", map[string]string{"name": "tom"}, nil)
func MList ¶
func MList(listMap map[string]interface{}, fn func(opts *ListOption))
MList show multi list data. Usage:
show.MList(data, nil)
show.MList(data, func(opts *ListOption) {
opts.LeftIndent = " "
})
Types ¶
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 (*List) WithOptions ¶
func (l *List) WithOptions(fn func(opts *ListOption)) *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 auto detect.
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 (*Lists) WithOptions ¶
func (ls *Lists) WithOptions(fn func(opts *ListOption)) *Lists
WithOptions with options func
type ShownFace ¶
type ShownFace interface {
// data to string
String() string
// print current message
Print()
// print current message
Println()
}
ShownFace shown interface
type Table ¶
type Table struct {
Base // use for internal
// Title for the table
Title string
// Cols the table head col data
Cols []string
// Rows table data rows
Rows []interface{}
// options ...
// HasBorder show border line
HasBorder bool
// RowBorder show row border
RowBorder bool
// HeadBorder show head border
HeadBorder bool
// WrapBorder wrap border for table
WrapBorder bool
}
Table a cli Table show
type Title ¶
type Title struct {
Title string
Style string
Formatter func(t *Title) string
// Formatter IFormatter
Char rune
Width int
Indent int
Position int
ShowBorder bool
}
Title definition
Click to show internal directories.
Click to hide internal directories.