Documentation
¶
Index ¶
- Constants
- func StripAnsi(input string) string
- type ByteRange
- type ConcatItem
- func (m ConcatItem) ByteRangesToMatches(byteRanges []ByteRange) []Match
- func (m ConcatItem) Content() string
- func (m ConcatItem) ContentNoAnsi() string
- func (m ConcatItem) ExtractExactMatches(exactMatch string) []Match
- func (m ConcatItem) ExtractRegexMatches(regex *regexp.Regexp) []Match
- func (m ConcatItem) LineBrokenItems() []Item
- func (m ConcatItem) NumWrappedLines(wrapWidth int) int
- func (m ConcatItem) Take(widthToLeft, takeWidth int, continuation string, highlights []Highlight) (string, int)
- func (m ConcatItem) Width() int
- type Highlight
- type Item
- type Match
- type MultiLineItem
- func (m MultiLineItem) ByteRangesToMatches(byteRanges []ByteRange) []Match
- func (m MultiLineItem) Content() string
- func (m MultiLineItem) ContentNoAnsi() string
- func (m MultiLineItem) ExtractExactMatches(exactMatch string) []Match
- func (m MultiLineItem) ExtractRegexMatches(regex *regexp.Regexp) []Match
- func (m MultiLineItem) LineBrokenItem(idx int) SingleItem
- func (m MultiLineItem) LineBrokenItems() []Item
- func (m MultiLineItem) NumLineBrokenItems() int
- func (m MultiLineItem) NumWrappedLines(wrapWidth int) int
- func (m MultiLineItem) String() string
- func (m MultiLineItem) Take(_, _ int, _ string, _ []Highlight) (string, int)
- func (m MultiLineItem) Width() int
- type SingleItem
- func (l SingleItem) ByteRangesToMatches(byteRanges []ByteRange) []Match
- func (l SingleItem) Content() string
- func (l SingleItem) ContentNoAnsi() string
- func (l SingleItem) ExtractExactMatches(exactMatch string) []Match
- func (l SingleItem) ExtractRegexMatches(regex *regexp.Regexp) []Match
- func (l SingleItem) LineBrokenItems() []Item
- func (l SingleItem) NumWrappedLines(wrapWidth int) int
- func (l SingleItem) Take(widthToLeft, takeWidth int, continuation string, highlights []Highlight) (string, int)
- func (l SingleItem) Width() int
- type WidthRange
Constants ¶
const RST = "\x1b[m"
RST is the ansi escape sequence for resetting styles lipgloss v2 uses the short form "\x1b[m"
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ConcatItem ¶
type ConcatItem struct {
// contains filtered or unexported fields
}
ConcatItem implements Item by wrapping multiple SingleItem's without extra memory allocation It is useful for e.g. prefixing content on an Item without needing to recompute that entire Item.
func NewConcat ¶
func NewConcat(items ...SingleItem) ConcatItem
NewConcat creates a new ConcatItem from the given items
func NewConcatWithPinned ¶
func NewConcatWithPinned(pinnedCount int, items ...SingleItem) ConcatItem
NewConcatWithPinned creates a new ConcatItem with the first pinnedCount items pinned to the left. Pinned items are not affected by horizontal panning (widthToLeft) in Take().
func (ConcatItem) ByteRangesToMatches ¶
func (m ConcatItem) ByteRangesToMatches(byteRanges []ByteRange) []Match
ByteRangesToMatches converts byte ranges in the concatenated ANSI-stripped content to Matches.
func (ConcatItem) Content ¶
func (m ConcatItem) Content() string
Content returns the concatenated content of all items.
func (ConcatItem) ContentNoAnsi ¶
func (m ConcatItem) ContentNoAnsi() string
ContentNoAnsi returns the concatenated content of all items without ANSI escape codes that style the string
func (ConcatItem) ExtractExactMatches ¶
func (m ConcatItem) ExtractExactMatches(exactMatch string) []Match
ExtractExactMatches extracts exact matches from the item's content without ANSI codes
func (ConcatItem) ExtractRegexMatches ¶
func (m ConcatItem) ExtractRegexMatches(regex *regexp.Regexp) []Match
ExtractRegexMatches extracts regex matches from the item's content without ANSI codes
func (ConcatItem) LineBrokenItems ¶
func (m ConcatItem) LineBrokenItems() []Item
LineBrokenItems returns a slice containing just this item (single-line).
func (ConcatItem) NumWrappedLines ¶
func (m ConcatItem) NumWrappedLines(wrapWidth int) int
NumWrappedLines returns the number of wrapped lines given a wrap width
func (ConcatItem) Take ¶
func (m ConcatItem) Take( widthToLeft, takeWidth int, continuation string, highlights []Highlight, ) (string, int)
Take returns a substring of the item that fits within the specified width. If pinnedCount > 0, the first pinnedCount items are rendered at offset 0 (ignoring widthToLeft), and the remaining items are rendered with widthToLeft applied in the remaining viewport width.
func (ConcatItem) Width ¶
func (m ConcatItem) Width() int
Width returns the total width across all items.
type Item ¶
type Item interface {
// Width returns the total width in terminal cells
Width() int
// Content returns the underlying complete string
Content() string
// ContentNoAnsi returns the underlying complete string without ANSI escape codes that style the string
ContentNoAnsi() string
// Take takes a substring (line) of the content with a specified widthToLeft and taking takeWidth.
// continuation replaces the start and end if the content exceeds the bounds.
// highlights is a list of highlights to apply to the taken content.
// Returns the line and the actual width taken
Take(
widthToLeft,
takeWidth int,
continuation string,
highlights []Highlight,
) (string, int)
// NumWrappedLines returns the number of wrapped lines given a wrap width
NumWrappedLines(wrapWidth int) int
// ExtractExactMatches extracts exact matches from the item's content without ANSI codes
ExtractExactMatches(exactMatch string) []Match
// ExtractRegexMatches extracts regex matches from the item's content without ANSI codes
ExtractRegexMatches(regex *regexp.Regexp) []Match
// ByteRangesToMatches converts byte ranges in the ANSI-stripped content to Matches
// with both byte ranges and width ranges populated.
ByteRangesToMatches(byteRanges []ByteRange) []Match
// LineBrokenItems returns the sub-items of this item, each rendered on a separate line.
// For single-line items, returns a slice containing just self.
// For multi-line items, returns one item per content line with line breaks between them.
LineBrokenItems() []Item
// contains filtered or unexported methods
}
Item defines the interface for item implementations
type Match ¶
type Match struct {
ByteRange ByteRange
WidthRange WidthRange
}
Match represents a range of bytes and their according start and end width in an item
type MultiLineItem ¶
type MultiLineItem struct {
// contains filtered or unexported fields
}
MultiLineItem implements Item by wrapping multiple SingleItems, rendered with line breaks between them. Each individual SingleItem may span multiple terminal lines if it wraps, but the MultiLineItem itself does not concatenate and wrap content across items (for that, see ConcatItem). Take() must not be called on a MultiLineItem — callers should use Take() on individual items returned by LineBrokenItems() instead.
func NewMultiLineItem ¶
func NewMultiLineItem(items ...SingleItem) MultiLineItem
NewMultiLineItem creates a new MultiLineItem from the given items.
func (MultiLineItem) ByteRangesToMatches ¶
func (m MultiLineItem) ByteRangesToMatches(byteRanges []ByteRange) []Match
ByteRangesToMatches converts byte ranges in the concatenated ANSI-stripped content to Matches.
func (MultiLineItem) Content ¶
func (m MultiLineItem) Content() string
Content returns the content of all items joined with newlines.
func (MultiLineItem) ContentNoAnsi ¶
func (m MultiLineItem) ContentNoAnsi() string
ContentNoAnsi returns the content of all items joined with newlines, without ANSI codes.
func (MultiLineItem) ExtractExactMatches ¶
func (m MultiLineItem) ExtractExactMatches(exactMatch string) []Match
ExtractExactMatches extracts exact matches from the concatenated content. Byte ranges are relative to ContentNoAnsi(). Width ranges are cumulative across items.
func (MultiLineItem) ExtractRegexMatches ¶
func (m MultiLineItem) ExtractRegexMatches(regex *regexp.Regexp) []Match
ExtractRegexMatches extracts regex matches from the concatenated content.
func (MultiLineItem) LineBrokenItem ¶
func (m MultiLineItem) LineBrokenItem(idx int) SingleItem
LineBrokenItem returns the line-broken item at the given index.
func (MultiLineItem) LineBrokenItems ¶
func (m MultiLineItem) LineBrokenItems() []Item
LineBrokenItems returns the individual items, each rendered on a separate line.
func (MultiLineItem) NumLineBrokenItems ¶
func (m MultiLineItem) NumLineBrokenItems() int
NumLineBrokenItems returns the number of line-broken items.
func (MultiLineItem) NumWrappedLines ¶
func (m MultiLineItem) NumWrappedLines(wrapWidth int) int
NumWrappedLines returns the total number of terminal lines needed to render all line-broken items, where each item wraps independently.
func (MultiLineItem) String ¶
func (m MultiLineItem) String() string
String returns the content for fmt.Stringer compatibility.
func (MultiLineItem) Take ¶
Take must not be called on a MultiLineItem. Callers should render individual items returned by LineBrokenItems() instead.
func (MultiLineItem) Width ¶
func (m MultiLineItem) Width() int
Width returns the total width in cells across all line-broken items.
type SingleItem ¶
type SingleItem struct {
// contains filtered or unexported fields
}
SingleItem provides functionality to get sequential strings of a specified terminal cell width, accounting for the ansi escape codes styling the line.
func NewItem ¶
func NewItem(line string) SingleItem
NewItem creates a new SingleItem from the given string.
func (SingleItem) ByteRangesToMatches ¶
func (l SingleItem) ByteRangesToMatches(byteRanges []ByteRange) []Match
ByteRangesToMatches converts byte ranges in the ANSI-stripped content to Matches.
func (SingleItem) Content ¶
func (l SingleItem) Content() string
Content returns the underlying string content
func (SingleItem) ContentNoAnsi ¶
func (l SingleItem) ContentNoAnsi() string
ContentNoAnsi returns the underlying string content without ANSI escape codes
func (SingleItem) ExtractExactMatches ¶
func (l SingleItem) ExtractExactMatches(exactMatch string) []Match
ExtractExactMatches extracts exact matches from the item's content without ANSI codes
func (SingleItem) ExtractRegexMatches ¶
func (l SingleItem) ExtractRegexMatches(regex *regexp.Regexp) []Match
ExtractRegexMatches extracts regex matches from the item's content without ANSI codes
func (SingleItem) LineBrokenItems ¶
func (l SingleItem) LineBrokenItems() []Item
LineBrokenItems returns a slice containing just this item (single-line).
func (SingleItem) NumWrappedLines ¶
func (l SingleItem) NumWrappedLines(wrapWidth int) int
NumWrappedLines returns the number of wrapped lines given a wrap width
func (SingleItem) Take ¶
func (l SingleItem) Take( widthToLeft, takeWidth int, continuation string, highlights []Highlight, ) (string, int)
Take returns a substring of the item that fits within the specified width
func (SingleItem) Width ¶
func (l SingleItem) Width() int
Width returns the total width in terminal cells.
type WidthRange ¶
type WidthRange struct {
Start, End int
}
WidthRange represents a range of character widths in terminal cells