GithubHelp home page GithubHelp logo

termtables's Introduction

Termtables

Build Status

A Go port of the Ruby library terminal-tables for fast and simple ASCII table generation.

Installation

go get github.com/xlab/termtables

Go Style Documentation

http://godoc.org/github.com/xlab/termtables

APC Command Line usage

--markdown — output a markdown table, e.g. apc app list --markdown

--html — output an html table, e.g. apc app list --html

--ascii — output an ascii table, e.g. apc app list --ascii

Basic Usage

package main

import (
  "fmt"
  "github.com/xlab/termtables"
)

func main() {
  table := termtables.CreateTable()

  table.AddHeaders("Name", "Age")
  table.AddRow("John", "30")
  table.AddRow("Sam", 18)
  table.AddRow("Julie", 20.14)

  fmt.Println(table.Render())
}

Result:

+-------+-------+
| Name  | Age   |
+-------+-------+
| John  | 30    |
| Sam   | 18    |
| Julie | 20.14 |
+-------+-------+

Advanced Usage

The package function-call EnableUTF8() will cause any tables created after that point to use Unicode box-drawing characters for the table lines.

Calling EnableUTF8PerLocale() uses the C library's locale functionality to determine if the current locale environment variables say that the current character map is UTF-8. If, and only if, so, then EnableUTF8() will be called.

Calling SetModeHTML(true) will cause any tables created after that point to be emitted in HTML, while SetModeMarkdown(true) will trigger Markdown. Neither should result in changes to later API to get the different results; the primary intended use-case is extracting the same table, but for documentation.

The table method .AddSeparator() inserts a rule line in the output. This only applies in normal terminal output mode.

The table method .AddTitle() adds a title to the table; in terminal output, this is an initial row; in HTML, it's a caption. In Markdown, it's a line of text before the table, prefixed by Table: .

The table method .SetAlign() takes an alignment and a column number (indexing starts at 1) and changes all current cells in that column to have the given alignment. It does not change the alignment of cells added to the table after this call. Alignment is only stored on a per-cell basis.

Known Issues

Normal output:

  • .SetAlign() does not affect headers.

Markdown output mode:

  • When emitting Markdown, the column markers are not re-flowed if a vertical bar is an element of a cell, causing an escape to take place; since Markdown is often converted to HTML, this only affects text viewing.
  • A title in Markdown is not escaped against all possible forms of Markdown markup (to avoid adding a dependency upon a Markdown library, as supported syntax can vary).
  • Markdown requires headers, so a dummy header will be inserted if needed.
  • Table alignment is not reflected in Markdown output.

termtables's People

Contributors

krobertson avatar alextoombs avatar johnschnake avatar klobucar avatar case avatar philpennock avatar lparis avatar xlab avatar horpto 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.