1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
|
/**
* @file terminal.h
*
* Complete terminal emulator state and rendering.
*/
#ifndef GHOSTTY_VT_TERMINAL_H
#define GHOSTTY_VT_TERMINAL_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <ghostty/vt/types.h>
#include <ghostty/vt/allocator.h>
#include <ghostty/vt/device.h>
#include <ghostty/vt/modes.h>
#include <ghostty/vt/size_report.h>
#include <ghostty/vt/grid_ref.h>
#include <ghostty/vt/io.h>
#include <ghostty/vt/kitty_graphics.h>
#include <ghostty/vt/screen.h>
#include <ghostty/vt/point.h>
#include <ghostty/vt/selection.h>
#include <ghostty/vt/style.h>
#ifdef __cplusplus
extern "C" {
#endif
/** Borrowed opened descriptor; size is sizeof this request. No path is supplied. */
typedef struct {
size_t size;
int64_t fd;
uint64_t expected_len;
} GhosttyKittyImageSnapshotFileRequest;
typedef bool (*GhosttyKittyImageFileReadFn)(void *context, uint8_t *dest, size_t len);
typedef void (*GhosttyKittyImageFileReleaseFn)(void *context);
typedef struct {
void *context;
uint64_t identity;
size_t len;
GhosttyKittyImageFileReadFn read;
GhosttyKittyImageFileReleaseFn release;
} GhosttyKittyImageFileBacking;
/** Optional synchronous callback, default NULL. Verify exact descriptor size
* and snapshot immutable bytes before returning true. True transfers one context
* reference; false transfers nothing. Do not close the borrowed descriptor or
* reenter the terminal. Both read and release MUST be non-NULL on success.
* Read must fill exactly len bytes; release is called once. An incomplete
* backing is rejected and ordinary file loading is used instead. If release
* is provided, rejection calls it once; without release, the host remains
* responsible for cleanup (the terminal cannot release that context).
* identity identifies the immutable revision, not a pathname or source inode.
*/
typedef bool (*GhosttyKittyImageSnapshotFileFn)(
GhosttyTerminal terminal, void *userdata,
const GhosttyKittyImageSnapshotFileRequest *request,
GhosttyKittyImageFileBacking *out_backing);
/** @defgroup terminal Terminal
*
* Complete terminal emulator state and rendering.
*
* A terminal instance manages the full emulator state including the screen,
* scrollback, cursor, styles, modes, and VT stream processing.
*
* Once a terminal session is up and running, you can configure a key encoder
* to write keyboard input via ghostty_key_encoder_setopt_from_terminal().
*
* ### Example: VT stream processing
* @snippet c-vt-stream/src/main.c vt-stream-init
* @snippet c-vt-stream/src/main.c vt-stream-write
*
* ## Scrollback Compression
*
* Scrollback compression is caller-driven. The terminal exposes an opaque
* activity token so an embedding application can restart an idle timer only
* when compression-relevant state changes. Once idle, call incremental
* compression until it no longer reports pending work. libghostty-vt does not
* create a timer or background thread.
*
* @snippet c-vt-compression/src/main.c compression-activity
* @snippet c-vt-compression/src/main.c compression-idle-step
*
* ## Effects
*
* By default, terminal sequence processing with the VT write functions only
* processes sequences that directly affect terminal state and
* ignores sequences that have side effect behavior or require responses.
* These sequences include things like bell characters, title changes, device
* attributes queries, and more. To handle these sequences, the embedder
* must configure "effects."
*
* Effects are callbacks that the terminal invokes in response to VT
* sequences processed during VT writes. They let the embedding application
* react to terminal-initiated events such as bell characters, title changes,
* device status report responses, and more.
*
* Each effect is registered with ghostty_terminal_set() using the
* corresponding `GhosttyTerminalOption` identifier. A `NULL` value
* pointer clears the callback and disables the effect.
*
* A userdata pointer can be attached via `GHOSTTY_TERMINAL_OPT_USERDATA`
* and is passed to every callback, allowing callers to route events
* back to their own application state without global variables.
* You cannot specify different userdata for different callbacks.
*
* All callbacks are invoked synchronously during VT writes. Callbacks
* **must not** call ghostty_terminal_vt_write() or
* ghostty_terminal_vt_write_until_ground() on the same terminal
* (no reentrancy).
* And callbacks must be very careful to not block for too long or perform
* expensive operations, since they are blocking further IO processing.
*
* The available effects are:
*
* | Option | Callback Type | Trigger |
* |-----------------------------------------|-----------------------------------|-------------------------------------------|
* | `GHOSTTY_TERMINAL_OPT_WRITE_PTY` | `GhosttyTerminalWritePtyFn` | VT query and mode reports written back to the PTY |
* | `GHOSTTY_TERMINAL_OPT_BELL` | `GhosttyTerminalBellFn` | BEL character (0x07) |
* | `GHOSTTY_TERMINAL_OPT_TITLE_CHANGED` | `GhosttyTerminalTitleChangedFn` | Title change via OSC 0 / OSC 2 |
* | `GHOSTTY_TERMINAL_OPT_PWD_CHANGED` | `GhosttyTerminalPwdChangedFn` | Pwd change via OSC 7 / OSC 9 / OSC 1337 |
* | `GHOSTTY_TERMINAL_OPT_ENQUIRY` | `GhosttyTerminalEnquiryFn` | ENQ character (0x05) |
* | `GHOSTTY_TERMINAL_OPT_XTVERSION` | `GhosttyTerminalXtversionFn` | XTVERSION query (CSI > q) |
* | `GHOSTTY_TERMINAL_OPT_SIZE` | `GhosttyTerminalSizeFn` | XTWINOPS query (CSI 14/16/18 t) or mode 2048 enable |
* | `GHOSTTY_TERMINAL_OPT_COLOR_SCHEME` | `GhosttyTerminalColorSchemeFn` | Color scheme query (CSI ? 996 n) |
* | `GHOSTTY_TERMINAL_OPT_DEVICE_ATTRIBUTES`| `GhosttyTerminalDeviceAttributesFn`| Device attributes query (CSI c / > c / = c)|
* | `GHOSTTY_TERMINAL_OPT_CLIPBOARD_WRITE` | `GhosttyTerminalClipboardWriteFn` | Clipboard write via OSC 52 / OSC 1337 / OSC 5522 |
* | `GHOSTTY_TERMINAL_OPT_CLIPBOARD_READ` | `GhosttyTerminalClipboardReadFn` | Clipboard read via OSC 52 "?" / OSC 5522 |
* | `GHOSTTY_TERMINAL_OPT_DESKTOP_NOTIFICATION`| `GhosttyTerminalDesktopNotificationFn` | Desktop notification via OSC 9 / OSC 777 |
* | `GHOSTTY_TERMINAL_OPT_PROGRESS_REPORT` | `GhosttyTerminalProgressReportFn` | Progress report via OSC 9;4 |
* | `GHOSTTY_TERMINAL_OPT_UNKNOWN_SEQUENCE` | `GhosttyTerminalUnknownSequenceFn` | Unsupported sequence identifier |
*
* ### Defining a write_pty callback
* @snippet c-vt-effects/src/main.c effects-write-pty
*
* ### Defining a bell callback
* @snippet c-vt-effects/src/main.c effects-bell
*
* ### Defining a title_changed callback
* @snippet c-vt-effects/src/main.c effects-title-changed
*
* ### Defining a clipboard_write callback
* @snippet c-vt-effects/src/main.c effects-clipboard-write
*
* ### Defining a clipboard_read callback
* @snippet c-vt-effects/src/main.c effects-clipboard-read
*
* ### Defining an unknown_sequence callback
* @snippet c-vt-effects/src/main.c effects-unknown-sequence
*
* ### Registering effects and processing VT data
* @snippet c-vt-effects/src/main.c effects-register
*
* ## Color Theme
*
* The terminal maintains a set of colors used for rendering: a foreground
* color, a background color, a cursor color, and a 256-color palette. Each
* of these has two layers: a **default** value set by the embedder, and an
* **override** value that programs running in the terminal can set via OSC
* escape sequences (e.g. OSC 10/11/12 for foreground/background/cursor,
* OSC 4 for individual palette entries).
*
* ### Default Colors
*
* Use ghostty_terminal_set() with the color options to configure the
* default colors. These represent the theme or configuration chosen by
* the embedder. Passing `NULL` clears the default, leaving the color
* unset.
*
* | Option | Input Type | Description |
* |-----------------------------------------|-------------------------|--------------------------------------|
* | `GHOSTTY_TERMINAL_OPT_COLOR_FOREGROUND` | `GhosttyColorRgb*` | Default foreground color |
* | `GHOSTTY_TERMINAL_OPT_COLOR_BACKGROUND` | `GhosttyColorRgb*` | Default background color |
* | `GHOSTTY_TERMINAL_OPT_COLOR_CURSOR` | `GhosttyColorRgb*` | Default cursor color |
* | `GHOSTTY_TERMINAL_OPT_COLOR_PALETTE` | `GhosttyColorRgb[256]*` | Default 256-color palette |
*
* For the palette, passing `NULL` resets to the built-in default palette.
* The palette set operation preserves any per-index OSC overrides that
* programs have applied; only unmodified indices are updated.
*
* ### Reading colors
*
* Use ghostty_terminal_get() to read colors. There are two variants for
* each color: the **effective** value (which returns the OSC override if
* one is active, otherwise the default) and the **default** value (which
* ignores any OSC overrides).
*
* | Data | Output Type | Description |
* |---------------------------------------------------|-------------------------|------------------------------------------------|
* | `GHOSTTY_TERMINAL_DATA_COLOR_FOREGROUND` | `GhosttyColorRgb*` | Effective foreground (override or default) |
* | `GHOSTTY_TERMINAL_DATA_COLOR_BACKGROUND` | `GhosttyColorRgb*` | Effective background (override or default) |
* | `GHOSTTY_TERMINAL_DATA_COLOR_CURSOR` | `GhosttyColorRgb*` | Effective cursor (override or default) |
* | `GHOSTTY_TERMINAL_DATA_COLOR_PALETTE` | `GhosttyColorRgb[256]*` | Current palette (with any OSC overrides) |
* | `GHOSTTY_TERMINAL_DATA_COLOR_FOREGROUND_DEFAULT` | `GhosttyColorRgb*` | Default foreground only (ignores OSC override) |
* | `GHOSTTY_TERMINAL_DATA_COLOR_BACKGROUND_DEFAULT` | `GhosttyColorRgb*` | Default background only (ignores OSC override) |
* | `GHOSTTY_TERMINAL_DATA_COLOR_CURSOR_DEFAULT` | `GhosttyColorRgb*` | Default cursor only (ignores OSC override) |
* | `GHOSTTY_TERMINAL_DATA_COLOR_PALETTE_DEFAULT` | `GhosttyColorRgb[256]*` | Default palette only (ignores OSC overrides) |
*
* For foreground, background, and cursor colors, the getters return
* `GHOSTTY_NO_VALUE` if no color is configured (neither a default nor an
* OSC override). The palette getters always succeed since the palette
* always has a value (the built-in default if nothing else is set).
*
* ### Setting a color theme
* @snippet c-vt-colors/src/main.c colors-set-defaults
*
* ### Reading effective and default colors
* @snippet c-vt-colors/src/main.c colors-read
*
* ### Full example with OSC overrides
* @snippet c-vt-colors/src/main.c colors-main
*
* @{
*/
/**
* Amount of compression work to perform before returning.
*
* @ingroup terminal
*/
typedef enum GHOSTTY_ENUM_TYPED {
/** Perform one bounded compression step suitable for idle scheduling. */
GHOSTTY_TERMINAL_COMPRESSION_MODE_INCREMENTAL = 0,
/** Synchronously inspect every currently eligible page. */
GHOSTTY_TERMINAL_COMPRESSION_MODE_FULL = 1,
GHOSTTY_TERMINAL_COMPRESSION_MODE_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE,
} GhosttyTerminalCompressionMode;
/**
* Scheduling result from terminal compression.
*
* @ingroup terminal
*/
typedef enum GHOSTTY_ENUM_TYPED {
/** Retained-mapping reclamation is unavailable on this target. */
GHOSTTY_TERMINAL_COMPRESSION_RESULT_UNSUPPORTED = 0,
/** More incremental compression work remains. */
GHOSTTY_TERMINAL_COMPRESSION_RESULT_PENDING = 1,
/** The pass has no continuation to schedule. */
GHOSTTY_TERMINAL_COMPRESSION_RESULT_COMPLETE = 2,
GHOSTTY_TERMINAL_COMPRESSION_RESULT_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE,
} GhosttyTerminalCompressionResult;
/**
* Scroll viewport behavior tag.
*
* @ingroup terminal
*/
typedef enum GHOSTTY_ENUM_TYPED {
/** Scroll to the top of the scrollback. */
GHOSTTY_SCROLL_VIEWPORT_TOP,
/** Scroll to the bottom (active area). */
GHOSTTY_SCROLL_VIEWPORT_BOTTOM,
/** Scroll by a delta amount (up is negative). */
GHOSTTY_SCROLL_VIEWPORT_DELTA,
/**
* Scroll to an absolute row offset from the top of the scrollable
* area. Row 0 is the top of the scrollback and the requested row
* becomes the first visible row of the viewport. The value is
* clamped so the viewport never scrolls beyond the top of the
* active area. If the terminal has no scrollback (e.g. the
* alternate screen is active), the viewport always remains on the
* active area.
*
* This is the same row space as the offset field of
* GhosttyTerminalScrollbar, so a scrollbar position obtained from
* GHOSTTY_TERMINAL_DATA_SCROLLBAR round-trips cleanly.
*/
GHOSTTY_SCROLL_VIEWPORT_ROW,
GHOSTTY_SCROLL_VIEWPORT_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE,
} GhosttyTerminalScrollViewportTag;
/**
* Scroll viewport value.
*
* @ingroup terminal
*/
typedef union {
/** Scroll delta (only used with GHOSTTY_SCROLL_VIEWPORT_DELTA). Up is negative. */
intptr_t delta;
/** Absolute row offset (only used with GHOSTTY_SCROLL_VIEWPORT_ROW). */
size_t row;
/** Padding for ABI compatibility. Do not use. */
uint64_t _padding[2];
} GhosttyTerminalScrollViewportValue;
/**
* Tagged union for scroll viewport behavior.
*
* @ingroup terminal
*/
typedef struct {
GhosttyTerminalScrollViewportTag tag;
GhosttyTerminalScrollViewportValue value;
} GhosttyTerminalScrollViewport;
/**
* Terminal screen identifier.
*
* Identifies which screen buffer is active in the terminal.
*
* @ingroup terminal
*/
typedef enum GHOSTTY_ENUM_TYPED {
/** The primary (normal) screen. */
GHOSTTY_TERMINAL_SCREEN_PRIMARY = 0,
/** The alternate screen. */
GHOSTTY_TERMINAL_SCREEN_ALTERNATE = 1,
GHOSTTY_TERMINAL_SCREEN_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE,
} GhosttyTerminalScreen;
/**
* Visual style of the terminal cursor.
*
* @ingroup terminal
*/
typedef enum GHOSTTY_ENUM_TYPED {
/** Bar cursor (DECSCUSR 5, 6). */
GHOSTTY_TERMINAL_CURSOR_STYLE_BAR = 0,
/** Block cursor (DECSCUSR 1, 2). */
GHOSTTY_TERMINAL_CURSOR_STYLE_BLOCK = 1,
/** Underline cursor (DECSCUSR 3, 4). */
GHOSTTY_TERMINAL_CURSOR_STYLE_UNDERLINE = 2,
/** Hollow block cursor. */
GHOSTTY_TERMINAL_CURSOR_STYLE_BLOCK_HOLLOW = 3,
GHOSTTY_TERMINAL_CURSOR_STYLE_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE,
} GhosttyTerminalCursorStyle;
/**
* Scrollbar state for the terminal viewport.
*
* Represents the scrollable area dimensions needed to render a scrollbar.
*
* @ingroup terminal
*/
typedef struct {
/** Total size of the scrollable area in rows. */
uint64_t total;
/** Offset into the total area that the viewport is at. */
uint64_t offset;
/** Length of the visible area in rows. */
uint64_t len;
} GhosttyTerminalScrollbar;
/**
* Callback function type for bell.
*
* Called when the terminal receives a BEL character (0x07).
*
* @param terminal The terminal handle
* @param userdata The userdata pointer set via GHOSTTY_TERMINAL_OPT_USERDATA
*
* @ingroup terminal
*/
typedef void (*GhosttyTerminalBellFn)(GhosttyTerminal terminal,
void* userdata);
/**
* Unsupported terminal sequence tags.
*
* Only APC sequences are currently reported. Additional sequence types may
* be added without changing the callback shape.
*
* @ingroup terminal
*/
typedef enum GHOSTTY_ENUM_TYPED {
/** Application Program Command (APC). */
GHOSTTY_TERMINAL_UNKNOWN_SEQUENCE_APC = 0,
GHOSTTY_TERMINAL_UNKNOWN_SEQUENCE_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE,
} GhosttyTerminalUnknownSequenceTag;
/**
* An unsupported string terminal sequence.
*
* The content is borrowed and valid only for the callback duration. It
* contains the bytes between the sequence introducer and terminator, may
* contain arbitrary binary data, and is not null-terminated.
*
* @ingroup terminal
*/
typedef struct {
/** Whether content was shortened by the byte limit or allocation failure. */
bool truncated;
/** Retained sequence content. */
GhosttyString content;
} GhosttyTerminalUnknownStringSequence;
/**
* Unsupported terminal sequence value.
*
* @ingroup terminal
*/
typedef union {
/** Application Program Command (APC). */
GhosttyTerminalUnknownStringSequence apc;
/**
* Padding for ABI compatibility. Do not use.
*
* 128 bytes leaves room for future structured sequence payloads, such as
* CSI with borrowed parameter, separator, and intermediate arrays, without
* changing the tagged union's ABI.
*/
uint64_t _padding[16];
} GhosttyTerminalUnknownSequenceValue;
/**
* An unsupported terminal sequence.
*
* @ingroup terminal
*/
typedef struct {
GhosttyTerminalUnknownSequenceTag tag;
GhosttyTerminalUnknownSequenceValue value;
} GhosttyTerminalUnknownSequence;
/**
* Callback function type for unsupported terminal sequences.
*
* Called synchronously for normally terminated sequences whose identifier is
* not supported by the active terminal handler. Aborted sequences, malformed
* recognized commands, and explicitly disabled known protocols are ignored.
*
* Capture must also be enabled with a nonzero
* GHOSTTY_TERMINAL_OPT_UNKNOWN_MAX_BYTES value. Installing this callback alone
* does not retain sequence content or allocate memory.
*
* @param terminal The terminal handle
* @param userdata The userdata pointer set via GHOSTTY_TERMINAL_OPT_USERDATA
* @param sequence Borrowed unsupported sequence
*
* @ingroup terminal
*/
typedef void (*GhosttyTerminalUnknownSequenceFn)(
GhosttyTerminal terminal,
void* userdata,
const GhosttyTerminalUnknownSequence* sequence);
/**
* Clipboard destination for a clipboard write.
*
* Protocol-specific destination identifiers are normalized to these values
* before the clipboard write callback is invoked.
*
* @ingroup terminal
*/
typedef enum GHOSTTY_ENUM_TYPED {
/** The standard system clipboard. */
GHOSTTY_CLIPBOARD_LOCATION_STANDARD = 0,
/** The selection clipboard. */
GHOSTTY_CLIPBOARD_LOCATION_SELECTION = 1,
/** The primary selection clipboard. */
GHOSTTY_CLIPBOARD_LOCATION_PRIMARY = 2,
GHOSTTY_CLIPBOARD_LOCATION_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE,
} GhosttyClipboardLocation;
/**
* One MIME representation in a clipboard write.
*
* Both strings are borrowed and valid only for the duration of the callback.
* The data is binary-safe and has already been decoded from any protocol-level
* encoding. A zero-length data string is an explicit empty representation; it
* does not clear the clipboard.
*
* This struct has a frozen layout and will not gain fields in future versions.
*
* @ingroup terminal
*/
typedef struct {
/** MIME type of the representation. */
GhosttyString mime;
/** Decoded, binary-safe representation data. */
GhosttyString data;
} GhosttyClipboardContent;
/**
* Result of a clipboard write reply.
*
* @ingroup terminal
*/
typedef enum GHOSTTY_ENUM_TYPED {
/** The clipboard write completed successfully. */
GHOSTTY_CLIPBOARD_WRITE_RESULT_SUCCESS = 0,
/** The clipboard write was denied by policy or the user. */
GHOSTTY_CLIPBOARD_WRITE_RESULT_DENIED = 1,
/** The destination or one or more representations are unsupported. */
GHOSTTY_CLIPBOARD_WRITE_RESULT_UNSUPPORTED = 2,
/** The clipboard is temporarily unavailable. */
GHOSTTY_CLIPBOARD_WRITE_RESULT_BUSY = 3,
/** One or more representations contain invalid data. */
GHOSTTY_CLIPBOARD_WRITE_RESULT_INVALID_DATA = 4,
/** The clipboard write failed due to an I/O error. */
GHOSTTY_CLIPBOARD_WRITE_RESULT_IO_ERROR = 5,
GHOSTTY_CLIPBOARD_WRITE_RESULT_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE,
} GhosttyClipboardWriteResult;
/**
* The reply to a clipboard write request.
*
* This is a sized struct; set `size` to `sizeof(GhosttyClipboardWriteReply)`.
* The reply is borrowed only for the duration of the reply call and may be
* freed as soon as it returns.
*
* The result answers the program with the matching protocol status for
* protocols with a write acknowledgement (OSC 5522: DONE, EPERM, ENOSYS,
* EBUSY, EINVAL, EIO); protocols without one (OSC 52, OSC 1337 Copy)
* discard the reply. `remember` is ignored on any result other than
* GHOSTTY_CLIPBOARD_WRITE_RESULT_SUCCESS.
*
* @ingroup terminal
*/
typedef struct {
/** Size of this struct in bytes. */
size_t size;
/** Outcome of the write. */
GhosttyClipboardWriteResult result;
/**
* Record a session grant so future requests from the same program skip
* the permission prompt. Only honored on success when
* GhosttyClipboardWrite::can_remember is set.
*/
bool remember;
} GhosttyClipboardWriteReply;
typedef struct GhosttyClipboardWrite GhosttyClipboardWrite;
/**
* Function type used to answer a clipboard write request. Obtained from
* GhosttyClipboardWrite::reply; see that struct for the contract.
*
* @param write The request being answered
* @param reply The reply, borrowed only for the duration of this call
*
* @ingroup terminal
*/
typedef void (*GhosttyClipboardWriteReplyFn)(
const GhosttyClipboardWrite* write,
const GhosttyClipboardWriteReply* reply);
/**
* A synchronous request to write clipboard contents.
*
* This is a sized struct. The callback must only access fields present in the
* size reported by `size`. The request, contents array, MIME strings, and
* data strings are all borrowed and valid only for the callback duration.
*
* All entries in `contents` are representations of the same logical value
* and must be committed atomically. A `contents_len` of zero requests that
* the destination be cleared. This is distinct from a content entry whose data
* has zero length.
*
* The write is answered by calling `reply` with this request and a
* GhosttyClipboardWriteReply. This must happen within the clipboard write
* request callback. This struct is only valid during that time. Calling
* `reply` more than once is safely ignored. Returning without replying
* denies the write.
*
* @ingroup terminal
*/
struct GhosttyClipboardWrite {
/** Size of this struct in bytes. */
size_t size;
/** Clipboard destination. */
GhosttyClipboardLocation location;
/** Borrowed array of MIME representations. */
const GhosttyClipboardContent* contents;
/** Number of entries in contents; zero means clear the destination. */
size_t contents_len;
/**
* Name of the writing program for permission prompts, if the protocol
* carries one. Empty otherwise.
*/
GhosttyString name;
/**
* True if the terminal already holds a session grant for this request
* The embedder should skip any permission prompt and perform the write.
*/
bool granted;
/**
* True if the program supplied a session password, so the embedder may
* offer to remember the user's decision through
* GhosttyClipboardWriteReply::remember. When false, remember is ignored.
*/
bool can_remember;
/** Terminal-owned reply state. Do not access. */
const void* ctx;
/** Answer the write; see the struct documentation. */
GhosttyClipboardWriteReplyFn reply;
};
/**
* Callback function type for clipboard_write.
*
* The embedder may ask for permission to write or perform the write
* async, but the callback itself is synchronous and the reply function
* must be called during the lifetime of this function. While this callback
* is active the VT stream is paused.
*
* Answer by calling `write->reply(write, &reply)` before returning. See
* GhosttyClipboardWrite for the full contract.
*
* The request may carry an optional program name requesting the write
* and the state of prior permission granted. If `can_remember` is set
* the response may set the `remember` flag and future requests from this
* same program will be "granted" and the embedder can skip permission
* requests.
*
* Clipboard read requests (OSC 52 "?" and OSC 5522 reads) are delivered
* to GhosttyTerminalClipboardReadFn instead.
*
* @param terminal The terminal handle
* @param userdata The userdata pointer set via GHOSTTY_TERMINAL_OPT_USERDATA
* @param write Borrowed atomic clipboard write request
*
* @ingroup terminal
*/
typedef void (*GhosttyTerminalClipboardWriteFn)(
GhosttyTerminal terminal,
void* userdata,
const GhosttyClipboardWrite* write);
/**
* Result of a clipboard read reply.
*
* @ingroup terminal
*/
typedef enum GHOSTTY_ENUM_TYPED {
/** The clipboard was read; the reply carries its contents. */
GHOSTTY_CLIPBOARD_READ_RESULT_SUCCESS = 0,
/** The clipboard read was denied by policy or the user. */
GHOSTTY_CLIPBOARD_READ_RESULT_DENIED = 1,
/** The embedder cannot read this clipboard. */
GHOSTTY_CLIPBOARD_READ_RESULT_UNSUPPORTED = 2,
/** The clipboard is temporarily unavailable. */
GHOSTTY_CLIPBOARD_READ_RESULT_BUSY = 3,
/** Reading the clipboard failed due to an I/O error. */
GHOSTTY_CLIPBOARD_READ_RESULT_IO_ERROR = 4,
GHOSTTY_CLIPBOARD_READ_RESULT_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE,
} GhosttyClipboardReadResult;
/**
* The reply to a clipboard read request.
*
* This is a sized struct; set `size` to `sizeof(GhosttyClipboardReadReply)`.
* All arrays and the strings they point to are borrowed only for the
* duration of the reply call and may be freed as soon as it returns.
*
* Any result other than GHOSTTY_CLIPBOARD_READ_RESULT_SUCCESS answers the
* program with an empty clipboard (OSC 52) or the matching protocol status
* (OSC 5522: EPERM, ENOSYS, EBUSY, EIO); the other fields are ignored in
* that case. On success, `contents` should carry one representation per
* requested MIME type (GhosttyClipboardRead::mimes) that the clipboard
* has; unrequested representations are ignored. Protocols that carry a
* single text value (OSC 52) use the first entry with a text MIME type
* such as "text/plain".
*
* @ingroup terminal
*/
typedef struct {
/** Size of this struct in bytes. */
size_t size;
/** Outcome of the read. */
GhosttyClipboardReadResult result;
/** Borrowed array of MIME representations of the clipboard contents. */
const GhosttyClipboardContent* contents;
/** Number of entries in contents. */
size_t contents_len;
/**
* Borrowed array of all MIME types available on the clipboard. Only
* used when GhosttyClipboardRead::list is set; may be NULL otherwise.
*/
const GhosttyString* available;
/** Number of entries in available. */
size_t available_len;
/**
* Record a session grant so future requests from the same program skip
* the permission prompt. Only honored on success when
* GhosttyClipboardRead::can_remember is set.
*/
bool remember;
} GhosttyClipboardReadReply;
typedef struct GhosttyClipboardRead GhosttyClipboardRead;
/**
* Function type used to answer a clipboard read request. Obtained from
* GhosttyClipboardRead::reply; see that struct for the contract.
*
* @param read The request being answered
* @param reply The reply, borrowed only for the duration of this call
*
* @ingroup terminal
*/
typedef void (*GhosttyClipboardReadReplyFn)(
const GhosttyClipboardRead* read,
const GhosttyClipboardReadReply* reply);
/**
* A synchronous request to read clipboard contents.
*
* This is a sized struct. The callback must only access fields present in the
* size reported by `size`. The request is borrowed and valid only for the
* callback duration.
*
* The read is answered by calling `reply` with this request and a
* GhosttyClipboardReadReply. This must happen before the callback returns;
* the request is invalid afterwards. Calling `reply` more than once is
* ignored. Returning without replying answers the program with an empty
* clipboard (OSC 52) or EPERM (OSC 5522).
*
* @ingroup terminal
*/
struct GhosttyClipboardRead {
/** Size of this struct in bytes. */
size_t size;
/** Clipboard to read. */
GhosttyClipboardLocation location;
/**
* Borrowed array of the MIME types the program wants, in order of
* preference. Protocols that only carry text (OSC 52) request
* "text/plain". NULL when mimes_len is zero.
*/
const GhosttyString* mimes;
/** Number of entries in mimes. */
size_t mimes_len;
/**
* True if the program also wants the list of MIME types available on the
* clipboard, delivered through GhosttyClipboardReadReply::available.
*/
bool list;
/**
* Name of the requesting program for permission prompts, if the protocol
* carries one. Empty otherwise.
*/
GhosttyString name;
/**
* True if the terminal already holds a session grant for this request
* (kitty clipboard protocol passwords). The embedder should skip any
* permission prompt and serve the read.
*
* Always false when mimes_len is zero: such a request is served
* without a prompt (see the callback docs), so the terminal never
* consults grants for it and a one-time password is preserved for
* the follow-up data read.
*/
bool granted;
/**
* True if the program supplied a session password, so the embedder may
* offer to remember the user's decision through
* GhosttyClipboardReadReply::remember. When false, remember is ignored.
*/
bool can_remember;
/** Terminal-owned reply state. Do not access. */
const void* ctx;
/** Answer the read; see the struct documentation. */
GhosttyClipboardReadReplyFn reply;
};
/**
* Callback function type for clipboard_read.
*
* Called synchronously when the running program requests clipboard contents
* via OSC 52 with a "?" payload or a Kitty clipboard (OSC 5522) read.
* Answering lets the program read the user's clipboard, so the embedder is
* expected to mediate consent. Because the read is synchronous, an embedder
* that needs to ask the user must block (for example by running a modal
* prompt) until it has an answer; the VT stream waits until the callback
* returns.
*
* Answer by calling `read->reply(read, &reply)` before returning. See
* GhosttyClipboardRead for the full contract.
*
* OSC 5522 requests carry the program's MIME list, name, and password grant
* state; a reply that sets `remember` records a session grant so later
* requests with the same password arrive with `granted` set. Kitty itself
* serves a request for only the targets listing (`list` with no `mimes`)
* without prompting, and embedders are expected to do the same; the
* terminal never consults grants for such requests (`granted` is false
* and one-time passwords are not consumed).
*
* Installing this callback also enables Kitty paste events (mode 5522):
* ghostty_terminal_paste() sends the program an event instead of the text,
* and the program's follow-up read arrives here with `granted` set since
* the user already pasted. See ghostty_terminal_paste().
*
* @param terminal The terminal handle
* @param userdata The userdata pointer set via GHOSTTY_TERMINAL_OPT_USERDATA
* @param read Borrowed clipboard read request
*
* @ingroup terminal
*/
typedef void (*GhosttyTerminalClipboardReadFn)(
GhosttyTerminal terminal,
void* userdata,
const GhosttyClipboardRead* read);
/**
* A request to show a desktop notification.
*
* This is a sized struct. The callback must only access fields present in the
* size reported by `size`. Both strings are borrowed and valid only for the
* duration of the callback.
*
* @ingroup terminal
*/
typedef struct {
/** Size of this struct in bytes. */
size_t size;
/** Notification title, or an empty string when the protocol omits it. */
GhosttyString title;
/** Notification body. */
GhosttyString body;
} GhosttyTerminalDesktopNotification;
/**
* Callback function type for desktop notifications.
*
* Called synchronously when the terminal receives OSC 9 or OSC 777.
*
* @param terminal The terminal handle
* @param userdata The userdata pointer set via GHOSTTY_TERMINAL_OPT_USERDATA
* @param notification Borrowed desktop notification request
*
* @ingroup terminal
*/
typedef void (*GhosttyTerminalDesktopNotificationFn)(
GhosttyTerminal terminal,
void* userdata,
const GhosttyTerminalDesktopNotification* notification);
/**
* State of a terminal progress report.
*
* @ingroup terminal
*/
typedef enum GHOSTTY_ENUM_TYPED {
/** Remove any visible progress indication. */
GHOSTTY_TERMINAL_PROGRESS_STATE_REMOVE = 0,
/** Show determinate progress. */
GHOSTTY_TERMINAL_PROGRESS_STATE_SET = 1,
/** Show a failed progress state. */
GHOSTTY_TERMINAL_PROGRESS_STATE_ERROR = 2,
/** Show indeterminate progress. */
GHOSTTY_TERMINAL_PROGRESS_STATE_INDETERMINATE = 3,
/** Show paused progress. */
GHOSTTY_TERMINAL_PROGRESS_STATE_PAUSE = 4,
GHOSTTY_TERMINAL_PROGRESS_STATE_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE,
} GhosttyTerminalProgressState;
/**
* A progress report emitted by the running program.
*
* This is a sized struct. The callback must only access fields present in the
* size reported by `size`.
*
* @ingroup terminal
*/
typedef struct {
/** Size of this struct in bytes. */
size_t size;
/** Literal progress state reported by the running program. */
GhosttyTerminalProgressState state;
/** Progress percentage from 0 through 100, or -1 when omitted. */
int8_t progress;
} GhosttyTerminalProgressReport;
/**
* Callback function type for progress reports.
*
* Called synchronously when the terminal receives OSC 9;4.
*
* @param terminal The terminal handle
* @param userdata The userdata pointer set via GHOSTTY_TERMINAL_OPT_USERDATA
* @param report Borrowed progress report
*
* @ingroup terminal
*/
typedef void (*GhosttyTerminalProgressReportFn)(
GhosttyTerminal terminal,
void* userdata,
const GhosttyTerminalProgressReport* report);
/**
* Callback function type for color scheme queries (CSI ? 996 n).
*
* Called when the terminal receives a color scheme device status report
* query. Return true and fill *out_scheme with the current color scheme,
* or return false to silently ignore the query.
*
* @param terminal The terminal handle
* @param userdata The userdata pointer set via GHOSTTY_TERMINAL_OPT_USERDATA
* @param[out] out_scheme Pointer to store the current color scheme
* @return true if the color scheme was filled, false to ignore the query
*
* @ingroup terminal
*/
typedef bool (*GhosttyTerminalColorSchemeFn)(GhosttyTerminal terminal,
void* userdata,
GhosttyColorScheme* out_scheme);
/**
* Callback function type for device attributes queries (DA1/DA2/DA3).
*
* Called when the terminal receives a device attributes query (CSI c,
* CSI > c, or CSI = c). Return true and fill *out_attrs with the
* response data, or return false to silently ignore the query.
*
* The terminal uses whichever sub-struct (primary, secondary, tertiary)
* matches the request type, but all three should be filled for simplicity.
*
* @param terminal The terminal handle
* @param userdata The userdata pointer set via GHOSTTY_TERMINAL_OPT_USERDATA
* @param[out] out_attrs Pointer to store the device attributes response
* @return true if attributes were filled, false to ignore the query
*
* @ingroup terminal
*/
typedef bool (*GhosttyTerminalDeviceAttributesFn)(GhosttyTerminal terminal,
void* userdata,
GhosttyDeviceAttributes* out_attrs);
/**
* Callback function type for enquiry (ENQ, 0x05).
*
* Called when the terminal receives an ENQ character. Return the
* response bytes as a GhosttyString. The memory must remain valid
* until the callback returns. Return a zero-length string to send
* no response.
*
* @param terminal The terminal handle
* @param userdata The userdata pointer set via GHOSTTY_TERMINAL_OPT_USERDATA
* @return The response bytes to write back to the pty
*
* @ingroup terminal
*/
typedef GhosttyString (*GhosttyTerminalEnquiryFn)(GhosttyTerminal terminal,
void* userdata);
/**
* Callback function type for terminal size reports.
*
* Called in response to XTWINOPS size queries (CSI 14/16/18 t) and when VT
* input enables in-band size reports (mode 2048).
* Return true and fill *out_size with the current terminal geometry,
* or return false to suppress the report.
*
* @param terminal The terminal handle
* @param userdata The userdata pointer set via GHOSTTY_TERMINAL_OPT_USERDATA
* @param[out] out_size Pointer to store the terminal size information
* @return true if size was filled, false to suppress the XTWINOPS response or
* mode 2048 report
*
* @ingroup terminal
*/
typedef bool (*GhosttyTerminalSizeFn)(GhosttyTerminal terminal,
void* userdata,
GhosttySizeReportSize* out_size);
/**
* Callback function type for title_changed.
*
* Called when the terminal title changes via escape sequences
* (e.g. OSC 0 or OSC 2). The new title can be queried from the
* terminal after the callback returns.
*
* @param terminal The terminal handle
* @param userdata The userdata pointer set via GHOSTTY_TERMINAL_OPT_USERDATA
*
* @ingroup terminal
*/
typedef void (*GhosttyTerminalTitleChangedFn)(GhosttyTerminal terminal,
void* userdata);
/**
* Callback function type for pwd_changed.
*
* Called when the terminal pwd (current working directory) changes via
* escape sequences: OSC 7 (file:// URI), OSC 9 (ConEmu CurrentDir), or
* OSC 1337 CurrentDir (iTerm2). Use ghostty_terminal_get() with
* GHOSTTY_TERMINAL_DATA_PWD inside the callback to read the new value.
*
* The terminal stores whatever bytes the shell emitted, without parsing.
* That means for OSC 7 the value is the raw URI (typically file://...);
* for OSC 9/OSC 1337 it is typically a bare path. The embedder is
* responsible for decoding any URI scheme or host if it cares about them.
*
* The callback also fires when the shell clears the pwd (e.g. an empty
* OSC 7). In that case GHOSTTY_TERMINAL_DATA_PWD returns a zero-length
* string.
*
* @param terminal The terminal handle
* @param userdata The userdata pointer set via GHOSTTY_TERMINAL_OPT_USERDATA
*
* @ingroup terminal
*/
typedef void (*GhosttyTerminalPwdChangedFn)(GhosttyTerminal terminal,
void* userdata);
/**
* Callback function type for write_pty.
*
* Called when the terminal needs to write data back to the pty, for
* example in response to a device status report, mode query, or VT-driven
* mode 2048 enable. The data is only valid for the duration of the call;
* callers must copy it if it needs to persist.
*
* @param terminal The terminal handle
* @param userdata The userdata pointer set via GHOSTTY_TERMINAL_OPT_USERDATA
* @param data Pointer to the response bytes
* @param len Length of the response in bytes
*
* @ingroup terminal
*/
typedef void (*GhosttyTerminalWritePtyFn)(GhosttyTerminal terminal,
void* userdata,
const uint8_t* data,
size_t len);
/**
* Callback function type for XTVERSION.
*
* Called when the terminal receives an XTVERSION query (CSI > q).
* Return the version string (e.g. "myterm 1.0") as a GhosttyString.
* The memory must remain valid until the callback returns. Return a
* zero-length string to report the default "libghostty" version.
*
* @param terminal The terminal handle
* @param userdata The userdata pointer set via GHOSTTY_TERMINAL_OPT_USERDATA
* @return The version string to report
*
* @ingroup terminal
*/
typedef GhosttyString (*GhosttyTerminalXtversionFn)(GhosttyTerminal terminal,
void* userdata);
/**
* A terminal mode and boolean value used for mode configuration and queries.
*
* For GHOSTTY_TERMINAL_DATA_MODE, initialize `mode` before calling
* ghostty_terminal_get(). On success, `value` contains the current mode value.
*
* This struct has a frozen layout and will not gain fields in future versions.
*
* @ingroup terminal
*/
typedef struct {
/** Mode to configure or query. */
GhosttyMode mode;
/** Value to set, or the current value returned by a query. */
bool value;
} GhosttyTerminalModeConfig;
/**
* Terminal option identifiers.
*
* These values are used with ghostty_terminal_set() to configure
* terminal callbacks and associated state.
*
* @ingroup terminal
*/
typedef enum GHOSTTY_ENUM_TYPED {
/**
* Opaque userdata pointer passed to all callbacks.
*
* Input type: void*
*/
GHOSTTY_TERMINAL_OPT_USERDATA = 0,
/**
* Callback invoked when the terminal needs to write data back
* to the pty (e.g. in response to a DECRQM query, device status
* report, or VT-driven mode 2048 enable). Set to NULL to ignore such
* sequences.
*
* Input type: GhosttyTerminalWritePtyFn
*/
GHOSTTY_TERMINAL_OPT_WRITE_PTY = 1,
/**
* Callback invoked when the terminal receives a BEL character
* (0x07). Set to NULL to ignore bell events.
*
* Input type: GhosttyTerminalBellFn
*/
GHOSTTY_TERMINAL_OPT_BELL = 2,
/**
* Callback invoked when the terminal receives an ENQ character
* (0x05). Set to NULL to send no response.
*
* Input type: GhosttyTerminalEnquiryFn
*/
GHOSTTY_TERMINAL_OPT_ENQUIRY = 3,
/**
* Callback invoked when the terminal receives an XTVERSION query
* (CSI > q). Set to NULL to report the default "libghostty" string.
*
* Input type: GhosttyTerminalXtversionFn
*/
GHOSTTY_TERMINAL_OPT_XTVERSION = 4,
/**
* Callback invoked when the terminal title changes via escape
* sequences (e.g. OSC 0 or OSC 2). Set to NULL to ignore title
* change events.
*
* Input type: GhosttyTerminalTitleChangedFn
*/
GHOSTTY_TERMINAL_OPT_TITLE_CHANGED = 5,
/**
* Callback invoked in response to XTWINOPS size queries
* (CSI 14/16/18 t). Set to NULL to silently ignore size queries.
*
* Input type: GhosttyTerminalSizeFn
*/
GHOSTTY_TERMINAL_OPT_SIZE = 6,
/**
* Callback invoked in response to a color scheme device status
* report query (CSI ? 996 n). Return true and fill the out pointer
* to report the current scheme, or return false to silently ignore.
* Set to NULL to ignore color scheme queries.
*
* Input type: GhosttyTerminalColorSchemeFn
*/
GHOSTTY_TERMINAL_OPT_COLOR_SCHEME = 7,
/**
* Callback invoked in response to a device attributes query
* (CSI c, CSI > c, or CSI = c). Return true and fill the out
* pointer with response data, or return false to silently ignore.
* Set to NULL to ignore device attributes queries.
*
* Input type: GhosttyTerminalDeviceAttributesFn
*/
GHOSTTY_TERMINAL_OPT_DEVICE_ATTRIBUTES = 8,
/**
* Set the terminal title manually.
*
* The string data is copied into the terminal. A NULL value pointer
* clears the title (equivalent to setting an empty string).
*
* Input type: GhosttyString*
*/
GHOSTTY_TERMINAL_OPT_TITLE = 9,
/**
* Set the terminal working directory manually.
*
* The string data is copied into the terminal. A NULL value pointer
* clears the pwd (equivalent to setting an empty string).
*
* Input type: GhosttyString*
*/
GHOSTTY_TERMINAL_OPT_PWD = 10,
/**
* Set the default foreground color.
*
* A NULL value pointer clears the default (unset).
*
* Input type: GhosttyColorRgb*
*/
GHOSTTY_TERMINAL_OPT_COLOR_FOREGROUND = 11,
/**
* Set the default background color.
*
* A NULL value pointer clears the default (unset).
*
* Input type: GhosttyColorRgb*
*/
GHOSTTY_TERMINAL_OPT_COLOR_BACKGROUND = 12,
/**
* Set the default cursor color.
*
* A NULL value pointer clears the default (unset).
*
* Input type: GhosttyColorRgb*
*/
GHOSTTY_TERMINAL_OPT_COLOR_CURSOR = 13,
/**
* Set the default 256-color palette.
*
* The value must point to an array of exactly 256 GhosttyColorRgb values.
* A NULL value pointer resets to the built-in default palette.
*
* Input type: GhosttyColorRgb[256]*
*/
GHOSTTY_TERMINAL_OPT_COLOR_PALETTE = 14,
/**
* Set the Kitty image storage limit in bytes.
*
* Applied to all initialized screens (primary and alternate).
* A value of zero disables the Kitty graphics protocol entirely,
* deleting all stored images and placements. A NULL value pointer
* is equivalent to zero (disables). Has no effect when Kitty graphics
* are disabled at build time.
*
* Input type: uint64_t*
*/
GHOSTTY_TERMINAL_OPT_KITTY_IMAGE_STORAGE_LIMIT = 15,
/**
* Enable or disable Kitty image loading via the file medium.
*
* A NULL value pointer is a no-op. Has no effect when Kitty graphics
* are disabled at build time.
*
* Input type: bool*
*/
GHOSTTY_TERMINAL_OPT_KITTY_IMAGE_MEDIUM_FILE = 16,
/**
* Enable Kitty image loading via the temporary file medium, restricted to
* the provided directory. The string data is copied into the terminal.
*
* A NULL value pointer disables the temporary file medium. Has no effect
* when Kitty graphics are disabled at build time.
*
* Input type: GhosttyString*
*/
GHOSTTY_TERMINAL_OPT_KITTY_IMAGE_MEDIUM_TEMP_FILE = 17,
/**
* Enable or disable Kitty image loading via the shared memory medium.
*
* A NULL value pointer is a no-op. Has no effect when Kitty graphics
* are disabled at build time.
*
* Input type: bool*
*/
GHOSTTY_TERMINAL_OPT_KITTY_IMAGE_MEDIUM_SHARED_MEM = 18,
/**
* Set the maximum bytes the APC handler will buffer for all protocols.
* This prevents malicious input from causing unbounded memory allocation.
* A NULL value pointer removes all overrides, reverting to the built-in
* defaults.
*
* Input type: size_t*
*/
GHOSTTY_TERMINAL_OPT_APC_MAX_BYTES = 19,
/**
* Set the maximum bytes the APC handler will buffer for Kitty graphics
* protocol data. A NULL value pointer removes the override, reverting
* to the built-in default.
*
* Input type: size_t*
*/
GHOSTTY_TERMINAL_OPT_APC_MAX_BYTES_KITTY = 20,
/**
* Set the active screen selection.
*
* The value must point to a GhosttySelection whose grid references are
* valid for this terminal's active screen at the time of the call. The
* terminal copies the selection immediately and converts it to
* terminal-owned tracked state, so the GhosttySelection struct and its
* untracked grid references do not need to outlive this call.
*
* Passing NULL clears the active screen selection.
*
* Input type: GhosttySelection*
*/
GHOSTTY_TERMINAL_OPT_SELECTION = 21,
/**
* Set the default cursor style used by DECSCUSR reset (CSI 0 q).
*
* A NULL value pointer resets to the built-in default block cursor.
*
* Input type: GhosttyTerminalCursorStyle*
*/
GHOSTTY_TERMINAL_OPT_DEFAULT_CURSOR_STYLE = 22,
/**
* Set whether the default cursor should blink when reset by DECSCUSR
* (CSI 0 q).
*
* A NULL value pointer resets to the built-in default of not blinking.
*
* Input type: bool*
*/
GHOSTTY_TERMINAL_OPT_DEFAULT_CURSOR_BLINK = 23,
/**
* Enable or disable Glyph Protocol APC handling.
*
* When disabled, Glyph Protocol APC sequences are ignored and no
* support/query/register/clear responses are emitted. Disabling also clears
* the terminal session's glyph glossary. A NULL value pointer is a no-op.
*
* Input type: bool*
*/
GHOSTTY_TERMINAL_OPT_GLYPH_PROTOCOL = 24,
/**
* Callback invoked when the terminal pwd changes via escape
* sequences (OSC 7, OSC 9, or OSC 1337 CurrentDir). Set to NULL
* to ignore pwd change events.
*
* Input type: GhosttyTerminalPwdChangedFn
*/
GHOSTTY_TERMINAL_OPT_PWD_CHANGED = 25,
/**
* Callback invoked when the running program performs a clipboard write.
* OSC 52, iTerm2 OSC 1337 Copy, and Kitty clipboard (OSC 5522) writes
* are normalized to an atomic set of decoded MIME representations. Set
* to NULL to ignore clipboard writes (Kitty clipboard writes are then
* refused with ENOSYS). Clipboard read requests are delivered to
* GHOSTTY_TERMINAL_OPT_CLIPBOARD_READ instead.
*
* Input type: GhosttyTerminalClipboardWriteFn
*/
GHOSTTY_TERMINAL_OPT_CLIPBOARD_WRITE = 26,
/**
* Set the maximum scrollback allocation in bytes.
*
* This is an estimate. Internally, libghostty only prunes bytes up
* to a "page"-granularity. A page is the minimum allocated unit of
* grid space within Ghostty. A page at the time of writing these docs
* is about 400KB, so the byte limit will be within this delta.
*
* This works alongside the line limit configuration. If both are set,
* the first-reached limit is used first. Both limits are dependent
* on external state (byte limit can be reached with less lines if
* more styles are used for example, line limit can be reached with
* a narrower terminal viewport). So, they are useful together.
*
* Lowering the limit immediately removes eligible complete historical
* pages. A value of zero disables scrollback and erases retained history.
* A NULL value pointer removes the byte limit.
*
* Input type: size_t*
*/
GHOSTTY_TERMINAL_OPT_SCROLLBACK_MAX_BYTES = 27,
/**
* Set the maximum number of physical lines retained in scrollback.
*
* This is an estimate. Internally, libghostty only prunes lines up
* to a "page"-granularity. A page is the minimum allocated unit of
* grid space within Ghostty. As a result, the actual available scrollback
* lines will almost always be higher than configured. The magnitude
* of the difference depends on the number of used styles, graphemes, etc.
* since the row-count in a page is dynamic based on that. In general,
* it ranges from dozens to a hundred or so lines.
*
* This works alongside the line limit configuration. If both are set,
* the first-reached limit is used first. Both limits are dependent
* on external state (byte limit can be reached with less lines if
* more styles are used for example, line limit can be reached with
* a narrower terminal viewport). So, they are useful together.
*
* Lowering the limit immediately removes eligible complete historical
* pages. A NULL value pointer removes the line limit.
*
* Input type: size_t*
*/
GHOSTTY_TERMINAL_OPT_SCROLLBACK_MAX_LINES = 28,
/**
* Callback invoked when the running program requests a desktop
* notification via OSC 9 or OSC 777. Set to NULL to ignore desktop
* notification requests.
*
* Input type: GhosttyTerminalDesktopNotificationFn
*/
GHOSTTY_TERMINAL_OPT_DESKTOP_NOTIFICATION = 29,
/**
* Callback invoked when the running program reports progress via OSC 9;4.
* Set to NULL to ignore progress reports.
*
* Input type: GhosttyTerminalProgressReportFn
*/
GHOSTTY_TERMINAL_OPT_PROGRESS_REPORT = 30,
/**
* Set the maximum number of replay-safe VT continuation bytes retained.
*
* Continuation bytes reconstruct an escape sequence or UTF-8 codepoint
* which was unfinished at the end of the most recent
* VT write call. They are used automatically by terminal snapshots and may
* also be exported directly with the continuation APIs.
*
* Tracking is disabled by default. A nonzero value enables tracking and
* sets its byte limit. Passing NULL or a pointer to zero disables tracking.
* Lowering the limit below an already-retained
* continuation, or enabling tracking while the parser is already
* unfinished, makes the current continuation unavailable because earlier
* bytes cannot be reconstructed. Tracking recovers automatically after a
* later write reaches the ground state or contains a fresh replay start.
*
* Input type: size_t*
*/
GHOSTTY_TERMINAL_OPT_CONTINUATION_MAX_BYTES = 31,
/**
* Enable window title reports in response to CSI 21 t.
*
* This is disabled by default because a running program can set a title and
* query it back into the pty input stream, potentially injecting commands
* that execute after user interaction. Passing NULL or a pointer to false
* disables title reporting.
*
* Input type: bool*
*/
GHOSTTY_TERMINAL_OPT_TITLE_REPORT = 32,
/**
* Set the reset default for a terminal mode.
*
* This unconditionally updates both the current value and the value restored
* by a full terminal reset (RIS).
*
* Some recognized modes represent transitions or mirror additional terminal
* state and cannot safely be configured as reset defaults. Those modes return
* GHOSTTY_INVALID_VALUE. A NULL value pointer also returns
* GHOSTTY_INVALID_VALUE.
*
* Input type: GhosttyTerminalModeConfig*
*/
GHOSTTY_TERMINAL_OPT_MODE_DEFAULT = 33,
/**
* Set the current value of a terminal mode.
*
* This does not change the value restored by a full terminal reset (RIS).
* A NULL value pointer or unknown mode returns GHOSTTY_INVALID_VALUE.
*
* Input type: GhosttyTerminalModeConfig*
*/
GHOSTTY_TERMINAL_OPT_MODE = 34,
/**
* Callback invoked for unsupported terminal sequence identifiers. Set to
* NULL to ignore unsupported sequences. Capture must also be enabled with
* GHOSTTY_TERMINAL_OPT_UNKNOWN_MAX_BYTES.
*
* Input type: GhosttyTerminalUnknownSequenceFn
*/
GHOSTTY_TERMINAL_OPT_UNKNOWN_SEQUENCE = 35,
/**
* Set the maximum content bytes retained for each unsupported terminal
* sequence. A NULL value pointer or zero disables capture and prevents
* unknown-sequence callbacks.
*
* When this limit is hit, the unknown sequence callback will still
* be invoked but `truncated` will be set to true.
*
* Input type: size_t*
*/
GHOSTTY_TERMINAL_OPT_UNKNOWN_MAX_BYTES = 36,
/**
* Set the name of the terminfo entry this terminal runs as, reported
* in response to an XTGETTCAP query for "TN" (e.g. "xterm-256color").
*
* The string data is copied into the terminal. A NULL value pointer
* clears the name (equivalent to setting an empty string). A name
* longer than 128 bytes returns GHOSTTY_INVALID_VALUE.
*
* If this is unset then we don't report anything for an XTGETTCAP
* TN query, because we don't know what the embedding terminal around
* libghostty is advertising itself as.
*
* Input type: GhosttyString*
*/
GHOSTTY_TERMINAL_OPT_TERMINFO_NAME = 37,
/**
* Callback invoked when the running program requests clipboard contents
* via OSC 52 with a "?" payload or a Kitty clipboard (OSC 5522) read. The
* read is synchronous and must be answered before the callback returns.
* Set to NULL (the default) to ignore OSC 52 read requests and refuse
* OSC 5522 reads with EPERM.
*
* Input type: GhosttyTerminalClipboardReadFn
*/
GHOSTTY_TERMINAL_OPT_CLIPBOARD_READ = 38,
/**
* Set the maximum total decoded bytes a single Kitty clipboard protocol
* (OSC 5522) write transaction may accumulate. The limit is captured
* when a transaction begins; an in-flight transaction keeps the limit
* it started with.
*
* Data beyond the limit fails the whole transaction with EFBIG. The
* transaction is discarded, later write-related packets are ignored
* until a new write begins, and nothing reaches the clipboard write
* callback.
*
* Transactions are buffered in memory, so this limit bounds how much
* memory a single write can make the terminal allocate. Pass SIZE_MAX
* to remove the limit. A NULL value pointer reverts to the built-in
* default of 64MiB, the minimum required by the protocol.
*
* This limit doesn't apply to OSC 52 writes, which are bounded by the
* maximum length of an escape sequence instead.
*
* Input type: size_t*
*/
GHOSTTY_TERMINAL_OPT_CLIPBOARD_WRITE_MAX_BYTES = 39,
/** Experimental, default-off PNG retention for quiet base transmissions.
* Input type: bool*. NULL is a no-op. Corrupt compressed pixels may only
* be detected when an animation operation materializes the image.
*/
GHOSTTY_TERMINAL_OPT_KITTY_IMAGE_PRESERVE_PNG = 40,
/** Optional synchronous GhosttyKittyImageSnapshotFileFn; NULL disables. */
GHOSTTY_TERMINAL_OPT_KITTY_IMAGE_SNAPSHOT_FILE = 41,
GHOSTTY_TERMINAL_OPT_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE,
} GhosttyTerminalOption;
/**
* Terminal data types.
*
* These values specify what type of data to extract from a terminal
* using `ghostty_terminal_get`.
*
* @ingroup terminal
*/
typedef enum GHOSTTY_ENUM_TYPED {
/** Invalid data type. Never results in any data extraction. */
GHOSTTY_TERMINAL_DATA_INVALID = 0,
/**
* Terminal width in cells.
*
* Output type: uint16_t *
*/
GHOSTTY_TERMINAL_DATA_COLS = 1,
/**
* Terminal height in cells.
*
* Output type: uint16_t *
*/
GHOSTTY_TERMINAL_DATA_ROWS = 2,
/**
* Cursor column position (0-indexed).
*
* Output type: uint16_t *
*/
GHOSTTY_TERMINAL_DATA_CURSOR_X = 3,
/**
* Cursor row position within the active area (0-indexed).
*
* Output type: uint16_t *
*/
GHOSTTY_TERMINAL_DATA_CURSOR_Y = 4,
/**
* Whether the cursor has a pending wrap (next print will soft-wrap).
*
* Output type: bool *
*/
GHOSTTY_TERMINAL_DATA_CURSOR_PENDING_WRAP = 5,
/**
* The currently active screen.
*
* Output type: GhosttyTerminalScreen *
*/
GHOSTTY_TERMINAL_DATA_ACTIVE_SCREEN = 6,
/**
* Whether the cursor is visible (DEC mode 25).
*
* Output type: bool *
*/
GHOSTTY_TERMINAL_DATA_CURSOR_VISIBLE = 7,
/**
* Current Kitty keyboard protocol flags.
*
* Output type: GhosttyKittyKeyFlags * (uint8_t *)
*/
GHOSTTY_TERMINAL_DATA_KITTY_KEYBOARD_FLAGS = 8,
/**
* Scrollbar state for the terminal viewport.
*
* This is amortized O(1): the total is maintained incrementally as
* the terminal is modified and the viewport offset is cached. The
* first read after the viewport moves to an arbitrary position that
* isn't an absolute row (e.g. scrolling to a selection) may cost
* O(pages) to compute the offset, after which it is cached again.
*
* There is intentionally no change notification for scroll state.
* Callers building scrollbars should poll this once per frame or
* per write batch and diff the result to detect changes; this is
* what Ghostty's own renderer does.
*
* Output type: GhosttyTerminalScrollbar *
*/
GHOSTTY_TERMINAL_DATA_SCROLLBAR = 9,
/**
* The current SGR style of the cursor.
*
* This is the style that will be applied to newly printed characters.
*
* Output type: GhosttyStyle *
*/
GHOSTTY_TERMINAL_DATA_CURSOR_STYLE = 10,
/**
* Whether any mouse tracking mode is active.
*
* Returns true if any of the mouse tracking modes (X10, normal, button,
* or any-event) are enabled.
*
* Output type: bool *
*/
GHOSTTY_TERMINAL_DATA_MOUSE_TRACKING = 11,
/**
* The terminal title as set by escape sequences (e.g. OSC 0/2).
*
* Returns a borrowed string. The pointer is valid until the next mutating
* terminal call. An empty string (len=0) is returned when no title has been
* set.
*
* Output type: GhosttyString *
*/
GHOSTTY_TERMINAL_DATA_TITLE = 12,
/**
* The terminal's current working directory as set by escape sequences
* (e.g. OSC 7).
*
* Returns a borrowed string. The pointer is valid until the next mutating
* terminal call. An empty string (len=0) is returned when no pwd has been
* set.
*
* Output type: GhosttyString *
*/
GHOSTTY_TERMINAL_DATA_PWD = 13,
/**
* The total number of rows in the active screen including scrollback.
*
* Output type: size_t *
*/
GHOSTTY_TERMINAL_DATA_TOTAL_ROWS = 14,
/**
* The number of scrollback rows (total rows minus viewport rows).
*
* Output type: size_t *
*/
GHOSTTY_TERMINAL_DATA_SCROLLBACK_ROWS = 15,
/**
* The total width of the terminal in pixels.
*
* This is cols * cell_width_px as set by ghostty_terminal_resize().
*
* Output type: uint32_t *
*/
GHOSTTY_TERMINAL_DATA_WIDTH_PX = 16,
/**
* The total height of the terminal in pixels.
*
* This is rows * cell_height_px as set by ghostty_terminal_resize().
*
* Output type: uint32_t *
*/
GHOSTTY_TERMINAL_DATA_HEIGHT_PX = 17,
/**
* The effective foreground color (override or default).
*
* Returns GHOSTTY_NO_VALUE if no foreground color is set.
*
* Output type: GhosttyColorRgb *
*/
GHOSTTY_TERMINAL_DATA_COLOR_FOREGROUND = 18,
/**
* The effective background color (override or default).
*
* Returns GHOSTTY_NO_VALUE if no background color is set.
*
* Output type: GhosttyColorRgb *
*/
GHOSTTY_TERMINAL_DATA_COLOR_BACKGROUND = 19,
/**
* The effective cursor color (override or default).
*
* Returns GHOSTTY_NO_VALUE if no cursor color is set.
*
* Output type: GhosttyColorRgb *
*/
GHOSTTY_TERMINAL_DATA_COLOR_CURSOR = 20,
/**
* The current 256-color palette.
*
* Output type: GhosttyColorRgb[256] *
*/
GHOSTTY_TERMINAL_DATA_COLOR_PALETTE = 21,
/**
* The default foreground color (ignoring any OSC override).
*
* Returns GHOSTTY_NO_VALUE if no default foreground color is set.
*
* Output type: GhosttyColorRgb *
*/
GHOSTTY_TERMINAL_DATA_COLOR_FOREGROUND_DEFAULT = 22,
/**
* The default background color (ignoring any OSC override).
*
* Returns GHOSTTY_NO_VALUE if no default background color is set.
*
* Output type: GhosttyColorRgb *
*/
GHOSTTY_TERMINAL_DATA_COLOR_BACKGROUND_DEFAULT = 23,
/**
* The default cursor color (ignoring any OSC override).
*
* Returns GHOSTTY_NO_VALUE if no default cursor color is set.
*
* Output type: GhosttyColorRgb *
*/
GHOSTTY_TERMINAL_DATA_COLOR_CURSOR_DEFAULT = 24,
/**
* The default 256-color palette (ignoring any OSC overrides).
*
* Output type: GhosttyColorRgb[256] *
*/
GHOSTTY_TERMINAL_DATA_COLOR_PALETTE_DEFAULT = 25,
/**
* The Kitty image storage limit in bytes for the active screen.
*
* A value of zero means the Kitty graphics protocol is disabled.
* Returns GHOSTTY_NO_VALUE when Kitty graphics are disabled at build time.
*
* Output type: uint64_t *
*/
GHOSTTY_TERMINAL_DATA_KITTY_IMAGE_STORAGE_LIMIT = 26,
/**
* Whether the file medium is enabled for Kitty image loading on the
* active screen.
*
* Returns GHOSTTY_NO_VALUE when Kitty graphics are disabled at build time.
*
* Output type: bool *
*/
GHOSTTY_TERMINAL_DATA_KITTY_IMAGE_MEDIUM_FILE = 27,
/**
* The directory allowed for Kitty image loading via the temporary file
* medium on the active screen. The string is empty when the medium is
* disabled.
*
* Returns GHOSTTY_NO_VALUE when Kitty graphics are disabled at build time.
*
* Output type: GhosttyString *
*/
GHOSTTY_TERMINAL_DATA_KITTY_IMAGE_MEDIUM_TEMP_FILE = 28,
/**
* Whether the shared memory medium is enabled for Kitty image loading
* on the active screen.
*
* Returns GHOSTTY_NO_VALUE when Kitty graphics are disabled at build time.
*
* Output type: bool *
*/
GHOSTTY_TERMINAL_DATA_KITTY_IMAGE_MEDIUM_SHARED_MEM = 29,
/**
* The Kitty graphics image storage for the active screen.
*
* Returns a borrowed pointer to the image storage. The pointer is valid
* until the next mutating terminal call (e.g. ghostty_terminal_vt_write()
* or ghostty_terminal_reset()).
*
* Returns GHOSTTY_NO_VALUE when Kitty graphics are disabled at build time.
*
* Output type: GhosttyKittyGraphics *
*/
GHOSTTY_TERMINAL_DATA_KITTY_GRAPHICS = 30,
/**
* The active screen's current selection.
*
* On success, writes an untracked snapshot of the terminal-owned selection
* to the caller-provided GhosttySelection. The GhosttySelection struct is
* caller-owned and may be kept, but the grid references inside it are
* untracked borrowed references into the active screen. They are only valid
* until the next mutating terminal call, such as ghostty_terminal_set(),
* ghostty_terminal_vt_write(), ghostty_terminal_resize(), or
* ghostty_terminal_reset().
*
* Returns GHOSTTY_NO_VALUE when there is no active selection.
*
* Output type: GhosttySelection *
*/
GHOSTTY_TERMINAL_DATA_SELECTION = 31,
/**
* Whether the viewport is currently pinned to the active area.
*
* This is true when the viewport is following the active terminal area,
* and false when the user has scrolled into history.
*
* Output type: bool *
*/
GHOSTTY_TERMINAL_DATA_VIEWPORT_ACTIVE = 32,
/**
* Whether VT processing encountered a non-gracefully handled error that may
* have prevented a terminal-owned semantic update.
*
* Processing remains best-effort, and ghostty_terminal_reset() does not
* clear it. Gracefully handled protocol failures, configured limits,
* malformed or unsupported input, and failures limited to external effects
* or query responses do not set it.
*
* This can't currently be unset. This is purely informational to consumers
* if there was some error that happened at some point during VT processing.
*
* Output type: bool *
*/
GHOSTTY_TERMINAL_DATA_VT_PROCESSING_ERROR = 33,
/**
* The configured maximum scrollback allocation in bytes.
*
* This always reports the primary screen's configured value, including
* while an alternate screen is active. Returns GHOSTTY_NO_VALUE when the
* configured byte limit is unlimited.
*
* Output type: size_t *
*/
GHOSTTY_TERMINAL_DATA_SCROLLBACK_MAX_BYTES = 34,
/**
* The configured maximum number of physical scrollback lines.
*
* This always reports the primary screen's configured value, including
* while an alternate screen is active. Returns GHOSTTY_NO_VALUE when the
* configured line limit is unlimited.
*
* Output type: size_t *
*/
GHOSTTY_TERMINAL_DATA_SCROLLBACK_MAX_LINES = 35,
/**
* The configured maximum retained VT continuation size in bytes.
*
* A value of zero means continuation tracking is disabled. This reports the
* configured limit even when a current unfinished continuation is
* temporarily unavailable.
*
* Output type: size_t *
*/
GHOSTTY_TERMINAL_DATA_CONTINUATION_MAX_BYTES = 36,
/**
* Get the current value of a terminal mode.
*
* The caller must initialize the `mode` field. On success, the `value` field
* is updated with the current value. A NULL pointer or unknown mode returns
* GHOSTTY_INVALID_VALUE.
*
* Input/output type: GhosttyTerminalModeConfig *
*/
GHOSTTY_TERMINAL_DATA_MODE = 37,
/**
* Whether VT processing is at ground.
*
* Ground is when the stream isn't in the middle of any type of sequence:
* UTF-8, ESC, CSI, OSC, etc. It is the stateless point of the stream.
*
* This is useful to know because it is a point at which you can
* safely insert out-of-band VT sequences. For example, while reading
* from a pty if you want to make your own changes, you can wait until
* the pty input reaches ground, then write yours.
*
* Output type: bool *
*/
GHOSTTY_TERMINAL_DATA_VT_GROUND = 38,
/**
* Whether the cursor is currently at a semantic shell prompt or input area.
*
* This depends on semantic prompt markers such as OSC 133. Returns false
* when semantic prompt information is unavailable or the alternate screen
* is active.
*
* Output type: bool *
*/
GHOSTTY_TERMINAL_DATA_CURSOR_AT_PROMPT = 39,
/**
* The configured maximum decoded bytes per Kitty clipboard protocol
* (OSC 5522) write transaction. See
* GHOSTTY_TERMINAL_OPT_CLIPBOARD_WRITE_MAX_BYTES.
*
* Output type: size_t *
*/
GHOSTTY_TERMINAL_DATA_CLIPBOARD_WRITE_MAX_BYTES = 40,
/**
* Whether xterm modifyOtherKeys mode 2 is enabled.
*
* Output type: bool *
*/
GHOSTTY_TERMINAL_DATA_MODIFY_OTHER_KEYS = 41,
GHOSTTY_TERMINAL_DATA_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE,
} GhosttyTerminalData;
/**
* Create a new terminal instance.
*
* The terminal starts with various reasonable defaults e.g. around
* scrollback limits. Use ghostty_terminal_set() to change any options
* prior to using the terminal.
*
* @param allocator Pointer to allocator, or NULL to use the default allocator
* @param terminal Pointer to store the created terminal handle
* @param cols Terminal width in cells (must be greater than zero)
* @param rows Terminal height in cells (must be greater than zero)
* @return GHOSTTY_SUCCESS on success, or an error code on failure
*
* @ingroup terminal
*/
GHOSTTY_API GhosttyResult ghostty_terminal_new(const GhosttyAllocator* allocator,
GhosttyTerminal* terminal,
uint16_t cols,
uint16_t rows);
/**
* Free a terminal instance.
*
* Releases all resources associated with the terminal. After this call,
* the terminal handle becomes invalid and must not be used.
*
* @param terminal The terminal handle to free (may be NULL)
*
* @ingroup terminal
*/
GHOSTTY_API void ghostty_terminal_free(GhosttyTerminal terminal);
/**
* Perform a full reset of the terminal (RIS).
*
* Resets all terminal state back to its initial configuration, including
* modes, scrollback, scrolling region, and screen contents. The terminal
* dimensions are preserved.
*
* @param terminal The terminal handle (may be NULL, in which case this is a no-op)
*
* @ingroup terminal
*/
GHOSTTY_API void ghostty_terminal_reset(GhosttyTerminal terminal);
/**
* Clear screen and history, retaining the cursor's soft-wrapped active line.
* Does not alter the VT parser or write to the child process. Returns false
* without changing the terminal on the alternate screen or for a NULL handle.
* Otherwise returns true and moves the retained line to the top of the screen.
*/
GHOSTTY_API bool ghostty_terminal_clear_screen(GhosttyTerminal terminal);
/**
* Resize the terminal to the given dimensions.
*
* Changes the number of columns and rows in the terminal. The primary
* screen will reflow content if wraparound mode is enabled; the alternate
* screen does not reflow. If the dimensions are unchanged, this is a no-op.
*
* This also updates the terminal's pixel dimensions (used for image
* protocols and size reports), disables synchronized output mode (allowed
* by the spec so that resize results are shown immediately), and sends an
* in-band size report if mode 2048 is enabled.
*
* @param terminal The terminal handle (NULL returns GHOSTTY_INVALID_VALUE)
* @param cols New width in cells (must be greater than zero)
* @param rows New height in cells (must be greater than zero)
* @param cell_width_px Width of a single cell in pixels
* @param cell_height_px Height of a single cell in pixels
* @return GHOSTTY_SUCCESS on success, or an error code on failure
*
* @ingroup terminal
*/
GHOSTTY_API GhosttyResult ghostty_terminal_resize(GhosttyTerminal terminal,
uint16_t cols,
uint16_t rows,
uint32_t cell_width_px,
uint32_t cell_height_px);
/**
* Set an option on the terminal.
*
* Configures terminal callbacks and associated state such as the
* write_pty callback and userdata pointer. The value is passed
* directly for pointer types (callbacks, userdata) or as a pointer
* to the value for non-pointer types (e.g. GhosttyString*).
* The behavior of a NULL value is specific to each option and is
* documented by the corresponding GhosttyTerminalOption value.
*
* Callbacks are invoked synchronously during VT writes. Callbacks must not
* call ghostty_terminal_vt_write() or
* ghostty_terminal_vt_write_until_ground() on the same terminal
* (no reentrancy).
*
* @param terminal The terminal handle (may be NULL, in which case this is a no-op)
* @param option The option to set
* @param value Pointer to the value to set (type depends on the option),
* or NULL to clear the option
*
* @ingroup terminal
*/
GHOSTTY_API GhosttyResult ghostty_terminal_set(GhosttyTerminal terminal,
GhosttyTerminalOption option,
const void* value);
/**
* Write VT-encoded data to the terminal for processing.
*
* Feeds raw bytes through the terminal's VT stream parser, updating
* terminal state accordingly. By default, sequences that require output
* (queries, device status reports) are silently ignored. Use
* ghostty_terminal_set() with GHOSTTY_TERMINAL_OPT_WRITE_PTY to install
* a callback that receives response data.
*
* This never fails. Any erroneous input or errors in processing the
* input are logged internally but do not cause this function to fail
* because this input is assumed to be untrusted and from an external
* source; so the primary goal is to keep the terminal state consistent and
* not allow malformed input to corrupt or crash.
*
* @param terminal The terminal handle
* @param data Pointer to the data to write
* @param len Length of the data in bytes
*
* @ingroup terminal
*/
GHOSTTY_API void ghostty_terminal_vt_write(GhosttyTerminal terminal,
const uint8_t* data,
size_t len);
/**
* Write VT-encoded data, but only the shortest prefix needed to reach ground.
*
* Ground is when the stream isn't in the middle of any type of sequence:
* UTF-8, ESC, CSI, OSC, etc. It is the stateless point of the stream.
*
* This is useful to know because it is a point at which you can
* safely insert out-of-band VT sequences. For example, while reading
* from a pty if you want to make your own changes, you can wait until
* the pty input reaches ground, then write yours.
*
* If the stream is already at ground then this consumes nothing and returns
* GHOSTTY_SUCCESS. On success, out_consumed is the number of bytes consumed
* before reaching ground, including the byte that reaches it.
* GHOSTTY_NO_VALUE means the full slice was consumed without reaching ground.
*
* @param terminal The terminal handle (must not be NULL)
* @param data Pointer to the data to write, or NULL when len is zero
* @param len Length of the data in bytes
* @param[out] out_consumed Number of bytes consumed (must not be NULL)
* @return GHOSTTY_SUCCESS if ground was reached, GHOSTTY_NO_VALUE if all input
* was consumed without reaching ground, or GHOSTTY_INVALID_VALUE if
* an argument is invalid
*
* @ingroup terminal
*/
GHOSTTY_API GhosttyResult ghostty_terminal_vt_write_until_ground(
GhosttyTerminal terminal,
const uint8_t* data,
size_t len,
size_t* out_consumed);
/**
* Write the terminal's replay-safe VT continuation to a callback writer.
*
* The continuation is the exact byte suffix needed to reconstruct unfinished
* VT parser or UTF-8 decoder state in an equivalent terminal. It is empty
* when the stream is at ground. The callback is invoked synchronously and
* may be called more than once. It must not call terminal APIs with the same
* terminal handle.
*
* Continuation tracking must have been enabled by setting
* GHOSTTY_TERMINAL_OPT_CONTINUATION_MAX_BYTES to a nonzero value before the
* input that produced the continuation was written.
*
* The caller must serialize this operation with both VT write functions and
* all other access to the same terminal.
*
* @param terminal Terminal to read from (must not be NULL)
* @param writer Destination writer whose write callback must not be NULL
* @return GHOSTTY_SUCCESS on success, GHOSTTY_IO_ERROR if the callback rejects
* a write, GHOSTTY_LIMIT_EXCEEDED if output accounting overflows, or
* GHOSTTY_INVALID_VALUE if an argument is invalid, tracking is
* disabled, or the current continuation is unavailable
*
* @ingroup terminal
*/
GHOSTTY_API GhosttyResult ghostty_terminal_continuation_write(
GhosttyTerminal terminal,
GhosttyWriter writer);
/**
* Copy the terminal's replay-safe VT continuation into a caller buffer.
*
* Pass NULL for buf with buf_len zero to query the required size. A size query
* returns GHOSTTY_OUT_OF_SPACE and stores the required size in out_written,
* including zero when the stream is at ground. If a non-NULL buffer is too
* small, the function has the same result and reports the full required size.
* Continuation tracking must have been enabled by setting
* GHOSTTY_TERMINAL_OPT_CONTINUATION_MAX_BYTES to a nonzero value before the
* input that produced the continuation was written.
*
* The caller must serialize this operation with all other access to the same
* terminal.
*
* @param terminal Terminal to read from (must not be NULL)
* @param buf Destination buffer, or NULL when buf_len is zero
* @param buf_len Destination buffer capacity in bytes
* @param[out] out_written Bytes written, or required size on
* GHOSTTY_OUT_OF_SPACE (must not be NULL)
* @return GHOSTTY_SUCCESS on success, GHOSTTY_OUT_OF_SPACE for a size query or
* insufficient buffer, or GHOSTTY_INVALID_VALUE if an argument is
* invalid, tracking is disabled, or the current continuation is
* unavailable
*
* @ingroup terminal
*/
GHOSTTY_API GhosttyResult ghostty_terminal_continuation_buf(
GhosttyTerminal terminal,
uint8_t* buf,
size_t buf_len,
size_t* out_written);
/**
* Return an allocated copy of the terminal's replay-safe VT continuation.
*
* The returned bytes are allocated with allocator, or the default allocator
* when allocator is NULL. The caller must release them with ghostty_free(),
* passing the same allocator and returned length. An empty continuation is a
* successful result with *out_ptr set to NULL and *out_len set to zero,
* which can also be passed to ghostty_free().
* Continuation tracking must have been enabled by setting
* GHOSTTY_TERMINAL_OPT_CONTINUATION_MAX_BYTES to a nonzero value before the
* input that produced the continuation was written.
*
* The caller must serialize this operation with all other access to the same
* terminal.
*
* @param terminal Terminal to read from (must not be NULL)
* @param allocator Allocator for the output, or NULL for the default allocator
* @param[out] out_ptr Allocated continuation bytes (must not be NULL)
* @param[out] out_len Number of continuation bytes (must not be NULL)
* @return GHOSTTY_SUCCESS on success, GHOSTTY_OUT_OF_MEMORY on allocation
* failure, or GHOSTTY_INVALID_VALUE if an argument is invalid,
* tracking is disabled, or the current continuation is unavailable
*
* @ingroup terminal
*/
GHOSTTY_API GhosttyResult ghostty_terminal_continuation_alloc(
GhosttyTerminal terminal,
const GhosttyAllocator* allocator,
uint8_t** out_ptr,
size_t* out_len);
/**
* Scroll the terminal viewport.
*
* Scrolls the terminal's viewport according to the given behavior.
* When using GHOSTTY_SCROLL_VIEWPORT_DELTA, set the delta field in
* the value union to specify the number of rows to scroll (negative
* for up, positive for down). When using GHOSTTY_SCROLL_VIEWPORT_ROW,
* set the row field to the absolute row offset from the top of the
* scrollable area (the same row space as the offset field of
* GhosttyTerminalScrollbar). For other behaviors, the value is ignored.
*
* @param terminal The terminal handle (may be NULL, in which case this is a no-op)
* @param behavior The scroll behavior as a tagged union
*
* @ingroup terminal
*/
GHOSTTY_API void ghostty_terminal_scroll_viewport(GhosttyTerminal terminal,
GhosttyTerminalScrollViewport behavior);
/**
* Return the current compression activity token.
*
* The token is opaque and only equality comparisons are meaningful. An
* embedding application should cache it and restart its compression idle
* delay whenever the value changes. The value may wrap and changes in either
* direction have the same meaning.
*
* This function only observes terminal state. It does not perform or schedule
* compression.
*
* @param terminal The terminal handle (NULL returns GHOSTTY_INVALID_VALUE)
* @param[out] out_activity Receives the current activity token
* @return GHOSTTY_SUCCESS on success, or GHOSTTY_INVALID_VALUE if an argument
* is NULL
*
* @ingroup terminal
*/
GHOSTTY_API GhosttyResult ghostty_terminal_compression_activity(
GhosttyTerminal terminal,
uint64_t* out_activity);
/**
* Compress eligible terminal scrollback.
*
* Incremental mode performs bounded work suitable for an idle callback. A
* pending result means the application should invoke another step while the
* terminal remains idle. A complete result means no continuation is needed
* until ghostty_terminal_compression_activity() changes. Full mode performs
* one synchronous scan and can stall on large scrollback buffers.
*
* Compression is opportunistic. Complete means the pass has finished, not
* that every page was compressed: pages may be unprofitable or encounter an
* allocation or reclamation failure. Compression changes only the terminal's
* storage representation and never its logical contents or scrollback limit.
* Accessing compressed history restores it transparently.
*
* This function is not thread-safe with other operations on the same
* terminal. The caller must serialize it with writes, rendering, searches,
* and other terminal access.
*
* @param terminal The terminal handle (NULL returns GHOSTTY_INVALID_VALUE)
* @param mode The amount of compression work to perform
* @param[out] out_result Receives the compression scheduling result
* @return GHOSTTY_SUCCESS on success, or GHOSTTY_INVALID_VALUE if an argument
* or mode is invalid
*
* @ingroup terminal
*/
GHOSTTY_API GhosttyResult ghostty_terminal_compress(
GhosttyTerminal terminal,
GhosttyTerminalCompressionMode mode,
GhosttyTerminalCompressionResult* out_result);
/**
* Get data from a terminal instance.
*
* Extracts typed data from the given terminal based on the specified
* data type. The output pointer must be of the appropriate type for the
* requested data kind. Valid data types and output types are documented
* in the `GhosttyTerminalData` enum.
*
* @param terminal The terminal handle (may be NULL)
* @param data The type of data to extract
* @param out Pointer to store the extracted data (type depends on data parameter)
* @return GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if the terminal
* is NULL or the data type is invalid
*
* @ingroup terminal
*/
GHOSTTY_API GhosttyResult ghostty_terminal_get(GhosttyTerminal terminal,
GhosttyTerminalData data,
void *out);
/**
* Get multiple data fields from a terminal in a single call.
*
* This is an optimization over calling ghostty_terminal_get()
* repeatedly, particularly useful in environments with high per-call
* overhead such as FFI or Cgo.
*
* Each element in the keys array specifies a data kind, and the
* corresponding element in the values array receives the result.
* The type of each values[i] pointer must match the output type
* documented for keys[i].
*
* Processing stops at the first error; on success out_written
* is set to count, on error it is set to the index of the
* failing key (i.e. the number of values successfully written).
*
* @param terminal The terminal handle (may be NULL)
* @param count Number of key/value pairs
* @param keys Array of data kinds to query
* @param values Array of output pointers (types must match each key's
* documented output type)
* @param[out] out_written On return, receives the number of values
* successfully written (may be NULL)
* @return GHOSTTY_SUCCESS if all queries succeed
*
* @ingroup terminal
*/
GHOSTTY_API GhosttyResult ghostty_terminal_get_multi(GhosttyTerminal terminal,
size_t count,
const GhosttyTerminalData* keys,
void** values,
size_t* out_written);
/**
* Resolve a point in the terminal grid to a grid reference.
*
* Resolves the given point (which can be in active, viewport, screen,
* or history coordinates) to a grid reference for that location. Use
* ghostty_grid_ref_cell() and ghostty_grid_ref_row() to extract the cell
* and row.
*
* Lookups using the `active` and `viewport` tags are fast. The `screen`
* and `history` tags may require traversing the full scrollback page list
* to resolve the y coordinate, so they can be expensive for large
* scrollback buffers.
*
* This function isn't meant to be used as the core of render loop. It
* isn't built to sustain the framerates needed for rendering large screens.
* Use the render state API for that. This API is instead meant for less
* strictly performance-sensitive use cases.
*
* @param terminal The terminal handle (NULL returns GHOSTTY_INVALID_VALUE)
* @param point The point specifying which cell to look up
* @param[out] out_ref On success, set to the grid reference at the given point (may be NULL)
* @return GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if the terminal
* is NULL or the point is out of bounds
*
* @ingroup terminal
*/
GHOSTTY_API GhosttyResult ghostty_terminal_grid_ref(GhosttyTerminal terminal,
GhosttyPoint point,
GhosttyGridRef *out_ref);
/**
* Create an owned tracked grid reference for a terminal point.
*
* This is the tracked variant of ghostty_terminal_grid_ref(). The returned
* handle follows the referenced cell as the terminal's page list is modified:
* scrolling, pruning, resize/reflow, and other page-list operations update the
* tracked reference automatically.
*
* The reference is attached to the terminal screen/page-list that is active at
* creation time.
*
* If the point is outside the requested coordinate space, this returns
* GHOSTTY_INVALID_VALUE and writes NULL to out_ref.
*
* The returned handle must be freed with ghostty_tracked_grid_ref_free(). If
* the terminal is freed first, the handle remains valid only for
* tracked-grid-ref APIs: it reports no value and can still be freed.
*
* @param terminal Terminal instance.
* @param point Point to track.
* @param[out] out_ref On success, receives the tracked reference handle.
* @return GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if terminal,
* point, or out_ref is invalid, or GHOSTTY_OUT_OF_MEMORY if allocation
* fails.
*
* @ingroup terminal
*/
GHOSTTY_API GhosttyResult ghostty_terminal_grid_ref_track(
GhosttyTerminal terminal,
GhosttyPoint point,
GhosttyTrackedGridRef *out_ref);
/**
* Convert a grid reference back to a point in the given coordinate system.
*
* This is the inverse of ghostty_terminal_grid_ref(): given a grid reference,
* it returns the x/y coordinates in the requested coordinate system (active,
* viewport, screen, or history).
*
* The grid reference must have been obtained from the same terminal instance.
* Like all grid references, it is only valid until the next mutating terminal
* call.
*
* Not every grid reference is representable in every coordinate system. For
* example, a cell in scrollback history cannot be expressed in active
* coordinates, and a cell that has scrolled off the visible area cannot be
* expressed in viewport coordinates. In these cases, the function returns
* GHOSTTY_NO_VALUE.
*
* @param terminal The terminal handle (NULL returns GHOSTTY_INVALID_VALUE)
* @param ref Pointer to the grid reference to convert
* @param tag The target coordinate system
* @param[out] out On success, set to the coordinate in the requested system (may be NULL)
* @return GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if the terminal
* or ref is NULL/invalid, GHOSTTY_NO_VALUE if the ref falls outside
* the requested coordinate system
*
* @ingroup terminal
*/
GHOSTTY_API GhosttyResult ghostty_terminal_point_from_grid_ref(
GhosttyTerminal terminal,
const GhosttyGridRef *ref,
GhosttyPointTag tag,
GhosttyPointCoordinate *out);
/** @} */
#ifdef __cplusplus
}
#endif
#endif /* GHOSTTY_VT_TERMINAL_H */
|