mintab

package module
v0.0.43 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2024 License: MIT Imports: 7 Imported by: 2

README

mintab

CI codecov Go Reference Go Report Card

mintab is a minimum ASCII table utilities written in Go

Motivation

While tablewriter is useful, I wanted a smaller package with features such as backlog format support that tablewriter does not have.

Format

Text

text

Text merged

text_merged

Compressed-text merged

text_compressed

Markdown merged

markdown

Backlog merged

backlog

Support

  • Text table format
  • Markdown table format
  • Backlog table format
  • Group rows based on previous field value
  • Ignore specified columns
  • Escape HTML special characters

Notes

  • Only non-nested struct slices are accepted
  • Using reflect

Usage

example

Author

nekrassov01

License

MIT

Documentation

Index

Constants

View Source
const (
	DefaultEmptyFieldPlaceholder         = "-"
	DefaultWordDelimiter                 = "\n"
	MarkdownDefaultEmptyFieldPlaceholder = "\\-"
	MarkdownDefaultWordDelimiter         = "<br>"
	BacklogDefaultEmptyFieldPlaceholder  = "-"
	BacklogDefaultWordDelimiter          = "&br;"
)

Default values for table rendering.

View Source
const Version = "0.0.43"

Variables

View Source
var Formats = []string{
	"text",
	"compressed",
	"markdown",
	"backlog",
}

Formats holds the string representations of each format constant.

Functions

This section is empty.

Types

type Format added in v0.0.30

type Format int

Format defines the output format of the content.

const (
	FormatText           Format = iota // Plain text format.
	FormatCompressedText               // Compressed plain text format.
	FormatMarkdown                     // Markdown format.
	FormatBacklog                      // Backlog-specific format.
)

Enumeration of supported output formats.

func (Format) String added in v0.0.30

func (o Format) String() string

String returns the string representation of a Format. If the format is not within the predefined range, an empty string is returned.

type Option

type Option func(*Table)

Option defines a type for functional options used to configure a Table.

func WithEmptyFieldPlaceholder

func WithEmptyFieldPlaceholder(emptyFieldPlaceholder string) Option

WithEmptyFieldPlaceholder sets the placeholder for empty fields.

func WithEscape added in v0.0.34

func WithEscape(has bool) Option

WithEscape enables or disables escaping of field content.

func WithFormat added in v0.0.4

func WithFormat(format Format) Option

WithFormat sets the output format of the table.

func WithHeader added in v0.0.4

func WithHeader(has bool) Option

WithHeader configures the rendering of the table header.

func WithIgnoreFields

func WithIgnoreFields(ignoreFields []int) Option

WithIgnoreFields specifies columns to be ignored during rendering.

func WithMargin added in v0.0.34

func WithMargin(margin int) Option

WithMargin sets the margin size around cell content.

func WithMergeFields

func WithMergeFields(mergeFields []int) Option

WithMergeFields specifies columns for merging based on their content.

func WithWordDelimiter added in v0.0.3

func WithWordDelimiter(wordDelimiter string) Option

WithWordDelimiter sets the delimiter for splitting words in a field.

type Table

type Table struct {
	// contains filtered or unexported fields
}

Table represents a table structure for rendering data in a matrix format.

func New

func New(w io.Writer, opts ...Option) *Table

New instantiates a new Table with the specified writer and options.

func (*Table) Load added in v0.0.4

func (t *Table) Load(input any) error

Load validates the input and converts it into table data. Returns an error if the input is not a slice or if it's empty.

func (*Table) Out

func (t *Table) Out()

Out renders the table to the specified writer. It supports markdown and backlog formats for easy copying and pasting.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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