tablecli

package module
v0.0.0-...-25f2438 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 6 Imported by: 1 module, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

tablecli

GoDoc Go Report Card

This package provides a convenient way to generate tabular output of any data, which is useful primarily for CLI tools.

Girl in a jacket
Install Package
go get github.com/aziontech/tablecli
Example of use:
package main

import (
    table "github.com/aziontech/tablecli"
    "github.com/fatih/color"
    "strings"
)


type list struct {
    ID string 
    Name string
}

func main() {
    tbl := table.New("ID", "NAME")
    headerFmt := color.New(color.FgBlue, color.Underline).SprintfFunc()
    columnFmt := color.New(color.FgGreen).SprintfFunc()
    tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(columnFmt)

    var list = []list{
        { "123123", "Jonh"},
        { "123121", "Jeff"},
    }

    for _, i := range list {
	tbl.AddRow(i.ID, i.Name)
    }

    format := strings.Repeat("%s", len(tbl.GetHeader())) + "\n"
    tbl.CalculateWidths([]string{})

    tbl.PrintHeader(format)
	for _, r := range tbl.GetRows() {
	    tbl.PrintRow(format, r)
    }
}
Output:
ID      NAME  
123123  Jonh  
123121  Jeff 

License

This project is licensed under the terms of the MIT license.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultPadding                        = 2
	DefaultWriter               io.Writer = os.Stdout
	DefaultHeaderFormatter      Formatter
	DefaultFirstColumnFormatter Formatter
	DefaultWidthFunc            WidthFunc = utf8.RuneCountInString
	WidthPersist                []int
)

Functions

This section is empty.

Types

type Formatter

type Formatter func(string, ...interface{}) string

type Table

type Table interface {
	WithHeaderFormatter(f Formatter) Table
	WithFirstColumnFormatter(f Formatter) Table
	WithPadding(p int) Table
	WithWriter(w io.Writer) Table
	WithWidthFunc(f WidthFunc) Table
	AddRow(vals ...interface{}) Table
	AddRows(rows []string) Table
	SetRows(Rows [][]string) Table
	Print()
	GetByteFormat() []byte
	CalculateWidths([]string)
	GetHeader() []string
	GetRows() [][]string
	GetWriter() io.Writer
	PrintHeader(format string)
	PrintRow(format string, row []string)
}

func New

func New(columnHeaders ...interface{}) Table

func NewTable

func NewTable(columns []string) Table

type WidthFunc

type WidthFunc func(string) int

Jump to

Keyboard shortcuts

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