ansis

package
v0.20.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

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

func StylesEqual(a, b lipgloss.Style) bool

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL