esc.ts
ink/termio/esc.ts
68
Lines
1444
Bytes
1
Exports
1
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 68 lines, 1 detected imports, and 1 detected exports.
Important relationships
Detected exports
parseEsc
Keywords
firstcursoractioncharsmovesequencecountsimplecharacterslength
Detected imports
./types.js
Source notes
This page embeds the full file contents. Small or leaf files are still indexed honestly instead of being over-explained.
Full source
/**
* ESC Sequence Parser
*
* Handles simple escape sequences: ESC + one or two characters
*/
import type { Action } from './types.js'
/**
* Parse a simple ESC sequence
*
* @param chars - Characters after ESC (not including ESC itself)
*/
export function parseEsc(chars: string): Action | null {
if (chars.length === 0) return null
const first = chars[0]!
// Full reset (RIS)
if (first === 'c') {
return { type: 'reset' }
}
// Cursor save (DECSC)
if (first === '7') {
return { type: 'cursor', action: { type: 'save' } }
}
// Cursor restore (DECRC)
if (first === '8') {
return { type: 'cursor', action: { type: 'restore' } }
}
// Index - move cursor down (IND)
if (first === 'D') {
return {
type: 'cursor',
action: { type: 'move', direction: 'down', count: 1 },
}
}
// Reverse index - move cursor up (RI)
if (first === 'M') {
return {
type: 'cursor',
action: { type: 'move', direction: 'up', count: 1 },
}
}
// Next line (NEL)
if (first === 'E') {
return { type: 'cursor', action: { type: 'nextLine', count: 1 } }
}
// Horizontal tab set (HTS)
if (first === 'H') {
return null // Tab stop, not commonly needed
}
// Charset selection (ESC ( X, ESC ) X, etc.) - silently ignore
if ('()'.includes(first) && chars.length >= 2) {
return null
}
// Unknown
return { type: 'unknown', sequence: `\x1b${chars}` }
}