table

package
v0.15.7 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const ColSpacing = 2

ColSpacing is the number of spaces between columns.

Variables

This section is empty.

Functions

func DisplayBytes

func DisplayBytes(row map[string]interface{}, field string) string

DisplayBytes converts an integer value to a string in bytes, kilobytes, megabytes, or gigabytes

func DisplayDateTime

func DisplayDateTime(row map[string]interface{}, field string) string

DisplayDateTime converts a time.Time value to a string in time.Stamp format

func DisplayDuration

func DisplayDuration(row map[string]interface{}, field string) string

DisplayDuration calculates the duration between two time.Time values and returns a string

Types

type FieldDefinition

type FieldDefinition struct {
	Name        string
	Width       int
	Type        FieldType
	Format      string // Used for time formatting
	DisplayFunc func(row map[string]interface{}, name string) string
}

FieldDefinition represents a field in a table.

type FieldType

type FieldType int

FieldType represents the type of a field in a table.

const (
	String FieldType = iota
	Int
	Float
	Time
)

FieldType constants

type Table

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

Table represents a table with fields and data.

func NewTable

func NewTable(fields []FieldDefinition, colorFunc func(map[string]interface{}) string) *Table

NewTable creates a new table with the specified fields and color function. The color function is used to color rows based on their content, it should return an ANSI color code.

func (*Table) DisplayJSON

func (t *Table) DisplayJSON() error

DisplayJSON outputs the table's data as an indented JSON string.

func (*Table) DisplayTable

func (t *Table) DisplayTable() error

DisplayTable displays a JSON array as a table, trimming rows to fit terminal width.

func (*Table) ParseJsonData

func (t *Table) ParseJsonData(dataJson []byte) error

Parse processes the data to conform to field definitions. The data should be a slice of maps where each map represents a row.

func (*Table) Sort

func (t *Table) Sort(sortFields []string) error

Sort sorts the table data by the specified fields. The `sortFields` argument is a slice of field names with an optional prefix "-" for descending order.

Jump to

Keyboard shortcuts

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