Categorygithub.com/scylladb/termtables
modulepackage
0.0.0-20191203121021-c4c0b6d42ff4
Repository: https://github.com/scylladb/termtables.git
Documentation: pkg.go.dev

# README

Termtables

Build Status

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

Installation

go get github.com/scylladb/termtables

Go Style Documentation

http://godoc.org/github.com/scylladb/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/scylladb/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.

# Packages

No description provided by the author

# Functions

CreateCell returns a Cell where the content is the supplied value, with the optional supplied style (which may be given as nil).
CreateRow returns a Row where the cells are created as needed to hold each item given; each item can be a Cell or content to go into a Cell created to hold it.
CreateTable creates an empty Table using defaults for style.
EnableUTF8 will unconditionally enable using UTF-8 box-drawing characters for any tables created after this call, as the default style.
EnableUTF8PerLocale will use current locale character map information to determine if UTF-8 is expected and, if so, is equivalent to EnableUTF8.
SetHTMLStyleTitle lets an HTML title output mode be chosen.
SetModeHTML will control whether or not new tables generated will be in HTML mode by default; HTML-or-not takes precedence over options which control how a terminal output will be rendered, such as whether or not to use UTF8.
SetModeMarkdown will control whether or not new tables generated will be in Markdown mode by default.

# Constants

These constants control the alignment which should be used when rendering the content of a cell.
These constants control the alignment which should be used when rendering the content of a cell.
These constants control the alignment which should be used when rendering the content of a cell.
LINE_BOTTOM has only ascenders.
LINE_INNER *must* be the default; where there are vertical lines drawn across an inner line, the character at that position should indicate that the vertical line goes both up and down from this horizontal line.
LINE_SUBTOP has only descenders in the middle, but goes both up and down at the far left & right edges.
LINE_TOP has only descenders.
No description provided by the author
No description provided by the author

# Variables

DefaultStyle is a TableStyle which can be used to get some simple default styling for a table, using ASCII characters for drawing borders.
MaxColumns represents the maximum number of columns that are available for display without wrapping around the right-hand side of the terminal window.

# Structs

A Cell denotes one cell of a table; it spans one row and a variable number of columns.
A CellStyle controls all style applicable to one Cell.
A Row represents one row of a Table, consisting of some number of Cell items.
A Separator is a horizontal rule line, with associated information which indicates where in a table it is, sufficient for simple cases to let clean tables be drawn.
A StraightSeparator is a horizontal line with associated information about what sort of position it takes in the table, so as to control which shapes will be used where vertical lines are expected to touch this horizontal line.
Table represents a terminal table.
TableStyle controls styling information for a Table as a whole.

# Interfaces

Element the interface that can draw a representation of the contents of a table cell.

# Type aliases

No description provided by the author