types

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SauceRecordSize = 128 // Size of SAUCE record (without EOF marker)
	SauceTotalSize  = 129 // Total size including EOF marker
	SauceEOF        = 0x1A
	SauceID         = "SAUCE00"

	// DataType values
	SauceDataTypeNone       = 0
	SauceDataTypeCharacter  = 1 // Character-based (ANSI, ASCII, etc.)
	SauceDataTypeBitmap     = 2
	SauceDataTypeVector     = 3
	SauceDataTypeAudio      = 4
	SauceDataTypeBinaryText = 5
	SauceDataTypeXBin       = 6
	SauceDataTypeArchive    = 7
	SauceDataTypeExecutable = 8

	// FileType values for DataType=Character (1)
	SauceFileTypeASCII      = 0
	SauceFileTypeANSi       = 1
	SauceFileTypeANSiMation = 2
	SauceFileTypeRIPScript  = 3
	SauceFileTypePCBoard    = 4
	SauceFileTypeAvatar     = 5
	SauceFileTypeHTML       = 6
	SauceFileTypeSource     = 7
	SauceFileTypeTundraDraw = 8
)

SAUCE record constants

View Source
const (
	SauceFlagNonBlink      = 0x01 // iCE colors (use background bright colors instead of blink)
	SauceFlagLetterSpacing = 0x06 // Bits 1-2: letter spacing
	SauceFlagAspectRatio   = 0x18 // Bits 3-4: aspect ratio
)

TFlags bit flags

Variables

View Source
var C0Names = map[byte]string{
	0x00: "NUL",
	0x01: "SOH",
	0x02: "STX",
	0x03: "ETX",
	0x04: "EOT",
	0x05: "ENQ",
	0x06: "ACK",
	0x07: "BEL",
	0x08: "BS",
	0x09: "HT",
	0x0A: "LF",
	0x0B: "VT",
	0x0C: "FF",
	0x0D: "CR",
	0x0E: "SO",
	0x0F: "SI",
	0x10: "DLE",
	0x11: "DC1",
	0x12: "DC2",
	0x13: "DC3",
	0x14: "DC4",
	0x15: "NAK",
	0x16: "SYN",
	0x17: "ETB",
	0x18: "CAN",
	0x19: "EM",
	0x1A: "SUB",
	0x1B: "ESC",
	0x1C: "FS",
	0x1D: "GS",
	0x1E: "RS",
	0x1F: "US",
}

C0 control codes names

View Source
var VGAPalette = [16][3]uint8{
	{0x00, 0x00, 0x00},
	{0xAA, 0x00, 0x00},
	{0x00, 0xAA, 0x00},
	{0xAA, 0x55, 0x00},
	{0x00, 0x00, 0xAA},
	{0xAA, 0x00, 0xAA},
	{0x00, 0xAA, 0xAA},
	{0xAA, 0xAA, 0xAA},
	{0x55, 0x55, 0x55},
	{0xFF, 0x55, 0x55},
	{0x55, 0xFF, 0x55},
	{0xFF, 0xFF, 0x55},
	{0x55, 0x55, 0xFF},
	{0xFF, 0x55, 0xFF},
	{0x55, 0xFF, 0xFF},
	{0xFF, 0xFF, 0xFF},
}

VGA Palette with exact VGA hardware color values

Functions

func ParseRGBHex added in v0.13.0

func ParseRGBHex(hexStr string) (r, g, b uint8, err error)

ParseRGBHex parses a 6-character hex string (RRGGBB) and returns R, G, B values.

Types

type Cell

type Cell struct {
	Char      rune
	SGR       *SGR
	Hyperlink *Hyperlink // Optional hyperlink (OSC 8)
}

Cell represents a single character in the virtual terminal buffer with its associated SGR (Select Graphic Rendition) styling.

func NewCell

func NewCell() Cell

NewCell creates a new empty cell with default SGR styling.

func (Cell) Copy

func (c Cell) Copy() Cell

Copy returns a deep copy of the cell.

type ColorType

