Open History to see the last commit
1/**
2 * @file device.h
3 *
4 * Device types used by the terminal for device status and device attribute
5 * queries.
6 */
7
8#ifndef GHOSTTY_VT_DEVICE_H
9#define GHOSTTY_VT_DEVICE_H
10
11#include <stddef.h>
12#include <stdint.h>
13
14#include <ghostty/vt/types.h>
15
16/* DA1 conformance levels (Pp parameter). */
17#define GHOSTTY_DA_CONFORMANCE_VT100 1
18#define GHOSTTY_DA_CONFORMANCE_VT101 1
19#define GHOSTTY_DA_CONFORMANCE_VT102 6
20#define GHOSTTY_DA_CONFORMANCE_VT125 12
21#define GHOSTTY_DA_CONFORMANCE_VT131 7
22#define GHOSTTY_DA_CONFORMANCE_VT132 4
23#define GHOSTTY_DA_CONFORMANCE_VT220 62
24#define GHOSTTY_DA_CONFORMANCE_VT240 62
25#define GHOSTTY_DA_CONFORMANCE_VT320 63
26#define GHOSTTY_DA_CONFORMANCE_VT340 63
27#define GHOSTTY_DA_CONFORMANCE_VT420 64
28#define GHOSTTY_DA_CONFORMANCE_VT510 65
29#define GHOSTTY_DA_CONFORMANCE_VT520 65
30#define GHOSTTY_DA_CONFORMANCE_VT525 65
31#define GHOSTTY_DA_CONFORMANCE_LEVEL_2 62
32#define GHOSTTY_DA_CONFORMANCE_LEVEL_3 63
33#define GHOSTTY_DA_CONFORMANCE_LEVEL_4 64
34#define GHOSTTY_DA_CONFORMANCE_LEVEL_5 65
35
36/* DA1 feature codes (Ps parameters). */
37#define GHOSTTY_DA_FEATURE_COLUMNS_132 1
38#define GHOSTTY_DA_FEATURE_PRINTER 2
39#define GHOSTTY_DA_FEATURE_REGIS 3
40#define GHOSTTY_DA_FEATURE_SIXEL 4
41#define GHOSTTY_DA_FEATURE_SELECTIVE_ERASE 6
42#define GHOSTTY_DA_FEATURE_USER_DEFINED_KEYS 8
43#define GHOSTTY_DA_FEATURE_NATIONAL_REPLACEMENT 9
44#define GHOSTTY_DA_FEATURE_TECHNICAL_CHARACTERS 15
45#define GHOSTTY_DA_FEATURE_LOCATOR 16
46#define GHOSTTY_DA_FEATURE_TERMINAL_STATE 17
47#define GHOSTTY_DA_FEATURE_WINDOWING 18
48#define GHOSTTY_DA_FEATURE_HORIZONTAL_SCROLLING 21
49#define GHOSTTY_DA_FEATURE_ANSI_COLOR 22
50#define GHOSTTY_DA_FEATURE_RECTANGULAR_EDITING 28
51#define GHOSTTY_DA_FEATURE_ANSI_TEXT_LOCATOR 29
52#define GHOSTTY_DA_FEATURE_CLIPBOARD 52
53
54/* DA2 device type identifiers (Pp parameter). */
55#define GHOSTTY_DA_DEVICE_TYPE_VT100 0
56#define GHOSTTY_DA_DEVICE_TYPE_VT220 1
57#define GHOSTTY_DA_DEVICE_TYPE_VT240 2
58#define GHOSTTY_DA_DEVICE_TYPE_VT330 18
59#define GHOSTTY_DA_DEVICE_TYPE_VT340 19
60#define GHOSTTY_DA_DEVICE_TYPE_VT320 24
61#define GHOSTTY_DA_DEVICE_TYPE_VT382 32
62#define GHOSTTY_DA_DEVICE_TYPE_VT420 41
63#define GHOSTTY_DA_DEVICE_TYPE_VT510 61
64#define GHOSTTY_DA_DEVICE_TYPE_VT520 64
65#define GHOSTTY_DA_DEVICE_TYPE_VT525 65
66
67#ifdef __cplusplus
68extern "C" {
69#endif
70
71/**
72 * Color scheme reported in response to a CSI ? 996 n query.
73 *
74 * @ingroup effects
75 */
76typedef enum GHOSTTY_ENUM_TYPED {
77 GHOSTTY_COLOR_SCHEME_LIGHT = 0,
78 GHOSTTY_COLOR_SCHEME_DARK = 1,
79 GHOSTTY_COLOR_SCHEME_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE,
80} GhosttyColorScheme;
81
82/**
83 * Primary device attributes (DA1) response data.
84 *
85 * Returned as part of GhosttyDeviceAttributes in response to a CSI c query.
86 * The conformance_level is the Pp parameter and features contains the Ps
87 * feature codes.
88 *
89 * @ingroup effects
90 */
91typedef struct {
92 /** Conformance level (Pp parameter). E.g. 62 for VT220. */
93 uint16_t conformance_level;
94
95 /** DA1 feature codes. Only the first num_features entries are valid. */
96 uint16_t features[64];
97
98 /** Number of valid entries in the features array. */
99 size_t num_features;
100} GhosttyDeviceAttributesPrimary;
101
102/**
103 * Secondary device attributes (DA2) response data.
104 *
105 * Returned as part of GhosttyDeviceAttributes in response to a CSI > c query.
106 * Response format: CSI > Pp ; Pv ; Pc c
107 *
108 * @ingroup effects
109 */
110typedef struct {
111 /** Terminal type identifier (Pp). E.g. 1 for VT220. */
112 uint16_t device_type;
113
114 /** Firmware/patch version number (Pv). */
115 uint16_t firmware_version;
116
117 /** ROM cartridge registration number (Pc). Always 0 for emulators. */
118 uint16_t rom_cartridge;
119} GhosttyDeviceAttributesSecondary;
120
121/**
122 * Tertiary device attributes (DA3) response data.
123 *
124 * Returned as part of GhosttyDeviceAttributes in response to a CSI = c query.
125 * Response format: DCS ! | D...D ST (DECRPTUI).
126 *
127 * @ingroup effects
128 */
129typedef struct {
130 /** Unit ID encoded as 8 uppercase hex digits in the response. */
131 uint32_t unit_id;
132} GhosttyDeviceAttributesTertiary;
133
134/**
135 * Device attributes response data for all three DA levels.
136 *
137 * Filled by the device_attributes callback in response to CSI c,
138 * CSI > c, or CSI = c queries. The terminal uses whichever sub-struct
139 * matches the request type.
140 *
141 * @ingroup effects
142 */
143typedef struct {
144 GhosttyDeviceAttributesPrimary primary;
145 GhosttyDeviceAttributesSecondary secondary;
146 GhosttyDeviceAttributesTertiary tertiary;
147} GhosttyDeviceAttributes;
148
149#ifdef __cplusplus
150}
151#endif
152
153#endif /* GHOSTTY_VT_DEVICE_H */