verticaltable

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2023 License: MIT Imports: 3 Imported by: 2

README

go-verticaltable

MIT License go-verticaltable CI go-verticaltable report card

go-verticaltable provides vertical key, value table which is separated by horizontal header line.

Usage

package main

import (
	"os"

	"github.com/bayashi/go-verticaltable"
)

func main() {
	vt := verticaltable.NewTable(os.Stdout)

	vt.Header("foo")
	vt.Row("ID", "123")
	vt.Row("Select Type", "SIMPLE")
	vt.Row("Table", "foo")

	vt.Header("bar")
	vt.Row("ID", "456")
	vt.Row("Select Type", "UNIQUE")
	vt.Row("Table", "bar")

	vt.Render()
	// Output:
	// ********** 1. foo **********
	//          ID: 123
	// Select Type: SIMPLE
	//       Table: foo
	// ********** 2. bar **********
	//          ID: 456
	// Select Type: UNIQUE
	//       Table: bar
}

Installation

go get github.com/bayashi/go-verticaltable

License

MIT License

Author

Dai Okabayashi: https://github.com/bayashi

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type VT

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

Vertical Table

Example
vt := NewTable(os.Stdout)
buildTables(vt).Render()
Output:

********** 1. foo **********
         ID: 123
Select Type: SIMPLE
      Table: foo
********** 2. bar **********
         ID: 456
Select Type: UNIQUE
      Table: bar

func NewTable

func NewTable(writer io.Writer, opts ...*VTOptions) *VT

func (*VT) Header

func (v *VT) Header(header string) *VT

func (*VT) Render

func (v *VT) Render() error

func (*VT) Row

func (v *VT) Row(k string, val string) *VT

type VTOptions

type VTOptions struct {
	HeaderFormat  string
	ShowCount     bool
	CountFormat   string
	KvSeparator   string
	KeyAlignRight bool
}
Example
vt := NewTable(os.Stdout, &VTOptions{
	HeaderFormat:  "--- %s",
	ShowCount:     false,
	KvSeparator:   " = ",
	KeyAlignRight: false,
})
buildTables(vt).Render()
Output:

--- foo
ID          = 123
Select Type = SIMPLE
Table       = foo
--- bar
ID          = 456
Select Type = UNIQUE
Table       = bar

Jump to

Keyboard shortcuts

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