about summary refs log tree commit diff stats
path: root/src/LYEditmap.c
blob: dec2ac99ec428dc7f3032bbb63417c12a40b4da4 (plain) (blame)
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
/*
 * $LynxId: LYEditmap.c,v 1.76 2018/12/27 10:33:52 tom Exp $
 *
 * LYEditMap.c
 * Keybindings for line and form editing.
 */

#include <HTUtils.h>
#include <HTAlert.h>
#include <HTFile.h>
#include <LYGlobalDefs.h>
#include <LYCharUtils.h>
#include <LYStrings.h>
#include <LYKeymap.h>		/* KEYMAP_SIZE, LKC_*, LYK_* - kw */
#include <LYLeaks.h>

#define PUTS(buf)    (*target->isa->put_string)(target, buf)

/* * * * * LynxEditactionCodes * * * * */
#ifdef USE_ALT_BINDINGS

/* Last valid index for the (lynxkeycode+modifier -> lynxeditactioncode)
 * tables.  Currently all three tables are the same.  - kw
 */
#define LAST_MOD1_LKC	0x111
#define LAST_MOD2_LKC	0x111
#define LAST_MOD3_LKC	0x111

/*  Get (lynxkeycode+modifier -> lynxeditactioncode) mapping, intermediate.
 */
#define LKC_TO_LEC_M1(c) ((c)>LAST_MOD1_LKC? (int)LYE_UNMOD: Mod1Binding[c])
#define LKC_TO_LEC_M2(c) ((c)>LAST_MOD2_LKC? (int)LYE_UNMOD: Mod2Binding[c])
#define LKC_TO_LEC_M3(c) ((c)>LAST_MOD3_LKC? (int)LYE_UNMOD: Mod3Binding[c])

#endif /* USE_ALT_BINDINGS */

int current_lineedit = 0;	/* Index into LYLineEditors[]   */

int escape_bound = 0;		/* User wanted Escape to perform actions?  */

/*
 * See LYStrings.h for the LYE definitions.
 */
/* *INDENT-OFF* */
struct emap {
    const char *name;
    const int   code;
    const char *descr;
};

#define SEPARATOR {"", -1, ""}

static struct emap ekmap[] = {
  {"NOP",	LYE_NOP,	"Do Nothing"},
  {"CHAR",	LYE_CHAR,	"Insert printable char"},
  SEPARATOR,
  {"ENTER",	LYE_ENTER,	"Input complete, return char"},
  {"TAB",	LYE_TAB,	"Input complete, return TAB"},
  {"STOP",	LYE_STOP,	"Input deactivated"},
  {"ABORT",	LYE_ABORT,	"Input cancelled"},
  SEPARATOR,
  {"PASS",	LYE_FORM_PASS,  "Fields only: input complete"},
  SEPARATOR,
  {"DELBL",	LYE_DELBL,	"Delete back to BOL"},
  {"DELEL",	LYE_DELEL,	"Delete thru EOL"},
  {"DELN",	LYE_DELN,	"Delete next/curr char"},
  {"DELP",	LYE_DELP,	"Delete prev      char"},
  {"DELNW",	LYE_DELNW,	"Delete next word"},
  {"DELPW",	LYE_DELPW,	"Delete prev word"},
  SEPARATOR,

  {"ERASE",	LYE_ERASE,	"Erase the line"},
  SEPARATOR,
  {"BOL",	LYE_BOL,	"Go to begin of line"},
  {"EOL",	LYE_EOL,	"Go to end   of line"},
  {"FORW",	LYE_FORW,	"Cursor forwards"},
  {"FORW_RL",	LYE_FORW_RL,	"Cursor forwards or right link"},
  {"BACK",	LYE_BACK,	"Cursor backwards"},
  {"BACK_LL",	LYE_BACK_LL,	"Cursor backwards or left link"},
  {"FORWW",	LYE_FORWW,	"Word forward"},
  {"BACKW",	LYE_BACKW,	"Word back"},
  SEPARATOR,
  {"LOWER",	LYE_LOWER,	"Lower case the line"},
  {"UPPER",	LYE_UPPER,	"Upper case the line"},
  SEPARATOR,
  {"LKCMD",	LYE_LKCMD,	"Invoke command prompt"},
  {"SWMAP",	LYE_SWMAP,	"Switch input keymap"},
  SEPARATOR,
  {"C1CHAR",	LYE_C1CHAR,	"Insert C1 char if printable"},
  {"SETM1",	LYE_SETM1,	"Set modifier 1 flag"},
  {"SETM2",	LYE_SETM2,	"Set modifier 2 flag"},
  {"UNMOD",	LYE_UNMOD,	"Fall back to no-modifier command"},
  SEPARATOR,
  {"TPOS",	LYE_TPOS,	"Transpose characters"},
  {"SETMARK",	LYE_SETMARK,	"emacs-like set-mark-command"},
  {"XPMARK",	LYE_XPMARK,	"emacs-like exchange-point-and-mark"},
  {"KILLREG",	LYE_KILLREG,	"emacs-like kill-region"},
  {"YANK",	LYE_YANK,	"emacs-like yank"},
#ifdef CAN_CUT_AND_PASTE
  SEPARATOR,
  {"PASTE",	LYE_PASTE,	"ClipBoard to Lynx"},
#endif
  SEPARATOR,
  {"AIX",	LYE_AIX,	"Hex 97"},
  {0,           -1,             0},
};
#undef SEPARATOR
/* *INDENT-ON* */

static LYEditCode DefaultEditBinding[KEYMAP_SIZE];

#ifdef USE_ALT_BINDINGS
static LYEditCode BetterEditBinding[KEYMAP_SIZE];
static LYEditCode BashlikeEditBinding[KEYMAP_SIZE];

/*
 * If a modifier bit is set in a lynxkeycode, it is first looked up here.
 *
 * Currently this table isn't specific to the current_lineedit value, it is
 * shared by all alternative "Bindings" to save space.  However, if the
 * modifier flag is set only by a LYE_SETMn lynxeditaction, this table can have
 * effect only for those Bindings that map a lynxkeycode to LYE_SETMn.  ( This
 * doesn't apply if the modifier is already being set in LYgetch().  ) - kw
 */
static LYEditCode Mod1Binding[KEYMAP_SIZE];

/*  Two more tables here, but currently they are all the same.
    In other words, we are cheating to save space, until there
    is a need for different tables. - kw */
static LYEditCode *Mod2Binding = Mod1Binding;
static LYEditCode *Mod3Binding = Mod1Binding;

static const LYEditInit initMod1Binding[] =
{
    {CTL('A'), LYE_BOL},
    {CTL('B'), LYE_BACKW},
    {CTL('C'), LYE_UNMOD},
    {CTL('D'), LYK_NEXT_LINK | LYE_FORM_LAC},
    {CTL('E'), LYK_EDITTEXTAREA | LYE_FORM_LAC},
    {CTL('F'), LYE_FORWW},
    {CTL('G'), LYE_ABORT},
    {CTL('H'), LYE_DELPW},
    {CTL('I'), LYE_UNMOD},
    {CTL('J'), LYE_ENTER},
    {CTL('K'), LYK_LPOS_NEXT_LINK | LYE_FORM_LAC},
    {CTL('L'), LYE_FORM_PASS},
    {CTL('M'), LYE_ENTER},
    {CTL('N'), LYE_FORWW},
    {CTL('O'), LYE_UNMOD},
    {CTL('P'), LYE_BACKW},
    {CTL('R'), LYE_BACKW},
    {CTL('U'), LYE_FORM_PASS},
    {CTL('W'), LYE_KILLREG},
    {CTL('X'), LYE_XPMARK},
    {CTL('Y'), LYE_UNMOD},
    {CTL('Z'), LYE_FORM_PASS},
    {CTL('\\'), LYE_FORM_PASS},
    {CTL(']'), LYE_FORM_PASS},
    {CTL('^'), LYE_UNMOD},
    {' ', LYE_UNMOD},
    {'!', LYE_UNMOD},
    {'"', LYE_UNMOD},
    {'#', LYE_UNMOD},
    {'$', LYE_UNMOD},
    {'%', LYE_UNMOD},
    {'&', LYE_UNMOD},
    {'\'', LYE_UNMOD},
    {'(', LYE_UNMOD},
    {')', LYE_UNMOD},
    {'*', LYE_UNMOD},
    {'+', LYE_UNMOD},
    {',', LYE_UNMOD},
    {'-', LYE_UNMOD},
    {'.', LYE_UNMOD},
    {'/', LYE_FORM_PASS},
    {'0', LYE_UNMOD},
    {'1', LYE_UNMOD},
    {'2', LYE_UNMOD},
    {'3', LYE_UNMOD},
    {'4', LYE_UNMOD},
    {'5', LYE_UNMOD},
    {'6', LYE_UNMOD},
    {'7', LYE_UNMOD},
    {'8', LYE_UNMOD},
    {'9', LYE_UNMOD},
    {':', LYE_UNMOD},
    {';', LYE_UNMOD},
    {'<', LYK_HOME | LYE_FORM_LAC},
    {'=', LYE_UNMOD},
    {'>', LYK_END | LYE_FORM_LAC},
    {'?', LYE_UNMOD},
    {'@', LYE_C1CHAR},
    {'A', LYE_C1CHAR},
    {'B', LYE_C1CHAR},
    {'C', LYE_C1CHAR},
    {'D', LYE_C1CHAR},
    {'E', LYE_C1CHAR},
    {'F', LYE_C1CHAR},
    {'G', LYE_C1CHAR},
    {'H', LYE_C1CHAR},
    {'I', LYE_C1CHAR},
    {'J', LYE_C1CHAR},
    {'K', LYE_C1CHAR},
    {'L', LYE_C1CHAR},
    {'M', LYE_C1CHAR},
    {'N', LYE_C1CHAR},
    {'O', LYE_C1CHAR},
    {'P', LYE_C1CHAR},
    {'Q', LYE_C1CHAR},
    {'R', LYE_C1CHAR},
    {'S', LYE_C1CHAR},
    {'T', LYE_C1CHAR},
    {'U', LYE_C1CHAR},
    {'V', LYE_C1CHAR},
    {'W', LYE_C1CHAR},
    {'X', LYE_C1CHAR},
    {'Y', LYE_C1CHAR},
    {'Z', LYE_C1CHAR},
    {'[', LYE_C1CHAR},
    {'\\', LYE_C1CHAR},
    {']', LYE_C1CHAR},
    {'^', LYE_C1CHAR},
    {'_', LYE_C1CHAR},
    {'`', LYE_UNMOD},
    {'a', LYE_BOL},
    {'b', LYE_BACKW},
    {'c', LYE_UNMOD},
    {'d', LYE_DELNW},
    {'e', LYK_EDITTEXTAREA | LYE_FORM_LAC},
    {'f', LYE_FORWW},
    {'g', LYK_GROWTEXTAREA | LYE_FORM_LAC},
    {'h', LYE_CHAR},
    {'i', LYK_INSERTFILE | LYE_FORM_LAC},
    {'j', LYE_CHAR},
    {'k', LYE_ERASE},
    {'l', LYE_LOWER},
    {'m', LYE_CHAR},
    {'n', LYE_FORM_PASS},
    {'o', LYE_UNMOD},
    {'p', LYE_CHAR},
    {'u', LYE_UPPER},
    {'z', LYE_UNMOD},
    {'{', LYE_UNMOD},
    {'|', LYE_UNMOD},
    {'}', LYE_UNMOD},
    {'~', LYE_UNMOD},
    {DEL_KEY, LYE_DELPW},
    {160, LYE_UNMOD},
    {161, LYE_UNMOD},
    {162, LYE_UNMOD},
    {163, LYE_UNMOD},
    {164, LYE_UNMOD},
    {165, LYE_UNMOD},
    {166, LYE_UNMOD},
    {167, LYE_UNMOD},
    {168, LYE_UNMOD},
    {169, LYE_UNMOD},
    {170, LYE_UNMOD},
    {171, LYE_UNMOD},
    {172, LYE_UNMOD},
    {173, LYE_UNMOD},
    {174, LYE_UNMOD},
    {175, LYE_UNMOD},
    {176, LYE_UNMOD},
    {177, LYE_UNMOD},
    {178, LYE_UNMOD},
    {179, LYE_UNMOD},
    {180, LYE_UNMOD},
    {181, LYE_UNMOD},
    {182, LYE_UNMOD},
    {183, LYE_UNMOD},
    {184, LYE_UNMOD},
    {185, LYE_UNMOD},
    {186, LYE_UNMOD},
    {187, LYE_UNMOD},
    {188, LYE_UNMOD},
    {189, LYE_UNMOD},
    {190, LYE_UNMOD},
    {191, LYE_UNMOD},
    {192, LYE_UNMOD},
    {193, LYE_UNMOD},
    {194, LYE_UNMOD},
    {195, LYE_UNMOD},
    {196, LYE_UNMOD},
    {197, LYE_UNMOD},
    {198, LYE_UNMOD},
    {199, LYE_UNMOD},
    {200, LYE_UNMOD},
    {201, LYE_UNMOD},
    {202, LYE_UNMOD},
    {203, LYE_UNMOD},
    {204, LYE_UNMOD},
    {205, LYE_UNMOD},
    {206, LYE_UNMOD},
    {207, LYE_UNMOD},
    {208, LYE_UNMOD},
    {209, LYE_UNMOD},
    {210, LYE_UNMOD},
    {211, LYE_UNMOD},
    {212, LYE_UNMOD},
    {213, LYE_UNMOD},
    {214, LYE_UNMOD},
    {215, LYE_UNMOD},
    {216, LYE_UNMOD},
    {217, LYE_UNMOD},
    {218, LYE_UNMOD},
    {219, LYE_UNMOD},
    {220, LYE_UNMOD},
    {221, LYE_UNMOD},
    {222, LYE_UNMOD},
    {223, LYE_UNMOD},
    {224, LYE_UNMOD},
    {225, LYE_UNMOD},
    {226, LYE_UNMOD},
    {227, LYE_UNMOD},
    {228, LYE_UNMOD},
    {229, LYE_UNMOD},
    {230, LYE_UNMOD},
    {231, LYE_UNMOD},
    {232, LYE_UNMOD},
    {233, LYE_UNMOD},
    {234, LYE_UNMOD},
    {235, LYE_UNMOD},
    {236, LYE_UNMOD},
    {237, LYE_UNMOD},
    {238, LYE_UNMOD},
    {239, LYE_UNMOD},
    {240, LYE_UNMOD},
    {241, LYE_UNMOD},
    {242, LYE_UNMOD},
    {243, LYE_UNMOD},
    {244, LYE_UNMOD},
    {245, LYE_UNMOD},
    {246, LYE_UNMOD},
    {247, LYE_UNMOD},
    {248, LYE_UNMOD},
    {249, LYE_UNMOD},
    {250, LYE_UNMOD},
    {251, LYE_UNMOD},
    {252, LYE_UNMOD},
    {253, LYE_UNMOD},
    {254, LYE_UNMOD},
    {255, LYE_UNMOD},
    {UPARROW_KEY, LYE_UNMOD},
    {DNARROW_KEY, LYE_UNMOD},
    {RTARROW_KEY, LYE_UNMOD},
    {LTARROW_KEY, LYE_UNMOD},
    {PGDOWN_KEY, LYE_UNMOD},
    {PGUP_KEY, LYE_UNMOD},
    {HOME_KEY, LYE_FORM_PASS},
    {END_KEY, LYE_FORM_PASS},
    {F1_KEY, LYK_DWIMHELP | LYE_FORM_LAC},
    {DO_KEY, LYE_UNMOD},
#if (defined(_WINDOWS) || defined(__DJGPP__))
    {FIND_KEY, LYE_UNMOD},
    {SELECT_KEY, LYE_UNMOD},
#else
    {FIND_KEY, LYK_WHEREIS | LYE_FORM_LAC},
    {SELECT_KEY, LYK_NEXT | LYE_FORM_LAC},
#endif
    {INSERT_KEY, LYE_UNMOD},
    {DO_NOTHING, LYE_UNMOD},
    {BACKTAB_KEY, LYE_UNMOD},
#if (defined(_WINDOWS) || defined(__DJGPP__)) && defined(USE_SLANG) && !defined(DJGPP_KEYHANDLER)
    {272, LYE_DELPW},
#else
    {272, LYE_UNMOD},
#endif
    {273, LYE_UNMOD},
    {-1, LYE_UNKNOWN}
};

LYEditConfig LYModifierBindings[] =
{
    {"Modifier Binding", initMod1Binding, Mod1Binding},
};

#endif /* USE_ALT_BINDINGS */

