formatter

package
v0.0.0-...-9997ea8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2026 License: BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package formatter renders the results of a Tarantool console request.

A Tarantool console answers with a YAML document; MakeOutput turns that document into the text shown to the user in one of the [Format]s: the YAML itself, a Lua expression, or tables (row per record, or transposed). The table formats take their look from Opts: pseudographics on or off, a maximum column width and a TableDialect (terminal, Markdown or Jira).

The output is what tt prints in its consoles, byte for byte, so a module that renders console results through this package prints them the same way tt's own commands do.

Index

Constants

This section is empty.

Variables

View Source
var StyleWithoutGraphics = table.BoxStyle{
	BottomLeft:       " ",
	BottomRight:      " ",
	BottomSeparator:  " ",
	EmptySeparator:   text.RepeatAndTrim(" ", text.RuneWidthWithoutEscSequences(" ")),
	Left:             " ",
	LeftSeparator:    " ",
	MiddleHorizontal: " ",
	MiddleSeparator:  " ",
	MiddleVertical:   " ",
	PaddingLeft:      " ",
	PaddingRight:     " ",
	PageSeparator:    "\n",
	Right:            " ",
	RightSeparator:   " ",
	TopLeft:          " ",
	TopRight:         " ",
	TopSeparator:     " ",
	UnfinishedRow:    " ",
}

StyleWithoutGraphics defines a style without graphics like below: col1 col2 col3 col4 1 477 Elizabeth 12 3 2804 David 33 4 1161 William 81 5 1172 Jack 35 6 1064 William 25.

Functions

func MakeOutput

func MakeOutput(format Format, data string, opts Opts) (string, error)

MakeOutput returns formatted output from a YAML data depending on the specified output format and passed formatting options.

Types

type Format

type Format int

Format defines a set of supported output format.

const (
	// YamlFormat prints the YAML document the console answered with.
	YamlFormat Format = iota
	// LuaFormat prints the values as a Lua expression.
	LuaFormat
	// TableFormat prints the values as tables, a row per record.
	TableFormat
	// TTableFormat prints the values as transposed tables, a column per
	// record.
	TTableFormat
	// FormatsAmount is the number of formats; it is not a format itself.
	// Every Format is below it, so a console can cycle through them.
	FormatsAmount
)
const (
	// DefaultFormat is a default format.
	DefaultFormat Format = YamlFormat
)

func ParseFormat

func ParseFormat(str string) (Format, bool)

ParseFormat parses a output format string representation. It supports mixed case letters.

func (Format) String

func (f Format) String() string

String returns a string representation of the output format.

type Opts

type Opts struct {
	// Graphics sets on/off the output of pseudographics characters.
	Graphics bool
	// ColumnWidthMax sets is a maximum width of columns.
	ColumnWidthMax int
	// TableDialect sets a current table dialect.
	TableDialect TableDialect
}

Opts contains formatting options.

type TableDialect

type TableDialect int

TableDialect defines a set of supported table dialect.

const (
	// DefaultTableDialect draws tables for a terminal, with pseudographics
	// or with spaces as [Opts.Graphics] says.
	DefaultTableDialect TableDialect = iota
	// MarkdownTableDialect writes tables to paste into Markdown.
	MarkdownTableDialect
	// JiraTableDialect writes tables to paste into Jira.
	JiraTableDialect
)

func ParseTableDialect

func ParseTableDialect(str string) (TableDialect, bool)

ParseTableDialect parses a table dialect string representation. It supports mixed case letters.

func (TableDialect) String

func (d TableDialect) String() string

String returns a string representation of the table dialect.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL