Documentation
¶
Overview ¶
Package ansis provides utilities for ANSI text styling and manipulation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StylesEqual ¶
StylesEqual compares two lipgloss.Style objects for equality. This is a simple comparison that checks if the rendered output would be the same.
Types ¶
type StyleEditor ¶
type StyleEditor struct {
// contains filtered or unexported fields
}
StyleEditor handles applying style transformations to ANSI-styled text. It preserves existing ANSI styling while adding new styling to specific character ranges based on plain text positions.
This is particularly useful for:
- Search result highlighting in colored text
- Error marking in syntax-highlighted code
- Adding emphasis to specific parts of formatted output
- Creating interactive text displays with hover effects
It works by maintaining parallel indices into both the original styled text (with ANSI escape sequences) and the plain text (stripped of ANSI). When applying new styles, it maps plain text positions to styled text positions while preserving the original formatting.
func NewStyleEditor ¶
func NewStyleEditor(text string) *StyleEditor
NewStyleEditor creates a new StyleEditor for the given text.
func (*StyleEditor) ApplyStyles ¶
func (se *StyleEditor) ApplyStyles(ranges []StyleRange) string
ApplyStyles applies style ranges to the text while preserving existing styling. The ranges are applied in priority order, with higher priority ranges overriding lower ones.
type StyleRange ¶
type StyleRange struct {
Style lipgloss.Style // The style to apply to this range.
Start int // 0-based character position within the line (inclusive).
End int // 0-based character position within the line (exclusive).
Priority int // Priority for overlapping ranges (higher priority wins).
}
StyleRange represents a range of text that should have a specific style applied.