static const LYEditInit initDefaultEditor[] =
{
    {CTL('A'), LYE_BOL},
    {CTL('B'), LYE_DELPW},
    {CTL('C'), LYE_ABORT},
    {CTL('D'), LYE_DELN},
    {CTL('E'), LYE_EOL},
    {CTL('F'), LYE_DELNW},
    {CTL('G'), LYE_ABORT},
    {CTL('H'), LYE_DELP},
    {CTL('I'), LYE_TAB},
    {CTL('J'), LYE_ENTER},
    {CTL('K'), LYE_LOWER},
    {CTL('M'), LYE_ENTER},
    {CTL('N'), LYE_FORWW},
    {CTL('O'), LYE_ABORT},
    {CTL('P'), LYE_BACKW},
    {CTL('R'), LYE_DELN},
    {CTL('T'), LYE_UPPER},
    {CTL('U'), LYE_ERASE},
    {CTL('V'), LYE_LKCMD},
#ifdef CAN_CUT_AND_PASTE
    {CTL('W'), LYE_PASTE},
#endif
    {CTL('X'), LYE_SETM1},
    {CTL('^'), LYE_SWMAP},
    {CTL('_'), LYE_DELEL},
    {' ', LYE_CHAR},
    {'!', LYE_CHAR},
    {'"', LYE_CHAR},
    {'#', LYE_CHAR},
    {'$', LYE_CHAR},
    {'%', LYE_CHAR},
    {'&', LYE_CHAR},
    {'\'', LYE_CHAR},
    {'(', LYE_CHAR},
    {')', LYE_CHAR},
    {'*', LYE_CHAR},
    {'+', LYE_CHAR},
    {',', LYE_CHAR},
    {'-', LYE_CHAR},
    {'.', LYE_CHAR},
    {'/', LYE_CHAR},
    {'0', LYE_CHAR},
    {'1', LYE_CHAR},
    {'2', LYE_CHAR},
    {'3', LYE_CHAR},
    {'4', LYE_CHAR},
    {'5', LYE_CHAR},
    {'6', LYE_CHAR},
    {'7', LYE_CHAR},
    {'8', LYE_CHAR},
    {'9', LYE_CHAR},
    {':', LYE_CHAR},
    {';', LYE_CHAR},
    {'<', LYE_CHAR},
    {'=', LYE_CHAR},
    {'>', LYE_CHAR},
    {'?', LYE_CHAR},
    {'@', LYE_CHAR},
    {'A', LYE_CHAR},
    {'B', LYE_CHAR},
    {'C', LYE_CHAR},
    {'D', LYE_CHAR},
    {'E', LYE_CHAR},
    {'F', LYE_CHAR},
    {'G', LYE_CHAR},
    {'H', LYE_CHAR},
    {'I', LYE_CHAR},
    {'J', LYE_CHAR},
    {'K', LYE_CHAR},
    {'L', LYE_CHAR},
    {'M', LYE_CHAR},
    {'N', LYE_CHAR},
    {'O', LYE_CHAR},
    {'P', LYE_CHAR},
    {'Q', LYE_CHAR},
    {'R', LYE_CHAR},
    {'S', LYE_CHAR},
    {'T', LYE_CHAR},
    {'U', LYE_CHAR},
    {'V', LYE_CHAR},
    {'W', LYE_CHAR},
    {'X', LYE_CHAR},
    {'Y', LYE_CHAR},
    {'Z', LYE_CHAR},
    {'[', LYE_CHAR},
    {'\\', LYE_CHAR},
    {']', LYE_CHAR},
    {'^', LYE_CHAR},
    {'_', LYE_CHAR},
    {'`', LYE_CHAR},
    {'a', LYE_CHAR},
    {'b', LYE_CHAR},
    {'c', LYE_CHAR},
    {'d', LYE_CHAR},
    {'e', LYE_CHAR},
    {'f', LYE_CHAR},
    {'g', LYE_CHAR},
    {'h', LYE_CHAR},
    {'i', LYE_CHAR},
    {'j', LYE_CHAR},
    {'k', LYE_CHAR},
    {'l', LYE_CHAR},
    {'m', LYE_CHAR},
    {'n', LYE_CHAR},
    {'o', LYE_CHAR},
    {'p', LYE_CHAR},
    {'q', LYE_CHAR},
    {'r', LYE_CHAR},
    {'s', LYE_CHAR},
    {'t', LYE_CHAR},
    {'u', LYE_CHAR},
    {'v', LYE_CHAR},
    {'w', LYE_CHAR},
    {'x', LYE_CHAR},
    {'y', LYE_CHAR},
    {'z', LYE_CHAR},
    {'{', LYE_CHAR},
    {'|', LYE_CHAR},
    {'}', LYE_CHAR},
    {'~', LYE_CHAR},
    {DEL_KEY, LYE_DELP},
    {128, LYE_CHAR},
    {129, LYE_CHAR},
    {130, LYE_CHAR},
    {131, LYE_CHAR},
    {132, LYE_CHAR},
    {133, LYE_CHAR},
    {134, LYE_CHAR},
    {135, LYE_CHAR},
    {136, LYE_CHAR},
    {137, LYE_CHAR},
    {138, LYE_CHAR},
    {139, LYE_CHAR},
    {140, LYE_CHAR},
    {141, LYE_CHAR},
#ifdef CJK_EX			/* 1997/11/03 (Mon) 20:30:54 */
    {142, LYE_CHAR},
#else
    {142, LYE_AIX},
#endif
    {143, LYE_CHAR},
    {144, LYE_CHAR},
    {145, LYE_CHAR},
    {146, LYE_CHAR},
    {147, LYE_CHAR},
    {148, LYE_CHAR},
    {149, LYE_CHAR},
    {150, LYE_CHAR},
    {151, LYE_CHAR},
    {152, LYE_CHAR},
    {153, LYE_CHAR},
    {154, LYE_CHAR},
    {155, LYE_CHAR},
    {156, LYE_CHAR},
    {157, LYE_CHAR},
    {158, LYE_CHAR},
    {159, LYE_CHAR},
    {160, LYE_CHAR},
    {161, LYE_CHAR},
    {162, LYE_CHAR},
    {163, LYE_CHAR},
    {164, LYE_CHAR},
    {165, LYE_CHAR},
    {166, LYE_CHAR},
    {167, LYE_CHAR},
    {168, LYE_CHAR},
    {169, LYE_CHAR},
    {170, LYE_CHAR},
    {171, LYE_CHAR},
    {172, LYE_CHAR},
    {173, LYE_CHAR},
    {174, LYE_CHAR},
    {175, LYE_CHAR},
    {176, LYE_CHAR},
    {177, LYE_CHAR},
    {178, LYE_CHAR},
    {179, LYE_CHAR},
    {180, LYE_CHAR},
    {181, LYE_CHAR},
    {182, LYE_CHAR},
    {183, LYE_CHAR},
    {184, LYE_CHAR},
    {185, LYE_CHAR},
    {186, LYE_CHAR},
    {187, LYE_CHAR},
    {188, LYE_CHAR},
    {189, LYE_CHAR},
    {190, LYE_CHAR},
    {191, LYE_CHAR},
    {192, LYE_CHAR},
    {193, LYE_CHAR},
    {194, LYE_CHAR},
    {195, LYE_CHAR},
    {196, LYE_CHAR},
    {197, LYE_CHAR},
    {198, LYE_CHAR},
    {199, LYE_CHAR},
    {200, LYE_CHAR},
    {201, LYE_CHAR},
    {202, LYE_CHAR},
    {203, LYE_CHAR},
    {204, LYE_CHAR},
    {205, LYE_CHAR},
    {206, LYE_CHAR},
    {207, LYE_CHAR},
    {208, LYE_CHAR},
    {209, LYE_CHAR},
    {210, LYE_CHAR},
    {211, LYE_CHAR},
    {212, LYE_CHAR},
    {213, LYE_CHAR},
    {214, LYE_CHAR},
    {215, LYE_CHAR},
    {216, LYE_CHAR},
    {217, LYE_CHAR},
    {218, LYE_CHAR},
    {219, LYE_CHAR},
    {220, LYE_CHAR},
    {221, LYE_CHAR},
    {222, LYE_CHAR},
    {223, LYE_CHAR},
    {224, LYE_CHAR},
    {225, LYE_CHAR},
    {226, LYE_CHAR},
    {227, LYE_CHAR},
    {228, LYE_CHAR},
    {229, LYE_CHAR},
    {230, LYE_CHAR},
    {231, LYE_CHAR},
    {232, LYE_CHAR},
    {233, LYE_CHAR},
    {234, LYE_CHAR},
    {235, LYE_CHAR},
    {236, LYE_CHAR},
    {237, LYE_CHAR},
    {238, LYE_CHAR},
    {239, LYE_CHAR},
    {240, LYE_CHAR},
    {241, LYE_CHAR},
    {242, LYE_CHAR},
    {243, LYE_CHAR},
    {244, LYE_CHAR},
    {245, LYE_CHAR},
    {246, LYE_CHAR},
    {247, LYE_CHAR},
    {248, LYE_CHAR},
    {249, LYE_CHAR},
    {250, LYE_CHAR},
    {251, LYE_CHAR},
    {252, LYE_CHAR},
    {253, LYE_CHAR},
    {254, LYE_CHAR},
    {255, LYE_CHAR},
    {UPARROW_KEY, LYE_FORM_PASS},
    {DNARROW_KEY, LYE_FORM_PASS},
    {RTARROW_KEY, LYE_FORW},
    {LTARROW_KEY, LYE_BACK},
    {PGDOWN_KEY, LYE_FORM_PASS},
    {PGUP_KEY, LYE_FORM_PASS},
    {HOME_KEY, LYE_BOL},
    {END_KEY, LYE_EOL},
    {F1_KEY, LYE_FORM_PASS},
#if !(defined(_WINDOWS) || defined(__DJGPP__))
    {DO_KEY, LYE_TAB},
    {FIND_KEY, LYE_BOL},
    {SELECT_KEY, LYE_EOL},
#endif
    {REMOVE_KEY, LYE_DELP},
    {BACKTAB_KEY, LYE_FORM_PASS},
#if (defined(_WINDOWS) || defined(__DJGPP__)) && defined(USE_SLANG) && !defined(DJGPP_KEYHANDLER)
    {272, LYE_DELP},
    {273, LYE_ENTER},
#endif
    {-1, LYE_UNKNOWN}
};

#ifdef USE_ALT_BINDINGS
static const LYEditInit initBetterEditor[] =
{
    {CTL('A'), LYE_BOL},
    {CTL('B'), LYE_BACK},
    {CTL('C'), LYE_ABORT},
    {CTL('D'), LYE_DELN},
    {CTL('E'), LYE_EOL},
    {CTL('F'), LYE_FORW},
    {CTL('G'), LYE_ABORT},
    {CTL('H'), LYE_DELP},
    {CTL('I'), LYE_ENTER},
    {CTL('J'), LYE_ENTER},
    {CTL('K'), LYE_DELEL},
    {CTL('M'), LYE_ENTER},
    {CTL('N'), LYE_FORWW},
    {CTL('O'), LYE_ABORT},
    {CTL('P'), LYE_BACKW},
    {CTL('R'), LYE_DELPW},
    {CTL('T'), LYE_DELNW},
    {CTL('U'), LYE_ERASE},
    {CTL('V'), LYE_LKCMD},
#ifdef CAN_CUT_AND_PASTE
    {CTL('W'), LYE_PASTE},
#endif
    {CTL('X'), LYE_SETM1},
    {CTL('^'), LYE_UPPER},
    {CTL('_'), LYE_LOWER},
    {' ', LYE_CHAR},
    {'!', LYE_CHAR},
    {'"', LYE_CHAR},
    {'#', LYE_CHAR},
    {'$', LYE_CHAR},
    {'%', LYE_CHAR},
    {'&', LYE_CHAR},
    {'\'', LYE_CHAR},
    {'(', LYE_CHAR},
    {')', LYE_CHAR},
    {'*', LYE_CHAR},
    {'+', LYE_CHAR},
    {',', LYE_CHAR},
    {'-', LYE_CHAR},
    {'.', LYE_CHAR},
    {'/', LYE_CHAR},
    {'0', LYE_CHAR},
    {'1', LYE_CHAR},
    {'2', LYE_CHAR},
    {'3', LYE_CHAR},
    {'4', LYE_CHAR},
    {'5', LYE_CHAR},
    {'6', LYE_CHAR},
    {'7', LYE_CHAR},
    {'8', LYE_CHAR},
    {'9', LYE_CHAR},
    {':', LYE_CHAR},
    {';', LYE_CHAR},
    {'<', LYE_CHAR},
    {'=', LYE_CHAR},
    {'>', LYE_CHAR},
    {'?', LYE_CHAR},
    {'@', LYE_CHAR},
    {'A', LYE_CHAR},
    {'B', LYE_CHAR},
    {'C', LYE_CHAR},
    {'D', LYE_CHAR},
    {'E', LYE_CHAR},
    {'F', LYE_CHAR},
    {'G', LYE_CHAR},
    {'H', LYE_CHAR},
    {'I', LYE_CHAR},
    {'J', LYE_CHAR},
    {'K', LYE_CHAR},
    {'L', LYE_CHAR},
    {'M', LYE_CHAR},
    {'N', LYE_CHAR},
    {'O', LYE_CHAR},
    {'P', LYE_CHAR},
    {'Q', LYE_CHAR},
    {'R', LYE_CHAR},
    {'S', LYE_CHAR},
    {'T', LYE_CHAR},
    {'U', LYE_CHAR},
    {'V', LYE_CHAR},
    {'W', LYE_CHAR},
    {'X', LYE_CHAR},
    {'Y', LYE_CHAR},
    {'Z', LYE_CHAR},
    {'[', LYE_CHAR},
    {'\\', LYE_CHAR},
    {']', LYE_CHAR},
    {'^', LYE_CHAR},
    {'_', LYE_CHAR},
    {'`', LYE_CHAR},
    {'a', LYE_CHAR},
    {'b', LYE_CHAR},
    {'c', LYE_CHAR},
    {'d', LYE_CHAR},
    {'e', LYE_CHAR},
    {'f', LYE_CHAR},
    {'g', LYE_CHAR},
    {'h', LYE_CHAR},
    {'i', LYE_CHAR},
    {'j', LYE_CHAR},
    {'k', LYE_CHAR},
    {'l', LYE_CHAR},
    {'m', LYE_CHAR},
    {'n', LYE_CHAR},
    {'o', LYE_CHAR},
    {'p', LYE_CHAR},
    {'q', LYE_CHAR},
    {'r', LYE_CHAR},
    {'s', LYE_CHAR},
    {'t', LYE_CHAR},
    {'u', LYE_CHAR},
    {'v', LYE_CHAR},
    {'w', LYE_CHAR},
    {'x', LYE_CHAR},
    {'y', LYE_CHAR},
    {'z', LYE_CHAR},
    {'{', LYE_CHAR},
    {'|', LYE_CHAR},
    {'}', LYE_CHAR},
    {'~', LYE_CHAR},
    {DEL_KEY, LYE_DELP},
    {128, LYE_CHAR},
    {129, LYE_CHAR},
    {130, LYE_CHAR},
    {131, LYE_CHAR},
    {132, LYE_CHAR},
    {133, LYE_CHAR},
    {134, LYE_CHAR},
    {135, LYE_CHAR},
    {136, LYE_CHAR},
    {137, LYE_CHAR},
    {138, LYE_CHAR},
    {139, LYE_CHAR},
    {140, LYE_CHAR},
    {141, LYE_CHAR},
#ifdef CJK_EX			/* 1997/11/03 (Mon) 20:30:54 */
    {142, LYE_CHAR},
#else
    {142, LYE_AIX},
#endif
    {143, LYE_CHAR},
    {144, LYE_CHAR},
    {145, LYE_CHAR},
    {146, LYE_CHAR},
    {147, LYE_CHAR},
    {148, LYE_CHAR},
    {149, LYE_CHAR},
    {150, LYE_CHAR},
    {151, LYE_CHAR},
    {152, LYE_CHAR},
    {153, LYE_CHAR},
    {154, LYE_CHAR},
    {155, LYE_CHAR},
    {156, LYE_CHAR},
    {157, LYE_CHAR},
    {158, LYE_CHAR},
    {159, LYE_CHAR},
    {160, LYE_CHAR},
    {161, LYE_CHAR},
    {162, LYE_CHAR},
    {163, LYE_CHAR},
    {164, LYE_CHAR},
    {165, LYE_CHAR},
    {166, LYE_CHAR},
    {167, LYE_CHAR},
    {168, LYE_CHAR},
    {169, LYE_CHAR},
    {170, LYE_CHAR},
    {171, LYE_CHAR},
    {172, LYE_CHAR},
    {173, LYE_CHAR},
    {174, LYE_CHAR},
    {175, LYE_CHAR},
    {176, LYE_CHAR},
    {177, LYE_CHAR},
    {178, LYE_CHAR},
    {179, LYE_CHAR},
    {180, LYE_CHAR},
    {181, LYE_CHAR},
    {182, LYE_CHAR},
    {183, LYE_CHAR},
    {184, LYE_CHAR},
    {185, LYE_CHAR},
    {186, LYE_CHAR},
    {187, LYE_CHAR},
    {188, LYE_CHAR},
    {189, LYE_CHAR},
    {190, LYE_CHAR},
    {191, LYE_CHAR},
    {192, LYE_CHAR},
    {193, LYE_CHAR},
    {194, LYE_CHAR},
    {195, LYE_CHAR},
    {196, LYE_CHAR},
    {197, LYE_CHAR},
    {198, LYE_CHAR},
    {199, LYE_CHAR},
    {200, LYE_CHAR},
    {201, LYE_CHAR},
    {202, LYE_CHAR},
    {203, LYE_CHAR},
    {204, LYE_CHAR},
    {205, LYE_CHAR},
    {206, LYE_CHAR},
    {207, LYE_CHAR},
    {208, LYE_CHAR},
    {209, LYE_CHAR},
    {210, LYE_CHAR},
    {211, LYE_CHAR},
    {212, LYE_CHAR},
    {213, LYE_CHAR},
    {214, LYE_CHAR},
    {215, LYE_CHAR},
    {216, LYE_CHAR},
    {217, LYE_CHAR},
    {218, LYE_CHAR},
    {219, LYE_CHAR},
    {220, LYE_CHAR},
    {221, LYE_CHAR},
    {222, LYE_CHAR},
    {223, LYE_CHAR},
    {224, LYE_CHAR},
    {225, LYE_CHAR},
    {226, LYE_CHAR},
    {227, LYE_CHAR},
    {228, LYE_CHAR},
    {229, LYE_CHAR},
    {230, LYE_CHAR},
    {231, LYE_CHAR},
    {232, LYE_CHAR},
    {233, LYE_CHAR},
    {234, LYE_CHAR},
    {235, LYE_CHAR},
    {236, LYE_CHAR},
    {237, LYE_CHAR},
    {238, LYE_CHAR},
    {239, LYE_CHAR},
    {240, LYE_CHAR},
    {241, LYE_CHAR},
    {242, LYE_CHAR},
    {243, LYE_CHAR},
    {244, LYE_CHAR},
    {245, LYE_CHAR},
    {246, LYE_CHAR},
    {247, LYE_CHAR},
    {248, LYE_CHAR},
    {249, LYE_CHAR},
    {250, LYE_CHAR},
    {251, LYE_CHAR},
    {252, LYE_CHAR},
    {253, LYE_CHAR},
    {254, LYE_CHAR},
    {255, LYE_CHAR},
    {UPARROW_KEY, LYE_FORM_PASS},
    {DNARROW_KEY, LYE_FORM_PASS},
    {RTARROW_KEY, LYE_FORW},
    {LTARROW_KEY, LYE_BACK},
    {PGDOWN_KEY, LYE_FORM_PASS},
    {PGUP_KEY, LYE_FORM_PASS},
    {HOME_KEY, LYE_BOL},
    {END_KEY, LYE_EOL},
    {F1_KEY, LYE_FORM_PASS},
#if !(defined(_WINDOWS) || defined(__DJGPP__))
    {DO_KEY, LYE_TAB},
    {FIND_KEY, LYE_BOL},
    {SELECT_KEY, LYE_EOL},
#endif
    {REMOVE_KEY, LYE_DELP},
    {BACKTAB_KEY, LYE_FORM_PASS},
#if (defined(_WINDOWS) || defined(__DJGPP__)) && defined(USE_SLANG) && !defined(DJGPP_KEYHANDLER)
    {272, LYE_DELP},
    {273, LYE_ENTER},
#endif
    {-1, LYE_UNKNOWN}
};

static const LYEditInit initBashlikeEditor[] =
{
    {CTL('@'), LYE_SETMARK},
    {CTL('A'), LYE_BOL},
    {CTL('B'), LYE_BACK},
    {CTL('C'), LYE_ABORT},
    {CTL('D'), LYE_DELN},
    {CTL('E'), LYE_EOL | LYE_DF},
    {CTL('F'), LYE_FORW},
    {CTL('G'), LYE_ABORT},
    {CTL('H'), LYE_DELP},
    {CTL('I'), LYE_TAB},
    {CTL('J'), LYE_ENTER},
    {CTL('K'), LYE_DELEL | LYE_DF},
    {CTL('L'), LYE_FORM_PASS},
    {CTL('M'), LYE_ENTER},
    {CTL('N'), LYE_FORM_PASS},
    {CTL('O'), LYE_FORM_PASS},
    {CTL('P'), LYE_FORM_PASS},
    {CTL('R'), LYE_BACKW},
    {CTL('S'), LYE_FORWW},
    {CTL('T'), LYE_TPOS},
    {CTL('U'), LYE_DELBL},
    {CTL('V'), LYE_LKCMD},
    {CTL('W'), LYE_DELPW},
    {CTL('X'), LYE_SETM1},
    {CTL('Y'), LYE_YANK},
    {CTL('Z'), LYE_FORM_PASS},
    {CTL('['), LYE_SETM2},
    {CTL('\\'), LYE_FORM_PASS},
    {CTL(']'), LYE_FORM_PASS},
    {CTL('^'), LYE_SWMAP},
    {CTL('_'), LYE_ABORT},
    {' ', LYE_CHAR},
    {'!', LYE_CHAR},
    {'"', LYE_CHAR},
    {'#', LYE_CHAR},
    {'$', LYE_CHAR},
    {'%', LYE_CHAR},
    {'&', LYE_CHAR},
    {'\'', LYE_CHAR},
    {'(', LYE_CHAR},
    {')', LYE_CHAR},
    {'*', LYE_CHAR},
    {'+', LYE_CHAR},
    {',', LYE_CHAR},
    {'-', LYE_CHAR},
    {'.', LYE_CHAR},
    {'/', LYE_CHAR},
    {'0', LYE_CHAR},
    {'1', LYE_CHAR},
    {'2', LYE_CHAR},
    {'3', LYE_CHAR},
    {'4', LYE_CHAR},
    {'5', LYE_CHAR},
    {'6', LYE_CHAR},
    {'7', LYE_CHAR},
    {'8', LYE_CHAR},
    {'9', LYE_CHAR},
    {':', LYE_CHAR},
    {';', LYE_CHAR},
    {'<', LYE_CHAR},
    {'=', LYE_CHAR},
    {'>', LYE_CHAR},
    {'?', LYE_CHAR},
    {'@', LYE_CHAR},
    {'A', LYE_CHAR},
    {'B', LYE_CHAR},
    {'C', LYE_CHAR},
    {'D', LYE_CHAR},
    {'E', LYE_CHAR},
    {'F', LYE_CHAR},
    {'G', LYE_CHAR},
    {'H', LYE_CHAR},
    {'I', LYE_CHAR},
    {'J', LYE_CHAR},
    {'K', LYE_CHAR},
    {'L', LYE_CHAR},
    {'M', LYE_CHAR},
    {'N', LYE_CHAR},
    {'O', LYE_CHAR},
    {'P', LYE_CHAR},
    {'Q', LYE_CHAR},
    {'R', LYE_CHAR},
    {'S', LYE_CHAR},
    {'T', LYE_CHAR},
    {'U', LYE_CHAR},
    {'V', LYE_CHAR},
    {'W', LYE_CHAR},
    {'X', LYE_CHAR},
    {'Y', LYE_CHAR},
    {'Z', LYE_CHAR},
    {'[', LYE_CHAR},
    {'\\', LYE_CHAR},
    {']', LYE_CHAR},
    {'^', LYE_CHAR},
    {'_', LYE_CHAR},
    {'`', LYE_CHAR},
    {'a', LYE_CHAR},
    {'b', LYE_CHAR},
    {'c', LYE_CHAR},
    {'d', LYE_CHAR},
    {'e', LYE_CHAR},
    {'f', LYE_CHAR},
    {'g', LYE_CHAR},
    {'h', LYE_CHAR},
    {'i', LYE_CHAR},
    {'j', LYE_CHAR},
    {'k', LYE_CHAR},
    {'l', LYE_CHAR},
    {'m', LYE_CHAR},
    {'n', LYE_CHAR},
    {'o', LYE_CHAR},
    {'p', LYE_CHAR},
    {'q', LYE_CHAR},
    {'r', LYE_CHAR},
    {'s', LYE_CHAR},
    {'t', LYE_CHAR},
    {'u', LYE_CHAR},
    {'v', LYE_CHAR},
    {'w', LYE_CHAR},
    {'x', LYE_CHAR},
    {'y', LYE_CHAR},
    {'z', LYE_CHAR},
    {'{', LYE_CHAR},
    {'|', LYE_CHAR},
    {'}', LYE_CHAR},
    {'~', LYE_CHAR},
    {DEL_KEY, LYE_DELP},
    {128, LYE_CHAR},
    {129, LYE_CHAR},
    {130, LYE_CHAR},
    {131, LYE_CHAR},
    {132, LYE_CHAR},
    {133, LYE_CHAR},
    {134, LYE_CHAR},
    {135, LYE_CHAR},
    {136, LYE_CHAR},
    {137, LYE_CHAR},
    {138, LYE_CHAR},
    {139, LYE_CHAR},
    {140, LYE_CHAR},
    {141, LYE_CHAR},
    {142, LYE_CHAR},
    {143, LYE_CHAR},
    {144, LYE_CHAR},
    {145, LYE_CHAR},
    {146, LYE_CHAR},
    {147, LYE_CHAR},
    {148, LYE_CHAR},
    {149, LYE_CHAR},
    {150, LYE_CHAR},
    {151, LYE_AIX},
    {152, LYE_CHAR},
    {153, LYE_CHAR},
    {154, LYE_CHAR},
    {155, LYE_CHAR},
    {156, LYE_CHAR},
    {157, LYE_CHAR},
    {158, LYE_CHAR},
    {159, LYE_CHAR},
    {160, LYE_CHAR},
    {161, LYE_CHAR},
    {162, LYE_CHAR},
    {163, LYE_CHAR},
    {164, LYE_CHAR},
    {165, LYE_CHAR},
    {166, LYE_CHAR},
    {167, LYE_CHAR},
    {168, LYE_CHAR},
    {169, LYE_CHAR},
    {170, LYE_CHAR},
    {171, LYE_CHAR},
    {172, LYE_CHAR},
    {173, LYE_CHAR},
    {174, LYE_CHAR},
    {175, LYE_CHAR},
    {176, LYE_CHAR},
    {177, LYE_CHAR},
    {178, LYE_CHAR},
    {179, LYE_CHAR},
    {180, LYE_CHAR},
    {181, LYE_CHAR},
    {182, LYE_CHAR},
    {183, LYE_CHAR},
    {184, LYE_CHAR},
    {185, LYE_CHAR},
    {186, LYE_CHAR},
    {187, LYE_CHAR},
    {188, LYE_CHAR},
    {189, LYE_CHAR},
    {190, LYE_CHAR},
    {191, LYE_CHAR},
    {192, LYE_CHAR},
    {193, LYE_CHAR},
    {194, LYE_CHAR},
    {195, LYE_CHAR},
    {196, LYE_CHAR},
    {197, LYE_CHAR},
    {198, LYE_CHAR},
    {199, LYE_CHAR},
    {200, LYE_CHAR},
    {201, LYE_CHAR},
    {202, LYE_CHAR},
    {203, LYE_CHAR},
    {204, LYE_CHAR},
    {205, LYE_CHAR},
    {206, LYE_CHAR},
    {207, LYE_CHAR},
    {208, LYE_CHAR},
    {209, LYE_CHAR},
    {210, LYE_CHAR},
    {211, LYE_CHAR},
    {212, LYE_CHAR},
    {213, LYE_CHAR},
    {214, LYE_CHAR},
    {215, LYE_CHAR},
    {216, LYE_CHAR},
    {217, LYE_CHAR},
    {218, LYE_CHAR},
    {219, LYE_CHAR},
    {220, LYE_CHAR},
    {221, LYE_CHAR},
    {222, LYE_CHAR},
    {223, LYE_CHAR},
    {224, LYE_CHAR},
    {225, LYE_CHAR},
    {226, LYE_CHAR},
    {227, LYE_CHAR},
    {228, LYE_CHAR},
    {229, LYE_CHAR},
    {230, LYE_CHAR},
    {231, LYE_CHAR},
    {232, LYE_CHAR},
    {233, LYE_CHAR},
    {234, LYE_CHAR},
    {235, LYE_CHAR},
    {236, LYE_CHAR},
    {237, LYE_CHAR},
    {238, LYE_CHAR},
    {239, LYE_CHAR},
    {240, LYE_CHAR},
    {241, LYE_CHAR},
    {242, LYE_CHAR},
    {243, LYE_CHAR},
    {244, LYE_CHAR},
    {245, LYE_CHAR},
    {246, LYE_CHAR},
    {247, LYE_CHAR},
    {248, LYE_CHAR},
    {249, LYE_CHAR},
    {250, LYE_CHAR},
    {251, LYE_CHAR},
    {252, LYE_CHAR},
    {253, LYE_CHAR},
    {254, LYE_CHAR},
    {255, LYE_CHAR},
    {UPARROW_KEY, LYE_FORM_PASS},
    {DNARROW_KEY, LYE_FORM_PASS},
    {RTARROW_KEY, LYE_FORW},
    {LTARROW_KEY, LYE_BACK},
    {PGDOWN_KEY, LYE_FORM_PASS},
    {PGUP_KEY, LYE_FORM_PASS},
    {HOME_KEY, LYE_BOL},
    {END_KEY, LYE_EOL},
    {F1_KEY, LYE_FORM_PASS},
#if !(defined(_WINDOWS) || defined(__DJGPP__))
    {DO_KEY, LYE_TAB},
    {FIND_KEY, LYE_BOL},
    {SELECT_KEY, LYE_EOL},
#endif
    {REMOVE_KEY, LYE_DELN},
    {BACKTAB_KEY, LYE_FORM_PASS},
#if (defined(_WINDOWS) || defined(__DJGPP__)) && defined(USE_SLANG) && !defined(DJGPP_KEYHANDLER)
    {272, LYE_DELP},
    {273, LYE_ENTER},
#endif
    {-1, LYE_UNKNOWN}
};
#endif /* USE_ALT_BINDINGS */

LYEditConfig LYLineEditors[] =
{
    {"Default Binding", initDefaultEditor, DefaultEditBinding},
#ifdef USE_ALT_BINDINGS
    {"Alternate Bindings", initBetterEditor, BetterEditBinding},
    {"Bash-like Bindings", initBashlikeEditor, BashlikeEditBinding},
#endif
};

const char *LYEditorNames[TABLESIZE(LYLineEditors) + 1];

/*
 * Add the URL (relative to helpfilepath) used for context-dependent
 * help on form field editing.
 *
 * The order must correspond to that of LYLineditNames.
 */
const char *LYLineeditHelpURLs[] =
{
    EDIT_HELP,
#ifdef USE_ALT_BINDINGS
    ALT_EDIT_HELP,
    BASHLIKE_EDIT_HELP,
#endif
    (char *) 0
};

static struct emap *name2emap(const char *name)
{
    struct emap *mp;
    struct emap *result = 0;

    if (non_empty(name)) {
	for (mp = ekmap; mp->name != NULL; mp++) {
	    if (strcasecomp(mp->name, name) == 0) {
		result = mp;
		break;
	    }
	}
    }
    return result;
}

static struct emap *code2emap(int code)
{
    struct emap *mp;
    struct emap *result = 0;

    for (mp = ekmap; mp->name != NULL; mp++) {
	if (mp->code == code) {
	    result = mp;
	    break;
	}
    }
    return result;
}

/*
 * Return editactioncode whose name is the string func.  func must be present
 * in the ekmap table.  returns -1 if not found.  - kw
 */
int lecname_to_lec(const char *func)
{
    struct emap *mp;
    int result = -1;

    if ((mp = name2emap(func)) != 0) {
	result = mp->code;
    }
    return result;
}

const char *lec_to_lecname(int code)
{
    struct emap *mp;
    const char *result = 0;

    if ((mp = code2emap(code)) != 0) {
	result = mp->name;
    }
    return result;
}

int EditBinding(int xlkc)
{
    int editaction, xleac = LYE_UNMOD;
    int c = xlkc & LKC_MASK;

    if (xlkc == -1)
	return LYE_NOP;		/* maybe LYE_ABORT? or LYE_FORM_LAC|LYK_UNKNOWN? */
#ifdef NOT_ASCII
    if (c < 256) {
	c = TOASCII(c);
    }
#endif
#ifdef USE_ALT_BINDINGS
    /*
     * Get intermediate code from one of the lynxkeycode+modifier tables if
     * applicable, otherwise get the lynxeditactioncode directly.  If we have
     * more than one modifier bits, the first currently wins.  - kw
     */
    if (xlkc & LKC_ISLECLAC) {
	return LKC2_TO_LEC(xlkc);
    } else if (xlkc & LKC_MOD1) {
	xleac = LKC_TO_LEC_M1(c);
    } else if (xlkc & LKC_MOD2) {
	xleac = LKC_TO_LEC_M2(c);
    } else if (xlkc & LKC_MOD3) {
	xleac = LKC_TO_LEC_M3(c);
    } else {
	xleac = UCH(CurrentLineEditor()[c]);
    }
#endif
    /*
     * If we have an intermediate code that says "same as without modifier",
     * look that up now; otherwise we are already done.  - kw
     */
    if (xleac == LYE_UNMOD) {
	editaction = CurrentLineEditor()[c];
    } else {
	editaction = xleac;
    }
    return editaction;
}

/*
 * Install lec as the lynxeditaction for lynxkeycode xlkc.  func must be
 * present in the revmap table.  For normal (non-modifier) lynxkeycodes,
 * select_edi selects which of the alternative line-editor binding tables is
 * modified.  If select_edi is positive, only the table given by it is modified
 * (the DefaultEditBinding table is numbered 1).  If select_edi is 0, all
 * tables are modified.  If select_edi is negative, all tables except the one
 * given by abs(select_edi) are modified.  returns TRUE if the mapping was
 * made, FALSE if not.  Note that this remapping cannot be undone (as might be
 * desirable as a result of re-parsing lynx.cfg), we don't remember the
 * original editaction from the Bindings tables anywhere.  - kw
 */
