ansi-control-codes 1.0.1

This library contains all ANSI Escape Codes that are defined in the ISO 6429 Standard
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
//! # Explanations of ansi-control-codes
//!
//! This module provides functionality to explain and inspect any ansi-control-code.
//!
//! Enable this module by using the feature `explain`
//!
//! ```text
//! cargo add ansi-control-codes --features explain
//! ```
//!
//! ## Names of Control Codes
//!
//! The functions [`short_name`][Explain::short_name] and [`long_name`][Explain::long_name] of the trait [`Explain`]
//! provide access to a control function's name. Short names are the abbreviated names of control functions, whereas
//! long names are the human readable equivalents.
//!
//! ```
//! use ansi_control_codes::categories::format_effectors::CR;
//! use ansi_control_codes::explain::Explain;
//! println!("short name: {}, long name: {}", CR.short_name().unwrap(), CR.long_name());
//! // this will print "short name: CR, long name: Carriage Return"
//! ```
//!
//! Short names of control functions are available for all control functions except for private-use control codes.
//!
//! ## Descriptions of Control Codes
//!
//! The functions [`short_description`][Explain::short_description] and [`long_description`][Explain::long_description]
//! of the trait [`Explain`] provide access to a control function's short and long descriptions. Not all control
//! functions have long descriptions, in which case the `long_description` returns the same description text as the
//! `short_description` functions.
//!
//! ```
//! use ansi_control_codes::categories::format_effectors::CR;
//! use ansi_control_codes::explain::Explain;
//! println!("short description: {}, long description: {}", CR.short_description(), CR.long_description());
//! ```

use std::{convert::Infallible, str::FromStr};

use crate::{control_sequences::*, modes::Mode, ControlFunction, ControlFunctionType};

macro_rules! param {
    ($self:ident, $index:literal, $default:literal) => {
        get_param(&$self.parameters, $index, $default)
    };
    ($self:ident, ordinal $index:literal, $default:literal) => {
        ordinal_indicator(get_param(&$self.parameters, $index, $default))
    };
}

macro_rules! explain_selection {
    ($selection:ident, $self:ident, $index:literal) => {
        $selection::from_str(
            $self
                .parameters
                .get($index)
                .map(&String::as_ref)
                .unwrap_or(""),
        )
        .expect("Reached infallible code.")
        .explain()
    };
}

#[derive(Debug)]
enum Function {
    // C0
    ACK,
    BEL,
    BS,
    CAN,
    CR,
    DC1,
    DC2,
    DC3,
    DC4,
    DLE,
    EM,
    ENQ,
    EOT,
    ESC,
    ETB,
    ETX,
    FF,
    HT,
    IS1,
    IS2,
    IS3,
    IS4,
    LF,
    LS0,
    LS1,
    NAK,
    NUL,
    SOH,
    STX,
    SUB,
    SYN,
    VT,
    // C1
    APC,
    BPH,
    CCH,
    CSI,
    DCS,
    EPA,
    ESA,
    HTJ,
    HTS,
    MW,
    NBH,
    NEL,
    OSC,
    PLD,
    PLU,
    PM,
    PU1,
    PU2,
    RI,
    SCI,
    SOS,
    SPA,
    SSA,
    SS2,
    SS3,
    ST,
    STS,
    VTS,
    // Independent Control Functions
    CMD,
    DMI,
    EMI,
    INT,
    LS1R,
    LS2,
    LS2R,
    LS3,
    LS3R,
    RIS,
    // Control Sequences
    CBT,
    CHA,
    CHT,
    CNL,
    CPL,
    CPR,
    CTC,
    CUB,
    CUD,
    CUF,
    CUP,
    CUU,
    CVT,
    DA,
    DAQ,
    DCH,
    DL,
    DSR,
    DTA,
    EA,
    ECH,
    ED,
    EF,
    EL,
    FNK,
    FNT,
    GCC,
    GSM,
    GSS,
    HPA,
    HPB,
    HPR,
    HVP,
    ICH,
    IDCS,
    IGS,
    IL,
    JFY,
    MC,
    NP,
    PEC,
    PFS,
    PP,
    PPA,
    PPB,
    PPR,
    PTX,
    QUAD,
    REP,
    RM,
    SACS,
    SAPV,
    SCO,
    SCP,
    SCS,
    SD,
    SDS,
    SEE,
    SEF,
    SGR,
    SHS,
    SIMD,
    SL,
    SLH,
    SLL,
    SLS,
    SM,
    SPD,
    SPH,
    SPI,
    SPL,
    SPQR,
    SR,
    SRCS,
    SRS,
    SSU,
    SSW,
    STAB,
    SU,
    SVS,
    TAC,
    TALE,
    TATE,
    TBC,
    TCC,
    TSR,
    TSS,
    VPA,
    VPB,
    VPR,
    PRIVATE,
}

fn function(control_function: &ControlFunction<'_>) -> Function {
    match control_function.function_type {
        ControlFunctionType::C0 => {
            // C0 control functions are always 1 byte long
            let byte = control_function.value.as_bytes()[0];

            match byte {
                0 => Function::NUL,
                1 => Function::SOH,
                2 => Function::STX,
                3 => Function::ETX,
                4 => Function::EOT,
                5 => Function::ENQ,
                6 => Function::ACK,
                7 => Function::BEL,
                8 => Function::BS,
                9 => Function::HT,
                10 => Function::LF,
                11 => Function::VT,
                12 => Function::FF,
                13 => Function::CR,
                14 => Function::LS1,
                15 => Function::LS0,
                16 => Function::DLE,
                17 => Function::DC1,
                18 => Function::DC2,
                19 => Function::DC3,
                20 => Function::DC4,
                21 => Function::NAK,
                22 => Function::SYN,
                23 => Function::ETB,
                24 => Function::CAN,
                25 => Function::EM,
                26 => Function::SUB,
                27 => Function::ESC,
                28 => Function::IS4,
                29 => Function::IS3,
                30 => Function::IS2,
                31 => Function::IS1,
                _ => {
                    unreachable!("No C0 control function exists outside of above range")
                }
            }
        }
        ControlFunctionType::C1 => {
            // C1 control functions are always 1 byte long
            let byte = control_function.value.as_bytes()[0];

            match byte {
                66 => Function::BPH,
                67 => Function::NBH,
                69 => Function::NEL,
                70 => Function::SSA,
                71 => Function::ESA,
                72 => Function::HTS,
                73 => Function::HTJ,
                74 => Function::VTS,
                75 => Function::PLD,
                76 => Function::PLU,
                77 => Function::RI,
                78 => Function::SS2,
                79 => Function::SS3,
                80 => Function::DCS,
                81 => Function::PU1,
                82 => Function::PU2,
                83 => Function::STS,
                84 => Function::CCH,
                85 => Function::MW,
                86 => Function::SPA,
                87 => Function::EPA,
                88 => Function::SOS,
                90 => Function::SCI,
                91 => Function::CSI,
                92 => Function::ST,
                93 => Function::OSC,
                94 => Function::PM,
                95 => Function::APC,
                _ => {
                    unreachable!("No C1 control function exists outside of above range")
                }
            }
        }
        ControlFunctionType::IndependentControlFunction => {
            // Independent control functions are always 1 byte long
            let byte = control_function.value.as_bytes()[0];

            match byte {
                96 => Function::DMI,
                97 => Function::INT,
                98 => Function::EMI,
                99 => Function::RIS,
                100 => Function::CMD,
                110 => Function::LS2,
                111 => Function::LS3,
                124 => Function::LS3R,
                125 => Function::LS2R,
                126 => Function::LS1R,
                _ => {
                    unreachable!("No independent control function exists outside of above range")
                }
            }
        }
        ControlFunctionType::ControlSequence => {
            let bytes = control_function.value.as_bytes();
            if bytes.len() == 1 {
                // control sequence with no intermediate byte
                let byte = bytes[0];
                return match byte {
                    64 => Function::ICH,
                    65 => Function::CUU,
                    66 => Function::CUD,
                    67 => Function::CUF,
                    68 => Function::CUB,
                    69 => Function::CNL,
                    70 => Function::CPL,
                    71 => Function::CHA,
                    72 => Function::CUP,
                    73 => Function::CHT,
                    74 => Function::ED,
                    75 => Function::EL,
                    76 => Function::IL,
                    77 => Function::DL,
                    78 => Function::EF,
                    79 => Function::EA,
                    80 => Function::DCH,
                    81 => Function::SEE,
                    82 => Function::CPR,
                    83 => Function::SU,
                    84 => Function::SD,
                    85 => Function::NP,
                    86 => Function::PP,
                    87 => Function::CTC,
                    88 => Function::ECH,
                    89 => Function::CVT,
                    90 => Function::CBT,
                    91 => Function::SRS,
                    92 => Function::PTX,
                    93 => Function::SDS,
                    94 => Function::SIMD,
                    96 => Function::HPA,
                    97 => Function::HPR,
                    98 => Function::REP,
                    99 => Function::DA,
                    100 => Function::VPA,
                    101 => Function::VPR,
                    102 => Function::HVP,
                    103 => Function::TBC,
                    104 => Function::SM,
                    105 => Function::MC,
                    106 => Function::HPB,
                    107 => Function::VPB,
                    108 => Function::RM,
                    109 => Function::SGR,
                    110 => Function::DSR,
                    111 => Function::DAQ,
                    112..=127 => Function::PRIVATE,
                    _ => {
                        unreachable!("No valid control sequence exist outside of above range")
                    }
                };
            }
            if bytes.len() == 2 {
                // control sequence with intermediate byte
                let byte = bytes[1];
                return match byte {
                    64 => Function::SL,
                    65 => Function::SR,
                    66 => Function::GSM,
                    67 => Function::GSS,
                    68 => Function::FNT,
                    69 => Function::TSS,
                    70 => Function::JFY,
                    71 => Function::SPI,
                    72 => Function::QUAD,
                    73 => Function::SSU,
                    74 => Function::PFS,
                    75 => Function::SHS,
                    76 => Function::SVS,
                    77 => Function::IGS,
                    79 => Function::IDCS,
                    80 => Function::PPA,
                    81 => Function::PPR,
                    82 => Function::PPB,
                    83 => Function::SPD,
                    84 => Function::DTA,
                    85 => Function::SLH,
                    86 => Function::SLL,
                    87 => Function::FNK,
                    88 => Function::SPQR,
                    89 => Function::SEF,
                    90 => Function::PEC,
                    91 => Function::SSW,
                    92 => Function::SACS,
                    93 => Function::SAPV,
                    94 => Function::STAB,
                    95 => Function::GCC,
                    96 => Function::TATE,
                    97 => Function::TALE,
                    98 => Function::TAC,
                    99 => Function::TCC,
                    100 => Function::TSR,
                    101 => Function::SCO,
                    102 => Function::SRCS,
                    103 => Function::SCS,
                    104 => Function::SLS,
                    105 => Function::SPH,
                    106 => Function::SPL,
                    107 => Function::SCP,
                    112..=127 => Function::PRIVATE,
                    _ => {
                        unreachable!("No valid control sequence exist outside of above range")
                    }
                };
            }
            unreachable!("No valid control sequence exist outside of above range")
        }
    }
}

fn ordinal_indicator(numeric_value: String) -> String {
    numeric_value
        .parse::<u64>()
        .map(|value| match value % 10 {
            0 | 4..=9 => numeric_value.clone(),
            1 => format!("{}st", value),
            2 => format!("{}nd", value),
            3 => format!("{}rd", value),
            _ => {
                unreachable!("This is not reachable, all possible values of modulo 10 are covered.")
            }
        })
        .unwrap_or_else(|_| numeric_value)
}

fn get_param(parameters: &Vec<String>, index: usize, default_value: u64) -> String {
    parameters
        .get(index)
        .map(|value| value.to_owned())
        .unwrap_or_else(|| format!("{default_value}"))
}

trait ExplainSelection {
    fn explain(&self) -> String;
}

trait ExplainMode {
    fn name(&self) -> String;
    fn explain_reset(&self) -> String;
    fn explain_set(&self) -> String;
}

/// Explanation of an ansi-control-code.
pub trait Explain {
    /// Returns the short name (abbreviation) of this control function, e.g. `CR`, `LF`.
    ///
    /// An abbreviated name is available for all ansi-escape-codes, except for those in the private use area.
    fn short_name(&self) -> Option<&'static str>;

    /// Returns the name of this control function, e.g. `Carriage Return`, `Line Feed`.
    fn long_name(&self) -> &'static str;

    /// Returns the short description of what this function does.
    fn short_description(&self) -> String;

    /// Returns a long description of what this function does.
    ///
    /// Not all control functions have a long description, in which case this will return the
    /// same as `short_description()`.
    fn long_description(&self) -> String;
}

