table

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Overview

ItemsTable 用于展示 Array 和 Slice 类型数据

支持以下特性:

样式

  1. 设置边框格式
  2. 自定义颜色
  3. 开启/关闭表格内边框

  1. 开启/关闭自动编号
  2. 设置最大宽度

Index

Constants

This section is empty.

Variables

View Source
var StyleBold = Style{
	"┏", "┳", "┓",
	"┣", "╋", "┫",
	"┗", "┻", "┛",
	"━", "┃",
}

StyleBold renders a table like below:

┏━━━━┳━━━━━━━┳━━━━━┓
┃ Id ┃ Name  ┃ Age ┃
┣━━━━╋━━━━━━━╋━━━━━┫
┃ 1  ┃ name1 ┃ 1   ┃
┃ 2  ┃ name2 ┃ 10  ┃
┗━━━━┻━━━━━━━┻━━━━━┛
View Source
var StyleDefault = Style{
	"+", "+", "+",
	"+", "+", "+",
	"+", "+", "+",
	"-", "|",
}

StyleDefault renders a table like below:

+----+-------+-----+
| Id | Name  | Age |
+----+-------+-----+
| 1  | name1 | 1   |
| 2  | name2 | 10  |
+----+-------+-----+
View Source
var StyleDouble = Style{
	"╔", "╦", "╗",
	"╠", "╬", "╣",
	"╚", "╩", "╝",
	"═", "║",
}

StyleBold renders a table like below:

╔════╦═══════╦═════╗
║ Id ║ Name  ║ Age ║
╠════╬═══════╬═════╣
║ 1  ║ name1 ║ 1   ║
║ 2  ║ name2 ║ 10  ║
╚════╩═══════╩═════╝
View Source
var StyleLight = Style{
	"┌", "┬", "┐",
	"├", "┼", "┤",
	"└", "┴", "┘",
	"─", "│",
}

StyleLight renders a table like below:

┌────┬───────┬─────┐
│ Id │ Name  │ Age │
├────┼───────┼─────┤
│ 1  │ name1 │ 1   │
│ 2  │ name2 │ 10  │
└────┴───────┴─────┘
View Source
var StyleRounded = Style{
	"╭", "┬", "╮",
	"├", "┼", "┤",
	"╰", "┴", "╯",
	"─", "│",
}

StyleRounded renders a table like below:

╭────┬───────┬─────╮
│ Id │ Name  │ Age │
├────┼───────┼─────┤
│ 1  │ name1 │ 1   │
│ 2  │ name2 │ 10  │
╰────┴───────┴─────╯

Functions

This section is empty.

Types

type H

type H struct {
	Title    string
	Field    string
	MaxWidth int
	// contains filtered or unexported fields
}

type ItemsTable

type ItemsTable struct {
	Name    string
	Headers []H
	Items   interface{}

	InlineBorder bool
	AutoIndex    bool
	// contains filtered or unexported fields
}

func NewItemsTable

func NewItemsTable(titles []string, items interface{}) *ItemsTable

func (*ItemsTable) EnableAutoIndex

func (t *ItemsTable) EnableAutoIndex() *ItemsTable

func (*ItemsTable) Render

func (t *ItemsTable) Render() (string, error)

func (*ItemsTable) SetColor

func (t *ItemsTable) SetColor(attributes ...color.Attribute) *ItemsTable

func (*ItemsTable) SetStyle

func (t *ItemsTable) SetStyle(style Style, colors ...color.Attribute) *ItemsTable

type Style

type Style []string

Jump to

Keyboard shortcuts

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