ansi.ts
ink/termio/ansi.ts
76
Lines
1490
Bytes
7
Exports
0
Imports
10
Keywords
What this is
This page documents one file from the repository and includes its full source so you can read it without leaving the docs site.
Beginner explanation
This file is one piece of the larger system. Its name, directory, imports, and exports show where it fits. Start by reading the exports and related files first.
How it is used
Start from the exports list and related files. Those are the easiest clues for where this file fits into the system.
Expert explanation
Architecturally, this file intersects with ui-flow. It contains 76 lines, 0 detected imports, and 7 detected exports.
Important relationships
Detected exports
C0ESCBELSEPESC_TYPEisC0isEscFinal
Keywords
bytecontrolsequenceansicharactersescapeintroducerscommandcheckfinal
Detected imports
- No import paths detected.
Source notes
This page embeds the full file contents. Small or leaf files are still indexed honestly instead of being over-explained.
Full source
/**
* ANSI Control Characters and Escape Sequence Introducers
*
* Based on ECMA-48 / ANSI X3.64 standards.
*/
/**
* C0 (7-bit) control characters
*/
export const C0 = {
NUL: 0x00,
SOH: 0x01,
STX: 0x02,
ETX: 0x03,
EOT: 0x04,
ENQ: 0x05,
ACK: 0x06,
BEL: 0x07,
BS: 0x08,
HT: 0x09,
LF: 0x0a,
VT: 0x0b,
FF: 0x0c,
CR: 0x0d,
SO: 0x0e,
SI: 0x0f,
DLE: 0x10,
DC1: 0x11,
DC2: 0x12,
DC3: 0x13,
DC4: 0x14,
NAK: 0x15,
SYN: 0x16,
ETB: 0x17,
CAN: 0x18,
EM: 0x19,
SUB: 0x1a,
ESC: 0x1b,
FS: 0x1c,
GS: 0x1d,
RS: 0x1e,
US: 0x1f,
DEL: 0x7f,
} as const
// String constants for output generation
export const ESC = '\x1b'
export const BEL = '\x07'
export const SEP = ';'
/**
* Escape sequence type introducers (byte after ESC)
*/
export const ESC_TYPE = {
CSI: 0x5b, // [ - Control Sequence Introducer
OSC: 0x5d, // ] - Operating System Command
DCS: 0x50, // P - Device Control String
APC: 0x5f, // _ - Application Program Command
PM: 0x5e, // ^ - Privacy Message
SOS: 0x58, // X - Start of String
ST: 0x5c, // \ - String Terminator
} as const
/** Check if a byte is a C0 control character */
export function isC0(byte: number): boolean {
return byte < 0x20 || byte === 0x7f
}
/**
* Check if a byte is an ESC sequence final byte (0-9, :, ;, <, =, >, ?, @ through ~)
* ESC sequences have a wider final byte range than CSI
*/
export function isEscFinal(byte: number): boolean {
return byte >= 0x30 && byte <= 0x7e
}