impl Explain for ControlFunction<'_> {
    fn short_name(&self) -> Option<&'static str> {
        match function(&self) {
            Function::ACK => Some("ACK"),
            Function::BEL => Some("BEL"),
            Function::BS => Some("BS"),
            Function::CAN => Some("CAN"),
            Function::CR => Some("CR"),
            Function::DC1 => Some("DC1"),
            Function::DC2 => Some("DC2"),
            Function::DC3 => Some("DC3"),
            Function::DC4 => Some("DC4"),
            Function::DLE => Some("DLE"),
            Function::EM => Some("EM"),
            Function::ENQ => Some("ENQ"),
            Function::EOT => Some("EOT"),
            Function::ESC => Some("ESC"),
            Function::ETB => Some("ETB"),
            Function::ETX => Some("ETX"),
            Function::FF => Some("FF"),
            Function::HT => Some("HT"),
            Function::IS1 => Some("IS1"),
            Function::IS2 => Some("IS2"),
            Function::IS3 => Some("IS3"),
            Function::IS4 => Some("IS4"),
            Function::LF => Some("LF"),
            Function::LS0 => Some("LS0"),
            Function::LS1 => Some("LS1"),
            Function::NAK => Some("NAK"),
            Function::NUL => Some("NUL"),
            Function::SOH => Some("SOH"),
            Function::STX => Some("STX"),
            Function::SUB => Some("SUB"),
            Function::SYN => Some("SYN"),
            Function::VT => Some("VT"),
            Function::APC => Some("APC"),
            Function::BPH => Some("BPH"),
            Function::CCH => Some("CCH"),
            Function::CSI => Some("CSI"),
            Function::DCS => Some("DCS"),
            Function::EPA => Some("EPA"),
            Function::ESA => Some("ESA"),
            Function::HTJ => Some("HTJ"),
            Function::HTS => Some("HTS"),
            Function::MW => Some("MW"),
            Function::NBH => Some("NBH"),
            Function::NEL => Some("NEL"),
            Function::OSC => Some("OSC"),
            Function::PLD => Some("PLD"),
            Function::PLU => Some("PLU"),
            Function::PM => Some("PM"),
            Function::PU1 => Some("PU1"),
            Function::PU2 => Some("PU2"),
            Function::RI => Some("RI"),
            Function::SCI => Some("SCI"),
            Function::SOS => Some("SOS"),
            Function::SPA => Some("SPA"),
            Function::SSA => Some("SSA"),
            Function::SS2 => Some("SS2"),
            Function::SS3 => Some("SS3"),
            Function::ST => Some("ST"),
            Function::STS => Some("STS"),
            Function::VTS => Some("VTS"),
            Function::CMD => Some("CMD"),
            Function::DMI => Some("DMI"),
            Function::EMI => Some("EMI"),
            Function::INT => Some("INT"),
            Function::LS1R => Some("LS1R"),
            Function::LS2 => Some("LS2"),
            Function::LS2R => Some("LS2R"),
            Function::LS3 => Some("LS3"),
            Function::LS3R => Some("LS3R"),
            Function::RIS => Some("RIS"),
            Function::CBT => Some("CBT"),
            Function::CHA => Some("CHA"),
            Function::CHT => Some("CHT"),
            Function::CNL => Some("CNL"),
            Function::CPL => Some("CPL"),
            Function::CPR => Some("CPR"),
            Function::CTC => Some("CTC"),
            Function::CUB => Some("CUB"),
            Function::CUD => Some("CUD"),
            Function::CUF => Some("CUF"),
            Function::CUP => Some("CUP"),
            Function::CUU => Some("CUU"),
            Function::CVT => Some("CVT"),
            Function::DA => Some("DA"),
            Function::DAQ => Some("DAQ"),
            Function::DCH => Some("DCH"),
            Function::DL => Some("DL"),
            Function::DSR => Some("DSR"),
            Function::DTA => Some("DTA"),
            Function::EA => Some("EA"),
            Function::ECH => Some("ECH"),
            Function::ED => Some("ED"),
            Function::EF => Some("EF"),
            Function::EL => Some("EL"),
            Function::FNK => Some("FNK"),
            Function::FNT => Some("FNT"),
            Function::GCC => Some("GCC"),
            Function::GSM => Some("GSM"),
            Function::GSS => Some("GSS"),
            Function::HPA => Some("HPA"),
            Function::HPB => Some("HPB"),
            Function::HPR => Some("HPR"),
            Function::HVP => Some("HVP"),
            Function::ICH => Some("ICH"),
            Function::IDCS => Some("IDCS"),
            Function::IGS => Some("IGS"),
            Function::IL => Some("IL"),
            Function::JFY => Some("JFY"),
            Function::MC => Some("MC"),
            Function::NP => Some("NP"),
            Function::PEC => Some("PEC"),
            Function::PFS => Some("PFS"),
            Function::PP => Some("PP"),
            Function::PPA => Some("PPA"),
            Function::PPB => Some("PPB"),
            Function::PPR => Some("PPR"),
            Function::PTX => Some("PTX"),
            Function::QUAD => Some("QUAD"),
            Function::REP => Some("REP"),
            Function::RM => Some("RM"),
            Function::SACS => Some("SACS"),
            Function::SAPV => Some("SAPV"),
            Function::SCO => Some("SCO"),
            Function::SCP => Some("SCP"),
            Function::SCS => Some("SCS"),
            Function::SD => Some("SD"),
            Function::SDS => Some("SDS"),
            Function::SEE => Some("SEE"),
            Function::SEF => Some("SEF"),
            Function::SGR => Some("SGR"),
            Function::SHS => Some("SHS"),
            Function::SIMD => Some("SIMD"),
            Function::SL => Some("SL"),
            Function::SLH => Some("SLH"),
            Function::SLL => Some("SLL"),
            Function::SLS => Some("SLS"),
            Function::SM => Some("SM"),
            Function::SPD => Some("SPD"),
            Function::SPI => Some("SPI"),
            Function::SPL => Some("SPL"),
            Function::SPH => Some("SPH"),
            Function::SPQR => Some("SPQR"),
            Function::SR => Some("SR"),
            Function::SRCS => Some("SRCS"),
            Function::SRS => Some("SRS"),
            Function::SSU => Some("SSU"),
            Function::SSW => Some("SSW"),
            Function::STAB => Some("STAB"),
            Function::SU => Some("SU"),
            Function::SVS => Some("SVS"),
            Function::TAC => Some("TAC"),
            Function::TALE => Some("TALE"),
            Function::TATE => Some("TATE"),
            Function::TBC => Some("TBC"),
            Function::TCC => Some("TCC"),
            Function::TSR => Some("TSR"),
            Function::TSS => Some("TSS"),
            Function::VPA => Some("VPA"),
            Function::VPB => Some("VPB"),
            Function::VPR => Some("VPR"),
            Function::PRIVATE => None,
        }
    }

    fn long_name(&self) -> &'static str {
        match function(&self) {
            Function::ACK => "Acknowledge",
            Function::BEL => "Bell",
            Function::BS => "Backspace",
            Function::CAN => "Cancel",
            Function::CR => "Carriage Return",
            Function::DC1 => "Device Control One",
            Function::DC2 => "Device Control Two",
            Function::DC3 => "Device Control Three",
            Function::DC4 => "Device Control Four",
            Function::DLE => "Data Link Escape",
            Function::EM => "End of Medium",
            Function::ENQ => "Enquiry",
            Function::EOT => "End of Transmission",
            Function::ESC => "Escape",
            Function::ETB => "End of Transmission Block",
            Function::ETX => "End of Text",
            Function::FF => "Form Feed",
            Function::HT => "Character Tabulation",
            Function::IS1 => "Information Separator One (US - Unit Separator)",
            Function::IS2 => "Information Separator Two (RS - Record Separator)",
            Function::IS3 => "Information Separator Three (GS - Group Separator)",
            Function::IS4 => "Information Separator Four (FS - File Separator)",
            Function::LF => "Line Feed",
            Function::LS0 => "Locking-Shift Zero (Shift-In)",
            Function::LS1 => "Locking-Shift One (Shift-Out)",
            Function::NAK => "Negative Acknowledge",
            Function::NUL => "Null",
            Function::SOH => "Start of Heading",
            Function::STX => "Start of Text",
            Function::SUB => "Substitute",
            Function::SYN => "Synchronous Idle",
            Function::VT => "Line Tabulation",
            Function::APC => "Application Program Command",
            Function::BPH => "Break Permitted Here",
            Function::CCH => "Cancel Character",
            Function::CSI => "Control Sequence Introducer",
            Function::DCS => "Device Control String",
            Function::EPA => "End of Guarded Area",
            Function::ESA => "End of Selected Area",
            Function::HTJ => "Character Tabulation With Justification",
            Function::HTS => "Character Tabulation Set",
            Function::MW => "Message Waiting",
            Function::NBH => "No Break Here",
            Function::NEL => "Next Line",
            Function::OSC => "Operating System Command",
            Function::PLD => "Partial Line Forward",
            Function::PLU => "Partial Line Backwards",
            Function::PM => "Privacy Message",
            Function::PU1 => "Private Use One",
            Function::PU2 => "Private Use Two",
            Function::RI => "Reverse Line Feed",
            Function::SCI => "Single Character Introducer",
            Function::SOS => "Start of String",
            Function::SPA => "Start of Guarded Area",
            Function::SSA => "Start of Selected Area",
            Function::SS2 => "Single-Shift Two",
            Function::SS3 => "Single-Shift Three",
            Function::ST => "String Terminator",
            Function::STS => "Set Transmit State",
            Function::VTS => "Line Tabulation Set",
            Function::CMD => "Coding Method Delimiter",
            Function::DMI => "Disable Manual Input",
            Function::EMI => "Enable Manual Input",
            Function::INT => "Interrupt",
            Function::LS1R => "Locking-Shift One Right",
            Function::LS2 => "Locking-Shift Two",
            Function::LS2R => "Locking-Shift Two Right",
            Function::LS3 => "Locking-Shift Three",
            Function::LS3R => "Locking-Shift Three Right",
            Function::RIS => "Reset to Initial State",
            Function::CBT => "Cursor Backwards Tabulation",
            Function::CHA => "Cursor Character Absolute",
            Function::CHT => "Cursor Forward Tabulation",
            Function::CNL => "Cursors Next Line",
            Function::CPL => "Cursor Preceding Line",
            Function::CPR => "Active Position Report",
            Function::CTC => "Cursor Tabulation Control",
            Function::CUB => "Cursor Left",
            Function::CUD => "Cursor Down",
            Function::CUF => "Cursor Right",
            Function::CUP => "Cursor Position",
            Function::CUU => "Cursor Up",
            Function::CVT => "Cursor Line Tabulation",
            Function::DA => "Device Attributes",
            Function::DAQ => "Define Area Qualification",
            Function::DCH => "Delete Character",
            Function::DL => "Delete Line",
            Function::DSR => "Device Status Report",
            Function::DTA => "Dimension Text Area",
            Function::EA => "Erase Area",
            Function::ECH => "Erase Character",
            Function::ED => "Erase in Page",
            Function::EF => "Erase in Field",
            Function::EL => "Erase in Line",
            Function::FNK => "Function Key",
            Function::FNT => "Font Selection",
            Function::GCC => "Graphic Character Combination",
            Function::GSM => "Graphic Size Modification",
            Function::GSS => "Graphic Size Selection",
            Function::HPA => "Character Position Absolute",
            Function::HPB => "Character Position Backwards",
            Function::HPR => "Character Position Forward",
            Function::HVP => "Character and Line Position",
            Function::ICH => "Insert Character",
            Function::IDCS => "Identify Device Control String",
            Function::IGS => "Identify Graphic Subrepertoire",
            Function::IL => "Insert Line",
            Function::JFY => "Justify",
            Function::MC => "Media Copy",
            Function::NP => "Next Page",
            Function::PEC => "Presentation Expand or Contract",
            Function::PFS => "Page Format Selection",
            Function::PP => "Preceding Page",
            Function::PPA => "Page Position Absolute",
            Function::PPB => "Page Position Backwards",
            Function::PPR => "Page Position Forward",
            Function::PTX => "Parallel Texts",
            Function::QUAD => "Quad",
            Function::REP => "Repeat",
            Function::RM => "Reset Mode",
            Function::SACS => "Set Additional Character Representation",
            Function::SAPV => "Select Alternative Presentation Variants",
            Function::SCO => "Select Character Orientation",
            Function::SCP => "Select Character Path",
            Function::SCS => "Set Character Spacing",
            Function::SD => "Scroll Down",
            Function::SDS => "Start Directed String",
            Function::SEE => "Select Editing Extent",
            Function::SEF => "Sheet Eject and Feed",
            Function::SGR => "Select Graphic Rendition",
            Function::SHS => "Select Character Spacing",
            Function::SIMD => "Select Implicit Movement Direction",
            Function::SL => "Scroll Left",
            Function::SLH => "Set Line Home",
            Function::SLL => "Set Line Limit",
            Function::SLS => "Set Line Spacing",
            Function::SM => "Set Mode",
            Function::SPD => "Select Presentation Direction",
            Function::SPH => "Set Page Home",
            Function::SPI => "Spacing Increment",
            Function::SPL => "Set Page Limit",
            Function::SPQR => "Select Page Quality and Rapidity",
            Function::SR => "Scroll Right",
            Function::SRCS => "Set Reduced Character Separation",
            Function::SRS => "Start Reversed String",
            Function::SSU => "Select Size Unit",
            Function::SSW => "Set Space Width",
            Function::STAB => "Selective Tabulation",
            Function::SU => "Scroll Up",
            Function::SVS => "Select Line Spacing",
            Function::TAC => "Tabulation Aligned Centred",
            Function::TALE => "Tabulation Aligned Leading Edge",
            Function::TATE => "Tabulation Aligned Trailing Edge",
            Function::TBC => "Tabulation Clear",
            Function::TCC => "Tabulation Centred on Character",
            Function::TSR => "Tabulation Stop Remove",
            Function::TSS => "Thin Space Specification",
            Function::VPA => "Line Position Absolute",
            Function::VPB => "Line Position Backwards",
            Function::VPR => "Line Position Forward",
            Function::PRIVATE => "Private Use / Experimental Use",
        }
    }

    fn short_description(&self) -> String {
        match function(&self) {
            Function::ACK => {
                String::from("Transmitted by a receiver as an affirmative response to the sender.")
            }
            Function::BEL => String::from("Calls for attention."),
            Function::BS => {
                String::from("Causes the active data position to be moved one character backwards.")
            }
            Function::CAN => String::from("Indicate that the preceding data is in error."),
            Function::CR => String::from("Move to the beginning of the line."),
            Function::DC1 => {
                String::from("Primarily intended for turning on or starting an ancillary device.")
            }
            Function::DC2 => {
                String::from("Primarily intended for turning on or starting an ancillary device.")
            }
            Function::DC3 => {
                String::from("Primarily intended for turning off or stopping an ancillary device.")
            }
            Function::DC4 => String::from(
                "Primarily intended for turning off, stopping, or interrupting an ancillary device."
            ),
            Function::DLE => String::from("Used exclusively to provide supplementary transmission control functions."),
            Function::EM => String::from("Identifies the physical end of a medium."),
            Function::ENQ => String::from("Transmitted by a sender as a request for a response from a receiver."),
            Function::EOT => String::from("Indicates the conclusion of the transmission of one or more texts."),
            Function::ESC => String::from("Used for code extension purposes."),
            Function::ETB => String::from(
                concat!(
                    "Indicates the end of a block of data, where the data are divided into such blocks for ",
                    "transmission purposes."
                )
            ),
            Function::ETX => String::from("Indicates the end of a text."),
            Function::FF => String::from(
                "Causes the active presentation position to be moved to the line home position of the next line."
            ),
            Function::HT => String::from(
                concat!(
                    "Causes the active presentation position to be moved to the following character tabulation stop ",
                    "in the presentation component."
                )
            ),
            Function::IS1 => String::from("Separates and qualifies data logically."),
            Function::IS2 => String::from("Separates and qualifies data logically."),
            Function::IS3 => String::from("Separates and qualifies data logically."),
            Function::IS4 => String::from("Separates and qualifies data logically."),
            Function::LF => String::from("Move to following line."),
            Function::LS0 => String::from("Used for code extension purposes."),
            Function::LS1 => String::from("Used for code extension purposes."),
            Function::NAK => String::from("Transmitted by a receiver as a negative response to the sender."),
            Function::NUL => String::from("Used for media-fill or time-fill."),
            Function::SOH => String::from("Indicates the beginning of a heading."),
            Function::STX => String::from("Indicates the beginning of a text and the end of a heading."),
            Function::SUB => String::from(
                "Used in the place of a character that has been found to be invalid or in error"
            ),
            Function::SYN => String::from(
                "Used by a synchronous transmission system in the absence of any other character."
            ),
            Function::VT => String::from("Move to the next line that has a line tabulation stop."),
            Function::APC => String::from("Opening delimiter of a control string for application program use."),
            Function::BPH => String::from("A break may occur here when text is formatted."),
            Function::CCH => String::from(
                concat!(
                    "Indicates that both the preceding graphic character in the data stream, and this character ",
                    "should be ignored."
                )
            ),
            Function::CSI => String::from("Used as the first character of a longer control sequence."),
            Function::DCS => String::from("Opening delimiter of a control string for device control use."),
            Function::EPA => String::from("End of an area that protects its content against unwanted alteration."),
            Function::ESA => String::from(
                "End of an area selected for transferring or transmitting to an ancillary input/output device."
            ),
            Function::HTJ => String::from(
                concat!(
                    "Shift the contents of the active field forward, so that it ends in before of the next character ",
                    "tabulation stop."
                )
            ),
            Function::HTS => String::from("Set a character tabulation stop at the current position."),
            Function::MW => String::from("Sets a message waiting indicator in the receiving device."),
            Function::NBH => String::from("A line break shall not occur here when the text is formatted."),
            Function::NEL => String::from("Move to the next line."),
            Function::OSC => String::from("Opening delimiter of a control string for operating system use."),
            Function::PLD => String::from(
                "Move to an imaginary line with a partial offset downwards of the current line."
            ),
            Function::PLU => String::from(
                "Move to an imaginary line with a partial offset upwards of the current line."
            ),
            Function::PM => String::from("Opening delimiter of a control string for privacy message use."),
            Function::PU1 => String::from(
                "Reserved for function without standardized meaning, for private use as required."
            ),
            Function::PU2 => String::from(
                "Reserved for function without standardized meaning, for private use as required."
            ),
            Function::RI => String::from("Move to the preceding line."),
            Function::SCI => String::from(
                "This character and the following one represent a control function or a graphic character."
            ),
            Function::SOS => String::from("Opening delimiter of a control String."),
            Function::SPA => String::from("
                First position of a string that is guarded against manual alteration, transmission, transferor deletion."
            ),
            Function::SSA => String::from(
                concat!(
                    "First position of a string that is eligible to be transmitted or transferred to an ancillary ",
                    "input/output device."
                )
            ),
            Function::SS2 => String::from(
                concat!(
                    "Used for code extension purposes. Changes the meaning of the bit combinations following it in ",
                    "the data stream."
                )
            ),
            Function::SS3 => String::from(
                concat!(
                    "Used for code extension purposes. Changes the meaning of the bit combinations following it in ",
                    "the data stream."
                )
            ),
            Function::ST => String::from("Closing delimiter of a control string opened by APC, DCS, OSC, PM or SOS."),
            Function::STS => String::from(
                concat!(
                    "Establish the transmit state in the receiving device. In this state the transmission of data ",
                    "from the device is possible."
                )
            ),
            Function::VTS => String::from("Set a line tabulation stop at the active line."),
            Function::CMD => String::from("Delimits a string of data coded according to standard ECMA-35."),
            Function::DMI => String::from("Causes the manual input facilities of a device to be disabled."),
            Function::EMI => String::from("Causes the manual input facilities of a device to be enabled."),
            Function::INT => String::from(
                concat!(
                    "Indicate to the receiving device that the current process is to be interrupted and an agreed ",
                    "procedure is to be initiated."
                )
            ),
            Function::LS1R => String::from(
                "Used for code extension purposes. Changes the meaning of the following characters in the data stream."
            ),
            Function::LS2 => String::from(
                "Used for code extension purposes. Changes the meaning of the following characters in the data stream."
            ),
            Function::LS2R => String::from(
                "Used for code extension purposes. Changes the meaning of the following characters in the data stream."
            ),
            Function::LS3 => String::from(
                "Used for code extension purposes. Changes the meaning of the following characters in the data stream."
            ),
            Function::LS3R => String::from(
                "Used for code extension purposes. Changes the meaning of the following characters in the data stream."
            ),
            Function::RIS => String::from("Causes a device to be reset to its initial state."),
            Function::CBT => format!(
                "Causes the active position to be moved backwards by {} tabulation stops.", 
                param!(self, 0, 1)
            ),
            Function::CHA => format!(
                "Causes the active position to be set to character position {} in the active line",
                param!(self, 0, 1)
            ),
            Function::CHT => format!(
                "Causes the active position to be moved forward by {} tabulation stops.",
                param!(self, 0, 1)
            ),
            Function::CNL => format!(
                "Causes the active position to be moved to the first character of the {} following line.",
                param!(self, ordinal 0, 1)
            ),
            Function::CPL => format!(
                concat!(
                    "Causes the active position to be moved to the first character of the {} preceding line."
                ),
                param!(self, ordinal 0, 1)
            ),
            Function::CPR => format!(
                concat!(
                    "The active position is reported to be in line {} at character position {}."
                ),
                param!(self, 0, 1), param!(self, 1, 1)
            ),
            Function::CTC => explain_selection!(TabulationControl, self, 0),
            Function::CUB => format!(
                "Move the active position {} characters to the left.",
                param!(self, 0, 1)
            ),
            Function::CUD => format!(
                "Move the active position {} lines downwards.",
                param!(self, 0, 1)
            ),
            Function::CUF => format!(
                "Move the active position {} characters to the right.",
                param!(self, 0, 1)
            ),
            Function::CUP => format!(
                "Move the active position to line {} and character {}.",
                param!(self, 0, 1),
                param!(self, 1, 1),
            ),
            Function::CUU => format!(
                "Move the active position {} lines upwards.",
                param!(self, 0, 1)
            ),
            Function::CVT => format!(
                "Causes the active position to the {} following line tabulation stop.",
                param!(self, ordinal 0, 1)
            ),
            Function::DA => explain_selection!(DeviceAttributes, self, 0),
            Function::DAQ => format!(
                "The active position is the first position of a qualified area. This area {}.",
                explain_selection!(AreaQualification, self, 0),
            ),
            Function::DCH => format!(
                "Delete {} characters, starting from the active position to the left.",
                param!(self, 0, 1)
            ),
            Function::DL => format!(
                "Delete {} lines",
                param!(self, 0, 1)
            ),
            Function::DSR => explain_selection!(DeviceStatusReport, self, 0),
            Function::DTA => format!(
                concat!(
                    "Establishes the dimension of the text area for subsequent pages. Dimension perpendicular to the ",
                    "line orientation: {}. Dimension parallel to the line orientation: {}."
                ),
                param!(self, 0, 0),
                param!(self, 1, 0)
            ),
            Function::EA => format!("This {}.", explain_selection!(EraseArea, self, 0)),
            Function::ECH => format!(
                concat!(
                    "Erase {} characters from the active position to the right."
                ),
                param!(self, 0, 1)
            ),
            Function::ED => format!("This {}.", explain_selection!(ErasePage, self, 0)),
            Function::EF => format!("This {}.", explain_selection!(EraseField, self, 0)),
            Function::EL => format!("This {}.", explain_selection!(EraseLine, self, 0)),
            Function::FNK => format!("Function Key number {} has been pressed.",
                param!(self, 0, 1)
            ),
            Function::FNT => format!(
                concat!(
                    "Indicates that the {} should be set to font {} and be accessible as {} from here on."
                ),
                explain_selection!(Font, self, 0),
                param!(self, 1, 0),
                explain_selection!(Font, self, 0)
            ),
            Function::GCC => explain_selection!(GraphicCharacterCombination, self, 0),
            Function::GSM => format!(
                "Modify the text height and / or width of all fonts to {}% height and  {}% width.",
                param!(self, 0, 100),
                param!(self, 1, 100)
            ),
            Function::GSS => format!(
                "Modify the text height of all fonts to {}. The width is implicitly defined by the height.",
                param!(self, 0, 0)
            ),
            Function::HPA => format!(
                "Move the active data position to character position {} in the active line.",
                param!(self, 0, 1)
            ),
            Function::HPB => format!(
                "Move the active data position backwards by {} characters.",
                param!(self, 0, 1)
            ),
            Function::HPR => format!(
                "Move the active data position forward by {} characters.",
                param!(self, 0, 1)
            ),
            Function::HVP => format!(
                "Move the active data position to the {} line and {} character.",
                param!(self, ordinal 0, 1),
                param!(self, ordinal 1, 1)
            ),
            Function::ICH => format!(
                "Prepare the insertion of {} characters.",
                param!(self, 0, 1)
            ),
            Function::IDCS => explain_selection!(IdentifyDeviceControlString, self, 0),
            Function::IGS => format!(
                "The graphic subrepertoire {} is used in the subsequent text.",
                param!(self, 0, 0)
            ),
            Function::IL => format!(
                "Prepare the insertion of {} liens.",
                param!(self, 0, 1)
            ),
            Function::JFY => explain_selection!(Justification, self, 0),
            Function::MC => explain_selection!(MediaCopy, self, 0),
            Function::NP => format!(
                "Display the {} following page in the presentation component.",
                param!(self, ordinal 0, 1)
            ),
            Function::PEC => format!(
                concat!(
                    "Display the following graphic characters with spacing and extent in {}."
                ),
                explain_selection!(PresentationExpandContract, self, 0)
            ),
            Function::PFS => explain_selection!(PageFormat, self, 0),
            Function::PP => format!(
                "Display the {} preceding page in the presentation component.",
                param!(self, ordinal 0, 1)
            ),
            Function::PPA => format!(
                "Causes the active data position to be moved to the corresponding character position on page {}.",
                param!(self, 0, 1)
            ),
            Function::PPB => format!(
                concat!(
                    "Causes the active data position to be moved to the corresponding character position on the {} ",
                    "previous pages."
                ),
                param!(self, ordinal 0, 1)
            ),
            Function::PPR => format!(
                concat!(
                    "Causes the active data position to be moved to the corresponding character position on the {} ",
                    "following pages."
                ),
                param!(self, ordinal 0, 1)
            ),
            Function::PTX => explain_selection!(ParallelText, self, 0),
            Function::QUAD => format!(
                "Indicates the end of a string of graphic characters that are to be positioned on a single line {}.",
                explain_selection!(Alignment, self, 0)
            ),
            Function::REP => format!(
                "Repeat the previous graphic character {} times.",
                param!(self, 0, 1)
            ),
            Function::RM => format!(
                "Reset the following Modes: {}",
                self.parameters.iter().map(|value| {
                    value.parse::<Mode>().expect("Expect only valid Modes").name()
                }).fold(String::new(), |mut modes, mode| {
                    modes.push_str(", ");
                    modes.push_str(&mode);
                    modes
                })
            ),
            Function::SACS => format!(
                "Enlarge inter-character escapement by {} units.",
                param!(self, 0, 0)
            ),
            Function::SAPV => format!(
                "Select an alternative presentation variant for the subsequent text. {}",
                explain_selection!(PresentationVariant, self, 0)
            ),
            Function::SCO => format!(
                "Establishes the amount of rotation of graphic characters following. {}",
                explain_selection!(CharacterOrientation, self, 0)
            ),
            Function::SCP => format!(
                "Change the character path. {} {}",
                explain_selection!(CharacterPath, self, 0),
                explain_selection!(CharacterPathScope, self, 1)
            ),
            Function::SCS => format!(
                "Character are spaced by {} units",
                param!(self, 0, 0)
            ),
            Function::SD => format!(
                concat!(
                    "Scroll down by {} lines."
                ),
                param!(self, 0, 1)
            ),
            Function::SDS => explain_selection!(StringDirection, self, 0),
            Function::SEE => format!(
                "When character or line insertions or deletions require content to be shifted, {}.",
                explain_selection!(EditingExtend, self, 0)
            ),
            Function::SEF => format!(
                "{} {}",
                explain_selection!(Load, self, 0),
                explain_selection!(Stack, self, 1)
            ),
            Function::SGR => format!(
                "Change the representation of following text. {}.",
                self.parameters.iter().map(|value| {
                    value.parse::<GraphicRendition>().expect("Expect only valid Graphic Renditions").explain()
                }).fold(String::new(), |mut renditions, rendition| {
                    renditions.push_str(", ");
                    renditions.push_str(&rendition);
                    renditions
                })
            ),
            Function::SHS => explain_selection!(CharacterSpacing, self, 0),
            Function::SIMD => explain_selection!(MovementDirection, self, 0),
            Function::SL => format!(
                "Scroll left by {} characters",
                param!(self, 0, 1)
            ),
            Function::SLH => format!(
                "Set the line home position to line {} for the active and following lines.",
                param!(self, 0, 0)
            ),
            Function::SLL => format!(
                "Set the line limit position to character position {} for the active and following lines.",
                param!(self, 0, 0)
            ),
            Function::SLS => format!(
                "Set the line spacing to {}, expressed in the unit established by 'Select Size Unit' (SSU).",
                param!(self, 0, 0)
            ),
            Function::SM => format!(
                "Set the following Modes: {}",
                self.parameters.iter().map(|value| {
                    value.parse::<Mode>().expect("Expect only valid Modes").name()
                }).fold(String::new(), |mut modes, mode| {
                    modes.push_str(", ");
                    modes.push_str(&mode);
                    modes
                })
            ),
            Function::SPD => format!(
                "In {}, set the presentation direction to {}.",
                explain_selection!(PresentationDirectionScope, self, 1),
                explain_selection!(PresentationDirection, self, 0)
            ),
            Function::SPH => format!(
                "Set the page home position to line position {}.",
                param!(self, 0, 0)
            ),
            Function::SPI => format!(
                concat!(
                    "Establish the spacing increment to {} line spacing and {} character spacing, expressed in the ",
                    "unit established by 'Select Size Unit' (SSU)."
                ),
                param!(self, 0, 0),
                param!(self, 1, 0)
            ),
            Function::SPL => format!(
                "Set the page limit position to line {} for the active and following lines.",
                param!(self, 0, 0)
            ),
            Function::SPQR => explain_selection!(PrintQuality, self, 0),
            Function::SR => format!(
                "Scroll right by {} characters.",
                param!(self, 0, 1)
            ),
            Function::SRCS => format!(
                "Establish reduced inter-character escapement by {} units for subsequent text.",
                param!(self, 0, 0)
            ),
            Function::SRS => explain_selection!(ReversedString, self, 0),
            Function::SSU => format!(
                "The size unit for operation is expressed as {}",
                explain_selection!(SizeUnit, self, 0)
            ),
            Function::SSW => format!(
                "Set the escapement of space to {} units.",
                param!(self, 0, 0)
            ),
            Function::STAB => format!(
                concat!(
                    "Causes subsequent text in the presentation component to be aligned according to the position and ",
                    "properties of a tabulation stop which is selected from a list according to the value of the ",
                    "parameter: {}."
                ),
                param!(self, 0, 0)
            ),
            Function::SU => format!(
                "Scroll up by {} lines.",
                param!(self, 0, 1)
            ),
            Function::SVS => explain_selection!(LineSpacing, self, 0),
            Function::TAC => format!(
                concat!(
                    "Causes a character tabulation stop calling for centring to be set at character position {} in ",
                    "the active line."
                ),
                param!(self, 0, 0)
            ),
            Function::TALE => format!(
                concat!(
                    "Causes a character tabulation stop calling for leading edge alignment to be set at character ",
                    "position {} in the active line."
                ),
                param!(self, 0, 0)
            ),
            Function::TATE => format!(
                concat!(
                    "Causes a character tabulation stop calling for trailing edge alignment to be set at character ",
                    "position {} in the active line."
                ),
                param!(self, 0, 0)
            ),
            Function::TBC => explain_selection!(ClearTabulation, self, 0),
            Function::TCC => format!(
                concat!(
                    "Causes a character tabulation stop calling for alignment of a target graphic character {} to be ",
                    "set at character position {} in the active line."
                ),
                param!(self, 1, 32),
                param!(self, 0, 0)
            ),
            Function::TSR => format!(
                concat!(
                    "Causes any character tabulation stop at character position {} in the active line and subsequent ",
                    "lines to be cleared."
                ),
                param!(self, 0, 0)
            ),
            Function::TSS => format!(
                "Establish the width of a thin space for subsequent text to be {} units.",
                param!(self, 0, 0)
            ),
            Function::VPA => format!(
                concat!(
                    "Causes the active data position to be moved to line position {} in the data component in a ",
                    "direction parallel to the line progression."
                ),
                param!(self, 0, 1)
            ),
            Function::VPB => format!(
                concat!(
                    "Causes the active data position to be moved by {} line positions in the data component in a ",
                    "direction opposite of that of the line progression."
                ),
                param!(self, 0, 1)
            ),
            Function::VPR => format!(
                concat!(
                    "Causes the active data position to be moved {} line positions in the data component in a ",
                    "direction parallel of the line progression."
                ),
                param!(self, 0, 1)
            ),
            Function::PRIVATE => String::from("Reserved for private use / not standardized."),
        }
    }

    fn long_description(&self) -> String {
        match function(&self) {
            Function::BEL => String::from(
                "Calls for the attention of the user by controlling an alarm or attention device.",
            ),
            Function::BS => String::from(
                concat!(
                    "Causes the active data position to be moved one character position in the direction opposite to ",
                    "that of the implicit character movement. The direction of the implicit movement depends on the ",
                    "parameter value of 'Select Implicit Movement Direction' (SIMD)."
                )
            ),
            Function::CAN => String::from(
                concat!(
                    "Indicates that the data preceding it is in error. As a result, this data shall be ignored. ",
                    "The specific meaning of this control function shall be defined for each application and/or ",
                    "between sender and recipient."
                )
            ),
            Function::CR => String::from(
                concat!(
                    "Move the cursor to the beginning of the line. The exact meaning depends on the setting of ",
                    "'Device Component Select Mode' (DCSM) and on the parameter value of 'Select Implicit Movement ",
                    "Direction' (SIMD).",
                    "\n",
                    "\n",
                    "If the DCSM is set to 'Presentation' and SIMD is set to 'Normal', it ",
                    "causes the active presentation position to be moved to the line home position of the same line ",
                    "in the presentation component. The line home position is established by the parameter value of ",
                    "'Set Line Home' SLH.",
                    "\n",
                    "With SIMD set to 'Opposite', it causes the active presentation position ",
                    "to be moved to the line limit position of the same line in the presentation component. ",
                    "The line limit position is established by the parameter value of 'Set Line Limit' (SLL).",
                    "\n",
                    "\n",
                    "If the DCSM is set to 'Data' and SIMD is set to 'Normal', it causes the active data position to ",
                    "be moved to the line home position of the same line in the data component. The line home ",
                    "position is established by the parameter value of 'Set Line Home' (SLH)",
                    "\n",
                    "With SIMD set to 'Opposite', it causes the active data position to be moved to the line limit ",
                    "position of the same line in the data component. The line limit position position is established ",
                    "by the parameter value of 'Set Line Limit' (SLL)."
                )
            ),
            Function::DC1 => String::from(
                concat!(
                    "Primarily intended for turning on or starting an ancillary device. If it is not required for ",
                    "this purpose, it may be used to restore a device to the basic mode of operation. When used for ",
                    "data flow control, it is also sometimes called X-ON."
                )
            ),
            Function::DC2 => String::from(
                concat!(
                    "Primarily intended for turning on or starting an ancillary device. If it is not required for ",
                    "this purpose, it may be used to set a device to a special mode of operation (in which case DC1 ",
                    "is used to restore the mode of operation to the normal mode), or for any other device control ",
                    "function not provided by other DCs."
                )
            ),
            Function::DC3 => String::from(
                concat!(
                    "Primarily intended for turning off or stopping an ancillary device. This function may be a ",
                    "secondary level stop, for example wait, pause, stand-by, or halt (in which case DC1 is used to ",
                    "restore normal operation). If it is not required for this purpose, it may be used for any other ",
                    "device control function not provided by other DCs."
                )
            ),
            Function::DC4 => String::from(
                concat!(
                    "Primarily intended for turning off, stopping, or interrupting an ancillary device. If it is not ",
                    "required for this purpose, it may be used for any other device control function not provided by ",
                    "other DCs."
                )
            ),
            Function::EM => String::from(
                concat!(
                    "Identifies the physical end of a medium, or the end of the used portion of a medium, or the end ",
                    "of the wanted portion of data recorded on a medium."
                )
            ),
            Function::ESC => String::from(
                concat!(
                    "Used for code extension purposes. It causes the meanings of a limited number of bit combinations ",
                    "following it in the data stream to be changed."
                )
            ),
            Function::FF => String::from(
                concat!(
                    "Causes the active presentation position to be moved to the corresponding character position of ",
                    "the line at the page home position of the next form or page in the presentation component. The ",
                    "page home position is established by the parameter value of 'Set Page Home' (SPH)."
                )
            ),
            Function::HT => String::from(
                concat!(
                    "Causes the active presentation position to be moved to the following character tabulation stop ",
                    "in the presentation component. In addition, if that following character tabulation stop has been ",
                    "set by 'Tabulation Align Center' (TAC), 'Tabulation Align Leading Edge' (TALE), or 'Tabulation ",
                    "Centred On Character' (TACE), it causes the beginning of a string of text which is to be ",
                    "positioned within a line according to the properties of that tabulation stop. The end of the ",
                    "string is indicated by the next occurrence of HT, CR, or NEL in the data stream."
                )
            ),
            Function::IS1 => String::from(
                concat!(
                    "Separates and qualifies data logically, its specific meaning has to be defined for each ",
                    "application. If this control function is used in hierarchical order, it may delimit a data item ",
                    "called a unit."
                )
            ),
            Function::IS2 => String::from(
                concat!(
                    "Separates and qualifies data logically, its specific meaning has to be defined for each ",
                    "application. If this control function is used in hierarchical order, it may delimit a data item ",
                    "called a record."
                )
            ),
            Function::IS3 => String::from(
                concat!(
                    "Separates and qualifies data logically, its specific meaning has to be defined for each ",
                    "application. If this control function is used in hierarchical order, it may delimit a data item ",
                    "called a group."
                )
            ),
            Function::IS4 => String::from(
                concat!(
                    "Separates and qualifies data logically, its specific meaning has to be defined for each ",
                    "application. If this control function is used in hierarchical order, it may delimit a data item ",
                    "called a file."
                )
            ),
            Function::LF => String::from(
                concat!(
                    "If the 'Device Component Select Mode' is set to 'Presentation', it causes the active ", 
                    "presentation position to be moved to the corresponding character position of the following line ",
                    "in the presentation component.",
                    "\n",
                    "\n",
                    "If the 'Device Component Select Mode' is set to 'Data', it causes the active data position to be ",
                    "moved to the corresponding character position of the following line in the data component."
                )
            ),
            Function::LS0 => String::from(
                concat!(
                    "Used for code extension purposes. It causes the meanings of the bit combinations following it in ",
                    "the data stream to be changed."
                )
            ),
            Function::LS1 => String::from(
                concat!(
                    "Used for code extension purposes. It causes the meanings of the bit combinations following it in ",
                    "the data stream to be changed."
                )
            ),
            Function::NUL => String::from(
                concat!(
                    "Used for media-fill or time-fill. NUL characters may be inserted into, or removed from, a data ",
                    "stream without affecting information content of that stream, but such action may affect the ",
                    "information layout and/or the control of equipment."
                )
            ),
            Function::SYN => String::from(
                concat!(
                    "Used by a synchronous transmission system in the absence of any other character (idle condition) ",
                    "to provide a signal from which synchronism may be achieved or retained between data terminal ",
                    "equipment."
                )
            ),
            Function::VT => String::from(
                concat!(
                    "Causes the active presentation position to be moved in the presentation component to the ",
                    "corresponding character position on th e line at which the following line tabulation stop is ",
                    "set."
                )
            ),
            Function::APC => String::from(
                concat!(
                    "Used as the opening delimiter of a control string for application program use. The command ",
                    "string following may consist of bit combinations in the range 00/08 to 00/13 and 02/00 to 07/14. ",
                    "The control string is closed by the terminating delimiter 'String Terminator' (ST). The ",
                    "interpretation of the command string depends on the relevant application program."
                )
            ),
            Function::CCH => String::from(
                concat!(
                    "Indicates that both the preceding graphic character in the data stream (represented by one or ",
                    "more bit combinations), including 'Space', and the control function itself are to be ignored ",
                    "for further interpretation in the data stream.",
                    "\n",
                    "\n",
                    "If the character preceding CCH in the data stream is a control function (represented by one or ",
                    "more bit combinations), the effect of CCH is not defined."
                )
            ),
            Function::DCS => String::from(
                concat!(
                    "Used as the opening delimiter of a control string for device control use. The command string ", 
                    "following may consist of bit combinations in the range 00/08 to 00/13 and 02/00 to 07/14. The ",
                    "control string is closed by the terminating delimiter 'String Terminator' (ST)."
                )
            ),
            Function::EPA => String::from(
                concat!(
                    "Indicates that the active presentation position is the last of a string of character positions ",
                    "in the presentation component, the contents of which are protected against manual alteration, ",
                    "are guarded against transmission or transfer, depending on the settings of 'Guarded Area ",
                    "Transfer Mode' (GATM), and may be protected against erasure, depending on the setting of ",
                    "'Erasure Mode' (ERM). The beginning of this string is indicated by 'Start of Guarded Area' (SPA)."
                )
            ),
            Function::ESA => String::from(
                concat!(
                    "Indicates that the active presentation position is the last of a string of character positions ",
                    "in the presentation component, the contents of which are eligible to be transmitted in the form ",
                    "of a data stream or transferred to an auxiliary input/output device. The beginning of the string ",
                    "is indicated by 'Start of Selected Area' (SSA)"
                )
            ),
            Function::HTJ => String::from(
                concat!(
                    "Causes the contents of the active field (the field in the presentation component that contains ",
                    "active presentation position) to be shifted forwarded, so that it ends at the character position ",
                    "preceding the following character tabulation stop. The active presentation position is moved to ",
                    "that following character tabulation stop. The character position which precede the beginning of ",
                    "the shifted string are put into the erased state."
                )
            ),
            Function::HTS => String::from(
                concat!(
                    "Causes a character tabulation stop to be set at the active presentation position in the ",
                    "presentation component. The number of lines affected depends on the setting of the ",
                    "'Tabulation Stop Mode' (TSM)."
                )
            ),
            Function::MW => String::from(
                concat!(
                    "Sets a message waiting indicated in the receiving device. An appropriate acknowledgement to the ",
                    "receipt of MW may be given by using 'Device Status Report' (DSR)."
                )
            ),
            Function::NBH => String::from(
                concat!(
                    "Indicates a point where a line break shall not occur when text is formatted. This may occur ",
                    "between two graphic characters, either or both which may be 'Space'."
                )
            ),
            Function::NEL => String::from(
                concat!(
                    "The effect of NEL depends on the setting of the 'Device Component Select Mode' (DCSM) and the ",
                    "parameter value of 'Select Implicit Movement Direction' (SIMD).",
                    "\n",
                    "\n",
                    "If DCSM is set to 'Presentation' and SIMD equal to 'Normal', it causes the active presentation ",
                    "position to be moved to the line home position of the following line in the presentation ",
                    "component. The line home position may be established by the parameter of 'Set Line Home' (SLH). ",
                    "\n",
                    "With SIMD equal to 'Opposite', it causes the active presentation position to be moved to the ",
                    "line limit position of the following line in the presentation component. The line limit position ",
                    "may be established by the parameter of 'Set Line Limit' (SLL).",
                    "\n",
                    "\n",
                    "If DCSM is set to 'Data' and SIMD equal to 'Normal', it causes the active data ",
                    "position to be moved to the line home position of the following line in the data ",
                    "component. The line home position may be established by the parameter of 'Set Line Home' (SLH). ",
                    "\n",
                    "With SIMD equal to 'Opposite', it causes the active data position to be moved to the ",
                    "line limit position of the following line in the data component. The line limit position ",
                    "may be established by the parameter of 'Set Line Limit' (SLL)."
                )
            ),
            Function::OSC => String::from(
                concat!(
                    "Opening delimiter of a control string for operating system use. The command string following may ",
                    "consist of a sequence of bit combinations in the range 00/08 to 00/13 and 02/00 to 07/14. The ",
                    "control string is closed by the terminating delimiter 'String Terminator' (ST). The ",
                    "interpretation of the command string depends on the relevant operating system."
                )
            ),
            Function::PLD => String::from(
                concat!(
                    "Move the active presentation position in the presentation component to the corresponding ",
                    "position of an imaginary line with a partial offset in the direction of line progression. This ",
                    "offset should be sufficient either to image following characters as subscripts until the first ",
                    "following occurrence of 'Partial Line Backwards' (PLU) in the data stream, or, if preceding ",
                    "characters were imaged as superscripts, to restore imaging of following characters to the active ",
                    "line."
                )
            ),
            Function::PLU => String::from(
                concat!(
                    "Move the active presentation position in the presentation component to the corresponding ",
                    "position of an imaginary line with a partial offset in the direction opposite of line ",
                    "progression. This offset should be sufficient either to image following characters as ",
                    "superscripts until the first following occurrence of 'Partial Line Forward' (PLD) in the data ",
                    "stream, or, if preceding characters were imaged as subscripts, to restore imaging of following ",
                    "characters to the active line."
                )
            ),
            Function::PM => String::from(
                concat!(
                    "Indicates the beginning of a control string privacy message use. The command string following ",
                    "may consist of bit combination sin the range 00/08 to 00/13 and 02/00 to 07/14. The control ",
                    "string is closed by the terminating delimiter 'String Terminator' (ST). The interpretation", 
                    "of the command string depends on the relevant privacy discipline."
                )
            ),
            Function::RI => String::from(
                concat!(
                    "If the 'Device Component Select Mode' (DCSM) is set to 'Presentation', it causes the active ",
                    "presentation position to be moved in the presentation component to the corresponding character ",
                    "position of the preceding line.",
                    "\n",
                    "\n",
                    "If the 'Device Component Select Mode' (DCSM) is set to 'Data', it causes the active ",
                    "data position to be moved in the data component to the corresponding character ",
                    "position of the preceding line."
                )
            ),
            Function::SCI => String::from(
                concat!(
                    "This and the bit combination following it are used to represent a control function or a graphic ",
                    "character. The bit combination following SCI must be from 00/08 to 00/13 or 02/00 to 07/14. The ",
                    "use of SCI is reserved for future standardization."
                )
            ),
            Function::SOS => String::from(
                concat!(
                    "Used as the opening delimiter of a control string. The character string following may consist of ",
                    "any bit combinations, except those representing SOS or 'String Terminator' (ST). The control ",
                    "string is closed by the terminating delimiter 'String Terminator' (ST). The interpretation of the ",
                    "character string depends on the application."
                )
            ),
            Function::SPA => String::from(
                concat!(
                    "Used to indicate that the active presentation position is the first of a string of character ",
                    "positions in the presentation component, the contents of which are protected against manual ",
                    "alteration, are guarded against transmission or transfer, depending on the setting of 'Guarded ",
                    "Area Transfer Mode' (GATM), and may be protected against erasure, depending on the setting of ",
                    "the 'Erasure Mode' (ERM). The end of this string is indicated by 'End of Guarded Area' (EPA)."
                )
            ),
            Function::SSA => String::from(
                concat!(
                    "Indicates that the active presentation position is the first of a string of character positions ",
                    "in the presentation component, the contents of which are eligible to be transmitted in the form ",
                    "of a data stream or transferred to an ancillary input/output device. The end of this string is ",
                    "indicated by 'End of Selected Area' (ESA). ",
                    "\n",
                    "\n",
                    "The string of character actually transmitted or transferred depends on the setting of 'Guarded ",
                    "Area Transfer mode' (GATM) and on any guarded areas established by 'Define Area Qualification' ",
                    "(DAQ), or by 'Start of Guarded Area' (SPA) and 'End of Guarded Area' (EPA)."
                )
            ),
            Function::STS => String::from(
                concat!(
                    "Used to establish the transmit state in the receiving device. In this state the transmission of ",
                    "data from the device is possible. The actual initiation of transmission of data is performed by ",
                    "a data communication or input/output interface control procedure, which is outside of the scope ",
                    "of this Standard.",
                    "\n",
                    "\n",
                    "The transmit state is established either by this appearing in the received data stream, or by ",
                    "the operation of an appropriate key on a keyboard."
                )
            ),
            Function::CMD => String::from(
                concat!(
                    "Delimits a string of data coded according to standard ECMA-35, and to switch to a general level ",
                    "of control. The use of this is not mandatory if the higher level protocol defines means of ",
                    "delimiting the string, for instance by specifying the length of the string."
                )
            ),
            Function::RIS => String::from(
                concat!(
                    "Reset the receiving device to its initial state, i.e. the state it has after it is made ",
                    "operational. This may imply, if applicable: clear tabulation stops, remove qualified areas, ",
                    "reset graphic rendition, put all character positions into the erased state, move the active ",
                    "presentation position to the first position of the first line in the presentation component, ",
                    "move the active data position to the first character position in the first line in the data ",
                    "component, set the modes into the reset state, etc.."
                )
            ),
            Function::CBT => format!(
                concat!(
                    "Causes the active presentation position to be moved to the character position corresponding ",
                    "to the {} preceding character tabulation stop in the presentation component, according to ",
                    "the character path.",

                ),
                param!(self, ordinal 0, 1)
            ),
            Function::CHA => format!(
                concat!(
                    "Causes the active presentation position to be moved to character position {} in the active line ",
                    "in the presentation component"
                ),
                param!(self, 0, 1)
            ),
            Function::CHT => format!(
                concat!(
                    "Causes the active presentation position to be moved to the character position corresponding to ",
                    "the {} following character tabulation stop in the presentation component, according to the ",
                    "character path."
                ),
                param!(self, ordinal 0, 1)
            ),
            Function::CNL => format!(
                concat!(
                    "Causes the active presentation position to be moved to the first character position of the {} ",
                    "following line in the presentation component."
                ),
                param!(self, ordinal 0, 1)
            ),
            Function::CPL => format!(
                concat!(
                    "Causes the active presentation position to be moved to the first character position of the {} ",
                    "preceding line in the presentation component."
                ),
                param!(self, ordinal 0, 1)
            ),
            Function::CPR => format!(
                concat!(
                    "If the 'Device Component Select Mode' (DCSM) is set to 'Presentation', reports the active ",
                    "presentation position of the sending device as residing in the presentation component at the {} ",
                    "line position according to the line progress and at the {} character position according to the ",
                    "character path.",
                    "\n\n",
                    "If the 'Device Component Select Mode' (DCSM) is set to 'Data', reports the active data position ",
                    "of the sending device as residing in the data component at the {} line position according to the ",
                    "line progression and at the {} character position according to the character progression.",
                    "\n\n",
                    "CPR may be solicited by a 'Device Status Report' (DSR) or be sent unsolicited."
                ),
                param!(self, ordinal 0, 1),
                param!(self, ordinal 1, 1),
                param!(self, ordinal 0, 1),
                param!(self, ordinal 1, 1),
            ),
            Function::CUB => format!(
                concat!(
                    "Causes the active presentation position to be moved leftwards in the presentation component by ",
                    "{} character positions, if the character path is horizontal, or by {} line positions, if the ",
                    "character path is vertical."
                ),
                param!(self, 0, 1),
                param!(self, 0, 1)
            ),
            Function::CUD => format!(
                concat!(
                    "Causes the active presentation position to be moved downwards in the presentation component by ",
                    "{} line positions, if the character path is horizontal, or by {} character positions, if the ",
                    "character path is vertical."
                ),
                param!(self, 0, 1),
                param!(self, 0, 1)
            ),
            Function::CUF => format!(
                concat!(
                    "Causes the active presentation position to be moved rightwards in the presentation component by ",
                    "{} character positions, if the character path is horizontal, or by {} line positions, if the ",
                    "character path is vertical."
                ),
                param!(self, 0, 1),
                param!(self, 0, 1)
            ),
            Function::CUP => format!(
                concat!(
                    "Causes the active presentation position to be moved in the presentation component to the {} line ",
                    "position according to the line progression, and to the {} character position according to the ",
                    "character path.",
                ),
                param!(self, ordinal 0, 1),
                param!(self, ordinal 1, 1)
            ),
            Function::CUU => format!(
                concat!(
                    "Causes the active presentation position to be moved upwards in the presentation component by {} ",
                    "line positions, if the character path is horizontal, or by {} character positions, if the ",
                    "character path is vertical."
                ),
                param!(self, 0, 1),
                param!(self, 0, 1)
            ),
            Function::CVT => format!(
                concat!(
                    "Causes the active presentation position to be moved to the character position of the line ",
                    "corresponding to the {} following line tabulation stop in the presentation component."
                ),
                param!(self, ordinal 0, 1)
            ),
            Function::DAQ => format!(
                concat!(
                    "This is used to indicate that the active presentation position in the presentation component is ",
                    "the first character position of a qualified area. The last character position of the qualified ",
                    "area is the character position in the presentation component immediately preceding the first ",
                    "character position of the following qualified area. This area {}."
                ),
                explain_selection!(AreaQualification, self, 0)
            ),
            Function::DCH => format!(
                concat!(
                    "If the 'Device Component Select Mode' (DSCM) is set to 'Presentation', it causes the contents ",
                    "of the active presentation position and, depending on the setting of 'Character Editing Mode' ",
                    "(HEM), the contents of the preceding or following character positions to be removed from the ",
                    "presentation component. The resulting gap of {} characters is closed by shifting the contents of ",
                    "the adjacent character positions towards the active presentation position. At the other end of ",
                    "the shifter part {} character positions are put into the erased state.",
                    "\n\n",
                    "The extend of the shifted part is established by 'Select Editing Extend' (SEE).",
                    "\n\n",
                    "The effect of this on the start or end of a selected area, the start or end of a qualified area, ",
                    "or a tabulation stop in the shifted part is undefined.",
                    "\n\n",
                    "If the 'Device Component Select Mode' (DCSM) is set to 'Data', it causes the contents of the ",
                    "active data position and, depending on the setting of 'Character Editing Mode' (HEM), the ",
                    "contents of the preceding or following character positions to be removed from the data ",
                    "component. The resulting gap of {} characters is closed by shifting the contents of the adjacent ",
                    "character positions towards the active data position. At the other end of the shifted part, {} ",
                    "character positions are put into the erased state."
                ),
                param!(self, 0, 1),
                param!(self, 0, 1),
                param!(self, 0, 1),
                param!(self, 0, 1)
            ),
            Function::DL => format!(
                concat!(
                    "If the 'Device Component Select Mode' (DSCM) is set to 'Presentation', it causes the contents of ",
                    "the active line (the line that contains the active presentation position) and, depending on the ",
                    "setting of the 'Line Editing Mode' (VEM), the contents of the preceding or following lines to be ",
                    "removed from the presentation component. The resulting gap of {} lines is closed by shifting the ",
                    "contents of a number of adjacent lines towards the active line. At the end of the shifted part, ",
                    "{} lines are put into the erased state. The active presentation position is moved to the line ",
                    "home position in the active line. The line home position is established by the parameter value ",
                    "of 'Set Line Home' (SLH). If the 'Tabulation Stop Mode' (TSM) is set to 'Single', character ",
                    "tabulation stops are cleared in the lines that are put into the erased state.",
                    "\n\n",
                    "The extend of the shifted part is established by 'Select Editing Extend' (SEE).",
                    "\n\n",
                    "Any occurrences of the start or end of a selected area, the start or end of a qualified area, or ",
                    "a tabulation stop in the shifted part, are also shifted.",
                    "\n\n",
                    "If the 'Device Component Select Mode (DCSM) is set to 'Data', it causes the contents of the ",
                    "active line (the line that contains the active data position) and, depending on the settings of ",
                    "the 'Line Editing Mode' (VEM), the contents of the preceding or following lines to be removed ",
                    "from the data component. The resulting gap of {} lines is closed by shifting the contents of a ",
                    "number of adjacent lines towards the active line. At the other end of the shifted part, {} lines ",
                    "are put into the erased state. The active data position is moved to the line home position in ",
                    "the active line. The line home position is established by the parameter value of 'Set Line Home' ",
                    "(SLH)."
                ),
                param!(self, 0, 1),
                param!(self, 0, 1),
                param!(self, 0, 1),
                param!(self, 0, 1)
            ),
            Function::DTA => format!(
                concat!(
                    "Establishes the dimension of the text area for subsequent pages. The established dimensions ",
                    "remain in effect until the next occurrence of DTA in the data stream. The new dimension is ",
                    "specified to be {} in the direction perpendicular to the line orientation and {} parallel to the ",
                    "line orientation. The unit in which the value is expressed is that established by the parameter ",
                    "value of 'Select Size Unit' (SSU)."
                ),
                param!(self, 0, 0),
                param!(self, 1, 0)
            ),
            Function::EA => format!(
                concat!(
                    "If the 'Device Component Select Mode' (DCSM) is set to 'Presentation', {} in the presentation ",
                    "component. The contents of the removed area are put into the erased state.",
                    "\n\n",
                    "If the 'Device Component Select Mode' (DCSM) is set to 'Data', {} in the data component. The ",
                    "contents of the removed area are put into the erased state.",
                    "\n\n",
                    "Whether the character positions of protected areas are put into the erased state, or the ",
                    "character positions of unprotected areas only, depends on the settings of 'Erasure Mode' (ERM)."
                ),
                explain_selection!(EraseArea, self, 0),
                explain_selection!(EraseArea, self, 0)
            ),
            Function::ECH => format!(
                concat!(
                    "If the 'Device Component Select Mode' (DCSM) is set to 'Presentation', it causes the active ",
                    "presentation position and the following character positions in the presentation component to be ",
                    "put into the erased state. {} characters will be erased.",
                    "\n\n",
                    "If the 'Device Component Select Mode' (DCSM) is set to 'Data', it causes the active data position ",
                    "and the following character positions in the data component to be put into the erased state. {} ",
                    "characters will be erased.",
                    "\n\n",
                    "Whether the character positions of protected areas are put into the erased state, or the ",
                    "character positions of unprotected areas only, depends on the settings of 'Erasure Mode' (ERM)."
                ),
                param!(self, 0, 1),
                param!(self, 0, 1)
            ),
            Function::ED => format!(
                concat!(
                    "If the 'Device Component Select Mode' (DCSM) is set to 'Presentation', {} in the presentation ",
                    "component. The contents of the removed page are put into the erased state.",
                    "\n\n",
                    "If the 'Device Component Select Mode' (DCSM) is set to 'Data', {} in the data component. The ",
                    "contents of the removed page are put into the erased state.",
                    "\n\n",
                    "Whether the character positions of protected areas are put into the erased state, or the ",
                    "character positions of unprotected areas only, depends on the settings of 'Erasure Mode' (ERM)."
                ),
                explain_selection!(EraseArea, self, 0),
                explain_selection!(EraseArea, self, 0)
            ),
            Function::EF => format!(
                concat!(
                    "If the 'Device Component Select Mode' (DCSM) is set to 'Presentation', {} in the presentation ",
                    "component. The contents of the removed field are put into the erased state.",
                    "\n\n",
                    "If the 'Device Component Select Mode' (DCSM) is set to 'Data', {} in the data component. The ",
                    "contents of the removed field are put into the erased state.",
                    "\n\n",
                    "Whether the character positions of protected areas are put into the erased state, or the ",
                    "character positions of unprotected areas only, depends on the settings of 'Erasure Mode' (ERM)."
                ),
                explain_selection!(EraseArea, self, 0),
                explain_selection!(EraseArea, self, 0)
            ),
            Function::EL => format!(
                concat!(
                    "If the 'Device Component Select Mode' (DCSM) is set to 'Presentation', {} in the presentation ",
                    "component. The contents of the removed line are put into the erased state.",
                    "\n\n",
                    "If the 'Device Component Select Mode' (DCSM) is set to 'Data', {} in the data component. The ",
                    "contents of the removed line are put into the erased state.",
                    "\n\n",
                    "Whether the character positions of protected areas are put into the erased state, or the ",
                    "character positions of unprotected areas only, depends on the settings of 'Erasure Mode' (ERM)."
                ),
                explain_selection!(EraseArea, self, 0),
                explain_selection!(EraseArea, self, 0)
            ),
            Function::FNT => format!(
                concat!(
                    "{}\n\n",
                    "The active Font might be switched in the following data stream by 'Select Graphic Rendition (SGR)."
                ),
                self.short_description()
            ),
            Function::GSM => format!(
                concat!(
                    "Used to modify the text height and / or width of the subsequent text for all primary and ",
                    "alternatives fonts and established 'Graphic Size Select' (GSS). The established values remain in ",
                    "effect until the next occurrence of GSM or GSS in the data stream. The new size is set to to {}% ",
                    "height and {}% width."
                ),
                param!(self, 0, 100),
                param!(self, 1, 100)
            ),
            Function::GSS => format!(
                concat!(
                    "Used to establish the height for the subsequent text for all primary and alternative fonts. The ",
                    "established value remains in effect until the next occurrence of GSS in the data stream. The new ",
                    "height is set to {} with a unit established by 'Select Size Unit' (SSU)."
                ),
                param!(self, 0, 0)
            ),
            Function::HPA => format!(
                concat!(
                    "Causes the active data position to be moved to the character position {} in the active line (the ",
                    "line in the data component that contains the active data position)"
                ),
                param!(self, 0, 1)
            ),
            Function::HPB => format!(
                concat!(
                    "Causes the active data position to be moved by {} character positions in the data component in ",
                    "the direction opposite to that of the character progression."
                ),
                param!(self, 0, 1)
            ),
            Function::HPR => format!(
                concat!(
                    "Causes the active data position to be moved by {} character positions in the data component in ",
                    "the direction of character progression."
                ),
                param!(self, 0, 1)
            ),
            Function::HVP => format!(
                concat!(
                    "Causes the active data position to be moved in the data component to the {} line position ",
                    "according to the line progression and to the {} character position according to the character ",
                    "position."
                ),
                param!(self, ordinal 0, 1),
                param!(self, ordinal 1, 1)
            ),
            Function::ICH => format!(
                concat!(
                    "If the 'Device Component Select Mode' (DCSM) is set to 'Presentation', this is used to prepare ",
                    "the insertion of {} characters, by putting into the erased state the active presentation ",
                    "position and, depending on the setting of the Character Editing Mode (HEM), the preceding or ",
                    "following character positions in the presentation component. The previous contents of the active ",
                    "presentation position and an adjacent string of character positions are shifted away from the ",
                    "active presentation position. The contents of {} character positions at the other end of the ",
                    "shifted part are removed. The active presentation position is moved to the line home position in ",
                    "the active line. The line home position is established by the parameter value of 'Set Line Home' ",
                    "(SLH).",
                    "\n\n",
                    "The extent of the shifted part is established by Select Editing Extend (SEE).",
                    "\n\n",
                    "The effect of this on the start or end of a selected area, the start or end of a qualified area, ",
                    "or a tabulation stop in the shifted part is undefined.",
                    "\n\n",
                    "If the 'Device Component Select Mode' (DCSM) is set to 'Data', this is used to prepare the ",
                    "insertion of {} characters, by putting into the erased state the active data position and, ",
                    "depending on the setting of the Character Editing Mode (HEM), the preceding or following ",
                    "character positions in the data component. The previous contents of the active data position and ",
                    "and adjacent string of character positions are shifted away from the active data position. ",
                    "The contents of {} character positions at the other end of the shifted part are removed. The ",
                    "active data position is moved to the line home position in the active line. The line ",
                    "home position is established by the parameter value of Set Line Home (SLH)."
                ),
                param!(self, ordinal 0, 1),
                param!(self, ordinal 0, 1),
                param!(self, ordinal 0, 1),
                param!(self, ordinal 0, 1)
            ),
            Function::IGS => format!(
                concat!(
                    "Indicates that the graphic subrepertoire {} is used in the subsequent text according to the ",
                    "graphic characters of ISO/IEC 10367. The graphic subrepertoire {} is registered in accordance ",
                    "with ISO/IEC 7350"
                ),
                param!(self, 0, 0),
                param!(self, 0, 0)
            ),
            Function::IL => format!(
                concat!(
                    "If the 'Device Component Select Mode' (DCSM) is set to 'Presentation', this is used to prepare ",
                    "the insertion of {} lines, by putting into the erased state in the presentation component the ",
                    "active line (the line that contains the active presentation position) and, depending on the ",
                    "setting of the 'Line Editing Mode' (VEM), the preceding or following lines. The previous contents ",
                    "of the active line and of adjacent lines are shifted away from the active line. The contents of ",
                    "{} lines at the other end of the shifted part are removed. The active presentation position is ",
                    "moved to the line home position in the active line. The line home position is established by the ",
                    "parameter value of 'Set Line Home' (SLH).",
                    "\n\n",
                    "The extent of the shifted part is established by 'Select Editing Extent' (SEE).",
                    "\n\n",
                    "Any occurrence of the start or end of a selected area, the start or end of a qualified area, or ",
                    "a tabulation stop in the shifted part, are also shifted.",
                    "\n\n",
                    "If the 'Tabulation Stop Mode' (TSM) is set to 'Single', character tabulation stops are cleared ",
                    "in the lines that are put into the erased state.",
                    "\n\n",
                    "If the 'Device Component Select Mode' (DCSM) is set to 'Data', this is used to prepare the ",
                    "insertion of {} lines, by putting into the erased state in the data component the active line ",
                    "(the line that contains the active data position) and, depending on the setting of the 'Line ",
                    "Editing Mode' (VEM), the preceding or following lines. The previous contents of the active line ",
                    "and of adjacent lines are shifted away from the active line. The contents of {} lines at the ",
                    "other end of the shifted part are removed. The active data position is moved to the line home ",
                    "position in the active line. The line home position is established by the parameter value of ",
                    "'Set Line Home' (SLH)."
                ),
                param!(self, 0, 1),
                param!(self, 0, 1),
                param!(self, 0, 1),
                param!(self, 0, 1)
            ),
            Function::JFY => format!(
                concat!(
                    "Indicates the beginning of a string of graphic characters in the presentation component that are ",
                    "to be justified according to the layout specified: {}"
                ),
                self.short_description()
            ),
            Function::PEC => format!(
                concat!(
                    "Establish the spacing and the extent of graphic characters for subsequent text. {}",
                    "\n\n",
                    "The spacing is specified in the line as multiples of the spacing established by the most recent ",
                    "occurrence of 'Set Character Spacing' (SCS), of 'Select Character Spacing' (SHS), or of 'Spacing ",
                    "Increment' (SPI) in the data stream. The extent of characters is implicitly established by these ",
                    "control functions. The established spacing and extent remain in effect until the next occurrence ",
                    "of PEC. "
                ),
                self.short_description()
            ),
            Function::PFS => format!(
                concat!(
                    "Establish the available area for the imaging of pages of text based on paper size. {}",
                    "\n\n",
                    "The pages are introduced by the subsequent occurrences of 'Form Feed' (FF) in the data stream. ",
                    "The established area stays into effect until the next occurrence.",
                    "\n\n",
                    "The page home position is established by 'Set Page Home' (SPH), the page limit position is ",
                    "established by 'Set Page Limit' (SPL)."
                ),
                self.short_description()
            ),
            Function::PTX => format!(
                concat!(
                    "Used to delimit strings of graphic characters that are communicated one after another in the ",
                    "data stream, but that are intended to be presented in parallel with another one, usually in ",
                    "adjacent lines.",
                    "\n\n",
                    "{}"
                ),
                self.short_description()
            ),
            Function::QUAD => format!(
                concat!(
                    "Indicates the end of a string of graphic characters that are to be positioned on a single line ",
                    "{}.\n\n",
                    "The beginning of the string to be positioned is indicated by the preceding occurrence in the data ",
                    "stream of either another QUAD, or one of the following formator functions: FF, LF, NEL, RI, VT, ",
                    "HVP, HPA, PPB, PPR, VPA, VPB.",
                    "\n\n",
                    "The line home position is established by the parameter value of 'Set Line Home' (SLH). The line ",
                    "limit position is established by the parameter value of 'Set Line Home' (SLH)."
                ),
                self.short_description()
            ),
            Function::REP => format!(
                concat!(
                    "Used to indicate that the preceding character in the data stream, if it is a graphic character, ",
                    "including 'Space', is to be repeated {} times. If the preceding character is a control function ",
                    "or part of a control function, the effect is undefined."
                ),
                param!(self, 0, 1)
            ),
            Function::RM =>
                self.parameters.iter().map(|value| {
                    value.parse::<Mode>().expect("Expect only valid Modes").explain_reset()
                }).fold(String::new(), |mut modes, mode| {
                    modes.push_str(", ");
                    modes.push_str(&mode);
                    modes
                }
            ),
            Function::SACS => format!(
                concat!(
                    "Used to establish extra inter-character escapement for subsequent text. The established extra ",
                    "escapement remains in effect until the next occurrence of SACS or of 'Set Reduced Character ",
                    "Separation' (SRCS) in the data stream or until it is reset to the default value by a subsequent ",
                    "occurrence of 'Carriage Return Line Feed' (CR LF) or of 'Next Line' (NEL) in the data stream.",
                    "\n\n",
                    "The inter-character escapement is enlarged by {} units",
                    "\n\n",
                    "the unit in which the parameter value is expressed is that established by the parameter value of ",
                    "'Select Size Unit' (SSU)."
                ),
                param!(self, 0, 0)
            ),
            Function::SCS => format!(
                concat!(
                    "Establishes the character spacing for subsequent text. The established spacing remains in effect ",
                    "until the next occurrence, or of 'Select Character Spacing' (SHS) or of 'Spacing Increment' ",
                    "(SPI) in the data stream.\n\nCharacters are spaced by {} units.",
                    "\n\n",
                    "The units in which the value is expressed is that established by the parameter value of 'Select ",
                    "Size Unit' (SSU)."
                ),
                param!(self, 0, 0)
            ),
            Function::SD => format!(
                concat!(
                    "Causes the data in the presentation component to be moved by {} line positions if the line ",
                    "orientation is horizontal, or by {} character positions if the line orientation is vertical, ",
                    "such that the data appear to move down.",
                    "\n\n",
                    "The active presentation position is not affected by this function."
                ),
                param!(self, 0, 1),
                param!(self, 0, 1)
            ),
            Function::SDS => format!(
                concat!(
                    "Establishes in the data component the beginning and end of a string of characters, as well as ",
                    "the direction of the string. This direction may be different from that currently established. ",
                    "The indicated string follows the preceding text. The established character progression is not ",
                    "affected. {}"
                ),
                self.short_description()
            ),
            Function::SEE => format!(
                concat!(
                    "Used to establish the editing extend for subsequent character or line insertion or deletion. The ",
                    "established context remains in effect until the next occurrence of SEE in the data stream. {}"
                ),
                self.short_description()
            ),
            Function::SEF => format!(
                concat!(
                    "Causes a sheet of paper to be ejected from a printing device into a specified output stacker an ",
                    "another sheet to be loaded into the printing device from a specified paper bin. {} {}"
                ),
                explain_selection!(Load, self, 0),
                explain_selection!(Stack, self, 1)
            ),
            Function::SGR => format!(
                concat!(
                    "Establishes one or more graphic rendition aspects for subsequent text. The established aspects ",
                    "remain in effect until the next occurrence, depending on the setting of the 'Graphic Rendition ",
                    "Combination Mode' (GRCM).\n\n{}"
                ),
                self.parameters.iter().map(|value| {
                    value.parse::<GraphicRendition>().expect("Expect only valid Graphic Renditions").explain()
                }).fold(String::new(), |mut renditions, rendition| {
                    renditions.push_str(", ");
                    renditions.push_str(&rendition);
                    renditions
                })
            ),
            Function::SHS => format!(
                concat!(
                    "Used to establish the character spacing for subsequent text. {} The established spacing remains ",
                    "in effect until the next occurrence of SHS or of 'Set Character Spacing' (SHS) or of 'Spacing ",
                    "Increment' (SPI)."
                ),
                self.short_description()
            ),
            Function::SIMD => format!(
                concat!(
                    "Used to select the direction of implicit movement of the data position relative to the character ",
                    "position. Remains in effect until the next occurrence of SIMD. {}"
                ),
                self.short_description()
            ),
            Function::SL => format!(
                concat!(
                    "Causes the data in the presentation component to be moved by {} character positions if the line ",
                    "orientation is horizontal, or by {} line positions if the line orientation is vertical, such ",
                    "that the data appear to move to the left. The active presentation position is not affected by ",
                    "this control function."
                ),
                param!(self, 0, 1),
                param!(self, 0, 1)
            ),
            Function::SLH => format!(
                concat!(
                    "If the 'Device Component Select Mode' (DCSM) is set to 'Presentation', this is used to establish ",
                    "at character position {} in the active line (the line that contains the active presentation ",
                    "position) and lines of subsequent text in the presentation component, the position to which the ",
                    "active presentation position will be moved by subsequent occurrences of 'Carriage Return' (CR), ",
                    "'Delete Line' (DL), 'Insert Line' (IL) or 'Next Line' (NEL) in the data stream. In the case of a ",
                    "device without a data component, it is also the position ahead of which no implicit movement of ",
                    "the active presentation position shall occur.",
                    "\n\n",
                    "If the 'Device Component Select Mode' (DCSM) is set to 'Data', this is used to establish at ",
                    "character position {} in the active line (the line that contains the active data position) and ",
                    "lines of subsequent text in the data component, the position to which the active data position ",
                    "will be moved by subsequent occurrences of 'Carriage Return' (CR), 'Delete Line' (DL), 'Insert ",
                    "Line' (IL), or 'Next Line' (NEL) in the data stream. It is also the position ahead of which no ",
                    "implicit movement of the active data position shall occur.",
                    "\n\n",
                    "The established position is called the line home position and remains in effect until the next ",
                    "occurrence of SLH in the data stream."
                ),
                param!(self, 0, 0),
                param!(self, 0, 0)
            ),
            Function::SLL => format!(
                concat!(
                    "If the 'Device Component Select Mode' (DCSM) is set to 'Presentation', this is used to establish ",
                    "at character position {} in the active line (the line that contains the active presentation ",
                    "position) and lines of subsequent text in the presentation component, the position to which the ",
                    "active presentation position will be moved by subsequent occurrences of 'Carriage Return' (CR) ",
                    "or 'Next Line' (NEL) in the data stream, if the parameter value of 'Select Implicit Movement ",
                    "Direction' (SIMD) is equal to 'Opposite'. In the case of a device without data component, it is ",
                    "also the position beyond which no implicit movement of the active presentation position shall ",
                    "occur.",
                    "\n\n",
                    "If the 'Device Component Select Mode' (DSCM) is set to 'Data', this is used to establish at ",
                    "character position {} in the active line (the line that contains the active data position) and ",
                    "lines of subsequent text in the data component, the position beyond which no implicit movement ",
                    "of the active data position shall occur. It is also the position in the data component to which ",
                    "the active data position will be moved by subsequent occurrences of 'Carriage Return' (CR) or ",
                    "'Next Line' (NEL) in the data stream, if the parameter value of 'Select Implicit Movement ",
                    "Direction' (SIMD) is equal to 'Opposite'.",
                    "\n\n",
                    "The established position is called the line limit position and remains in effect until the next ",
                    "occurrence of SLL in the data stream."
                ),
                param!(self, 0, 0),
                param!(self, 0, 0)
            ),
            Function::SLS => format!(
                concat!(
                    "Establishes the line spacing for subsequent text. The established spacing remains in effect ",
                    "until the next occurrence of SLS or of 'Select Line Spacing' (SVS) in the data stream. {}"
                ),
                self.short_description()
            ),
            Function::SM =>
                self.parameters.iter().map(|value| {
                    value.parse::<Mode>().expect("Expect only valid Modes").explain_set()
                }).fold(String::new(), |mut modes, mode| {
                    modes.push_str(", ");
                    modes.push_str(&mode);
                    modes
                }
            ),
            Function::SPH => format!(
                concat!(
                    "If the 'Device Component Select Mode' (DCSM) is set to 'Presentation', this is used to establish ",
                    "at line position {} in the active page (the page that contains the active presentation position) ",
                    "and subsequent pages in the presentation component, the position to which the active ",
                    "presentation position will be moved by subsequent occurrences of 'Form Feed' (FF) in the data ",
                    "stream. In the case of a device without data component, it is also the position ahead of which ",
                    "no implicit movement of the active presentation position shall occur.",
                    "\n\n",
                    "If the 'Device Component Select Mode' (DCSM) is set to 'Data', this is used to establish at line ",
                    "position {} in the active page (the page that contains the active data position) and subsequent ",
                    "pages in the data component, the position to which the active data position will be moved by ",
                    "subsequent occurrences of 'Form Feed' (FF) in the data stream. It is also the position ahead of ",
                    "which no implicit movement of the active presentation position shall occur.",
                    "\n\n",
                    "The established position is called the page home position and remains in effect until the next ",
                    "occurrence of SPH in the data stream."
                ),
                param!(self, 0, 0),
                param!(self, 0, 0)
            ),
            Function::SPI => format!(
                concat!(
                    "Used to establish the line spacing and the character spacing for subsequent text. The ",
                    "established line spacing remains in effect until the next occurrence of SPI or 'Set Line ",
                    "Spacing' (SLS) or of 'Select Line Spacing' (SVS) in the data stream. The established character ",
                    "spacing remains in effect until the next occurrence of 'Set Character Spacing' (SCS) or of ",
                    "'Select Character Spacing' (SHS) in the data stream.",
                    "\n\n",
                    "Line spacing is set to {}, character spacing is set to {}, expressed in the unit that is ",
                    "established by 'Select Size Unit' (SSU)."

                ),
                param!(self, 0, 0),
                param!(self, 1, 0)
            ),
            Function::SPL => format!(
                concat!(
                    "If the 'Device Component Select Mode' (DCSM) is set to 'Presentation', this is used to establish ",
                    "at line position {} in the active page (the page that contains the active presentation position) ",
                    "and pages of subsequent text in the presentation component, the position beyond which the active ",
                    "presentation position can normally not be moved. In the case of a device without data component, ",
                    "it is also the position beyond which no implicit movement of the active presentation position ",
                    "shall occur.",
                    "\n\n",
                    "If the 'Device Component Select Mode' (DCSM) is set to 'Data', this is used to establish at line ",
                    "position {} in the active page (the page that contains the active data position) and pages of ",
                    "subsequent text in the data component, the position beyond which no implicit movement of the ",
                    "active data position shall occur.",
                    "\n\n",
                    "The established position is called the page limit position and remains in effect until the next ",
                    "occurrence of SPL in the data stream."
                ),
                param!(self, 0, 0),
                param!(self, 0, 0)
            ),
            Function::SPQR => format!(
                concat!(
                    "Select the relative print quality and print speed for devices where the output quality and ",
                    "speed are inversely related. The selected value will remain in effect until the next ",
                    "occurrence of SPQR. {}"
                ),
                self.short_description()
            ),
            Function::SR => format!(
                concat!(
                    "Causes the data in the presentation component to be moved by {} character positions if the ",
                    "line orientation is horizontal, or by {} line positions if the line orientation is ",
                    "vertical, such that the data appear to be moved to the right.",
                    "\n\n",
                    "The active presentation position is not affected by this control function."
                ),
                param!(self, 0, 1),
                param!(self, 0, 1)
            ),
            Function::SRCS => format!(
                concat!(
                    "Used to establish reduced inter-character escapement by {} units. The established reduced ",
                    "escapement remains in effect until the next occurrence of SRCS or of 'Set Additional ",
                    "Character Separation' (SACS) in the data stream or until it is reset to the default value ",
                    "by a subsequent occurrence of 'Carriage Return/Line Feed' (CRLF) or of 'Next Line' (NEL) in ",
                    "the data stream.",
                    "\n\n",
                    "The unit in which the escapement is reduced is that established by 'Select Size Unit' (SSU)."
                ),
                param!(self, 0, 0)
            ),
            Function::SRS => format!(
                concat!(
                    "Used to establish in the data component the beginning and the end of a string of ",
                    "characters as well as the direction of this string. This direction is opposite to that ",
                    "currently established. The indicated string follows the preceding text. The established ",
                    "character progression is not affected. {}"
                ),
                self.short_description()
            ),
            Function::SSU => format!(
                concat!(
                    "Used to establish the unit in which the numeric parameters of certain control functions ",
                    "are expressed. The establish unit remains in effect until the next occurrence of SSU in ",
                    "the data stream. {}"
                ),
                self.short_description()
            ),
            Function::SSW => format!(
                concat!(
                    "Used to establish for subsequent text the character escapement associated with the ",
                    "character 'SPACE'. The established escapement remains in effect until the next occurrence ",
                    "of SSW in the data stream or until it is reset to the default value by a subsequent ",
                    "occurrence of 'Carriage Return/Line Feed' (CRLF), 'Carriage Return/Form Feed' (CRFF), or ",
                    "'Next Line' (NEL) in the data stream.",
                    "\n\n",
                    "{}",
                    "\n\n",
                    "The unit in which the value is expressed is defined by 'Select Size Unit' (SSU).",
                    "\n\n",
                    "The default character escapement of 'SPACE' is specified by the most recent occurrence of ",
                    "'Set Character Spacing' (SCS) or of 'Select Character Spacing' (SHS) or of 'Select Spacing ",
                    "Increment' (SPI) in the data stream if the current font has constant spacing, or is ",
                    "specified by the normal width of the character 'SPACE' in the current font if that font ",
                    "has proportional spacing."
                ),
                self.short_description()
            ),
            Function::STAB => format!(
                concat!(
                    "{} The use of this control function and means of specifying a list of tabulation stop to ",
                    "be referenced by the control function are specified in other standards, for example ISO ",
                    "8613-6."
                ),
                self.short_description()
            ),
            Function::SU => format!(
                concat!(
                    "Causes the data in the presentation component to be moved by {} line positions, if the line ",
                    "operation is horizontal, or by {} character positions, if the line orientation is vertical, ",
                    "such that the data appear to move up. The active presentation position is not affected by ",
                    "this control function."
                ),
                param!(self, 0, 1),
                param!(self, 0, 1)
            ),
            Function::SVS => format!(
                concat!(
                    "Used to establish the line spacing for subsequent text. {} The established spacing remains ",
                    "in effect until the next occurrence of SVS or of 'Set Line Spacing' (SLS) or of 'Spacing ",
                    "Increment' (SPI) in the data stream."
                ),
                explain_selection!(LineSpacing, self, 0)
            ),
            Function::TAC => format!(
                concat!(
                    "Causes a character tabulation stop calling for centring to be set at character position {} ",
                    "in the active line (the line that contains the active presentation position) and lines of ",
                    "subsequent text in the presentation component. TAC causes the replacement of any ",
                    "tabulation stop previously set at that character position, but does not affect other ",
                    "tabulation stops.",
                    "\n\n",
                    "A text string centred upon a tabulation stop set by TAC will be positioned so that the ",
                    "(trailing edge of the) first graphic character and the (leading edge of the) last graphic ",
                    "character are at approximately equal distances from the tabulation stop."
                ),
                param!(self, 0, 0)
            ),
            Function::TALE => format!(
                concat!(
                    "Causes a character tabulation stop calling for leading edge alignment to be set at ",
                    "character position {} in the active line (the line that contains the active presentation ",
                    "position) and lines of subsequent text in the presentation component. TALE causes the ",
                    "replacement of any tabulation stop previously set at that character position, but does not ",
                    "affect other tabulation stops.",
                    "\n\n",
                    "A text string aligned with a tabulation stop set by TALE will be positioned so that the ",
                    "(leading edge of the) last graphic character of the string is placed at the tabulation stop."
                ),
                param!(self, 0, 0)
            ),
            Function::TATE => format!(
                concat!(
                    "Causes a character tabulation stop calling for trailing edge alignment to be set at ",
                    "character position {} in the active line (the line that contains the active presentation ",
                    "position) and lines of subsequent text in the presentation component. TATE causes the ",
                    "replacement of any tabulation stop previously set at the character position, but does not ",
                    "affect other tabulation stops.",
                    "\n\n",
                    "A text string aligned with a tabulation stop set by TATE will be positioned so that the ",
                    "(trailing edge of the) first graphic character of the string is placed at the tabulation ",
                    "stop."
                ),
                param!(self, 0, 0)
            ),
            Function::TCC => format!(
                concat!(
                    "Causes a character tabulation stop calling for alignment of a target graphic character {} ",
                    "to be set at character position {} in the active line (the line that contains the active ",
                    "presentation position) and lines of subsequent text in the presentation component. TCC ",
                    "causes the replacement of any tabulation stop previously set at that character position, ",
                    "but does not affect other tabulation stops.",
                    "\n\n",
                    "The positioning of a text string aligned with a tabulation stop set by TCC will be ",
                    "determined by the first occurrence in the string of the target graphic character; that ",
                    "character will be centred upon the tabulation stop. If the target character does not occur ",
                    "within the string, then the trailing edge of the first character of the string will be ",
                    "positioned at the tabulation stop.",
                    "\n\n",
                    "The value of {} indicates the code table position (binary value) of the target character ",
                    "in the currently invoked code. For a 7-bit code, the permissible range of values is 32 ",
                    "to 127; for an 8-bit code, the permissible range of values is 32 to 127 and 160 to 255."
                ),
                param!(self, 1, 32),
                param!(self, 0, 0),
                param!(self, 1, 32)
            ),
            Function::TSS => format!(
                concat!(
                    "Used to establish the width of a thin space for subsequent text to be {} units. The ",
                    "established width remains in effect until the next occurrence of TSS in the data stream.",
                    "\n\n",
                    "The unit in which the parameter is expressed is that established by the value of 'Select ",
                    "Size Unit' (SSU)."
                ),
                param!(self, 0, 0)
            ),
            _ => self.short_description(),
        }
    }
}

