{"modulePath":"github.com/coder/pretty","version":"v0.0.0-20230908205945-e89ba86370e0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package pretty\n\n## Functions\n\n```go\nfunc Fprint(w io.Writer, f Formatter, args ...interface{})\n```\nFprint formats the given string with the formatter and writes it to the given writer.\n\n```go\nfunc Fprintf(w io.Writer, f Formatter, format string, args ...interface{})\n```\nFprintf formats the given string with the formatter and writes it to the given writer.\n\n```go\nfunc Printf(f Formatter, format string, args ...interface{})\n```\nPrintf formats the given string with the formatter and prints it to stdout.\n\n```go\nfunc Sprint(f Formatter, args ...interface{}) string\n```\nSprint formats the given string with the formatter.\n\n```go\nfunc Sprintf(f Formatter, format string, args ...interface{}) string\n```\nSprintf formats the given string with the formatter.\n\n## Types\n\n```go\ntype Formatter interface {\n\tFormat(*Text)\n}\n```\nFormatter manipulates Text.\n\n```go\nvar Nop Formatter = formatterFunc(func(t *Text) {})\n```\nNop is a no-op formatter.\n\n```go\nfunc BgColor(c termenv.Color) Formatter\n```\nBgColor returns a formatter that sets the background color. Example:\n\n\tBgColor(termenv.RGBColor(\"#ff0000\"))\n\tBgColor(termenv.ANSI256Color(196))\n\tBgColor(termenv.ANSIColor(31))\n\n```go\nfunc Bold() Formatter\n```\nBold returns a formatter that makes the text bold.\n\n```go\nfunc CSI(seq string) Formatter\n```\nCSI wraps the text in the given CSI (Control Sequence Introducer) sequence. Example:\n\n\tCSI(termenv.BoldSeq)\n\tCSI(termenv.UnderlineSeq)\n\tCSI(termenv.ItalicSeq)\n\n```go\nfunc FgColor(c termenv.Color) Formatter\n```\nFgColor returns a formatter that sets the foreground color. Example:\n\n\tFgColor(termenv.RGBColor(\"#ff0000\"))\n\tFgColor(termenv.ANSI256Color(196))\n\tFgColor(termenv.ANSIColor(31))\n\n```go\nfunc Italic() Formatter\n```\nItalic returns a formatter that makes the text italic.\n\n```go\nfunc LineWrap(width int) Formatter\n```\nLineWrap 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.\n\n```go\nfunc Underline() Formatter\n```\nUnderline returns a formatter that underlines the text.\n\n```go\nfunc Wrap(prefix, suffix string) Formatter\n```\nWrap wraps the text in the given prefix and suffix. It is useful for wrapping text in ANSI sequences.\n\n```go\nfunc XPad(left, right int) Formatter\n```\nXPad pads the text on the left and right.\n\n```go\ntype Style []Formatter\n```\nStyle is a special Formatter that applies multiple Formatters to a text in order.\n\n```go\nfunc (s Style) Format(t *Text)\n```\nFormat applies all formatters in the style to the text and returns the modified text.\n\nWhen performance is a concern, use WriteTo instead of String on the returned text.\n\n```go\nfunc (s Style) With(fs ...Formatter) Style\n```\nWith returns a new style with the given formatters appended.\n\n```go\ntype Text struct {\n\tS    string\n\tNext *Text\n\tPrev *Text\n}\n```\nText 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.\n\nThe 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.\n\n```go\nfunc String(s ...string) *Text\n```\nString creates a new Text object from the given strings.\n\n```go\nfunc (t *Text) Append(ss ...string) *Text\n```\nAppend appends strings to the end of the text in order. Example:\n\n\ttxt := String(\"a\")\n\ttxt = txt.Append(\"b\", \"c\")\n\tfmt.Println(txt.String())\n\t// Output: abc\n\n```go\nfunc (t *Text) Bytes(b []byte) []byte\n```\nBytes allocates a new byte slice containing the entire text. It uses the given buffer if it is large enough.\n\n```go\nfunc (t *Text) Head() *Text\n```\nHead returns the absolute head of the text. It adjusts the pointer to the head of the text.\n\n```go\nfunc (t *Text) Insert(s string) *Text\n```\nInsert inserts the given text before the current text. It returns the new node.\n\n```go\nfunc (t *Text) Len() int\n```\nLen returns the length of the text.\n\n```go\nfunc (t *Text) Prepend(ss ...string) *Text\n```\nPrepend prepends strings to the beginning of the text in order. Example:\n\n\ttxt := String(\"c\")\n\ttxt = txt.Prepend(\"a\", \"b\")\n\tfmt.Println(txt.String())\n\t// Output: abc\n\n```go\nfunc (t *Text) Split(n int) *Text\n```\nSplit 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.\n\n```go\nfunc (t *Text) String() string\n```\nString allocates a new string containing the entire text.\n\n```go\nfunc (t *Text) Tail() *Text\n```\nTail returns the absolute tail of the text. It adjusts the pointer to the tail of the text\n\n```go\nfunc (t *Text) WriteTo(w io.Writer) (int64, error)\n```\nWriteTo writes the text to the given writer, avoiding string allocations.\n\n","path":"github.com/coder/pretty","name":"pretty","synopsis":"","isRedistributable":true}
