tables

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

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

Go to latest
Published: Jan 18, 2020 License: MIT Imports: 6 Imported by: 3

README

tables

Go Report Card Build Status Codacy Badge Coverage Status

Simple representation of tables on console

Examples

Basic example

import "github.com/saromanov/tables"

func main() {
	t := tables.New()
	t.AddHeader("foo", "bar")
	t.AddLine("a", "b")
	t.AddLine("c", "d")
	t.Build()
}

Output:

foo  bar
---  ---
a    b
c    d

Hooks

You can add hook before execution of the table. As example it might be colorized of the table


import (
	"github.com/fatih/color"
	"github.com/saromanov/tables"
)

	table := tables.New()
	table.AddHooks(func(s string) string {
		return color.New(color.FgGreen).SprintFunc()(s)
	},
	)
	table.AddHeader("one", "two", "three", "four")
	table.AddHooks(func(s string) string {
		return color.New(color.FgYellow).SprintFunc()(s)
	},
	)
	table.AddLine("red", "poom", "boom", "sasdsadasdas")
	table.AddLine("red", "poom", "boom", "sasdsadasdas")
	table.Build()
	```

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

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

App is provides create of the new app

func New

func New() *App

New provides create of the new app

func (*App) AddHeader

func (t *App) AddHeader(args ...interface{})

AddHeader will write a new table line followed by a separator

func (*App) AddHooks

func (t *App) AddHooks(hooks ...Hook)

AddHooks provides adding of line hooks Its call at the stage of formatting. So, its doesen't change content of the lines. For example, this is possible to add color of the lines

func (*App) AddLine

func (t *App) AddLine(args ...interface{})

AddLine will write a new table line

func (*App) Build

func (t *App) Build()

Build will write the table to the terminal

func (*App) String

func (t *App) String() string

String returns formated string

type Hook

type Hook func(string) string

Hook defines function type for hook definition inside that method is able to modify string and dtehn retrun it

Jump to

Keyboard shortcuts

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