Documentation
¶
Index ¶
- func Fprint(w io.Writer, f Formatter, args ...any)
- func Fprintf(w io.Writer, f Formatter, format string, args ...any)
- func Printf(f Formatter, format string, args ...any)
- func Sprint(f Formatter, args ...any) string
- func Sprintf(f Formatter, format string, args ...any) string
- type Formatter
- type Style
- type Text
- func (t *Text) Append(ss ...string) *Text
- func (t *Text) Bytes(b []byte) []byte
- func (t *Text) Head() *Text
- func (t *Text) Insert(s string) *Text
- func (t *Text) Len() int
- func (t *Text) Prepend(ss ...string) *Text
- func (t *Text) Split(n int) *Text
- func (t *Text) String() string
- func (t *Text) Tail() *Text
- func (t *Text) WriteTo(w io.Writer) (int64, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Formatter ¶
type Formatter interface {
Format(*Text)
}
Formatter manipulates Text.
func LineWrap ¶
LineWrap wraps the text at the given width. It breaks lines at word boundaries when possible.
type Style ¶
type Style []Formatter
Style applies multiple formatters to a text in order.
type Text ¶
Text is a linked-list structure that represents an in-progress text string. Most formatters work by prepending and appending to text, so this structure is far more efficient than manipulating strings directly.
The pointer is intrinsically a cursor that points to the current text segment. So, subsequent appends and prepends are O(1) since the cursor is already at the tail or head respectively.
func (*Text) Bytes ¶
Bytes allocates a new byte slice containing the entire text. It uses the given buffer if it is large enough.
func (*Text) Head ¶
Head returns the absolute head of the text. It adjusts the pointer to the head of the text.
func (*Text) Insert ¶
Insert inserts the given text before the current text. It returns the new node.
func (*Text) Split ¶
Split splits the current text into two parts at the given index. The current node contains the first part, and the new node contains the second part. It returns the new node, and does not adjust the pointer.