impl FromStr for TabulationControl {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::SetLineTabulationStop,
            "2" => Self::ClearCharacterTabulationStop,
            "3" => Self::ClearLineTabulationStop,
            "4" => Self::ClearCharacterTabulationStopsInLine,
            "5" => Self::ClearAllCharacterTabulationStops,
            "6" => Self::ClearLineTabulationStop,
            _ => Self::SetCharacterTabulationStop,
        })
    }
}

impl ExplainSelection for TabulationControl {
    fn explain(&self) -> String {
        match self {
            Self::SetCharacterTabulationStop => {
                String::from("Set a character tabulation at the active position.")
            }
            Self::SetLineTabulationStop => {
                String::from("Set a line tabulation stop at the active line.")
            }
            Self::ClearCharacterTabulationStop => {
                String::from("Clear the character tabulation stop at the active position.")
            }
            Self::ClearLineTabulationStop => {
                String::from("Clear the line tabulation stop at the active line.")
            }
            Self::ClearCharacterTabulationStopsInLine => {
                String::from("Clear all character tabulation stops in the active line.")
            }
            Self::ClearAllCharacterTabulationStops => {
                String::from("Clear all character tabulation stops.")
            }
            Self::ClearAllLineTabulationStops => String::from("Clear all line tabulation stops."),
        }
    }
}