type ColorType int
const (
	ColorDefault  ColorType = iota
	ColorStandard           // 0-15 (codes 30-37, 90-97, etc.)
	ColorIndexed            // 0-255 (ESC[38;5;n)
	ColorRGB                // RGB (ESC[38;2;r;g;b)
)

type ColorValue

type ColorValue struct {
	Type    ColorType
	R, G, B uint8
	Index   uint8
}

func ParseNeotexColor added in v0.13.0

func ParseNeotexColor(code string, isForeground bool) (ColorValue, error)

ParseNeotexColor parses a neotex color code for a known target. The code may include an optional F/B prefix (e.g. Fk, B00FF00).

func ParseNeotexColorCode added in v0.13.0

func ParseNeotexColorCode(code string) (isForeground bool, color ColorValue, ok bool, err error)

ParseNeotexColorCode parses a neotex color code with an explicit F/B prefix. Returns ok=false when the code does not look like a color code.

func (ColorValue) IsDefault

func (c ColorValue) IsDefault() bool

func (ColorValue) String

func (c ColorValue) String() string

type CropRegion

type CropRegion struct {
	X      int // Start X (column)
	Y      int // Start Y (row)
	Width  int // Width of region
	Height int // Height of region
}

CropRegion defines a rectangular region for cropping. Coordinates are 1-indexed in input, stored as 0-indexed internally.

func ParseCropRegion

func ParseCropRegion(s string) (*CropRegion, error)

ParseCropRegion parses a crop string in format "x,y:x1,y1" (start:end coordinates). Coordinates are 1-indexed (first column/row is 1, not 0). Returns nil if the string is empty.

func (*CropRegion) IsSet

func (c *CropRegion) IsSet() bool

IsSet returns true if the crop region is defined (not nil).

type Hyperlink struct {
	URL     string            // The target URL
	Params  map[string]string // Optional parameters (e.g., id=xyz)
	HoverFg *ColorValue       // Optional hover foreground color
	HoverBg *ColorValue       // Optional hover background color
}

Hyperlink represents an OSC 8 hyperlink with URL and optional parameters. OSC 8 format: ESC ] 8 ; params ; URL ST text ESC ] 8 ; ; ST

func NewHyperlink(url string) *Hyperlink

NewHyperlink creates a new Hyperlink with the given URL.

func (*Hyperlink) Copy added in v0.4.0

func (h *Hyperlink) Copy() *Hyperlink

Copy returns a deep copy of the Hyperlink.

func (*Hyperlink) Equals added in v0.4.0

func (h *Hyperlink) Equals(other *Hyperlink) bool

Equals checks if two Hyperlinks are equal.

type HyperlinkSequence added in v0.4.0

type HyperlinkSequence struct {
	Position  int        // Position of the character in the line (0-indexed)
	Hyperlink *Hyperlink // The hyperlink to apply (nil = hyperlink OFF)
}

HyperlinkSequence represents a hyperlink state change at a specific position

type LineWithSequences

type LineWithSequences struct {
	Text               string
	Sequences          []SGRSequence
	HyperlinkSequences []HyperlinkSequence
	OrderedSequences   []SequenceOp
	Comment            string
}

LineWithSequences contains a line of text and all SGR changes within that line

type SGR

type SGR struct {
	FgColor       ColorValue
	BgColor       ColorValue
	Bold          bool
	Dim           bool
	Italic        bool
	Underline     bool
	Blink         bool
	Reverse       bool
	Hidden        bool
	Strikethrough bool
	LinkFgColor   ColorValue
	LinkBgColor   ColorValue
}

func NewSGR

func NewSGR() *SGR

func (*SGR) ApplyParams

func (s *SGR) ApplyParams(params []int)

func (*SGR) Copy

func (s *SGR) Copy() *SGR

func (*SGR) Diff

func (s *SGR) Diff(previous *SGR, legacyMode bool) []int

