Categorygithub.com/danielgatis/go-ansicode
repositorypackage
1.0.6
Repository: https://github.com/danielgatis/go-ansicode.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# README

go-ansicode

Go Report Card License MIT Go Doc

go-ansicode is a package that interprets ANSI codes and allows you to register a handler to deal with the operations.

Supported Sequences

C0

OperationDescription
NULNull (NUL) character.
SOHStart of Heading (SOH).
STXStart of Text (STX).
ETXEnd of Text (ETX).
EOTEnd of Transmission (EOT).
ENQEnquiry (ENQ).
ACKAcknowledge (ACK).
BELBell (BEL).
BSBackspace (BS).
HTHorizontal Tab (HT).
LFLine Feed (LF).
VTVertical Tab (VT).
FFForm Feed (FF).
CRCarriage Return (CR).
SOShift Out (SO).
SIShift In (SI).
DLEData Link Escape (DLE).
XONDevice Control 1 (XON).
DC2Device Control 2 (DC2).
XOFFDevice Control 3 (XOFF).
DC4Device Control 4 (DC4).
NAKNegative Acknowledge (NAK).
SYNSynchronous Idle (SYN).
ETBEnd of Transmission Block (ETB).
CANCancel (CAN).
EMEnd of Medium (EM).
SUBSubstitute (SUB).
ESCEscape (ESC).
FSFile Separator (FS).
GSGroup Separator (GS).
RSRecord Separator (RS).

C1

OperationDescription
INDIndex - Move to the next line (Line Feed)
NELNext Line - Line Feed followed by Carriage Return
HTSHorizontal Tab Set
RIReverse Index - Move to the previous line
DECIDIdentify Terminal - Request for terminal identification
RISReset to Initial State - Reset all settings to defaults
DECSCSave Cursor - Save current cursor position and attributes
DECRCRestore Cursor - Restore cursor position and attributes
DECALNAlignment Test - Perform an alignment test
DECKPAMKeypad Application Mode - Enable Keypad Application Mode
DECKPNMNumeric Mode - Disable Keypad Application Mode

CSI

CSI SequenceDescription
CSI Ps 'Single-character tabulation set (HTS)
CSI Ps @Character tabulation with justification (CHA)
CSI Ps ALine tabulation set (VTS)
CSI Ps BPartial line forward (incomplete)
CSI Ps bRepeat character (REP)
CSI Ps CCursor forward (CUF)
CSI Ps cSend device attributes (DA)
CSI Ps aCharacter position forward (CHA)
CSI Ps DCursor backward (CUB)
CSI Ps dVertical position absolute (VPA)
CSI Ps ENext line (NEL)
CSI Ps eVertical position relative (VPR)
CSI Ps FPrevious line (RI)
CSI Ps GHorizontal tab set (HTS)
CSI Ps gTab clear (TBC)
CSI Ps ; Ps HCursor position (CUP)
CSI Ps ; Ps fHorizontal and vertical position (HVP)
CSI Ps IForward tabulation (HT)
CSI Ps JErase in display (ED)
CSI Ps KErase in line (EL)
CSI Ps LInsert line (IL)
CSI Ps lReset mode (DEC)
CSI ? Ps lDEC private mode reset
CSI Ps MDelete line (DL)
CSI Pm mCharacter attribute (SGR)
CSI > Pp ; Pv mSelect character protection attribute (DECSCPP)
CSI ? Pp mSelect media character set and invoke macro (DECSEL)
CSI Ps nDevice status report (DSR)
CSI Ps PDelete character (DCH)
CSI Ps SP qSelect modifier and use bit combination (SMRM)
CSI Ps ; Ps rSet top and bottom margins (DECSTBM)
CSI Ps SScroll up (SU)
CSI sSave cursor position (SCP)
CSI Ps TScroll down (SD)
CSI Ps tWindow manipulation (DECSWT)
CSI uRestore cursor position (RCP)
CSI ? uDEC private mode reset
CSI = Ps ; Ps uSet conformance level (DECSCL)
CSI > Ps uSet ANSI conformance level (DECSASD)
CSI < Ps uSet conformance level (DECSCL)
CSI Ps XErase character (ECH)
CSI Ps ZCursor back tabulation (CBT)

OSC

OSC SequenceDescription
OSC 0 ; Pt BELSet icon name and window title
OSC 2 ; Pt BELSet window title
OSC 4 ; c ; spec BELChange color in palette (8/16 colors)
OSC 8 ; params ; uri BELSet hyperlinks
OSC 10 ; Ps BELSet foreground text color
OSC 11 ; Ps BELSet background text color
OSC 12 ; Ps BELSet cursor text color
OSC 104 ; c BELReset color in palette (8/16 colors)
OSC 110 BELReset icon name and window title
OSC 111 BELReset window title
OSC 112 BELReset color in palette (24-bit)

Install

go get -u github.com/danielgatis/go-ansicode

And then import the package in your code:

import "github.com/danielgatis/go-ansicode"

Example

Please look at: examples/ansilog/main.go

❯ echo -ne "\033[31;42mThis text is red on a green background\033[0m\nbye" | go run ./examples/ansilog/main.go
SetTerminalCharAttribute {22 0x14000112018 <nil> <nil>}
SetTerminalCharAttribute {23 0x14000112020 <nil> <nil>}
Input 84
Input 104
Input 105
Input 115
Input 32
Input 116
Input 101
Input 120
Input 116
Input 32
Input 105
Input 115
Input 32
Input 114
Input 101
Input 100
Input 32
Input 111
Input 110
Input 32
Input 97
Input 32
Input 103
Input 114
Input 101
Input 101
Input 110
Input 32
Input 98
Input 97
Input 99
Input 107
Input 103
Input 114
Input 111
Input 117
Input 110
Input 100
SetTerminalCharAttribute {0 <nil> <nil> <nil>}
LineFeed
Input 98
Input 121
Input 101

License

Copyright (c) 2023-present Daniel Gatis

Licensed under MIT License