Tabular simplifies printing ASCII tables from command line utilities

LICENSE Build Status codecov Go Report Card Godocs

tabular

Tabular simplifies printing ASCII tables from command line utilities without the need to pass large sets of data to it's API.

Simply define the table columns and tabular will parse the right format specifier that you can use in your calls to fmt.Printf() or any other function that supports it.

Table columns can be defined once and then reused over and over again making it easy to modify column length and heading in one place. And a subset of columns can be specified during tabular.Print() or tabular.Parse() calls to modify the table's title without redefining it.

Example (also available in example/example.go):

package main

import (
	"fmt"
	"log"

	"github.com/InVisionApp/tabular"
)

var tab tabular.Table

func init() {
	tab = tabular.New()
	tab.Col("env", "Environment", 14)
	tab.Col("cls", "Cluster", 10)
	tab.Col("svc", "Service", 15)
	tab.Col("hst", "Database Host", 20)
	tab.ColRJ("pct", "%CPU", 7)
}

var data = []struct {
	e, c, s, d string
	v          float64
}{
	{
		e: "production",
		c: "cluster-1",
		s: "service-a",
		d: "database-host-1",
		v: 70.01,
	},
	{
		e: "production",
		c: "cluster-1",
		s: "service-b",
		d: "database-host-2",
		v: 99.51,
	},
	{
		e: "production",
		c: "cluster-2",
		s: "service-a",
		d: "database-host-1",
		v: 70.01,
	},
	{
		e: "production",
		c: "cluster-2",
		s: "service-b",
		d: "database-host-2",
		v: 99.51,
	},
}

func main() {
	// Print a subset of columns (Environments and Clusters)
	format := tab.Print("env", "cls")
	for _, x := range data {
		fmt.Printf(format, x.e, x.c)
	}

	// Print All Columns
	format = tab.Print("*")
	for _, x := range data {
		fmt.Printf(format, x.e, x.c, x.s, x.d, x.v)
	}

	// Print All Columns to a custom destination such as a log
	table := tab.Parse("*")
	log.Println(table.Header)
	log.Println(table.SubHeader)
	for _, x := range data {
		log.Printf(table.Format, x.e, x.c, x.s, x.d, x.v)
	}
}

Produces:

Environment    Cluster
-------------- ----------
production     cluster-1
production     cluster-1
production     cluster-2
production     cluster-2

Environment    Cluster    Service         Database Host           %CPU
-------------- ---------- --------------- -------------------- -------
production     cluster-1  service-a       database-host-1        70.01
production     cluster-1  service-b       database-host-2        99.51
production     cluster-2  service-a       database-host-1        70.01
production     cluster-2  service-b       database-host-2        99.51

2018/05/14 11:19:41 Environment    Cluster    Service         Database Host           %CPU
2018/05/14 11:19:41 -------------- ---------- --------------- -------------------- -------
2018/05/14 11:19:41 production     cluster-1  service-a       database-host-1        70.01
2018/05/14 11:19:41 production     cluster-1  service-b       database-host-2        99.51
2018/05/14 11:19:41 production     cluster-2  service-a       database-host-1        70.01
2018/05/14 11:19:41 production     cluster-2  service-b       database-host-2        99.51
Similar Resources

go.pipeline is a utility library that imitates unix pipeline. It simplifies chaining unix commands (and other stuff) in Go.

go.pipeline go.pipeline is a utility library that imitates unix pipeline. It simplifies chaining unix commands (and other stuff) in Go. Installation g

May 8, 2022

The Fabric Smart Client is a new Fabric Client that lets you focus on the business processes and simplifies the development of Fabric-based distributed application.

Fabric Smart Client The Fabric Smart Client (FSC, for short) is a new Fabric client-side component whose objective is twofold. FSC aims to simplify th

Dec 14, 2022

alonzo-testnet simplifies deploying a private alonzo testnet.