impl FromStr for DeviceAttributes {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "0" => Self::Request,
            value @ _ => Self::Identify(
                value
                    .parse::<u32>()
                    .expect("Expected valid Device Attributes."),
            ),
        })
    }
}

impl ExplainSelection for DeviceAttributes {
    fn explain(&self) -> String {
        match self {
            Self::Request => {
                String::from("Request Device Attribute identification from the receiving device.")
            }
            Self::Identify(v) => {
                format!(
                    "The device sending this identifies as device with code {}.",
                    v
                )
            }
        }
    }
}

impl FromStr for AreaQualification {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::ProtectedGuarded,
            "2" => Self::GraphicCharacterInput,
            "3" => Self::NumericInput,
            "4" => Self::AlphabeticInput,
            "5" => Self::InputAlignedRight,
            "6" => Self::FillZeros,
            "7" => Self::SetCharacterTabulationStop,
            "8" => Self::ProtectedUnguarded,
            "9" => Self::FillSpaces,
            "10" => Self::InputAlignedLeft,
            "11" => Self::Reversed,
            _ => Self::UnprotectedUnguarded,
        })
    }
}

impl ExplainSelection for AreaQualification {
    fn explain(&self) -> String {
        match self {
            Self::UnprotectedUnguarded => String::from("is unprotected an unguarded"),
            Self::ProtectedGuarded => String::from("is protected and guarded"),
            Self::GraphicCharacterInput => String::from("is a graphic input area"),
            Self::NumericInput => String::from("is a numeric input area"),
            Self::AlphabeticInput => String::from("is an alphabetic input area"),
            Self::InputAlignedRight => {
                String::from("has input aligned to the last position of this area")
            }
            Self::FillZeros => String::from("will be filled with ZEROs"),
            Self::SetCharacterTabulationStop => String::from("indicates a beginning of a field"),
            Self::ProtectedUnguarded => String::from("is protected and unguarded"),
            Self::FillSpaces => String::from("will be filled with SPACEs"),
            Self::InputAlignedLeft => {
                String::from("has input aligned to the first position of the area")
            }
            Self::Reversed => {
                String::from("has the order of character positions in the input field reversed.")
            }
        }
    }
}