BOOL LYRemapEditBinding(int xlkc,
			int lec,
			int select_edi)
{
    int j;
    int c = xlkc & LKC_MASK;
    BOOLEAN success = FALSE;

    if (xlkc >= 0 && !(xlkc & LKC_ISLAC) && (c < KEYMAP_SIZE)) {
	LYEditCode code = (LYEditCode) lec;

#ifdef USE_ALT_BINDINGS
	if (xlkc & LKC_MOD1) {
	    if (c <= LAST_MOD1_LKC) {
		Mod1Binding[c] = code;
		success = TRUE;
	    }
	} else if (xlkc & LKC_MOD2) {
	    if (c <= LAST_MOD2_LKC) {
		Mod2Binding[c] = code;
		success = TRUE;
	    }
	} else if (xlkc & LKC_MOD3) {
	    if (c <= LAST_MOD3_LKC) {
		Mod3Binding[c] = code;
		success = TRUE;
	    }
	} else
#endif /* USE_ALT_BINDINGS */
	{
#ifndef UCHAR_MAX
#define UCHAR_MAX 255
#endif
	    if ((unsigned int) lec <= UCHAR_MAX) {
		if (select_edi > 0) {
		    if ((unsigned int) select_edi < TABLESIZE(LYLineEditors)) {
			LYLineEditors[select_edi - 1].used[c] = code;
			success = TRUE;
		    }
		} else {
		    for (j = 0; j < (int) TABLESIZE(LYLineEditors); j++) {
			success = TRUE;
			if ((select_edi < 0) && ((j + 1 + select_edi) == 0))
			    continue;
			LYLineEditors[j].used[c] = code;
		    }
		}
	    }
	}
    }
    return success;
}

/*
 * Macro to walk through lkc-indexed tables up to imax, in the (ASCII) order
 *     97 - 122  ('a' - 'z'),
 *     32 -  96  (' ' - '`', includes 'A' - 'Z'),
 *    123 - 126  ('{' - '~'),
 *      0 -  31  (^@  - ^_),
 *    256 - imax,
 *    127 - 255
 */
#define NEXT_I(i,imax) ((i==122) ? 32 : (i==96) ? 123 : (i==126) ? 0 :\
			(i==31) ? 256 : (i==imax) ? 127 :\
			(i==255) ? (-1) :i+1)
#define FIRST_I 97

int LYKeyForEditAction(int lec)
{
    int editaction, i;

    for (i = FIRST_I; i >= 0; i = NEXT_I(i, KEYMAP_SIZE - 1)) {
	editaction = CurrentLineEditor()[i];
	if (editaction == lec) {
#ifdef NOT_ASCII
	    if (i < 256) {
		return FROMASCII(i);
	    } else
#endif
		return i;
	}
    }
    return (-1);
}

/*
 * Given a lynxactioncode, return a key (lynxkeycode) or sequence of two keys
 * that results in the given action while forms-editing.  The main keycode is
 * returned as function value, possibly with modifier bits set; in addition, if
 * applicable, a key that sets the required modifier flag is returned in
 * *pmodkey if (pmodkey!=NULL).  Non-lineediting bindings that would require
 * typing LYE_LKCMD (default ^V) to activate are not checked here, the caller
 * should do that separately if required.  If no key is bound by current
 * line-editor bindings to the action, -1 is returned.
 *
 * This is all a bit long - it is general enough to continue to work should the
 * three Mod<N>Binding[] become different tables.  - kw
 */
int LYEditKeyForAction(int lac,
		       int *pmodkey)
{
    int editaction, i, c;
    int mod1found = -1, mod2found = -1, mod3found = -1;

    if (pmodkey)
	*pmodkey = -1;
    for (i = FIRST_I; i >= 0; i = NEXT_I(i, KEYMAP_SIZE - 1)) {
	editaction = CurrentLineEditor()[i];
#ifdef NOT_ASCII
	if (i < 256) {
	    c = FROMASCII(i);
	} else
#endif
	    c = i;
	if (editaction == (lac | LYE_FORM_LAC))
	    return c;
	if (editaction == LYE_FORM_PASS) {
#if defined(DIRED_SUPPORT) && defined(OK_OVERRIDE)
	    if (lynx_edit_mode && !no_dired_support && lac &&
		LKC_TO_LAC(key_override, c) == lac)
		return c;
#endif /* DIRED_SUPPORT && OK_OVERRIDE */
	    if (LKC_TO_LAC(keymap, c) == lac)
		return c;
	}
	if (editaction == LYE_TAB) {
#if defined(DIRED_SUPPORT) && defined(OK_OVERRIDE)
	    if (lynx_edit_mode && !no_dired_support && lac &&
		LKC_TO_LAC(key_override, '\t') == lac)
		return c;
#endif /* DIRED_SUPPORT && OK_OVERRIDE */
	    if (LKC_TO_LAC(keymap, '\t') == lac)
		return c;
	}
	if (editaction == LYE_SETM1 && mod1found < 0)
	    mod1found = i;
	if (editaction == LYE_SETM2 && mod2found < 0)
	    mod2found = i;
	if ((editaction & LYE_DF) && mod3found < 0)
	    mod3found = i;
    }
#ifdef USE_ALT_BINDINGS
    if (mod3found >= 0) {
	for (i = mod3found; i >= 0; i = NEXT_I(i, LAST_MOD3_LKC)) {
	    editaction = CurrentLineEditor()[i];
	    if (!(editaction & LYE_DF))
		continue;
	    editaction = Mod3Binding[i];
#ifdef NOT_ASCII
	    if (i < 256) {
		c = FROMASCII(i);
	    } else
#endif
		c = i;
	    if (pmodkey)
		*pmodkey = c;
	    if (editaction == (lac | LYE_FORM_LAC))
		return (c | LKC_MOD3);
	    if (editaction == LYE_FORM_PASS) {
#if defined(DIRED_SUPPORT) && defined(OK_OVERRIDE)
		if (lynx_edit_mode && !no_dired_support && lac &&
		    LKC_TO_LAC(key_override, c) == lac)
		    return (c | LKC_MOD3);
#endif /* DIRED_SUPPORT && OK_OVERRIDE */
		if (LKC_TO_LAC(keymap, c) == lac)
		    return (c | LKC_MOD3);
	    }
	    if (editaction == LYE_TAB) {
#if defined(DIRED_SUPPORT) && defined(OK_OVERRIDE)
		if (lynx_edit_mode && !no_dired_support && lac &&
		    LKC_TO_LAC(key_override, '\t') == lac)
		    return (c | LKC_MOD3);
#endif /* DIRED_SUPPORT && OK_OVERRIDE */
		if (LKC_TO_LAC(keymap, '\t') == lac)
		    return (c | LKC_MOD3);
	    }
	}
    }
    if (mod1found >= 0) {
	if (pmodkey) {
#ifdef NOT_ASCII
	    if (mod1found < 256) {
		*pmodkey = FROMASCII(mod1found);
	    } else
#endif
		*pmodkey = mod1found;
	}
	for (i = FIRST_I; i >= 0; i = NEXT_I(i, LAST_MOD1_LKC)) {
	    editaction = Mod1Binding[i];
#ifdef NOT_ASCII
	    if (i < 256) {
		c = FROMASCII(i);
	    } else
#endif
		c = i;
	    if (editaction == (lac | LYE_FORM_LAC))
		return (c | LKC_MOD1);
	    if (editaction == LYE_FORM_PASS) {
#if defined(DIRED_SUPPORT) && defined(OK_OVERRIDE)
		if (lynx_edit_mode && !no_dired_support && lac &&
		    LKC_TO_LAC(key_override, c) == lac)
		    return (c | LKC_MOD1);
#endif /* DIRED_SUPPORT && OK_OVERRIDE */
		if (LKC_TO_LAC(keymap, c) == lac)
		    return (c | LKC_MOD1);
	    }
	    if (editaction == LYE_TAB) {
#if defined(DIRED_SUPPORT) && defined(OK_OVERRIDE)
		if (lynx_edit_mode && !no_dired_support && lac &&
		    LKC_TO_LAC(key_override, '\t') == lac)
		    return (c | LKC_MOD1);
#endif /* DIRED_SUPPORT && OK_OVERRIDE */
		if (LKC_TO_LAC(keymap, '\t') == lac)
		    return (c | LKC_MOD1);
	    }
	}
    }
    if (mod2found >= 0) {
	if (pmodkey) {
#ifdef NOT_ASCII
	    if (mod1found < 256) {
		*pmodkey = FROMASCII(mod1found);
	    } else
#endif
		*pmodkey = mod1found;
	}
	for (i = FIRST_I; i >= 0; i = NEXT_I(i, LAST_MOD2_LKC)) {
	    editaction = Mod2Binding[i];
#ifdef NOT_ASCII
	    if (i < 256) {
		c = FROMASCII(i);
	    } else
#endif
		c = i;
	    if (editaction == (lac | LYE_FORM_LAC))
		return (c | LKC_MOD2);
	    if (editaction == LYE_FORM_PASS) {
#if defined(DIRED_SUPPORT) && defined(OK_OVERRIDE)
		if (lynx_edit_mode && !no_dired_support && lac &&
		    LKC_TO_LAC(key_override, c) == lac)
		    return (c | LKC_MOD2);
#endif /* DIRED_SUPPORT && OK_OVERRIDE */
		if (LKC_TO_LAC(keymap, c) == lac)
		    return (c | LKC_MOD2);
	    }
	    if (editaction == LYE_TAB) {
#if defined(DIRED_SUPPORT) && defined(OK_OVERRIDE)
		if (lynx_edit_mode && !no_dired_support && lac &&
		    LKC_TO_LAC(key_override, '\t') == lac)
		    return (c | LKC_MOD2);
#endif /* DIRED_SUPPORT && OK_OVERRIDE */
		if (LKC_TO_LAC(keymap, '\t') == lac)
		    return (c | LKC_MOD2);
	    }
	}
    }
#endif /* USE_ALT_BINDINGS */
    if (pmodkey)
	*pmodkey = -1;
    return (-1);
}

#if 0
/*
 * This function was useful in converting the hand-crafted key-bindings to
 * their reusable form in 2.8.8 -TD
 */
static void checkEditMap(LYEditConfig * table)
{
    unsigned j, k;
    char comment[80];
    int first = TRUE;

    for (j = 0; table->init[j].code >= 0; ++j) {
	int code = table->init[j].code;

	if (table->init[j].edit != table->used[code]) {
	    if (first) {
		printf("TABLE %s\n", table->name);
		first = FALSE;
	    }
	    printf("%u: init %d vs used %d\n",
		   j,
		   table->init[j].edit,
		   table->used[code]);
	}
    }
    for (j = 0; j < KEYMAP_SIZE; ++j) {
	int code = (int) j;
	BOOL found = FALSE;

	for (k = 0; table->init[k].code >= 0; ++k) {
	    if (code == table->init[k].code) {
		found = TRUE;
		break;
	    }
	}
	if (!found) {
	    if (table->used[j] != 0) {
		int edit = table->used[j];
		int has_DF = (edit & LYE_DF);
		int has_LAC = (edit & LYE_FORM_LAC);
		const char *prefix = "LYE_";
		const char *name = 0;

		edit &= 0x7f;
		if (has_LAC) {
		    Kcmd *cmd = LYKeycodeToKcmd(edit);

		    if (cmd != 0) {
			prefix = "LYK_";
			name = cmd->name;
		    }
		} else {
		    name = lec_to_lecname(edit);
		}

		if (j < 32) {
		    char temp[80];
		    const char *what = 0;

		    switch (j) {
		    case 0:
			what = "nul";
			break;
		    case 17:
			what = "XON";
			break;
		    case 19:
			what = "XOFF";
			break;
		    default:
			sprintf(temp, "^%c", j + 'A');
			what = temp;
			break;
		    }
		    sprintf(comment, "\t/* %s */", what);
		} else if (j < 127) {
		    sprintf(comment, "\t/* %c */", j);
		} else {
		    const char *what = LYextraKeysToName(j);

		    if (Non_Empty(what)) {
			sprintf(comment, "\t/* %s%s */", what,
				((StrChr(what, '_') != 0)
				 ? ""
				 : "_KEY"));
		    } else {
			strcpy(comment, "");
		    }
		}
		if (name == 0) {
		    name = "XXX";
		} else if (!strcasecomp(name, "PASS")) {
		    name = "FORM_PASS";
		}
		if (first) {
		    printf("TABLE %s\n", table->name);
		    first = FALSE;
		}
		printf("\t{ %d, %s%s%s%s },%s\n", code, prefix, name,
		       has_DF ? "|LYE_DF" : "",
		       has_LAC ? "|LYE_FORM_LAC" : "",
		       comment);
	    }
	}
    }
}

#else
#define checkEditMap(table)	/* nothing */
#endif

static void initLineEditor(LYEditConfig * table)
{
    unsigned k;
    LYEditCode *used = table->used;
    const LYEditInit *init = table->init;

    memset(used, 0, sizeof(LYEditCode) * KEYMAP_SIZE);

    for (k = 0; init[k].code >= 0; ++k) {
	int code = init[k].code;

	used[code] = init[k].edit;
    }
    checkEditMap(table);
}

/*
 * Reset the editor bindings to their default values.
 */
void LYinitEditmap(void)
{
    unsigned j;

    for (j = 0; j < TABLESIZE(LYLineEditors); ++j) {
	LYEditorNames[j] = LYLineEditors[j].name;
	initLineEditor(&LYLineEditors[j]);
    }
#ifdef USE_ALT_BINDINGS
    for (j = 0; j < TABLESIZE(LYModifierBindings); ++j) {
	initLineEditor(&LYModifierBindings[j]);
    }
#endif
}

static char *showRanges(int *state)
{
    char *result = 0;
    int range[2];
    int i;

    range[0] = range[1] = -1;
    for (i = 0; i < KEYMAP_SIZE; ++i) {
	if (!state[i]) {
	    int code = CurrentLineEditor()[i];

	    if (code == LYE_CHAR) {
		if (range[0] < 0)
		    range[0] = i;
		range[1] = i;
		state[i] = 3;
	    } else if (range[0] >= 0) {
		if (non_empty(result))
		    StrAllocCat(result, ", ");
		HTSprintf(&result, "%d-%d", range[0], range[1]);
		range[0] = range[1] = -1;
	    }
	}
    }
    return result;
}

static int LYLoadEditmap(const char *arg GCC_UNUSED,
			 HTParentAnchor *anAnchor,
			 HTFormat format_out,
			 HTStream *sink)
{
#define FORMAT "  %-*s  %-*s  -  %s\n"
    HTFormat format_in = WWW_HTML;
    HTStream *target;
    int state[KEYMAP_SIZE];
    int width[2];
    char *buf = 0;
    char *ranges = 0;
    struct emap *mp;
    int i;
    int hanging;
    int wrapped;
    int had_output = FALSE;
    int result;

    if ((target = HTStreamStack(format_in, format_out, sink, anAnchor)) != 0) {
	anAnchor->no_cache = TRUE;

	HTSprintf0(&buf,
		   "<html>\n<head>\n<title>%s</title>\n</head>\n<body>\n",
		   CURRENT_EDITMAP_TITLE);
	PUTS(buf);
	HTSprintf0(&buf, "<pre>\n");
	PUTS(buf);

	/* determine the column-widths we will use for showing bindings */
	width[0] = 0;
	width[1] = 0;
	for (i = 0; i < KEYMAP_SIZE; ++i) {
	    int code = CurrentLineEditor()[i];

	    if (code == LYE_NOP) {
		state[i] = 1;
	    } else {
		int need;

		if ((mp = code2emap(code)) != 0) {
		    state[i] = 0;
		    if ((need = (int) strlen(mp->name)) > width[0])
			width[0] = need;
		    if ((need = (int) strlen(mp->descr)) > width[1])
			width[1] = need;
		} else {
		    state[i] = 2;
		}
	    }
	}
	hanging = 2 + width[0] + 2 + width[1] + 5;
	wrapped = hanging;

	/*
	 * Tell which set of bindings we are showing, and link to the
	 * handcrafted page, which adds explanations.
	 */
	PUTS(gettext("These are the current edit-bindings:"));
	HTSprintf0(&buf,
		   " <a href=\"%s\">%s</a>\n\n",
		   LYLineeditHelpURL(),
		   LYEditorNames[current_lineedit]);
	PUTS(buf);

	/* Show by groups to match the arrangement in the handmade files. */
	for (mp = ekmap; mp->name != 0; ++mp) {
	    if (isEmpty(mp->name)) {
		if (had_output) {
		    PUTS("\n");
		    had_output = FALSE;
		}
	    } else if (mp->code == LYE_CHAR) {
		ranges = showRanges(state);
		HTSprintf0(&buf, FORMAT,
			   width[0], mp->name,
			   width[1], mp->descr,
			   ranges);
		FREE(ranges);
		PUTS(buf);
		had_output = TRUE;
	    } else {
		for (i = 0; i < KEYMAP_SIZE; ++i) {
		    int code = CurrentLineEditor()[i];

		    if ((code == mp->code) && !state[i]) {
			char *value = LYKeycodeToString(i, (i >= 160 &&
							    i <= 255));
			int before = wrapped + (ranges ? ((int)
							  strlen(ranges)) : 0);
			int after = before;

			if (non_empty(ranges)) {
			    StrAllocCat(ranges, ", ");
			    after += 2;
			}
			after += (int) strlen(value) + 2;
			if ((before / LYcols) != (after / LYcols)) {
			    wrapped += (LYcols - (before % LYcols));
			    HTSprintf(&ranges, "\n%-*s", hanging, " ");
			}
			StrAllocCat(ranges, value);
		    }
		}
		if (non_empty(ranges)) {
		    LYEntify(&ranges, TRUE);
		    HTSprintf0(&buf, FORMAT,
			       width[0], mp->name,
			       width[1], mp->descr,
			       ranges);
		    PUTS(buf);
		    FREE(ranges);
		    had_output = TRUE;
		}
	    }
	}

	HTSprintf0(&buf, "</pre>\n</body>\n</html>\n");
	PUTS(buf);

	(*target->isa->_free) (target);
	result = HT_LOADED;
    } else {
	HTSprintf0(&buf, CANNOT_CONVERT_I_TO_O,
		   HTAtom_name(format_in), HTAtom_name(format_out));
	HTAlert(buf);
	result = HT_NOT_LOADED;
    }
    FREE(ranges);
    FREE(buf);
    return result;
#undef FORMAT
}

