show

package
v3.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2023 License: MIT Imports: 15 Imported by: 3

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

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 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) Buffer added in v3.1.1

func (b *Base) Buffer() *bytes.Buffer

Buffer get

func (*Base) Err added in v3.1.1

func (b *Base) Err() error

Err get

func (*Base) Format

func (b *Base) Format()

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) SetBuffer added in v3.1.1

func (b *Base) SetBuffer(buf *bytes.Buffer)

SetBuffer field

func (*Base) SetOutput

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

SetOutput for print message

func (*Base) String added in v3.1.1

func (b *Base) String() string

String format given data to string

type FormatterFace

type FormatterFace interface {
	Format()
}

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) IsKind added in v3.2.0

func (item *Item) IsKind(kind reflect.Kind) bool

IsKind check

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

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

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 PosFlag added in v3.1.1

type PosFlag = strutil.PosFlag

PosFlag type

const (
	PosLeft PosFlag = iota
	PosRight
	PosMiddle
)

some position constants

type PrettyJSON added in v3.1.1

type PrettyJSON struct {
	Base
}

PrettyJSON struct

func NewPrettyJSON added in v3.1.1

func NewPrettyJSON() *PrettyJSON

NewPrettyJSON instance

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

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