show

package
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2022 License: MIT Imports: 15 Imported by: 2

README

Show data

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

  • title

  • table

  • panel

  • section

  • padding

  • list

  • multi list

  • alert(block)

  • markdown

  • json

GoDoc

Please see https://pkg.go.dev/github.com/gookit/gcli/v3/show

Install

go get github.com/gookit/gcli/v3/show

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 (
	// Left position
	Left = iota
	Middle
	Right
)

some constants

Variables

View Source
var Output io.Writer = os.Stdout

Output the global input output 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 Error

func Error(format string, v ...any) int

Error tips message print

func JSON

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

JSON print pretty JSON data

func MList

func MList(listMap map[string]any, fns ...ListOpFunc)

MList show multi list data.

Usage:

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

func ResetOutput added in v3.1.0

func ResetOutput()

ResetOutput stream

func SetOutput added in v3.1.0

func SetOutput(out io.Writer)

SetOutput stream

func Success

func Success(format string, v ...any) int

Success tips message print

func TabWriter

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

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 Base

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

Base formatter

func (*Base) Format

func (b *Base) Format() string

Format given data to string

func (*Base) Print

func (b *Base) Print()

Print formatted message

func (*Base) Println

func (b *Base) Println()

Println formatted message and print newline

func (*Base) SetOutput

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

SetOutput for print message

type FormatterFace

type FormatterFace interface {
	Format() string
}

FormatterFace interface

type Item

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

Item definition

func (*Item) IsArray added in v3.0.2

func (item *Item) IsArray() bool

IsArray get is array, slice

func (*Item) IsEmpty added in v3.0.2

func (item *Item) IsEmpty() bool

IsEmpty get value is empty: nil, empty string.

func (*Item) Kind added in v3.0.2

func (item *Item) Kind() reflect.Kind

Kind get

func (*Item) RftVal added in v3.0.2

func (item *Item) RftVal() reflect.Value

RftVal get

func (*Item) ValString added in v3.0.2

func (item *Item) ValString() string

ValString get

type Items

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

Items definition

func NewItems

func NewItems(data any) *Items

NewItems create a Items for data.

func (*Items) Each

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

Each handle item in the items.List

func (*Items) ItemType

func (its *Items) ItemType() string

ItemType get

func (*Items) KeyMaxWidth

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 any, fns ...ListOpFunc) *List

NewList instance.

data allow type:

struct, slice, array, map

func (*List) Flush

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

func (l *List) Println()

Println formatted message with newline

func (*List) SetBuffer

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

SetBuffer field

func (*List) String

func (l *List) String() string

String returns formatted string

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 ListOpFunc added in v3.1.0

type ListOpFunc func(opts *ListOption)

ListOpFunc define

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 NewLists

func NewLists(listMap map[string]any, fns ...ListOpFunc) *Lists

NewLists create lists

func (*Lists) Flush

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

func (ls *Lists) Println()

Println formatted message with newline

func (*Lists) String

func (ls *Lists) String() string

String returns formatted string

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 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 []any
	// 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

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) Flush

func (w *Writer) Flush() error

Flush data to io.Writer

func (*Writer) Print

func (w *Writer) Print()

Print data to io.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