dyn_table

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

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

Go to latest
Published: Nov 15, 2022 License: MIT Imports: 3 Imported by: 0

README

DynTable

I was trying to use the awesome-go table for my purpose, but in my case, I need to add rows to the table while my application is running.

Since the table constructor now has no information about the data length of each table cell, I added a column width parameter. Also, each column of the table has an alignment option - Left or Right.

Usage


import table "github.com/PVKonovalov/dyn_table"

func main() {
	tab := table.DynTable{
		Width:   []int{1, 7, 5, 7, 5, 6, 12, 12, 7, 6},
		Headers: []string{" ", "Address", "ASDU", "Point #", "Name", "Value", "Time", "Time recv", "Quality", "Source"},
		Align: []int{table.AlignLeft, table.AlignRight, table.AlignRight, table.AlignRight, table.AlignLeft,
			table.AlignRight, table.AlignLeft, table.AlignLeft, table.AlignLeft, table.AlignRight},
	}

	rows := [][]string{
		{"Q", "1000", "1/30", "34567", "CB-12 circuit breaker", "2", "12:33:45.567", "12:33:45.567", "OK", "15"},
		{"V", "1001", "13/36", "34568", "Ua", "100.12", "12:33:45.567", "12:33:45.567", "OK", "15"},
		{"V", "1002", "1/30", "34569", "Ub", "12.56", "12:33:45.567", "12:33:45.567", "OK", "15"},
		{"T", "1003", "1/30", "345610", "Uc", "12.78", "12:33:45.567", "12:33:45.567", "OK", "15"},
	}

	tab.WriteHeader(nil, 2)
	for _, row := range rows {
		tab.AppendRow(row)
	}
}

Installation

go install github.com/PVKonovalov/dyn_table

Lisence

MIT

Documentation

Index

Constants

View Source
const (
	AlignLeft = iota
	AlignRight
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ShowIndex       bool     // shows the index/row number as the first column
	Color           bool     // use the color codes in the output
	AlternateColors bool     // alternate the colors when writing
	TitleColorCode  string   // the ansi code for the title row
	AltColorCodes   []string // the ansi codes to alternate between
}

Config is the

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default config for table, if its ever left null in a method this will be the one used to display the table

type DynTable

type DynTable struct {
	Width   []int
	Align   []int
	Headers []string
	// contains filtered or unexported fields
}

DynTable is the struct used to define the structure, this can be used from a zero state, or inferred using the reflection based methods

func (*DynTable) AppendRow

func (t *DynTable) AppendRow(row []string)

func (*DynTable) WriteHeader

func (t *DynTable) WriteHeader(conf *Config, idxColumnWidth int)

Jump to

Keyboard shortcuts

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