impl FromStr for DeviceStatusReport {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::BusyRepeat,
            "2" => Self::BusyLater,
            "3" => Self::MalfunctionRepeat,
            "4" => Self::MalfunctionLater,
            "5" => Self::RequestDeviceStatusReport,
            "6" => Self::RequestActivePositionReport,
            _ => Self::Ready,
        })
    }
}

impl ExplainSelection for DeviceStatusReport {
    fn explain(&self) -> String {
        match self {
            Self::Ready => String::from(
                "The sending device reports to be read and no malfunctions have been detected."
            ),
            Self::BusyRepeat => String::from(
                "The sending device is busy. Another Device Status Report must be requested later."
            ),
            Self::BusyLater => String::from(
                "The sending device is busy. Another Device Status Report will be sent later."
            ),
            Self::MalfunctionRepeat => String::from(
                concat!(
                    "Some malfunction has been detected by the sending device. Another Device Status Report must be ",
                    "requested later."
                )
            ),
            Self::MalfunctionLater => String::from(
                concat!(
                    "Some malfunction has been detected by the sending device. Another Device Status Report will ",
                    "be sent later."
                )
            ),
            Self::RequestDeviceStatusReport => String::from(
                "A device status report is requested."
            ),
            Self::RequestActivePositionReport => String::from(
                concat!(
                    "A report of the active presentation position or of the active data position in form of 'Active ",
                    "Position Report' (CPR) is requested from the receiving device."
                )
            )
        }
    }
}

