Documentation ¶
Overview ¶
The colfmt package supplies various implementations of the col.Formatter interface.
Index ¶
Constants ¶
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 // Verb specifies the formatting verb. If left unset it will use // 'f'. There will be a panic if it is not one of 'eEfFgGxX' Verb rune // TrimTrailingZeroes removes any trailing zeroes after the decimal // point. It leaves a zero immediately after the point TrimTrailingZeroes bool // ReformatOutOfBoundValues will generate a new format to be used if the // passed value is too big or too small to be shown in the space // available ReformatOutOfBoundValues bool }
Float records the values needed for the formatting of a float(64/32) value
func (Float) Just ¶
func (f Float) Just() col.Justification
Just returns the justification of the value
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 // Verb specifies the formatting verb. If left unset it will use // 'd'. There will be a panic if it is not one of 'bcdoOqxXU' Verb rune }
Int records the values needed for the formatting of an int 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) Just ¶
func (f Percent) Just() col.Justification
Just returns the justification of the value
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) Just ¶
func (f String) Just() col.Justification
Just returns the justification of the value
type Time ¶
Time records the values needed for the formatting of a time value
func (*Time) Formatted ¶
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
type WrappedString ¶ added in v2.2.0
type WrappedString struct { // W gives the width of the block that the string should fit within. This // must be set to some non-zero value. W int // IgnoreNil, if set to true will make nil values print as the empty string IgnoreNil bool }
WrappedString records the values needed for the formatting of a string value.
func (WrappedString) Formatted ¶ added in v2.2.0
func (f WrappedString) Formatted(v interface{}) string
Formatted returns the value formatted as a string. The string is wrapped to a maximum length of WrappedString.W and any trailing newlines are trimmed
func (WrappedString) Just ¶ added in v2.2.0
func (f WrappedString) Just() col.Justification
Just returns the justification of the value
func (WrappedString) Width ¶ added in v2.2.0
func (f WrappedString) Width() int
Width returns the intended width of the value