source dump of claude code
at main 75 lines 1.5 kB view raw
1/** 2 * ANSI Control Characters and Escape Sequence Introducers 3 * 4 * Based on ECMA-48 / ANSI X3.64 standards. 5 */ 6 7/** 8 * C0 (7-bit) control characters 9 */ 10export const C0 = { 11 NUL: 0x00, 12 SOH: 0x01, 13 STX: 0x02, 14 ETX: 0x03, 15 EOT: 0x04, 16 ENQ: 0x05, 17 ACK: 0x06, 18 BEL: 0x07, 19 BS: 0x08, 20 HT: 0x09, 21 LF: 0x0a, 22 VT: 0x0b, 23 FF: 0x0c, 24 CR: 0x0d, 25 SO: 0x0e, 26 SI: 0x0f, 27 DLE: 0x10, 28 DC1: 0x11, 29 DC2: 0x12, 30 DC3: 0x13, 31 DC4: 0x14, 32 NAK: 0x15, 33 SYN: 0x16, 34 ETB: 0x17, 35 CAN: 0x18, 36 EM: 0x19, 37 SUB: 0x1a, 38 ESC: 0x1b, 39 FS: 0x1c, 40 GS: 0x1d, 41 RS: 0x1e, 42 US: 0x1f, 43 DEL: 0x7f, 44} as const 45 46// String constants for output generation 47export const ESC = '\x1b' 48export const BEL = '\x07' 49export const SEP = ';' 50 51/** 52 * Escape sequence type introducers (byte after ESC) 53 */ 54export const ESC_TYPE = { 55 CSI: 0x5b, // [ - Control Sequence Introducer 56 OSC: 0x5d, // ] - Operating System Command 57 DCS: 0x50, // P - Device Control String 58 APC: 0x5f, // _ - Application Program Command 59 PM: 0x5e, // ^ - Privacy Message 60 SOS: 0x58, // X - Start of String 61 ST: 0x5c, // \ - String Terminator 62} as const 63 64/** Check if a byte is a C0 control character */ 65export function isC0(byte: number): boolean { 66 return byte < 0x20 || byte === 0x7f 67} 68 69/** 70 * Check if a byte is an ESC sequence final byte (0-9, :, ;, <, =, >, ?, @ through ~) 71 * ESC sequences have a wider final byte range than CSI 72 */ 73export function isEscFinal(byte: number): boolean { 74 return byte >= 0x30 && byte <= 0x7e 75}