impl FromStr for EraseArea {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::BeginToActivePosition,
            "2" => Self::BeginToEnd,
            _ => Self::ActivePositionToEnd,
        })
    }
}

impl ExplainSelection for EraseArea {
    fn explain(&self) -> String {
        match self {
            Self::ActivePositionToEnd => String::from(
                "erases the contents of the currently active qualified area from the current position to the end"
            ),
            Self::BeginToActivePosition => String::from(
                concat!(
                    "erases the contents of the currently active qualified area from the beginning of format area to ",
                    "the current position"
                )
            ),
            Self::BeginToEnd => String::from(
                "erases all contents of the currently active qualified area"
            ),
        }
    }
}

impl FromStr for ErasePage {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::BeginToActivePosition,
            "2" => Self::BeginToEnd,
            _ => Self::ActivePositionToEnd,
        })
    }
}

impl ExplainSelection for ErasePage {
    fn explain(&self) -> String {
        match self {
            Self::ActivePositionToEnd => String::from(
                "erases the contents of the currently active page from the current position to the end"
            ),
            Self::BeginToActivePosition => String::from(
                concat!(
                    "erases the contents of the currently active page from the beginning of format area to ",
                    "the current position"
                )
            ),
            Self::BeginToEnd => String::from(
                "erases all contents of the currently active page"
            ),
        }
    }
}

impl FromStr for EraseField {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::BeginToActivePosition,
            "2" => Self::BeginToEnd,
            _ => Self::ActivePositionToEnd,
        })
    }
}

impl ExplainSelection for EraseField {
    fn explain(&self) -> String {
        match self {
            Self::ActivePositionToEnd => String::from(
                "erases the contents of the currently active field from the current position to the end"
            ),
            Self::BeginToActivePosition => String::from(
                concat!(
                    "erases the contents of the currently active field from the beginning of format area to ",
                    "the current position"
                )
            ),
            Self::BeginToEnd => String::from(
                "erases all contents of the currently active field"
            ),
        }
    }
}

impl FromStr for EraseLine {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::BeginToActivePosition,
            "2" => Self::BeginToEnd,
            _ => Self::ActivePositionToEnd,
        })
    }
}

impl ExplainSelection for EraseLine {
    fn explain(&self) -> String {
        match self {
            Self::ActivePositionToEnd => String::from(
                "erases the contents of the currently active line from the current position to the end"
            ),
            Self::BeginToActivePosition => String::from(
                concat!(
                    "erases the contents of the currently active line from the beginning of format area to ",
                    "the current position"
                )
            ),
            Self::BeginToEnd => String::from(
                "erases all contents of the currently active line"
            ),
        }
    }
}

impl FromStr for Font {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::Alternative1,
            "2" => Self::Alternative2,
            "3" => Self::Alternative3,
            "4" => Self::Alternative4,
            "5" => Self::Alternative5,
            "6" => Self::Alternative6,
            "7" => Self::Alternative7,
            "8" => Self::Alternative8,
            "9" => Self::Alternative9,
            _ => Self::Primary,
        })
    }
}

impl ExplainSelection for Font {
    fn explain(&self) -> String {
        match self {
            Self::Primary => String::from("primary font"),
            Self::Alternative1 => String::from("alternative font 1"),
            Self::Alternative2 => String::from("alternative font 2"),
            Self::Alternative3 => String::from("alternative font 3"),
            Self::Alternative4 => String::from("alternative font 4"),
            Self::Alternative5 => String::from("alternative font 5"),
            Self::Alternative6 => String::from("alternative font 6"),
            Self::Alternative7 => String::from("alternative font 7"),
            Self::Alternative8 => String::from("alternative font 8"),
            Self::Alternative9 => String::from("alternative font 9"),
        }
    }
}

impl FromStr for GraphicCharacterCombination {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::StartOfCombination,
            "2" => Self::EndOfCombination,
            _ => Self::CombineTwo,
        })
    }
}

impl ExplainSelection for GraphicCharacterCombination {
    fn explain(&self) -> String {
        match self {
            Self::CombineTwo => String::from(
                "Combine the following two graphic characters into a single symbol."
            ),
            Self::StartOfCombination => String::from(
                concat!(
                    "Combine all following graphic characters into a single symbol, until the end of combination of ",
                    "characters is indicated."
                )
            ),
            Self::EndOfCombination => String::from(
                "Indicates the end of combining all previous graphic characters into a single symbol."
            ),
        }
    }
}

impl FromStr for IdentifyDeviceControlString {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "0" => Self::Diagnostic,
            "1" => Self::DynamicallyRedefinableCharacterSet,
            value @ _ => Self::Private(
                value
                    .parse::<u32>()
                    .expect("Expected valid Identify Device Control String."),
            ),
        })
    }
}

impl ExplainSelection for IdentifyDeviceControlString {
    fn explain(&self) -> String {
        match self {
            Self::Diagnostic => String::from(
                concat!(
                    "Subsequent 'Device Control Strings' (DCS) are intended for the diagnostic state of the ",
                    "'Status Report Transfer Mode'"
                )
            ),
            Self::DynamicallyRedefinableCharacterSet => String::from(
                concat!(
                    "Subsequent 'Device Control Strings' (DCS) are reserved for dynamically refinable character sets ",
                    "according to Standard ECMA-35."
                )
            ),
            Self::Private(_) => String::from(
                "Subsequent 'Device Control Strings' (DCS) are for private use."
            ),
        }
    }
}

impl FromStr for Justification {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::WordFill,
            "2" => Self::WordSpace,
            "3" => Self::LetterSpace,
            "4" => Self::Hyphenation,
            "5" => Self::Left,
            "6" => Self::Centre,
            "7" => Self::Right,
            "8" => Self::ItalianHyphenation,
            _ => Self::None,
        })
    }
}

impl ExplainSelection for Justification {
    fn explain(&self) -> String {
        match self {
            Self::None => {
                String::from("The following text is not formatted to a special justification.")
            }
            Self::WordFill => String::from("The following text uses word-fill justification."),
            Self::WordSpace => String::from("The following text uses word-space justification."),
            Self::LetterSpace => {
                String::from("The following text uses letter-space justification.")
            }
            Self::Hyphenation => String::from("The following text uses hyphenation justification."),
            Self::Left => String::from("The following text is left aligned."),
            Self::Centre => String::from("The following text is centred."),
            Self::Right => String::from("The following text is right aligned."),
            Self::ItalianHyphenation => {
                String::from("The following text uses italian hyphenation justification.")
            }
        }
    }
}

impl FromStr for MediaCopy {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::BeginTransferFromPrimary,
            "2" => Self::BeginTransferToSecondary,
            "3" => Self::BeginTransferFromSecondary,
            "4" => Self::StopRelayPrimary,
            "5" => Self::StartRelayPrimary,
            "6" => Self::StopRelaySecondary,
            "7" => Self::StartRelaySecondary,
            _ => Self::BeginTransferToPrimary,
        })
    }
}

impl ExplainSelection for MediaCopy {
    fn explain(&self) -> String {
        match self {
            Self::BeginTransferToPrimary => {
                String::from("Initiate transfer to a primary auxiliary device.")
            }
            Self::BeginTransferFromPrimary => {
                String::from("Initiate transfer from a primary auxiliary device.")
            }
            Self::BeginTransferToSecondary => {
                String::from("Initiate transfer to a secondary auxiliary device.")
            }
            Self::BeginTransferFromSecondary => {
                String::from("Initiate transfer from a secondary auxiliary device.")
            }
            Self::StopRelayPrimary => String::from("Stop relay to a primary auxiliary device."),
            Self::StartRelayPrimary => String::from("Start relay to a primary auxiliary device."),
            Self::StopRelaySecondary => String::from("Stop relay to a secondary auxiliary device."),
            Self::StartRelaySecondary => {
                String::from("Start relay to a secondary auxiliary device.")
            }
        }
    }
}

impl FromStr for PresentationExpandContract {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::Expanded,
            "2" => Self::Condensed,
            _ => Self::Normal,
        })
    }
}

impl ExplainSelection for PresentationExpandContract {
    fn explain(&self) -> String {
        match self {
            Self::Normal => String::from("normal mode, as specified by SCS, SHS or SPI"),
            Self::Expanded => {
                String::from("extended mode, multiplied by a factor not greater than 2")
            }
            Self::Condensed => {
                String::from("condensed mode, multiplied by a factor not less than 0.5")
            }
        }
    }
}

impl FromStr for PageFormat {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::WideBasicText,
            "2" => Self::TallBasicA4,
            "3" => Self::WideBasicA4,
            "4" => Self::TallLetter,
            "5" => Self::WideLetter,
            "6" => Self::TallExtendedA4,
            "7" => Self::WideExtendedA4,
            "8" => Self::TallLegal,
            "9" => Self::WideLegal,
            "10" => Self::A4ShortLines,
            "11" => Self::A4LongLines,
            "12" => Self::B5ShortLines,
            "13" => Self::B5LongLines,
            "14" => Self::B4ShortLines,
            "15" => Self::B4LongLines,
            _ => Self::TallBasicText,
        })
    }
}

impl ExplainSelection for PageFormat {
    fn explain(&self) -> String {
        match self {
            Self::TallBasicText => String::from("Set the page to tall basic communication format."),
            Self::WideBasicText => String::from("Set the page to wide basic communication format."),
            Self::TallBasicA4 => String::from("Set the page to tall basic A4 format."),
            Self::WideBasicA4 => String::from("Set the page to wide basic A4 format."),
            Self::TallLetter => String::from("Set the page to north american tall letter format."),
            Self::WideLetter => String::from("Set the page to north american wide letter format."),
            Self::TallExtendedA4 => String::from("Set the page to tall extended A4 format."),
            Self::WideExtendedA4 => String::from("Set the page to wide extended A4 format."),
            Self::TallLegal => String::from("Set the page to north american tall legal format."),
            Self::WideLegal => String::from("Set the page to north american wide legal format."),
            Self::A4ShortLines => String::from("Set the page to A4 short lines format."),
            Self::A4LongLines => String::from("Set the page to A4 long lines format."),
            Self::B5ShortLines => String::from("Set the page to B5 short lines format."),
            Self::B5LongLines => String::from("Set the page to B5 long lines format."),
            Self::B4ShortLines => String::from("Set the page to B4 short lines format."),
            Self::B4LongLines => String::from("Set the page to B4 long lines format."),
        }
    }
}

