lists

package
v3.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ItemMap parsed from map, struct
	ItemMap = "map"
	// ItemList parsed from array, slice
	ItemList = "list"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Item

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

Item definition

func (*Item) IsArray

func (item *Item) IsArray() bool

IsArray get is array, slice

func (*Item) IsEmpty

func (item *Item) IsEmpty() bool

IsEmpty get value is empty: nil, empty string.

func (*Item) IsKind

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

IsKind check

func (*Item) Kind

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

Kind get

func (*Item) RftVal

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

RftVal get

func (*Item) ValString

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 an 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

func (*Items) Len

func (its *Items) Len() int

func (*Items) Less

func (its *Items) Less(i, j int) bool

func (*Items) Swap

func (its *Items) Swap(i, j int)

type List

type List struct {
	showcom.Base // use for internal
	// options
	Opts *Options
	// contains filtered or unexported fields
}

List definition. data allow type: struct, slice, array, map

String len:

len("你好"), len("hello"), len("hello你好") -> 6 5 11

func NewList

func NewList(title string, data any, fns ...OptionFunc) *List

NewList instance.

data type allow: 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) WithOptionFns

func (l *List) WithOptionFns(fns []OptionFunc) *List

WithOptionFns with options func

func (*List) WithOptions

func (l *List) WithOptions(fns ...OptionFunc) *List

WithOptions with options func

type ListOpFunc

type ListOpFunc = OptionFunc

type Lists

type Lists struct {
	showcom.Base // use for internal
	// options
	Opts *Options
	// contains filtered or unexported fields
}

Lists use for formatting and printing multi list data

func NewEmptyLists

func NewEmptyLists(fns ...OptionFunc) *Lists

NewEmptyLists create empty lists

func NewLists

func NewLists(mList any, fns ...OptionFunc) *Lists

NewLists create lists. allow: map[string]any, struct-ptr

func (*Lists) AddSublist

func (ls *Lists) AddSublist(title string, data any) *Lists

AddSublist with options func list

func (*Lists) Flush

func (ls *Lists) Flush()

Flush formatted message to console

func (*Lists) Format

func (ls *Lists) Format()

Format as string

func (*Lists) WithOptionFns

func (ls *Lists) WithOptionFns(fns []OptionFunc) *Lists

WithOptionFns with options func

func (*Lists) WithOptions

func (ls *Lists) WithOptions(fns ...OptionFunc) *Lists

WithOptions with an options func list

type OptionFunc

type OptionFunc func(opts *Options)

OptionFunc define

type Options

type Options struct {
	// IgnoreEmpty ignore empty value item. default: true
	IgnoreEmpty bool
	// UpperFirst upper first char for the item.value. default: false
	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
	// FilterFunc filter item.
	//  - return true to show item, otherwise hide item.
	FilterFunc func(item *Item) bool
}

Options for List, Lists

func NewOptions

func NewOptions() *Options

NewOptions instance

Jump to

Keyboard shortcuts

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