Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/rodaine/table

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/rodaine/table

  • v1.3.0
  • Source
  • Go
  • Socket score

Version published
Created
Source

table
GoDoc

Example Table Output With ANSI Colors

Package table provides a convenient way to generate tabular output of any data, primarily useful for CLI tools.

Features

  • Accepts all data types (string, int, interface{}, everything!) and will use the String() string method of a type if available.
  • Can specify custom formatting for the header and first column cells for better readability.
  • Columns are left-aligned and sized to fit the data, with customizable padding.
  • The printed output can be sent to any io.Writer, defaulting to os.Stdout.
  • Built to an interface, so you can roll your own Table implementation.
  • Works well with ANSI colors (fatih/color in the example)!
  • Can provide a custom WidthFunc to accomodate multi- and zero-width characters (such as runewidth)

Usage

Download the package:

go get github.com/rodaine/table

Example:

package main

import (
  "fmt"
  "strings"

  "github.com/fatih/color"
  "github.com/rodaine/table"
)

func main() {
  headerFmt := color.New(color.FgGreen, color.Underline).SprintfFunc()
  columnFmt := color.New(color.FgYellow).SprintfFunc()

  tbl := table.New("ID", "Name", "Score", "Added")
  tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(columnFmt)

  for _, widget := range getWidgets() {
    tbl.AddRow(widget.ID, widget.Name, widget.Cost, widget.Added)
  }

  tbl.Print()
}

Consult the documentation for further examples and usage information

License

table is released under the MIT License (Expat). See the full license.

FAQs

Package last updated on 02 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc