File: Readline.pm

package info (click to toggle)
perl6-readline 0.1.4-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 232 kB
  • sloc: perl: 67; makefile: 2
file content (2675 lines) | stat: -rw-r--r-- 108,965 bytes parent folder | download | duplicates (2)
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
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
use v6;
use NativeCall;
#
# XXX &cglobal.signature -> (Any $libname, Any $symbol, Any $target-type)
#

=begin pod

=begin NAME

Readline - GNU Readline binding for perl6

=end NAME

=begin SYNOPSIS

    my $readline = Readline.new;
    while my $response = $readline.readline( "prompt here (<cr> to exit)> " ) {
        $readline.add-history( $response ) if $response ~~ /\S/;
        say "[$response]";
    }

=end SYNOPSIS

=begin DESCRIPTION

A thin OO wrapper around the GNU Readline library. It exposes every function that the current Readline library does, along with some of the structs for history and keymap manipulation from the header files, so that you can peek into the internals. Most people will just use the basic C<readline> and C<add-history> functions, but the more advanced keymapping, history and completion bindings are available for use.

Method names are taken verbatim from the GNU Readline library, with one exception. Library calls use '_', Readline methods use '-'. This helps keep the two layers separate, and is a not-so-subtle reminder that you're using perl6 when using the library.

The documentation in the METHODS section is a verbatim paste of the appropriate bits from the GNU Readline documentation, so for further explanation of the methods, especially callbacks and completion, please see the L<GNU Readline> documentation.

Any chapter references in the documentation refer to the GNU Readline or GNU History manual.

=end DESCRIPTION

=begin LIBRARY

By default the Perl 6 module searches for libreadline.so.* and takes the most recent match it can find.

If you're on OS X, it searches for libreadline.dynlib.*.
On OpenBSD it searches for libereadline.so.*.

While I'd prefer to use L<LibraryCheck>'s technique of just attempting to link to a library, it doesn't seem to work inside of the C<is native(&func)> attribute. So instead, it defaults to v7 (the current version as of 2018-07-14) and searches for other versions along a fixed set of library paths, taken from bug reports.

I'll eventually put this into a proper library-find method.

=end LIBRARY

=begin METHODS

=item readline( Str $prompt ) returns Str

=item initialize( ) returns int32

    Initialize or re-initialize Readline's internal state. It's not strictly necessary to call this; readline() calls it before reading any input.

=item ding( ) returns int32

    Ring the terminal bell, obeying the setting of C<$bell-style>.

=begin History

These methods let you add, delete and manipulate history entries. See the L<examples/echo.pl6> script for usage.

=item add-history( Str $history )

    Place string C<$history> at the end of the history list. The associated data field (if any) is set to NULL.

=item using-history( )

    Begin a session in which the history functions might be used. This initializes the interactive variables.

    Author's note - C<add-history()> works fine without this call, maybe it's for methods that require state.

=item history-get-history-state( ) returns HISTORY_STATE

    Return a structure describing the current state of the input history.

=item history-set-history-state( HISTORY_STATE $state )

    Set the state of the history list according to C<$state>.

=item add-history-time( Str $timestamp )

    Change the time stamp associated with the most recent history entry to C<$timestamp>.

=item remove-history( int32 $which ) returns HIST_ENTRY

    Remove history entry at offset C<$which> from the history. The removed element is returned so you can free the line, data, and containing structure.

=item free-history-entry( HIST_ENTRY $entry ) returns Str # histdata_t

    Free the history entry C<$entry> and any history library private data associated with it. Returns the application-specific data so the caller can dispose of it.

=item replace-history-entry( int32 $which, Str $line, Str $data ) returns HIST_ENTRY # histdata_t $data ) returns HIST_ENTRY

    Make the history entry at offset C<$which> have C<$line> and C<$data>. This returns the old entry so the caller can dispose of any application-specific data. In the case of an invalid C<$which>, a NULL pointer is returned.

=item clear-history( )

    Clear the history list by deleting all the entries.

=item stifle-history( int32 $max )

    Stifle the history list, remembering only the last C<$max> entries.

=item unstifle-history( )

    Stop stifling the history. This returns the previously-set maximum number of history entries (as set by stifle_history()). The value is positive if the history was stifled, negative if it wasn't.

=item history-is-stifled( ) returns Bool

    Returns True if the history is stifled, False if not. The C version returns non-zero if the history is stifled, this gets converted to a Perl6 boolean.
   
=item history-list( ) returns CArray[HIST_ENTRY]

    Return a NULL terminated array of HIST_ENTRY * which is the current input history. Element 0 of this list is the beginning of time. If there is no history, return NULL.

=item where-history( ) returns int32

    Returns the offset of the current history element.

=item current-history( int32 $which ) returns HIST_ENTRY

    Return the history entry at the position C<$which>, as determined by C<where-history()>. If there is no entry there, return a NULL pointer.

=item history-get( int32 $which ) returns HIST_ENTRY

    Return the history entry at position C<$which>, starting from C<$history_base> (see section 2.4 History Variables). If there is no entry there, or if offset is greater than the history length, return a NULL pointer.

=item history-get-time( HIST_ENTRY $entry ) returns time_t

    Return the time stamp associated with the history entry C<$entry>.

=item history-total-bytes( ) returns int32

    Return the number of bytes that the primary history entries are using. This function returns the sum of the lengths of all the lines in the history.

=item history-set-pos( int32 $pos ) returns int32

    Set the current history offset to C<$pos>, an absolute index into the list. Returns 1 on success, 0 if C<$pos> is less than zero or greater than the number of history entries.

=item previous-history( ) returns HIST_ENTRY

    Back up the current history offset to the previous history entry, and return a pointer to that entry. If there is no previous entry, return a NULL pointer.

=item next-history( ) returns HIST_ENTRY

    Move the current history offset forward to the next history entry, and return the a pointer to that entry. If there is no next entry, return a NULL pointer.

=item history-search( Str $text, int32 $pos ) returns int32

    Search the history for C<$text>, starting at history offset C<$pos>. If direction is less than 0, then the search is through previous entries, otherwise through subsequent entries. If string is found, then the current history index is set to that history entry, and the value returned is the offset in the line of the entry where string was found. Otherwise, nothing is changed, and a -1 is returned.

=item history-search-prefix( Str $prefix, int32 $pos ) returns int32

    Search the history for a line prefixed with C<$prefix>, starting at history offset C<$pos>. The search is anchored: matching lines must begin with C<$prefix>. If direction is less than 0, then the search is through previous entries, otherwise through subsequent entries. If string is found, then the current history index is set to that entry, and the return value is 0. Otherwise, nothing is changed, and a -1 is returned.

=item history-search-pos( Str $text, int32 $pos, int32 $dir ) returns int32

    Search for C<$text> in the history list, starting at C<$pos>, an absolute index into the list. If C<$direction> is negative, the search proceeds backward from C<$pos>, otherwise forward. Returns the absolute index of the history element where C<$text> was found, or -1 otherwise.

=item read-history( Str $filename ) returns int32

    Add the contents of C<$filename> to the history list, a line at a time. If C<$filename> is Empty, then read from `~/.history'. Returns 0 if successful, or errno if not.

=item read-history-range( Str $filename, int32 $from, int32 $to ) returns int32

    Read a range of lines from C<$filename>, adding them to the history list. Start reading at line C<$from> and end at C<$to>. If C<$from> is zero, start at the beginning. If C<$to> is less than C<$from>, then read until the end of the file. If filename is Empty, then read from `~/.history'. Returns 0 if successful, or errno if not.

=item write-history( Str $filename ) returns int32

    Write the current history to C<$filename>, overwriting C<$filename> if necessary. If C<$filename> is NULL, then write the history list to `~/.history'. Returns 0 on success, or errno on a read or write error.

=item append-history( int32 $offset, Str $filename ) returns int32

    Append the elements starting at C<$offset> of the history list to C<$filename>. If C<$filename> is Empty, then append to `~/.history'. Returns 0 on success, or errno on a read or write error.

=item history-truncate-file( Str $filename, int32 $nLines ) returns int32

    Truncate the history file C<$filename>, leaving only the last C<$nLines> lines. If C<$filename> is Empty, then `~/.history' is truncated. Returns 0 on success, or errno on failure.

=item history-expand( Str $string, Pointer[Str] $output ) returns int32

    Expand C<$string>, placing the result into C<$output>, a pointer to a string (see section 1.1 History Expansion). Returns:

    0  If no expansions took place (or, if the only change in the text was the removal of escape characters preceding the history expansion character);
    1  if expansions did take place;
    -1 if there was an error in expansion;
    2  if the returned line should be displayed, but not executed, as with the :p modifier (see section 1.1.3 Modifiers).

    If an error occurred in expansion, then output contains a descriptive error message.

=item history-arg-extract( int32 $first, int32 $last, Str $string ) returns Str

    Extract a string segment consisting of the C<$first> through C<$last> arguments present in C<$string>. Arguments are split using C<history_tokenize()>.

=item get-history-event( Str $string, Pointer[int32] $cIndex, Str $delimiting-quote ) returns Str

    Returns the text of the history event beginning C<$$cIndex> characters into C<$string>.  C<$$cIndex> is modified to point to after the event specifier. At function entry, C<$cIndex> points to the index into string where the history event specification begins. qchar is a character that is allowed to end the event specification in addition to the "normal" terminating characters.

    Editor's note: C<$$cIndex> may be a byte offset into C<$string> rather than a character offset, so Unicode users beware.

    Editor's note - C<$delimiting-quote> is an integer in the underlying C API - If you want to use the actual C function call, please call C<rl_get_history_event()> instead.

    DELIMITING_QUOTE is a character that is allowed to end the string specification for what to search for in addition to the normal characters `:', ` ', `\t', `\n', and sometimes `?'.

=item history-tokenize( Str $string ) returns CArray[Str]

    Return an array of tokens parsed out of C<$string>, much as the shell might. The tokens are split on the characters in the C<$history_word_delimiters> variable, and shell quoting conventions are obeyed.

=end History

=begin Keymap

These methods let you manipulate the built-in key mappings.

=item make-bare-keymap( ) returns Keymap

    Returns a new, empty keymap. The space for the keymap is allocated with malloc(); the caller should free it by calling rl_free_keymap() when done.

=item copy-keymap( Keymap $map ) returns Keymap

    Return a new keymap which is a copy of C<$map>.

=item make-keymap( ) returns Keymap

    Return a new keymap with the printing characters bound to C<$rl_insert>, the lowercase Meta characters bound to run their equivalents, and the Meta digits bound to produce numeric arguments.

=item discard-keymap( Keymap $map )

    Free the storage associated with the data in C<$map>. The caller should free the pointer to C<$map>.

=item free-keymap( Keymap $map )

    Free all storage associated with C<$map>. This calls C<rl_discard_keymap()> to free subordindate keymaps and macros.

=item get-keymap-by-name( Str $name ) returns Keymap

    Return the keymap matching C<$name>. C<$name> is one which would be supplied in a set keymap inputrc line (see section 1.3 Readline Init File).

=item get-keymap( ) returns Keymap

    Returns the currently active keymap.

=item get-keymap-name( Keymap $map ) returns Str

    Return the name matching C<$map>. name is one which would be supplied in a set keymap inputrc line (see section 1.3 Readline Init File).

=item set-keymap( Keymap $map )

    Makes C<$map> the currently active keymap.

=end Keymap

=begin Callback

These functions let you use L<Readline> as an interactive event loop.

=item callback-handler-install( Str $prompt, &callback (Str) )

    Set up the terminal for readline I/O and display the initial expanded value of C<$prompt>. Save the value of lhandler to use as a handler function to call when a complete line of input has been entered. The handler function receives the text of the line as an argument.

=item callback-read-char( )

    Whenever an application determines that keyboard input is available, it should call rl_callback_read_char(), which will read the next character from the current input source. If that character completes the line, rl_callback_read_char will invoke the lhandler function installed by rl_callback_handler_install to process the line. Before calling the lhandler function, the terminal settings are reset to the values they had before calling rl_callback_handler_install. If the lhandler function returns, and the line handler remains installed, the terminal settings are modified for Readline's use again. EOF is indicated by calling lhandler with a NULL line.

=item callback-handler-remove( )

    Restore the terminal to its initial state and remove the line handler. This may be called from within a callback as well as independently. If the handler installed by rl_callback_handler_install does not exit the program, either this function or the function referred to by the value of rl_deprep_term_function should be called before the program exits to reset the terminal settings.