impl FromStr for ParallelText {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::BeginPrincipal,
            "2" => Self::BeginSupplementary,
            "3" => Self::BeginJapanesePhonetic,
            "4" => Self::BeginChinesePhonetic,
            "5" => Self::EndPhonetic,
            _ => Self::End,
        })
    }
}

impl ExplainSelection for ParallelText {
    fn explain(&self) -> String {
        match self {
            Self::End => String::from(
                "End of parallel texts."
            ),
            Self::BeginPrincipal => String::from(
                concat!(
                    "Beginning of principal text that should be displayed in parallel with one or more strings of ",
                    "supplementary text."
                )
            ),
            Self::BeginSupplementary => String::from(
                "Beginning of supplementary text that should be displayed in parallel to the principal text."
            ),
            Self::BeginJapanesePhonetic => String::from(
                concat!(
                    "Beginning of supplementary japanese phonetic annotation that should be displayed in parallel to ",
                    "the principal text."
                )
            ),
            Self::BeginChinesePhonetic => String::from(
                concat!(
                    "Beginning of supplementary chinese phonetic annotation that should be displayed in parallel to ",
                    "the principal text."
                )
            ),
            Self::EndPhonetic => String::from(
                "End of a string of supplementary phonetic annotations."
            ),
        }
    }
}

impl FromStr for Alignment {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::LineHomeLeader,
            "2" => Self::Centre,
            "3" => Self::CentreLeader,
            "4" => Self::LineLimit,
            "5" => Self::LineLimitLeader,
            "6" => Self::Justify,
            _ => Self::LineHome,
        })
    }
}

impl ExplainSelection for Alignment {
    fn explain(&self) -> String {
        match self {
            Self::LineHome => String::from(
                "flush to the line home position"
            ),
            Self::LineHomeLeader => String::from(
                "flush to the line home position, margin and fill with leader"
            ),
            Self::Centre => String::from(
                "centred between line home position and line limit position margins"
            ),
            Self::CentreLeader => String::from(
                "centred between line home position and line limit position margins and fill with leader"
            ),
            Self::LineLimit => String::from(
                "flush to the line limit position margin"
            ),
            Self::LineLimitLeader => String::from(
                "flush to the line limit position margin and fill with leader"
            ),
            Self::Justify => String::from(
                "flush to both margins"
            ),
        }
    }
}

impl FromStr for Mode {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "2" => Self::KeyboardActionMode,
            "3" => Self::ControlPresentationMode,
            "4" => Self::InsertionReplacementMode,
            "5" => Self::StatusReportTransferMode,
            "6" => Self::ErasureMode,
            "7" => Self::LineEditingMode,
            "8" => Self::BiDirectionalSupportMode,
            "9" => Self::DeviceComponentSelectMode,
            "10" => Self::CharacterEditingMode,
            "11" => Self::PositioningUnitMode,
            "12" => Self::SendReceiveMode,
            "13" => Self::FormatEffectorActionMode,
            "14" => Self::FormatEffectorTransferMode,
            "15" => Self::MultipleAreaTransferMode,
            "16" => Self::TransferTerminationMode,
            "17" => Self::StatusReportTransferMode,
            "18" => Self::TabulationStopMode,
            "21" => Self::GraphicRenditionCombinationMode,
            "22" => Self::ZeroDefaultMode,
            _ => Self::GuardedAreaTransferMode,
        })
    }
}

impl ExplainMode for Mode {
    fn name(&self) -> String {
        match self {
            Self::GuardedAreaTransferMode => String::from("Guarded Area Transfer Mode"),
            Self::KeyboardActionMode => String::from("Keyboard Action Mode"),
            Self::ControlPresentationMode => String::from("Control Presentation Mode"),
            Self::InsertionReplacementMode => String::from("Insertion Replacement Mode"),
            Self::StatusReportTransferMode => String::from("Status Report Transfer Mode"),
            Self::ErasureMode => String::from("Erasure Mode"),
            Self::LineEditingMode => String::from("Line Editing Mode"),
            Self::BiDirectionalSupportMode => String::from("Bi-Directional Support Mode"),
            Self::DeviceComponentSelectMode => String::from("Device Component Select Mode"),
            Self::CharacterEditingMode => String::from("Character Editing Mode"),
            Self::PositioningUnitMode => String::from("Positioning Unit Mode"),
            Self::SendReceiveMode => String::from("Send Receive Mode"),
            Self::FormatEffectorActionMode => String::from("Format Effector Action Mode"),
            Self::FormatEffectorTransferMode => String::from("Format Effector Transfer Mode"),
            Self::MultipleAreaTransferMode => String::from("Multiple Area Transfer mode"),
            Self::TransferTerminationMode => String::from("Transfer Termination Mode"),
            Self::SelectedAreaTransferMode => String::from("Selected Area Transfer Mode"),
            Self::TabulationStopMode => String::from("Tabulation Stop Mode"),
            Self::GraphicRenditionCombinationMode => {
                String::from("Graphic Rendition Combination Mode")
            }
            Self::ZeroDefaultMode => String::from("Zero Default Mode"),
        }
    }

    fn explain_reset(&self) -> String {
        match self {
            Self::GuardedAreaTransferMode => String::from(
                "Only the contents of unguarded areas in an eligible area are transmitted or transferred."
            ),
            Self::KeyboardActionMode => String::from(
                "All or part of the manual input facilities are enabled to be used."
            ),
            Self::ControlPresentationMode => String::from(
                "All control functions are performed as defined."
            ),
            Self::InsertionReplacementMode => String::from(
                concat!(
                    "The graphic symbol of a graphic character or a control function, for which a graphical ",
                    "representation is required, replaces (or, depending on the implementation, is combined with) the ",
                    "graphic symbol imaged at the active presentation position"
                )
            ),
            Self::StatusReportTransferMode => String::from(
                "Status reports in the form of 'Device Control String' (DCS) are not generated automatically."
            ),
            Self::ErasureMode => String::from(
                "Only the contents of unprotected areas are affected by an erasure control function."
            ),
            Self::LineEditingMode => String::from(
                concat!(
                    "The insertion of a line causes the contents of the active line and the following lines to be ",
                    "shifted in the direction of line progression. A line deletion causes the contents of the ",
                    "following lines to shifted in the opposite direction of line progression."
                )
            ),
            Self::BiDirectionalSupportMode => String::from(
                "Control functions are performed in the data component or the presentation component."
            ),
            Self::DeviceComponentSelectMode => String::from(
                "Certain control functions are performed in the presentation component at the current position."
            ),
            Self::CharacterEditingMode => String::from(
                concat!(
                    "The insertion of a character causes the following contents to be shifted in the direction of ",
                    "character progression. A character deletion causes the following contents to be shifted in the ",
                    "direction opposite of character progression."
                )
            ),
            Self::PositioningUnitMode => String::from(
                "The unit for numeric parameters of the position format effectors is one character position."
            ),
            Self::SendReceiveMode => String::from(
                "Data which are locally entered are immediately imaged."
            ),
            Self::FormatEffectorActionMode => String::from(
                "Formator functions are performed immediately and may be stored in addition to being performed."
            ),
            Self::FormatEffectorTransferMode => String::from(
                concat!(
                    "Formator functions may be inserted in a data stream to be transmitted or in data to be ",
                    "transferred to an auxiliary input/output device."
                )
            ),
            Self::MultipleAreaTransferMode => String::from(
                concat!(
                    "Only the contents of the selected area which contains the active presentation position are ",
                    "eligible to be transmitted or transferred."
                )
            ),
            Self::TransferTerminationMode => String::from(
                concat!(
                    "Only the contents of the character positions preceding the active presentation position in the ",
                    "presentation component are eligible to be transmitted or transferred."
                )
            ),
            Self::SelectedAreaTransferMode => String::from(
                "Only the contents of selected areas are eligible to be transmitted or transferred."
            ),
            Self::TabulationStopMode => String::from(
                concat!(
                    "Character tabulation stops in the presentation component are set or cleared in the active line ",
                    "and in the corresponding character positions of the preceding lines and the following lines."
                )
            ),
            Self::GraphicRenditionCombinationMode => String::from(
                concat!(
                    "Each occurrence of the control function 'Select Graphic Rendition' (SGR) cancels the effect of ",
                    "any preceding occurrence."
                )
            ),
            Self::ZeroDefaultMode => String::from(
                "A parameter value of 0 of a control functions means the number 0."
            ),
        }
    }

    fn explain_set(&self) -> String {
        match self {
            Self::GuardedAreaTransferMode => String::from(
                concat!(
                    "The contents of guarded as well as of unguarded areas in an eligible area are transmitted or ",
                    "transferred."
                )
            ),
            Self::KeyboardActionMode => String::from(
                "All or part of the manual input facilities are disabled."
            ),
            Self::ControlPresentationMode => String::from(
                "All control functions, except 'Reset Mode' are treated as graphic characters."
            ),
            Self::InsertionReplacementMode => String::from(
                concat!(
                    "The graphic symbol of a graphic character or a control function, for which a graphical ",
                    "representation is required,is inserted at the active presentation position."
                )
            ),
            Self::StatusReportTransferMode => String::from(
                concat!(
                    "Status reports in the form of 'Device Control String' (DCS) are included in every data stream ",
                    "transmitted or transferred."
                )
            ),
            Self::ErasureMode => String::from(
                "Only the contents of protected as well as protected areas are affected by an erasure control function."
            ),
            Self::LineEditingMode => String::from(
                concat!(
                    "The insertion of a line causes the contents of the active line and the following lines to be ",
                    "shifted in the direction of line progression. A line deletion causes the contents of the ",
                    "following lines to shifted in the opposite direction of line progression."
                )
            ),
            Self::BiDirectionalSupportMode => String::from(
                concat!(
                    "Control functions are performed in the data component. All bi-directional aspects of data are ",
                    "handled by the device itself."
                )
            ),
            Self::DeviceComponentSelectMode => String::from(
                "Certain control functions are performed in the data component at the current position."
            ),
            Self::CharacterEditingMode => String::from(
                concat!(
                    "The insertion of a character causes the following contents to be shifted in the direction ",
                    "opposite of character progression. A character deletion causes the following contents to be ",
                    "shifted in the direction of character progression."
                )
            ),
            Self::PositioningUnitMode => String::from(
                concat!(
                    "The unit for numeric parameters of the position format effectors is that established by 'Select ",
                    "Size Unit' (SSU)."
                )
            ),
            Self::SendReceiveMode => String::from(
                "Local input facilities are logically disconnected from the output mechanism."
            ),
            Self::FormatEffectorActionMode => String::from(
                "Formator functions are stored but not performed."
            ),
            Self::FormatEffectorTransferMode => String::from(
                concat!(
                    "No formator functions other than those received while the 'Format Effector Action Mode' (FEAM) ",
                    "is set to 'Store' are included in a transmitted data stream."
                )
            ),
            Self::MultipleAreaTransferMode => String::from(
                "The contents of all selected areas are eligible to be transmitted or transferred."
            ),
            Self::TransferTerminationMode => String::from(
                concat!(
                    "The contents of character positions preceding, following, and at the active position are ",
                    "eligible to be transmitted or transferred."
                )
            ),
            Self::SelectedAreaTransferMode => String::from(
                concat!(
                    "The contents of all character positions, irrespective of any explicitly defined selected areas, ",
                    "are eligible to be transmitted or transferred."
                )
            ),
            Self::TabulationStopMode => String::from(
                "Character tabulation stops in the presentation component are set or cleared in the active line only."
            ),
            Self::GraphicRenditionCombinationMode => String::from(
                concat!(
                    "Each occurrence of the control function 'Select Graphic Rendition' (SGR) cancels only those ",
                    "graphic rendition aspects to be changed that are specified by that SGR. All other graphic ",
                    "rendition aspects remain unchanged."
                )
            ),
            Self::ZeroDefaultMode => String::from(
                "A parameter value of 0 of a control functions means a default value that might be different from 0."
            ),
        }
    }
}

impl FromStr for PresentationVariant {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::LatinDecimals,
            "2" => Self::ArabicDecimals,
            "3" => Self::MirrorPairs,
            "4" => Self::MirrorFormulae,
            "5" => Self::Isolated,
            "6" => Self::Initial,
            "7" => Self::Medial,
            "8" => Self::Final,
            "9" => Self::DecimalFullStop,
            "10" => Self::DecimalComma,
            "11" => Self::VowelAboveOrBelow,
            "12" => Self::VowelAfterPreceding,
            "13" => Self::ContextualShapeArabicScriptWithLamAleph,
            "14" => Self::ContextualShapeArabicScript,
            "15" => Self::NoMirroring,
            "16" => Self::NoVowels,
            "17" => Self::SlantFollowsStringDirection,
            "18" => Self::NoContextualShapeArabicScript,
            "19" => Self::NoContextualShapeArabicScriptExceptDigits,
            "20" => Self::DeviceDependentDecimalDigits,
            "21" => Self::PersistCharacterForm,
            "22" => Self::DesistCharacterForm,
            _ => Self::Default,
        })
    }
}

impl ExplainSelection for PresentationVariant {
    fn explain(&self) -> String {
        match self {
            Self::Default => String::from(
                "Default presentation. Cancels the effect of any other preceding SAPV."
            ),
            Self::LatinDecimals => String::from(
                "The decimal digits are presented by means of the graphic symbols used in the Latin script."
            ),
            Self::ArabicDecimals => String::from(
                concat!(
                    "The decimal digits are presented by means of the graphic symbols used in the Arabic script, i.e. ",
                    "the Hindi symbols."
                )
            ),
            Self::MirrorPairs => String::from(
                concat!(
                    "When the direction of the character path is right-to-left, each of the graphic characters in the ",
                    "character set(s) in use which is one of a left/right handed pair (parenthesis, square brackets, ",
                    "curly brackets, greater-than/less-than signs, etc.) is presented as mirrored"
                )
            ),
            Self::MirrorFormulae => String::from(
                concat!(
                    "When the direction of the character path is right-to-left, all graphic characters which ",
                    "represent operators and delimiters in mathematical formulae and which are not symmetrical about ",
                    "a vertical axis are presented as mirrored about that vertical axis."
                )
            ),
            Self::Isolated => String::from(
                "The following graphic character is presented in its isolated form."
            ),
            Self::Initial => String::from(
                "The following graphic character is presented in its initial form."
            ),
            Self::Medial => String::from(
                "The following graphic character is presented in its medial form."
            ),
            Self::Final => String::from(
                "The following graphic character is presented in its final form."
            ),
            Self::DecimalFullStop => String::from(
                concat!(
                    "Where the bit combination 02/14 (FULL STOP) is intended to represent a decimal mark in a decimal ",
                    "number it shall be represented by means of the graphic symbol FULL STOP."
                )
            ),
            Self::DecimalComma => String::from(
                concat!(
                    "Where the bit combination 02/14 (FULL STOP) is intended to represent a decimal mark in a decimal ",
                    "number it shall be presented by means of the graphic symbol COMMA."
                )
            ),
            Self::VowelAboveOrBelow => String::from(
                "Vowels are presented above or below the preceding character."
            ),
            Self::VowelAfterPreceding => String::from(
                "Vowels are presented after the preceding character."
            ),
            Self::ContextualShapeArabicScriptWithLamAleph => String::from(
                concat!(
                    "Contextual shap determination of Arabic scripts, including the LAM-ALEPH ligature but excluding ",
                    "all other Arabic ligatures."
                )
            ),
            Self::ContextualShapeArabicScript => String::from(
                "Contextual shape determination of Arabic scripts, excluding all Arabic ligatures."
            ),
            Self::NoMirroring => String::from(
                "Cancels the effect of mirroring settings."
            ),
            Self::NoVowels => String::from(
                "Vowels are not presented."
            ),
            Self::SlantFollowsStringDirection => String::from(
                concat!(
                    "When the string direction is right-to-left, the italicized characters are slanted to the left, ",
                    "when the string direction is left-to-right, the italicized characters are slanted to the left."
                )
            ),
            Self::NoContextualShapeArabicScript => String::from(
                concat!(
                    "Contextual shape determination of Arabic scripts is not used, the graphic characters - including ",
                    "the digits - are presented in the form they are stored (pass-through)."
                )
            ),
            Self::NoContextualShapeArabicScriptExceptDigits => String::from(
                concat!(
                    "Contextual shape determination of Arabic scripts is not used, the graphic characters - excluding ",
                    "the digits - are presented in the form they are stored (pass-through)."
                )
            ),
            Self::DeviceDependentDecimalDigits => String::from(
                "The graphic symbols used to present the decimal digits are device dependent."
            ),
            Self::PersistCharacterForm => String::from(
                concat!(
                    "Establishes the effect of parameter values 'Isolated', 'Initial, 'Medial', and 'Final' for the ",
                    "following graphic characters until cancelled."
                )
            ),
            Self::DesistCharacterForm => String::from(
                concat!(
                    "Establishes the effect of parameter values 'Isolated', 'Initial', 'Medial', and 'Final' for the ",
                    "next single graphic character only."
                )
            ),
        }
    }
}

impl FromStr for CharacterOrientation {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::Rotate45,
            "2" => Self::Rotate90,
            "3" => Self::Rotate135,
            "4" => Self::Rotate180,
            "5" => Self::Rotate225,
            "6" => Self::Rotate270,
            "7" => Self::Rotate315,
            _ => Self::Normal,
        })
    }
}

impl ExplainSelection for CharacterOrientation {
    fn explain(&self) -> String {
        match self {
            Self::Normal => String::from("Rotate by 0°."),
            Self::Rotate45 => String::from("Rotate by 45°."),
            Self::Rotate90 => String::from("Rotate by 90°."),
            Self::Rotate135 => String::from("Rotate by 135°."),
            Self::Rotate180 => String::from("Rotate by 180°."),
            Self::Rotate225 => String::from("Rotate by 225°."),
            Self::Rotate270 => String::from("Rotate by 270°."),
            Self::Rotate315 => String::from("Rotate by 315°."),
        }
    }
}

impl FromStr for CharacterPath {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "2" => Self::RightToLeft,
            _ => Self::LefToRight,
        })
    }
}

impl ExplainSelection for CharacterPath {
    fn explain(&self) -> String {
        match self {
            Self::LefToRight => String::from("Left-to-right, or top-to-bottom."),
            Self::RightToLeft => String::from("Right-to-left, or bottom-to-top."),
        }
    }
}

impl FromStr for CharacterPathScope {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::InPresentationComponent,
            "2" => Self::InDataComponent,
            _ => Self::Undefined,
        })
    }
}

impl ExplainSelection for CharacterPathScope {
    fn explain(&self) -> String {
        match self {
            CharacterPathScope::Undefined => String::from(
                "The scope of the new character path is undefined."
            ),
            CharacterPathScope::InPresentationComponent => String::from(
                concat!(
                    "The content of the active line in the presentation component is updated to correspond to the ",
                    "content of the active line in the data component according to the newly established character ",
                    "path characteristics in the presentation component."
                )
            ),
            CharacterPathScope::InDataComponent => String::from(
                concat!(
                    "The content of the active line in the data component is updated to correspond to the content of ",
                    "the active line in the presentation component according to the newly established character path ",
                    "characteristics in the presentation component."
                )
            ),
        }
    }
}

