Documentation
¶
Overview ¶
Package tblfmt provides streaming table encoders for result sets (ie, from a database).
Index ¶
- func Encode(w io.Writer, resultSet ResultSet, params map[string]string, options ...Option) error
- func EncodeAll(w io.Writer, resultSet ResultSet, params map[string]string, options ...Option) 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 WithEncoder(encoder func(interface{}) ([]byte, error)) 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 WithMask(mask string) EscapeFormatterOption
- func WithNumericLocale(enable bool, locale string) EscapeFormatterOption
- func WithTimeFormat(timeFormat string) EscapeFormatterOption
- func WithTimeLocation(timeLocation *time.Location) EscapeFormatterOption
- type ExpandedEncoder
- type Formatter
- type JSONEncoder
- type LineStyle
- type Option
- func FormatterOptionFromMap(opts map[string]string) Option
- func WithBorder(border int) Option
- func WithColumnTypes(columnTypes func(ResultSet, []interface{}, int) error) Option
- func WithColumnTypesFunc(f func(*sql.ColumnType) (interface{}, error)) 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 Summary) 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 Summary
- type TableEncoder
- type TemplateEncoder
- type UnalignedEncoder
- type Value
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Encode ¶
Encode encodes the result set to the writer using the supplied map params and any additional options.
func EncodeAll ¶
EncodeAll encodes all result sets to the writer using the supplied map params and any additional 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" // ErrResultSetReturnedInvalidColumnTypes is the result set returned invalid column types error. ErrResultSetReturnedInvalidColumnTypes Error = "result set returned invalid column types" // 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" // ErrInvalidCSVFieldSeparator is the invalid csv field separator error. ErrInvalidCSVFieldSeparator Error = "invalid csv 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.
When the encoder is not nil, then it will be passed any map[string]interface{} and []interface{} values encountered, otherwise the stdlib's encoding/json.Encoder will be used.
func NewEscapeFormatter ¶
func NewEscapeFormatter(opts ...EscapeFormatterOption) *EscapeFormatter
NewEscapeFormatter creates a escape formatter to handle basic Go values, such as []byte, string, time.Time, and sql.Null*. Formatting for map[string]interface{} and []interface{} will be passed to a marshaler provided by WithEncoder, 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 WithEncoder ¶ added in v0.10.0
func WithEncoder(encoder func(interface{}) ([]byte, error)) EscapeFormatterOption
WithEncoder is an escape formatter option to set a standard Go encoder to use for encoding the value.
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 WithMask ¶
func WithMask(mask string) EscapeFormatterOption
WithMask is an escape formatter option to set the mask used for empty headers.
func WithNumericLocale ¶ added in v0.10.0
func WithNumericLocale(enable bool, locale string) EscapeFormatterOption
WithNumericLocale sets the numeric locale printer.
func WithTimeFormat ¶
func WithTimeFormat(timeFormat string) EscapeFormatterOption
WithTimeFormat is an escape formatter option to set the time format used for time values.
func WithTimeLocation ¶ added in v0.13.1
func WithTimeLocation(timeLocation *time.Location) EscapeFormatterOption
WithTimeLocation is an escape formatter option to set the time location 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 FormatterOptionFromMap ¶ added in v0.11.1
FormatterOptionFromMap builds formatter encoding options from the named options.
func WithBorder ¶
WithBorder is a encoder option to set the border size.
func WithColumnTypes ¶ added in v0.12.0
WithColumnTypes is a encoder option to set a func to use for building column types.
func WithColumnTypesFunc ¶ added in v0.12.0
func WithColumnTypesFunc(f func(*sql.ColumnType) (interface{}, error)) Option
WithColumnTypesFunc is a encoder option to set a func to build each column's type.
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 table summary.
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 Summary ¶ added in v0.13.0
Summary is the interface for a summary map.
func DefaultTableSummary ¶
func DefaultTableSummary() Summary
DefaultTableSummary is the default table summary.
Default table summaries look like the following:
(3 rows)
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.