Documentation
¶
Index ¶
Constants ¶
View Source
const ( SORT_ASCENDING = '^' SORT_DESCENDING = 'v' )
View Source
const UNSET byte = 0
Variables ¶
View Source
var ( HintStyles = map[string]*HintStyle{ "": &HintStyle{ AlignLeft: ":--", AlignRight: "--:", AlignCenter: "-:-", AlignNumber: "-.-", }, "none": &HintStyle{ FlagsMask: 0xff, }, "markdown": &HintStyle{ FlagsMask: ^model.AlignmentMask, AlignLeft: ":--", AlignRight: "--:", AlignCenter: ":-:", Replace: map[model.ColumnFlags]model.ColumnFlags{ model.AlignNumericFlag: model.AlignRightFlag, }, }, } )
Functions ¶
This section is empty.
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder parses rulers from input lines
The input is expected to be either
- a ruler template, or
- a row being parsed from an existing PSV table
nil is returned if the input cannot be parsed.
Expected use while parsing a document:
rulerDec := NewDecoder()
rowDec := NewRowDecoder()
for scanner.Scan() {
line := scanner.Text()
prefix, content := SplitPrefix(line)
doc.SetTablePrefixOnce(prefix)
if ruler := rulerDec.Decode(content); ruler != nil {
doc.AppendRuler(ruler)
continue
}
if row := rowDec.Decode(content); row != nil {
doc.AppendRow(row)
continue
}
// line is not part of the table
}
A Ruler may also be created via &model.Ruler{}, in which case it will use the default template of "| -"
func NewDecoder ¶
func NewDecoder() *Decoder
type Encoder ¶
type Encoder struct {
*HintStyle
}
func (*Encoder) Encode ¶
Encode encodes a ruler according to the column alignments and widths provided.
func (*Encoder) EncodeWithHints ¶
func (enc *Encoder) EncodeWithHints( buf *bytes.Buffer, ruler *model.Ruler, cws []model.ColumnWidth, cfs []model.ColumnFlags, )
EncodeWithHints encodes a ruler for a set number of columns, and includes additional alignment hints, according to the configured hint-styles.
Rulers with column hints have a general form of:
[padding] <left> <line> <center> <line> <right> <order> [<padding>]
type HintStyle ¶
type HintStyle struct {
FlagsMask model.ColumnFlags // mask to remove unsupported flags, 0: everything supported, 0xff: nothing supported
AlignLeft string //
AlignRight string //
AlignCenter string //
AlignNumber string //
Replace map[model.ColumnFlags]model.ColumnFlags // map of equivalent flags
}
REFACTOR: 2025-03-12 move to EncodingStyle see also cmd/psv/flags.go
type RulerBuilder ¶
type RulerBuilder struct {
// contains filtered or unexported fields
}
func (*RulerBuilder) SetAlignment ¶
func (rb *RulerBuilder) SetAlignment(alignmentFlags model.ColumnFlags)
func (*RulerBuilder) SetSort ¶
func (rb *RulerBuilder) SetSort(sortFlags model.ColumnFlags)
func (*RulerBuilder) SetSortPriority ¶
func (rb *RulerBuilder) SetSortPriority(sortPriority int)
Click to show internal directories.
Click to hide internal directories.