impl FromStr for StringDirection {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::StartLeftToRight,
            "2" => Self::StartRightToLeft,
            _ => Self::End,
        })
    }
}

impl ExplainSelection for StringDirection {
    fn explain(&self) -> String {
        match self {
            Self::End => {
                String::from("End of a directed string - re-establish the previous direction.")
            }
            Self::StartLeftToRight => {
                String::from("Start of a directed string, establish the direction left-to-right.")
            }
            Self::StartRightToLeft => {
                String::from("Start of a directed string, establish the direction right-to-left.")
            }
        }
    }
}

impl FromStr for EditingExtend {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::ActiveLine,
            "2" => Self::ActiveField,
            "3" => Self::QualifiedArea,
            "4" => Self::All,
            _ => Self::ActivePage,
        })
    }
}

impl ExplainSelection for EditingExtend {
    fn explain(&self) -> String {
        match self {
            Self::ActivePage => String::from("the shifted part is limited to the active page"),
            Self::ActiveLine => String::from("the shifted part is limited to the active line"),
            Self::ActiveField => String::from("the shifted part is limited to the active field"),
            Self::QualifiedArea => {
                String::from("the shifted part is limited to the active qualified area")
            }
            Self::All => String::from("the shifted part is not limited"),
        }
    }
}

impl FromStr for Load {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "0" => Self::None,
            value @ _ => Self::Bin(
                value
                    .parse::<u32>()
                    .expect("Expected valid value for Load directive"),
            ),
        })
    }
}

impl ExplainSelection for Load {
    fn explain(&self) -> String {
        match self {
            Self::None => String::from("Eject sheet, no new sheet loaded."),
            Self::Bin(bin) => format!("Eject sheet, load a new sheet from bin {}.", bin),
        }
    }
}

impl FromStr for Stack {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "0" => Self::None,
            value @ _ => Self::Stacker(
                value
                    .parse::<u32>()
                    .expect("Expected valid value for Load directive"),
            ),
        })
    }
}

impl ExplainSelection for Stack {
    fn explain(&self) -> String {
        match self {
            Self::None => String::from("Eject sheet, no stacker specified."),
            Self::Stacker(stacker) => format!("Eject sheet into the stacker {}.", stacker),
        }
    }
}

impl FromStr for GraphicRendition {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::HighIntensity,
            "2" => Self::LowIntensity,
            "3" => Self::Italicized,
            "4" => Self::Underlined,
            "5" => Self::SlowlyBlinking,
            "6" => Self::RapidlyBlinking,
            "7" => Self::Negative,
            "8" => Self::Concealed,
            "9" => Self::CrossedOut,
            "10" => Self::PrimaryFont,
            "11" => Self::FirstAlternativeFont,
            "12" => Self::SecondAlternativeFont,
            "13" => Self::ThirdAlternativeFont,
            "14" => Self::ForthAlternativeFont,
            "15" => Self::FifthAlternativeFont,
            "16" => Self::SixthAlternativeFont,
            "17" => Self::SeventhAlternativeFont,
            "18" => Self::EighthAlternativeFont,
            "19" => Self::NinthAlternativeFont,
            "20" => Self::Fraktur,
            "21" => Self::DoublyUnderlined,
            "22" => Self::NormalIntensity,
            "23" => Self::NormalStyle,
            "24" => Self::NotUnderlined,
            "25" => Self::NotBlinking,
            "27" => Self::Positive,
            "28" => Self::Revealed,
            "29" => Self::NotCrossedOut,
            "30" => Self::BlackForeground,
            "31" => Self::RedForeground,
            "32" => Self::GreenForeground,
            "33" => Self::YellowForeground,
            "34" => Self::BlueForeground,
            "35" => Self::MagentaForeground,
            "36" => Self::CyanForeground,
            "37" => Self::WhiteForeground,
            "39" => Self::DefaultForeground,
            "40" => Self::BlackBackground,
            "41" => Self::RedBackground,
            "42" => Self::GreenBackground,
            "43" => Self::YellowBackground,
            "44" => Self::BlueBackground,
            "45" => Self::MagentaBackground,
            "46" => Self::CyanBackground,
            "47" => Self::WhiteBackground,
            "49" => Self::DefaultBackground,
            "51" => Self::Framed,
            "52" => Self::Encircled,
            "53" => Self::Overlined,
            "54" => Self::NotFramed,
            "55" => Self::NotOverlined,
            "60" => Self::IdeogramUnderline,
            "61" => Self::IdeogramUnderline,
            "62" => Self::IdeogramStressMarking,
            "63" => Self::CancelIdeogramRendition,
            _ => Self::Default,
        })
    }
}

impl ExplainSelection for GraphicRendition {
    fn explain(&self) -> String {
        match self {
            Self::Default => String::from("Default rendition, cancel all effects."),
            Self::HighIntensity => String::from("Bold or increased intensity."),
            Self::LowIntensity => String::from("Faint, decreased intensity or second color."),
            Self::Italicized => String::from("Italicized."),
            Self::Underlined => String::from("Singly underlined."),
            Self::SlowlyBlinking => String::from("Slowly blinking (less than 150 per minute)."),
            Self::RapidlyBlinking => String::from("Rapidly blinking (more than 150 per minute)."),
            Self::Negative => String::from("Negative image."),
            Self::Concealed => String::from("Concealed characters."),
            Self::CrossedOut => {
                String::from("Crossed-out (characters still legible but marked as to be deleted).")
            }
            Self::PrimaryFont => String::from("Primary (default) font."),
            Self::FirstAlternativeFont => String::from("First alternative font."),
            Self::SecondAlternativeFont => String::from("Second alternative font."),
            Self::ThirdAlternativeFont => String::from("Third alternative font."),
            Self::ForthAlternativeFont => String::from("Forth alternative font."),
            Self::FifthAlternativeFont => String::from("Fifth alternative font."),
            Self::SixthAlternativeFont => String::from("Sixth alternative font."),
            Self::SeventhAlternativeFont => String::from("Seventh alternative font."),
            Self::EighthAlternativeFont => String::from("Eighth alternative font."),
            Self::NinthAlternativeFont => String::from("Ninth alternative font."),
            Self::Fraktur => String::from("Fraktur (Gothic)."),
            Self::DoublyUnderlined => String::from("Doubly underlined."),
            Self::NormalIntensity => String::from("Normal intensity or normal color."),
            Self::NormalStyle => String::from("Normal style, not italicized, not fraktur."),
            Self::NotUnderlined => String::from("Not underlined."),
            Self::NotBlinking => String::from("Not blinking."),
            Self::Positive => String::from("Positive image."),
            Self::Revealed => String::from("Revealed characters."),
            Self::NotCrossedOut => String::from("Not crossed out."),
            Self::BlackForeground => String::from("Black foreground color."),
            Self::RedForeground => String::from("Red foreground color."),
            Self::GreenForeground => String::from("Green foreground color."),
            Self::YellowForeground => String::from("Yellow foreground color."),
            Self::BlueForeground => String::from("Blue foreground color."),
            Self::MagentaForeground => String::from("Magenta foreground color."),
            Self::CyanForeground => String::from("Cyan foreground color."),
            Self::WhiteForeground => String::from("White foreground color."),
            Self::DefaultForeground => String::from("Default foreground color."),
            Self::BlackBackground => String::from("Black background color."),
            Self::RedBackground => String::from("Red background color."),
            Self::GreenBackground => String::from("Green background color."),
            Self::YellowBackground => String::from("Yellow background color."),
            Self::BlueBackground => String::from("Blue background color."),
            Self::MagentaBackground => String::from("Magenta background color."),
            Self::CyanBackground => String::from("Cyan background color."),
            Self::WhiteBackground => String::from("White background color."),
            Self::DefaultBackground => String::from("Default background color."),
            Self::Framed => String::from("Framed."),
            Self::Encircled => String::from("Encircled."),
            Self::Overlined => String::from("Overlined."),
            Self::NotFramed => String::from("Not Framed."),
            Self::NotOverlined => String::from("Not Overlined."),
            Self::IdeogramUnderline => String::from("Ideogram underline or right side line."),
            Self::IdeogramDoubleUnderline => {
                String::from("Ideogram double underline or double line on the right side.")
            }
            Self::IdeogramStressMarking => String::from("Ideogram stress marking."),
            Self::CancelIdeogramRendition => String::from("Cancel Ideogram rendition settings."),
        }
    }
}

impl FromStr for CharacterSpacing {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::TwelveCharacters,
            "2" => Self::FifteenCharacters,
            "3" => Self::SixCharacters,
            "4" => Self::ThreeCharacters,
            "5" => Self::NineCharacters,
            "6" => Self::FourCharacters,
            _ => Self::TenCharacters,
        })
    }
}

impl ExplainSelection for CharacterSpacing {
    fn explain(&self) -> String {
        match self {
            Self::TenCharacters => {
                String::from("Set character spacing to 10 characters per 25.4mm.")
            }
            Self::TwelveCharacters => {
                String::from("Set character spacing to 12 characters per 25.4mm.")
            }
            Self::FifteenCharacters => {
                String::from("Set character spacing to 15 characters per 25.4mm.")
            }
            Self::SixCharacters => {
                String::from("Set character spacing to 6 characters per 25.4mm.")
            }
            Self::ThreeCharacters => {
                String::from("Set character spacing to 3 characters per 25.4mm.")
            }
            Self::NineCharacters => {
                String::from("Set character spacing to 9 characters per 25.4mm.")
            }
            Self::FourCharacters => {
                String::from("Set character spacing to 4 characters per 25.4mm.")
            }
        }
    }
}

impl FromStr for MovementDirection {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::Opposite,
            _ => Self::Normal,
        })
    }
}

impl ExplainSelection for MovementDirection {
    fn explain(&self) -> String {
        match self {
            Self::Normal => String::from(
                "Implicit movement is in the same direction as that of character progression.",
            ),
            Self::Opposite => String::from(
                "Implicit movement is in the opposite direction as that of character progression.",
            ),
        }
    }
}

impl FromStr for PresentationDirection {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::VerticalLinesRightToLeftTopToBottom,
            "2" => Self::VerticalLinesLeftToRightTopToBottom,
            "3" => Self::HorizontalLinesTopToBottomRightToLeft,
            "4" => Self::VerticalLinesLeftToRightBottomToTop,
            "5" => Self::HorizontalLinesBottomToTopRightToLeft,
            "6" => Self::HorizontalLinesBottomToTopLefToRight,
            "7" => Self::VerticalLinesRightToLeftBottomToTop,
            _ => Self::HorizontalLinesTopToBottomLeftToRight,
        })
    }
}

impl ExplainSelection for PresentationDirection {
    fn explain(&self) -> String {
        match self {
            Self::HorizontalLinesTopToBottomLeftToRight => String::from(
                "horizontal line orientation, top-to-bottom line progression, left-to-right character path"
            ),
            Self::VerticalLinesRightToLeftTopToBottom => String::from(
                "vertical line orientation, right-to-left line progression, top-to-bottom character path"
            ),
            Self::VerticalLinesLeftToRightTopToBottom => String::from(
                "vertical line orientation, left-to-right line progression, top-to-bottom character path"
            ),
            Self::HorizontalLinesTopToBottomRightToLeft => String::from(
                "horizontal line orientation, top-to-bottom line progression, right-to-left character path"
            ),
            Self::VerticalLinesLeftToRightBottomToTop => String::from(
                "vertical line orientation, left-to-right line progression, bottom-to-top character path"
            ),
            Self::HorizontalLinesBottomToTopRightToLeft => String::from(
                "horizontal line orientation, bottom-to-top line progression, right-to-left character path"
            ),
            Self::HorizontalLinesBottomToTopLefToRight => String::from(
                "horizontal line orientation, bottom-to-top line progression, left-to-right character path"
            ),
            Self::VerticalLinesRightToLeftBottomToTop => String::from(
                "vertical line orientation, right to left line progression, bottom-to-top character path"
            ),
        }
    }
}

impl FromStr for PresentationDirectionScope {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::InPresentationComponent,
            "2" => Self::InDataComponent,
            _ => Self::Undefined,
        })
    }
}

impl ExplainSelection for PresentationDirectionScope {
    fn explain(&self) -> String {
        match self {
            Self::Undefined => String::from("an undefined scope"),
            Self::InPresentationComponent => String::from("the presentation component"),
            Self::InDataComponent => String::from("the data component"),
        }
    }
}

impl FromStr for PrintQuality {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::MediumQualityMediumSpeed,
            "2" => Self::LowQualityHighSpeed,
            _ => Self::HighQualityLowSpeed,
        })
    }
}

impl ExplainSelection for PrintQuality {
    fn explain(&self) -> String {
        match self {
            Self::HighQualityLowSpeed => String::from("Print in high quality with low speed."),
            Self::MediumQualityMediumSpeed => {
                String::from("Print in medium quality with medium speed.")
            }
            Self::LowQualityHighSpeed => String::from("Print in low quality with high speed."),
        }
    }
}

impl FromStr for ReversedString {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::Start,
            _ => Self::End,
        })
    }
}

impl ExplainSelection for ReversedString {
    fn explain(&self) -> String {
        match self {
            Self::End => {
                String::from("End of a reversed string; re-establish the previous direction.")
            }
            Self::Start => String::from("Beginning of a reversed string; reverse the direction."),
        }
    }
}

impl FromStr for SizeUnit {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::Millimetre,
            "2" => Self::ComputerDecipoint,
            "3" => Self::Decidot,
            "4" => Self::Mil,
            "5" => Self::BasicMeasuringUnit,
            "6" => Self::Micrometer,
            "7" => Self::Pixel,
            "8" => Self::Decipoint,
            _ => Self::Character,
        })
    }
}

impl ExplainSelection for SizeUnit {
    fn explain(&self) -> String {
        match self {
            Self::Character => {
                String::from("Character. The dimension of this unit is device-dependent.")
            }
            Self::Millimetre => String::from("Millimetre."),
            Self::ComputerDecipoint => {
                String::from("Computer decipoint (0.03528 mm - 1/720 of 25.4 mm).")
            }
            Self::Decidot => String::from("Decidot (0.03759 mm - 10/266 mm)."),
            Self::Mil => String::from("Mil (0.0254 mm - 1/1000 of 25.4 mm)."),
            Self::BasicMeasuringUnit => {
                String::from("Basic Measuring Unit (BMU) (0.02117 mm - 1/1200 of 25.4 mm).")
            }
            Self::Micrometer => String::from("Micrometer (0.001 mm)"),
            Self::Pixel => {
                String::from("Pixel, the smallest increment that can be specified in the device.")
            }
            Self::Decipoint => String::from("Decipoint (0.03514mm - 35/996 mm)."),
        }
    }
}

impl FromStr for LineSpacing {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::FourLinesPer25,
            "2" => Self::ThreeLinesPer25,
            "3" => Self::TwelveLinesPer25,
            "4" => Self::EightLinesPer25,
            "5" => Self::SixLinesPer30,
            "6" => Self::FourLinesPer30,
            "7" => Self::ThreeLinesPer30,
            "8" => Self::TwelveLinesPer30,
            "9" => Self::TwoLinesPer25,
            _ => Self::SixLinesPer25,
        })
    }
}

impl ExplainSelection for LineSpacing {
    fn explain(&self) -> String {
        match self {
            Self::SixLinesPer25 => String::from("Set line spacing to 6 lines per 25 mm."),
            Self::FourLinesPer25 => String::from("Set line spacing to 4 lines per 25 mm."),
            Self::ThreeLinesPer25 => String::from("Set line spacing to 3 lines per 25 mm."),
            Self::TwelveLinesPer25 => String::from("Set line spacing to 12 lines per 25 mm."),
            Self::EightLinesPer25 => String::from("Set line spacing to 8 lines per 25 mm."),
            Self::SixLinesPer30 => String::from("Set line spacing to 6 lines per 30 mm."),
            Self::FourLinesPer30 => String::from("Set line spacing to 4 lines per 30 mm."),
            Self::ThreeLinesPer30 => String::from("Set line spacing to 3 lines per 30 mm."),
            Self::TwelveLinesPer30 => String::from("Set line spacing to 12 lines per 30 mm."),
            Self::TwoLinesPer25 => String::from("Set line spacing to 2 lines per 25 mm."),
        }
    }
}

impl FromStr for ClearTabulation {
    type Err = Infallible;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "1" => Self::LineTabulationStopActiveLine,
            "2" => Self::AllCharacterTabulationStopsActiveLine,
            "3" => Self::AllCharacterTabulationStops,
            "4" => Self::AllTabulationStops,
            "5" => Self::AllTabulationStops,
            _ => Self::CharacterTabulationStopActivePosition,
        })
    }
}

impl ExplainSelection for ClearTabulation {
    fn explain(&self) -> String {
        match self {
            Self::CharacterTabulationStopActivePosition => String::from(
                "Clear the character tabulation stop at the active presentation position.",
            ),
            Self::LineTabulationStopActiveLine => {
                String::from("Clear the line tabulation stop at the active line.")
            }
            Self::AllCharacterTabulationStopsActiveLine => {
                String::from("Clear all character tabulation stops at the active line.")
            }
            Self::AllCharacterTabulationStops => {
                String::from("Clear all character tabulation stops.")
            }
            Self::AllLineTabulationStops => String::from("Clear all line tabulation stops."),
            Self::AllTabulationStops => String::from("Clear all tabulation stops."),
        }
    }
}

#[cfg(test)]
mod tests {
    use crate::{c0::CR, explain::Explain};

    /// Test the output of short_name
    #[test]
    fn get_short_name() {
        assert_eq!(CR.short_name(), Some("CR"))
    }

    /// Test the output of long_name
    #[test]
    fn get_long_name() {
        assert_eq!(CR.long_name(), "Carriage Return")
    }

    /// Test the output of short_description
    #[test]
    fn get_short_description() {
        assert_eq!(CR.short_description(), "Move to the beginning of the line.")
    }

    /// Test the output of long_description
    #[test]
    fn get_long_description() {
        assert_eq!(CR.long_description(),
        concat!(
            "Move the cursor to the beginning of the line. The exact meaning depends on the setting of 'Device ",
            "Component Select Mode' (DCSM) and on the parameter value of 'Select Implicit Movement Direction' (SIMD).",
            "\n\nIf the DCSM is set to 'Presentation' and SIMD is set to 'Normal', it causes the active presentation ",
            "position to be moved to the line home position of the same line in the presentation component. The line ",
            "home position is established by the parameter value of 'Set Line Home' SLH.\nWith SIMD set to ",
            "'Opposite', it causes the active presentation position to be moved to the line limit position of the ",
            "same line in the presentation component. The line limit position is established by the parameter value ",
            "of 'Set Line Limit' (SLL).\n\nIf the DCSM is set to 'Data' and SIMD is set to 'Normal', it causes the ",
            "active data position to be moved to the line home position of the same line in the data component. The ",
            "line home position is established by the parameter value of 'Set Line Home' (SLH)\nWith SIMD set to ",
            "'Opposite', it causes the active data position to be moved to the line limit position of the same line ",
            "in the data component. The line limit position position is established by the parameter value of ",
            "'Set Line Limit' (SLL)."
        )
    )
    }
}