alonzo-testnet alonzo-testnet simplifies deploying a private alonzo testnet. SundaeSwap heavily leverages AWS and consequently, this tooling has been

Oct 5, 2022

fastcache is an HTTP response caching package that plugs into fastglue that simplifies

fastcache fastcache is a simple response caching package that plugs into fastglue. The Cached() middleware can be wrapped around fastglue GET handlers

Apr 5, 2022

Go package simplifies nullable fields handling using Go Generics.

Go Nullable with Generics Go package simplifies nullable fields handling with Go Generics. Package gonull provides a generic Nullable type for handlin

May 7, 2023

Our notification system simplifies the process of sending notifications via email, SMS, and push notifications for multiple applications. It supports multiple providers, customizable templates, and is easy to integrate into any application.

Our notification system simplifies the process of sending notifications via email, SMS, and push notifications for multiple applications. It supports multiple providers, customizable templates, and is easy to integrate into any application.

Simplify Notification Management with Customizable Templates and Multi-Provider Integration ⭐️ Why Envoyer Nowadays, notifications play a crucial role

May 11, 2023

A lightweight eventbus that simplifies communication between goroutines,

English | 简体中文 eventbus A lightweight eventbus that simplifies communication between goroutines, it supports synchronous and asynchronous message publ

Apr 28, 2023

The main goal of this code is to create a basic dnstap printing tool based on the golang-dnstap library.

dnstap-parse The main goal of this code is to create a basic dnstap printing tool based on the golang-dnstap library. The output is supposed to mimic

Nov 14, 2021

Tool for printing a directory tree and indicating the space it occupies.

Tool for printing a directory tree and indicating the space it occupies.

Nov 6, 2021

A program to create assembly 8086 strings to print without using any printing/strings related function but only mov-xchg-int and loops

Assembly String builder tool A program to create assembly 8086 strings to print without using any printing/strings related function but only mov-xchg-

Feb 1, 2022

Basic timestamped console printing.

loglines Basic timestamped console printing. What This is a very simple package with three functions: NowString() returns a string with the current ti

Nov 20, 2021

Timediff is a Go package for printing human readable, relative time differences 🕰️

timediff is a Go package for printing human readable, relative time differences. Output is based on ranges defined in the Day.js JavaScript library, and can be customized if needed.

Dec 25, 2022

This project aims for printing HTTP requests from outside simply

HTTP Debug Server This project aims for printing HTTP requests from outside simp

Jan 29, 2022

OTF font with vertical bars for one-line ASCII spectrum analyzers, graphs, etc

OTF font with vertical bars for one-line ASCII spectrum analyzers, graphs, etc

graph-bars-font OTF font with vertical bars for one-line ASCII spectrum analyzers, graphs, etc. I didn't find anything similar on the net so I decided

Jul 28, 2022

A command to output longified ascii art.

longify A command to output longified ascii art. Inspired by Tweet from @sheepla: https://twitter.com/Sheeeeepla/status/1522199846870196225 Installati

Sep 12, 2022

A go library to improve readability in terminal apps using tabular data

uitable uitable is a go library for representing data as tables for terminal applications. It provides primitives for sizing and wrapping columns to i

Dec 30, 2022

Gotabulate - Easily pretty-print your tabular data with Go

Gotabulate - Easily pretty-print tabular data Summary Go-Tabulate - Generic Go Library for easy pretty-printing of tabular data. Installation go get g

Dec 27, 2022

A Go native tabular data extraction package. Currently supports .xls, .xlsx, .csv, .tsv formats.

grate A Go native tabular data extraction package. Currently supports .xls, .xlsx, .csv, .tsv formats. Why? Grate focuses on speed and stability first

Dec 26, 2022

datatable is a Go package to manipulate tabular data, like an excel spreadsheet.

datatable is a Go package to manipulate tabular data, like an excel spreadsheet.

