colfmt

package
v2.1.4 Latest Latest
Warning

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

Go to latest
Published: May 26, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

The colfmt package supplies various implementations of the col.Formatter interface.

Index

Constants

View Source
const DfltTimeFormat = "2006/01/02 15:04:05.000"

DfltTimeFormat is the format that will be used by the Time Formatter for printing out times if no other format is given. Note that the order of the date is Year/Month/Day not Year/Day/Month

Variables

This section is empty.

Functions

This section is empty.

Types

type Float

type Float struct {
	// W gives the minimum space to be taken by the formatted value
	W int
	// Prec gives the precision with which to print the value when formatted
	// Negative values are treated as zero
	Prec int
	// IgnoreNil, if set to true will make nil values print as the empty string
	IgnoreNil bool
	// Zeroes records any desired special handling for zero values
	Zeroes *FloatZeroHandler
}

Float records the values needed for the formatting of a float(64/32) value

func (*Float) Formatted

func (f *Float) Formatted(v interface{}) string

Formatted returns the value formatted as a float

func (Float) Just

func (f Float) Just() col.Justification

Just returns the justification of the value

func (Float) Width

func (f Float) Width() int

Width returns the intended width of the value. An invalid width or one incompatible with the given precision is ignored

type FloatZeroHandler

type FloatZeroHandler struct {
	// Handle, if set to true will check if the value to be printed is zero
	// (or closer than the given precision can reveal) and if so it will
	// print the Replacement string instead. The string printed will not be
	// wider than the minimum space indicated by the given width
	Handle bool
	// Replace is the value to be printed for zero if Handle is true
	Replace string
	// contains filtered or unexported fields
}

FloatZeroHandler is a mixin for handling zero values for columns taking floats

func (*FloatZeroHandler) GetZeroStr

func (fzh *FloatZeroHandler) GetZeroStr(prec int, v interface{}) (bool, string)

GetZeroStr calculates the appropriate zero string and returns it with a boolean indicating whether it should be used or not (if the value passed was actually zero)

type Int

type Int struct {
	// W gives the minimum space to be taken by the formatted value
	W int
	// IgnoreNil, if set to true will make nil values print as the empty string
	IgnoreNil bool
	// HandleZeroes, if set to true will check if the value to be printed is
	// zero and if so it will print the ZeroReplacement string instead. The
	// string printed will not be wider than the minimum space given by the W
	// value
	HandleZeroes bool
	// ZeroReplacement is the value to be printed for zero if HandleZeroes is
	// true
	ZeroReplacement string
}

Int records the values needed for the formatting of an int value

func (Int) Formatted

func (f Int) Formatted(v interface{}) string

Formatted returns the value formatted as an int

func (Int) Just

func (f Int) Just() col.Justification

Just returns the justification of the value

func (Int) Width

func (f Int) Width() int

Width returns the intended width of the value

type Percent

type Percent struct {
	// W gives the minimum space to be taken by the formatted value
	W int
	// Prec gives the precision with which to print the value when formatted
	// Negative values are treated as zero
	Prec int
	// IgnoreNil, if set to true will make nil values print as the empty string
	IgnoreNil bool
	// SuppressPct, if set to true will cause the '%' sign not to be printed
	SuppressPct bool
	// Zeroes records any desired special handling for zero values
	Zeroes *FloatZeroHandler
}

Percent records the values needed for the formatting of a proportion as a percentage value. The value is expected to be a proportion and so is multiplied by 100 to convert it into a percentage value and then a % sign is added to the end (unless SuppressPct is set to true)

func (*Percent) Formatted

func (f *Percent) Formatted(v interface{}) string

Formatted returns the value formatted as a percentage

func (Percent) Just

func (f Percent) Just() col.Justification

Just returns the justification of the value

func (Percent) Width

func (f Percent) Width() int

Width returns the intended width of the value. An invalid width or one incompatible with the given precision is ignored

type String

type String struct {
	// W gives the minimum width of the string that should be printed
	W int
	// MaxW gives the maximum width of the string, if it is set to zero then
	// no limit is applied. If it is set to a negative value then the W
	// value is used. If it is a positive value then that is used
	MaxW int
	// StrJust gives the justification to be used
	StrJust col.Justification
	// IgnoreNil, if set to true will make nil values print as the empty string
	IgnoreNil bool
}

String records the values needed for the formatting of a string value.

func (String) Formatted

func (f String) Formatted(v interface{}) string

Formatted returns the value formatted as a string

func (String) Just

func (f String) Just() col.Justification

Just returns the justification of the value

func (String) Width

func (f String) Width() int

Width returns the intended width of the value

type Time

type Time struct {
	W         int
	Format    string
	IgnoreNil bool
}

Time records the values needed for the formatting of a time value

func (*Time) Formatted

func (f *Time) Formatted(v interface{}) string

Formatted returns the value formatted as a time. If the format string is not set then it is set to the DfltTimeFormat.

func (Time) Just

func (f Time) Just() col.Justification

Just returns the justification of the value

func (*Time) Width

func (f *Time) Width() int

Width returns the intended width of the value. If it is set to zero then the length of the format string is used as a reasonable (but imperfect) value. If the format string is not set then it is set to the DfltTimeFormat before the width is calculated.

Jump to

Keyboard shortcuts

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