Pretty console printing of tabular data

go-tableify

Go Report Card GoDoc

Pretty console printing of tabular data

Installation

Make sure you have a working Go environment. Follow the Go install instructions.

To install go-tableify, simply run:

go get github.com/subchen/go-tableify

Example

Manunal Set

package main

import (
	"github.com/subchen/go-tableify"
)

func main() {
	t := tableify.New()
	t.SetHeaders("Name", "Files", "Updated")
	t.SetWidths(10, 0, 0) // optional
	t.EmptyText = "no data in table"

	t.AddRow("yum-repo", 45, "2018-01-06T07:45:22Z")
	t.AddRow("deb-repo", 12, "2018-01-06T08:05:09Z")

	t.Print()
}

Using Struct

package main

import (
	"github.com/subchen/go-tableify"
)

type Repo struct {
	Name        string   `json:"name" tableify:"-"`
	Desc        string   `json:"desc"`
	Files       int      `json:"files" tableify:"-,5"`
	LastUpdated string   `json:"lastUpdated" tableify:"Updated"`
}

func main() {
	repolist := []Repo{
		{
			Name:         "yum-repo",
			Files:        45,
			LastUpdated:  "2018-01-06T07:45:22Z",
		},
		{
			Name:         "deb-repo",
			Files:        12,
			LastUpdated:  "2018-01-06T08:05:09Z",
		},
	}

	t := tableify.New()
	t.SetHeadersFromStruct(new(Repo))
	t.AddRowObjectList(repolist)
	t.Print()
}

Struct Field Tag formats:

  • name or -

    eg: tableify:"-", tableify:"NAME"

  • name,width

    eg: tableify:"-,20"

  • name,width,format

    eg: tableify:"-,0,%.2f"

Output

Name         Files   Updated
-----------------------------------------
yum-repo     45      2018-01-06T07:45:22Z
deb-repo     12      2018-01-06T08:05:09Z
Similar Resources

This is a Go Cli app that receives an string path to a log file, and based on it generates and prints in console an encoded polyline with the locations found in the log file.

This is a Go Cli app that receives an string path to a log file, and based on it generates  and prints in console an encoded polyline with the locations found in the log file.

GEOENCODE GO CLI APP DESCRIPTION This is a Go Cli app that receives an string path to a log file, and based on it generates and prints in console an e

Oct 1, 2021

Use Golang to achieve better console backend services

Use Golang to achieve better console backend services

Dec 7, 2021

This is a cli to watch anime using the console/terminal.

 This is a cli to watch anime using the console/terminal.

monas-chinas-cli Este un un cli para ver anime usando la consola/terminal. This is a cli to watch anime using the console/terminal. ⚠️ AVISO ⚠️ Los an

Dec 8, 2022

Windows API to hide console window by golang

Doge-Hide windows API to hide console window by golang ShowWindow ShowWindowAsy

Nov 7, 2022

mlp is a comman line tool responsible for creating, updating and deleting kubernetes resources based on files generated by Mia-Platform Console.

mlp is a comman line tool responsible for creating, updating and deleting kubernetes resources based on files generated by Mia-Platform Console.

Apr 28, 2022

Godbolt console wrapper for easily execute local file without any security risk and compiler.

Godbolt CLI Godbolt console wrapper for easily execute local file without any security risk and compiler. Install Compile the source code and add to y

May 22, 2022

📝 connote is a simple console-based note taking tool.

📝 connote connote is a simple console-based note taking tool. Install Download the binary for your operating system from Releases Run go install gith

Jun 10, 2022

Query, update and convert data structures from the command line. Comparable to jq/yq but supports JSON, TOML, YAML, XML and CSV with zero runtime dependencies.

Query, update and convert data structures from the command line. Comparable to jq/yq but supports JSON, TOML, YAML, XML and CSV with zero runtime dependencies.

dasel Dasel (short for data-selector) allows you to query and modify data structures using selector strings. Comparable to jq / yq, but supports JSON,

Jan 2, 2023

Pi-hole data right from your terminal. Live updating view, query history extraction and more!

Pi-hole data right from your terminal. Live updating view, query history extraction and more!

Pi-CLI Pi-CLI is a command line program used to view data from a Pi-Hole instance directly in your terminal.

Dec 12, 2022
Comments
  • 怎样对齐表格和表头

    怎样对齐表格和表头

    想问一下,怎么让表格里的数据和表头对齐在同一列呢? 比如我现在是这样的:

    城市 更新时间 湿度 温度 风向 日出 日落 风力

    上海 20:20 65% 28 东风 05:25 18:27 2级

tabitha is a no-frills tabular formatter for the terminal.

tabitha tabitha is a no-frills tabular formatter for the terminal. Features Supports padding output to the longest display text, honoring ANSI colors

Aug 19, 2022
code is pretty self explanatory and decently commented
code is pretty self explanatory and decently commented

square_approximation code is pretty self explanatory and decently commented when limit set to 10^9 or more ram usage goes to >42 gigs of ram which is

Apr 7, 2022
Gofetch is a pretty command-line "Go and System information" tool written in Go
Gofetch is a pretty command-line

GoFetch Show off your Go information with this cool command-line tool! Report Bug || Request Feature Table of Contents About the Project Built With Ge

Nov 1, 2022
Console-based JVM monitoring tool
Console-based JVM monitoring tool

jvm-mon Console based JVM monitoring - when you just want to SSH into a server and see what's going on. jvm-top lets you monitor your JVM server appli

Jan 2, 2023
Console progress bar for Golang

Terminal progress bar for Go Installation go get github.com/cheggaaa/pb/v3 Documentation for v1 bar available here Quick start package main import (

Jan 9, 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
Disk usage analyzer with console interface written in Go
Disk usage analyzer with console interface written in Go

Gdu is intended primarily for SSD disks where it can fully utilize parallel processing. However HDDs work as well, but the performance gain is not so huge.

Jan 7, 2023
Integrated console application library, using Go structs as commands, with menus, completions, hints, history, Vim mode, $EDITOR usage, and more ...
Integrated console application library, using Go structs as commands, with menus, completions, hints, history, Vim mode, $EDITOR usage, and more ...

Gonsole - Integrated Console Application library This package rests on a readline console library, (giving advanced completion, hint, input and histor

Nov 20, 2022
oc CLI plugin to interact with Helm features provided by the OpenShift Console

OpenShift provides support for managing the lifecycle of Helm charts. This capability is limited primarily to the Web Console. This plugin enables the management of Helm charts similar to using the standalone Helm CLI while offloading much of the work to OpenShift.

Aug 20, 2022
Simple console formatting library for Go
Simple console formatting library for Go

flair Simple console formatting library for Go Motivation There are definitely a bunch of other libraries like this, but I wanted one I knew would be

Aug 30, 2021