tbl

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 3 Imported by: 0

README

tbl

tbl is a simple way to print text tables.

Installing

go get -u github.com/alligator/tbl

Example

package main

import (
	"fmt"

	"github.com/alligator/tbl"
)

type row struct {
	id   int
	name string
}

func main() {
	rows := []row{
		{1, "gate"},
		{2, "boop"},
	}

	t := tbl.NewTable()

	for _, row := range rows {
		t.NewRow()

		t.NewCol("Id")
		t.Printf("%d", row.id)

		t.NewCol("Name")
		t.Print(row.name)
	}

	fmt.Print(t.String())
}

Documentation

Overview

Package tbl implements a simple way to print tables

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Table

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

func NewTable

func NewTable() *Table

func (*Table) NewCol

func (t *Table) NewCol(name string)

NewCol adds a column with the given name to the current row

func (*Table) NewRow

func (t *Table) NewRow()

NewRow adds a row to the end of table

func (*Table) Print

func (t *Table) Print(s string)

Print s to the current column

func (*Table) Printf

func (t *Table) Printf(format string, a ...any)

Printf is shorthand for

tbl.Print(fmt.Sprintf(format, a))

func (*Table) String

func (t *Table) String() string

String returns the formatted table

Jump to

Keyboard shortcuts

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