datatable is a Go package to manipulate tabular data, like an excel spreadsheet. datatable is inspired by the pandas python package and the data.frame R structure. Although it's production ready, be aware that we're still working on API improvements

Nov 23, 2022
Comments
  • supports select * style of table parsing and printing

    supports select * style of table parsing and printing

    supports select * style of table parsing and printing

    For example:

    // Print All Columns
    format = tab.Print("*")
    for _, x := range data {
        fmt.Printf(format, x.e, x.c, x.s, x.d, x.v)
    }
    
  • fixes header padding error when first column is RightJustified

    fixes header padding error when first column is RightJustified

    Prior to this fix, if the first table column is RightJustified, then tabular would loose the left padding on the header. Now, it works as expected and there is a test for this.

  • reworked public API and added Parse to support other output destinations

    reworked public API and added Parse to support other output destinations

    Breaking API Changes:

    1. To add a new column call tab.Col() instead of tab.Add()
    2. To print the table's title and get it's format specifier for columns call tab.Print() instead of tab.Do()

    API Additions:

    1. To silently get the table's title (header + subHeader) call tab.Parse() - this can be used when you need to print to other destinations.
A go library to improve readability in terminal apps using tabular data

uitable uitable is a go library for representing data as tables for terminal applications. It provides primitives for sizing and wrapping columns to i

Dec 30, 2022
✨ #PTerm is a modern go module to beautify console output. Featuring charts, progressbars, tables, trees, and many more 🚀 It's completely configurable and 100% cross-platform compatible.
✨ #PTerm is a modern go module to beautify console output. Featuring charts, progressbars, tables, trees, and many more 🚀 It's completely configurable and 100% cross-platform compatible.

?? PTerm | Pretty Terminal Printer A golang module to print pretty text Show Demo Code PTerm.sh | Installation | Documentation | Quick Start | Example

Dec 27, 2022
Simple tables in terminal with Go

Simple tables in terminal with Go This package allows to generate and display ascii tables in the terminal, f.e.: +----+------------------+-----------

Dec 29, 2022
A tiny library for super simple Golang tables

Tabby A tiny library for super simple Golang tables Get Tabby go get github.com/cheynewallace/tabby Import Tabby import "github.com/cheynewallace/tabb

Nov 23, 2022
asciigrid is a Go package that implements decoder and encoder for the Esri ASCII grid format, also known as ARC/INFO ASCII GRID.

asciigrid asciigrid is a Go package that implements decoder and encoder for the Esri ASCII grid format, also known as ARC/INFO ASCII GRID. Install go

Jul 3, 2022
Command line interface to windows clipboard over KiTTY remote-control printing

kclip Command line interface to windows clipboard over KiTTY remote-control printing About This tool behaves like the cat command, it just tries to pa

Dec 12, 2021
Go package to make lightweight ASCII line graph ╭┈╯ in command line apps with no other dependencies.
Go package to make lightweight ASCII line graph ╭┈╯ in command line apps with no other dependencies.

asciigraph Go package to make lightweight ASCII line graphs ╭┈╯. Installation go get github.com/guptarohit/asciigraph Usage Basic graph package main

Jan 1, 2023
Go package to make lightweight ASCII line graph ╭┈╯ in command line apps with no other dependencies.
Go package to make lightweight ASCII line graph ╭┈╯ in command line apps with no other dependencies.

asciigraph Go package to make lightweight ASCII line graphs ╭┈╯. Installation go get github.com/guptarohit/asciigraph Usage Basic graph package main

Jan 8, 2023
Utilities to prettify console output of tables, lists, progress-bars, text, etc.
Utilities to prettify console output of tables, lists, progress-bars, text, etc.

go-pretty Utilities to prettify console output of tables, lists, progress-bars, text, etc. Table Pretty-print tables into ASCII/Unicode strings.

Dec 29, 2022
Simple utilities for creating ascii text in Go

Simple utilities for creating ascii text in Go

Oct 30, 2021