ansi

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ANSIConverter

type ANSIConverter struct {
	// contains filtered or unexported fields
}

ANSIConverter converts ANSI escape sequences to HTML.

func NewANSIConverter

func NewANSIConverter() *ANSIConverter

NewANSIConverter creates a new ANSI to HTML converter

func (*ANSIConverter) ConvertToHTML

func (c *ANSIConverter) ConvertToHTML(input string) (string, error)

ConvertToHTML converts ANSI-formatted text to HTML

func (*ANSIConverter) ConvertToPlainText

func (c *ANSIConverter) ConvertToPlainText(input string) string

ConvertToPlainText removes ANSI escape sequences and returns plain text

type ANSIParser

type ANSIParser struct {
	// contains filtered or unexported fields
}

ANSIParser parses ANSI escape sequences from text.

func NewANSIParser

func NewANSIParser() *ANSIParser

NewANSIParser creates a new ANSI parser

func (*ANSIParser) Parse

func (p *ANSIParser) Parse(input string) ([]ANSIToken, error)

Parse parses the input string and returns a slice of ANSI tokens

func (*ANSIParser) ParseSimple

func (p *ANSIParser) ParseSimple(input string) string

ParseSimple is a helper method that parses input and returns just the text content with escape sequences removed. Useful for extracting plain text.

type ANSIState

type ANSIState struct {
	Bold          bool
	Italic        bool
	Underline     bool
	StrikeThrough bool
	FgColor       string
	BgColor       string
}

ANSIState tracks the current ANSI formatting state.

func NewANSIState

func NewANSIState() *ANSIState

NewANSIState creates a new ANSI state with default values

func (*ANSIState) ApplyCodes

func (s *ANSIState) ApplyCodes(codes []int, colorMapper *ColorMapper)

ApplyCodes applies ANSI codes to update the current state

func (*ANSIState) Clone

func (s *ANSIState) Clone() *ANSIState

Clone creates a copy of the current state

func (*ANSIState) GetClasses

func (s *ANSIState) GetClasses() []string

GetClasses returns CSS classes based on the current state

func (*ANSIState) GetStyles

func (s *ANSIState) GetStyles() map[string]string

GetStyles returns CSS styles based on the current state

func (*ANSIState) HasFormatting

func (s *ANSIState) HasFormatting() bool

HasFormatting returns true if the state has any formatting applied

func (*ANSIState) Reset

func (s *ANSIState) Reset()

Reset resets the state to default values

type ANSIToken

type ANSIToken struct {
	Type    TokenType
	Content string
	Codes   []int
}

ANSIToken represents a parsed ANSI token.

type ColorMapper

type ColorMapper struct {
	// contains filtered or unexported fields
}

ColorMapper maps ANSI color codes to CSS colors.

func NewColorMapper

func NewColorMapper() *ColorMapper

NewColorMapper creates a new color mapper with standard ANSI colors

func (*ColorMapper) Get256Color

func (m *ColorMapper) Get256Color(index int) string

Get256Color returns the CSS color for a 256-color palette index

func (*ColorMapper) GetBackgroundColor

func (m *ColorMapper) GetBackgroundColor(code int) (string, bool)

GetBackgroundColor returns the CSS color for a background ANSI code

func (*ColorMapper) GetForegroundColor

func (m *ColorMapper) GetForegroundColor(code int) (string, bool)

GetForegroundColor returns the CSS color for a foreground ANSI code

func (*ColorMapper) GetRGBColor

func (m *ColorMapper) GetRGBColor(r, g, b int) string

GetRGBColor returns the CSS color for RGB values

type TokenType

type TokenType int

TokenType represents the type of ANSI token.

const (
	// TokenText represents plain text content
	TokenText TokenType = iota
	// TokenEscapeSequence represents an ANSI escape sequence
	TokenEscapeSequence
)

Jump to

Keyboard shortcuts

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