show

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2019 License: MIT Imports: 13 Imported by: 0

README

Format message

contains section, panel, padding, helpPanel, table, tree, title, list, multiList

  • title

  • table

  • panel

  • section

  • padding

  • list

  • multi list

  • alert(block)

  • markdown

  • json

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
)
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 added in v1.1.2

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 Error

func Error(format string, v ...interface{}) int

Error tips message print

func JSON

func JSON(v interface{}, settings ...string) int

JSON print pretty JSON data

func MList added in v1.1.2

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 = "    "
})

func Success added in v1.1.2

func Success(format string, v ...interface{}) int

Success tips message print

func TabWriter added in v1.2.1

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

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

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

Types

type Base added in v1.1.2

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

Base formatter

func (*Base) Format added in v1.1.2

func (b *Base) Format() string

Format given data to string

func (*Base) Print added in v1.1.2

func (b *Base) Print()

Print formatted message

func (*Base) Println added in v1.1.2

func (b *Base) Println()

Println formatted message and print newline

func (*Base) SetOutput added in v1.2.1

func (b *Base) SetOutput(output io.Writer)

SetOutput for print message

type FormatterFace added in v1.1.2

type FormatterFace interface {
	Format() string
}

FormatterFace interface

type Item added in v1.2.1

type Item struct {
	Key string
	Val string
	// contains filtered or unexported fields
}

Item definition

type Items added in v1.2.1

type Items struct {
	List []*Item
	// contains filtered or unexported fields
}

Items definition

func NewItems added in v1.2.1

func NewItems(data interface{}) *Items

NewItems create a Items for data.

func (*Items) Each added in v1.2.1

func (its *Items) Each(fn func(item *Item))

Each handle item in the items.List

func (*Items) ItemType added in v1.2.1

func (its *Items) ItemType() string

ItemType get

func (*Items) KeyMaxWidth added in v1.2.1

func (its *Items) KeyMaxWidth(userSetting int) int

KeyMaxWidth get

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 interface{}) *List

NewList instance

func (*List) Flush added in v1.2.1

func (l *List) Flush()

Flush formatted message to console

func (*List) Format

func (l *List) Format() string

Format as string

func (*List) Print

func (l *List) Print()

Print formatted message

func (*List) Println added in v1.2.1

func (l *List) Println()

Println formatted message with newline

func (*List) SetBuffer added in v1.2.1

func (l *List) SetBuffer(buffer *bytes.Buffer)

SetBuffer field

func (*List) String

func (l *List) String() string

String returns formatted string

func (*List) WithOptions added in v1.2.1

func (l *List) WithOptions(fn func(opts *ListOption)) *List

WithOptions with options func

type ListOption added in v1.2.1

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 NewLists

func NewLists(listMap map[string]interface{}) *Lists

NewLists create lists

func (*Lists) Flush added in v1.2.1

func (ls *Lists) Flush()

Flush formatted message to console

func (*Lists) Format

func (ls *Lists) Format() string

Format as string

func (*Lists) Print

func (ls *Lists) Print()

Print formatted message

func (*Lists) Println added in v1.2.1

func (ls *Lists) Println()

Println formatted message with newline

func (*Lists) String

func (ls *Lists) String() string

String returns formatted string

func (*Lists) WithOptions added in v1.2.1

func (ls *Lists) WithOptions(fn func(opts *ListOption)) *Lists

WithOptions with options func

type ShownFace added in v1.1.2

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

func NewTable

func NewTable(title string) *Table

NewTable create table

func (*Table) Format

func (t *Table) Format() string

Format as string

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

func NewTitle

func NewTitle(title string) *Title

NewTitle instance

type Writer added in v1.2.1

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

Writer definition

func NewWriter added in v1.2.1

func NewWriter(output io.Writer) *Writer

NewWriter create a new writer

func (*Writer) Flush added in v1.2.1

func (w *Writer) Flush() error

Flush data to io.Writer

func (*Writer) Print added in v1.2.1

func (w *Writer) Print()

Print data to io.Writer

func (*Writer) Write added in v1.2.1

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

Write

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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