Documentation ¶
Index ¶
- Constants
- func GraphemeClusterIsEmoji(gc []rune) bool
- func GraphemeClusterIsRegionalIndicator(gc []rune) bool
- type GraphemeClusterBreaker
- type GraphemeClusterIter
- type GraphemeClusterWidthFunc
- type LineBreakDecision
- type LineBreaker
- type LineWrapConfig
- type ReverseGraphemeClusterIter
- type Segment
- type WrappedLineIter
Constants ¶
const ( NoLineBreak = LineBreakDecision(iota) AllowLineBreakBefore RequireLineBreakBefore RequireLineBreakAfter )
Variables ¶
This section is empty.
Functions ¶
func GraphemeClusterIsEmoji ¶
GraphemeClusterIsEmoji checks whether the grapheme cluster represents an emoji.
func GraphemeClusterIsRegionalIndicator ¶
GraphemeClusterIsRegionalIndicator checks whether the grapheme cluster represents a regional indicator (usually rendered as a flag).
Types ¶
type GraphemeClusterBreaker ¶ added in v0.3.0
type GraphemeClusterBreaker struct {
// contains filtered or unexported fields
}
GraphemeClusterBreaker finds breakpoints between grapheme clusters in a sequence of runes.
func (*GraphemeClusterBreaker) ProcessRune ¶ added in v0.3.0
func (gb *GraphemeClusterBreaker) ProcessRune(r rune) (canBreakBefore bool)
ProcessRune determines whether the position before the rune is a valid breakpoint (starts a new grapheme cluster).
type GraphemeClusterIter ¶ added in v0.3.0
type GraphemeClusterIter struct {
// contains filtered or unexported fields
}
GraphemeClusterIter segments text into grapheme clusters. A grapheme cluster is a user-perceived character, which can be composed of multiple unicode codepoints. For full details see https://www.unicode.org/reports/tr29/ version 13.0.0, revision 37. Copying the struct produces a new, independent iterator.
func NewGraphemeClusterIter ¶
func NewGraphemeClusterIter(reader text.Reader) GraphemeClusterIter
NewGraphemeClusterIter initializes a new iterator. The iterator assumes that the first character it receives is at a break point (either the start of the text or the beginning of a new grapheme cluster). The input reader MUST produce valid UTF-8 codepoints.
func (*GraphemeClusterIter) NextSegment ¶ added in v0.3.0
func (g *GraphemeClusterIter) NextSegment(segment *Segment) error
NextSegment retrieves the next grapheme cluster.
type GraphemeClusterWidthFunc ¶
GraphemeClusterWidthFunc returns the width in cells for a given grapheme cluster.
type LineBreakDecision ¶ added in v0.6.0
type LineBreakDecision byte
type LineBreaker ¶ added in v0.6.0
type LineBreaker struct {
// contains filtered or unexported fields
}
LineBreaker finds possible breakpoints between lines. This uses the Unicode line breaking algorithm from https://www.unicode.org/reports/tr14/
func (*LineBreaker) ProcessRune ¶ added in v0.6.0
func (lb *LineBreaker) ProcessRune(r rune) (decision LineBreakDecision)
ProcessRune finds valid breakpoints between lines.
type LineWrapConfig ¶
type LineWrapConfig struct { MaxLineWidth uint64 // Maximum number of cells per line, which must be at least one. AllowCharBreaks bool // Allow breaks at grapheme cluster boundaries. WidthFunc GraphemeClusterWidthFunc }
LineWrapConfig controls how lines should be soft-wrapped.
type ReverseGraphemeClusterIter ¶ added in v0.3.0
type ReverseGraphemeClusterIter struct {
// contains filtered or unexported fields
}
ReverseGraphemeClusterIter identifies valid breakpoints between grapheme clusters in a reversed-order sequence of runes. Copying the struct produces a new, independent iterator.
func NewReverseGraphemeClusterIter ¶
func NewReverseGraphemeClusterIter(reader text.ReverseReader) ReverseGraphemeClusterIter
NewReverseGraphemeClusterIter constructs a new BreakIter from a runeIter that yields runes in reverse order.
func (*ReverseGraphemeClusterIter) NextSegment ¶ added in v0.3.0
func (g *ReverseGraphemeClusterIter) NextSegment(segment *Segment) error
NextSegment retrives the next grapheme cluster reading backwards. The returned locations are relative to the end of the text.
type Segment ¶
type Segment struct {
// contains filtered or unexported fields
}
Segment represents a sequence of runes from a larger text (for example a grapheme cluster).
func (*Segment) HasNewline ¶
HasNewline checks whether a segment contains a line feed rune.
func (*Segment) IsWhitespace ¶
IsWhitespace checks whether the segment contains only whitespace runes (spaces, tabs, etc).
func (*Segment) ReverseRunes ¶
ReverseRunes reverses the order of the runes in the segment.
type WrappedLineIter ¶ added in v0.3.0
type WrappedLineIter struct {
// contains filtered or unexported fields
}
WrappedLineIter iterates through soft- and hard-wrapped lines.
func NewWrappedLineIter ¶
func NewWrappedLineIter(wrapConfig LineWrapConfig, textTree *text.Tree, startPos uint64) WrappedLineIter
NewWrappedLineIter constructs a segment iterator for soft- and hard-wrapped lines.
func (*WrappedLineIter) NextSegment ¶ added in v0.3.0
func (iter *WrappedLineIter) NextSegment(segment *Segment) error
NextSegment retrieves the next soft- or hard-wrapped line. For hard-wrapped lines, the grapheme cluster containing the newline will be included at the end of the line. If a segment is too long to fit on any line, put it in its own line.