Documentation
¶
Index ¶
- Constants
- Variables
- type Flags
- func (f Flags) AlignmentString() string
- func (f Flags) CmpSign() int
- func (f *Flags) DisableSort()
- func (f *Flags) EnableSort()
- func (f Flags) HasPriority() bool
- func (f Flags) IsAlignedCenter() bool
- func (f Flags) IsAlignedDefault() bool
- func (f Flags) IsAlignedLeft() bool
- func (f Flags) IsAlignedNumber() bool
- func (f Flags) IsAlignedPivot() bool
- func (f Flags) IsAlignedRight() bool
- func (f Flags) IsAlignedVersion() bool
- func (f Flags) IsAlignment() bool
- func (f Flags) IsAscendingOrder() bool
- func (f Flags) IsConfigured() bool
- func (f Flags) IsDescendingOrder() bool
- func (f Flags) IsSorted() bool
- func (f *Flags) ResetSort()
- func (f *Flags) ReverseSort()
- func (f *Flags) SetAlignment(flags Flags)
- func (f *Flags) SetFlags(flags, mask Flags)
- func (f *Flags) SetSort(s Flags)
- func (f *Flags) SetSortPriority(prio int)
- func (f Flags) SortPriority() int
- func (f Flags) String() string
- type Index
- func (i *Index) At(pos int) *Info
- func (i Index) Clone() Index
- func (i *Index) Column(name string) *Info
- func (i *Index) ColumnNames() []string
- func (i *Index) FindName(want string) (position int, strategy string)
- func (i *Index) FindPosition(s *Specifier) int
- func (i *Index) GrowTo(targetSize int)
- func (i *Index) HasPostion(pos int) bool
- func (i *Index) InitFlags(flags []Flags)
- func (i *Index) InitNames(names []string)
- func (i *Index) Len() int
- func (i *Index) Position(name string) int
- func (i *Index) ResetPositions()
- func (i *Index) SetNames(names []string)
- func (i *Index) String() string
- func (i *Index) Trim()
- type Info
- type LocType
- type Option
- func AlignCenter() Option
- func AlignLeft() Option
- func AlignNumber() Option
- func AlignRight() Option
- func AlignVersion() Option
- func ResetAlignment() Option
- func ResetSorting() Option
- func SetAlignment(flags Flags) Option
- func SetFlags(flags, mask Flags) Option
- func SetSort(flags Flags) Option
- func SortAscending() Option
- func SortDescending() Option
- func SortWithPriority(prio int) Option
- type Specifier
- func (s *Specifier) AtPosition(pos int) *Specifier
- func (s *Specifier) FirstColumn(name string) *Specifier
- func (s *Specifier) LastColumn(name string) *Specifier
- func (s *Specifier) String() string
- func (s *Specifier) WithName(name string) *Specifier
- func (s *Specifier) WithNameOrPosition(nameOrPos string) *Specifier
- type Width
Constants ¶
const ( UnconfiguredFlags Flags = 0b000_00_000 // .... .... - an unconfigured column: default alignment, no sorting AlignDefaultFlag Flags = 0b000_00_000 // .... .000 - default alignment (left aligned, but without a ruler hint) AlignRightFlag Flags = 0b000_00_001 // .... .001 - align text to the right of the column AlignLeftFlag Flags = 0b000_00_100 // .... .100 - align text to the left of the column AlignCenterFlag Flags = 0b000_00_010 // .... .010 - center text within the column (psv style |--:--|) AlignCenterAltFlag Flags = 0b000_00_101 // .... .101 - center text within the columna (markdown style |:---:|) AlignNumberFlag Flags = 0b000_00_011 // .... .011 - align numbers around their decimal point, otherwise right aligned AlignVersionFlag Flags = 0b000_00_110 // .... .110 - align on first point or left, sort using integer numbers only AlignPivotMask Flags = 0b000_00_010 // .... ..1. - align content relative to a calculated "pivot" position AlignFlagsMask Flags = 0b000_00_111 // .... .111 SortEnabledFlag Flags = 0b000_01_000 // .... 1... - indicate that the column should be sorted (default: no sorting) SortColumnMask Flags = 0b000_01_000 // .... 1... SortAscendingFlag Flags = 0b000_00_000 // ...0 1... - only valid in combination with FlagSortColumn SortDescendingFlag Flags = 0b000_10_000 // ...1 1... - only valid in combination with FlagSortColumn SortDirectionMask Flags = 0b000_10_000 // ...1 .... SortFlagsMask Flags = 0b000_11_000 // ...1 1... SortPriorityMask Flags = 0b111_00_000 // 111. .... - 1 .. 7 only - only only valid in combination with FlagSortColumn AllFlagsMask Flags = 0b111_11_111 // 1111 1111 SortPriorityShift int = 5 // 111. .... == .... .111 << 5 )
const ( FirstPosition = 0 LastPosition = -1 )
Variables ¶
var SearchStrategies = []strategyProvider{
&stringEqualityStrategy{name: "full exact"},
®exStrategy{name: "lone number", beforeRE: `(^|\W)`, afterRE: `(\W|$)`, validate: `^\d+$`},
®exStrategy{name: "embedded number", beforeRE: `(^|\D)`, afterRE: `(\D|$)`, validate: `^\d+$`},
®exStrategy{name: "prefix exact", beforeRE: `^`, afterRE: ``},
®exStrategy{name: "word exact", beforeRE: `\b`, afterRE: `\b`, validate: `^\w(.*\w)?$`},
®exStrategy{name: "word prefix exact", beforeRE: `\b`, afterRE: ``, validate: `^\w(.*\w)?$`},
®exStrategy{name: "any exact", beforeRE: ``, afterRE: ``},
®exStrategy{name: "full relaxed", beforeRE: `(?i)^`, afterRE: `$`},
®exStrategy{name: "prefix relaxed", beforeRE: `(?i)^`, afterRE: ``},
®exStrategy{name: "word relaxed", beforeRE: `(?i)\b`, afterRE: `\b`, validate: `^\w(.*\w)?$`},
®exStrategy{name: "word prefix relaxed", beforeRE: `(?i)\b`, afterRE: ``, validate: `^\w(.*\w)?$`},
®exStrategy{name: "any relaxed", beforeRE: `(?i)`, afterRE: ``},
}
Functions ¶
This section is empty.
Types ¶
type Flags ¶
type Flags byte
Flags flags are used to specify how a column should be prepared for rendering.
- Alignment - Sorting (incl. sort priority, between 0 and 7)
func FlagsFromString ¶
FlagsFromString parses a Flags string and returns a flags byte
Assumption: all flags strings are 7-bit ASCII
Examples:
| string | flags | | | ------ | --------------------------------------------------------- | -------------------------------- | | | none | empty string, no hints, no flags | | l | left aligned | | | c | center aligned | | | r | right aligned | | | sa | sort ascending | | | nsa | align and sort numerically, in ascending order | | | vsd3 | align and sort by version, in descending order and prio 3 | |
func (Flags) AlignmentString ¶
func (Flags) CmpSign ¶
CmpSign returns -1, 0 or +1 depending on the columne's sort configuration
- -1 for descending order
- 0 for no sort
- +1 for ascending order
func (*Flags) DisableSort ¶
func (f *Flags) DisableSort()
func (*Flags) EnableSort ¶
func (f *Flags) EnableSort()
func (Flags) HasPriority ¶
func (Flags) IsAlignedCenter ¶
func (Flags) IsAlignedDefault ¶
func (Flags) IsAlignedLeft ¶
func (Flags) IsAlignedNumber ¶
func (Flags) IsAlignedPivot ¶
func (Flags) IsAlignedRight ¶
func (Flags) IsAlignedVersion ¶
func (Flags) IsAlignment ¶
func (Flags) IsAscendingOrder ¶
func (Flags) IsConfigured ¶
func (Flags) IsDescendingOrder ¶
func (*Flags) ReverseSort ¶
func (f *Flags) ReverseSort()
func (*Flags) SetAlignment ¶
func (*Flags) SetSortPriority ¶
SetSortPriority sets the priority used when determining which columns to compare, and in what order, when sorting rows
Setting a column's priority does not enable or disable a column's sort status. (Setting a columns priority should always be compbined with EnableSort())
func (Flags) SortPriority ¶
SortPriority returns the sort-priority of the column.
Invariants:
- only values between 0 and 7 will be returned
- 0 indicates 'no special priority'
func (Flags) String ¶
String returns a string representing the alignment and sorting configuration of the column.
The string will have 0, 1, 2 or 3 positional characters for the alignment, sorting direction and sorting priority.
- "" indicates a default column without any alignment or sorting preferences
- justification character: "l" - left justified "r" - right justified "c" - center justified "n" - justified to decimal point (numerically) "v" - justify to major version number
- sorting direction character: "^" - sort column from lowest to highest values "V" - sort column from highest to lowest values
- sorting priority character: [0…7] - comparison priority of the column when sorting
e.g.: "nv2" would indicate "numeric alignment", "sorted in descending order" and "compared with priority 3 while sorting"
type Index ¶
type Index struct {
Info []Info
}
func (*Index) At ¶
At returns the column.Info for a column, indexed by its position in the index.
The index will grow if necessary
func (*Index) ColumnNames ¶
func (*Index) FindName ¶
FindName searches for a column by name and returns the index of the column and the name of the strategy that found the matching name
func (*Index) FindPosition ¶ added in v0.4.25
returns (0..n-1) - the position of the column in the index or -1 if the specified does not match any columns in the index
Caution: Specifier.Pos (1..n) needs to be translated to (0..n-1)
func (*Index) HasPostion ¶
func (*Index) ResetPositions ¶
func (i *Index) ResetPositions()
ResetPositions re-numbers all of the columns so that their .Position value represents their current position in the column index.
Purpose:
- this is called after applying commands to columns (re-arranging, adding, removing)
type Info ¶
type LocType ¶ added in v0.4.20
type LocType int
const ( NameOrPosLocType LocType = iota // default: name was provided as a bare word, could be name or position NameOnlyLocType // name was provided with preceeding ':' - use name only PosOnlyLocType // position was provided with a preceeding '.' - use position only KeywordLocType // "last" or "first" - dynamically named columns )
type Option ¶
func AlignCenter ¶
func AlignCenter() Option
func AlignNumber ¶
func AlignNumber() Option
func AlignRight ¶
func AlignRight() Option
func AlignVersion ¶
func AlignVersion() Option
func ResetAlignment ¶ added in v0.4.20
func ResetAlignment() Option
func ResetSorting ¶ added in v0.4.20
func ResetSorting() Option
func SetAlignment ¶
func SetFlags ¶
Option returns a function which can be used to apply a change to a column's flags. Used by [command.Builder] for preparing table manipulators.
func SortAscending ¶
func SortAscending() Option
func SortDescending ¶
func SortDescending() Option
func SortWithPriority ¶
type Specifier ¶ added in v0.4.20
type Specifier struct {
LocType // possible restrictions on the use of this locator
Pos int // position of the column (1..n)
Name string // name of the column (fuzzy search)
Flags // flags to apply to the column
Mask Flags // 0x00 - leave flags unchanged, 0xff - replace column's flags
}
Specifier is used to identify a column depending on how the column was specified, in order of priority: - an explicit integer position (1..n) - an explicit name to be searched (no first/last/keyword lookups) - via keywords "first" or "last" - as a search string which may contain a name or a position
func FirstColumn ¶ added in v0.4.20
func LastColumn ¶ added in v0.4.20
func (*Specifier) AtPosition ¶ added in v0.4.20
AtPosition returns a positional column id (1..n)
func (*Specifier) FirstColumn ¶ added in v0.4.20
Relative column names: first & last