Documentation
ΒΆ
Overview ΒΆ
Package tblfmt provides streaming table encoders for result sets (ie, from a database).
Index ΒΆ
- func DefaultTableSummary() map[int]func(io.Writer, int) (int, error)
- func Encode(w io.Writer, resultSet ResultSet, options map[string]string) error
- func EncodeAll(w io.Writer, resultSet ResultSet, options map[string]string) error
- func EncodeAsciiDoc(w io.Writer, resultSet ResultSet, opts ...Option) error
- func EncodeAsciiDocAll(w io.Writer, resultSet ResultSet, opts ...Option) error
- func EncodeCSV(w io.Writer, resultSet ResultSet, opts ...Option) error
- func EncodeCSVAll(w io.Writer, resultSet ResultSet, opts ...Option) error
- func EncodeExpanded(w io.Writer, resultSet ResultSet, opts ...Option) error
- func EncodeExpandedAll(w io.Writer, resultSet ResultSet, opts ...Option) error
- func EncodeHTML(w io.Writer, resultSet ResultSet, opts ...Option) error
- func EncodeHTMLAll(w io.Writer, resultSet ResultSet, opts ...Option) error
- func EncodeJSON(w io.Writer, resultSet ResultSet, opts ...Option) error
- func EncodeJSONAll(w io.Writer, resultSet ResultSet, opts ...Option) error
- func EncodeTable(w io.Writer, resultSet ResultSet, opts ...Option) error
- func EncodeTableAll(w io.Writer, resultSet ResultSet, opts ...Option) error
- func EncodeTemplate(w io.Writer, resultSet ResultSet, opts ...Option) error
- func EncodeTemplateAll(w io.Writer, resultSet ResultSet, opts ...Option) error
- func EncodeUnaligned(w io.Writer, resultSet ResultSet, opts ...Option) error
- func EncodeUnalignedAll(w io.Writer, resultSet ResultSet, opts ...Option) error
- func EncodeVertical(w io.Writer, resultSet ResultSet, opts ...Option) error
- func EncodeVerticalAll(w io.Writer, resultSet ResultSet, opts ...Option) error
- func FromMap(opts map[string]string) (Builder, []Option)
- type Align
- type Builder
- type CrosstabView
- type Encoder
- func NewAsciiDocEncoder(resultSet ResultSet, opts ...Option) (Encoder, error)
- func NewCSVEncoder(resultSet ResultSet, opts ...Option) (Encoder, error)
- func NewExpandedEncoder(resultSet ResultSet, opts ...Option) (Encoder, error)
- func NewHTMLEncoder(resultSet ResultSet, opts ...Option) (Encoder, error)
- func NewJSONEncoder(resultSet ResultSet, opts ...Option) (Encoder, error)
- func NewTableEncoder(resultSet ResultSet, opts ...Option) (Encoder, error)
- func NewTemplateEncoder(resultSet ResultSet, opts ...Option) (Encoder, error)
- func NewUnalignedEncoder(resultSet ResultSet, opts ...Option) (Encoder, error)
- func NewVerticalEncoder(resultSet ResultSet, opts ...Option) (Encoder, error)
- type Error
- type EscapeFormatter
- type EscapeFormatterOption
- func WithHeaderAlign(a Align) EscapeFormatterOption
- func WithInvalid(invalid string) EscapeFormatterOption
- func WithIsJSON(isJSON bool) EscapeFormatterOption
- func WithIsRaw(isRaw bool, sep, quote rune) EscapeFormatterOption
- func WithJSONConfig(prefix, indent string, escapeHTML bool) EscapeFormatterOption
- func WithMarshaler(marshaler func(interface{}) ([]byte, error)) EscapeFormatterOption
- func WithMask(mask string) EscapeFormatterOption
- func WithTimeFormat(timeFormat string) EscapeFormatterOption
- type ExpandedEncoder
- type Formatter
- type JSONEncoder
- type LineStyle
- type Option
- func WithBorder(border int) Option
- func WithCount(count int) Option
- func WithEmpty(empty string) Option
- func WithExecutor(executor func(io.Writer, interface{}) error) Option
- func WithFormatter(formatter Formatter) Option
- func WithFormatterOptions(opts ...EscapeFormatterOption) Option
- func WithInline(inline bool) Option
- func WithLineStyle(lineStyle LineStyle) Option
- func WithLowerColumnNames(lowerColumnNames bool) Option
- func WithMinExpandWidth(w int) Option
- func WithMinPagerHeight(h int) Option
- func WithMinPagerWidth(w int) Option
- func WithNewline(newline string) Option
- func WithPager(p string) Option
- func WithParams(params ...string) Option
- func WithQuote(quote rune) Option
- func WithRawTemplate(text, typ string) Option
- func WithSeparator(sep rune) Option
- func WithSkipHeader(s bool) Option
- func WithSummary(summary map[int]func(io.Writer, int) (int, error)) Option
- func WithTableAttributes(a string) Option
- func WithTemplate(name string) Option
- func WithTitle(title string) Option
- func WithUseColumnTypes(useColumnTypes bool) Option
- func WithWidths(widths ...int) Option
- type ResultSet
- type TableEncoder
- type TemplateEncoder
- type UnalignedEncoder
- type Value
Examples ΒΆ
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
func DefaultTableSummary ΒΆ
DefaultTableSummary is the default table summary.
Default table summaries look like the following:
(3 rows)
func EncodeAll ΒΆ
EncodeAll encodes all result sets to the writer using the supplied map options.
Example ΒΆ
package main
import (
"fmt"
"log"
"os"
"github.com/xo/tblfmt"
)
// result is a simple type providing a tblfmt.ResultSet.
type result struct {
pos int
cols []string
vals [][]interface{}
}
// Columns satisfies the tblfmt.ResultSet interface.
func (res *result) Columns() ([]string, error) {
return res.cols, nil
}
// Next satisfies the tblfmt.ResultSet interface.
func (res *result) Next() bool {
return res.pos < len(res.vals)
}
// Scan satisfies the tblfmt.ResultSet interface.
func (res *result) Scan(vals ...interface{}) error {
for i := range vals {
x, ok := vals[i].(*interface{})
if !ok {
return fmt.Errorf("scan for col %d expected *interface{}, got: %T", i, vals[i])
}
*x = res.vals[res.pos][i]
}
res.pos++
return nil
}
// Err satisfies the tblfmt.ResultSet interface.
func (res *result) Err() error {
return nil
}
// Close satisfies the tblfmt.ResultSet interface.
func (res *result) Close() error {
return nil
}
// NextResultSet satisfies the tblfmt.ResultSet interface.
func (res *result) NextResultSet() bool {
return false
}
// getDatabaseResults returns a tblfmt.ResultSet, which is an interface that is
// compatible with Go's standard
func getDatabaseResults() tblfmt.ResultSet {
return &result{
cols: []string{"author_id", "name", "z"},
vals: [][]interface{}{
{14, "a\tb\tc\td", nil},
{15, "aoeu\ntest\n", nil},
{2, "θ’\tθ’\t\tθ’", nil},
},
}
}
func main() {
res := getDatabaseResults()
if err := tblfmt.EncodeAll(os.Stdout, res, map[string]string{
"format": "csv",
"fieldsep": "|",
"null": "<nil>",
}); err != nil {
log.Fatal(err)
}
}
Output: author_id,name,z 14,"a b c d",<nil> 15,"aoeu test ",<nil> 2,"θ’ θ’ θ’",<nil>
func EncodeAsciiDoc ΒΆ added in v0.6.2
EncodeAsciiDoc encodes the result set to the writer using the asciidoc template and the supplied encoding options.
func EncodeAsciiDocAll ΒΆ added in v0.6.2
EncodeAsciiDoc encodes the result set to the writer using the asciidoc template and the supplied encoding options.
func EncodeCSV ΒΆ
EncodeCSV encodes the result set to the writer unaligned using the supplied encoding options.
func EncodeCSVAll ΒΆ
EncodeCSVAll encodes all result sets to the writer unaligned using the supplied encoding options.
func EncodeExpanded ΒΆ
EncodeExpanded encodes result set to the writer as a table using the supplied encoding options.
func EncodeExpandedAll ΒΆ
EncodeExpandedAll encodes all result sets to the writer as a table using the supplied encoding options.
func EncodeHTML ΒΆ added in v0.6.2
EncodeHTML encodes the result set to the writer using the html template and the supplied encoding options.
func EncodeHTMLAll ΒΆ added in v0.6.2
EncodeHTML encodes the result set to the writer using the html template and the supplied encoding options.
func EncodeJSON ΒΆ
EncodeJSON encodes the result set to the writer as JSON using the supplied encoding options.
func EncodeJSONAll ΒΆ
EncodeJSONAll encodes all result sets to the writer as JSON using the supplied encoding options.
func EncodeTable ΒΆ
EncodeTable encodes result set to the writer as a table using the supplied encoding options.
func EncodeTableAll ΒΆ
EncodeTableAll encodes all result sets to the writer as a table using the supplied encoding options.
func EncodeTemplate ΒΆ
EncodeTemplate encodes the result set to the writer using a template from the supplied encoding options.
func EncodeTemplateAll ΒΆ
EncodeTemplateAll encodes all result sets to the writer using a template from the supplied encoding options.
Example ΒΆ
package main
import (
"fmt"
"log"
"os"
"github.com/xo/tblfmt"
)
// result is a simple type providing a tblfmt.ResultSet.
type result struct {
pos int
cols []string
vals [][]interface{}
}
// Columns satisfies the tblfmt.ResultSet interface.
func (res *result) Columns() ([]string, error) {
return res.cols, nil
}
// Next satisfies the tblfmt.ResultSet interface.
func (res *result) Next() bool {
return res.pos < len(res.vals)
}
// Scan satisfies the tblfmt.ResultSet interface.
func (res *result) Scan(vals ...interface{}) error {
for i := range vals {
x, ok := vals[i].(*interface{})
if !ok {
return fmt.Errorf("scan for col %d expected *interface{}, got: %T", i, vals[i])
}
*x = res.vals[res.pos][i]
}
res.pos++
return nil
}
// Err satisfies the tblfmt.ResultSet interface.
func (res *result) Err() error {
return nil
}
// Close satisfies the tblfmt.ResultSet interface.
func (res *result) Close() error {
return nil
}
// NextResultSet satisfies the tblfmt.ResultSet interface.
func (res *result) NextResultSet() bool {
return false
}
// getDatabaseResults returns a tblfmt.ResultSet, which is an interface that is
// compatible with Go's standard
func getDatabaseResults() tblfmt.ResultSet {
return &result{
cols: []string{"author_id", "name", "z"},
vals: [][]interface{}{
{14, "a\tb\tc\td", nil},
{15, "aoeu\ntest\n", nil},
{2, "θ’\tθ’\t\tθ’", nil},
},
}
}
func main() {
res := getDatabaseResults()
if err := tblfmt.EncodeTemplateAll(os.Stdout, res, tblfmt.WithTemplate("html")); err != nil {
log.Fatal(err)
}
}
Output: <table> <caption></caption> <thead> <tr> <th align="left">author_id</th> <th align="left">name</th> <th align="left">z</th> </tr> </thead> <tbody> <tr> <td align="right">14</td> <td align="left">a b c d</td> <td align="left"></td> </tr> <tr> <td align="right">15</td> <td align="left">aoeu test </td> <td align="left"></td> </tr> <tr> <td align="right">2</td> <td align="left">θ’ θ’ θ’</td> <td align="left"></td> </tr> </tbody> </table>
func EncodeUnaligned ΒΆ added in v0.5.0
EncodeUnaligned encodes the result set to the writer unaligned using the supplied encoding options.
func EncodeUnalignedAll ΒΆ added in v0.5.0
EncodeUnalignedAll encodes all result sets to the writer unaligned using the supplied encoding options.
func EncodeVertical ΒΆ added in v0.6.2
EncodeVertical encodes the result set to the writer using the vertical template and the supplied encoding options.
func EncodeVerticalAll ΒΆ added in v0.6.2
EncodeVertical encodes the result set to the writer using the vertical template and the supplied encoding options.
Types ΒΆ
type CrosstabView ΒΆ added in v0.5.0
type CrosstabView struct {
// contains filtered or unexported fields
}
CrosstabView is a crosstab view for result sets.
CAUTION:
A design decision was made to not support multiple result sets, and to force the user to create a new crosstab view for each result set. As such, NextResultSet always returns false, and any use of this view should take care when using inside a loop or passing to other code that calls NextResultSet.
func (*CrosstabView) Close ΒΆ added in v0.5.0
func (view *CrosstabView) Close() error
Close satisfies the ResultSet interface.
func (*CrosstabView) Columns ΒΆ added in v0.5.0
func (view *CrosstabView) Columns() ([]string, error)
Columns satisfies the ResultSet interface.
func (*CrosstabView) Err ΒΆ added in v0.5.0
func (view *CrosstabView) Err() error
Err satisfies the ResultSet interface.
func (*CrosstabView) Next ΒΆ added in v0.5.0
func (view *CrosstabView) Next() bool
Next satisfies the ResultSet interface.
func (*CrosstabView) NextResultSet ΒΆ added in v0.5.0
func (view *CrosstabView) NextResultSet() bool
NextResultSet satisfies the ResultSet interface.
func (*CrosstabView) Scan ΒΆ added in v0.5.0
func (view *CrosstabView) Scan(v ...interface{}) error
Scan satisfies the ResultSet interface.
type Encoder ΒΆ
Encoder is the shared interface for encoders.
func NewAsciiDocEncoder ΒΆ added in v0.5.0
NewAsciiDocEncoder creates a new asciidoc template encoder using the provided options.
func NewCSVEncoder ΒΆ
NewCSVEncoder creates a new csv encoder using the provided options.
Creates an unaligned encoder using the default field separator ',' and field quote of '"'.
func NewExpandedEncoder ΒΆ
NewExpandedEncoder creates a new expanded table encoder using the provided options.
func NewHTMLEncoder ΒΆ added in v0.5.0
NewHTMLEncoder creates a new html template encoder using the provided options.
func NewJSONEncoder ΒΆ
NewJSONEncoder creates a new JSON encoder using the provided options.
func NewTableEncoder ΒΆ
NewTableEncoder creates a new table encoder using the provided options.
The table encoder has a default value of border 1, and a tab width of 8.
Example ΒΆ
package main
import (
"fmt"
"log"
"os"
"github.com/xo/tblfmt"
)
// result is a simple type providing a tblfmt.ResultSet.
type result struct {
pos int
cols []string
vals [][]interface{}
}
// Columns satisfies the tblfmt.ResultSet interface.
func (res *result) Columns() ([]string, error) {
return res.cols, nil
}
// Next satisfies the tblfmt.ResultSet interface.
func (res *result) Next() bool {
return res.pos < len(res.vals)
}
// Scan satisfies the tblfmt.ResultSet interface.
func (res *result) Scan(vals ...interface{}) error {
for i := range vals {
x, ok := vals[i].(*interface{})
if !ok {
return fmt.Errorf("scan for col %d expected *interface{}, got: %T", i, vals[i])
}
*x = res.vals[res.pos][i]
}
res.pos++
return nil
}
// Err satisfies the tblfmt.ResultSet interface.
func (res *result) Err() error {
return nil
}
// Close satisfies the tblfmt.ResultSet interface.
func (res *result) Close() error {
return nil
}
// NextResultSet satisfies the tblfmt.ResultSet interface.
func (res *result) NextResultSet() bool {
return false
}
// getDatabaseResults returns a tblfmt.ResultSet, which is an interface that is
// compatible with Go's standard
func getDatabaseResults() tblfmt.ResultSet {
return &result{
cols: []string{"author_id", "name", "z"},
vals: [][]interface{}{
{14, "a\tb\tc\td", nil},
{15, "aoeu\ntest\n", nil},
{2, "θ’\tθ’\t\tθ’", nil},
},
}
}
func main() {
res := getDatabaseResults()
enc, err := tblfmt.NewTableEncoder(
res,
tblfmt.WithBorder(2),
tblfmt.WithLineStyle(tblfmt.UnicodeDoubleLineStyle()),
tblfmt.WithWidths(20, 20),
tblfmt.WithSummary(tblfmt.DefaultTableSummary()),
)
if err != nil {
log.Fatal(err)
}
if err := enc.EncodeAll(os.Stdout); err != nil {
log.Fatal(err)
}
}
Output: ββββββββββββββββββββββββ¦ββββββββββββββββββββββββββββ¦ββββ β author_id β name β z β β βββββββββββββββββββββββ¬ββββββββββββββββββββββββββββ¬ββββ£ β 14 β a b c d β β β 15 β aoeu β΅β β β β test β΅β β β β β β β 2 β θ’ θ’ θ’ β β ββββββββββββββββββββββββ©ββββββββββββββββββββββββββββ©ββββ (3 rows)
func NewTemplateEncoder ΒΆ
NewTemplateEncoder creates a new template encoder using the provided options.
func NewUnalignedEncoder ΒΆ added in v0.5.0
NewUnalignedEncoder creates a new unaligned encoder using the provided options.
type Error ΒΆ
type Error string
Error is an error.
const ( // ErrResultSetIsNil is the result set is nil error. ErrResultSetIsNil Error = "result set is nil" // ErrResultSetHasNoColumnTypes is the result set has no column types error. ErrResultSetHasNoColumnTypes Error = "result set has no column types" // ErrResultSetHasNoColumns is the result set has no columns error. ErrResultSetHasNoColumns Error = "result set has no columns" // ErrInvalidFormat is the invalid format error. ErrInvalidFormat Error = "invalid format" // ErrInvalidLineStyle is the invalid line style error. ErrInvalidLineStyle Error = "invalid line style" // ErrInvalidTemplate is the invalid template error. ErrInvalidTemplate Error = "invalid template" // ErrInvalidFieldSeparator is the invalid field separator error. ErrInvalidFieldSeparator Error = "invalid field separator" // ErrInvalidColumnParams is the invalid column params error. ErrInvalidColumnParams Error = "invalid column params" // ErrCrosstabResultMustHaveAtLeast3Columns is the crosstab result must // have at least 3 columns error. ErrCrosstabResultMustHaveAtLeast3Columns Error = "crosstab result must have at least 3 columns" // ErrCrosstabDataColumnMustBeSpecifiedWhenQueryReturnsMoreThanThreeColumnsA // is the data column must be specified when query returns more than three // columns error. ErrCrosstabDataColumnMustBeSpecifiedWhenQueryReturnsMoreThanThreeColumns Error = "data column must be specified when query returns more than three columns" // ErrCrosstabVerticalAndHorizontalColumnsMustNotBeSame is the crosstab // vertical and horizontal columns must not be same error. ErrCrosstabVerticalAndHorizontalColumnsMustNotBeSame Error = "crosstab vertical and horizontal columns must not be same" // ErrCrosstabVerticalColumnNotInResult is the crosstab vertical column not // in result error. ErrCrosstabVerticalColumnNotInResult Error = "crosstab vertical column not in result" // ErrCrosstabHorizontalColumnNotInResult is the crosstab horizontal column // not in result error. ErrCrosstabHorizontalColumnNotInResult Error = "crosstab horizontal column not in result" // ErrCrosstabDataColumnNotInResult is the crosstab data column not in // result error. ErrCrosstabDataColumnNotInResult Error = "crosstab data column not in result" // ErrCrosstabHorizontalSortColumnNotInResult is the crosstab horizontal // sort column not in result error. ErrCrosstabHorizontalSortColumnNotInResult Error = "crosstab horizontal sort column not in result" // ErrCrosstabDuplicateVerticalAndHorizontalValue is the crosstab duplicate // vertical and horizontal value error. ErrCrosstabDuplicateVerticalAndHorizontalValue Error = "crosstab duplicate vertical and horizontal value" // ErrCrosstabHorizontalSortColumnIsNotANumber is the crosstab horizontal // sort column is not a number error. ErrCrosstabHorizontalSortColumnIsNotANumber Error = "crosstab horizontal sort column is not a number" )
Error values.
type EscapeFormatter ΒΆ
type EscapeFormatter struct {
// contains filtered or unexported fields
}
EscapeFormatter is an escaping formatter, that handles formatting the standard Go types.
If Marshaler is not nil, then it will be passed any map[string]interface{} and []interface{} values encountered. If nil, then the standard encoding/json.Encoder will be used instead.
func NewEscapeFormatter ΒΆ
func NewEscapeFormatter(opts ...EscapeFormatterOption) *EscapeFormatter
NewEscapeFormatter creates a escape formatter to handle basic Go values, such as []byte, string, time.Time. Formatting for map[string]interface{} and []interface{} will be passed to a marshaler provided by WithMarshaler, otherwise the standard encoding/json.Encoder will be used to marshal those values.
func (*EscapeFormatter) Format ΒΆ
func (f *EscapeFormatter) Format(vals []interface{}) ([]*Value, error)
Format satisfies the Formatter interface.
type EscapeFormatterOption ΒΆ
type EscapeFormatterOption func(*EscapeFormatter)
EscapeFormatterOption is an escape formatter option.
func WithHeaderAlign ΒΆ added in v0.2.0
func WithHeaderAlign(a Align) EscapeFormatterOption
WithHeaderAlign sets the alignment of header values.
func WithInvalid ΒΆ
func WithInvalid(invalid string) EscapeFormatterOption
WithInvalid is an escape formatter option to set the invalid value used when an invalid rune is encountered during escaping.
func WithIsJSON ΒΆ added in v0.5.0
func WithIsJSON(isJSON bool) EscapeFormatterOption
WithIsJSON is an escape formatter option to enable special escaping for JSON characters in non-complex values.
func WithIsRaw ΒΆ added in v0.5.0
func WithIsRaw(isRaw bool, sep, quote rune) EscapeFormatterOption
WithIsRaw is an escape formatter option to enable special escaping for raw characters in values.
func WithJSONConfig ΒΆ
func WithJSONConfig(prefix, indent string, escapeHTML bool) EscapeFormatterOption
WithJSONConfig is an escape formatter option to set the JSON encoding prefix, indent value, and whether or not to escape HTML. Passed to the standard encoding/json.Encoder when a marshaler has not been set on the escape formatter.
func WithMarshaler ΒΆ
func WithMarshaler(marshaler func(interface{}) ([]byte, error)) EscapeFormatterOption
WithMarshaler is an escape formatter option to set a standard Go encoder to use for encoding the value.
func WithMask ΒΆ
func WithMask(mask string) EscapeFormatterOption
WithMask is an escape formatter option to set the mask used for empty headers.
func WithTimeFormat ΒΆ
func WithTimeFormat(timeFormat string) EscapeFormatterOption
WithTimeFormat is an escape formatter option to set the time format used for time values.
type ExpandedEncoder ΒΆ
type ExpandedEncoder struct {
TableEncoder
}
ExpandedEncoder is a buffered, lookahead expanded table encoder for result sets.
type Formatter ΒΆ
type Formatter interface {
// Header returns a slice of formatted values for the provided headers.
Header([]string) ([]*Value, error)
// Format returns a slice of formatted value the provided row values.
Format([]interface{}) ([]*Value, error)
}
Formatter is the common interface for formatting values.
type JSONEncoder ΒΆ
type JSONEncoder struct {
// contains filtered or unexported fields
}
JSONEncoder is an unbuffered JSON encoder for result sets.
type LineStyle ΒΆ
LineStyle is a table line style.
See the ASCII, OldASCII, and Unicode styles below for predefined table styles.
Tables generally look like the following:
+-----------+---------------------------+---+ | author_id | name | z | +-----------+---------------------------+---+ | 14 | a b c d | | | 15 | aoeu +| | | | test +| | | | | | +-----------+---------------------------+---+
When border is 0, then no surrounding borders will be shown:
author_id name z
--------- ------------------------- -
14 a b c d
15 aoeu +
test +
When border is 1, then a border between columns will be shown:
author_id | name | z
-----------+---------------------------+---
14 | a b c d |
15 | aoeu +|
| test +|
| |
func ASCIILineStyle ΒΆ
func ASCIILineStyle() LineStyle
ASCIILineStyle is the ASCII line style for tables.
Tables using this style will look like the following:
+-----------+---------------------------+---+ | author_id | name | z | +-----------+---------------------------+---+ | 14 | a b c d | | | 15 | aoeu +| | | | test +| | | | | | +-----------+---------------------------+---+
func OldASCIILineStyle ΒΆ
func OldASCIILineStyle() LineStyle
OldASCIILineStyle is the old ASCII line style for tables.
Tables using this style will look like the following:
+-----------+---------------------------+---+ | author_id | name | z | +-----------+---------------------------+---+ | 14 | a b c d | | | 15 | aoeu | | | : test | | : | +-----------+---------------------------+---+
func UnicodeDoubleLineStyle ΒΆ
func UnicodeDoubleLineStyle() LineStyle
UnicodeDoubleLineStyle is the Unicode double line style for tables.
Tables using this style will look like the following:
βββββββββββββ¦ββββββββββββββββββββββββββββ¦ββββ β author_id β name β z β β ββββββββββββ¬ββββββββββββββββββββββββββββ¬ββββ£ β 14 β a b c d β β β 15 β aoeu β΅β β β β test β΅β β β β β β βββββββββββββ©ββββββββββββββββββββββββββββ©ββββ
func UnicodeLineStyle ΒΆ
func UnicodeLineStyle() LineStyle
UnicodeLineStyle is the Unicode line style for tables.
Tables using this style will look like the following:
βββββββββββββ¬ββββββββββββββββββββββββββββ¬ββββ β author_id β name β z β βββββββββββββΌββββββββββββββββββββββββββββΌββββ€ β 14 β a b c d β β β 15 β aoeu β΅β β β β test β΅β β β β β β βββββββββββββ΄ββββββββββββββββββββββββββββ΄ββββ
type Option ΒΆ
type Option interface {
// contains filtered or unexported methods
}
Option is a Encoder option.
func WithBorder ΒΆ
WithBorder is a encoder option to set the border size.
func WithExecutor ΒΆ added in v0.5.0
WithExecutor is a encoder option to set the executor.
func WithFormatter ΒΆ
WithFormatter is a encoder option to set a formatter for formatting values.
func WithFormatterOptions ΒΆ added in v0.7.1
func WithFormatterOptions(opts ...EscapeFormatterOption) Option
WithFormatterOptions is a encoder option to add additional formatter options.
func WithInline ΒΆ
WithInline is a encoder option to set the column headers as inline to the top line.
func WithLineStyle ΒΆ
WithLineStyle is a encoder option to set the table line style.
func WithLowerColumnNames ΒΆ added in v0.7.5
WithLowerColumnNames is a encoder option to lower case column names when column names are all caps.
func WithMinExpandWidth ΒΆ added in v0.3.0
WithMinExpandWidth is a encoder option to set maximum width before switching to expanded format.
func WithMinPagerHeight ΒΆ added in v0.3.0
WithMinPagerHeight is a encoder option to set maximum height before redirecting output to pager.
func WithMinPagerWidth ΒΆ added in v0.3.0
WithMinPagerWidth is a encoder option to set maximum width before redirecting output to pager.
func WithNewline ΒΆ
WithNewline is a encoder option to set the newline.
func WithParams ΒΆ added in v0.5.0
WithParams is a view option to set the column parameters.
func WithRawTemplate ΒΆ added in v0.5.0
WithRawTemplate is a encoder option to set a raw template of either "text" or "html" type.
func WithSeparator ΒΆ added in v0.5.0
WithSeparator is a encoder option to set the field separator.
func WithSkipHeader ΒΆ added in v0.4.0
WithSkipHeader is a encoder option to disable writing a header.
func WithSummary ΒΆ
WithSummary is a encoder option to set a summary callback map.
func WithTableAttributes ΒΆ added in v0.2.0
WithTableAttributes is a encoder option to set the table attributes.
func WithTemplate ΒΆ
WithTemplate is a encoder option to set a named template.
func WithUseColumnTypes ΒΆ added in v0.7.0
WithUseColumnTypes is a encoder option to use the result set's column types.
func WithWidths ΒΆ
WithWidths is a encoder option to set (minimum) widths for a column.
type ResultSet ΒΆ
type ResultSet interface {
Next() bool
Scan(...interface{}) error
Columns() ([]string, error)
Close() error
Err() error
NextResultSet() bool
}
ResultSet is the shared interface for a result set.
type TableEncoder ΒΆ
type TableEncoder struct {
// contains filtered or unexported fields
}
TableEncoder is a buffered, lookahead table encoder for result sets.
type TemplateEncoder ΒΆ
type TemplateEncoder struct {
// contains filtered or unexported fields
}
TemplateEncoder is an unbuffered template encoder for result sets.
type UnalignedEncoder ΒΆ added in v0.5.0
type UnalignedEncoder struct {
// contains filtered or unexported fields
}
UnalignedEncoder is an unbuffered, unaligned encoder for result sets.
Provides a way of encoding unaligned result sets in formats such as comma-separated value (CSV) or tab-separated value (TSV) files.
By default uses a field separator of '|', no quote separator, and record separator using the default newline for the platfom ("\r\n" on Windows, "\n" otherwise).
type Value ΒΆ
type Value struct {
// Buf is the formatted value.
Buf []byte
// Newlines are the positions of newline characters in Buf.
Newlines [][2]int
// Tabs are the positions of tab characters in Buf, split per line.
Tabs [][][2]int
// Width is the remaining width.
Width int
// Align indicates value alignment.
Align Align
// Raw tracks whether or not the value should be encoded or not.
Raw bool
// Quoted tracks whether or not a raw value should be quoted or not (ie,
// contains a space or non printable character).
Quoted bool
}
Value contains information pertaining to a formatted value.
func FormatBytes ΒΆ
func FormatBytes(src []byte, invalid []byte, invalidWidth int, isJSON, isRaw bool, sep, quote rune) *Value
FormatBytes parses src, saving escaped (encoded) and unescaped runes to a Value, along with tab and newline positions in the generated buf.