tableprinter

package
v0.0.1-alpha.8 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	WithColor    = tableprinter.WithColor
	WithPadding  = tableprinter.WithPadding
	WithTruncate = tableprinter.WithTruncate
)
View Source
var NoHeader = headerOption{}

NoHeader disable printing or checking for a table header.

Deprecated: use WithHeader unless required otherwise.

Functions

func DisplayURL

func DisplayURL(urlStr string) string

DisplayURL returns a copy of the string urlStr removing everything except the scheme, hostname, and path. If the scheme is not specified, "https" is assumed. If there is an error parsing urlStr then urlStr is returned without modification.

func DisplayWidth

func DisplayWidth(s string) int

func FormatSlice

func FormatSlice(values []string, lineLength uint, indent uint, prependWith string, appendWith string, sort bool) string

FormatSlice concatenates elements of the given string slice into a well-formatted, possibly multiline, string with specific line length limit. Elements can be optionally surrounded by custom strings (e.g., quotes or brackets). If the lineLength argument is non-positive, no line length limit will be applied.

func FuzzyAgo

func FuzzyAgo(a, b time.Time) string

func FuzzyAgoAbbr

func FuzzyAgoAbbr(a, b time.Time) string

FuzzyAgoAbbr is an abbreviated version of FuzzyAgo. It returns a human readable string of the time duration between a and b that is estimated to the nearest unit of time.

func Indent

func Indent(s, indent string) string

func PadRight

func PadRight(maxWidth int, s string) string

func Pluralize

func Pluralize(num int, thing string) string

func RemoveDiacritics

func RemoveDiacritics(value string) string

RemoveDiacritics returns the input value without "diacritics", or accent marks

func RemoveExcessiveWhitespace

func RemoveExcessiveWhitespace(s string) string

RemoveExcessiveWhitespace returns a copy of the string s with excessive whitespace removed.

func Title

func Title(s string) string

Title returns a copy of the string s with all Unicode letters that begin words mapped to their Unicode title case.

func Truncate

func Truncate(maxWidth int, s string) string

func WithHeader

func WithHeader(columns ...string) headerOption

WithHeader defines the column names for a table. Panics if columns is nil or empty.

Types

type TablePrinter

type TablePrinter struct {
	tableprinter.TablePrinter
	// contains filtered or unexported fields
}

func New

func New(ios *iostreams.IOStreams, headers headerOption) *TablePrinter

New creates a TablePrinter from an IOStreams.

func NewWithWriter

func NewWithWriter(w io.Writer, isTTY bool, maxWidth int, cs *iostreams.ColorScheme, headers headerOption) *TablePrinter

NewWithWriter creates a TablePrinter from a Writer, whether the output is a terminal, the terminal width, and more.

func (*TablePrinter) AddTimeField

func (tp *TablePrinter) AddTimeField(now, t time.Time, c func(string) string)

AddTimeField in TTY mode displays the fuzzy time difference between now and t. In non-TTY mode it just displays t with the time.RFC3339 format.

func (*TablePrinter) IsTTY

func (t *TablePrinter) IsTTY() bool

IsTTY gets whether the TablePrinter will render to a terminal.

Jump to

Keyboard shortcuts

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