Documentation ¶
Index ¶
- func MultiMatcher(chars []rune, stream CharStream) (string, error)
- type BoxBorderType
- type BoxStyle
- type CharStream
- type ErrNoClosestWordFound
- type LavenshteinTable
- type RuneTable
- func (rt *RuneTable) AlignRightEdge() int
- func (rt *RuneTable) AppendBottomRow(row []rune)
- func (rt *RuneTable) PrefixEachRow(prefix []rune)
- func (rt *RuneTable) PrependTopRow(row []rune)
- func (rt *RuneTable) RightMostEdge() int
- func (rt *RuneTable) String() string
- func (rt *RuneTable) SuffixEachRow(suffix []rune)
- type Stream
- type WordMatcher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MultiMatcher ¶
func MultiMatcher(chars []rune, stream CharStream) (string, error)
MultiMatcher kinda works like WordMatcher but, unlike WordMatcher, it only matches a specific set of characters.
Parameters:
- chars: The characters to match.
- stream: The CharStream to use.
Returns:
- string: The matched string.
- error: An error if the matching process failed.
Errors:
- *common.ErrInvalidParameter: If the input stream is nil or the input characters are empty.
Types ¶
type BoxBorderType ¶
type BoxBorderType int
BoxBorderType is the type of the box border.
const ( // BtNormal is the normal box border type. BtNormal BoxBorderType = iota // BtTriple is the triple box border type. BtTriple // BtQuadruple is the quadruple box border type. BtQuadruple // BtDouble is the double box border type. BtDouble // BtRounded is like BtNormal but with rounded corners. BtRounded )
type BoxStyle ¶
type BoxStyle struct { // LineType is the type of the line. LineType BoxBorderType // IsHeavy is whether the line is heavy or not. // Only applicable to BtNormal, BtTriple, and BtQuadruple. IsHeavy bool // Padding is the padding of the box. // [Top, Right, Bottom, Left] Padding [4]int }
BoxStyle is the style of the box.
var ( // DefaultBoxStyle is the default box style. DefaultBoxStyle *BoxStyle )
func NewBoxStyle ¶
func NewBoxStyle(line_type BoxBorderType, is_heavy bool, padding [4]int) *BoxStyle
NewBoxStyle creates a new box style.
Negative padding are set to 0.
Parameters:
- line_type: The line type.
- is_heavy: Whether the line is heavy or not.
- padding: The padding of the box. [Top, Right, Bottom, Left]
Returns:
- *BoxStyle: The new box style.
func (*BoxStyle) ApplyStrings ¶
DrawBox draws a box around the content.
Format: If the content is ["Hello", "World"], the box will be:
┏━━━━━━━┓ ┃ Hello ┃ ┃ World ┃ ┗━━━━━━━┛
Parameters:
- content: The content.
Returns:
- *RuneTable: The content in a box.
- error: An error if the content could not be processed.
Behaviors:
- If the box style is nil, the default box style will be used.
func (*BoxStyle) Corners ¶ added in v0.1.6
Corners gets the corners of the box.
Returns:
- [4]rune: The corners. [TopLeft, TopRight, BottomLeft, BottomRight]
func (*BoxStyle) SideBorder ¶ added in v0.1.6
SideBorder gets the side border of the box.
It also applies to the left border as they are the same.
Returns:
- string: The side border.
type CharStream ¶
type CharStream interface { // IsDone checks whether the stream is done. // // Returns: // - bool: True if the stream is done. False otherwise. IsDone() bool // Next returns the next character in the stream while advancing the position. // // Returns: // - rune: The next character in the stream. utf8.RuneError if the stream is done. // - bool: True if the stream has more characters. False otherwise. Next() (rune, bool) // Peek returns the next character in the stream without advancing the position. // // Returns: // - rune: The next character in the stream. utf8.RuneError if the stream is done. // - bool: True if the stream has more characters. False otherwise. Peek() (rune, bool) // Refuse undoes the last Next operation. // // Returns: // - bool: True if the last Next operation was undone. False otherwise. Refuse() bool // RefuseMany undoes any Next operation since the last Accept operation. // This is useful when you want to abandon the current word and start a new one. RefuseMany() // Accept accepts the next character in the stream. This is useful for signifying // valid sequences that should not be undone. Accept() }
CharStream is an interface for a character stream.
type ErrNoClosestWordFound ¶
type ErrNoClosestWordFound struct{}
ErrNoClosestWordFound is an error when no closest word is found.
func NewErrNoClosestWordFound ¶
func NewErrNoClosestWordFound() *ErrNoClosestWordFound
NewErrNoClosestWordFound creates a new ErrNoClosestWordFound.
Returns:
- *ErrNoClosestWordFound: The new ErrNoClosestWordFound.
func (*ErrNoClosestWordFound) Error ¶
func (e *ErrNoClosestWordFound) Error() string
Error implements the error interface.
Message: "no closest word was found"
type LavenshteinTable ¶
type LavenshteinTable struct {
// contains filtered or unexported fields
}
LevenshteinTable is a table of words for the Levenshtein distance.
func NewLevenshteinTable ¶
func NewLevenshteinTable(words ...string) (*LavenshteinTable, error)
NewLevenshteinTable creates a new Levenshtein table with the given words.
Parameters:
- words: The words to add to the table.
Returns:
- *LevenshteinTable: The new Levenshtein table.
- error: An error if any of the words cannot be added to the table.
Errors:
- *common.ErrAt: Whenever a word is not valid UTF-8.
It is the same as creating an empty table and then adding the words to it.
func (*LavenshteinTable) AddWord ¶
func (lt *LavenshteinTable) AddWord(word string) error
AddWord adds a word to the table.
Parameters:
- word: The word to add.
Returns:
- error: An error of type *ErrInvalidUTF8Encoding if the word is not valid UTF-8.
func (*LavenshteinTable) Closest ¶ added in v0.1.6
func (lt *LavenshteinTable) Closest(target []rune) (string, error)
Closest gets the closest word to a target.
Parameters:
- target: The target.
Returns:
- string: The closest word.
- error: The error if any occurs.
Errors:
- *common.ErrInvalidParameter: If the target is empty.
- *ErrNoClosestWordFound: If no closest word is found.
type RuneTable ¶
type RuneTable struct {
// contains filtered or unexported fields
}
RuneTable is a table of runes.
func NewRuneTable ¶
NewRuneTable creates a new RuneTable with the given lines.
Parameters:
- lines: The lines to add to the table.
Returns:
- *RuneTable: The new RuneTable.
- error: An error if any.
func (*RuneTable) AlignRightEdge ¶
AlignRightEdge aligns the right edge of the table.
Returns:
- int: The right most edge.
func (*RuneTable) AppendBottomRow ¶
AppendBottomRow appends a row to the bottom of the table.
Parameters:
- row: The row to append.
func (*RuneTable) PrefixEachRow ¶
PrefixEachRow prefixes each row with the given prefix.
Parameters:
- prefix: The prefix to add to each row.
func (*RuneTable) PrependTopRow ¶
PrependTopRow prepends a row to the top of the table.
Parameters:
- row: The row to prepend.
func (*RuneTable) RightMostEdge ¶ added in v0.1.6
RightMostEdge gets the right most edge of the content.
Parameters:
- content: The content.
Returns:
- int: The right most edge.
func (*RuneTable) SuffixEachRow ¶
SuffixEachRow suffixes each row with the given suffix.
Parameters:
- suffix: The suffix to add to each row.
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream is a character stream.
func NewStream ¶
NewStream creates a new stream with the given runes.
Parameters:
- b: The rune slice of the stream.
Returns:
- *Stream: The new stream. Never nil.
func (*Stream) RefuseMany ¶
func (s *Stream) RefuseMany()
RefuseMany implements the CharStream interface.
type WordMatcher ¶
type WordMatcher struct {
// contains filtered or unexported fields
}
WordMatcher is the word matcher.
func NewWordMatcher ¶
func NewWordMatcher() *WordMatcher
NewWordMatcher returns a new WordMatcher.
Returns:
- *WordMatcher: The new WordMatcher. Never nil.
func (*WordMatcher) AddWord ¶
func (wm *WordMatcher) AddWord(word string) error
AddWord adds a word to the matcher. It ignores empty or duplicated words.
Parameters:
- word: The word to add.
Returns:
- error: An error if the word is invalid.
Errors:
- *common.ErrAt: When the word is not a valid UTF-8 string.
func (*WordMatcher) Match ¶
func (wm *WordMatcher) Match(is CharStream) (string, error)
Match matches the input stream.
Parameters:
- is: The input stream to match.
Returns:
- string: The matched word.
- error: An error if the stream could not be matched.
Errors:
- *common.ErrAt: If the input stream is not a valid UTF-8 stream.