table

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Align 内容方位

  • 以 AlignLeft, AlignCenter, AlignTopLeft 为例,表示在单元格内容分别是置于左侧,和顶部左侧 = eg. 当单元格高度为4, 实际内容高度为2, 以 AlignLeft 则居左为 [ ] [ align 2 ] [ align 3 ] [ ] = AlignCenter [ ] [ align 2 ] [ align 3 ] [ ] = AlignTopLeft [ align 2 ] [ align 3 ] [ ] [ ]
  • Align.Repeat(in string, w int) string 函数 = 仅支持针对left, center, rights三个方位的拓展, in 是输入, w是实际所需长度, 若

Cell 单元格

  • 目前实现了以下几种 Cell, 均基于BaseCell = BaseCell

  • 基本单元格

  • 只有最基本的功能

  • EmptyCell

  • 空单元格

  • 没有内容的单元格

  • InterfaceCell

  • 空接口单元格

  • 用于接纳任意类型的单元格

  • MergeCell

  • 合并单元格

  • 可以跨多行多列的单元格

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultContour default
	/*
		┌──────────┬──────┐
		|    A     |  B   |
		├──────────┼──────┤
		|   112    |  2   |
		|    1     | 223  |
		|    4     |  5   |
		| 72312312 | 2328 |
		└──────────┴──────┘
	*/
	DefaultContour = Contour{
		T: "─", R: "|",
		L: "|", D: "─",
		TL: "┌", TR: "┐",
		DL: "└", DR: "┘",
		TI: "┬", DI: "┴",
		LI: "├", RI: "┤",
		I: "┼", CH: "|", CV: "─",
	}

	// EmptyContour is empty
	/*
	     A        B

	    112       2
	     1       223
	     4        5
	  72312312   2328
	*/
	EmptyContour = Contour{
		T: " ", R: " ",
		L: " ", D: " ",
		TL: " ", TR: " ",
		DL: " ", DR: " ",
		TI: " ", DI: " ",
		LI: " ", RI: " ",
		I: " ", CH: " ", CV: " ",
	}

	// MariaDBContour like to mysql
	/*
		+----------+------+
		|    A     |  B   |
		+----------+------+
		|   112    |  2   |
		|    1     | 223  |
		|    4     |  5   |
		| 72312312 | 2328 |
		+----------+------+
	*/
	MariaDBContour = Contour{
		T: "-", R: "|",
		L: "|", D: "-",
		TL: "+", TR: "+",
		DL: "+", DR: "+",
		TI: "+", DI: "+",
		LI: "+", RI: "+",
		I: "+", CH: "|", CV: "-",
	}
)
View Source
var DefaultColorStylesClient = &defaultColorStyles{
	Enable:          true,
	defaultColor:    nil,
	typeTo:          map[reflect.Kind]color.Color{},
	customizeTypeTo: map[string]color.Color{},
}
View Source
var DefaultOption = &Option{
	ExpendID: true,
	Align:    AlignCenter,
	Contour:  DefaultContour,
}

Functions

func DefaultTransformContentByColor

func DefaultTransformContentByColor(in interface{}) interface{}
	DefaultTransformContentByColor
	中文:
		*依据不同类型进行颜色的区分输出,输出最终格式为string*
		目前使用的颜色只支持linux和macOs系统, windows系统需要自己参考定义好一个颜色引擎
		+ 调用优先级: CustomizeTypeTo > typeTo > defaultColor
			- Enable: 启用与不启用
			- typeTo: 是依据对不同的【基础数据类型】进行颜色输出时的处理
			- customizeTypeTo: 依据输入的数据结构反射出的结构进行输出颜色
	en:
		*Differentiate the output of colors according to different types,
         and the final output format is string*
		The currently used colors only support linux and `macOS` systems, `windows`system needs refer to define a color engine by itself
		+ call priority: CustomizeTypeTo > typeTo > defaultColor
			- Enable: enable and disable
			- typeTo: it is based on the processing of color output for different [basic data types]
			- customizeTypeTo: output color according to the structure reflected from the input data structure
	func:
		DisEnableDefaultColor
			- 禁用
		EnableDefaultColor
			- 启用
		SetDefaultColor
			- 设置该类型数据渲染为该颜色
		DeleteDefaultColor
			- 删除输入同类型的颜色

func DefaultTransformContentByTime

func DefaultTransformContentByTime(in interface{}) interface{}

func DeleteDefaultColor

func DeleteDefaultColor(in ...interface{})

func DisEnableDefaultColor

func DisEnableDefaultColor()

func EnableDefaultColor

func EnableDefaultColor()

func SetDefaultColor

func SetDefaultColor(cor color.Color, in ...interface{})

Types

type Align

type Align int
const (
	AlignLeft Align = iota
	AlignCenter
	AlignRight

	AlignTopLeft
	AlignTopCenter
	AlignTopRight

	AlignBottomLeft
	AlignBottomCenter
	AlignBottomRight
)

func (Align) Repeat

func (a Align) Repeat(in string, count uint) string

func (Align) Repeats

func (a Align) Repeats(in []string, count uint) []string

type BaseCell

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

func NewBaseCell

func NewBaseCell(ag Align, in []string) *BaseCell

func (*BaseCell) Add

func (c *BaseCell) Add(in ...string)

func (*BaseCell) Align

func (c *BaseCell) Align() Align