=end Callback

=begin Prompt

These methods manage the readline prompt.

=item set-prompt( Str $prompt ) returns int32

    Make Readline use C<$prompt> for subsequent redisplay. This calls C<rl_expand_prompt()> to expand the prompt and sets C<$rl_prompt> to the result.

=item expand-prompt( Str $prompt ) returns int32

    Expand any special character sequences in C<$prompt> and set up the local Readline prompt redisplay variables. This function is called by C<readline()>. It may also be called to expand the primary prompt if the C<rl_on_new_line_with_prompt()> function or C<$rl-already_prompted> variable is used. It returns the number of visible characters on the last line of the (possibly multi-line) prompt. Applications may indicate that the prompt contains characters that take up no physical screen space when displayed by bracketing a sequence of such characters with the special markers C<RL_PROMPT_START_IGNORE> and C<RL_PROMPT_END_IGNORE> (declared in `readline.h' and exposed in the Readline module as constants.) This may be used to embed terminal-specific escape sequences in prompts.

=end Prompt

=begin Binding

=item bind-key( Str $key, &callback (int32, int32 --> int32) ) returns int32

    rl_bind_key() takes two arguments: C<$key> is the character that you want to bind, and the callback function is called when key is pressed. Binding TAB to C<rl_insert()> makes TAB insert itself. C<rl_bind_key()> returns non-zero if key is not a valid ASCII character code (between 0 and 255).

    Editor's note - C<$key> is an integer in the underlying C API - If you want to use the actual C function call, please call C<rl_bind_key()> instead.

=item bind-key-in-map( Str $key, &callback (int32, int32 --> int32), Keymap $map ) returns int32

    Bind C<$key> to function in C<$map>. Returns non-zero in the case of an invalid key.

    Editor's note - C<$delimiting-quote> is an integer in the underlying C API - If you want to use the actual C function call, please call C<rl_bind_key_in_map()> instead.

=item unbind-key( Str $key ) returns Bool

    Bind C<$key> to the null function in the currently active keymap. Returns C<False> in case of error.

    Editor's note - C<$key> is an integer in the underlying C API - If you want to use the actual C function call, please call C<rl_unbind_key()> instead.

    Editor's note - The underlying C function returns non-zero on error, this is mapped onto a Perl6 Bool type. If you want the original behavior, call the underlying C<rl_unbind_key()> function rather than the Perl6 layer.

=item unbind-key-in-map( Str $key, Keymap $map ) returns Bool

    Bind C<$key> to the null function in C<$map>. Returns False in case of error.

    Editor's note - C<$key> is an integer in the underlying C API - If you want to use the actual C function call, please call C<rl_unbind_key_in_map()> instead.

    Editor's note - The underlying C function returns non-zero on error, this is mapped onto a Perl6 Bool type. If you want the original behavior, call the underlying C<rl_unbind_key_in_map()> function rather than the Perl6 layer.

=item bind-key-if-unbound( Str $key, &callback (int32, int32 --> int32) ) returns Bool

    Binds C<$key> to function if it is not already bound in the currently active keymap. Returns False in the case of an invalid key or if key is already bound.

    Editor's note - C<$key> is an integer in the underlying C API - If you want to use the actual C function call, please call C<rl_bind_key_if_unbound()> instead.

    Editor's note - The underlying C function returns non-zero on error, this is mapped onto a Perl6 Bool type. If you want the original behavior, call the underlying C<rl_bind_key_if_unbound()> function rather than the Perl6 layer.

=item bind-key-if-unbound-in-map( Str $key, &callback (int32, int32 --> int32), Keymap $map ) returns Bool

    Binds C<$key> to function if it is not already bound in C<$map>. Returns False in the case of an invalid key or if C<$key> is already bound.

    Editor's note - C<$key> is an integer in the underlying C API - If you want to use the actual C function call, please call C<rl_bind_key_if_unbound_in_map()> instead.

    Editor's note - The underlying C function returns non-zero on error, this is mapped onto a Perl6 Bool type. If you want the original behavior, call the underlying C<rl_bind_keyseq()> function rather than the Perl6 layer.

=item unbind-function-in-map ( &callback (int32, int32 --> int32), Keymap $map ) returns int32

    Unbind all keys that execute function in C<$map>.

=item bind-keyseq( Str $keyseq, &callback (int32, int32 --> int32) ) returns Bool

    Bind the key sequence represented by the string C<$keyseq> to the function function, beginning in the current keymap. This makes new keymaps as necessary. Returns False if C<$keyseq> is invalid.

    Editor's note - The underlying C function returns non-zero on error, this is mapped onto a Perl6 Bool type. If you want the original behavior, call the underlying C<rl_bind_keyseq()> function rather than the Perl6 layer.

=item bind-keyseq-in-map( Str $keyseq, &callback (int32, int32 --> int32), Keymap $map ) returns Bool

    Bind the key sequence represented by the string C<$keyseq> to the callback function. This makes new keymaps as necessary. Initial bindings are performed in map. The return value is False if C<$keyseq> is invalid.

    Editor's note - The underlying C function returns non-zero on error, this is mapped onto a Perl6 Bool type. If you want the original behavior, call the underlying C<rl_bind_keyseq_in_map()> function rather than the Perl6 layer.

=item bind-keyseq-if-unbound( Str $keyseq, &callback (int32, int32 --> int32) ) returns Bool

    Binds keyseq to function if it is not already bound in the currently active keymap. Returns False in the case of an invalid keyseq or if C<$keyseq> is already bound.

    Editor's note - The underlying C function returns non-zero on error, this is mapped onto a Perl6 Bool type. If you want the original behavior, call the underlying C<rl_bind_keyseq_if_unbound()> function rather than the Perl6 layer.

=item bind-keyseq-if-unbound-in-map( Str $str, &callback (int32, int32 --> int32), Keymap $map ) returns Bool

    Binds keyseq to function if it is not already bound in map. Returns non-zero in the case of an invalid keyseq or if keyseq is already bound.

    Editor's note - The underlying C function returns non-zero on error, this is mapped onto a Perl6 Bool type. If you want the original behavior, call the underlying C<rl_bind_keyseq_if_unbound_in_map()> function rather than the Perl6 layer.

=item generic-bind( int32 $i, Str $keyseq, Str $t, Keymap $map ) returns int32

    Bind the key sequence represented by the string C<$keyseq> to the arbitrary pointer data. type says what kind of data is pointed to by data; this can be a function (ISFUNC), a macro (ISMACR), or a keymap (ISKMAP). This makes new keymaps as necessary. The initial keymap in which to do bindings is map.

=end Binding

=item add-defun( Str $str, &callback (int32, int32 --> int32), Str $key ) returns int32

    Add name to the list of named functions. Make function be the function that gets called. If C<$key> is not -1, then bind it to function using rl_bind_key().

    Editor's note - C<$key> is an integer in the underlying C API - If you want to use the actual C function call, please call C<rl_add_defun()> instead.

    Using this function alone is sufficient for most applications. It is the recommended way to add a few functions to the default functions that Readline has built in. If you need to do something other than adding a function to Readline, you may need to use the underlying functions described below.

=item variable-value( Str $variable ) returns Str

    Return a string representing the value of the Readline variable C<$variable>. For boolean variables, this string is either `on' or `off'.

=item variable-bind( Str $variable, Str $value ) returns int32

    Make the Readline variable C<$variable> have value C<$alue>. This behaves as if the readline command `set variable value' had been executed in an inputrc file (see section 1.3.1 Readline Init File Syntax).

=item set-key( Str $str, &callback (int32, int32 --> int32), Keymap $map )

    Equivalent to C<rl-bind-keyseq-in-map()>.

=item macro-bind( Str $keyseq, Str $macro, Keymap $map ) returns int32

    Bind the key sequence C<$keyseq> to invoke the macro C<$macro>. The binding is performed in C<$map>. When C<$keyseq> is invoked, the macro will be inserted into the line. This function is deprecated; use C<rl_generic_bind()> instead.

=item named-function( Str $s ) returns &callback (int32, int32 --> int32)

    Return the function with name name.

=item function-of-keyseq( Str $keyseq, Keymap $map, Pointer[int32] $type ) returns &callback (int32, int32 --> int32)

    Return the function invoked by C<$keyseq> in keymap C<$map>. If C<$map> is Nil, the current keymap is used. If C<$type> is not Nil, the type of the object is returned in the int variable it points to (one of ISFUNC, ISKMAP, or ISMACR).

=item list-funmap-names( )

    Print the names of all bindable Readline functions to rl_outstream.

=item invoking-keyseqs-in-map( Pointer[&callback (int32, int32 --> int32)] $p-cmd, Keymap $map ) returns CArray[Str]

    Return an array of strings representing the key sequences used to invoke function in the keymap C<$map>.

=item invoking-keyseqs( Pointer[&callback (int32, int32 --> int32)] $p-cmd ) returns CArray[Str]

    Return an array of strings representing the key sequences used to invoke function in the current keymap.

=item function-dumper( Bool $readable )

    Print the readline function names and the key sequences currently bound to them to C<$rl_outstream>. If C<$readable> is True, the list is formatted in such a way that it can be made part of an inputrc file and re-read.

    Editor's note - The Perl6 layer translates True values of C<$readable> to non-zero, so if you want to specify a particular int32 value, please use the underlying C<rl_function_dumper()> call.

=item macro-dumper( Bool $readable )

    Print the key sequences bound to macros and their values, using the current keymap, to C<$rl_outstream>. If C<$readable> is True, the list is formatted in such a way that it can be made part of an inputrc file and re-read.

    Editor's note - The Perl6 layer translates True values of C<$readable> to non-zero, so if you want to specify a particular int32 value, please use the underlying C<rl_macro_dumper()> call.

=item variable-dumper( Bool $readable )

    Print the readline variable names and their current values to C<$rl_outstream>. If readable is True, the list is formatted in such a way that it can be made part of an inputrc file and re-read.

    Editor's note - The Perl6 layer translates True values of C<$readable> to non-zero, so if you want to specify a particular int32 value, please use the underlying C<rl_variable_dumper()> call.

=item read-init-file( Str $filename )

    Read keybindings and variable assignments from C<$filename> (see section 1.3 Readline Init File).

=item parse-and-bind( Str $line ) returns int32

    Parse C<$line> as if it had been read from the inputrc file and perform any key bindings and variable assignments found (see section 1.3 Readline Init File).

=item add-funmap-entry( Str $name, &callback (int32, int32 --> int32) ) returns int32

    Add C<$name> to the list of bindable Readline command names, and make function the function to be called when name is invoked.

=item funmap-names( ) returns CArray[Str]

    Return a NULL terminated array of known function names. The array is sorted. The array itself is allocated, but not the strings inside. You should free the array, but not the pointers, using free or rl_free when you are done.

=item push-macro-input( Str $macro )

    Cause C<$macro> to be inserted into the line, as if it had been invoked by a key bound to a macro. Not especially useful; use C<rl_insert_text()> instead.

=item free-undo-list( )

    Free the existing undo list.

=item do-undo( ) returns int32

    Undo the first thing on the undo list. Returns False if there was nothing to undo, True if something was undone.

    Editor's note - The underlying C function returns non-zero on error, this is mapped onto a Perl6 Bool type. If you want the original behavior, call the underlying C<rl_do_undo()> function rather than the Perl6 layer.

=item begin-undo-group( ) returns int32

    Begins saving undo information in a group construct. The undo information usually comes from calls to rl_insert_text() and rl_delete_text(), but could be the result of calls to rl_add_undo().

=item end-undo-group( ) returns int32

    Closes the current undo group started with rl_begin_undo_group (). There should be one call to rl_end_undo_group() for each call to rl_begin_undo_group().

=item modifying( int32 $start, int32 $end ) returns int32

    Tell Readline to save the text between C<$start> and C<$end> as a single undo unit. It is assumed that you will subsequently modify that text.

=item redisplay( )

    Change what's displayed on the screen to reflect the current contents of rl_line_buffer.

=item on-new-line( ) returns int32

    Tell the update functions that we have moved onto a new (empty) line, usually after outputting a newline.

=item on-new-line-with-prompt( ) returns int32

    Tell the update functions that we have moved onto a new line, with C<$rl_prompt> already displayed. This could be used by applications that want to output the prompt string themselves, but still need Readline to know the prompt string length for redisplay. It should be used after setting rl_already_prompted.

=item forced-update-display( ) returns int32

    Force the line to be updated and redisplayed, whether or not Readline thinks the screen display is correct.

=item clear-message( ) returns int32

    Clear the message in the echo area. If the prompt was saved with a call to rl_save_prompt before the last call to rl_message, call rl_restore_prompt before calling this function.

=item reset-line-state( ) returns int32

    Reset the display state to a clean state and redisplay the current line starting on a new line.

=item crlf( ) returns int32

    Move the cursor to the start of the next screen line.

=item show-char( Str $c ) returns int32

    Display character c on rl_outstream. If Readline has not been set to display meta characters directly, this will convert meta characters to a meta-prefixed key sequence. This is intended for use by applications which wish to do their own redisplay.

    Editor's note - C<$key> is an integer in the underlying C API - If you want to use the actual C function call, please call C<rl_show_char()> instead.

=item save-prompt( )

    Save the local Readline prompt display state in preparation for displaying a new message in the message area with rl_message().

=item restore-prompt( )

    Restore the local Readline prompt display state saved by the most recent call to rl_save_prompt. if rl_save_prompt was called to save the prompt before a call to rl_message, this function should be called before the corresponding call to rl_clear_message.

=item replace-line( Str $text, int32 $clear-undo )

    Replace the contents of C<$rl_line_buffer> with C<$text>. The point and mark are preserved, if possible. If C<$clear-undo> is non-zero, the undo list associated with the current line is cleared.

=item insert-text( Str $text ) returns int32

    Insert C<$text> into the line at the current cursor position. Returns the number of characters inserted.

=item delete-text( int32 $start, int32 $end ) returns int32

    Delete the text between C<$start> and C<$end> in the current line. Returns the number of characters deleted.

=item kill-text( int32 $start, int32 $end ) returns int32

    Copy the text between C<$start> and C<$end> in the current line to the kill ring, appending or prepending to the last kill if the last command was a kill command. The text is deleted. If C<$start> is less than C<$end>, the text is appended, otherwise prepended. If the last command was not a kill, a new kill ring slot is used.

=item copy-text( int32 $start, int32 $end ) returns Str

    Return a copy of the text between C<$start> and C<$end> in the current line.

=item prep-terminal( int32 $meta-flag )

    Modify the terminal settings for Readline's use, so readline() can read a single character at a time from the keyboard. The C<$meta-flag> argument should be non-zero if Readline should read eight-bit input.

=item deprep-terminal( )

    Undo the effects of C<rl_prep_terminal()>, leaving the terminal in the state in which it was before the most recent call to C<rl_prep_terminal()>.

=item tty-set-default-bindings( Keymap $map )

    Read the operating system's terminal editing characters (as would be displayed by stty) to their Readline equivalents. The bindings are performed in keymap C<$map>.

=item tty-unset-default-bindings( Keymap $map )

    Reset the bindings manipulated by C<$rl_tty_set_default_bindings> so that the terminal editing characters are bound to C<$rl_insert>. The bindings are performed in keymap C<$map>.

=item reset-terminal( Str $terminal-name ) returns int32

    Reinitialize Readline's idea of the terminal settings using C<$terminal-name> as the terminal type (e.g., vt100). If terminal_name is NULL, the value of the TERM environment variable is used.

=item resize-terminal( )

    Update Readline's internal screen size by reading values from the kernel.

=item set-screen-size( int32 $rows, int32 $cols )

    Set Readline's idea of the terminal size to C<$rows> rows and C<$cols> columns. If either C<$rows> or C<$cols> is less than or equal to 0, Readline's idea of that terminal dimension is unchanged.

If an application does not want to install a SIGWINCH handler, but is still interested in the screen dimensions, Readline's idea of the screen size may be queried.

=item get-screen-size( Pointer[int32] $rows, Pointer[int32] $cols )

    Return Readline's idea of the terminal's size in the variables pointed to by the arguments.

=item reset-screen-size( )

    Cause Readline to reobtain the screen size and recalculate its dimensions.

=item get-termcap( Str $cap ) returns Str

    Retrieve the string value of the termcap capability C<$cap>. Readline fetches the termcap entry for the current terminal name and uses those capabilities to move around the screen line and perform other terminal-specific operations, like erasing a line. Readline does not use all of a terminal's capabilities, and this function will return values for only those capabilities Readline uses.

=item extend-line-buffer( int32 $len )

    Ensure that rl_line_buffer has enough space to hold C<$len> characters, possibly reallocating it if necessary.

=item alphabetic( Str $c ) returns Bool

    Return True if c is an alphabetic character.

    Editor's note - The underlying C function returns non-zero on error, this is mapped onto a Perl6 Bool type. If you want the original behavior, call the underlying C<rl_alphabetic()> function rather than the Perl6 layer.

    Editor's note - C<$c> is an integer in the underlying C API - If you want to use the actual C function call, please call C<rl_alphabetic()> instead.

=item free( Pointer $mem )

    Deallocate the memory pointed to by C<$mem>. C<$mem> must have been allocated by malloc.

=begin Signals

These methods manipulate signal handling for L<Readline>.

=item set-signals( ) returns int32

    Install Readline's signal handler for SIGINT, SIGQUIT, SIGTERM, SIGHUP, SIGALRM, SIGTSTP, SIGTTIN, SIGTTOU, and SIGWINCH, depending on the values of rl_catch_signals and rl_catch_sigwinch.

=item clear-signals( ) returns int32

    Remove all of the Readline signal handlers installed by C<rl_set_signals()>.

=item cleanup-after-signal( )

    This function will reset the state of the terminal to what it was before readline() was called, and remove the Readline signal handlers for all signals, depending on the values of C<$rl-catch-signals> and C<$rl-catch-sigwinch>.

=item reset-after-signal( )

    This will reinitialize the terminal and reinstall any Readline signal handlers, depending on the values of C<$rl_catch_signals> and C<$rl_catch_sigwinch>.

    If an application does not wish Readline to catch SIGWINCH, it may call C<rl_resize_terminal()> or C<rl_set_screen_size()> to force Readline to update its idea of the terminal size when a SIGWINCH is received.

=item free-line-state( )

    This will free any partial state associated with the current input line (undo information, any partial history entry, any partially-entered keyboard macro, and any partially-entered numeric argument). This should be called before C<rl_cleanup_after_signal()>. The Readline signal handler for SIGINT calls this to abort the current input line.

=item echo-signal( int32 $c ) # XXX not in v6

    If an application wishes to install its own signal handlers, but still have readline display characters that generate signals, calling this function with sig set to SIGINT, SIGQUIT, or SIGTSTP will display the character generating that signal.

=end Signals

=item set-paren-blink-timeout( int32 $c ) returns int32

    Set the time interval (in microseconds) that Readline waits when showing a balancing character when blink-matching-paren has been enabled.

=item complete-internal( int32 $what-to-do ) returns int32

    Complete the word at or before point. C<$what-to-do> says what to do with the completion. A value of `?' means list the possible completions. `TAB' means do standard completion. `*' means insert all of the possible completions. `!' means to display all of the possible completions, if there is more than one, as well as performing partial completion. `@' is similar to `!', but possible completions are not listed if the possible completions share a common prefix.

=item username-completion-function ( Str $text, int32 $i ) returns Str # XXX doesn't exist?

    A completion generator for usernames. C<$text> contains a partial username preceded by a random character (usually `~'). As with all completion generators, state is zero on the first call and non-zero for subsequent calls.

=item filename-completion-function ( Str $text, int32 $i ) returns Str # XXX Doesn't exist?

    A generator function for filename completion in the general case. C<$text> is a partial filename. The Bash source is a useful reference for writing application-specific completion functions (the Bash completion functions call this and other Readline functions).

=item completion-mode( Pointer[&callback (int32, int32 --> int32)] $cfunc ) returns int32

    Returns the appropriate value to pass to C<rl_complete_internal()> depending on whether C<$cfunc> was called twice in succession and the values of the show-all-if-ambiguous and show-all-if-unmodified variables. Application-specific completion functions may use this function to present the same interface as rl_complete().

=item save-state( readline_state $sp ) returns int32

    Save a snapshot of Readline's internal state to C<$sp>. The contents of the readline_state structure are documented in `readline.h'. The caller is responsible for allocating the structure.

=item tilde-expand( Str $str ) returns Str

    Return a new string which is the result of tilde-expanding C<$str>.

=item tilde-expand-word( Str $filename ) returns Str

    Do the work of tilde expansion on C<$filename>.  C<$filename> starts with a tilde.  If there is no expansion, call C<$tilde_expansion_failure_hook>.

=item tilde-find-word( Str $word, int32 $offset, Pointer[int32] $p-end-offset ) returns Str

    Find the portion of the string beginning with ~ that should be expanded.

=item restore-state( readline_state $sp ) returns int32

    Restore Readline's internal state to that stored in C<$sp>, which must have been saved by a call to C<rl_save_state()>. The contents of the readline_state structure are documented in `readline.h'. The caller is responsible for freeing the structure.

=end METHODS

=end pod

class Readline:ver<0.1.4> {

  sub LIBREADLINE {
    my $library = 'readline';
    my $library-match = rx/:i libreadline\.so\.(\d+) $/;
    my $version = v7;

    # Collect library paths from arbitrary OSen to search.
    #
    my constant LIBRARY-PATHS = (
      '/lib/x86_64-linux-gnu', # Author's VM
      '/usr/local/lib',        # Generic path
      '/usr/lib64',            # Slackware 14 among others
      '/usr/lib',              # Generic path
      '/lib'                   # even more generic.
    );
    my @library-path = grep { .IO.e }, LIBRARY-PATHS;

    given $*VM.osname {
      when 'openbsd' {
        $library = 'ereadline';
        $library-match = rx/:i libereadline\.so\.(\d+) $/;
        $version = v1.0;
        my sub tgetnum(Str --> int32) is native('ncurses') { * }
        tgetnum('');
      }
      when 'darwin' {
        $library-match = rx/:i libreadline\.dynlib\.\d+ $/;
      }
    }

    # Search each of the LIBRARY-PATHS paths for libreadline.
    #
    for @library-path -> $path {
      # Filter out everything but libreadline.{so,dynlib}.*
      # Sort it so the last entry is the latest
      #
      my @dir = sort dir( $path, :test( $library-match ) );
      next unless @dir;

      @dir[*-1] ~~ $library-match;
      $version = Version.new( ( $0 ) );
      last;
    }

    ( $library, $version )
  }

  # Embedded typedefs here
  #
#  my class histdata_t is repr('CPointer') { }; # typedef char *histdata_t;
  my class time_t is repr('CPointer') { }; # XXX probably already a native type.
  my class Keymap is repr('CPointer') { }; # typedef KEYMAP_ENTRY *Keymap;
  # typedef void rl_vcpfunc_t (char *);

  #my class rl_command_func_t is repr('CPointer') { }; #typedef int rl_command_func_t (int, int);
  my class rl_compentry_func_t is repr('CPointer') { }; #typedef char *rl_compentry_func_t (const char *, int);

  constant meta_character_threshold = 0x07f; # Larger than this is Meta.
  constant meta_character_bit       = 0x080; # x0000000, must be on.
  constant largest_char             = 255;   # Largest character value.

  sub META_CHAR( $c ) {
    ord( $c ) > meta_character_threshold && ord( $c ) <= largest_char
  }

  sub META( $c ) {
    ord( $c ) | meta_character_bit
  }

  sub UNMETA( $c ) {
    ord( $c ) & ~meta_character_bit
  }

  ############################################################################
  #
  # history.h -- the names of functions that you can call in history.
  #

  # The structure used to store a history entry.
  #
  my class HIST_ENTRY is repr('CStruct') {
    has Str $.line;        # char *line;
    has Str $.timestamp;   # char *timestamp;
#    has histdata_t $.data; # histdata_t data;
    has Str $.data;        # histdata_t is really char*
  }

  # Size of the history-library-managed space in history entry HS.
  #
  sub HISTENT_BYTES( $hs ) {
    $hs.line.length + $hs.timestamp.length
  }

  # A structure used to pass the current state of the history stuff around.
  #
  my class HISTORY_STATE is repr('CStruct') {
    has Pointer $.entries; # Pointer to an array of HIST_ENTRY types.
    has int     $.offset;  # The location pointer within this array.
    has int     $.length;  # Number of elements within this array.
    has int     $.size;    # Number of slots allocated to this array.
    has int     $.flags;
  }

  # Flag values for the `flags' member of HISTORY_STATE.
  #
  constant HS_STIFLED = 0x01;

  # Initialization and state management.
  #
  # Begin a session in which the history functions might be used.  This
  # just initializes the interactive variables.
  #
  sub using_history( )
    is native( LIBREADLINE ) { * }
  method using-history( ) {
    using_history() }

  # Return the current HISTORY_STATE of the history.
  #
  sub history_get_history_state( )
    returns HISTORY_STATE
    is native( LIBREADLINE ) { * }
  method history-get-history-state( )
    returns HISTORY_STATE {
    history_get_history_state() }

  # Set the state of the current history array to STATE.
  #
  sub history_set_history_state( HISTORY_STATE )
    is native( LIBREADLINE ) { * }
  method history-set-history-state( HISTORY_STATE $state ) {
    history_set_history_state( $state ) }

  # Manage the history list.
  #
  # Place STRING at the end of the history list.
  # The associated data field (if any) is set to NULL.
  #
  sub add_history( Str ) is export
    is native( LIBREADLINE ) { * }
  method add-history( Str $history ) {
    add_history( $history ) }

  # Change the timestamp associated with the most recent history entry to
  # STRING.
  #
  sub add_history_time( Str )
    is native( LIBREADLINE ) { * }
  method add-history-time( Str $timestamp ) {
    add_history_time( $timestamp ) }

  # A reasonably useless function, only here for completeness.  WHICH
  # is the magic number that tells us which element to delete.  The
  # elements are numbered from 0.
  #
  sub remove_history( int32 )
    returns HIST_ENTRY
    is native( LIBREADLINE ) { * }
  method remove-history( int32 $which )
    returns HIST_ENTRY {
    remove_history( $which ) }

  # Free the history entry H and return any application-specific data
  # associated with it.
  #
  sub free_history_entry( HIST_ENTRY )
#    returns histdata_t
    returns Str
    is native( LIBREADLINE ) { * }
  method free-history-entry( HIST_ENTRY $entry )
#    returns histdata_t {
    returns Str {
    free_history_entry( $entry ) }

#  sub replace_history_entry( int32, Str, histdata_t )
  sub replace_history_entry( int32, Str, Str )
    returns HIST_ENTRY
    is native( LIBREADLINE ) { * }
#  method replace-history-entry( int32 $which, Str $line, histdata_t $data )
  method replace-history-entry( int32 $which, Str $line, Str $data )
    returns HIST_ENTRY {
      replace_history_entry( $which, $line, $data ) }

  sub clear_history( )
    is native( LIBREADLINE ) { * }
  method clear-history( ) {
    clear_history() }

  sub stifle_history( int32 )
    is native( LIBREADLINE ) { * }
  method stifle-history( int32 $max ) {
    stifle_history( $max ) }

  sub unstifle_history( )
    is native( LIBREADLINE ) { * }
  method unstifle-history( ) {
    unstifle_history() }

  sub history_is_stifled( )
    returns int32
    is native( LIBREADLINE ) { * }
  method history-is-stifled( )
    returns Bool {
    history_is_stifled() ?? True !! False }

  # Information about the history list.
  #
  sub history_list( )
    returns CArray[HIST_ENTRY]
    is native( LIBREADLINE ) { * }
  method history-list( )
    returns CArray[HIST_ENTRY] {
    history_list() }

  sub where_history( )
    returns int32
    is native( LIBREADLINE ) { * }
  method where-history( )
    returns int32 {
    where_history() }

  sub current_history( int32 )
    returns HIST_ENTRY
    is native( LIBREADLINE ) { * }
  method current-history( int32 $which )
    returns HIST_ENTRY {
    current_history( $which ) }

  sub history_get( int32 )
    returns HIST_ENTRY
    is native( LIBREADLINE ) { * }
  method history-get( int32 $which )
    returns HIST_ENTRY {
    history_get( $which ) }

  sub history_get_time( HIST_ENTRY )
    returns time_t
    is native( LIBREADLINE ) { * }
  method history-get-time( HIST_ENTRY $h )
    returns time_t {
    history_get_time( $h ) }

  sub history_total_bytes( )
    returns int32
    is native( LIBREADLINE ) { * }
  method history-total-bytes( )
    returns int32 {
    history_total_bytes( ) }

  # Moving around the history list.
  #
  sub history_set_pos( int32 )
    returns int32
    is native( LIBREADLINE ) { * }
  method history-set-pos( int32 $pos )
    returns int32 {
    history_set_pos( $pos ) }

  sub previous_history( )
    returns HIST_ENTRY
    is native( LIBREADLINE ) { * }
  method previous-history( )
    returns HIST_ENTRY {
    previous_history( ) }

  sub next_history( )
    returns HIST_ENTRY
    is native( LIBREADLINE ) { * }
  method next-history( )
    returns HIST_ENTRY {
    next_history( ) }

  # Searching the history list.
  #
  sub history_search( Str, int32 )
    returns int32
    is native( LIBREADLINE ) { * }
  method history-search( Str $text, int32 $pos )
    returns int32 {
    history_search( $text, $pos ) }

  sub history_search_prefix( Str, int32 )
    returns int32
    is native( LIBREADLINE ) { * }
  method history-search-prefix( Str $text, int32 $pos )
    returns int32 {
    history_search_prefix( $text, $pos ) }

  sub history_search_pos( Str, int32, int32 )
    returns int32
    is native( LIBREADLINE ) { * }
  method history-search-pos( Str $text, int32 $pos, int32 $dir )
    returns int32 {
    history_search_pos( $text, $pos, $dir ) }

  # Managing the history file.
  #
  sub read_history( Str )
    returns int32
    is native( LIBREADLINE ) { * }
  method read-history( Str $text )
    returns int32 {
    my $rv = read_history( $text );
    $rv == 0 ?? True !! $rv }

  sub read_history_range( Str, int32, int32 )
    returns int32
    is native( LIBREADLINE ) { * }
  method read-history-range( Str $text, int32 $from, int32 $to )
    returns int32 {
    read_history_range( $text, $from, $to ) }

  sub write_history( Str )
    returns int32
    is native( LIBREADLINE ) { * }
  method write-history( Str $filename )
    returns int32 {
    my $rv = write_history( $filename );
    $rv == 0 ?? True !! $rv }

  sub append_history( int32, Str )
    returns int32
    is native( LIBREADLINE ) { * }
  method append-history( int32 $offset, Str $filename )
    returns int32 {
    append_history( $offset, $filename ) }

  sub history_truncate_file( Str, int32 )
    returns int32
    is native( LIBREADLINE ) { * }
  method history-truncate-file( Str $filename, int32 $nLines )
    returns int32 {
    my $rv = history_truncate_file( $filename, $nLines );
    $rv == 0 ?? True !! $rv }

  # History expansion.
  #
  sub history_expand( Str, Pointer[Str] )
    returns int32
    is native( LIBREADLINE ) { * }
  method history-expand( Str $string, Pointer[Str] $output )
    returns int32 {
    history_expand( $string, $output ) }

  sub history_arg_extract( int32, int32, Str )
    returns Str
    is native( LIBREADLINE ) { * }
  method history-arg-extract( int32 $first, int32 $last, Str $string )
    returns Str {
    history_arg_extract( $first, $last, $string ) }

  sub get_history_event( Str, Pointer[int32], int32 )
    returns Str
    is native( LIBREADLINE ) { * }
  method get-history-event( Str $string, Pointer[int32] $index, Str $delimiting-quote )
    returns Str {
    get_history_event( $string, $index, ord( $delimiting-quote.substr(0,1) ) ) }


  sub history_tokenize( Str )
    returns CArray[Str]
    is native( LIBREADLINE ) { * }
  method history-tokenize( Str $string )
    returns CArray[Str] {
    history_tokenize( $string ) }

  # Exported history variables.
  #extern int history_base;
  #extern int history_length;
  #extern int history_max_entries;
  #extern char history_expansion_char;
  #extern char history_subst_char;
  #extern char *history_word_delimiters;
  #extern char history_comment_char;
  #extern char *history_no_expand_chars;
  #extern char *history_search_delimiter_chars;
  #extern int history_quotes_inhibit_expansion;

  #extern int history_write_timestamps;

  # Backwards compatibility 
  #
  #extern int max_input_history;

  # If set, this function is called to decide whether or not a particular
  # history expansion should be treated as a special case for the calling
  # application and not expanded.
  #
  #extern rl_linebuf_func_t *history_inhibit_expansion_function;

  #############################################################################
  #
  # keymaps.h -- Manipulation of readline keymaps.
  #
  # A keymap contains one entry for each key in the ASCII set.
  # Each entry consists of a type and a pointer.
  # FUNCTION is the address of a function to run, or the
  # address of a keymap to indirect through.
  # TYPE says which kind of thing FUNCTION is.
  #

  my class KEYMAP_ENTRY is repr('CStruct') {
    has byte              $.type;     # char type;
#    has rl_command_func_t $.function; # rl_command_func_t *function # XXX
  }

  # This must be large enough to hold bindings for all of the characters
  # in a desired character set (e.g, 128 for ASCII, 256 for ISO Latin-x,
  # and so on) plus one for subsequence matching.
  #
  constant KEYMAP_SIZE = 257;
  constant ANYOTHERKEY = KEYMAP_SIZE - 1;

  #typedef KEYMAP_ENTRY KEYMAP_ENTRY_ARRAY[KEYMAP_SIZE];
  #
  # The values that TYPE can have in a keymap entry.
  #
  constant ISFUNC = 0;
  constant ISKMAP = 1;
  constant ISMACR = 2;

  #extern KEYMAP_ENTRY_ARRAY emacs_standard_keymap, emacs_meta_keymap;
  #extern KEYMAP_ENTRY emacs_ctlx_keymap;
  #extern KEYMAP_ENTRY_ARRAY vi_insertion_keymap, vi_movement_keymap;

  sub rl_make_bare_keymap( )
    returns Keymap
    is native( LIBREADLINE ) { * }
  method make-bare-keymap( )
    returns Keymap {
    rl_make_bare_keymap( ) }

  sub rl_copy_keymap( Keymap )
    returns Keymap
    is native( LIBREADLINE ) { * }
  method copy-keymap( Keymap $map )
    returns Keymap {
    rl_copy_keymap( $map ) }

  sub rl_make_keymap( )
    returns Keymap
    is native( LIBREADLINE ) { * }
  method make-keymap( )
    returns Keymap {
    rl_make_keymap( ) }

  sub rl_discard_keymap( Keymap )
    is native( LIBREADLINE ) { * }
  method discard-keymap( Keymap $map ) {
    rl_discard_keymap( $map ) }

  sub rl_free_keymap( Keymap )
    is native( LIBREADLINE ) { * }
  method free-keymap( Keymap $map ) {
    rl_free_keymap( $map ) }

  # These functions actually appear in bind.c
  #
  sub rl_get_keymap_by_name( Str )
    returns Keymap
    is native( LIBREADLINE ) { * }
  method get-keymap-by-name( Str $name )
    returns Keymap {
    rl_get_keymap_by_name( $name ) }

  sub rl_get_keymap( )
    returns Keymap
    is native( LIBREADLINE ) { * }
  method get-keymap( )
    returns Keymap {
    rl_get_keymap( ) }

  sub rl_get_keymap_name( Keymap )
    returns Str
    is native( LIBREADLINE ) { * }
  method get-keymap-name( Keymap $map )
    returns Str {
    rl_get_keymap_name( $map ) }

  sub rl_set_keymap( Keymap )
    is native( LIBREADLINE ) { * }
  method set-keymap( Keymap $map ) {
    rl_set_keymap( $map ) }

  #############################################################################
  #
  # Readline.h -- the names of functions callable from within readline.
  #
  # Readline data structures.
  #
  # Maintaining the state of undo.  We remember individual deletes and inserts
  # on a chain of things to do.
  #
  # The actions that undo knows how to undo.  Notice that UNDO_DELETE means
  # to insert some text, and UNDO_INSERT means to delete some text.   I.e.,
  # the code tells undo what to undo, not how to undo it.
  #
  #enum undo_code { UNDO_DELETE, UNDO_INSERT, UNDO_BEGIN, UNDO_END };

  constant UNDO_DELETE = 0;
  constant UNDO_INSERT = 1;
  constant UNDO_BEGIN  = 2;
  constant UNDO_END    = 3;

  # What an element of THE_UNDO_LIST looks like.
  #
  my class UNDO_LIST is repr('CStruct') {
    has UNDO_LIST $.next; # struct undo_list *next;
    has int $.start;      # int start; # Where the change took place.
    has int $.end;        # int end;
    has Str $.text;       # char *text; # The text to insert, if undoing a delete
    has byte $.what;      # enum undo_code what; # Delete, Insert, Begin, End.
  }

  # The current undo list for RL_LINE_BUFFER.
  #
  #extern UNDO_LIST *rl_undo_list;

  # The data structure for mapping textual names to code addresses.
  #
  my class FUNMAP is repr('CStruct') {
    has Str     $.name;     # const char *name;
#    has Pointer $.function; # rl_command_func_t *function; # XXX
  }

  #extern FUNMAP **funmap;

  # Bindable commands for numeric arguments.
  #
  # These should only be passed as callbacks, I believe.
  #
  sub rl_digit_argument( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_universal_argument( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }

  # Bindable commands for moving the cursor.
  #
  sub rl_forward_byte( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_forward_char( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_forward( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_backward_byte( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_backward_char( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_backward( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_beg_of_line( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_end_of_line( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_forward_word( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_backward_word( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_refresh_line( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_clear_screen( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_skip_csi_sequence( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_arrow_keys( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }

  # Bindable commands for inserting and deleting text.
  #
  sub rl_insert( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_quoted_insert( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_tab_insert( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_newline( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_do_lowercase_version( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_rubout( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_delete( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_rubout_or_delete( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_delete_horizontal_space( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_delete_or_show_completions( int32, int32 ) returns int32
    is native( LIBREADLINE ) { * }
  sub rl_insert_comment( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }

  # Bindable commands for changing case.
  #
  sub rl_upcase_word( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_downcase_word( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_capitalize_word( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }

  # Bindable commands for transposing characters and words.
  #
  sub rl_transpose_words( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_transpose_chars( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }

  # Bindable commands for searching within a line.
  #
  sub rl_char_search( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_backward_char_search( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }

  # Bindable commands for readline's interface to the command history.
  #
  sub rl_beginning_of_history ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_end_of_history ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_get_next_history ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_get_previous_history ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }

  # Bindable commands for managing the mark and region.
  #
  sub rl_set_mark ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_exchange_point_and_mark ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }

  # Bindable commands to set the editing mode (emacs or vi).
  #
  sub rl_vi_editing_mode ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_emacs_editing_mode ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }

  # Bindable commands to change the insert mode (insert or overwrite)
  #
  sub rl_overwrite_mode ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }

  # Bindable commands for managing key bindings.
  #
  sub rl_re_read_init_file ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_dump_functions ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_dump_macros ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_dump_variables ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }

  # Bindable commands for word completion.
  #
  sub rl_complete ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_possible_completions ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_insert_completions ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_old_menu_complete ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_menu_complete ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_backward_menu_complete ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }

  # Bindable commands for killing and yanking text, and managing the kill ring.
  #
  sub rl_kill_word ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_backward_kill_word ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_kill_line ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_backward_kill_line ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_kill_full_line ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_unix_word_rubout ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_unix_filename_rubout ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_unix_line_discard ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_copy_region_to_kill ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_kill_region ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_copy_forward_word ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_copy_backward_word ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_yank ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_yank_pop ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_yank_nth_arg ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_yank_last_arg ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_paste_from_clipboard ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }

  # Bindable commands for incremental searching.
  #
  sub rl_reverse_search_history ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_forward_search_history ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }

  # Bindable keyboard macro commands.
  #
  sub rl_start_kbd_macro ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_end_kbd_macro ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_call_last_kbd_macro ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_print_last_kbd_macro ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  #
  # Bindable undo commands.
  #
  sub rl_revert_line ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_undo_command ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }

  # Bindable tilde expansion commands.
  #
  sub rl_tilde_expand ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }

  # Bindable terminal control commands.
  #
  sub rl_restart_output ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_stop_output ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }

  # Miscellaneous bindable commands.
  #
  sub rl_abort ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_tty_status ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }

  # Bindable commands for incremental and non-incremental history searching.
  #
  sub rl_history_search_forward ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_history_search_backward ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_history_substr_search_forward ( int32, int32 ) returns int32
    is native( LIBREADLINE ) { * }
  sub rl_history_substr_search_backward ( int32, int32 ) returns int32
    is native( LIBREADLINE ) { * }
  sub rl_noninc_forward_search ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_noninc_reverse_search ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_noninc_forward_search_again ( int32, int32 ) returns int32
    is native( LIBREADLINE ) { * }
  sub rl_noninc_reverse_search_again ( int32, int32 ) returns int32
    is native( LIBREADLINE ) { * }

  # Bindable command used when inserting a matching close character.
  #
  sub rl_insert_close ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }

  # Not available unless READLINE_CALLBACKS is defined.
  #

 sub rl_callback_handler_install( Str, &callback (Str) ) is export
   is native( LIBREADLINE ) { * }
#  method callback-handler-install( Str $s, &callback (Str) ) {
#    rl_callback_handler_install( $s, $cb ) }

  sub rl_callback_read_char( ) is export
    is native( LIBREADLINE ) { * }
  method callback-read-char( ) {
    rl_callback_read_char( ) }
 
  sub rl_callback_handler_remove( ) is export
    is native( LIBREADLINE ) { * }
  method callback-handler-remove( ) {
    rl_callback_handler_remove( ) }

  # Things for vi mode. Not available unless readline is compiled -DVI_MODE.
  #
  # VI-mode bindable commands.
  #
  sub rl_vi_redo ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_undo ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_yank_arg ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_fetch_history ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_search_again ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_search ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_complete ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_tilde_expand ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_prev_word ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_next_word ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_end_word ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_insert_beg ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_append_mode ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_append_eol ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_eof_maybe ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_insertion_mode ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_insert_mode ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_movement_mode ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_arg_digit ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_change_case ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_put ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_column ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_delete_to ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_change_to ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_yank_to ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_rubout ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_delete ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_back_to_indent ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_first_print ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_char_search ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_match ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_change_char ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_subst ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_overstrike ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_overstrike_delete ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_replace ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_set_mark ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_goto_mark ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }

  # VI-mode utility functions.
  #
  sub rl_vi_check( ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_domove( int32, Pointer[int32] ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_bracktype( int32 ) returns int32 is native( LIBREADLINE ) { * }

  sub rl_vi_start_inserting( int32, int32, int32 ) returns int32 is native( LIBREADLINE ) { * }

  # VI-mode pseudo-bindable commands, used as utility functions.
  #
  sub rl_vi_fWord ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_bWord ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_eWord ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_fword ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_bword ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }
  sub rl_vi_eword ( int32, int32 ) returns int32 is native( LIBREADLINE ) { * }

  ###################################################################
  #								    #
  #			Well Published Functions		    #
  #								    #
  ###################################################################
  #
  # Readline functions.
  #
  sub readline( Str )
    is export
    returns Str
    is native( LIBREADLINE ) { * }
  method readline( Str $prompt )
    returns Str {
    readline( $prompt ) }

  sub rl_set_prompt( Str )
    returns int32
    is native( LIBREADLINE ) { * }
  method set-prompt( Str $prompt )
    returns int32 {
    rl_set_prompt( $prompt ) }

  sub rl_expand_prompt( Str )
    returns int32
    is native( LIBREADLINE ) { * }
  method expand-prompt( Str $prompt )
    returns int32 {
    rl_expand_prompt( $prompt ) }

  sub rl_initialize( )
    returns int32
    is native( LIBREADLINE ) { * }
  method initialize( )
    returns int32 {
    rl_initialize( ) }

  # Utility functions to bind keys to readline commands.
  #
  sub rl_bind_key( int32, &callback (int32, int32 --> int32) )
    returns int32
    is native( LIBREADLINE ) { * }
  method bind-key( Str $key, $cb )
    returns int32 {
    rl_bind_key( ord( $key.substr(0,1) ), $cb ) }

  sub rl_bind_key_in_map( int32, &callback (int32, int32 --> int32), Keymap )
    returns int32
    is native( LIBREADLINE ) { * }
  method bind-key-in-map( Str $key, $cb, Keymap $map )
    returns int32 {
    rl_bind_key_in_map( ord( $key.substr(0,1) ), $cb, $map ) }

  sub rl_unbind_key( int32 )
    returns int32
    is native( LIBREADLINE ) { * }
  method unbind-key( Str $key )
    returns Bool {
    rl_unbind_key( ord( $key.substr(0,1) ) ) != 0 ?? False !! True }

  sub rl_unbind_key_in_map( int32, Keymap )
    returns int32
    is native( LIBREADLINE ) { * }
  method unbind-key-in-map( Str $key, Keymap $map )
    returns Bool {
    rl_unbind_key_in_map( ord( $key.substr(0,1) ), $map ) != 0 ?? False !! True }

  sub rl_bind_key_if_unbound( int32, &callback (int32, int32 --> int32) )
    returns int32
    is native( LIBREADLINE ) { * }
  method bind-key-if-unbound( Str $key, $cb )
    returns int32 {
    rl_bind_key_if_unbound( ord( $key.substr(0,1) ), $cb ) }

  sub rl_bind_key_if_unbound_in_map( int32, &callback (int32, int32 --> int32), Keymap )
    returns int32
    is native( LIBREADLINE ) { * }
  method bind-key-if-unbound-in-map
    ( Str $key, $cb, Keymap $map )
    returns Bool {
      rl_bind_key_if_unbound_in_map( ord( $key.substr(0,1) ), $cb, $map ) != 0 ?? False !! True }

  sub rl_unbind_function_in_map( &callback (int32, int32 --> int32), Keymap )
    returns int32
    is native( LIBREADLINE ) { * }
  method unbind-function-in-map ( $cb, Keymap $map )
    returns int32 {
      rl_unbind_function_in_map( $cb, $map ) }

  sub rl_bind_keyseq( Str, &callback (int32, int32 --> int32) )
    returns int32
    is native( LIBREADLINE ) { * }
  method bind-keyseq( Str $str, $cb )
    returns Bool {
      rl_bind_keyseq( $str, $cb ) != 0 ?? False !! True }

  sub rl_bind_keyseq_in_map( Str, &callback (int32, int32 --> int32), Keymap )
    returns int32
    is native( LIBREADLINE ) { * }
  method bind-keyseq-in-map( Str $str, $cb, Keymap $map )
    returns Bool {
      rl_bind_keyseq_in_map( $str, $cb, $map ) != 0 ?? False !! True }

  sub rl_bind_keyseq_if_unbound( Str, &callback (int32, int32 --> int32) )
    returns int32
    is native( LIBREADLINE ) { * }
  method bind-keyseq-if-unbound( Str $str, $cb )
   returns Bool {
    rl_bind_keyseq_if_unbound( $str, $cb ) != 0 ?? False !! True }

  sub rl_bind_keyseq_if_unbound_in_map
    ( Str, &callback (int32, int32 --> int32), Keymap )
    returns int32
    is native( LIBREADLINE ) { * }
  method bind-keyseq-if-unbound-in-map
    ( Str $str, $cb, Keymap $map )
    returns Bool {
      rl_bind_keyseq_if_unbound_in_map( $str, $cb, $map )
        != 0 ?? False !! True }

  sub rl_generic_bind( int32, Str, Str, Keymap )
    returns int32
    is native( LIBREADLINE ) { * }
  method generic-bind( int32 $i, Str $s, Str $t, Keymap $map )
    returns int32 {
    rl_generic_bind( $i, $s, $t, $map ) }

  sub rl_add_defun( Str, &callback (int32, int32 --> int32), int32 )
    returns int32
    is native( LIBREADLINE ) { * }
  method add-defun( Str $str, $cb, Str $key )
    returns int32 {
    rl_add_defun( $str, $cb, ord( $key.substr(0,1) ) ) }

  sub rl_variable_value( Str )
    returns Str
    is native( LIBREADLINE ) { * }
  method variable-value( Str $s )
    returns Str {
    rl_variable_value( $s ) }

  sub rl_variable_bind( Str, Str )
    returns int32
    is native( LIBREADLINE ) { * }
  method variable-bind( Str $s, Str $t )
    returns int32 {
    rl_variable_bind( $s, $t ) }

  # Backwards compatibility, use rl_bind_keyseq_in_map instead.
  #
  sub rl_set_key( Str, &callback (int32, int32 --> int32), Keymap )
    returns int32
    is native( LIBREADLINE ) { * }
  method set-key( Str $str, $cb, Keymap $map )
    returns int32 {
      rl_set_key( $str, $cb, $map ) }

  # Backwards compatibility, use rl_generic_bind instead.
  #
  sub rl_macro_bind( Str, Str, Keymap )
    returns int32
    is native( LIBREADLINE ) { * }
  method macro-bind( Str $str, Str $b, Keymap $map )
    returns int32 {
    rl_macro_bind( $str, $b, $map ) }

  sub rl_named_function( Str, Str, Keymap )
    returns int32
    is native( LIBREADLINE ) { * }
#  method named-function( Str $str ) {
#    returns &callback (int32, int32 --> int32) {
#    rl_macro_bind( $str, $b, $map ) }

  sub rl_translate_keyseq( Str, Str, Pointer[int32] )
    returns int32
    is native( LIBREADLINE ) { * }
  method translate-keyseq( Str $str, Str $b, Pointer[int32] $k )
    returns int32 {
    rl_translate_keyseq( $str, $b, $k ) }

  sub rl_untranslate_keyseq( int32 )
    returns int32
    is native( LIBREADLINE ) { * }
  method untranslate-keyseq( int32 $i )
    returns int32 {
    rl_untranslate_keyseq( $i ) }

# XXX Not sure how to return callback type.
#
#  sub rl_named_function( Str )
#    returns &callback (int32, int32 --> int32)
#    is native( LIBREADLINE ) { * }
#  method named-function( Str $s )
#    returns rl_command_func_t {
#    rl_named_function( $s ) }

# XXX Not sure how to return callback type.
#
#  sub rl_function_of_keyseq( Str, Keymap, Pointer[int32] )
#    returns &callback (int32, int32 --> int32)
#    is native( LIBREADLINE ) { * }
#  method function-of-keyseq( Str $s, Keymap $map, Pointer[int32] $p )
#    returns rl_command_func_t {
#      rl_function_of_keyseq( $s, $map, $p ) }

  sub rl_list_funmap_names( )
    is native( LIBREADLINE ) { * }
  method list-funmap-names( ) {
    rl_list_funmap_names( ) }

  sub rl_invoking_keyseqs_in_map( &callback (int32, int32 --> int32), Keymap )
    returns CArray[Str]
    is native( LIBREADLINE ) { * }
  method invoking-keyseqs-in-map( $cb, Keymap $map )
    returns CArray[Str] {
      rl_invoking_keyseqs_in_map( $cb, $map ) }

  sub rl_invoking_keyseqs( &callback (int32, int32 --> int32) )
    returns CArray[Str]
    is native( LIBREADLINE ) { * }
  method invoking-keyseqs( $cb )
    returns CArray[Str] {
    rl_invoking_keyseqs( $cb ) }

  sub rl_function_dumper( int32 )
    is native( LIBREADLINE ) { * }
  method function-dumper( Bool $readable ) {
    rl_function_dumper( $readable ?? 1 !! 0 ) }

  sub rl_macro_dumper( int32 )
    is native( LIBREADLINE ) { * }
  method macro-dumper( Bool $readable ) {
    rl_macro_dumper( $readable ?? 1 !! 0 ) }

  sub rl_variable_dumper( int32 )
    is native( LIBREADLINE ) { * }
  method variable-dumper( Bool $readable ) {
    rl_variable_dumper( $readable ?? 1 !! 0 ) }

  sub rl_read_init_file( Str )
    is native( LIBREADLINE ) { * }
  method read-init-file( Str $line ) {
    rl_read_init_file( $line ) }

  sub rl_parse_and_bind( Str )
    returns int32
    is native( LIBREADLINE ) { * }
  method parse-and-bind( Str $line )
    returns int32 {
    rl_parse_and_bind( $line ) }

  # Functions for manipulating the funmap, which maps command names
  # to functions.
  #
  sub rl_add_funmap_entry( Str, &callback (int32, int32 --> int32) )
    returns int32
    is native( LIBREADLINE ) { * }
  method add-funmap-entry( Str $name, $cb ) # XXX Type this properly
    returns int32 {
    rl_add_funmap_entry( $name, $cb ) }

  sub rl_funmap_names( )
    returns CArray[Str]
    is native( LIBREADLINE ) { * }
  method funmap-names( )
    returns CArray[Str] {
    rl_funmap_names( ) }

  # Utility functions for managing keyboard macros.
  #
  sub rl_push_macro_input( Str )
    is native( LIBREADLINE ) { * }
  method push-macro-input( Str $macro ) {
    rl_push_macro_input( $macro ) }

  # Functions for undoing, from undo.c
  #
  sub rl_add_undo( int32, int32, int32, Str ) # XXX first arg is undo_code
    is native( LIBREADLINE ) { * }
  method add-undo( int32 $code, int32 $a, int32 $b, Str $mark ) {
    rl_add_undo( $code, $a, $b, $mark ) }

  sub rl_free_undo_list( )
    is native( LIBREADLINE ) { * }
  method free-undo-list( ) {
    rl_free_undo_list( ) }

  sub rl_do_undo( )
    returns int32
    is native( LIBREADLINE ) { * }
  method do-undo( )
    returns Bool {
    rl_do_undo( ) == 0 ?? False !! True }

  sub rl_begin_undo_group( )
    returns int32
    is native( LIBREADLINE ) { * }
  method begin-undo-group( )
    returns int32 {
    rl_begin_undo_group( ) }

  sub rl_end_undo_group( )
    returns int32
    is native( LIBREADLINE ) { * }
  method end-undo-group( )
    returns int32 {
    rl_end_undo_group( ) }

  sub rl_modifying( int32, int32 )
    returns int32
    is native( LIBREADLINE ) { * }
  method modifying( int32 $start, int32 $end )
    returns int32 {
    rl_modifying( $start, $end ) }

  # Functions for redisplay.
  #
  sub rl_redisplay( )
    is native( LIBREADLINE ) { * }
  method redisplay( ) {
    rl_redisplay( ) }

  sub rl_on_new_line( )
    returns int32
    is native( LIBREADLINE ) { * }
  method on-new-line( )
    returns int32 {
    rl_on_new_line( ) }

  sub rl_on_new_line_with_prompt( )
    returns int32
    is native( LIBREADLINE ) { * }
  method on-new-line-with-prompt( )
    returns int32 {
    rl_on_new_line_with_prompt( ) }

  sub rl_forced_update_display( )
    returns int32
    is native( LIBREADLINE ) { * }
  method forced-update-display( )
    returns int32 {
    rl_forced_update_display( ) }

  sub rl_clear_message( )
    returns int32
    is native( LIBREADLINE ) { * }
  method clear-message( )
    returns int32 {
    rl_clear_message( ) }

  sub rl_reset_line_state( )
    returns int32
    is native( LIBREADLINE ) { * }
  method reset-line-state( )
    returns int32 {
    rl_reset_line_state( ) }

  sub rl_crlf( )
    returns int32
    is native( LIBREADLINE ) { * }
  method crlf( )
    returns int32 {
    rl_crlf( ) }

  #extern int rl_message (const char *, ...)  __rl_attribute__((__format__ (printf, 1, 2)); # XXX

  sub rl_show_char( int32 )
    returns int32
    is native( LIBREADLINE ) { * }
  method show-char( Str $c )
    returns int32 {
    rl_show_char( ord( $c.substr(0,1) ) ) }

  # Undocumented in texinfo manual.
  #
  sub rl_character_len( int32, int32 )
    returns int32
    is native( LIBREADLINE ) { * }
  method character-len( int32 $c, int32 $d )
    returns int32 {
    rl_character_len( $c, $d ) }

  # Save and restore internal prompt redisplay information.
  #
  sub rl_save_prompt( )
    is native( LIBREADLINE ) { * }
  method save-prompt( ) {
    rl_save_prompt( ) }

  sub rl_restore_prompt( )
    is native( LIBREADLINE ) { * }
  method restore-prompt( ) {
    rl_restore_prompt( ) }

  # Modifying text.
  #
  sub rl_replace_line( Str, int32 )
    is native( LIBREADLINE ) { * }
  method replace-line( Str $text, int32 $clear-undo ) {
    rl_replace_line( $text, $clear-undo ) }

  sub rl_insert_text( Str )
    returns int32
    is native( LIBREADLINE ) { * }
  method insert-text( Str $text )
    returns int32 {
    rl_insert_text( $text ) }

  sub rl_delete_text( int32, int32 )
    returns int32
    is native( LIBREADLINE ) { * }
  method delete-text( int32 $start, int32 $end )
    returns int32 {
    rl_delete_text( $start, $end ) }

  sub rl_kill_text( int32, int32 )
    returns int32
    is native( LIBREADLINE ) { * }
  method kill-text( int32 $start, int32 $end )
    returns int32 {
    rl_kill_text( $start, $end ) }

  sub rl_copy_text( int32, int32 )
    returns Str
    is native( LIBREADLINE ) { * }
  method copy-text( int32 $start, int32 $end )
    returns Str {
    rl_copy_text( $start, $end ) }

  # Terminal and tty mode management.
  #
  sub rl_prep_terminal( int32 )
    is native( LIBREADLINE ) { * }
  method prep-terminal( int32 $meta-flag ) {
    rl_prep_terminal( $meta-flag ) }

  sub rl_deprep_terminal( )
    is native( LIBREADLINE ) { * }
  method deprep-terminal( ) {
    rl_deprep_terminal( ) }

  sub rl_tty_set_default_bindings( Keymap )
    is native( LIBREADLINE ) { * }
  method tty-set-default-bindings( Keymap $map ) {
    rl_tty_set_default_bindings ( $map ) }

  sub rl_tty_unset_default_bindings ( Keymap )
    is native( LIBREADLINE ) { * }
  method tty-unset-default-bindings( Keymap $map ) {
    rl_tty_unset_default_bindings ( $map ) }

  sub rl_reset_terminal( Str )
    returns int32
    is native( LIBREADLINE ) { * }
  method reset-terminal( Str $terminal-name )
    returns int32 {
    rl_reset_terminal( $terminal-name ) }

  sub rl_resize_terminal( )
    is native( LIBREADLINE ) { * }
  method resize-terminal( ) {
    rl_resize_terminal( ) }

  sub rl_set_screen_size( int32, int32 )
    is native( LIBREADLINE ) { * }
  method set-screen-size( int32 $rows, int32 $cols ) {
    rl_set_screen_size( $rows, $cols ) }

  sub rl_get_screen_size( Pointer[int32], Pointer[int32] )
    is native( LIBREADLINE ) { * }
  method get-screen-size( Pointer[int32] $rows, Pointer[int32] $cols ) {
    rl_get_screen_size( $rows, $cols ) }

  sub rl_reset_screen_size( )
    is native( LIBREADLINE ) { * }
  method reset-screen-size( ) {
    rl_reset_screen_size( ) }

  sub rl_get_termcap( Str )
    returns Str
    is native( LIBREADLINE ) { * }
  method get-termcap( Str $cap )
    returns Str {
    rl_get_termcap( $cap ) }

  # Functions for character input.
  #
  #extern int rl_getc (FILE *);
  #extern int rl_set_keyboard_input_timeout (int);

  sub rl_stuff_char( int32 )
    returns int32
    is native( LIBREADLINE ) { * }
  method stuff-char( int32 $c )
    returns int32 {
    rl_stuff_char( $c ) }

  sub rl_execute_next( int32 )
    returns int32
    is native( LIBREADLINE ) { * }
  method execute-next( int32 $c )
    returns int32 {
    rl_execute_next( $c ) }

  sub rl_clear_pending_input( )
    returns int32
    is native( LIBREADLINE ) { * }
  method clear-pending-input( )
    returns int32 {
    rl_clear_pending_input( ) }

  sub rl_read_key( )
    returns int32
    is native( LIBREADLINE ) { * }
  method read-key( )
    returns int32 {
    rl_read_key( ) }

  # `Public' utility functions.
  #
  sub rl_extend_line_buffer( int32 )
    is native( LIBREADLINE ) { * }
  method extend-line-buffer( int32 $len ) {
    rl_extend_line_buffer( $len ) }

  sub rl_ding( )
    returns int32
    is native( LIBREADLINE ) { * }
  method ding( )
    returns int32 {
    rl_ding( ) }

  sub rl_alphabetic( int32 )
    returns int32
    is native( LIBREADLINE ) { * }
  method alphabetic( Str $c )
    returns Bool {
    rl_alphabetic( ord( $c.substr(0,1) ) ) == 1 ?? True !! False }

  sub rl_free( Pointer )
    is native( LIBREADLINE ) { * }
  method free( Pointer $mem ) {
    rl_free( $mem ) }

  # Readline signal handling, from signals.c
  #
  sub rl_set_signals( )
    returns int32
    is native( LIBREADLINE ) { * }
  method set-signals( )
    returns int32 {
    rl_set_signals( ) }

  sub rl_clear_signals( )
    returns int32
    is native( LIBREADLINE ) { * }
  method clear-signals( )
    returns int32 {
    rl_clear_signals( ) }

  sub rl_cleanup_after_signal( )
    is native( LIBREADLINE ) { * }
  method cleanup-after-signal( ) {
    rl_cleanup_after_signal( ) }

  sub rl_reset_after_signal( )
    is native( LIBREADLINE ) { * }
  method reset-after-signal( ) {
    rl_reset_after_signal( ) }

  sub rl_free_line_state( )
    is native( LIBREADLINE ) { * }
  method free-line-state( ) {
    rl_free_line_state( ) }

#  sub rl_echo_signal( int32 )
#    is native( LIBREADLINE ) { * }
#  method echo-signal( int32 $c ) {
#    rl_echo_signal( $c ) }

  sub rl_set_paren_blink_timeout( int32 )
    returns int32
    is native( LIBREADLINE ) { * }
  method set-paren-blink-timeout( int32 $c )
    returns int32 {
    rl_set_paren_blink_timeout( $c ) }

  # Completion functions.
  #
  sub rl_complete_internal( int32 ) returns int32
    is native( LIBREADLINE ) { * }
  method complete-internal( int32 $what-to-do ) returns int32 {
    rl_complete_internal( $what-to-do ) }

  sub rl_display_match_list( CArray[Str], int32, int32 )
    returns int32
    is native( LIBREADLINE ) { * }
  method display-match-list( CArray[Str] $list, int32 $a, int32 $b )
    returns int32 {
    rl_display_match_list( $list, $a, $b ) }

  sub rl_completion_matches( Str, &callback (Str, int32 --> Str) )
    returns Pointer[Str]
    is native( LIBREADLINE ) { * }
  method completion-matches( Str $text, $cb )
    returns Pointer[Str] {
    rl_completion_matches( $text, $cb ) }

  sub rl_completion_mode( &callback (int32, int32 --> int32) )
    returns int32
    is native( LIBREADLINE ) { * }
  method completion-mode( $cb )
    returns int32 {
    rl_completion_mode( $cb ) }

  ############################################################
  #  							     #
  #  		Well Published Variables		     #
  #  							     #
  ############################################################
  #
  # The version of this incarnation of the readline library.
  #
  #extern const char *rl_library_version;	/* e.g., "4.2" */
  #extern int rl_readline_version;		/* e.g., 0x0402 */

  # True if this is real GNU readline.
  #
  #extern int rl_gnu_readline_p;

  # Flags word encapsulating the current readline state.
  #
  #extern int rl_readline_state;

  # Says which editing mode readline is currently using.  1 means emacs mode;
  # 0 means vi mode.
  #
  #extern int rl_editing_mode;

  # Insert or overwrite mode for emacs mode.  1 means insert mode; 0 means
  # overwrite mode.  Reset to insert mode on each input line.
  #
  #extern int rl_insert_mode;

  # The name of the calling program.  You should initialize this to
  # whatever was in argv[0].  It is used when parsing conditionals.
  #
  #extern const char *rl_readline_name;

  # The prompt readline uses.  This is set from the argument to
  # readline (), and should not be assigned to directly.
  #
  #extern char *rl_prompt;

  # The prompt string that is actually displayed by rl_redisplay.  Public so
  # applications can more easily supply their own redisplay functions.
  #
  #extern char *rl_display_prompt;

  # The line buffer that is in use.
  #
  #extern char *rl_line_buffer;

  # The location of point, and end.
  #
  #extern int rl_point;
  #extern int rl_end;

  # The mark, or saved cursor position.
  #
  #extern int rl_mark;

  # Flag to indicate that readline has finished with the current input
  # line and should return it.
  #
  #extern int rl_done;

  # If set to a character value, that will be the next keystroke read.
  #
  #extern int rl_pending_input;

  # Non-zero if we called this function from _rl_dispatch().  It's present
  # so functions can find out whether they were called from a key binding
  # or directly from an application.
  #
  #extern int rl_dispatching;

  # Non-zero if the user typed a numeric argument before executing the
  # current function.
  #
  #extern int rl_explicit_arg;

  # The current value of the numeric argument specified by the user.
  #
  #extern int rl_numeric_arg;

  # The address of the last command function Readline executed.
  #
  #extern rl_command_func_t *rl_last_func;

  # The name of the terminal to use.
  #
  #extern const char *rl_terminal_name;

  # The input and output streams.
  #
#my $GlobalInt := cglobal('./10-cglobals', 'GlobalInt', int32);

  # XXX sizeof(FILE*) width.
  # 64-bit pointer
  our $rl_instream := cglobal( LIBREADLINE, 'rl_instream', num64 );

  #extern FILE *rl_instream;
  #extern FILE *rl_outstream;

  # If non-zero, Readline gives values of LINES and COLUMNS from the environment
  # greater precedence than values fetched from the kernel when computing the
  # screen dimensions.
  #
  #extern int rl_prefer_env_winsize;

  # If non-zero, then this is the address of a function to call just
  # before readline_internal () prints the first prompt.
  #
  #extern rl_hook_func_t *rl_startup_hook;

  # If non-zero, this is the address of a function to call just before
  # readline_internal_setup () returns and readline_internal starts
  # reading input characters.
  #
  #extern rl_hook_func_t *rl_pre_input_hook;

  # The address of a function to call periodically while Readline is
  # awaiting character input, or NULL, for no event handling.
  #
  #extern rl_hook_func_t *rl_event_hook;

  # The address of a function to call if a read is interrupted by a signal.
  #
  #extern rl_hook_func_t *rl_signal_event_hook;

  # The address of a function to call if Readline needs to know whether or not
  # there is data available from the current input source.
  #
  #extern rl_hook_func_t *rl_input_available_hook;

  # The address of the function to call to fetch a character from the current
  # Readline input stream.
  #
  #extern rl_getc_func_t *rl_getc_function;

  #extern rl_voidfunc_t *rl_redisplay_function;

  #extern rl_vintfunc_t *rl_prep_term_function;
  #extern rl_voidfunc_t *rl_deprep_term_function;

  # Dispatch variables.
  #
  #extern Keymap rl_executing_keymap;
  #extern Keymap rl_binding_keymap;

  #extern int rl_executing_key;
  #extern char *rl_executing_keyseq;
  #extern int rl_key_sequence_length;

  # Display variables.
  #
  # If non-zero, readline will erase the entire line, including any prompt,
  # if the only thing typed on an otherwise-blank line is something bound to
  # rl_newline.
  #
  #extern int rl_erase_empty_line;

  # If non-zero, the application has already printed the prompt (rl_prompt)
  # before calling readline, so readline should not output it the first time
  # redisplay is done.
  #
  #extern int rl_already_prompted;

  # A non-zero value means to read only this many characters rather than
  # up to a character bound to accept-line.
  #
  #extern int rl_num_chars_to_read;

  # The text of a currently-executing keyboard macro.
  #
  #extern char *rl_executing_macro;

  # Variables to control readline signal handling.
  #
  # If non-zero, readline will install its own signal handlers for
  # SIGINT, SIGTERM, SIGQUIT, SIGALRM, SIGTSTP, SIGTTIN, and SIGTTOU.
  #
  #extern int rl_catch_signals;

  # If non-zero, readline will install a signal handler for SIGWINCH
  # that also attempts to call any calling application's SIGWINCH signal
  # handler.  Note that the terminal is not cleaned up before the
  # application's signal handler is called; use rl_cleanup_after_signal()
  # to do that.
  #
  #extern int rl_catch_sigwinch;

  # If non-zero, the readline SIGWINCH handler will modify LINES and
  # COLUMNS in the environment.
  #
  #extern int rl_change_environment;

  # Completion variables.
  #
  # Pointer to the generator function for completion_matches ().
  # NULL means to use rl_filename_completion_function (), the default
  # filename completer.
  #
  #extern rl_compentry_func_t *rl_completion_entry_function;

  # Optional generator for menu completion.  Default is
  # rl_completion_entry_function (rl_filename_completion_function).
  #
  # extern rl_compentry_func_t *rl_menu_completion_entry_function;

  # If rl_ignore_some_completions_function is non-NULL it is the address
  # of a function to call after all of the possible matches have been
  # generated, but before the actual completion is done to the input line.
  # The function is called with one argument; a NULL terminated array
  # of (char *).  If your function removes any of the elements, they
  # must be free()'ed.
  #
  #extern rl_compignore_func_t *rl_ignore_some_completions_function;

  # Pointer to alternative function to create matches.
  # Function is called with TEXT, START, and END.
  # START and END are indices in RL_LINE_BUFFER saying what the boundaries
  # of TEXT are.
  # If this function exists and returns NULL then call the value of
  # rl_completion_entry_function to try to match, otherwise use the
  # array of strings returned.
  #
  #extern rl_completion_func_t *rl_attempted_completion_function;

  # The basic list of characters that signal a break between words for the
  # completer routine.  The initial contents of this variable is what
  # breaks words in the shell, i.e. "n\"\\'`@$>".
  #
  #extern const char *rl_basic_word_break_characters;

  # The list of characters that signal a break between words for
  # rl_complete_internal.  The default list is the contents of
  # rl_basic_word_break_characters.
  #
  #extern char *rl_completer_word_break_characters;

  # Hook function to allow an application to set the completion word
  # break characters before readline breaks up the line.  Allows
  # position-dependent word break characters.
  #
  #extern rl_cpvfunc_t *rl_completion_word_break_hook;

  # List of characters which can be used to quote a substring of the line.
  # Completion occurs on the entire substring, and within the substring   
  # rl_completer_word_break_characters are treated as any other character,
  # unless they also appear within this list.
  #
  #extern const char *rl_completer_quote_characters;

  # List of quote characters which cause a word break.
  #
  #extern const char *rl_basic_quote_characters;

  # List of characters that need to be quoted in filenames by the completer.
  #
  #extern const char *rl_filename_quote_characters;

  # List of characters that are word break characters, but should be left
  # in TEXT when it is passed to the completion function.  The shell uses
  # this to help determine what kind of completing to do.
  #
  #extern const char *rl_special_prefixes;

  # If non-zero, then this is the address of a function to call when
  # completing on a directory name.  The function is called with
  # the address of a string (the current directory name) as an arg.  It
  # changes what is displayed when the possible completions are printed
  # or inserted.  The directory completion hook should perform
  # any necessary dequoting.  This function should return 1 if it modifies
  # the directory name pointer passed as an argument.  If the directory
  # completion hook returns 0, it should not modify the directory name
  # pointer passed as an argument.
  #
  #extern rl_icppfunc_t *rl_directory_completion_hook;

  # If non-zero, this is the address of a function to call when completing
  # a directory name.  This function takes the address of the directory name
  # to be modified as an argument.  Unlike rl_directory_completion_hook, it
  # only modifies the directory name used in opendir(2), not what is displayed
  # when the possible completions are printed or inserted.  If set, it takes
  # precedence over rl_directory_completion_hook.  The directory rewrite
  # hook should perform any necessary dequoting.  This function has the same
  # return value properties as the directory_completion_hook.
  #
  # I'm not happy with how this works yet, so it's undocumented.  I'm trying
  # it in bash to see how well it goes.
  #
  #extern rl_icppfunc_t *rl_directory_rewrite_hook;

  # If non-zero, this is the address of a function for the completer to call
  # before deciding which character to append to a completed name.  It should
  # modify the directory name passed as an argument if appropriate, and return
  # non-zero if it modifies the name.  This should not worry about dequoting
  # the filename; that has already happened by the time it gets here. */
  #
  #extern rl_icppfunc_t *rl_filename_stat_hook;

  # If non-zero, this is the address of a function to call when reading
  # directory entries from the filesystem for completion and comparing
  # them to the partial word to be completed.  The function should
  # either return its first argument (if no conversion takes place) or
  # newly-allocated memory.  This can, for instance, convert filenames
  # between character sets for comparison against what's typed at the
  # keyboard.  The returned value is what is added to the list of
  # matches.  The second argument is the length of the filename to be
  # converted.
  #
  #extern rl_dequote_func_t *rl_filename_rewrite_hook;

  # If non-zero, then this is the address of a function to call when
  # completing a word would normally display the list of possible matches.
  # This function is called instead of actually doing the display.
  # It takes three arguments: (char **matches, int num_matches, int max_length)
  # where MATCHES is the array of strings that matched, NUM_MATCHES is the
  # number of strings in that array, and MAX_LENGTH is the length of the
  # longest string in that array.
  #
  #extern rl_compdisp_func_t *rl_completion_display_matches_hook;

  # Non-zero means that the results of the matches are to be treated
  # as filenames.  This is ALWAYS zero on entry, and can only be changed
  # within a completion entry finder function.
  #
  #extern int rl_filename_completion_desired;

  # Non-zero means that the results of the matches are to be quoted using
  # double quotes (or an application-specific quoting mechanism) if the
  # filename contains any characters in rl_word_break_chars.  This is
  # ALWAYS non-zero on entry, and can only be changed within a completion
  # entry finder function.
  #
  #extern int rl_filename_quoting_desired;

  # Set to a function to quote a filename in an application-specific fashion.
  # Called with the text to quote, the type of match found (single or multiple)
  # and a pointer to the quoting character to be used, which the function can
  # reset if desired.
  #
  #extern rl_quote_func_t *rl_filename_quoting_function;

  # Function to call to remove quoting characters from a filename.  Called
  # before completion is attempted, so the embedded quotes do not interfere
  # with matching names in the file system.
  #
  #extern rl_dequote_func_t *rl_filename_dequoting_function;

  # Function to call to decide whether or not a word break character is
  # quoted.  If a character is quoted, it does not break words for the
  # completer.
  #
  #extern rl_linebuf_func_t *rl_char_is_quoted_p;

  # Non-zero means to suppress normal filename completion after the
  # user-specified completion function has been called.
  #
  #extern int rl_attempted_completion_over;

  # Set to a character describing the type of completion being attempted by
  # rl_complete_internal; available for use by application completion
  # functions.
  #
  #extern int rl_completion_type;

  # Set to the last key used to invoke one of the completion functions.
  #
  #extern int rl_completion_invoking_key;

  # Up to this many items will be displayed in response to a
  # possible-completions call.  After that, we ask the user if she
  # is sure she wants to see them all.  The default value is 100.
  #
  #extern int rl_completion_query_items;

  # Character appended to completed words when at the end of the line.  The
  # default is a space.  Nothing is added if this is '\0'.
  #
  #extern int rl_completion_append_character;

  # If set to non-zero by an application completion function,
  # rl_completion_append_character will not be appended.
  #
  #extern int rl_completion_suppress_append;

  # Set to any quote character readline thinks it finds before any application
  # completion function is called.
  #
  #extern int rl_completion_quote_character;

  # Set to a non-zero value if readline found quoting anywhere in the word to
  # be completed; set before any application completion function is called.
  #
  #extern int rl_completion_found_quote;

  # If non-zero, the completion functions don't append any closing quote.
  # This is set to 0 by rl_complete_internal and may be changed by an
  # application-specific completion function.
  #
  #extern int rl_completion_suppress_quote;

  # If non-zero, readline will sort the completion matches.  On by default.
  #
  #extern int rl_sort_completion_matches;

  # If non-zero, a slash will be appended to completed filenames that are
  # symbolic links to directory names, subject to the value of the
  # mark-directories variable (which is user-settable).  This exists so
  # that application completion functions can override the user's preference
  # (set via the mark-symlinked-directories variable) if appropriate.
  # It's set to the value of _rl_complete_mark_symlink_dirs in
  # rl_complete_internal before any application-specific completion
  # function is called, so without that function doing anything, the user's
  # preferences are honored.
  #
  #extern int rl_completion_mark_symlink_dirs;

  # If non-zero, then disallow duplicates in the matches.
  #
  #extern int rl_ignore_completion_duplicates;

  # If this is non-zero, completion is (temporarily) inhibited, and the
  # completion character will be inserted as any other.
  #
  #extern int rl_inhibit_completion;

  # Input error; can be returned by (*rl_getc_function) if readline is reading
  # a top-level command (RL_ISSTATE (RL_STATE_READCMD)).

  constant READERR = -2;

  # Definitions available for use by readline clients.
  #
  constant RL_PROMPT_START_IGNORE = '\001';
  constant RL_PROMPT_END_IGNORE   = '\002';

  # Possible values for do_replace argument to rl_filename_quoting_function,
  # called by rl_complete_internal.
  #
  constant NO_MATCH     = 0;
  constant SINGLE_MATCH = 1;
  constant MULT_MATCH   = 2;

  # Possible state values for rl_readline_state
  #
  constant RL_STATE_NONE	 = 0x0000000; # no state; before first call 

  constant RL_STATE_INITIALIZING = 0x0000001; # initializing
  constant RL_STATE_INITIALIZED	 = 0x0000002; # initialization done
  constant RL_STATE_TERMPREPPED	 = 0x0000004; # terminal is prepped
  constant RL_STATE_READCMD	 = 0x0000008; # reading a command key
  constant RL_STATE_METANEXT	 = 0x0000010; # reading input after ESC
  constant RL_STATE_DISPATCHING	 = 0x0000020; # dispatching to a command
  constant RL_STATE_MOREINPUT	 = 0x0000040; # reading more input in a command function
  constant RL_STATE_ISEARCH	 = 0x0000080; # doing incremental search
  constant RL_STATE_NSEARCH	 = 0x0000100; # doing non-inc search
  constant RL_STATE_SEARCH	 = 0x0000200; # doing a history search
  constant RL_STATE_NUMERICARG	 = 0x0000400; # reading numeric argument
  constant RL_STATE_MACROINPUT	 = 0x0000800; # getting input from a macro
  constant RL_STATE_MACRODEF	 = 0x0001000; # defining keyboard macro
  constant RL_STATE_OVERWRITE	 = 0x0002000; # overwrite mode
  constant RL_STATE_COMPLETING	 = 0x0004000; # doing completion
  constant RL_STATE_SIGHANDLER	 = 0x0008000; # in readline sighandler
  constant RL_STATE_UNDOING	 = 0x0010000; # doing an undo
  constant RL_STATE_INPUTPENDING = 0x0020000; # rl_execute_next called 
  constant RL_STATE_TTYCSAVED	 = 0x0040000; # tty special chars saved
  constant RL_STATE_CALLBACK	 = 0x0080000; # using the callback interface
  constant RL_STATE_VIMOTION	 = 0x0100000; # reading vi motion arg
  constant RL_STATE_MULTIKEY	 = 0x0200000; # reading multiple-key command
  constant RL_STATE_VICMDONCE	 = 0x0400000; # entered vi command mode at least once
  constant RL_STATE_REDISPLAYING = 0x0800000; # updating terminal display

  constant RL_STATE_DONE	 = 0x1000000; # done; accepted line

  #define RL_SETSTATE(x)	(rl_readline_state |= (x))
  #define#RL_UNSETSTATE(x)	(rl_readline_state &= ~(x))
  #define RL_ISSTATE(x)		(rl_readline_state & (x))

  my class readline_state is repr('CStruct') {
    # line state
    has int $.point;  # int point;
    has int $.end;    # int end;
    has int $.mark;   # int mark;
    has Str $.buffer; # char *buffer;
    has int $.buflen; # int buflen;
    has Pointer $.ul; # UNDO_LIST *ul;
    has Str $.prompt; # char *prompt;

    # global state
    has int $.rlstate; # int rlstate;
    has int $.done; # int done;
    has Pointer $.keymap; # Keymap kmap;

    # input state
    has Pointer $.lastfunc; # rl_command_func_t *lastfunc;
    has int $.insmode;      # int insmode;
    has int $.edmode;       # int edmode;
    has int $.kseqlen;      # int kseqlen;
    has Pointer $.inf;      # FILE *inf;
    has Pointer $.outf;     # FILE *outf;
    has int $.pendingin;    # int pendingin;
    has Str $.macro;        # char *macro;

    # signal state
    has int $.catchsigs;     # int catchsigs;
    has int $.catchsigwinch; # int catchsigwinch;

    # search state

    # completion state

    # options state

    # reserved for future expansion, so the struct size doesn't change
    has int $.reserved; # char reserved[64]; # XXX
  }

  sub rl_save_state( readline_state )
    returns int32
    is native( LIBREADLINE ) { * }
  method save-state( readline_state $state )
    returns int32 {
    rl_save_state( $state ) }

  sub rl_restore_state( readline_state )
    returns int32
    is native( LIBREADLINE ) { * }
  method restore-state( readline_state $state )
    returns int32 {
    rl_restore_state( $state ) }

  ############################################################################
  #
  # rltypedefs.h -- Type declarations for readline functions. */
  #
  # Typedefs for the completion system
  #
  #typedef char *rl_compentry_func_t (const char *, int);
  #typedef char **rl_completion_func_t (const char *, int, int);

  #typedef char *rl_quote_func_t (char *, int, char *);
  #typedef char *rl_dequote_func_t (char *, int);

  #typedef int rl_compignore_func_t (char **);

  #typedef void rl_compdisp_func_t (char **, int, int);

  # Type for input and pre-read hook functions like rl_event_hook
  #
  #typedef int rl_hook_func_t (void);

  # Input function type
  #
  #typedef int rl_getc_func_t (FILE *);

  # Generic function that takes a character buffer (which could be the readline
  # line buffer) and an index into it (which could be rl_point) and returns
  # an int.
  #
  #typedef int rl_linebuf_func_t (char *, int);

  # `Generic' function pointer typedefs
  #
  #typedef int rl_icppfunc_t (char **);

  #typedef void rl_voidfunc_t (void);
  #typedef void rl_vintfunc_t (int);
  #typedef void rl_vcpfunc_t (char *);
  #
  #typedef char *rl_cpvfunc_t (void);

  #############################################################################
  #
  # tilde.h: Externally available variables and function in libtilde.a.
  #
  #typedef char *tilde_hook_func_t (char *);

  # If non-null, this contains the address of a function that the application
  # wants called before trying the standard tilde expansions.  The function
  # is called with the text sans tilde, and returns a malloc()'ed string
  # which is the expansion, or a NULL pointer if the expansion fails.
  #
  #extern tilde_hook_func_t *tilde_expansion_preexpansion_hook;

  # If non-null, this contains the address of a function to call if the
  # standard meaning for expanding a tilde fails.  The function is called
  # with the text (sans tilde, as in "foo"), and returns a malloc()'ed string
  # which is the expansion, or a NULL pointer if there is no expansion.
  #
  #extern tilde_hook_func_t *tilde_expansion_failure_hook;

  # When non-null, this is a NULL terminated array of strings which
  # are duplicates for a tilde prefix.  Bash uses this to expand
  # `=~' and `:~'.
  #
  #extern char **tilde_additional_prefixes;

  # When non-null, this is a NULL terminated array of strings which match
  # the end of a username, instead of just "/".  Bash sets this to
  # `:' and `=~'.
  #
  #extern char **tilde_additional_suffixes;

  # Return a new string which is the result of tilde expanding STRING.
  #
  sub tilde_expand( Str )
    returns Str
    is native( LIBREADLINE ) { * }
  method tilde-expand( Str $filename )
    returns Str {
    tilde_expand( $filename ) }

  sub tilde_expand_word( Str )
    returns Str
    is native( LIBREADLINE ) { * }
  method tilde-expand-word( Str $filename )
    returns Str {
    tilde_expand_word( $filename ) }

  sub tilde_find_word( Str, int32, Pointer[int32] ) returns Str
    is native( LIBREADLINE ) { * }
  method tilde-find-word( Str $str, int32 $offset, Pointer[int32] $p-offset )
    returns Str {
      tilde_find_word( $str, $offset, $p-offset ) }
}