Documentation
¶
Index ¶
- Constants
- Variables
- type Cell
- type ColorType
- type ColorValue
- type CropRegion
- type Hyperlink
- type HyperlinkSequence
- type LineWithSequences
- type SGR
- func (s *SGR) ApplyParams(params []int)
- func (s *SGR) Copy() *SGR
- func (s *SGR) Diff(previous *SGR, legacyMode bool) []int
- func (s *SGR) DiffToANSI(previous *SGR, useVGAColors bool, legacyMode bool) string
- func (s *SGR) Equals(other *SGR) bool
- func (s *SGR) Reset()
- func (s *SGR) String() string
- func (s *SGR) ToANSI(useVGAColors bool, legacyMode bool) string
- type SGRSequence
- type Sauce
- type Token
- type TokenStats
- type TokenType
- type Tokenizer
- type TokenizerWithStats
Constants ¶
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
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 ¶
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
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 ¶
This section is empty.
Types ¶
type Cell ¶
Cell represents a single character in the virtual terminal buffer with its associated SGR (Select Graphic Rendition) styling.
type ColorValue ¶
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 ¶ added in v0.4.0
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 ¶ added in v0.4.0
NewHyperlink creates a new Hyperlink with the given URL.
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
}
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 (*SGR) ApplyParams ¶
func (*SGR) Diff ¶
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 ¶
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).
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
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
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
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
HasICEColors returns true if iCE colors are enabled.
func (*Sauce) SetDimensions ¶ added in v0.3.0
SetDimensions sets the width and height in the SAUCE record.
func (*Sauce) SetICEColors ¶ added in v0.3.0
SetICEColors enables or disables iCE colors (non-blink mode).
func (*Sauce) ToBytes ¶ added in v0.3.0
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 Token ¶
type Token struct {
Type TokenType `json:"type"`
Pos int `json:"pos"`
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
}
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
func (TokenType) MarshalJSON ¶
func (*TokenType) UnmarshalJSON ¶
type TokenizerWithStats ¶
type TokenizerWithStats interface {
Tokenizer
GetStats() TokenStats
}
Tokenize with statistics