Code Monkey home page Code Monkey logo

termtable's Introduction

termtable

A Go library to easily generate table in you CLI

Install

$ go get github.com/stevedomin/termtable

Usage

Print a simple table without separators:

package main

import(
    "fmt"
    "github.com/stevedomin/termtable"
)

func main() {
    t := termtable.NewTable(nil, nil)
    t.SetHeader([]string{"LOWERCASE", "UPPERCASE", "NUMBERS"})
    t.AddRow([]string{"abc", "ABCD", "12345"})
    t.AddRow([]string{"defg", "EFGHI", "678"})
    t.AddRow([]string{"hijkl", "JKL", "9000"})
    fmt.Println(t.Render())

    // Output :
    // LOWERCASE UPPERCASE NUMBERS
    // abc       ABCD      12345
    // defg      EFGHI     678
    // hijkl     JKL       9000
}

Print a simple table with separators and custom padding (alt syntax):

package main

import(
    "github.com/stevedomin/termtable"
)

func main() {
    rows := [][]string{
      []string{"abc", "ABCD", "12345"},
      []string{"defg", "EFGHI", "678"},
      []string{"hijkl", "JKL", "9000"},
    }
    t := termtable.NewTable(rows, &termtable.TableOptions{
     Padding: 3,
     UseSeparator: true,
    })
    fmt.Println(t.Render())

    // Output (vertical bars look better in terminal):
    // +---------------+---------------+-------------+
    // |   LOWERCASE   |   UPPERCASE   |   NUMBERS   |
    // +---------------+---------------+-------------+
    // |   abc         |   ABCD        |   12345     |
    // |   defg        |   EFGHI       |   678       |
    // |   hijkl       |   JKL         |   9000      |
    // +---------------+---------------+-------------+
}

Development

To run test:

$ go test

To run benchmarks:

$ go test -bench . -benchmem

Todo

  • Column align
  • Cell align
  • Support more types: int, float, bool
  • Rows separator
  • Multiline cell
  • Custom column width

termtable's People

Contributors

stevedomin avatar wfarr avatar jmoiron avatar

Watchers

Antony Ingram avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.