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