gotable

package module
v0.0.0-...-1113793 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2022 License: MIT Imports: 9 Imported by: 35

README

gotable 5: Safe

Generate beautiful ASCII tables.

package main

import (
	"fmt"
	"github.com/liushuochen/gotable"
)

func main() {
	table, err := gotable.Create("version", "description")
	if err != nil {
		fmt.Println("Create table failed: ", err.Error())
		return
	}

	table.AddRow([]string{"gotable 5", "Safe: New table type to enhance concurrency security"})
	table.AddRow([]string{"gotable 4", "Colored: Print colored column"})
	table.AddRow([]string{"gotable 3", "Storage: Store the table data as a file"})
	table.AddRow([]string{"gotable 2", "Simple: Use simpler APIs to control table"})
	table.AddRow([]string{"gotable 1", "Gotable: Print a beautiful ASCII table"})

	fmt.Println(table)
}

+-----------+------------------------------------------------------+
|  version  |                     description                      |
+-----------+------------------------------------------------------+
| gotable 5 | Safe: New table type to enhance concurrency security |
| gotable 4 |            Colored: Print colored column             |
| gotable 3 |       Storage: Store the table data as a file        |
| gotable 2 |      Simple: Use simpler APIs to control table       |
| gotable 1 |        Gotable: Print a beautiful ASCII table        |
+-----------+------------------------------------------------------+

Reference

Please refer to guide: gotable guide

Supported character set

  • ASCII
  • Chinese characters

API

Please refer to 'gotable APIs' for more gotable API information.

Demo

Please refer to gotable demo page for more demos code.

Error type

Please refer to this guide 'error type' for more gotable error information.

Documentation

Index

Constants

View Source
const (
	Center  = table.C
	Left    = table.L
	Right   = table.R
	Default = table.Default
)
View Source
const (
	TerminalDefault = 0
	Highlight       = 1
	Underline       = 4
	Flash           = 5
)

Colored display control

View Source
const (
	Black          = 30
	Red            = 31
	Green          = 32
	Yellow         = 33
	Blue           = 34
	Purple         = 35
	Cyan           = 36
	Write          = 37
	NoneBackground = 0
)

Colored control

Variables

This section is empty.

Functions

func Create

func Create(columns ...string) (*table.Table, error)

Create an empty simple table. When duplicate values in columns, table creation fails. It will return a table pointer and an error. Error: - If the length of columns is not greater than 0, an *exception.ColumnsLengthError error is returned. - If columns contain duplicate values, an error is returned. - Otherwise, the value of error is nil.

func CreateByStruct

func CreateByStruct(v interface{}) (*table.Table, error)

CreateByStruct creates an empty table from struct. You can rename a field using struct tag: gotable It will return a table pointer and an error. Error: - If the length of columns is not greater than 0, an *exception.ColumnsLengthError error is returned. - If columns contain duplicate values, an error is returned. - Otherwise, the value of error is nil.

func CreateSafeTable

func CreateSafeTable(columns ...string) (*table.SafeTable, error)

CreateSafeTable function used to create an empty safe table. When duplicate values in columns, table creation fails. It will return a table pointer and an error. Error: - If the length of columns is not greater than 0, an *exception.ColumnsLengthError error is returned. - If columns contain duplicate values, an error is returned. - Otherwise, the value of error is nil.

func Read

func Read(path string) (*table.Table, error)

Read from file to create a *table instance. Currently, support csv and json file. It will return a table pointer and an error. Error:

  • If path is not a file, or does not exist, an *exception.FileDoNotExistError is returned.
  • If path is a JSON file, the contents of the file are not eligible table contents, an *exception.NotGotableJSONFormatError is returned.
  • If path is a CSV file, and the contents of the file are empty, an *exception.ColumnsLengthError is returned.
  • If there are duplicate columns in the parse result, an error is returned.
  • Otherwise the value if error is nil.

func Version

func Version() string

Version The version function returns a string representing the version information of the gotable. e.g.

gotable 3.4.0

func Versions

func Versions() []string

Versions returns a list of version numbers.

Types

This section is empty.

Directories

Path Synopsis
Package table define all table types methods.
Package table define all table types methods.

Jump to

Keyboard shortcuts

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