/ ink / termio / dec.ts
dec.ts
 1  /**
 2   * DEC (Digital Equipment Corporation) Private Mode Sequences
 3   *
 4   * DEC private modes use CSI ? N h (set) and CSI ? N l (reset) format.
 5   * These are terminal-specific extensions to the ANSI standard.
 6   */
 7  
 8  import { csi } from './csi.js'
 9  
10  /**
11   * DEC private mode numbers
12   */
13  export const DEC = {
14    CURSOR_VISIBLE: 25,
15    ALT_SCREEN: 47,
16    ALT_SCREEN_CLEAR: 1049,
17    MOUSE_NORMAL: 1000,
18    MOUSE_BUTTON: 1002,
19    MOUSE_ANY: 1003,
20    MOUSE_SGR: 1006,
21    FOCUS_EVENTS: 1004,
22    BRACKETED_PASTE: 2004,
23    SYNCHRONIZED_UPDATE: 2026,
24  } as const
25  
26  /** Generate CSI ? N h sequence (set mode) */
27  export function decset(mode: number): string {
28    return csi(`?${mode}h`)
29  }
30  
31  /** Generate CSI ? N l sequence (reset mode) */
32  export function decreset(mode: number): string {
33    return csi(`?${mode}l`)
34  }
35  
36  // Pre-generated sequences for common modes
37  export const BSU = decset(DEC.SYNCHRONIZED_UPDATE)
38  export const ESU = decreset(DEC.SYNCHRONIZED_UPDATE)
39  export const EBP = decset(DEC.BRACKETED_PASTE)
40  export const DBP = decreset(DEC.BRACKETED_PASTE)
41  export const EFE = decset(DEC.FOCUS_EVENTS)
42  export const DFE = decreset(DEC.FOCUS_EVENTS)
43  export const SHOW_CURSOR = decset(DEC.CURSOR_VISIBLE)
44  export const HIDE_CURSOR = decreset(DEC.CURSOR_VISIBLE)
45  export const ENTER_ALT_SCREEN = decset(DEC.ALT_SCREEN_CLEAR)
46  export const EXIT_ALT_SCREEN = decreset(DEC.ALT_SCREEN_CLEAR)
47  // Mouse tracking: 1000 reports button press/release/wheel, 1002 adds drag
48  // events (button-motion), 1003 adds all-motion (no button held — for
49  // hover), 1006 uses SGR format (CSI < btn;col;row M/m) instead of legacy
50  // X10 bytes. Combined: wheel + click/drag for selection + hover.
51  export const ENABLE_MOUSE_TRACKING =
52    decset(DEC.MOUSE_NORMAL) +
53    decset(DEC.MOUSE_BUTTON) +
54    decset(DEC.MOUSE_ANY) +
55    decset(DEC.MOUSE_SGR)
56  export const DISABLE_MOUSE_TRACKING =
57    decreset(DEC.MOUSE_SGR) +
58    decreset(DEC.MOUSE_ANY) +
59    decreset(DEC.MOUSE_BUTTON) +
60    decreset(DEC.MOUSE_NORMAL)