Diff returns the minimal set of SGR codes to transition from previous to current state. If previous is nil, returns full state codes. If legacyMode is true, uses [0m + full state when any attribute needs to be turned OFF. If legacyMode is false, uses individual OFF codes (22, 23, 24, etc.).

func (*SGR) DiffToANSI

func (s *SGR) DiffToANSI(previous *SGR, useVGAColors bool, legacyMode bool) string

DiffToANSI generates the minimal ANSI escape sequence to transition from previous to current state. If legacyMode is true, uses [0m + full state when attributes need to be turned OFF (ANSI 1990 compatible). If legacyMode is false, uses individual OFF codes (modern terminals).

func (*SGR) Equals

func (s *SGR) Equals(other *SGR) bool

func (*SGR) Reset

func (s *SGR) Reset()

func (*SGR) String

func (s *SGR) String() string

func (*SGR) ToANSI

func (s *SGR) ToANSI(useVGAColors bool, legacyMode bool) string

type SGRSequence

type SGRSequence struct {
	Position int  // Position of the character in the line (0-indexed)
	SGR      *SGR // The SGR sequence to apply from this position
}

SGRSequence represents a SGR style at a specific position in a line

type Sauce added in v0.3.0

type Sauce struct {
	Title    string    // 35 characters max - Title of the file
	Author   string    // 20 characters max - Author/creator name
	Group    string    // 20 characters max - Group/organization name
	Date     time.Time // Creation date (stored as YYYYMMDD)
	FileSize uint32    // Size of the file before SAUCE record
	DataType uint8     // Type of data (1 = Character for ANSI)
	FileType uint8     // File type (1 = ANSi for DataType=Character)
	TInfo1   uint16    // Width in characters
	TInfo2   uint16    // Height in lines
	TInfo3   uint16    // Reserved (0 for ANSI)
	TInfo4   uint16    // Reserved (0 for ANSI)
	Comments uint8     // Number of comment lines (0-255)
	TFlags   uint8     // Flags (iCE colors, letter spacing, aspect ratio)
	TInfoS   string    // 22 characters max - Font name/info
}

Sauce represents a SAUCE (Standard Architecture for Universal Comment Extensions) record. SAUCE is a 128-byte metadata block appended to the end of ANSI art files.

func FromBytes added in v0.3.0

func FromBytes(data []byte) (*Sauce, error)

FromBytes parses a 129-byte slice (EOF + 128-byte record) into a Sauce struct. Returns an error if the data is invalid (wrong size, missing SAUCE00 signature).

func FromBytesWithEncoding added in v0.3.0

func FromBytesWithEncoding(data []byte, sourceEncoding string) (*Sauce, error)

FromBytesWithEncoding parses a 129-byte slice and converts text fields from source encoding. This is used when the SAUCE record was extracted before encoding conversion to preserve binary fields (FileSize, TInfo1-4, etc.) while still converting text fields.

func NewSauce added in v0.3.0

func NewSauce(width, height int) *Sauce

NewSauce creates a new SAUCE record with default values for ANSI files. Width and height are stored in TInfo1 and TInfo2 respectively.

func (*Sauce) HasICEColors added in v0.3.0

func (s *Sauce) HasICEColors() bool

HasICEColors returns true if iCE colors are enabled.

func (*Sauce) SetDimensions added in v0.3.0

func (s *Sauce) SetDimensions(width, height int)

SetDimensions sets the width and height in the SAUCE record.

func (*Sauce) SetICEColors added in v0.3.0

func (s *Sauce) SetICEColors(enabled bool)

SetICEColors enables or disables iCE colors (non-blink mode).

func (*Sauce) ToBytes added in v0.3.0

func (s *Sauce) ToBytes() []byte

ToBytes serializes the SAUCE record to a 129-byte slice (EOF + 128-byte record). Format:

Offset  Size  Field
0       1     EOF (0x1A)
1       5     "SAUCE"
6       2     "00"
8       35    Title
43      20    Author
63      20    Group
83      8     Date (YYYYMMDD)
91      4     FileSize (little-endian)
95      1     DataType
96      1     FileType
97      2     TInfo1/Width (little-endian)
99      2     TInfo2/Height (little-endian)
101     2     TInfo3 (little-endian)
103     2     TInfo4 (little-endian)
105     1     Comments
106     1     TFlags
107     22    TInfoS

type SequenceOp added in v0.15.0

type SequenceOp struct {
	Position  int
	Order     int
	Kind      SequenceOpKind
	Scope     SequenceScope
	SGR       *SGR
	Hyperlink *Hyperlink
	Control   string
}

SequenceOp represents an ordered sequence operation at a position. The Scope determines whether it is emitted to export (EX/VX) and/or applied to the virtual terminal (VT/VX).

type SequenceOpKind added in v0.15.0

type SequenceOpKind int

SequenceOpKind identifies the operation kind for ordered sequences.

const (
	SequenceOpSGR SequenceOpKind = iota
	SequenceOpHyperlink
	SequenceOpControl
)

type SequenceScope added in v0.15.0

type SequenceScope int
const (
	ScopeVT SequenceScope = iota
	ScopeEX
	ScopeVX
)

func ParseSequenceScope added in v0.15.0

func ParseSequenceScope(value string) (SequenceScope, bool)

func (SequenceScope) IncludesExport added in v0.15.0

func (s SequenceScope) IncludesExport() bool

func (SequenceScope) IncludesVT added in v0.15.0

func (s SequenceScope) IncludesVT() bool

func (SequenceScope) MarshalJSON added in v0.15.0

func (s SequenceScope) MarshalJSON() ([]byte, error)

func (SequenceScope) Normalize added in v0.15.0

func (s SequenceScope) Normalize() SequenceScope

func (SequenceScope) String added in v0.15.0

func (s SequenceScope) String() string

func (*SequenceScope) UnmarshalJSON added in v0.15.0

func (s *SequenceScope) UnmarshalJSON(data []byte) error

type Token

type Token struct {
	Type          TokenType     `json:"type"`
	Pos           int           `json:"pos"`
	Scope         SequenceScope `json:"scope,omitempty"`
	Line          int           `json:"line,omitempty"`
	Comment       string        `json:"comment,omitempty"`
	Raw           string        `json:"raw"`
	Value         string        `json:"value,omitempty"`
	Parameters    []string      `json:"parameters,omitempty"`
	C0Code        byte          `json:"c0_code,omitempty"`
	C1Code        string        `json:"c1_code,omitempty"`
	CSINotation   string        `json:"csi_notation,omitempty"`
	Signification string        `json:"signification,omitempty"`
	Sauce         *Sauce        `json:"sauce,omitempty"`
	Hyperlink     *Hyperlink    `json:"hyperlink,omitempty"` // OSC 8 hyperlink
}

func (Token) String

func (t Token) String() string

type TokenStats

type TokenStats struct {
	TotalTokens         int               `json:"total_tokens"`
	TokensByType        map[TokenType]int `json:"tokens_by_type"`
	SGRCodes            map[string]int    `json:"sgr_codes"`
	CSISequences        map[string]int    `json:"csi_sequences"`
	C0Codes             map[byte]int      `json:"c0_codes"`
	C1Codes             map[string]int    `json:"c1_codes"`
	TotalTextLength     int               `json:"total_text_length"`
	FileSize            int64             `json:"file_size"`
	ParsedPercent       float64           `json:"parsed_percent"`
	PosFirstBadSequence int64             `json:"pos_first_bad_sequence"`
}

type TokenType

type TokenType int
const (
	TokenText TokenType = iota
	TokenC0
	TokenC1
	TokenCSI
	TokenCSIInterupted
	TokenSGR
	TokenHoverFg
	TokenHoverBg
	TokenDCS
	TokenOSC
	TokenEscape
	TokenSauce
	TokenSequenceComment
	TokenUnknown
)

func (TokenType) MarshalJSON

func (t TokenType) MarshalJSON() ([]byte, error)

func (TokenType) String

func (t TokenType) String() string

func (*TokenType) UnmarshalJSON

func (t *TokenType) UnmarshalJSON(data []byte) error

type Tokenizer

type Tokenizer interface {
	Tokenize() []Token
}

type TokenizerWithStats

type TokenizerWithStats interface {
	Tokenizer
	GetStats() TokenStats
}

Tokenize with statistics

Jump to

Keyboard shortcuts

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