column

package
v0.4.17 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
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

)
View Source
const (
	FirstPosition = 0
	LastPosition  = -1
)

Variables

View Source
var SearchStrategies = []strategyProvider{
	&stringEqualityStrategy{name: "full exact"},
	&regexStrategy{name: "lone number", beforeRE: `(^|\W)`, afterRE: `(\W|$)`, validate: `^\d+$`},
	&regexStrategy{name: "embedded number", beforeRE: `(^|\D)`, afterRE: `(\D|$)`, validate: `^\d+$`},
	&regexStrategy{name: "prefix exact", beforeRE: `^`, afterRE: ``},
	&regexStrategy{name: "word exact", beforeRE: `\b`, afterRE: `\b`, validate: `^\w(.*\w)?$`},
	&regexStrategy{name: "word prefix exact", beforeRE: `\b`, afterRE: ``, validate: `^\w(.*\w)?$`},
	&regexStrategy{name: "any exact", beforeRE: ``, afterRE: ``},
	&regexStrategy{name: "full relaxed", beforeRE: `(?i)^`, afterRE: `$`},
	&regexStrategy{name: "prefix relaxed", beforeRE: `(?i)^`, afterRE: ``},
	&regexStrategy{name: "word relaxed", beforeRE: `(?i)\b`, afterRE: `\b`, validate: `^\w(.*\w)?$`},
	&regexStrategy{name: "word prefix relaxed", beforeRE: `(?i)\b`, afterRE: ``, validate: `^\w(.*\w)?$`},
	&regexStrategy{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

func FlagsFromString(in string) Flags

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 (f Flags) AlignmentString() string

func (Flags) CmpSign

func (f Flags) CmpSign() int

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 (f Flags) HasPriority() bool

func (Flags) IsAlignedCenter

func (f Flags) IsAlignedCenter() bool

func (Flags) IsAlignedDefault

func (f Flags) IsAlignedDefault() bool

func (Flags) IsAlignedLeft

func (f Flags) IsAlignedLeft() bool

func (Flags) IsAlignedNumber

func (f Flags) IsAlignedNumber() bool

func (Flags) IsAlignedPivot

func (f Flags) IsAlignedPivot() bool

func (Flags) IsAlignedRight

func (f Flags) IsAlignedRight() bool

func (Flags) IsAlignedVersion

func (f Flags) IsAlignedVersion() bool

func (Flags) IsAlignment

func (f Flags) IsAlignment() bool

func (Flags) IsAscendingOrder

func (f Flags) IsAscendingOrder() bool

func (Flags) IsConfigured

func (f Flags) IsConfigured() bool

func (Flags) IsDescendingOrder

func (f Flags) IsDescendingOrder() bool

func (Flags) IsSorted

func (f Flags) IsSorted() bool

func (*Flags) ResetSort

func (f *Flags) ResetSort()

func (*Flags) ReverseSort

func (f *Flags) ReverseSort()

func (*Flags) SetAlignment

func (f *Flags) SetAlignment(flags Flags)

func (*Flags) SetSort

func (f *Flags) SetSort(s Flags)

func (*Flags) SetSortPriority

func (f *Flags) SetSortPriority(prio int)

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

func (f Flags) SortPriority() int

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

func (f Flags) String() 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

func (i *Index) At(pos int) *Info

At returns the column.Info for a column, indexed by its position in the index.

The index will grow if necessary

func (Index) Clone

func (i Index) Clone() Index

func (*Index) Column

func (i *Index) Column(name string) *Info

func (*Index) ColumnNames

func (i *Index) ColumnNames() []string

func (*Index) FindLocation

func (i *Index) FindLocation(loc Locator) int

func (*Index) FindName

func (i *Index) FindName(want string) (position int, strategy string)

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) GrowTo

func (i *Index) GrowTo(targetSize int)

func (*Index) HasPostion

func (i *Index) HasPostion(pos int) bool

func (*Index) InitFlags

func (i *Index) InitFlags(flags []Flags)

func (*Index) InitNames

func (i *Index) InitNames(names []string)

func (*Index) Len

func (i *Index) Len() int

func (*Index) Position

func (i *Index) Position(name string) int

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)

func (*Index) SetNames

func (i *Index) SetNames(names []string)

func (*Index) String

func (i *Index) String() string

func (*Index) Trim

func (i *Index) Trim()

Trim removes trailing empty columns

type Info

type Info struct {
	FieldPosition int    // position of this column's fields in the original data
	Flags                // alignment / sorting flags
	Width                // width and alignment pivot
	Name          string // optional column name
}

func (*Info) String

func (i *Info) String() string

type Locator

type Locator struct {
	IsKeyword  bool   // the position was specified by keyword (stored in Name)
	IsPosition bool   // column was specifed by number
	Position   int    // position of the column
	Name       string // column name to search for
}

Locator is used to identify a column depending on how the column was specified, in order of priority: - via keywords "first" or "last" - as an integer number, e.g. 3, 5, 11 etc (starting at 1) - as a name to be searched

func AtPosition

func AtPosition(pos int) Locator

AtPosition returns a positional column id

func First

func First(name string) Locator

Relative column names: first & last

func Last

func Last(name string) Locator

func WithName

func WithName(name string) Locator

WithName columns have unknown positions and may or may not exist in a table

Asking a column.Index for a column by name will return the position of the column

func (Locator) String

func (loc Locator) String() string

type Option

type Option func(*Flags) Option

func AlignCenter

func AlignCenter() Option

func AlignLeft

func AlignLeft() Option

func AlignNumber

func AlignNumber() Option

func AlignRight

func AlignRight() Option

func AlignVersion

func AlignVersion() Option

func SetAlignment

func SetAlignment(flags Flags) Option

func SetFlags

func SetFlags(flags, mask Flags) Option

func SetSort

func SetSort(flags Flags) Option

func SortAscending

func SortAscending() Option

func SortDescending

func SortDescending() Option

func SortWithPriority

func SortWithPriority(prio int) Option

type Width

type Width struct {
	Chars int
	Left  int
	Right int
}

func (*Width) String

func (w *Width) String() string

func (*Width) UpdateChars

func (w *Width) UpdateChars(chars int)

func (*Width) UpdateLeft

func (w *Width) UpdateLeft(left int)

func (*Width) UpdateRight

func (w *Width) UpdateRight(right int)

func (*Width) UpdateWidth

func (w *Width) UpdateWidth(o Width)

Jump to

Keyboard shortcuts

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