Documentation
¶
Index ¶
- func Fprint(w io.Writer, f Formatter, args ...interface{})
- func Fprintf(w io.Writer, f Formatter, format string, args ...interface{})
- func Printf(f Formatter, format string, args ...interface{})
- func Sprint(f Formatter, args ...interface{}) string
- func Sprintf(f Formatter, format string, args ...interface{}) 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 ¶
func Fprintf ¶
Fprintf formats the given string with the formatter and writes it to the given writer.
Types ¶
type Formatter ¶
type Formatter interface {
Format(*Text)
}
Formatter manipulates Text.
func BgColor ¶
BgColor returns a formatter that sets the background color. Example:
BgColor(termenv.RGBColor("#ff0000")) BgColor(termenv.ANSI256Color(196)) BgColor(termenv.ANSIColor(31))
func CSI ¶
CSI wraps the text in the given CSI (Control Sequence Introducer) sequence. Example:
CSI(termenv.BoldSeq) CSI(termenv.UnderlineSeq) CSI(termenv.ItalicSeq)
func FgColor ¶
FgColor returns a formatter that sets the foreground color. Example:
FgColor(termenv.RGBColor("#ff0000")) FgColor(termenv.ANSI256Color(196)) FgColor(termenv.ANSIColor(31))
func LineWrap ¶
LineWrap wraps the text at the given width. It breaks lines at word boundaries when possible. It will never break up a word so that URLs and other long strings present correctly.
type Style ¶
type Style []Formatter
Style is a special Formatter that 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 instrinsicly 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) Append ¶
Append appends strings to the end of the text in order. Example:
txt := String("a") txt = txt.Append("b", "c") fmt.Println(txt.String()) // Output: abc
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) Prepend ¶
Prepend prepends strings to the beginning of the text in order. Example:
txt := String("c") txt = txt.Prepend("a", "b") fmt.Println(txt.String()) // Output: abc
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.