#ifdef GLOBALDEF_IS_MACRO
#define _LYEDITMAP_C_GLOBALDEF_1_INIT { "LYNXEDITMAP", LYLoadEditmap, 0}
GLOBALDEF(HTProtocol, LYLynxEditmap, _LYEDITMAP_C_GLOBALDEF_1_INIT);
#else
GLOBALDEF HTProtocol LYLynxEditmap =
{
    "LYNXEDITMAP", LYLoadEditmap, 0
};
#endif /* GLOBALDEF_IS_MACRO */
="nv">duplex-list <- get-address *editor, before-cursor:offset init:address:duplex-list <- get *editor, data:offset # while not at start of line, move { at-start-of-text?:boolean <- equal *before-cursor, init break-if at-start-of-text? prev:character <- get **before-cursor, value:offset at-start-of-line?:boolean <- equal prev, 10/newline break-if at-start-of-line? *before-cursor <- prev-duplex *before-cursor assert *before-cursor, [move-to-start-of-line tried to move before start of text] loop } ] recipe move-to-end-of-line [ local-scope editor:address:editor-data <- next-ingredient before-cursor:address:address:duplex-list <- get-address *editor, before-cursor:offset cursor-column:address:number <- get-address *editor, cursor-column:offset # while not at start of line, move { next:address:duplex-list <- next-duplex *before-cursor break-unless next # end of text nextc:character <- get *next, value:offset at-end-of-line?:boolean <- equal nextc, 10/newline break-if at-end-of-line? *before-cursor <- copy next *cursor-column <- add *cursor-column, 1 loop } # move one past final character *cursor-column <- add *cursor-column, 1 ] recipe delete-to-start-of-line [ local-scope editor:address:editor-data <- next-ingredient # compute range to delete init:address:duplex-list <- get *editor, data:offset before-cursor:address:address:duplex-list <- get-address *editor, before-cursor:offset start:address:duplex-list <- copy *before-cursor end:address:duplex-list <- next-duplex *before-cursor { at-start-of-text?:boolean <- equal start, init break-if at-start-of-text? curr:character <- get *start, value:offset at-start-of-line?:boolean <- equal curr, 10/newline break-if at-start-of-line? start <- prev-duplex start assert start, [delete-to-start-of-line tried to move before start of text] loop } # snip it out start-next:address:address:duplex-list <- get-address *start, next:offset *start-next <- copy end end-prev:address:address:duplex-list <- get-address *end, prev:offset *end-prev <- copy start # adjust cursor *before-cursor <- prev-duplex end left:number <- get *editor, left:offset cursor-column:address:number <- get-address *editor, cursor-column:offset *cursor-column <- copy left ] recipe delete-to-end-of-line [ local-scope editor:address:editor-data <- next-ingredient # compute range to delete start:address:duplex-list <- get *editor, before-cursor:offset end:address:duplex-list <- next-duplex start { at-end-of-text?:boolean <- equal end, 0/null break-if at-end-of-text? curr:character <- get *end, value:offset at-end-of-line?:boolean <- equal curr, 10/newline break-if at-end-of-line? end <- next-duplex end loop } # snip it out start-next:address:address:duplex-list <- get-address *start, next:offset *start-next <- copy end { break-unless end end-prev:address:address:duplex-list <- get-address *end, prev:offset *end-prev <- copy start } ] scenario editor-handles-empty-event-queue [ assume-screen 10/width, 5/height 1:address:array:character <- new [abc] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right assume-console [] run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] screen-should-contain [ . . .abc . . . ] ] scenario editor-handles-mouse-clicks [ assume-screen 10/width, 5/height 1:address:array:character <- new [abc] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right assume-console [ left-click 1, 1 # on the 'b' ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data 3:number <- get *2:address:editor-data, cursor-row:offset 4:number <- get *2:address:editor-data, cursor-column:offset ] screen-should-contain [ . . .abc . . . ] memory-should-contain [ 3 <- 1 # cursor is at row 0.. 4 <- 1 # ..and column 1 ] ] scenario editor-handles-mouse-clicks-outside-text [ assume-screen 10/width, 5/height 1:address:array:character <- new [abc] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right assume-console [ left-click 1, 7 # last line, to the right of text ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data 3:number <- get *2:address:editor-data, cursor-row:offset 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 1 # cursor row 4 <- 3 # cursor column ] ] scenario editor-handles-mouse-clicks-outside-text-2 [ assume-screen 10/width, 5/height 1:address:array:character <- new [abc def] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right assume-console [ left-click 1, 7 # interior line, to the right of text ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data 3:number <- get *2:address:editor-data, cursor-row:offset 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 1 # cursor row 4 <- 3 # cursor column ] ] scenario editor-handles-mouse-clicks-outside-text-3 [ assume-screen 10/width, 5/height 1:address:array:character <- new [abc def] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right assume-console [ left-click 3, 7 # below text ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data 3:number <- get *2:address:editor-data, cursor-row:offset 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 2 # cursor row 4 <- 3 # cursor column ] ] scenario editor-handles-mouse-clicks-outside-column [ assume-screen 10/width, 5/height 1:address:array:character <- new [abc] # editor occupies only left half of screen 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 5/right assume-console [ # click on right half of screen left-click 3, 8 ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data 3:number <- get *2:address:editor-data, cursor-row:offset 4:number <- get *2:address:editor-data, cursor-column:offset ] screen-should-contain [ . . .abc . . . ] memory-should-contain [ 3 <- 1 # no change to cursor row 4 <- 0 # ..or column ] ] scenario editor-inserts-characters-into-empty-editor [ assume-screen 10/width, 5/height 1:address:array:character <- new [] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 5/right assume-console [ type [abc] ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] screen-should-contain [ . . .abc . . . ] ] scenario editor-inserts-characters-at-cursor [ assume-screen 10/width, 5/height 1:address:array:character <- new [abc] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right assume-console [ type [0] left-click 1, 2 type [d] ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] screen-should-contain [ . . .0adbc . . . ] ] scenario editor-inserts-characters-at-cursor-2 [ assume-screen 10/width, 5/height 1:address:array:character <- new [abc] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right assume-console [ left-click 1, 5 # right of last line type [d] # should append ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] screen-should-contain [ . . .abcd . . . ] ] scenario editor-inserts-characters-at-cursor-3 [ assume-screen 10/width, 5/height 1:address:array:character <- new [abc] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right assume-console [ left-click 3, 5 # below all text type [d] # should append ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] screen-should-contain [ . . .abcd . . . ] ] scenario editor-inserts-characters-at-cursor-4 [ assume-screen 10/width, 5/height 1:address:array:character <- new [abc d] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right assume-console [ left-click 3, 5 # below all text type [e] # should append ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] screen-should-contain [ . . .abc . .de . . . ] ] scenario editor-inserts-characters-at-cursor-5 [ assume-screen 10/width, 5/height 1:address:array:character <- new [abc d] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right assume-console [ left-click 3, 5 # below all text type [ef] # should append multiple characters in order ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] screen-should-contain [ . . .abc . .def . . . ] ] scenario editor-wraps-line-on-insert [ assume-screen 5/width, 5/height 1:address:array:character <- new [abc] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 5/right # type a letter assume-console [ type [e] ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] # no wrap yet screen-should-contain [ . . .eabc . . . . . ] # type a second letter assume-console [ type [f] ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] # now wrap screen-should-contain [ . . .efab. .c . . . ] ] scenario editor-moves-cursor-after-inserting-characters [ assume-screen 10/width, 5/height 1:address:array:character <- new [ab] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 5/right assume-console [ type [01] ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] screen-should-contain [ . . .01ab . . . ] ] scenario editor-wraps-cursor-after-inserting-characters [ assume-screen 10/width, 5/height 1:address:array:character <- new [abcde] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 5/right assume-console [ left-click 1, 4 # line is full; no wrap icon yet type [f] ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data 3:number <- get *2:address:editor-data, cursor-row:offset 4:number <- get *2:address:editor-data, cursor-column:offset ] screen-should-contain [ . . .abcd . .fe . . . ] memory-should-contain [ 3 <- 2 # cursor row 4 <- 1 # cursor column ] ] scenario editor-wraps-cursor-after-inserting-characters-2 [ assume-screen 10/width, 5/height 1:address:array:character <- new [abcde] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 5/right assume-console [ left-click 1, 3 # right before the wrap icon type [f] ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data 3:number <- get *2:address:editor-data, cursor-row:offset 4:number <- get *2:address:editor-data, cursor-column:offset ] screen-should-contain [ . . .abcf . .de . . . ] memory-should-contain [ 3 <- 2 # cursor row 4 <- 0 # cursor column ] ] scenario editor-moves-cursor-down-after-inserting-newline [ assume-screen 10/width, 5/height 1:address:array:character <- new [abc] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right assume-console [ type [0 1] ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] screen-should-contain [ . . .0 . .1abc . . . ] ] scenario editor-moves-cursor-down-after-inserting-newline-2 [ assume-screen 10/width, 5/height 1:address:array:character <- new [abc] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 1/left, 10/right assume-console [ type [0 1] ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] screen-should-contain [ . . . 0 . . 1abc . . . ] ] scenario editor-clears-previous-line-completely-after-inserting-newline [ assume-screen 10/width, 5/height 1:address:array:character <- new [abcde] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 5/right # press just a 'newline' assume-console [ type [ ] ] screen-should-contain [ . . .abcd . .e . . . . . ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] # line should be fully cleared screen-should-contain [ . . . . .abcd . .e . . . ] ] scenario editor-inserts-indent-after-newline [ assume-screen 10/width, 10/height 1:address:array:character <- new [ab cd ef] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right # position cursor after 'cd' and hit 'newline' assume-console [ left-click 2, 8 type [ ] ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data 3:number <- get *2:address:editor-data, cursor-row:offset 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor should be below start of previous line memory-should-contain [ 3 <- 3 # cursor row 4 <- 2 # cursor column (indented) ] ] scenario editor-handles-backspace-key [ assume-screen 10/width, 5/height 1:address:array:character <- new [abc] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right assume-console [ left-click 1, 1 type [«] ] 3:event/backspace <- merge 0/text, 8/backspace, 0/dummy, 0/dummy replace-in-console 171/«, 3:event/backspace run [ editor-event-loop screen:address, console:address, 2:address:editor-data 4:number <- get *2:address:editor-data, cursor-row:offset 5:number <- get *2:address:editor-data, cursor-column:offset ] screen-should-contain [ . . .bc . . . ] memory-should-contain [ 4 <- 1 5 <- 0 ] ] scenario editor-clears-last-line-on-backspace [ assume-screen 10/width, 5/height # just one character in final line 1:address:array:character <- new [ab cd] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right assume-console [ left-click 2, 0 # cursor at only character in final line type [«] ] 3:event/backspace <- merge 0/text, 8/backspace, 0/dummy, 0/dummy replace-in-console 171/«, 3:event/backspace run [ editor-event-loop screen:address, console:address, 2:address:editor-data 4:number <- get *2:address:editor-data, cursor-row:offset 5:number <- get *2:address:editor-data, cursor-column:offset ] screen-should-contain [ . . .abcd . . . ] memory-should-contain [ 4 <- 1 5 <- 2 ] ] scenario editor-inserts-two-spaces-on-tab [ assume-screen 10/width, 5/height # just one character in final line 1:address:array:character <- new [ab cd] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 5/right assume-console [ type [»] ] 3:event/tab <- merge 0/text, 9/tab, 0/dummy, 0/dummy replace-in-console 187/», 3:event/tab run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] screen-should-contain [ . . . ab . .cd . ] ] scenario editor-moves-cursor-right-with-key [ assume-screen 10/width, 5/height 1:address:array:character <- new [abc] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right assume-console [ press 65514 # right arrow type [0] ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] screen-should-contain [ . . .a0bc . . . ] ] scenario editor-moves-cursor-to-next-line-with-right-arrow [ assume-screen 10/width, 5/height 1:address:array:character <- new [abc d] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right assume-console [ press 65514 # right arrow press 65514 # right arrow press 65514 # right arrow press 65514 # right arrow - next line type [0] ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] screen-should-contain [ . . .abc . .0d . . . ] ] scenario editor-moves-cursor-to-next-line-with-right-arrow-2 [ assume-screen 10/width, 5/height 1:address:array:character <- new [abc d] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 1/left, 10/right assume-console [ press 65514 # right arrow press 65514 # right arrow press 65514 # right arrow press 65514 # right arrow - next line type [0] ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] screen-should-contain [ . . . abc . . 0d . . . ] ] scenario editor-moves-cursor-to-next-wrapped-line-with-right-arrow [ assume-screen 10/width, 5/height 1:address:array:character <- new [abcdef] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 5/right assume-console [ left-click 1, 3 press 65514 # right arrow ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data 3:number <- get *2:address:editor-data, cursor-row:offset 4:number <- get *2:address:editor-data, cursor-column:offset ] screen-should-contain [ . . .abcd . .ef . . . ] memory-should-contain [ 3 <- 2 4 <- 0 ] ] scenario editor-moves-cursor-to-next-wrapped-line-with-right-arrow-2 [ assume-screen 10/width, 5/height # line just barely wrapping 1:address:array:character <- new [abcde] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 5/right # position cursor at last character before wrap and hit right-arrow assume-console [ left-click 1, 3 press 65514 # right arrow ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data 3:number <- get *2:address:editor-data, cursor-row:offset 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 2 4 <- 0 ] # now hit right arrow again assume-console [ press 65514 ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data 3:number <- get *2:address:editor-data, cursor-row:offset 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 2 4 <- 1 ] ] scenario editor-moves-cursor-to-next-wrapped-line-with-right-arrow-3 [ assume-screen 10/width, 5/height 1:address:array:character <- new [abcdef] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 1/left, 6/right assume-console [ left-click 1, 4 press 65514 # right arrow ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data 3:number <- get *2:address:editor-data, cursor-row:offset 4:number <- get *2:address:editor-data, cursor-column:offset ] screen-should-contain [ . . . abcd . . ef . . . ] memory-should-contain [ 3 <- 2 4 <- 1 ] ] scenario editor-moves-cursor-to-next-line-with-right-arrow-at-end-of-line [ assume-screen 10/width, 5/height 1:address:array:character <- new [abc d] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right assume-console [ left-click 1, 3 press 65514 # right arrow - next line type [0] ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] screen-should-contain [ . . .abc . .0d . . . ] ] scenario editor-moves-cursor-left-with-key [ assume-screen 10/width, 5/height 1:address:array:character <- new [abc] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right assume-console [ left-click 1, 2 press 65515 # left arrow type [0] ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] screen-should-contain [ . . .a0bc . . . ] ] scenario editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line [ assume-screen 10/width, 5/height # initialize editor with two lines 1:address:array:character <- new [abc d] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right # position cursor at start of second line (so there's no previous newline) assume-console [ left-click 2, 0 press 65515 # left arrow ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data 3:number <- get *2:address:editor-data, cursor-row:offset 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 1 4 <- 3 ] ] scenario editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line-2 [ assume-screen 10/width, 5/height # initialize editor with three lines 1:address:array:character <- new [abc def g] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right # position cursor further down (so there's a newline before the character at # the cursor) assume-console [ left-click 3, 0 press 65515 # left arrow type [0] ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] screen-should-contain [ . . .abc . .def0 . .g . . . ] ] scenario editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line-3 [ assume-screen 10/width, 5/height 1:address:array:character <- new [abc def g] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right # position cursor at start of text assume-console [ left-click 1, 0 press 65515 # left arrow should have no effect type [0] ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] screen-should-contain [ . . .0abc . .def . .g . . . ] ] scenario editor-moves-cursor-to-previous-line-with-left-arrow-at-start-of-line-4 [ assume-screen 10/width, 5/height # initialize editor with text containing an empty line 1:address:array:character <- new [abc d] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right # position cursor right after empty line assume-console [ left-click 3, 0 press 65515 # left arrow type [0] ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] screen-should-contain [ . . .abc . .0 . .d . . . ] ] scenario editor-moves-across-screen-lines-across-wrap-with-left-arrow [ assume-screen 10/width, 5/height # initialize editor with text containing an empty line 1:address:array:character <- new [abcdef] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 5/right screen-should-contain [ . . .abcd . .ef . . . ] # position cursor right after empty line assume-console [ left-click 2, 0 press 65515 # left arrow ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data 3:number <- get *2:address:editor-data, cursor-row:offset 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 1 # previous row 4 <- 3 # end of wrapped line ] ] scenario editor-moves-to-previous-line-with-up-arrow [ assume-screen 10/width, 5/height 1:address:array:character <- new [abc def] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right assume-console [ left-click 2, 1 press 65517 # up arrow ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data 3:number <- get *2:address:editor-data, cursor-row:offset 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 1 4 <- 1 ] ] scenario editor-moves-to-next-line-with-down-arrow [ assume-screen 10/width, 5/height 1:address:array:character <- new [abc def] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right # cursor starts out at (1, 0) assume-console [ press 65516 # down arrow ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data 3:number <- get *2:address:editor-data, cursor-row:offset 4:number <- get *2:address:editor-data, cursor-column:offset ] # ..and ends at (2, 0) memory-should-contain [ 3 <- 2 4 <- 0 ] ] scenario editor-adjusts-column-at-previous-line [ assume-screen 10/width, 5/height 1:address:array:character <- new [ab def] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right assume-console [ left-click 2, 3 press 65517 # up arrow ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data 3:number <- get *2:address:editor-data, cursor-row:offset 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 1 4 <- 2 ] ] scenario editor-adjusts-column-at-next-line [ assume-screen 10/width, 5/height 1:address:array:character <- new [abc de] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right assume-console [ left-click 1, 3 press 65516 # down arrow ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data 3:number <- get *2:address:editor-data, cursor-row:offset 4:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 3 <- 2 4 <- 2 ] ] scenario editor-moves-to-start-of-line-with-ctrl-a [ assume-screen 10/width, 5/height 1:address:array:character <- new [123 456] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right # start on second line, press ctrl-a assume-console [ left-click 2, 3 type [a] # ctrl-a ] 3:event/ctrl-a <- merge 0/text, 1/ctrl-a, 0/dummy, 0/dummy replace-in-console 97/a, 3:event/ctrl-a run [ editor-event-loop screen:address, console:address, 2:address:editor-data 4:number <- get *2:address:editor-data, cursor-row:offset 5:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves to start of line memory-should-contain [ 4 <- 2 5 <- 0 ] ] scenario editor-moves-to-start-of-line-with-ctrl-a-2 [ assume-screen 10/width, 5/height 1:address:array:character <- new [123 456] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right # start on first line (no newline before), press ctrl-a assume-console [ left-click 1, 3 type [a] # ctrl-a ] 3:event/ctrl-a <- merge 0/text, 1/ctrl-a, 0/dummy, 0/dummy replace-in-console 97/a, 3:event/ctrl-a run [ editor-event-loop screen:address, console:address, 2:address:editor-data 4:number <- get *2:address:editor-data, cursor-row:offset 5:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves to start of line memory-should-contain [ 4 <- 1 5 <- 0 ] ] scenario editor-moves-to-start-of-line-with-home [ assume-screen 10/width, 5/height 1:address:array:character <- new [123 456] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right # start on second line, press 'home' assume-console [ left-click 2, 3 press 65521 # 'home' ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data 3:number <- get *2:address:editor-data, cursor-row:offset 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves to start of line memory-should-contain [ 3 <- 2 4 <- 0 ] ] scenario editor-moves-to-start-of-line-with-home-2 [ assume-screen 10/width, 5/height 1:address:array:character <- new [123 456] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right # start on first line (no newline before), press 'home' assume-console [ left-click 1, 3 press 65521 # 'home' ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data 3:number <- get *2:address:editor-data, cursor-row:offset 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves to start of line memory-should-contain [ 3 <- 1 4 <- 0 ] ] scenario editor-moves-to-start-of-line-with-ctrl-e [ assume-screen 10/width, 5/height 1:address:array:character <- new [123 456] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right # start on first line, press ctrl-e assume-console [ left-click 1, 1 type [e] # ctrl-e ] 3:event/ctrl-e <- merge 0/text, 5/ctrl-e, 0/dummy, 0/dummy replace-in-console 101/e, 3:event/ctrl-e run [ editor-event-loop screen:address, console:address, 2:address:editor-data 4:number <- get *2:address:editor-data, cursor-row:offset 5:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves to end of line memory-should-contain [ 4 <- 1 5 <- 3 ] # editor inserts future characters at cursor assume-console [ type [z] ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data 4:number <- get *2:address:editor-data, cursor-row:offset 5:number <- get *2:address:editor-data, cursor-column:offset ] memory-should-contain [ 4 <- 1 5 <- 4 ] screen-should-contain [ . . .123z . .456 . . . ] ] scenario editor-moves-to-end-of-line-with-ctrl-e-2 [ assume-screen 10/width, 5/height 1:address:array:character <- new [123 456] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right # start on second line (no newline after), press ctrl-e assume-console [ left-click 2, 1 type [e] # ctrl-e ] 3:event/ctrl-e <- merge 0/text, 5/ctrl-e, 0/dummy, 0/dummy replace-in-console 101/e, 3:event/ctrl-e run [ editor-event-loop screen:address, console:address, 2:address:editor-data 4:number <- get *2:address:editor-data, cursor-row:offset 5:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves to end of line memory-should-contain [ 4 <- 2 5 <- 3 ] ] scenario editor-moves-to-end-of-line-with-end [ assume-screen 10/width, 5/height 1:address:array:character <- new [123 456] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right # start on first line, press 'end' assume-console [ left-click 1, 1 press 65520 # 'end' ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data 3:number <- get *2:address:editor-data, cursor-row:offset 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves to end of line memory-should-contain [ 3 <- 1 4 <- 3 ] ] scenario editor-moves-to-end-of-line-with-end-2 [ assume-screen 10/width, 5/height 1:address:array:character <- new [123 456] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right # start on second line (no newline after), press 'end' assume-console [ left-click 2, 1 press 65520 # 'end' ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data 3:number <- get *2:address:editor-data, cursor-row:offset 4:number <- get *2:address:editor-data, cursor-column:offset ] # cursor moves to end of line memory-should-contain [ 3 <- 2 4 <- 3 ] ] scenario editor-deletes-to-start-of-line-with-ctrl-u [ assume-screen 10/width, 5/height 1:address:array:character <- new [123 456] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right # start on second line, press ctrl-u assume-console [ left-click 2, 2 type [u] # ctrl-u ] 3:event/ctrl-a <- merge 0/text, 21/ctrl-u, 0/dummy, 0/dummy replace-in-console 117/u, 3:event/ctrl-u run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] # cursor deletes to start of line screen-should-contain [ . . .123 . .6 . . . ] ] scenario editor-deletes-to-start-of-line-with-ctrl-u-2 [ assume-screen 10/width, 5/height 1:address:array:character <- new [123 456] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right # start on first line (no newline before), press ctrl-u assume-console [ left-click 1, 2 type [u] # ctrl-u ] 3:event/ctrl-u <- merge 0/text, 21/ctrl-a, 0/dummy, 0/dummy replace-in-console 117/a, 3:event/ctrl-u run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] # cursor deletes to start of line screen-should-contain [ . . .3 . .456 . . . ] ] scenario editor-deletes-to-start-of-line-with-ctrl-u-3 [ assume-screen 10/width, 5/height 1:address:array:character <- new [123 456] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right # start past end of line, press ctrl-u assume-console [ left-click 1, 3 type [u] # ctrl-u ] 3:event/ctrl-u <- merge 0/text, 21/ctrl-a, 0/dummy, 0/dummy replace-in-console 117/a, 3:event/ctrl-u run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] # cursor deletes to start of line screen-should-contain [ . . . . .456 . . . ] ] scenario editor-deletes-to-end-of-line-with-ctrl-k [ assume-screen 10/width, 5/height 1:address:array:character <- new [123 456] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right # start on first line, press ctrl-k assume-console [ left-click 1, 1 type [k] # ctrl-k ] 3:event/ctrl-k <- merge 0/text, 11/ctrl-k, 0/dummy, 0/dummy replace-in-console 107/k, 3:event/ctrl-k run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] # cursor deletes to end of line screen-should-contain [ . . .1 . .456 . . . ] ] scenario editor-deletes-to-end-of-line-with-ctrl-k-2 [ assume-screen 10/width, 5/height 1:address:array:character <- new [123 456] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right # start on second line (no newline after), press ctrl-k assume-console [ left-click 2, 1 type [k] # ctrl-k ] 3:event/ctrl-k <- merge 0/text, 11/ctrl-k, 0/dummy, 0/dummy replace-in-console 107/k, 3:event/ctrl-k run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] # cursor deletes to end of line screen-should-contain [ . . .123 . .4 . . . ] ] scenario editor-deletes-to-end-of-line-with-ctrl-k-3 [ assume-screen 10/width, 5/height 1:address:array:character <- new [123 456] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right # start at end of line assume-console [ left-click 1, 2 type [k] # ctrl-k ] 3:event/ctrl-k <- merge 0/text, 11/ctrl-k, 0/dummy, 0/dummy replace-in-console 107/k, 3:event/ctrl-k run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] # cursor deletes to end of line screen-should-contain [ . . .12 . .456 . . . ] ] scenario editor-deletes-to-end-of-line-with-ctrl-k-4 [ assume-screen 10/width, 5/height 1:address:array:character <- new [123 456] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right # start past end of line assume-console [ left-click 1, 3 type [k] # ctrl-k ] 3:event/ctrl-k <- merge 0/text, 11/ctrl-k, 0/dummy, 0/dummy replace-in-console 107/k, 3:event/ctrl-k run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] # cursor deletes to end of line screen-should-contain [ . . .123 . .456 . . . ] ] scenario editor-deletes-to-end-of-line-with-ctrl-k-5 [ assume-screen 10/width, 5/height 1:address:array:character <- new [123 456] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right # start at end of text assume-console [ left-click 2, 2 type [k] # ctrl-k ] 3:event/ctrl-k <- merge 0/text, 11/ctrl-k, 0/dummy, 0/dummy replace-in-console 107/k, 3:event/ctrl-k run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] # cursor deletes to end of line screen-should-contain [ . . .123 . .45 . . . ] ] scenario editor-deletes-to-end-of-line-with-ctrl-k-6 [ assume-screen 10/width, 5/height 1:address:array:character <- new [123 456] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right # start past end of text assume-console [ left-click 2, 3 type [k] # ctrl-k ] 3:event/ctrl-k <- merge 0/text, 11/ctrl-k, 0/dummy, 0/dummy replace-in-console 107/k, 3:event/ctrl-k run [ editor-event-loop screen:address, console:address, 2:address:editor-data ] # cursor deletes to end of line screen-should-contain [ . . .123 . .456 . . . ] ] ## putting the environment together out of editors container programming-environment-data [ recipes:address:editor-data recipe-warnings:address:array:character current-sandbox:address:editor-data sandbox:address:sandbox-data # list of sandboxes, from top to bottom sandbox-in-focus?:boolean # false => cursor in recipes; true => cursor in current-sandbox ] recipe new-programming-environment [ local-scope screen:address <- next-ingredient initial-recipe-contents:address:array:character <- next-ingredient initial-sandbox-contents:address:array:character <- next-ingredient width:number <- screen-width screen height:number <- screen-height screen # top menu result:address:programming-environment-data <- new programming-environment-data:type draw-horizontal screen, 0, 0/left, width, 32/space, 0/black, 238/grey button-start:number <- subtract width, 20 button-on-screen?:boolean <- greater-or-equal button-start, 0 assert button-on-screen?, [screen too narrow for menu] move-cursor screen, 0/row, button-start run-button:address:array:character <- new [ run (F4) ] print-string screen, run-button, 255/white, 161/reddish # dotted line down the middle divider:number, _ <- divide-with-remainder width, 2 draw-vertical screen, divider, 1/top, height, 9482/vertical-dotted # recipe editor on the left recipes:address:address:editor-data <- get-address *result, recipes:offset *recipes <- new-editor initial-recipe-contents, screen, 0/left, divider/right # sandbox editor on the right new-left:number <- add divider, 1 new-right:number <- add new-left, 5 current-sandbox:address:address:editor-data <- get-address *result, current-sandbox:offset *current-sandbox <- new-editor initial-sandbox-contents, screen, new-left, width/right screen <- render-all screen, result reply result ] recipe event-loop [ local-scope screen:address <- next-ingredient console:address <- next-ingredient env:address:programming-environment-data <- next-ingredient recipes:address:editor-data <- get *env, recipes:offset current-sandbox:address:editor-data <- get *env, current-sandbox:offset sandbox-in-focus?:address:boolean <- get-address *env, sandbox-in-focus?:offset { # looping over each (keyboard or touch) event as it occurs +next-event e:event, console, found?:boolean, quit?:boolean <- read-event console loop-unless found? break-if quit? # only in tests trace [app], [next-event] # check for global events that will trigger regardless of which editor has focus { k:address:number <- maybe-convert e:event, keycode:variant break-unless k +global-keypress } { c:address:character <- maybe-convert e:event, text:variant break-unless c +global-type # ctrl-n? - switch focus { ctrl-n?:boolean <- equal *c, 14/ctrl-n break-unless ctrl-n? *sandbox-in-focus? <- not *sandbox-in-focus? update-cursor screen, recipes, current-sandbox, *sandbox-in-focus? show-screen screen loop +next-event:label } } # 'touch' event - send to both sides, see what picks it up { t:address:touch-event <- maybe-convert e:event, touch:variant break-unless t # ignore all but 'left-click' events for now # todo: test this touch-type:number <- get *t, type:offset is-left-click?:boolean <- equal touch-type, 65513/mouse-left loop-unless is-left-click?, +next-event:label # later exceptions for non-editor touches will go here +global-touch # send to both editors _ <- move-cursor-in-editor screen, recipes, *t *sandbox-in-focus? <- move-cursor-in-editor screen, current-sandbox, *t render-minimal screen, env loop +next-event:label } # if it's not global and not a touch event, send to appropriate editor { { break-if *sandbox-in-focus? handle-event screen, console, recipes, e:event } { break-unless *sandbox-in-focus? handle-event screen, console, current-sandbox, e:event } # optimization: refresh screen only if no more events # todo: test this more-events?:boolean <- has-more-events? console break-if more-events? render-minimal screen, env } loop } ] scenario point-at-multiple-editors [ $close-trace assume-screen 30/width, 5/height # initialize both halves of screen 1:address:array:character <- new [abc] 2:address:array:character <- new [def] 3:address:programming-environment-data <- new-programming-environment screen:address, 1:address:array:character, 2:address:array:character # focus on both sides assume-console [ left-click 1, 1 left-click 1, 17 ] # check cursor column in each run [ event-loop screen:address, console:address, 3:address:programming-environment-data 4:address:editor-data <- get *3:address:programming-environment-data, recipes:offset 5:number <- get *4:address:editor-data, cursor-column:offset 6:address:editor-data <- get *3:address:programming-environment-data, current-sandbox:offset 7:number <- get *6:address:editor-data, cursor-column:offset ] memory-should-contain [ 5 <- 1 7 <- 17 ] ] scenario edit-multiple-editors [ $close-trace assume-screen 30/width, 5/height # initialize both halves of screen 1:address:array:character <- new [abc] 2:address:array:character <- new [def] 3:address:programming-environment-data <- new-programming-environment screen:address, 1:address:array:character, 2:address:array:character # type one letter in each of them assume-console [ left-click 1, 1 type [0] left-click 1, 17 type [1] ] run [ event-loop screen:address, console:address, 3:address:programming-environment-data 4:address:editor-data <- get *3:address:programming-environment-data, recipes:offset 5:number <- get *4:address:editor-data, cursor-column:offset 6:address:editor-data <- get *3:address:programming-environment-data, current-sandbox:offset 7:number <- get *6:address:editor-data, cursor-column:offset ] screen-should-contain [ . run (F4) . # this line has a different background, but we don't test that yet .a0bc d1ef . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━. . . ] memory-should-contain [ 5 <- 2 # cursor column of recipe editor 7 <- 18 # cursor column of sandbox editor ] # show the cursor at the right window run [ screen:address <- print-character screen:address, 9251/ ] screen-should-contain [ . run (F4) . .a0bc d1f . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━. . . ] ] scenario multiple-editors-cover-only-their-own-areas [ $close-trace assume-screen 60/width, 10/height run [ 1:address:array:character <- new [abc] 2:address:array:character <- new [def] 3:address:programming-environment-data <- new-programming-environment screen:address, 1:address:array:character, 2:address:array:character ] # divider isn't messed up screen-should-contain [ . run (F4) . .abc def . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . . . . ] ] scenario editor-in-focus-keeps-cursor [ $close-trace assume-screen 30/width, 5/height 1:address:array:character <- new [abc] 2:address:array:character <- new [def] # initialize programming environment and highlight cursor assume-console [] run [ 3:address:programming-environment-data <- new-programming-environment screen:address, 1:address:array:character, 2:address:array:character event-loop screen:address, console:address, 3:address:programming-environment-data screen:address <- print-character screen:address, 9251/ ] # is cursor at the right place? screen-should-contain [ . run (F4) . .bc def . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━. . . ] # now try typing a letter assume-console [ type [z] ] run [ 3:address:programming-environment-data <- new-programming-environment screen:address, 1:address:array:character, 2:address:array:character event-loop screen:address, console:address, 3:address:programming-environment-data screen:address <- print-character screen:address, 9251/ ] # cursor should still be right screen-should-contain [ . run (F4) . .zbc def . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━. . . ] ] recipe render-all [ local-scope screen:address <- next-ingredient env:address:programming-environment-data <- next-ingredient screen <- render-recipes screen, env screen <- render-sandbox-side screen, env recipes:address:editor-data <- get *env, recipes:offset current-sandbox:address:editor-data <- get *env, current-sandbox:offset sandbox-in-focus?:boolean <- get *env, sandbox-in-focus?:offset update-cursor screen, recipes, current-sandbox, sandbox-in-focus? show-screen screen reply screen/same-as-ingredient:0 ] recipe render-minimal [ local-scope screen:address <- next-ingredient env:address:programming-environment-data <- next-ingredient recipes:address:editor-data <- get *env, recipes:offset current-sandbox:address:editor-data <- get *env, current-sandbox:offset sandbox-in-focus?:boolean <- get *env, sandbox-in-focus?:offset { break-if sandbox-in-focus? screen <- render-recipes screen, env cursor-row:number <- get *recipes, cursor-row:offset cursor-column:number <- get *recipes, cursor-column:offset } { break-unless sandbox-in-focus? screen <- render-sandbox-side screen, env cursor-row:number <- get *current-sandbox, cursor-row:offset cursor-column:number <- get *current-sandbox, cursor-column:offset } move-cursor screen, cursor-row, cursor-column show-screen screen reply screen/same-as-ingredient:0 ] recipe render-recipes [ local-scope screen:address <- next-ingredient env:address:programming-environment-data <- next-ingredient recipes:address:editor-data <- get *env, recipes:offset # render recipes left:number <- get *recipes, left:offset right:number <- get *recipes, right:offset row:number, screen <- render screen, recipes recipe-warnings:address:array:character <- get *env, recipe-warnings:offset { # print any warnings break-unless recipe-warnings row, screen <- render-string screen, recipe-warnings, left, right, 1/red, row } { # no warnings? move to next line break-if recipe-warnings row <- add row, 1 } # draw dotted line after recipes draw-horizontal screen, row, left, right, 9480/horizontal-dotted # clear rest of screen row <- add row, 1 move-cursor screen, row, left screen-height:number <- screen-height screen { at-bottom-of-screen?:boolean <- greater-or-equal row, screen-height break-if at-bottom-of-screen? move-cursor screen, row, left clear-line-delimited screen, left, right row <- add row, 1 loop } reply screen/same-as-ingredient:0 ] # helper for testing a single editor recipe update-cursor [ local-scope screen:address <- next-ingredient recipes:address:editor-data <- next-ingredient current-sandbox:address:editor-data <- next-ingredient sandbox-in-focus?:boolean <- next-ingredient { break-if sandbox-in-focus? #? $print [recipes in focus #? ] #? 1 cursor-row:number <- get *recipes, cursor-row:offset cursor-column:number <- get *recipes, cursor-column:offset } { break-unless sandbox-in-focus? #? $print [sandboxes in focus #? ] #? 1 cursor-row:number <- get *current-sandbox, cursor-row:offset cursor-column:number <- get *current-sandbox, cursor-column:offset } move-cursor screen, cursor-row, cursor-column ] ## running code from the editor and creating sandboxes container sandbox-data [ data:address:array:character response:address:array:character warnings:address:array:character expected-response:address:array:character # coordinates to track clicks starting-row-on-screen:number response-starting-row-on-screen:number screen:address:screen # prints in the sandbox go here next-sandbox:address:sandbox-data ] scenario run-and-show-results [ $close-trace # trace too long for github assume-screen 100/width, 15/height # recipe editor is empty 1:address:array:character <- new [] # sandbox editor contains an instruction without storing outputs 2:address:array:character <- new [divide-with-remainder 11, 3] 3:address:programming-environment-data <- new-programming-environment screen:address, 1:address:array:character, 2:address:array:character # run the code in the editors assume-console [ press 65532 # F4 ] run [ event-loop screen:address, console:address, 3:address:programming-environment-data ] # check that screen prints the results screen-should-contain [ . run (F4) . . . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . x. . divide-with-remainder 11, 3 . . 3 . . 2 . . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . . ] screen-should-contain-in-color 7/white, [ . . . . . . . . . divide-with-remainder 11, 3 . . . . . . . . . ] screen-should-contain-in-color 245/grey, [ . . . . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . x. . . . 3 . . 2 . . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . . ] # run another command assume-console [ left-click 1, 80 type [add 2, 2] press 65532 # F4 ] run [ event-loop screen:address, console:address, 3:address:programming-environment-data ] # check that screen prints the results screen-should-contain [ . run (F4) . . . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . x. . add 2, 2 . . 4 . . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . x. . divide-with-remainder 11, 3 . . 3 . . 2 . . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . . ] ] # hook into event-loop recipe: read non-unicode keypress from k, process it if # necessary, then go to next level after +global-keypress [ # F4? load all code and run all sandboxes. { do-run?:boolean <- equal *k, 65532/F4 break-unless do-run? run-sandboxes env # F4 might update warnings and results on both sides screen <- render-all screen, env update-cursor screen, recipes, current-sandbox, *sandbox-in-focus? show-screen screen loop +next-event:label } ] recipe run-sandboxes [ local-scope env:address:programming-environment-data <- next-ingredient recipes:address:editor-data <- get *env, recipes:offset # copy code from recipe editor, persist, load into mu, save any warnings in:address:array:character <- editor-contents recipes save [recipes.mu], in recipe-warnings:address:address:array:character <- get-address *env, recipe-warnings:offset *recipe-warnings <- reload in # if recipe editor has errors, stop reply-if *recipe-warnings # check contents of right editor (sandbox) current-sandbox:address:editor-data <- get *env, current-sandbox:offset { sandbox-contents:address:array:character <- editor-contents current-sandbox break-unless sandbox-contents # if contents exist, first save them # run them and turn them into a new sandbox-data new-sandbox:address:sandbox-data <- new sandbox-data:type data:address:address:array:character <- get-address *new-sandbox, data:offset *data <- copy sandbox-contents # push to head of sandbox list dest:address:address:sandbox-data <- get-address *env, sandbox:offset next:address:address:sandbox-data <- get-address *new-sandbox, next-sandbox:offset *next <- copy *dest *dest <- copy new-sandbox # clear sandbox editor init:address:address:duplex-list <- get-address *current-sandbox, data:offset *init <- push-duplex 167/§, 0/tail } # save all sandboxes before running, just in case we die when running save-sandboxes env # run all sandboxes curr:address:sandbox-data <- get *env, sandbox:offset { break-unless curr data <- get-address *curr, data:offset response:address:address:array:character <- get-address *curr, response:offset warnings:address:address:array:character <- get-address *curr, warnings:offset fake-screen:address:address:screen <- get-address *curr, screen:offset *response, *warnings, *fake-screen <- run-interactive *data #? $print *warnings, [ ], **warnings, 10/newline curr <- get *curr, next-sandbox:offset loop } ] recipe save-sandboxes [ local-scope env:address:programming-environment-data <- next-ingredient current-sandbox:address:editor-data <- get *env, current-sandbox:offset # first clear previous versions, in case we deleted some sandbox $system [rm lesson/[0-9]* >/dev/null 2>/dev/null] # some shells can't handle '>&' curr:address:sandbox-data <- get *env, sandbox:offset suffix:address:array:character <- new [.out] idx:number <- copy 0 { break-unless curr data:address:array:character <- get *curr, data:offset filename:address:array:character <- integer-to-decimal-string idx save filename, data { expected-response:address:array:character <- get *curr, expected-response:offset break-unless expected-response filename <- string-append filename, suffix save filename, expected-response } idx <- add idx, 1 curr <- get *curr, next-sandbox:offset loop } ] recipe render-sandbox-side [ local-scope screen:address <- next-ingredient env:address:programming-environment-data <- next-ingredient #? trace [app], [render sandbox side] #? 1 current-sandbox:address:editor-data <- get *env, current-sandbox:offset left:number <- get *current-sandbox, left:offset right:number <- get *current-sandbox, right:offset row:number, screen <- render screen, current-sandbox row <- add row, 1 draw-horizontal screen, row, left, right, 9473/horizontal-double sandbox:address:sandbox-data <- get *env, sandbox:offset row, screen <- render-sandboxes screen, sandbox, left, right, row # clear rest of screen row <- add row, 1 move-cursor screen, row, left screen-height:number <- screen-height screen { at-bottom-of-screen?:boolean <- greater-or-equal row, screen-height break-if at-bottom-of-screen? move-cursor screen, row, left clear-line-delimited screen, left, right row <- add row, 1 loop } reply screen/same-as-ingredient:0 ] recipe render-sandboxes [ local-scope screen:address <- next-ingredient sandbox:address:sandbox-data <- next-ingredient left:number <- next-ingredient right:number <- next-ingredient row:number <- next-ingredient reply-unless sandbox, row/same-as-ingredient:4, screen/same-as-ingredient:0 screen-height:number <- screen-height screen at-bottom?:boolean <- greater-or-equal row, screen-height reply-if at-bottom?:boolean, row/same-as-ingredient:4, screen/same-as-ingredient:0 # render sandbox menu row <- add row, 1 move-cursor screen, row, left clear-line-delimited screen, left, right print-character screen, 120/x, 245/grey # save menu row so we can detect clicks to it later starting-row:address:number <- get-address *sandbox, starting-row-on-screen:offset *starting-row <- copy row # render sandbox contents sandbox-data:address:array:character <- get *sandbox, data:offset row, screen <- render-string screen, sandbox-data, left, right, 7/white, row # render sandbox warnings, screen or response, in that order response-starting-row:address:number <- get-address *sandbox, response-starting-row-on-screen:offset sandbox-response:address:array:character <- get *sandbox, response:offset sandbox-warnings:address:array:character <- get *sandbox, warnings:offset sandbox-screen:address <- get *sandbox, screen:offset { break-unless sandbox-warnings *response-starting-row <- copy 0 # no response row, screen <- render-string screen, sandbox-warnings, left, right, 1/red, row } { break-if sandbox-warnings empty-screen?:boolean <- fake-screen-is-empty? sandbox-screen break-if empty-screen? row, screen <- render-screen screen, sandbox-screen, left, right, row } { break-if sandbox-warnings break-unless empty-screen? *response-starting-row <- add row, 1 +render-sandbox-response row, screen <- render-string screen, sandbox-response, left, right, 245/grey, row } +render-sandbox-end at-bottom?:boolean <- greater-or-equal row, screen-height reply-if at-bottom?, row/same-as-ingredient:4, screen/same-as-ingredient:0 # draw solid line after sandbox draw-horizontal screen, row, left, right, 9473/horizontal-double # draw next sandbox next-sandbox:address:sandbox-data <- get *sandbox, next-sandbox:offset row, screen <- render-sandboxes screen, next-sandbox, left, right, row reply row/same-as-ingredient:4, screen/same-as-ingredient:0 ] # assumes programming environment has no sandboxes; restores them from previous session recipe restore-sandboxes [ local-scope env:address:programming-environment-data <- next-ingredient # read all scenarios, pushing them to end of a list of scenarios suffix:address:array:character <- new [.out] idx:number <- copy 0 curr:address:address:sandbox-data <- get-address *env, sandbox:offset { filename:address:array:character <- integer-to-decimal-string idx contents:address:array:character <- restore filename break-unless contents # stop at first error; assuming file didn't exist # create new sandbox for file *curr <- new sandbox-data:type data:address:address:array:character <- get-address **curr, data:offset *data <- copy contents # restore expected output for sandbox if it exists { filename <- string-append filename, suffix contents <- restore filename break-unless contents expected-response:address:address:array:character <- get-address **curr, expected-response:offset *expected-response <- copy contents } # increment loop variables idx <- add idx, 1 curr <- get-address **curr, next-sandbox:offset loop } reply env/same-as-ingredient:0 ] # row:number, screen:address <- render-screen screen:address, sandbox-screen:address, left:number, right:number, row:number # print the fake sandbox screen to 'screen' with appropriate delimiters # leave cursor at start of next line recipe render-screen [ local-scope screen:address <- next-ingredient s:address:screen <- next-ingredient left:number <- next-ingredient right:number <- next-ingredient row:number <- next-ingredient row <- add row, 1 reply-unless s, row/same-as-ingredient:4, screen/same-as-ingredient:0 # print 'screen:' header:address:array:character <- new [screen:] row <- subtract row, 1 # compensate for render-string below row <- render-string screen, header, left, right, 245/grey, row # newline row <- add row, 1 move-cursor screen, row, left # start printing s column:number <- copy left s-width:number <- screen-width s s-height:number <- screen-height s buf:address:array:screen-cell <- get *s, data:offset stop-printing:number <- add left, s-width, 3 max-column:number <- min stop-printing, right i:number <- copy 0 len:number <- length *buf screen-height:number <- screen-height screen { done?:boolean <- greater-or-equal i, len break-if done? done? <- greater-or-equal row, screen-height break-if done? column <- copy left move-cursor screen, row, column # initial leader for each row: two spaces and a '.' print-character screen, 32/space, 245/grey print-character screen, 32/space, 245/grey print-character screen, 46/full-stop, 245/grey column <- add left, 3 { # print row row-done?:boolean <- greater-or-equal column, max-column break-if row-done? curr:screen-cell <- index *buf, i c:character <- get curr, contents:offset print-character screen, c, 245/grey column <- add column, 1 i <- add i, 1 loop } # print final '.' print-character screen, 46/full-stop, 245/grey column <- add column, 1 { # clear rest of current line line-done?:boolean <- greater-than column, right break-if line-done? print-character screen, 32/space column <- add column, 1 loop } row <- add row, 1 loop } reply row/same-as-ingredient:4, screen/same-as-ingredient:0 ] scenario run-updates-results [ $close-trace # trace too long for github assume-screen 100/width, 12/height # define a recipe (no indent for the 'add' line below so column numbers are more obvious) 1:address:array:character <- new [ recipe foo [ z:number <- add 2, 2 ]] # sandbox editor contains an instruction without storing outputs 2:address:array:character <- new [foo] 3:address:programming-environment-data <- new-programming-environment screen:address, 1:address:array:character, 2:address:array:character # run the code in the editors assume-console [ press 65532 # F4 ] run [ event-loop screen:address, console:address, 3:address:programming-environment-data ] # check that screen prints the results screen-should-contain [ . run (F4) . . . .recipe foo [ ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. .z:number <- add 2, 2 x. .] foo . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊4 . . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . . ] # make a change (incrementing one of the args to 'add'), then rerun assume-console [ left-click 3, 28 # one past the value of the second arg type [«3] # replace press 65532 # F4 ] 4:event/backspace <- merge 0/text, 8/backspace, 0/dummy, 0/dummy replace-in-console 171/«, 4:event/backspace run [ event-loop screen:address, console:address, 3:address:programming-environment-data ] # check that screen updates the result on the right screen-should-contain [ . run (F4) . . . .recipe foo [ ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. .z:number <- add 2, 3 x. .] foo . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊5 . . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . . ] ] scenario run-instruction-and-print-warnings [ $close-trace # trace too long for github assume-screen 100/width, 10/height # left editor is empty 1:address:array:character <- new [] # right editor contains an illegal instruction 2:address:array:character <- new [get 1234:number, foo:offset] 3:address:programming-environment-data <- new-programming-environment screen:address, 1:address:array:character, 2:address:array:character # run the code in the editors assume-console [ press 65532 # F4 ] run [ event-loop screen:address, console:address, 3:address:programming-environment-data ] # check that screen prints error message in red screen-should-contain [ . run (F4) . . . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . x. . get 1234:number, foo:offset . . unknown element foo in container number . . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . . ] screen-should-contain-in-color 7/white, [ . . . . . . . . . get 1234:number, foo:offset . . . . . . . ] screen-should-contain-in-color 1/red, [ . . . . . . . . . . . unknown element foo in container number . . . ] screen-should-contain-in-color 245/grey, [ . . . . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . x. . . . . . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . . ] ] scenario run-instruction-and-print-warnings-only-once [ $close-trace # trace too long for github assume-screen 100/width, 10/height # left editor is empty 1:address:array:character <- new [] # right editor contains an illegal instruction 2:address:array:character <- new [get 1234:number, foo:offset] 3:address:programming-environment-data <- new-programming-environment screen:address, 1:address:array:character, 2:address:array:character # run the code in the editors multiple times assume-console [ press 65532 # F4 press 65532 # F4 ] run [ event-loop screen:address, console:address, 3:address:programming-environment-data ] # check that screen prints error message just once screen-should-contain [ . run (F4) . . . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . x. . get 1234:number, foo:offset . . unknown element foo in container number . . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . . ] ] recipe editor-contents [ local-scope editor:address:editor-data <- next-ingredient buf:address:buffer <- new-buffer 80 curr:address:duplex-list <- get *editor, data:offset # skip § sentinel assert curr, [editor without data is illegal; must have at least a sentinel] curr <- next-duplex curr reply-unless curr, 0 { break-unless curr c:character <- get *curr, value:offset buffer-append buf, c curr <- next-duplex curr loop } result:address:array:character <- buffer-to-array buf reply result ] scenario editor-provides-edited-contents [ assume-screen 10/width, 5/height 1:address:array:character <- new [abc] 2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right assume-console [ left-click 1, 2 type [def] ] run [ editor-event-loop screen:address, console:address, 2:address:editor-data 3:address:array:character <- editor-contents 2:address:editor-data 4:array:character <- copy *3:address:array:character ] memory-should-contain [ 4:string <- [abdefc] ] ] ## editing sandboxes after they've been created scenario clicking-on-a-sandbox-moves-it-to-editor [ $close-trace assume-screen 40/width, 10/height # basic recipe 1:address:array:character <- new [ recipe foo [ add 2, 2 ]] # run it 2:address:array:character <- new [foo] assume-console [ press 65532 # F4 ] 3:address:programming-environment-data <- new-programming-environment screen:address, 1:address:array:character, 2:address:array:character event-loop screen:address, console:address, 3:address:programming-environment-data screen-should-contain [ . run (F4) . . . .recipe foo [ ┊━━━━━━━━━━━━━━━━━━━. . add 2, 2 x. .] foo . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊4 . . ┊━━━━━━━━━━━━━━━━━━━. . . ] # click somewhere on the sandbox assume-console [ left-click 4, 30 ] run [ event-loop screen:address, console:address, 3:address:programming-environment-data ] # it pops back into editor screen-should-contain [ . run (F4) . . foo . .recipe foo [ ┊━━━━━━━━━━━━━━━━━━━. . add 2, 2 . .] . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊ . . . . . ] ] after +global-touch [ # right side of screen and below sandbox editor? pop appropriate sandbox # contents back into sandbox editor provided it's empty { sandbox-left-margin:number <- get *current-sandbox, left:offset click-column:number <- get *t, column:offset on-sandbox-side?:boolean <- greater-or-equal click-column, sandbox-left-margin break-unless on-sandbox-side? first-sandbox:address:sandbox-data <- get *env, sandbox:offset break-unless first-sandbox first-sandbox-begins:number <- get *first-sandbox, starting-row-on-screen:offset click-row:number <- get *t, row:offset below-sandbox-editor?:boolean <- greater-or-equal click-row, first-sandbox-begins break-unless below-sandbox-editor? empty-sandbox-editor?:boolean <- empty-editor? current-sandbox break-unless empty-sandbox-editor? # make the user hit F4 before editing a new sandbox # identify the sandbox to edit and remove it from the sandbox list sandbox:address:sandbox-data <- extract-sandbox env, click-row text:address:array:character <- get *sandbox, data:offset current-sandbox <- insert-text current-sandbox, text screen <- render-sandbox-side screen, env update-cursor screen, recipes, current-sandbox, *sandbox-in-focus? show-screen screen loop +next-event:label } ] recipe empty-editor? [ local-scope editor:address:editor-data <- next-ingredient head:address:duplex-list <- get *editor, data:offset first:address:duplex-list <- next-duplex head result:boolean <- not first reply result ] recipe extract-sandbox [ local-scope env:address:programming-environment-data <- next-ingredient click-row:number <- next-ingredient # assert click-row >= sandbox.starting-row-on-screen sandbox:address:address:sandbox-data <- get-address *env, sandbox:offset start:number <- get **sandbox, starting-row-on-screen:offset clicked-on-sandboxes?:boolean <- greater-or-equal click-row, start assert clicked-on-sandboxes?, [extract-sandbox called on click to sandbox editor] { next-sandbox:address:sandbox-data <- get **sandbox, next-sandbox:offset break-unless next-sandbox # if click-row < sandbox.next-sandbox.starting-row-on-screen, break next-start:number <- get *next-sandbox, starting-row-on-screen:offset found?:boolean <- lesser-than click-row, next-start break-if found? sandbox <- get-address **sandbox, next-sandbox:offset loop } # snip sandbox out of its list result:address:sandbox-data <- copy *sandbox *sandbox <- copy next-sandbox reply result ] ## deleting sandboxes scenario deleting-sandboxes [ $close-trace # trace too long for github assume-screen 100/width, 15/height 1:address:array:character <- new [] 2:address:array:character <- new [] 3:address:programming-environment-data <- new-programming-environment screen:address, 1:address:array:character, 2:address:array:character # run a few commands assume-console [ left-click 1, 80 type [divide-with-remainder 11, 3] press 65532 # F4 type [add 2, 2] press 65532 # F4 ] run [ event-loop screen:address, console:address, 3:address:programming-environment-data ] screen-should-contain [ . run (F4) . . . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . x. . add 2, 2 . . 4 . . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . x. . divide-with-remainder 11, 3 . . 3 . . 2 . . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . . ] # delete second sandbox assume-console [ left-click 7, 99 ] run [ event-loop screen:address, console:address, 3:address:programming-environment-data ] screen-should-contain [ . run (F4) . . . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . x. . add 2, 2 . . 4 . . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . . . . ] # delete first sandbox assume-console [ left-click 3, 99 ] run [ event-loop screen:address, console:address, 3:address:programming-environment-data ] screen-should-contain [ . run (F4) . . . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . . . . ] ] after +global-touch [ # on a sandbox delete icon? process delete { was-delete?:boolean <- delete-sandbox *t, env break-unless was-delete? #? trace [app], [delete clicked] #? 1 screen <- render-sandbox-side screen, env update-cursor screen, recipes, current-sandbox, *sandbox-in-focus? show-screen screen loop +next-event:label } ] # was-deleted?:boolean <- delete-sandbox t:touch-event, env:address:programming-environment-data recipe delete-sandbox [ local-scope t:touch-event <- next-ingredient env:address:programming-environment-data <- next-ingredient click-column:number <- get t, column:offset current-sandbox:address:editor-data <- get *env, current-sandbox:offset right:number <- get *current-sandbox, right:offset at-right?:boolean <- equal click-column, right reply-unless at-right?, 0/false click-row:number <- get t, row:offset prev:address:address:sandbox-data <- get-address *env, sandbox:offset curr:address:sandbox-data <- get *env, sandbox:offset { break-unless curr # more sandboxes to check { target-row:number <- get *curr, starting-row-on-screen:offset delete-curr?:boolean <- equal target-row, click-row break-unless delete-curr? # delete this sandbox, rerender and stop *prev <- get *curr, next-sandbox:offset reply 1/true } prev <- get-address *curr, next-sandbox:offset curr <- get *curr, next-sandbox:offset loop } reply 0/false ] scenario run-instruction-manages-screen-per-sandbox [ $close-trace # trace too long for github #? 1 assume-screen 100/width, 20/height # left editor is empty 1:address:array:character <- new [] # right editor contains an illegal instruction 2:address:array:character <- new [print-integer screen:address, 4] 3:address:programming-environment-data <- new-programming-environment screen:address, 1:address:array:character, 2:address:array:character # run the code in the editor assume-console [ press 65532 # F4 ] run [ event-loop screen:address, console:address, 3:address:programming-environment-data ] # check that it prints a little 5x5 toy screen # hack: screen address is brittle screen-should-contain [ . run (F4) . . . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . x. . print-integer screen:address, 4 . . screen: . . .4 . . . . . . . . . . . . . . . . . . . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . . ] ] ## clicking on sandbox results to 'fix' them and turn sandboxes into tests scenario sandbox-click-on-result-toggles-color-to-green [ $close-trace assume-screen 40/width, 10/height # basic recipe 1:address:array:character <- new [ recipe foo [ add 2, 2 ]] # run it 2:address:array:character <- new [foo] assume-console [ press 65532 # F4 ] 3:address:programming-environment-data <- new-programming-environment screen:address, 1:address:array:character, 2:address:array:character event-loop screen:address, console:address, 3:address:programming-environment-data screen-should-contain [ . run (F4) . . . .recipe foo [ ┊━━━━━━━━━━━━━━━━━━━. . add 2, 2 x. .] foo . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊4 . . ┊━━━━━━━━━━━━━━━━━━━. . . ] # click on the '4' in the result assume-console [ left-click 5, 21 ] run [ event-loop screen:address, console:address, 3:address:programming-environment-data ] # color toggles to green screen-should-contain-in-color 2/green, [ . . . . . . . . . . . 4 . . . . . ] # now change the second arg of the 'add' # then rerun assume-console [ left-click 3, 11 # cursor to end of line type [«3] # turn '2' into '3' press 65532 # F4 ] 4:event/backspace <- merge 0/text, 8/backspace, 0/dummy, 0/dummy replace-in-console 171/«, 4:event/backspace run [ event-loop screen:address, console:address, 3:address:programming-environment-data ] # result turns red screen-should-contain-in-color 1/red, [ . . . . . . . . . . . 5 . . . . . ] ] # clicks on sandbox responses save it as 'expected' after +global-touch [ # right side of screen? check if it's inside the output of any sandbox { sandbox-left-margin:number <- get *current-sandbox, left:offset click-column:number <- get *t, column:offset on-sandbox-side?:boolean <- greater-or-equal click-column, sandbox-left-margin break-unless on-sandbox-side? first-sandbox:address:sandbox-data <- get *env, sandbox:offset break-unless first-sandbox first-sandbox-begins:number <- get *first-sandbox, starting-row-on-screen:offset click-row:number <- get *t, row:offset below-sandbox-editor?:boolean <- greater-or-equal click-row, first-sandbox-begins break-unless below-sandbox-editor? # identify the sandbox whose output is being clicked on sandbox:address:sandbox-data <- find-click-in-sandbox-output env, click-row break-unless sandbox # toggle its expected-response, and save session sandbox <- toggle-expected-response sandbox save-sandboxes env screen <- render-sandbox-side screen, env, 1/clear # no change in cursor show-screen screen loop +next-event:label } ] recipe find-click-in-sandbox-output [ local-scope env:address:programming-environment-data <- next-ingredient click-row:number <- next-ingredient # assert click-row >= sandbox.starting-row-on-screen sandbox:address:sandbox-data <- get *env, sandbox:offset start:number <- get *sandbox, starting-row-on-screen:offset clicked-on-sandboxes?:boolean <- greater-or-equal click-row, start assert clicked-on-sandboxes?, [extract-sandbox called on click to sandbox editor] # while click-row < sandbox.next-sandbox.starting-row-on-screen { next-sandbox:address:sandbox-data <- get *sandbox, next-sandbox:offset break-unless next-sandbox next-start:number <- get *next-sandbox, starting-row-on-screen:offset found?:boolean <- lesser-than click-row, next-start break-if found? sandbox <- copy next-sandbox loop } # return sandbox if click is in its output region response-starting-row:number <- get *sandbox, response-starting-row-on-screen:offset click-in-response?:boolean <- greater-or-equal click-row, response-starting-row { break-if click-in-response? reply 0/no-click-in-sandbox-output } reply sandbox ] recipe toggle-expected-response [ local-scope sandbox:address:sandbox-data <- next-ingredient expected-response:address:address:array:character <- get-address *sandbox, expected-response:offset { # if expected-response is set, reset break-unless *expected-response *expected-response <- copy 0 reply sandbox/same-as-ingredient:0 } # if not, current response is the expected response response:address:array:character <- get *sandbox, response:offset *expected-response <- copy response reply sandbox/same-as-ingredient:0 ] # when rendering a sandbox, color it in red/green if expected response exists after +render-sandbox-response [ { break-unless sandbox-response expected-response:address:array:character <- get *sandbox, expected-response:offset break-unless expected-response # fall-through to print in grey response-is-expected?:boolean <- string-equal expected-response, sandbox-response { break-if response-is-expected?:boolean row, screen <- render-string screen, sandbox-response, left, right, 1/red, row } { break-unless response-is-expected?:boolean row, screen <- render-string screen, sandbox-response, left, right, 2/green, row } jump +render-sandbox-end:label } ] ## handling malformed programs scenario run-shows-warnings-in-get [ $close-trace assume-screen 100/width, 15/height assume-console [ press 65532 # F4 ] run [ x:address:array:character <- new [ recipe foo [ get 123:number, foo:offset ]] y:address:array:character <- new [foo] env:address:programming-environment-data <- new-programming-environment screen:address, x:address:array:character, y:address:array:character event-loop screen:address, console:address, env:address:programming-environment-data ] screen-should-contain [ . run (F4) . . foo . .recipe foo [ ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . get 123:number, foo:offset . .] . .unknown element foo in container number . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊ . . . ] screen-should-contain-in-color 1/red, [ . . . . . . . . . . .unknown element foo in container number . . . ] ] scenario run-shows-missing-type-warnings [ $close-trace assume-screen 100/width, 15/height assume-console [ press 65532 # F4 ] run [ x:address:array:character <- new [ recipe foo [ x <- copy 0 ]] y:address:array:character <- new [foo] env:address:programming-environment-data <- new-programming-environment screen:address, x:address:array:character, y:address:array:character event-loop screen:address, console:address, env:address:programming-environment-data ] screen-should-contain [ . run (F4) . . foo . .recipe foo [ ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . x <- copy 0 . .] . .missing type in 'x <- copy 0' . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊ . . . ] ] scenario run-shows-get-on-non-container-warnings [ $close-trace assume-screen 100/width, 15/height assume-console [ press 65532 # F4 ] run [ x:address:array:character <- new [ recipe foo [ x:address:point <- new point:type get x:address:point, 1:offset ]] y:address:array:character <- new [foo] env:address:programming-environment-data <- new-programming-environment screen:address, x:address:array:character, y:address:array:character event-loop screen:address, console:address, env:address:programming-environment-data ] screen-should-contain [ . run (F4) . . . .recipe foo [ ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . x:address:point <- new point:type x. . get x:address:point, 1:offset foo . .] foo: first ingredient of 'get' should be a conta. .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊iner, but got x:address:point . . ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . . ] ] scenario run-shows-non-literal-get-argument-warnings [ $close-trace assume-screen 100/width, 15/height assume-console [ press 65532 # F4 ] run [ x:address:array:character <- new [ recipe foo [ x:number <- copy 0 y:address:point <- new point:type get *y:address:point, x:number ]] y:address:array:character <- new [foo] env:address:programming-environment-data <- new-programming-environment screen:address, x:address:array:character, y:address:array:character event-loop screen:address, console:address, env:address:programming-environment-data ] screen-should-contain [ . run (F4) . . foo . .recipe foo [ ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━. . x:number <- copy 0 . . y:address:point <- new point:type . . get *y:address:point, x:number . .] . .foo: expected ingredient 1 of 'get' to have type ↩┊ . .'offset'; got x:number . .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊ . . . ] ] ## helpers for drawing editor borders recipe draw-box [ local-scope screen:address <- next-ingredient top:number <- next-ingredient left:number <- next-ingredient bottom:number <- next-ingredient right:number <- next-ingredient color:number, color-found?:boolean <- next-ingredient { # default color to white break-if color-found? color <- copy 245/grey } # top border draw-horizontal screen, top, left, right, color draw-horizontal screen, bottom, left, right, color draw-vertical screen, left, top, bottom, color draw-vertical screen, right, top, bottom, color draw-top-left screen, top, left, color draw-top-right screen, top, right, color draw-bottom-left screen, bottom, left, color draw-bottom-right screen, bottom, right, color # position cursor inside box move-cursor screen, top, left cursor-down screen cursor-right screen ] recipe draw-horizontal [ local-scope screen:address <- next-ingredient row:number <- next-ingredient x:number <- next-ingredient right:number <- next-ingredient style:character, style-found?:boolean <- next-ingredient { break-if style-found? style <- copy 9472/horizontal } color:number, color-found?:boolean <- next-ingredient { # default color to white break-if color-found? color <- copy 245/grey } bg-color:number, bg-color-found?:boolean <- next-ingredient { break-if bg-color-found? bg-color <- copy 0/black } move-cursor screen, row, x { continue?:boolean <- lesser-or-equal x, right # right is inclusive, to match editor-data semantics break-unless continue? print-character screen, style, color, bg-color x <- add x, 1 loop } ] recipe draw-vertical [ local-scope screen:address <- next-ingredient col:number <- next-ingredient y:number <- next-ingredient bottom:number <- next-ingredient style:character, style-found?:boolean <- next-ingredient { break-if style-found? style <- copy 9474/vertical } color:number, color-found?:boolean <- next-ingredient { # default color to white break-if color-found? color <- copy 245/grey } { continue?:boolean <- lesser-than y, bottom break-unless continue? move-cursor screen, y, col print-character screen, style, color y <- add y, 1 loop } ] recipe draw-top-left [ local-scope screen:address <- next-ingredient top:number <- next-ingredient left:number <- next-ingredient color:number, color-found?:boolean <- next-ingredient { # default color to white break-if color-found? color <- copy 245/grey } move-cursor screen, top, left print-character screen, 9484/down-right, color ] recipe draw-top-right [ local-scope screen:address <- next-ingredient top:number <- next-ingredient right:number <- next-ingredient color:number, color-found?:boolean <- next-ingredient { # default color to white break-if color-found? color <- copy 245/grey } move-cursor screen, top, right print-character screen, 9488/down-left, color ] recipe draw-bottom-left [ local-scope screen:address <- next-ingredient bottom:number <- next-ingredient left:number <- next-ingredient color:number, color-found?:boolean <- next-ingredient { # default color to white break-if color-found? color <- copy 245/grey } move-cursor screen, bottom, left print-character screen, 9492/up-right, color ] recipe draw-bottom-right [ local-scope screen:address <- next-ingredient bottom:number <- next-ingredient right:number <- next-ingredient color:number, color-found?:boolean <- next-ingredient { # default color to white break-if color-found? color <- copy 245/grey } move-cursor screen, bottom, right print-character screen, 9496/up-left, color ] recipe print-string-with-gradient-background [ local-scope screen:address <- next-ingredient s:address:array:character <- next-ingredient color:number <- next-ingredient bg-color1:number <- next-ingredient bg-color2:number <- next-ingredient len:number <- length *s color-range:number <- subtract bg-color2, bg-color1 color-quantum:number <- divide color-range, len bg-color:number <- copy bg-color1 i:number <- copy 0 { done?:boolean <- greater-or-equal i, len break-if done? c:character <- index *s, i print-character screen, c, color, bg-color i <- add i, 1 bg-color <- add bg-color, color-quantum loop } reply screen/same-as-ingredient:0 ]