func (*BaseCell) Height

func (c *BaseCell) Height() uint

func (*BaseCell) Line

func (c *BaseCell) Line(idx uint) string

func (*BaseCell) Lines

func (c *BaseCell) Lines() (out []string)

func (*BaseCell) SetHeight

func (c *BaseCell) SetHeight(h uint)

func (*BaseCell) SetWidth

func (c *BaseCell) SetWidth(w uint)

func (*BaseCell) Width

func (c *BaseCell) Width() uint

type Cell

type Cell interface {
	Width() uint
	Height() uint
	SetWidth(uint)
	SetHeight(uint)
	Align() Align
	Add(...string)
	Line(uint) string
	Lines() []string
}

type Contour

type Contour struct {
	// border like standard 8 azimuth
	//  ┌ ─ ┐       '┌' TL  '─' T  '┐' TR
	//  |   |   ->  '|' L          '|' R
	//  └ - ┘       '└  DL  '-' D  '┘' DR
	T, R, L, D     string
	TL, TR, DL, DR string
	// top | down intersection
	// for example, the two points highlighted above are the intersection points
	//  ┌ '┬' ─ ┐     '┬' TI -> top intersection
	//  |       | ->
	//  └ '┴' - ┘     '┴' DI -> down intersection
	TI, DI string
	// left | right intersection
	// for example, the two points highlighted above are the intersection points
	//   ┌ ─ ┐
	// 	'├'  |     '├' LI -> left intersection
	//   |  '┤'    '┤' RI -> right intersection
	//   └ - ┘
	LI, RI string
	// intersection location
	// ┌ ─ ┬ ─ ┬ - ┐
	// | - | - |'-'|  '-' CV -> center vertical
	// |  '|'  |   |  '|' CH -> center horizontal
	// ├ -'┼'- ┼ - ┤  '┼' I -> intersection
	// └ - ┴ - ┴ - ┘
	I, CH, CV string
}

Contour outlines are required when rendering the table

func (Contour) Footer

func (c Contour) Footer(sw []uint) string

func (Contour) Handler

func (c Contour) Handler(sw []uint) string

Handler output : ┌──────────┬──────┐

func (Contour) Intersection

func (c Contour) Intersection(sw []uint) string

type EmptyCell

type EmptyCell struct{ *BaseCell }

func NewEmptyCell

func NewEmptyCell(w, h uint) EmptyCell

func (EmptyCell) Add

func (c EmptyCell) Add(in ...string)

func (EmptyCell) Line

func (c EmptyCell) Line(uint) string

func (EmptyCell) Lines

func (c EmptyCell) Lines() (out []string)

type InterfaceCell

type InterfaceCell struct {
	*BaseCell
	AnyVal []interface{}
}

func NewInterfaceCell

func NewInterfaceCell(ag Align, data ...interface{}) *InterfaceCell

func (*InterfaceCell) Add

func (c *InterfaceCell) Add(in ...string)

func (*InterfaceCell) ToBaseCell

func (c *InterfaceCell) ToBaseCell() *BaseCell

type MergeCell

type MergeCell struct {
	*BaseCell
	Row    uint
	Column uint
}

func NewMergeCells

func NewMergeCells(cells [][]Cell) *MergeCell

type Option

type Option struct {
	ExpendID          bool
	Align             Align
	Contour           Contour
	TransformContents []TransformContent
}

type RowCell

type RowCell []Cell

type Table

type Table struct {
	Opt *Option
	// val
	Headers RowCell
	Body    []RowCell
	Footers RowCell
}

func DefaultSimpleTable

func DefaultSimpleTable(in interface{}) *Table

func NewTable

func NewTable(opt *Option) *Table

func SimpleTable

func SimpleTable(in interface{}, opt *Option) (*Table, error)

func (*Table) AddBody

func (t *Table) AddBody(in ...interface{}) *Table

func (*Table) AddBodyRow

func (t *Table) AddBodyRow(r RowCell) *Table

func (*Table) AddHeaders

func (t *Table) AddHeaders(in ...interface{}) *Table

func (*Table) Copy

func (t *Table) Copy() *Table

func (*Table) GetCellAt

func (t *Table) GetCellAt(p image.Point) (Cell, error)

func (*Table) Page

func (t *Table) Page(limit, offset int) *Table

func (*Table) Search

func (t *Table) Search(eq interface{}, str string) (Cell, error)

func (*Table) SetBody

func (t *Table) SetBody(idx int, in ...interface{}) *Table

func (*Table) SetCellAt

func (t *Table) SetCellAt(p image.Point, c Cell) error

func (*Table) SetHeaders

func (t *Table) SetHeaders(in ...interface{}) *Table

func (*Table) SetHeadersRow

func (t *Table) SetHeadersRow(r RowCell) *Table

func (*Table) Sort

func (t *Table) Sort(column int, less func(i, j int) bool) *Table

func (*Table) String

func (t *Table) String() (out string)

type TransformContent

type TransformContent func(in interface{}) interface{}

TransformContent shi cn:

当你不想对原有内容作出改变的时候,返回值为原值

en:

When you do not want to make changes to the original content, should return origin

E.g:

func t(in interface{}) (interface{}, error) {
	times, ok := in.(time.Time)
	if !ok {
		return in  <<<<-----
	}
	return times.Format(time.RFC822), nil
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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