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
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
|
/*
* This is a curses module for Python.
*
* Based on prior work by Lance Ellinghaus and Oliver Andrich
* Version 1.2 of this module: Copyright 1994 by Lance Ellinghouse,
* Cathedral City, California Republic, United States of America.
*
* Version 1.5b1, heavily extended for ncurses by Oliver Andrich:
* Copyright 1996,1997 by Oliver Andrich, Koblenz, Germany.
*
* Tidied for Python 1.6, and currently maintained by <amk@amk.ca>.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this source file to use, copy, modify, merge, or publish it
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or in any new file that contains a substantial portion of
* this file.
*
* THE AUTHOR MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF
* THE SOFTWARE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT
* EXPRESS OR IMPLIED WARRANTY. THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE, STRICT LIABILITY OR
* ANY OTHER ACTION ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/*
A number of SysV or ncurses functions don't have wrappers yet; if you
need a given function, add it and send a patch. See
http://www.python.org/dev/patches/ for instructions on how to submit
patches to Python.
Here's a list of currently unsupported functions:
addchnstr addchstr color_set define_key
del_curterm delscreen dupwin inchnstr inchstr innstr keyok
mcprint mvaddchnstr mvaddchstr mvcur mvinchnstr
mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr
mvwinchnstr mvwinchstr mvwinnstr newterm
restartterm ripoffline scr_dump
scr_init scr_restore scr_set scrl set_curterm set_term setterm
tgetent tgetflag tgetnum tgetstr tgoto timeout tputs
vidattr vidputs waddchnstr waddchstr
wcolor_set winchnstr winchstr winnstr wmouse_trafo wscrl
Low-priority:
slk_attr slk_attr_off slk_attr_on slk_attr_set slk_attroff
slk_attron slk_attrset slk_clear slk_color slk_init slk_label
slk_noutrefresh slk_refresh slk_restore slk_set slk_touch
Menu extension (ncurses and probably SYSV):
current_item free_item free_menu item_count item_description
item_index item_init item_name item_opts item_opts_off
item_opts_on item_term item_userptr item_value item_visible
menu_back menu_driver menu_fore menu_format menu_grey
menu_init menu_items menu_mark menu_opts menu_opts_off
menu_opts_on menu_pad menu_pattern menu_request_by_name
menu_request_name menu_spacing menu_sub menu_term menu_userptr
menu_win new_item new_menu pos_menu_cursor post_menu
scale_menu set_current_item set_item_init set_item_opts
set_item_term set_item_userptr set_item_value set_menu_back
set_menu_fore set_menu_format set_menu_grey set_menu_init
set_menu_items set_menu_mark set_menu_opts set_menu_pad
set_menu_pattern set_menu_spacing set_menu_sub set_menu_term
set_menu_userptr set_menu_win set_top_row top_row unpost_menu
Form extension (ncurses and probably SYSV):
current_field data_ahead data_behind dup_field
dynamic_fieldinfo field_arg field_back field_buffer
field_count field_fore field_index field_info field_init
field_just field_opts field_opts_off field_opts_on field_pad
field_status field_term field_type field_userptr form_driver
form_fields form_init form_opts form_opts_off form_opts_on
form_page form_request_by_name form_request_name form_sub
form_term form_userptr form_win free_field free_form
link_field link_fieldtype move_field new_field new_form
new_page pos_form_cursor post_form scale_form
set_current_field set_field_back set_field_buffer
set_field_fore set_field_init set_field_just set_field_opts
set_field_pad set_field_status set_field_term set_field_type
set_field_userptr set_fieldtype_arg set_fieldtype_choice
set_form_fields set_form_init set_form_opts set_form_page
set_form_sub set_form_term set_form_userptr set_form_win
set_max_field set_new_page unpost_form
*/
/* Release Number */
static const char PyCursesVersion[] = "2.2";
/* Includes */
#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "pycore_long.h" // _PyLong_GetZero()
#ifdef __hpux
#define STRICT_SYSV_CURSES
#endif
#define CURSES_MODULE
#include "py_curses.h"
#if defined(HAVE_TERM_H) || defined(__sgi)
/* For termname, longname, putp, tigetflag, tigetnum, tigetstr, tparm
which are not declared in SysV curses and for setupterm. */
#include <term.h>
/* Including <term.h> #defines many common symbols. */
#undef lines
#undef columns
#endif
#ifdef HAVE_LANGINFO_H
#include <langinfo.h>
#endif
#if !defined(HAVE_NCURSES_H) && (defined(sgi) || defined(__sun) || defined(SCO5))
#define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
typedef chtype attr_t; /* No attr_t type is available */
#endif
#if defined(_AIX)
#define STRICT_SYSV_CURSES
#endif
#if defined(NCURSES_EXT_COLORS) && defined(NCURSES_EXT_FUNCS)
#define _NCURSES_EXTENDED_COLOR_FUNCS 1
#else
#define _NCURSES_EXTENDED_COLOR_FUNCS 0
#endif /* defined(NCURSES_EXT_COLORS) && defined(NCURSES_EXT_FUNCS) */
#if _NCURSES_EXTENDED_COLOR_FUNCS
#define _NCURSES_COLOR_VAL_TYPE int
#define _CURSES_INIT_COLOR_FUNC init_extended_color
#define _CURSES_INIT_PAIR_FUNC init_extended_pair
#define _COLOR_CONTENT_FUNC extended_color_content
#define _CURSES_PAIR_NUMBER_FUNC extended_pair_content
#else
#define _NCURSES_COLOR_VAL_TYPE short
#define _CURSES_INIT_COLOR_FUNC init_color
#define _CURSES_INIT_PAIR_FUNC init_pair
#define _COLOR_CONTENT_FUNC color_content
#define _CURSES_PAIR_NUMBER_FUNC pair_content
#endif /* _NCURSES_EXTENDED_COLOR_FUNCS */
#define _CURSES_FUNC_NAME_STR(s) #s
#define _CURSES_INIT_COLOR_FUNC_NAME _CURSES_FUNC_NAME_STR(_CURSES_INIT_COLOR_FUNC)
#define _CURSES_INIT_PAIR_FUNC_NAME _CURSES_FUNC_NAME_STR(_CURSES_INIT_PAIR_FUNC)
/*[clinic input]
module _curses
class _curses.window "PyCursesWindowObject *" "&PyCursesWindow_Type"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=43265c372c2887d6]*/
/* Definition of exception curses.error */
static PyObject *PyCursesError;
/* Tells whether setupterm() has been called to initialise terminfo. */
static int initialised_setupterm = FALSE;
/* Tells whether initscr() has been called to initialise curses. */
static int initialised = FALSE;
/* Tells whether start_color() has been called to initialise color usage. */
static int initialisedcolors = FALSE;
static char *screen_encoding = NULL;
/* Utility Macros */
#define PyCursesSetupTermCalled \
if (initialised_setupterm != TRUE) { \
PyErr_SetString(PyCursesError, \
"must call (at least) setupterm() first"); \
return 0; }
#define PyCursesInitialised \
if (initialised != TRUE) { \
PyErr_SetString(PyCursesError, \
"must call initscr() first"); \
return 0; }
#define PyCursesInitialisedColor \
if (initialisedcolors != TRUE) { \
PyErr_SetString(PyCursesError, \
"must call start_color() first"); \
return 0; }
/* Utility Functions */
static inline int
color_pair_to_attr(short color_number)
{
return ((int)color_number << 8);
}
static inline short
attr_to_color_pair(int attr)
{
return (short)((attr & A_COLOR) >> 8);
}
/*
* Check the return code from a curses function and return None
* or raise an exception as appropriate. These are exported using the
* capsule API.
*/
static PyObject *
PyCursesCheckERR(int code, const char *fname)
{
if (code != ERR) {
Py_RETURN_NONE;
} else {
if (fname == NULL) {
PyErr_SetString(PyCursesError, catchall_ERR);
} else {
PyErr_Format(PyCursesError, "%s() returned ERR", fname);
}
return NULL;
}
}
/* Convert an object to a byte (an integer of type chtype):
- int
- bytes of length 1
- str of length 1
Return 1 on success, 0 on error (invalid type or integer overflow). */
static int
PyCurses_ConvertToChtype(PyCursesWindowObject *win, PyObject *obj, chtype *ch)
{
long value;
if(PyBytes_Check(obj) && PyBytes_Size(obj) == 1) {
value = (unsigned char)PyBytes_AsString(obj)[0];
}
else if (PyUnicode_Check(obj)) {
if (PyUnicode_GetLength(obj) != 1) {
PyErr_Format(PyExc_TypeError,
"expect bytes or str of length 1, or int, "
"got a str of length %zi",
PyUnicode_GET_LENGTH(obj));
return 0;
}
value = PyUnicode_READ_CHAR(obj, 0);
if (128 < value) {
PyObject *bytes;
const char *encoding;
if (win)
encoding = win->encoding;
else
encoding = screen_encoding;
bytes = PyUnicode_AsEncodedString(obj, encoding, NULL);
if (bytes == NULL)
return 0;
if (PyBytes_GET_SIZE(bytes) == 1)
value = (unsigned char)PyBytes_AS_STRING(bytes)[0];
else
value = -1;
Py_DECREF(bytes);
if (value < 0)
goto overflow;
}
}
else if (PyLong_CheckExact(obj)) {
int long_overflow;
value = PyLong_AsLongAndOverflow(obj, &long_overflow);
if (long_overflow)
goto overflow;
}
else {
PyErr_Format(PyExc_TypeError,
"expect bytes or str of length 1, or int, got %s",
Py_TYPE(obj)->tp_name);
return 0;
}
*ch = (chtype)value;
if ((long)*ch != value)
goto overflow;
return 1;
overflow:
PyErr_SetString(PyExc_OverflowError,
"byte doesn't fit in chtype");
return 0;
}
/* Convert an object to a byte (chtype) or a character (cchar_t):
- int
- bytes of length 1
- str of length 1
Return:
- 2 if obj is a character (written into *wch)
- 1 if obj is a byte (written into *ch)
- 0 on error: raise an exception */
static int
PyCurses_ConvertToCchar_t(PyCursesWindowObject *win, PyObject *obj,
chtype *ch
#ifdef HAVE_NCURSESW
, wchar_t *wch
#endif
)
{
long value;
#ifdef HAVE_NCURSESW
wchar_t buffer[2];
#endif
if (PyUnicode_Check(obj)) {
#ifdef HAVE_NCURSESW
if (PyUnicode_AsWideChar(obj, buffer, 2) != 1) {
PyErr_Format(PyExc_TypeError,
"expect bytes or str of length 1, or int, "
"got a str of length %zi",
PyUnicode_GET_LENGTH(obj));
return 0;
}
*wch = buffer[0];
return 2;
#else
return PyCurses_ConvertToChtype(win, obj, ch);
#endif
}
else if(PyBytes_Check(obj) && PyBytes_Size(obj) == 1) {
value = (unsigned char)PyBytes_AsString(obj)[0];
}
else if (PyLong_CheckExact(obj)) {
int overflow;
value = PyLong_AsLongAndOverflow(obj, &overflow);
if (overflow) {
PyErr_SetString(PyExc_OverflowError,
"int doesn't fit in long");
return 0;
}
}
else {
PyErr_Format(PyExc_TypeError,
"expect bytes or str of length 1, or int, got %s",
Py_TYPE(obj)->tp_name);
return 0;
}
*ch = (chtype)value;
if ((long)*ch != value) {
PyErr_Format(PyExc_OverflowError,
"byte doesn't fit in chtype");
return 0;
}
return 1;
}
/* Convert an object to a byte string (char*) or a wide character string
(wchar_t*). Return:
- 2 if obj is a character string (written into *wch)
- 1 if obj is a byte string (written into *bytes)
- 0 on error: raise an exception */
static int
PyCurses_ConvertToString(PyCursesWindowObject *win, PyObject *obj,
PyObject **bytes, wchar_t **wstr)
{
char *str;
if (PyUnicode_Check(obj)) {
#ifdef HAVE_NCURSESW
assert (wstr != NULL);
*wstr = PyUnicode_AsWideCharString(obj, NULL);
if (*wstr == NULL)
return 0;
return 2;
#else
assert (wstr == NULL);
*bytes = PyUnicode_AsEncodedString(obj, win->encoding, NULL);
if (*bytes == NULL)
return 0;
/* check for embedded null bytes */
if (PyBytes_AsStringAndSize(*bytes, &str, NULL) < 0) {
return 0;
}
return 1;
#endif
}
else if (PyBytes_Check(obj)) {
Py_INCREF(obj);
*bytes = obj;
/* check for embedded null bytes */
if (PyBytes_AsStringAndSize(*bytes, &str, NULL) < 0) {
return 0;
}
return 1;
}
PyErr_Format(PyExc_TypeError, "expect bytes or str, got %s",
Py_TYPE(obj)->tp_name);
return 0;
}
static int
color_converter(PyObject *arg, void *ptr)
{
long color_number;
int overflow;
color_number = PyLong_AsLongAndOverflow(arg, &overflow);
if (color_number == -1 && PyErr_Occurred())
return 0;
if (overflow > 0 || color_number > COLORS) {
PyErr_Format(PyExc_ValueError,
"Color number is greater than COLORS (%d).",
COLORS);
return 0;
}
else if (overflow < 0 || color_number < 0) {
PyErr_SetString(PyExc_ValueError,
"Color number is less than 0.");
return 0;
}
*(int *)ptr = (int)color_number;
return 1;
}
/*[python input]
class color_converter(CConverter):
type = 'int'
converter = 'color_converter'
[python start generated code]*/
/*[python end generated code: output=da39a3ee5e6b4b0d input=4260d2b6e66b3709]*/
static int
pair_converter(PyObject *arg, void *ptr)
{
long pair_number;
int overflow;
pair_number = PyLong_AsLongAndOverflow(arg, &overflow);
if (pair_number == -1 && PyErr_Occurred())
return 0;
if (overflow > 0 || pair_number > COLOR_PAIRS - 1) {
PyErr_Format(PyExc_ValueError,
"Color pair is greater than COLOR_PAIRS-1 (%d).",
COLOR_PAIRS - 1);
return 0;
}
else if (overflow < 0 || pair_number < 1) {
PyErr_SetString(PyExc_ValueError,
"Color pair is less than 1.");
return 0;
}
*(int *)ptr = (int)pair_number;
return 1;
}
/*[python input]
class pair_converter(CConverter):
type = 'int'
converter = 'pair_converter'
[python start generated code]*/
/*[python end generated code: output=da39a3ee5e6b4b0d input=1a918ae6a1b32af7]*/
static int
component_converter(PyObject *arg, void *ptr)
{
long component;
int overflow;
component = PyLong_AsLongAndOverflow(arg, &overflow);
if (component == -1 && PyErr_Occurred())
return 0;
if (overflow > 0 || component > 1000) {
PyErr_SetString(PyExc_ValueError,
"Color component is greater than 1000");
return 0;
}
else if (overflow < 0 || component < 0) {
PyErr_SetString(PyExc_ValueError,
"Color component is less than 0");
return 0;
}
*(short *)ptr = (short)component;
return 1;
}
/*[python input]
class component_converter(CConverter):
type = 'short'
converter = 'component_converter'
[python start generated code]*/
/*[python end generated code: output=da39a3ee5e6b4b0d input=38e9be01d33927fb]*/
/* Function versions of the 3 functions for testing whether curses has been
initialised or not. */
static int func_PyCursesSetupTermCalled(void)
{
PyCursesSetupTermCalled;
return 1;
}
static int func_PyCursesInitialised(void)
{
PyCursesInitialised;
return 1;
}
static int func_PyCursesInitialisedColor(void)
{
PyCursesInitialisedColor;
return 1;
}
/*****************************************************************************
The Window Object
******************************************************************************/
/* Definition of the window type */
PyTypeObject PyCursesWindow_Type;
/* Function prototype macros for Window object
X - function name
TYPE - parameter Type
ERGSTR - format string for construction of the return value
PARSESTR - format string for argument parsing
*/
#define Window_NoArgNoReturnFunction(X) \
static PyObject *PyCursesWindow_ ## X \
(PyCursesWindowObject *self, PyObject *Py_UNUSED(ignored)) \
{ return PyCursesCheckERR(X(self->win), # X); }
#define Window_NoArgTrueFalseFunction(X) \
static PyObject * PyCursesWindow_ ## X \
(PyCursesWindowObject *self, PyObject *Py_UNUSED(ignored)) \
{ \
return PyBool_FromLong(X(self->win)); }
#define Window_NoArgNoReturnVoidFunction(X) \
static PyObject * PyCursesWindow_ ## X \
(PyCursesWindowObject *self, PyObject *Py_UNUSED(ignored)) \
{ \
X(self->win); Py_RETURN_NONE; }
#define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR) \
static PyObject * PyCursesWindow_ ## X \
(PyCursesWindowObject *self, PyObject *Py_UNUSED(ignored)) \
{ \
TYPE arg1, arg2; \
X(self->win,arg1,arg2); return Py_BuildValue(ERGSTR, arg1, arg2); }
#define Window_OneArgNoReturnVoidFunction(X, TYPE, PARSESTR) \
static PyObject * PyCursesWindow_ ## X \
(PyCursesWindowObject *self, PyObject *args) \
{ \
TYPE arg1; \
if (!PyArg_ParseTuple(args, PARSESTR, &arg1)) return NULL; \
X(self->win,arg1); Py_RETURN_NONE; }
#define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR) \
static PyObject * PyCursesWindow_ ## X \
(PyCursesWindowObject *self, PyObject *args) \
{ \
TYPE arg1; \
if (!PyArg_ParseTuple(args,PARSESTR, &arg1)) return NULL; \
return PyCursesCheckERR(X(self->win, arg1), # X); }
#define Window_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \
static PyObject * PyCursesWindow_ ## X \
(PyCursesWindowObject *self, PyObject *args) \
{ \
TYPE arg1, arg2; \
if (!PyArg_ParseTuple(args,PARSESTR, &arg1, &arg2)) return NULL; \
return PyCursesCheckERR(X(self->win, arg1, arg2), # X); }
/* ------------- WINDOW routines --------------- */
Window_NoArgNoReturnFunction(untouchwin)
Window_NoArgNoReturnFunction(touchwin)
Window_NoArgNoReturnFunction(redrawwin)
Window_NoArgNoReturnFunction(winsertln)
Window_NoArgNoReturnFunction(werase)
Window_NoArgNoReturnFunction(wdeleteln)
Window_NoArgTrueFalseFunction(is_wintouched)
Window_NoArgNoReturnVoidFunction(wsyncup)
Window_NoArgNoReturnVoidFunction(wsyncdown)
Window_NoArgNoReturnVoidFunction(wstandend)
Window_NoArgNoReturnVoidFunction(wstandout)
Window_NoArgNoReturnVoidFunction(wcursyncup)
Window_NoArgNoReturnVoidFunction(wclrtoeol)
Window_NoArgNoReturnVoidFunction(wclrtobot)
Window_NoArgNoReturnVoidFunction(wclear)
Window_OneArgNoReturnVoidFunction(idcok, int, "i;True(1) or False(0)")
#ifdef HAVE_CURSES_IMMEDOK
Window_OneArgNoReturnVoidFunction(immedok, int, "i;True(1) or False(0)")
#endif
Window_OneArgNoReturnVoidFunction(wtimeout, int, "i;delay")
Window_NoArg2TupleReturnFunction(getyx, int, "ii")
Window_NoArg2TupleReturnFunction(getbegyx, int, "ii")
Window_NoArg2TupleReturnFunction(getmaxyx, int, "ii")
Window_NoArg2TupleReturnFunction(getparyx, int, "ii")
Window_OneArgNoReturnFunction(clearok, int, "i;True(1) or False(0)")
Window_OneArgNoReturnFunction(idlok, int, "i;True(1) or False(0)")
Window_OneArgNoReturnFunction(keypad, int, "i;True(1) or False(0)")
Window_OneArgNoReturnFunction(leaveok, int, "i;True(1) or False(0)")
Window_OneArgNoReturnFunction(nodelay, int, "i;True(1) or False(0)")
Window_OneArgNoReturnFunction(notimeout, int, "i;True(1) or False(0)")
Window_OneArgNoReturnFunction(scrollok, int, "i;True(1) or False(0)")
Window_OneArgNoReturnFunction(winsdelln, int, "i;nlines")
#ifdef HAVE_CURSES_SYNCOK
Window_OneArgNoReturnFunction(syncok, int, "i;True(1) or False(0)")
#endif
Window_TwoArgNoReturnFunction(mvwin, int, "ii;y,x")
Window_TwoArgNoReturnFunction(mvderwin, int, "ii;y,x")
Window_TwoArgNoReturnFunction(wmove, int, "ii;y,x")
#ifndef STRICT_SYSV_CURSES
Window_TwoArgNoReturnFunction(wresize, int, "ii;lines,columns")
#endif
/* Allocation and deallocation of Window Objects */
static PyObject *
PyCursesWindow_New(WINDOW *win, const char *encoding)
{
PyCursesWindowObject *wo;
if (encoding == NULL) {
#if defined(MS_WINDOWS)
char *buffer[100];
UINT cp;
cp = GetConsoleOutputCP();
if (cp != 0) {
PyOS_snprintf(buffer, sizeof(buffer), "cp%u", cp);
encoding = buffer;
}
#elif defined(CODESET)
const char *codeset = nl_langinfo(CODESET);
if (codeset != NULL && codeset[0] != 0)
encoding = codeset;
#endif
if (encoding == NULL)
encoding = "utf-8";
}
wo = PyObject_New(PyCursesWindowObject, &PyCursesWindow_Type);
if (wo == NULL) return NULL;
wo->win = win;
wo->encoding = _PyMem_Strdup(encoding);
if (wo->encoding == NULL) {
Py_DECREF(wo);
PyErr_NoMemory();
return NULL;
}
return (PyObject *)wo;
}
static void
PyCursesWindow_Dealloc(PyCursesWindowObject *wo)
{
if (wo->win != stdscr) delwin(wo->win);
if (wo->encoding != NULL)
PyMem_Free(wo->encoding);
PyObject_Free(wo);
}
/* Addch, Addstr, Addnstr */
/*[clinic input]
_curses.window.addch
[
y: int
Y-coordinate.
x: int
X-coordinate.
]
ch: object
Character to add.
[
attr: long(c_default="A_NORMAL") = _curses.A_NORMAL
Attributes for the character.
]
/
Paint the character.
Paint character ch at (y, x) with attributes attr,
overwriting any character previously painted at that location.
By default, the character position and attributes are the
current settings for the window object.
[clinic start generated code]*/
static PyObject *
_curses_window_addch_impl(PyCursesWindowObject *self, int group_left_1,
int y, int x, PyObject *ch, int group_right_1,
long attr)
/*[clinic end generated code: output=00f4c37af3378f45 input=95ce131578458196]*/
{
int coordinates_group = group_left_1;
int rtn;
int type;
chtype cch = 0;
#ifdef HAVE_NCURSESW
wchar_t wstr[2];
cchar_t wcval;
#endif
const char *funcname;
#ifdef HAVE_NCURSESW
type = PyCurses_ConvertToCchar_t(self, ch, &cch, wstr);
if (type == 2) {
funcname = "add_wch";
wstr[1] = L'\0';
setcchar(&wcval, wstr, attr, attr_to_color_pair(attr), NULL);
if (coordinates_group)
rtn = mvwadd_wch(self->win,y,x, &wcval);
else {
rtn = wadd_wch(self->win, &wcval);
}
}
else
#else
type = PyCurses_ConvertToCchar_t(self, ch, &cch);
#endif
if (type == 1) {
funcname = "addch";
if (coordinates_group)
rtn = mvwaddch(self->win,y,x, cch | (attr_t) attr);
else {
rtn = waddch(self->win, cch | (attr_t) attr);
}
}
else {
return NULL;
}
return PyCursesCheckERR(rtn, funcname);
}
/*[clinic input]
_curses.window.addstr
[
y: int
Y-coordinate.
x: int
X-coordinate.
]
str: object
String to add.
[
attr: long
Attributes for characters.
]
/
Paint the string.
Paint the string str at (y, x) with attributes attr,
overwriting anything previously on the display.
By default, the character position and attributes are the
current settings for the window object.
[clinic start generated code]*/
static PyObject *
_curses_window_addstr_impl(PyCursesWindowObject *self, int group_left_1,
int y, int x, PyObject *str, int group_right_1,
long attr)
/*[clinic end generated code: output=65a928ea85ff3115 input=ff6cbb91448a22a3]*/
{
int rtn;
int strtype;
PyObject *bytesobj = NULL;
#ifdef HAVE_NCURSESW
wchar_t *wstr = NULL;
#endif
attr_t attr_old = A_NORMAL;
int use_xy = group_left_1, use_attr = group_right_1;
const char *funcname;
#ifdef HAVE_NCURSESW
strtype = PyCurses_ConvertToString(self, str, &bytesobj, &wstr);
#else
strtype = PyCurses_ConvertToString(self, str, &bytesobj, NULL);
#endif
if (strtype == 0)
return NULL;
if (use_attr) {
attr_old = getattrs(self->win);
(void)wattrset(self->win,attr);
}
#ifdef HAVE_NCURSESW
if (strtype == 2) {
funcname = "addwstr";
if (use_xy)
rtn = mvwaddwstr(self->win,y,x,wstr);
else
rtn = waddwstr(self->win,wstr);
PyMem_Free(wstr);
}
else
#endif
{
const char *str = PyBytes_AS_STRING(bytesobj);
funcname = "addstr";
if (use_xy)
rtn = mvwaddstr(self->win,y,x,str);
else
rtn = waddstr(self->win,str);
Py_DECREF(bytesobj);
}
if (use_attr)
(void)wattrset(self->win,attr_old);
return PyCursesCheckERR(rtn, funcname);
}
/*[clinic input]
_curses.window.addnstr
[
y: int
Y-coordinate.
x: int
X-coordinate.
]
str: object
String to add.
n: int
Maximal number of characters.
[
attr: long
Attributes for characters.
]
/
Paint at most n characters of the string.
Paint at most n characters of the string str at (y, x) with
attributes attr, overwriting anything previously on the display.
By default, the character position and attributes are the
current settings for the window object.
[clinic start generated code]*/
static PyObject *
_curses_window_addnstr_impl(PyCursesWindowObject *self, int group_left_1,
int y, int x, PyObject *str, int n,
int group_right_1, long attr)
/*[clinic end generated code: output=6d21cee2ce6876d9 input=72718415c2744a2a]*/
{
int rtn;
int strtype;
PyObject *bytesobj = NULL;
#ifdef HAVE_NCURSESW
wchar_t *wstr = NULL;
#endif
attr_t attr_old = A_NORMAL;
int use_xy = group_left_1, use_attr = group_right_1;
const char *funcname;
#ifdef HAVE_NCURSESW
strtype = PyCurses_ConvertToString(self, str, &bytesobj, &wstr);
#else
strtype = PyCurses_ConvertToString(self, str, &bytesobj, NULL);
#endif
if (strtype == 0)
return NULL;
if (use_attr) {
attr_old = getattrs(self->win);
(void)wattrset(self->win,attr);
}
#ifdef HAVE_NCURSESW
if (strtype == 2) {
funcname = "addnwstr";
if (use_xy)
rtn = mvwaddnwstr(self->win,y,x,wstr,n);
else
rtn = waddnwstr(self->win,wstr,n);
PyMem_Free(wstr);
}
else
#endif
{
const char *str = PyBytes_AS_STRING(bytesobj);
funcname = "addnstr";
if (use_xy)
rtn = mvwaddnstr(self->win,y,x,str,n);
else
rtn = waddnstr(self->win,str,n);
Py_DECREF(bytesobj);
}
if (use_attr)
(void)wattrset(self->win,attr_old);
return PyCursesCheckERR(rtn, funcname);
}
/*[clinic input]
_curses.window.bkgd
ch: object
Background character.
attr: long(c_default="A_NORMAL") = _curses.A_NORMAL
Background attributes.
/
Set the background property of the window.
[clinic start generated code]*/
static PyObject *
_curses_window_bkgd_impl(PyCursesWindowObject *self, PyObject *ch, long attr)
/*[clinic end generated code: output=058290afb2cf4034 input=634015bcb339283d]*/
{
chtype bkgd;
if (!PyCurses_ConvertToChtype(self, ch, &bkgd))
return NULL;
return PyCursesCheckERR(wbkgd(self->win, bkgd | attr), "bkgd");
}
/*[clinic input]
_curses.window.attroff
attr: long
/
Remove attribute attr from the "background" set.
[clinic start generated code]*/
static PyObject *
_curses_window_attroff_impl(PyCursesWindowObject *self, long attr)
/*[clinic end generated code: output=8a2fcd4df682fc64 input=786beedf06a7befe]*/
{
return PyCursesCheckERR(wattroff(self->win, (attr_t)attr), "attroff");
}
/*[clinic input]
_curses.window.attron
attr: long
/
Add attribute attr from the "background" set.
[clinic start generated code]*/
static PyObject *
_curses_window_attron_impl(PyCursesWindowObject *self, long attr)
/*[clinic end generated code: output=7afea43b237fa870 input=5a88fba7b1524f32]*/
{
return PyCursesCheckERR(wattron(self->win, (attr_t)attr), "attron");
}
/*[clinic input]
_curses.window.attrset
attr: long
/
Set the "background" set of attributes.
[clinic start generated code]*/
static PyObject *
_curses_window_attrset_impl(PyCursesWindowObject *self, long attr)
/*[clinic end generated code: output=84e379bff20c0433 input=42e400c0d0154ab5]*/
{
return PyCursesCheckERR(wattrset(self->win, (attr_t)attr), "attrset");
}
/*[clinic input]
_curses.window.bkgdset
ch: object
Background character.
attr: long(c_default="A_NORMAL") = _curses.A_NORMAL
Background attributes.
/
Set the window's background.
[clinic start generated code]*/
static PyObject *
_curses_window_bkgdset_impl(PyCursesWindowObject *self, PyObject *ch,
long attr)
/*[clinic end generated code: output=8cb994fc4d7e2496 input=e09c682425c9e45b]*/
{
chtype bkgd;
if (!PyCurses_ConvertToChtype(self, ch, &bkgd))
return NULL;
wbkgdset(self->win, bkgd | attr);
return PyCursesCheckERR(0, "bkgdset");
}
/*[clinic input]
_curses.window.border
ls: object(c_default="NULL") = _curses.ACS_VLINE
Left side.
rs: object(c_default="NULL") = _curses.ACS_VLINE
Right side.
ts: object(c_default="NULL") = _curses.ACS_HLINE
Top side.
bs: object(c_default="NULL") = _curses.ACS_HLINE
Bottom side.
tl: object(c_default="NULL") = _curses.ACS_ULCORNER
Upper-left corner.
tr: object(c_default="NULL") = _curses.ACS_URCORNER
Upper-right corner.
bl: object(c_default="NULL") = _curses.ACS_LLCORNER
Bottom-left corner.
br: object(c_default="NULL") = _curses.ACS_LRCORNER
Bottom-right corner.
/
Draw a border around the edges of the window.
Each parameter specifies the character to use for a specific part of the
border. The characters can be specified as integers or as one-character
strings. A 0 value for any parameter will cause the default character to be
used for that parameter.
[clinic start generated code]*/
static PyObject *
_curses_window_border_impl(PyCursesWindowObject *self, PyObject *ls,
PyObject *rs, PyObject *ts, PyObject *bs,
PyObject *tl, PyObject *tr, PyObject *bl,
PyObject *br)
/*[clinic end generated code: output=670ef38d3d7c2aa3 input=e015f735d67a240b]*/
{
chtype ch[8];
int i;
/* Clear the array of parameters */
for(i=0; i<8; i++)
ch[i] = 0;
#define CONVERTTOCHTYPE(obj, i) \
if ((obj) != NULL && !PyCurses_ConvertToChtype(self, (obj), &ch[(i)])) \
return NULL;
CONVERTTOCHTYPE(ls, 0);
CONVERTTOCHTYPE(rs, 1);
CONVERTTOCHTYPE(ts, 2);
CONVERTTOCHTYPE(bs, 3);
CONVERTTOCHTYPE(tl, 4);
CONVERTTOCHTYPE(tr, 5);
CONVERTTOCHTYPE(bl, 6);
CONVERTTOCHTYPE(br, 7);
#undef CONVERTTOCHTYPE
wborder(self->win,
ch[0], ch[1], ch[2], ch[3],
ch[4], ch[5], ch[6], ch[7]);
Py_RETURN_NONE;
}
/*[clinic input]
_curses.window.box
[
verch: object(c_default="_PyLong_GetZero()") = 0
Left and right side.
horch: object(c_default="_PyLong_GetZero()") = 0
Top and bottom side.
]
/
Draw a border around the edges of the window.
Similar to border(), but both ls and rs are verch and both ts and bs are
horch. The default corner characters are always used by this function.
[clinic start generated code]*/
static PyObject *
_curses_window_box_impl(PyCursesWindowObject *self, int group_right_1,
PyObject *verch, PyObject *horch)
/*[clinic end generated code: output=f3fcb038bb287192 input=f00435f9c8c98f60]*/
{
chtype ch1 = 0, ch2 = 0;
if (group_right_1) {
if (!PyCurses_ConvertToChtype(self, verch, &ch1)) {
return NULL;
}
if (!PyCurses_ConvertToChtype(self, horch, &ch2)) {
return NULL;
}
}
box(self->win,ch1,ch2);
Py_RETURN_NONE;
}
#if defined(HAVE_NCURSES_H) || defined(MVWDELCH_IS_EXPRESSION)
#define py_mvwdelch mvwdelch
#else
int py_mvwdelch(WINDOW *w, int y, int x)
{
mvwdelch(w,y,x);
/* On HP/UX, mvwdelch already returns. On other systems,
we may well run into this return statement. */
return 0;
}
#endif
#if defined(HAVE_CURSES_IS_PAD)
#define py_is_pad(win) is_pad(win)
#elif defined(WINDOW_HAS_FLAGS)
#define py_is_pad(win) ((win) ? ((win)->_flags & _ISPAD) != 0 : FALSE)
#endif
/* chgat, added by Fabian Kreutz <fabian.kreutz at gmx.net> */
#ifdef HAVE_CURSES_WCHGAT
/*[-clinic input]
_curses.window.chgat
[
y: int
Y-coordinate.
x: int
X-coordinate.
]
n: int = -1
Number of characters.
attr: long
Attributes for characters.
/
Set the attributes of characters.
Set the attributes of num characters at the current cursor position, or at
position (y, x) if supplied. If no value of num is given or num = -1, the
attribute will be set on all the characters to the end of the line. This
function does not move the cursor. The changed line will be touched using
the touchline() method so that the contents will be redisplayed by the next
window refresh.
[-clinic start generated code]*/
static PyObject *
PyCursesWindow_ChgAt(PyCursesWindowObject *self, PyObject *args)
{
int rtn;
int x, y;
int num = -1;
short color;
attr_t attr = A_NORMAL;
long lattr;
int use_xy = FALSE;
switch (PyTuple_Size(args)) {
case 1:
if (!PyArg_ParseTuple(args,"l;attr", &lattr))
return NULL;
attr = lattr;
break;
case 2:
if (!PyArg_ParseTuple(args,"il;n,attr", &num, &lattr))
return NULL;
attr = lattr;
break;
case 3:
if (!PyArg_ParseTuple(args,"iil;int,int,attr", &y, &x, &lattr))
return NULL;
attr = lattr;
use_xy = TRUE;
break;
case 4:
if (!PyArg_ParseTuple(args,"iiil;int,int,n,attr", &y, &x, &num, &lattr))
return NULL;
attr = lattr;
use_xy = TRUE;
break;
default:
PyErr_SetString(PyExc_TypeError, "chgat requires 1 to 4 arguments");
return NULL;
}
color = (short)((attr >> 8) & 0xff);
attr = attr - (color << 8);
if (use_xy) {
rtn = mvwchgat(self->win,y,x,num,attr,color,NULL);
touchline(self->win,y,1);
} else {
getyx(self->win,y,x);
rtn = wchgat(self->win,num,attr,color,NULL);
touchline(self->win,y,1);
}
return PyCursesCheckERR(rtn, "chgat");
}
#endif
/*[clinic input]
_curses.window.delch
[
y: int
Y-coordinate.
x: int
X-coordinate.
]
/
Delete any character at (y, x).
[clinic start generated code]*/
static PyObject *
_curses_window_delch_impl(PyCursesWindowObject *self, int group_right_1,
int y, int x)
/*[clinic end generated code: output=22e77bb9fa11b461 input=d2f79e630a4fc6d0]*/
{
if (!group_right_1) {
return PyCursesCheckERR(wdelch(self->win), "wdelch");
}
else {
return PyCursesCheckERR(py_mvwdelch(self->win, y, x), "mvwdelch");
}
}
/*[clinic input]
_curses.window.derwin
[
nlines: int = 0
Height.
ncols: int = 0
Width.
]
begin_y: int
Top side y-coordinate.
begin_x: int
Left side x-coordinate.
/
Create a sub-window (window-relative coordinates).
derwin() is the same as calling subwin(), except that begin_y and begin_x
are relative to the origin of the window, rather than relative to the entire
screen.
[clinic start generated code]*/
static PyObject *
_curses_window_derwin_impl(PyCursesWindowObject *self, int group_left_1,
int nlines, int ncols, int begin_y, int begin_x)
/*[clinic end generated code: output=7924b112d9f70d6e input=966d9481f7f5022e]*/
{
WINDOW *win;
win = derwin(self->win,nlines,ncols,begin_y,begin_x);
if (win == NULL) {
PyErr_SetString(PyCursesError, catchall_NULL);
return NULL;
}
return (PyObject *)PyCursesWindow_New(win, NULL);
}
/*[clinic input]
_curses.window.echochar
ch: object
Character to add.
attr: long(c_default="A_NORMAL") = _curses.A_NORMAL
Attributes for the character.
/
Add character ch with attribute attr, and refresh.
[clinic start generated code]*/
static PyObject *
_curses_window_echochar_impl(PyCursesWindowObject *self, PyObject *ch,
long attr)
/*[clinic end generated code: output=13e7dd875d4b9642 input=e7f34b964e92b156]*/
{
chtype ch_;
if (!PyCurses_ConvertToChtype(self, ch, &ch_))
return NULL;
#ifdef py_is_pad
if (py_is_pad(self->win)) {
return PyCursesCheckERR(pechochar(self->win, ch_ | (attr_t)attr),
"echochar");
}
else
#endif
return PyCursesCheckERR(wechochar(self->win, ch_ | (attr_t)attr),
"echochar");
}
#ifdef NCURSES_MOUSE_VERSION
/*[clinic input]
_curses.window.enclose -> long
y: int
Y-coordinate.
x: int
X-coordinate.
/
Return True if the screen-relative coordinates are enclosed by the window.
[clinic start generated code]*/
static long
_curses_window_enclose_impl(PyCursesWindowObject *self, int y, int x)
/*[clinic end generated code: output=5251c961cbe3df63 input=dfe1d9d4d05d8642]*/
{
return wenclose(self->win, y, x);
}
#endif
/*[clinic input]
_curses.window.getbkgd -> long
Return the window's current background character/attribute pair.
[clinic start generated code]*/
static long
_curses_window_getbkgd_impl(PyCursesWindowObject *self)
/*[clinic end generated code: output=c52b25dc16b215c3 input=a69db882fa35426c]*/
{
return (long) getbkgd(self->win);
}
/*[clinic input]
_curses.window.getch -> int
[
y: int
Y-coordinate.
x: int
X-coordinate.
]
/
Get a character code from terminal keyboard.
The integer returned does not have to be in ASCII range: function keys,
keypad keys and so on return numbers higher than 256. In no-delay mode, -1
is returned if there is no input, else getch() waits until a key is pressed.
[clinic start generated code]*/
static int
_curses_window_getch_impl(PyCursesWindowObject *self, int group_right_1,
int y, int x)
/*[clinic end generated code: output=980aa6af0c0ca387 input=bb24ebfb379f991f]*/
{
int rtn;
Py_BEGIN_ALLOW_THREADS
if (!group_right_1) {
rtn = wgetch(self->win);
}
else {
rtn = mvwgetch(self->win, y, x);
}
Py_END_ALLOW_THREADS
return rtn;
}
/*[clinic input]
_curses.window.getkey
[
y: int
Y-coordinate.
x: int
X-coordinate.
]
/
Get a character (string) from terminal keyboard.
Returning a string instead of an integer, as getch() does. Function keys,
keypad keys and other special keys return a multibyte string containing the
key name. In no-delay mode, an exception is raised if there is no input.
[clinic start generated code]*/
static PyObject *
_curses_window_getkey_impl(PyCursesWindowObject *self, int group_right_1,
int y, int x)
/*[clinic end generated code: output=8490a182db46b10f input=be2dee34f5cf57f8]*/
{
int rtn;
Py_BEGIN_ALLOW_THREADS
if (!group_right_1) {
rtn = wgetch(self->win);
}
else {
rtn = mvwgetch(self->win, y, x);
}
Py_END_ALLOW_THREADS
if (rtn == ERR) {
/* getch() returns ERR in nodelay mode */
PyErr_CheckSignals();
if (!PyErr_Occurred())
PyErr_SetString(PyCursesError, "no input");
return NULL;
} else if (rtn <= 255) {
#ifdef NCURSES_VERSION_MAJOR
#if NCURSES_VERSION_MAJOR*100+NCURSES_VERSION_MINOR <= 507
/* Work around a bug in ncurses 5.7 and earlier */
if (rtn < 0) {
rtn += 256;
}
#endif
#endif
return PyUnicode_FromOrdinal(rtn);
} else {
const char *knp = keyname(rtn);
return PyUnicode_FromString((knp == NULL) ? "" : knp);
}
}
#ifdef HAVE_NCURSESW
/*[clinic input]
_curses.window.get_wch
[
y: int
Y-coordinate.
x: int
X-coordinate.
]
/
Get a wide character from terminal keyboard.
Return a character for most keys, or an integer for function keys,
keypad keys, and other special keys.
[clinic start generated code]*/
static PyObject *
_curses_window_get_wch_impl(PyCursesWindowObject *self, int group_right_1,
int y, int x)
/*[clinic end generated code: output=9f4f86e91fe50ef3 input=dd7e5367fb49dc48]*/
{
int ct;
wint_t rtn;
Py_BEGIN_ALLOW_THREADS
if (!group_right_1) {
ct = wget_wch(self->win ,&rtn);
}
else {
ct = mvwget_wch(self->win, y, x, &rtn);
}
Py_END_ALLOW_THREADS
if (ct == ERR) {
if (PyErr_CheckSignals())
return NULL;
/* get_wch() returns ERR in nodelay mode */
PyErr_SetString(PyCursesError, "no input");
return NULL;
}
if (ct == KEY_CODE_YES)
return PyLong_FromLong(rtn);
else
return PyUnicode_FromOrdinal(rtn);
}
#endif
/*[-clinic input]
_curses.window.getstr
[
y: int
Y-coordinate.
x: int
X-coordinate.
]
n: int = 1023
Maximal number of characters.
/
Read a string from the user, with primitive line editing capacity.
[-clinic start generated code]*/
static PyObject *
PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args)
{
int x, y, n;
char rtn[1024]; /* This should be big enough.. I hope */
int rtn2;
switch (PyTuple_Size(args)) {
case 0:
Py_BEGIN_ALLOW_THREADS
rtn2 = wgetnstr(self->win,rtn, 1023);
Py_END_ALLOW_THREADS
break;
case 1:
if (!PyArg_ParseTuple(args,"i;n", &n))
return NULL;
if (n < 0) {
PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");
return NULL;
}
Py_BEGIN_ALLOW_THREADS
rtn2 = wgetnstr(self->win, rtn, Py_MIN(n, 1023));
Py_END_ALLOW_THREADS
break;
case 2:
if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
return NULL;
Py_BEGIN_ALLOW_THREADS
#ifdef STRICT_SYSV_CURSES
rtn2 = wmove(self->win,y,x)==ERR ? ERR : wgetnstr(self->win, rtn, 1023);
#else
rtn2 = mvwgetnstr(self->win,y,x,rtn, 1023);
#endif
Py_END_ALLOW_THREADS
break;
case 3:
if (!PyArg_ParseTuple(args,"iii;y,x,n", &y, &x, &n))
return NULL;
if (n < 0) {
PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");
return NULL;
}
#ifdef STRICT_SYSV_CURSES
Py_BEGIN_ALLOW_THREADS
rtn2 = wmove(self->win,y,x)==ERR ? ERR :
wgetnstr(self->win, rtn, Py_MIN(n, 1023));
Py_END_ALLOW_THREADS
#else
Py_BEGIN_ALLOW_THREADS
rtn2 = mvwgetnstr(self->win, y, x, rtn, Py_MIN(n, 1023));
Py_END_ALLOW_THREADS
#endif
break;
default:
PyErr_SetString(PyExc_TypeError, "getstr requires 0 to 3 arguments");
return NULL;
}
if (rtn2 == ERR)
rtn[0] = 0;
return PyBytes_FromString(rtn);
}
/*[clinic input]
_curses.window.hline
[
y: int
Starting Y-coordinate.
x: int
Starting X-coordinate.
]
ch: object
Character to draw.
n: int
Line length.
[
attr: long(c_default="A_NORMAL") = _curses.A_NORMAL
Attributes for the characters.
]
/
Display a horizontal line.
[clinic start generated code]*/
static PyObject *
_curses_window_hline_impl(PyCursesWindowObject *self, int group_left_1,
int y, int x, PyObject *ch, int n,
int group_right_1, long attr)
/*[clinic end generated code: output=c00d489d61fc9eef input=81a4dea47268163e]*/
{
chtype ch_;
if (!PyCurses_ConvertToChtype(self, ch, &ch_))
return NULL;
if (group_left_1) {
if (wmove(self->win, y, x) == ERR) {
return PyCursesCheckERR(ERR, "wmove");
}
}
return PyCursesCheckERR(whline(self->win, ch_ | (attr_t)attr, n), "hline");
}
/*[clinic input]
_curses.window.insch
[
y: int
Y-coordinate.
x: int
X-coordinate.
]
ch: object
Character to insert.
[
attr: long(c_default="A_NORMAL") = _curses.A_NORMAL
Attributes for the character.
]
/
Insert a character before the current or specified position.
All characters to the right of the cursor are shifted one position right, with
the rightmost characters on the line being lost.
[clinic start generated code]*/
static PyObject *
_curses_window_insch_impl(PyCursesWindowObject *self, int group_left_1,
int y, int x, PyObject *ch, int group_right_1,
long attr)
/*[clinic end generated code: output=ade8cfe3a3bf3e34 input=336342756ee19812]*/
{
int rtn;
chtype ch_ = 0;
if (!PyCurses_ConvertToChtype(self, ch, &ch_))
return NULL;
if (!group_left_1) {
rtn = winsch(self->win, ch_ | (attr_t)attr);
}
else {
rtn = mvwinsch(self->win, y, x, ch_ | (attr_t)attr);
}
return PyCursesCheckERR(rtn, "insch");
}
/*[clinic input]
_curses.window.inch -> unsigned_long
[
y: int
Y-coordinate.
x: int
X-coordinate.
]
/
Return the character at the given position in the window.
The bottom 8 bits are the character proper, and upper bits are the attributes.
[clinic start generated code]*/
static unsigned long
_curses_window_inch_impl(PyCursesWindowObject *self, int group_right_1,
int y, int x)
/*[clinic end generated code: output=6c4719fe978fe86a input=fac23ee11e3b3a66]*/
{
unsigned long rtn;
if (!group_right_1) {
rtn = winch(self->win);
}
else {
rtn = mvwinch(self->win, y, x);
}
return rtn;
}
/*[-clinic input]
_curses.window.instr
[
y: int
Y-coordinate.
x: int
X-coordinate.
]
n: int = 1023
Maximal number of characters.
/
Return a string of characters, extracted from the window.
Return a string of characters, extracted from the window starting at the
current cursor position, or at y, x if specified. Attributes are stripped
from the characters. If n is specified, instr() returns a string at most
n characters long (exclusive of the trailing NUL).
[-clinic start generated code]*/
static PyObject *
PyCursesWindow_InStr(PyCursesWindowObject *self, PyObject *args)
{
int x, y, n;
char rtn[1024]; /* This should be big enough.. I hope */
int rtn2;
switch (PyTuple_Size(args)) {
case 0:
rtn2 = winnstr(self->win,rtn, 1023);
break;
case 1:
if (!PyArg_ParseTuple(args,"i;n", &n))
return NULL;
if (n < 0) {
PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");
return NULL;
}
rtn2 = winnstr(self->win, rtn, Py_MIN(n, 1023));
break;
case 2:
if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
return NULL;
rtn2 = mvwinnstr(self->win,y,x,rtn,1023);
break;
case 3:
if (!PyArg_ParseTuple(args, "iii;y,x,n", &y, &x, &n))
return NULL;
if (n < 0) {
PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");
return NULL;
}
rtn2 = mvwinnstr(self->win, y, x, rtn, Py_MIN(n,1023));
break;
default:
PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments");
return NULL;
}
if (rtn2 == ERR)
rtn[0] = 0;
return PyBytes_FromString(rtn);
}
/*[clinic input]
_curses.window.insstr
[
y: int
Y-coordinate.
x: int
X-coordinate.
]
str: object
String to insert.
[
attr: long
Attributes for characters.
]
/
Insert the string before the current or specified position.
Insert a character string (as many characters as will fit on the line)
before the character under the cursor. All characters to the right of
the cursor are shifted right, with the rightmost characters on the line
being lost. The cursor position does not change (after moving to y, x,
if specified).
[clinic start generated code]*/
static PyObject *
_curses_window_insstr_impl(PyCursesWindowObject *self, int group_left_1,
int y, int x, PyObject *str, int group_right_1,
long attr)
/*[clinic end generated code: output=c259a5265ad0b777 input=6827cddc6340a7f3]*/
{
int rtn;
int strtype;
PyObject *bytesobj = NULL;
#ifdef HAVE_NCURSESW
wchar_t *wstr = NULL;
#endif
attr_t attr_old = A_NORMAL;
int use_xy = group_left_1, use_attr = group_right_1;
const char *funcname;
#ifdef HAVE_NCURSESW
strtype = PyCurses_ConvertToString(self, str, &bytesobj, &wstr);
#else
strtype = PyCurses_ConvertToString(self, str, &bytesobj, NULL);
#endif
if (strtype == 0)
return NULL;
if (use_attr) {
attr_old = getattrs(self->win);
(void)wattrset(self->win, (attr_t)attr);
}
#ifdef HAVE_NCURSESW
if (strtype == 2) {
funcname = "inswstr";
if (use_xy)
rtn = mvwins_wstr(self->win,y,x,wstr);
else
rtn = wins_wstr(self->win,wstr);
PyMem_Free(wstr);
}
else
#endif
{
const char *str = PyBytes_AS_STRING(bytesobj);
funcname = "insstr";
if (use_xy)
rtn = mvwinsstr(self->win,y,x,str);
else
rtn = winsstr(self->win,str);
Py_DECREF(bytesobj);
}
if (use_attr)
(void)wattrset(self->win,attr_old);
return PyCursesCheckERR(rtn, funcname);
}
/*[clinic input]
_curses.window.insnstr
[
y: int
Y-coordinate.
x: int
X-coordinate.
]
str: object
String to insert.
n: int
Maximal number of characters.
[
attr: long
Attributes for characters.
]
/
Insert at most n characters of the string.
Insert a character string (as many characters as will fit on the line)
before the character under the cursor, up to n characters. If n is zero
or negative, the entire string is inserted. All characters to the right
of the cursor are shifted right, with the rightmost characters on the line
being lost. The cursor position does not change (after moving to y, x, if
specified).
[clinic start generated code]*/
static PyObject *
_curses_window_insnstr_impl(PyCursesWindowObject *self, int group_left_1,
int y, int x, PyObject *str, int n,
int group_right_1, long attr)
/*[clinic end generated code: output=971a32ea6328ec8b input=70fa0cd543901a4c]*/
{
int rtn;
int strtype;
PyObject *bytesobj = NULL;
#ifdef HAVE_NCURSESW
wchar_t *wstr = NULL;
#endif
attr_t attr_old = A_NORMAL;
int use_xy = group_left_1, use_attr = group_right_1;
const char *funcname;
#ifdef HAVE_NCURSESW
strtype = PyCurses_ConvertToString(self, str, &bytesobj, &wstr);
#else
strtype = PyCurses_ConvertToString(self, str, &bytesobj, NULL);
#endif
if (strtype == 0)
return NULL;
if (use_attr) {
attr_old = getattrs(self->win);
(void)wattrset(self->win, (attr_t)attr);
}
#ifdef HAVE_NCURSESW
if (strtype == 2) {
funcname = "insn_wstr";
if (use_xy)
rtn = mvwins_nwstr(self->win,y,x,wstr,n);
else
rtn = wins_nwstr(self->win,wstr,n);
PyMem_Free(wstr);
}
else
#endif
{
const char *str = PyBytes_AS_STRING(bytesobj);
funcname = "insnstr";
if (use_xy)
rtn = mvwinsnstr(self->win,y,x,str,n);
else
rtn = winsnstr(self->win,str,n);
Py_DECREF(bytesobj);
}
if (use_attr)
(void)wattrset(self->win,attr_old);
return PyCursesCheckERR(rtn, funcname);
}
/*[clinic input]
_curses.window.is_linetouched
line: int
Line number.
/
Return True if the specified line was modified, otherwise return False.
Raise a curses.error exception if line is not valid for the given window.
[clinic start generated code]*/
static PyObject *
_curses_window_is_linetouched_impl(PyCursesWindowObject *self, int line)
/*[clinic end generated code: output=ad4a4edfee2db08c input=a7be0c189f243914]*/
{
int erg;
erg = is_linetouched(self->win, line);
if (erg == ERR) {
PyErr_SetString(PyExc_TypeError,
"is_linetouched: line number outside of boundaries");
return NULL;
}
return PyBool_FromLong(erg);
}
#ifdef py_is_pad
/*[clinic input]
_curses.window.noutrefresh
[
pminrow: int
pmincol: int
sminrow: int
smincol: int
smaxrow: int
smaxcol: int
]
/
Mark for refresh but wait.
This function updates the data structure representing the desired state of the
window, but does not force an update of the physical screen. To accomplish
that, call doupdate().
[clinic start generated code]*/
static PyObject *
_curses_window_noutrefresh_impl(PyCursesWindowObject *self,
int group_right_1, int pminrow, int pmincol,
int sminrow, int smincol, int smaxrow,
int smaxcol)
/*[clinic end generated code: output=809a1f3c6a03e23e input=3e56898388cd739e]*/
#else
/*[clinic input]
_curses.window.noutrefresh
Mark for refresh but wait.
This function updates the data structure representing the desired state of the
window, but does not force an update of the physical screen. To accomplish
that, call doupdate().
[clinic start generated code]*/
static PyObject *
_curses_window_noutrefresh_impl(PyCursesWindowObject *self)
/*[clinic end generated code: output=6ef6dec666643fee input=876902e3fa431dbd]*/
#endif
{
int rtn;
#ifdef py_is_pad
if (py_is_pad(self->win)) {
if (!group_right_1) {
PyErr_SetString(PyCursesError,
"noutrefresh() called for a pad "
"requires 6 arguments");
return NULL;
}
Py_BEGIN_ALLOW_THREADS
rtn = pnoutrefresh(self->win, pminrow, pmincol,
sminrow, smincol, smaxrow, smaxcol);
Py_END_ALLOW_THREADS
return PyCursesCheckERR(rtn, "pnoutrefresh");
}
if (group_right_1) {
PyErr_SetString(PyExc_TypeError,
"noutrefresh() takes no arguments (6 given)");
return NULL;
}
#endif
Py_BEGIN_ALLOW_THREADS
rtn = wnoutrefresh(self->win);
Py_END_ALLOW_THREADS
return PyCursesCheckERR(rtn, "wnoutrefresh");
}
/*[clinic input]
_curses.window.overlay
destwin: object(type="PyCursesWindowObject *", subclass_of="&PyCursesWindow_Type")
[
sminrow: int
smincol: int
dminrow: int
dmincol: int
dmaxrow: int
dmaxcol: int
]
/
Overlay the window on top of destwin.
The windows need not be the same size, only the overlapping region is copied.
This copy is non-destructive, which means that the current background
character does not overwrite the old contents of destwin.
To get fine-grained control over the copied region, the second form of
overlay() can be used. sminrow and smincol are the upper-left coordinates
of the source window, and the other variables mark a rectangle in the
destination window.
[clinic start generated code]*/
static PyObject *
_curses_window_overlay_impl(PyCursesWindowObject *self,
PyCursesWindowObject *destwin, int group_right_1,
int sminrow, int smincol, int dminrow,
int dmincol, int dmaxrow, int dmaxcol)
/*[clinic end generated code: output=82bb2c4cb443ca58 input=7edd23ad22cc1984]*/
{
int rtn;
if (group_right_1) {
rtn = copywin(self->win, destwin->win, sminrow, smincol,
dminrow, dmincol, dmaxrow, dmaxcol, TRUE);
return PyCursesCheckERR(rtn, "copywin");
}
else {
rtn = overlay(self->win, destwin->win);
return PyCursesCheckERR(rtn, "overlay");
}
}
/*[clinic input]
_curses.window.overwrite
destwin: object(type="PyCursesWindowObject *", subclass_of="&PyCursesWindow_Type")
[
sminrow: int
smincol: int
dminrow: int
dmincol: int
dmaxrow: int
dmaxcol: int
]
/
Overwrite the window on top of destwin.
The windows need not be the same size, in which case only the overlapping
region is copied. This copy is destructive, which means that the current
background character overwrites the old contents of destwin.
To get fine-grained control over the copied region, the second form of
overwrite() can be used. sminrow and smincol are the upper-left coordinates
of the source window, the other variables mark a rectangle in the destination
window.
[clinic start generated code]*/
static PyObject *
_curses_window_overwrite_impl(PyCursesWindowObject *self,
PyCursesWindowObject *destwin,
int group_right_1, int sminrow, int smincol,
int dminrow, int dmincol, int dmaxrow,
int dmaxcol)
/*[clinic end generated code: output=12ae007d1681be28 input=ea5de1b35cd948e0]*/
{
int rtn;
if (group_right_1) {
rtn = copywin(self->win, destwin->win, sminrow, smincol,
dminrow, dmincol, dmaxrow, dmaxcol, FALSE);
return PyCursesCheckERR(rtn, "copywin");
}
else {
rtn = overwrite(self->win, destwin->win);
return PyCursesCheckERR(rtn, "overwrite");
}
}
/*[clinic input]
_curses.window.putwin
file: object
/
Write all data associated with the window into the provided file object.
This information can be later retrieved using the getwin() function.
[clinic start generated code]*/
static PyObject *
_curses_window_putwin(PyCursesWindowObject *self, PyObject *file)
/*[clinic end generated code: output=3a25e2a5e7a040ac input=0608648e09c8ea0a]*/
{
/* We have to simulate this by writing to a temporary FILE*,
then reading back, then writing to the argument file. */
FILE *fp;
PyObject *res = NULL;
fp = tmpfile();
if (fp == NULL)
return PyErr_SetFromErrno(PyExc_OSError);
if (_Py_set_inheritable(fileno(fp), 0, NULL) < 0)
goto exit;
res = PyCursesCheckERR(putwin(self->win, fp), "putwin");
if (res == NULL)
goto exit;
fseek(fp, 0, 0);
while (1) {
char buf[BUFSIZ];
Py_ssize_t n = fread(buf, 1, BUFSIZ, fp);
_Py_IDENTIFIER(write);
if (n <= 0)
break;
Py_DECREF(res);
res = _PyObject_CallMethodId(file, &PyId_write, "y#", buf, n);
if (res == NULL)
break;
}
exit:
fclose(fp);
return res;
}
/*[clinic input]
_curses.window.redrawln
beg: int
Starting line number.
num: int
The number of lines.
/
Mark the specified lines corrupted.
They should be completely redrawn on the next refresh() call.
[clinic start generated code]*/
static PyObject *
_curses_window_redrawln_impl(PyCursesWindowObject *self, int beg, int num)
/*[clinic end generated code: output=ea216e334f9ce1b4 input=152155e258a77a7a]*/
{
return PyCursesCheckERR(wredrawln(self->win,beg,num), "redrawln");
}
/*[clinic input]
_curses.window.refresh
[
pminrow: int
pmincol: int
sminrow: int
smincol: int
smaxrow: int
smaxcol: int
]
/
Update the display immediately.
Synchronize actual screen with previous drawing/deleting methods.
The 6 optional arguments can only be specified when the window is a pad
created with newpad(). The additional parameters are needed to indicate
what part of the pad and screen are involved. pminrow and pmincol specify
the upper left-hand corner of the rectangle to be displayed in the pad.
sminrow, smincol, smaxrow, and smaxcol specify the edges of the rectangle to
be displayed on the screen. The lower right-hand corner of the rectangle to
be displayed in the pad is calculated from the screen coordinates, since the
rectangles must be the same size. Both rectangles must be entirely contained
within their respective structures. Negative values of pminrow, pmincol,
sminrow, or smincol are treated as if they were zero.
[clinic start generated code]*/
static PyObject *
_curses_window_refresh_impl(PyCursesWindowObject *self, int group_right_1,
int pminrow, int pmincol, int sminrow,
int smincol, int smaxrow, int smaxcol)
/*[clinic end generated code: output=42199543115e6e63 input=95e01cb5ffc635d0]*/
{
int rtn;
#ifdef py_is_pad
if (py_is_pad(self->win)) {
if (!group_right_1) {
PyErr_SetString(PyCursesError,
"refresh() for a pad requires 6 arguments");
return NULL;
}
Py_BEGIN_ALLOW_THREADS
rtn = prefresh(self->win, pminrow, pmincol,
sminrow, smincol, smaxrow, smaxcol);
Py_END_ALLOW_THREADS
return PyCursesCheckERR(rtn, "prefresh");
}
#endif
if (group_right_1) {
PyErr_SetString(PyExc_TypeError,
"refresh() takes no arguments (6 given)");
return NULL;
}
Py_BEGIN_ALLOW_THREADS
rtn = wrefresh(self->win);
Py_END_ALLOW_THREADS
return PyCursesCheckERR(rtn, "prefresh");
}
/*[clinic input]
_curses.window.setscrreg
top: int
First line number.
bottom: int
Last line number.
/
Define a software scrolling region.
All scrolling actions will take place in this region.
[clinic start generated code]*/
static PyObject *
_curses_window_setscrreg_impl(PyCursesWindowObject *self, int top,
int bottom)
/*[clinic end generated code: output=486ab5db218d2b1a input=1b517b986838bf0e]*/
{
return PyCursesCheckERR(wsetscrreg(self->win, top, bottom), "wsetscrreg");
}
/*[clinic input]
_curses.window.subwin
[
nlines: int = 0
Height.
ncols: int = 0
Width.
]
begin_y: int
Top side y-coordinate.
begin_x: int
Left side x-coordinate.
/
Create a sub-window (screen-relative coordinates).
By default, the sub-window will extend from the specified position to the
lower right corner of the window.
[clinic start generated code]*/
static PyObject *
_curses_window_subwin_impl(PyCursesWindowObject *self, int group_left_1,
int nlines, int ncols, int begin_y, int begin_x)
/*[clinic end generated code: output=93e898afc348f59a input=2129fa47fd57721c]*/
{
WINDOW *win;
/* printf("Subwin: %i %i %i %i \n", nlines, ncols, begin_y, begin_x); */
#ifdef py_is_pad
if (py_is_pad(self->win)) {
win = subpad(self->win, nlines, ncols, begin_y, begin_x);
}
else
#endif
win = subwin(self->win, nlines, ncols, begin_y, begin_x);
if (win == NULL) {
PyErr_SetString(PyCursesError, catchall_NULL);
return NULL;
}
return (PyObject *)PyCursesWindow_New(win, self->encoding);
}
/*[clinic input]
_curses.window.scroll
[
lines: int = 1
Number of lines to scroll.
]
/
Scroll the screen or scrolling region.
Scroll upward if the argument is positive and downward if it is negative.
[clinic start generated code]*/
static PyObject *
_curses_window_scroll_impl(PyCursesWindowObject *self, int group_right_1,
int lines)
/*[clinic end generated code: output=4541a8a11852d360 input=c969ca0cfabbdbec]*/
{
if (!group_right_1) {
return PyCursesCheckERR(scroll(self->win), "scroll");
}
else {
return PyCursesCheckERR(wscrl(self->win, lines), "scroll");
}
}
/*[clinic input]
_curses.window.touchline
start: int
count: int
[
changed: bool(accept={int}) = True
]
/
Pretend count lines have been changed, starting with line start.
If changed is supplied, it specifies whether the affected lines are marked
as having been changed (changed=True) or unchanged (changed=False).
[clinic start generated code]*/
static PyObject *
_curses_window_touchline_impl(PyCursesWindowObject *self, int start,
int count, int group_right_1, int changed)
/*[clinic end generated code: output=65d05b3f7438c61d input=918ad1cbdadf93ea]*/
{
if (!group_right_1) {
return PyCursesCheckERR(touchline(self->win, start, count), "touchline");
}
else {
return PyCursesCheckERR(wtouchln(self->win, start, count, changed), "touchline");
}
}
/*[clinic input]
_curses.window.vline
[
y: int
Starting Y-coordinate.
x: int
Starting X-coordinate.
]
ch: object
Character to draw.
n: int
Line length.
[
attr: long(c_default="A_NORMAL") = _curses.A_NORMAL
Attributes for the character.
]
/
Display a vertical line.
[clinic start generated code]*/
static PyObject *
_curses_window_vline_impl(PyCursesWindowObject *self, int group_left_1,
int y, int x, PyObject *ch, int n,
int group_right_1, long attr)
/*[clinic end generated code: output=287ad1cc8982217f input=a6f2dc86a4648b32]*/
{
chtype ch_;
if (!PyCurses_ConvertToChtype(self, ch, &ch_))
return NULL;
if (group_left_1) {
if (wmove(self->win, y, x) == ERR)
return PyCursesCheckERR(ERR, "wmove");
}
return PyCursesCheckERR(wvline(self->win, ch_ | (attr_t)attr, n), "vline");
}
static PyObject *
PyCursesWindow_get_encoding(PyCursesWindowObject *self, void *closure)
{
return PyUnicode_FromString(self->encoding);
}
static int
PyCursesWindow_set_encoding(PyCursesWindowObject *self, PyObject *value, void *Py_UNUSED(ignored))
{
PyObject *ascii;
char *encoding;
/* It is illegal to del win.encoding */
if (value == NULL) {
PyErr_SetString(PyExc_TypeError,
"encoding may not be deleted");
return -1;
}
if (!PyUnicode_Check(value)) {
PyErr_SetString(PyExc_TypeError,
"setting encoding to a non-string");
return -1;
}
ascii = PyUnicode_AsASCIIString(value);
if (ascii == NULL)
return -1;
encoding = _PyMem_Strdup(PyBytes_AS_STRING(ascii));
Py_DECREF(ascii);
if (encoding == NULL) {
PyErr_NoMemory();
return -1;
}
PyMem_Free(self->encoding);
self->encoding = encoding;
return 0;
}
#include "clinic/_cursesmodule.c.h"
static PyMethodDef PyCursesWindow_Methods[] = {
_CURSES_WINDOW_ADDCH_METHODDEF
_CURSES_WINDOW_ADDNSTR_METHODDEF
_CURSES_WINDOW_ADDSTR_METHODDEF
_CURSES_WINDOW_ATTROFF_METHODDEF
_CURSES_WINDOW_ATTRON_METHODDEF
_CURSES_WINDOW_ATTRSET_METHODDEF
_CURSES_WINDOW_BKGD_METHODDEF
#ifdef HAVE_CURSES_WCHGAT
{"chgat", (PyCFunction)PyCursesWindow_ChgAt, METH_VARARGS},
#endif
_CURSES_WINDOW_BKGDSET_METHODDEF
_CURSES_WINDOW_BORDER_METHODDEF
_CURSES_WINDOW_BOX_METHODDEF
{"clear", (PyCFunction)PyCursesWindow_wclear, METH_NOARGS},
{"clearok", (PyCFunction)PyCursesWindow_clearok, METH_VARARGS},
{"clrtobot", (PyCFunction)PyCursesWindow_wclrtobot, METH_NOARGS},
{"clrtoeol", (PyCFunction)PyCursesWindow_wclrtoeol, METH_NOARGS},
{"cursyncup", (PyCFunction)PyCursesWindow_wcursyncup, METH_NOARGS},
_CURSES_WINDOW_DELCH_METHODDEF
{"deleteln", (PyCFunction)PyCursesWindow_wdeleteln, METH_NOARGS},
_CURSES_WINDOW_DERWIN_METHODDEF
_CURSES_WINDOW_ECHOCHAR_METHODDEF
_CURSES_WINDOW_ENCLOSE_METHODDEF
{"erase", (PyCFunction)PyCursesWindow_werase, METH_NOARGS},
{"getbegyx", (PyCFunction)PyCursesWindow_getbegyx, METH_NOARGS},
_CURSES_WINDOW_GETBKGD_METHODDEF
_CURSES_WINDOW_GETCH_METHODDEF
_CURSES_WINDOW_GETKEY_METHODDEF
_CURSES_WINDOW_GET_WCH_METHODDEF
{"getmaxyx", (PyCFunction)PyCursesWindow_getmaxyx, METH_NOARGS},
{"getparyx", (PyCFunction)PyCursesWindow_getparyx, METH_NOARGS},
{"getstr", (PyCFunction)PyCursesWindow_GetStr, METH_VARARGS},
{"getyx", (PyCFunction)PyCursesWindow_getyx, METH_NOARGS},
_CURSES_WINDOW_HLINE_METHODDEF
{"idcok", (PyCFunction)PyCursesWindow_idcok, METH_VARARGS},
{"idlok", (PyCFunction)PyCursesWindow_idlok, METH_VARARGS},
#ifdef HAVE_CURSES_IMMEDOK
{"immedok", (PyCFunction)PyCursesWindow_immedok, METH_VARARGS},
#endif
_CURSES_WINDOW_INCH_METHODDEF
_CURSES_WINDOW_INSCH_METHODDEF
{"insdelln", (PyCFunction)PyCursesWindow_winsdelln, METH_VARARGS},
{"insertln", (PyCFunction)PyCursesWindow_winsertln, METH_NOARGS},
_CURSES_WINDOW_INSNSTR_METHODDEF
_CURSES_WINDOW_INSSTR_METHODDEF
{"instr", (PyCFunction)PyCursesWindow_InStr, METH_VARARGS},
_CURSES_WINDOW_IS_LINETOUCHED_METHODDEF
{"is_wintouched", (PyCFunction)PyCursesWindow_is_wintouched, METH_NOARGS},
{"keypad", (PyCFunction)PyCursesWindow_keypad, METH_VARARGS},
{"leaveok", (PyCFunction)PyCursesWindow_leaveok, METH_VARARGS},
{"move", (PyCFunction)PyCursesWindow_wmove, METH_VARARGS},
{"mvderwin", (PyCFunction)PyCursesWindow_mvderwin, METH_VARARGS},
{"mvwin", (PyCFunction)PyCursesWindow_mvwin, METH_VARARGS},
{"nodelay", (PyCFunction)PyCursesWindow_nodelay, METH_VARARGS},
{"notimeout", (PyCFunction)PyCursesWindow_notimeout, METH_VARARGS},
_CURSES_WINDOW_NOUTREFRESH_METHODDEF
_CURSES_WINDOW_OVERLAY_METHODDEF
_CURSES_WINDOW_OVERWRITE_METHODDEF
_CURSES_WINDOW_PUTWIN_METHODDEF
_CURSES_WINDOW_REDRAWLN_METHODDEF
{"redrawwin", (PyCFunction)PyCursesWindow_redrawwin, METH_NOARGS},
_CURSES_WINDOW_REFRESH_METHODDEF
#ifndef STRICT_SYSV_CURSES
{"resize", (PyCFunction)PyCursesWindow_wresize, METH_VARARGS},
#endif
_CURSES_WINDOW_SCROLL_METHODDEF
{"scrollok", (PyCFunction)PyCursesWindow_scrollok, METH_VARARGS},
_CURSES_WINDOW_SETSCRREG_METHODDEF
{"standend", (PyCFunction)PyCursesWindow_wstandend, METH_NOARGS},
{"standout", (PyCFunction)PyCursesWindow_wstandout, METH_NOARGS},
{"subpad", (PyCFunction)_curses_window_subwin, METH_VARARGS, _curses_window_subwin__doc__},
_CURSES_WINDOW_SUBWIN_METHODDEF
{"syncdown", (PyCFunction)PyCursesWindow_wsyncdown, METH_NOARGS},
#ifdef HAVE_CURSES_SYNCOK
{"syncok", (PyCFunction)PyCursesWindow_syncok, METH_VARARGS},
#endif
{"syncup", (PyCFunction)PyCursesWindow_wsyncup, METH_NOARGS},
{"timeout", (PyCFunction)PyCursesWindow_wtimeout, METH_VARARGS},
_CURSES_WINDOW_TOUCHLINE_METHODDEF
{"touchwin", (PyCFunction)PyCursesWindow_touchwin, METH_NOARGS},
{"untouchwin", (PyCFunction)PyCursesWindow_untouchwin, METH_NOARGS},
_CURSES_WINDOW_VLINE_METHODDEF
{NULL, NULL} /* sentinel */
};
static PyGetSetDef PyCursesWindow_getsets[] = {
{"encoding",
(getter)PyCursesWindow_get_encoding,
(setter)PyCursesWindow_set_encoding,
"the typecode character used to create the array"},
{NULL, NULL, NULL, NULL } /* sentinel */
};
/* -------------------------------------------------------*/
PyTypeObject PyCursesWindow_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
"_curses.window", /*tp_name*/
sizeof(PyCursesWindowObject), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
(destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/
0, /*tp_vectorcall_offset*/
(getattrfunc)0, /*tp_getattr*/
(setattrfunc)0, /*tp_setattr*/
0, /*tp_as_async*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash*/
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT, /*tp_flags*/
0, /*tp_doc*/
0, /*tp_traverse*/
0, /*tp_clear*/
0, /*tp_richcompare*/
0, /*tp_weaklistoffset*/
0, /*tp_iter*/
0, /*tp_iternext*/
PyCursesWindow_Methods, /*tp_methods*/
0, /* tp_members */
PyCursesWindow_getsets, /* tp_getset */
};
/* Function Prototype Macros - They are ugly but very, very useful. ;-)
X - function name
TYPE - parameter Type
ERGSTR - format string for construction of the return value
PARSESTR - format string for argument parsing
*/
#define NoArgNoReturnFunctionBody(X) \
{ \
PyCursesInitialised \
return PyCursesCheckERR(X(), # X); }
#define NoArgOrFlagNoReturnFunctionBody(X, flag) \
{ \
PyCursesInitialised \
if (flag) \
return PyCursesCheckERR(X(), # X); \
else \
return PyCursesCheckERR(no ## X(), # X); \
}
#define NoArgReturnIntFunctionBody(X) \
{ \
PyCursesInitialised \
return PyLong_FromLong((long) X()); }
#define NoArgReturnStringFunctionBody(X) \
{ \
PyCursesInitialised \
return PyBytes_FromString(X()); }
#define NoArgTrueFalseFunctionBody(X) \
{ \
PyCursesInitialised \
return PyBool_FromLong(X()); }
#define NoArgNoReturnVoidFunctionBody(X) \
{ \
PyCursesInitialised \
X(); \
Py_RETURN_NONE; }
/*********************************************************************
Global Functions
**********************************************************************/
#ifdef HAVE_CURSES_FILTER
/*[clinic input]
_curses.filter
[clinic start generated code]*/
static PyObject *
_curses_filter_impl(PyObject *module)
/*[clinic end generated code: output=fb5b8a3642eb70b5 input=668c75a6992d3624]*/
{
/* not checking for PyCursesInitialised here since filter() must
be called before initscr() */
filter();
Py_RETURN_NONE;
}
#endif
/*[clinic input]
_curses.baudrate
Return the output speed of the terminal in bits per second.
[clinic start generated code]*/
static PyObject *
_curses_baudrate_impl(PyObject *module)
/*[clinic end generated code: output=3c63c6c401d7d9c0 input=921f022ed04a0fd9]*/
NoArgReturnIntFunctionBody(baudrate)
/*[clinic input]
_curses.beep
Emit a short attention sound.
[clinic start generated code]*/
static PyObject *
_curses_beep_impl(PyObject *module)
/*[clinic end generated code: output=425274962abe49a2 input=a35698ca7d0162bc]*/
NoArgNoReturnFunctionBody(beep)
/*[clinic input]
_curses.can_change_color
Return True if the programmer can change the colors displayed by the terminal.
[clinic start generated code]*/
static PyObject *
_curses_can_change_color_impl(PyObject *module)
/*[clinic end generated code: output=359df8c3c77d8bf1 input=d7718884de0092f2]*/
NoArgTrueFalseFunctionBody(can_change_color)
/*[clinic input]
_curses.cbreak
flag: bool(accept={int}) = True
If false, the effect is the same as calling nocbreak().
/
Enter cbreak mode.
In cbreak mode (sometimes called "rare" mode) normal tty line buffering is
turned off and characters are available to be read one by one. However,
unlike raw mode, special characters (interrupt, quit, suspend, and flow
control) retain their effects on the tty driver and calling program.
Calling first raw() then cbreak() leaves the terminal in cbreak mode.
[clinic start generated code]*/
static PyObject *
_curses_cbreak_impl(PyObject *module, int flag)
/*[clinic end generated code: output=9f9dee9664769751 input=150be619eb1f1458]*/
NoArgOrFlagNoReturnFunctionBody(cbreak, flag)
/*[clinic input]
_curses.color_content
color_number: color
The number of the color (0 - COLORS).
/
Return the red, green, and blue (RGB) components of the specified color.
A 3-tuple is returned, containing the R, G, B values for the given color,
which will be between 0 (no component) and 1000 (maximum amount of component).
[clinic start generated code]*/
static PyObject *
_curses_color_content_impl(PyObject *module, int color_number)
/*[clinic end generated code: output=17b466df7054e0de input=c10ef58f694b13ee]*/
{
_NCURSES_COLOR_VAL_TYPE r,g,b;
PyCursesInitialised;
PyCursesInitialisedColor;
if (_COLOR_CONTENT_FUNC(color_number, &r, &g, &b) != ERR)
return Py_BuildValue("(iii)", r, g, b);
else {
PyErr_SetString(PyCursesError,
"Argument 1 was out of range. Check value of COLORS.");
return NULL;
}
}
/*[clinic input]
_curses.color_pair
color_number: color
The number of the color (0 - COLORS).
/
Return the attribute value for displaying text in the specified color.
This attribute value can be combined with A_STANDOUT, A_REVERSE, and the
other A_* attributes. pair_number() is the counterpart to this function.
[clinic start generated code]*/
static PyObject *
_curses_color_pair_impl(PyObject *module, int color_number)
/*[clinic end generated code: output=3fd752e8e24c93fb input=b049033819ab4ef5]*/
{
PyCursesInitialised;
PyCursesInitialisedColor;
return PyLong_FromLong(color_pair_to_attr(color_number));
}
/*[clinic input]
_curses.curs_set
visibility: int
0 for invisible, 1 for normal visible, or 2 for very visible.
/
Set the cursor state.
If the terminal supports the visibility requested, the previous cursor
state is returned; otherwise, an exception is raised. On many terminals,
the "visible" mode is an underline cursor and the "very visible" mode is
a block cursor.
[clinic start generated code]*/
static PyObject *
_curses_curs_set_impl(PyObject *module, int visibility)
/*[clinic end generated code: output=ee8e62483b1d6cd4 input=81a7924a65d29504]*/
{
int erg;
PyCursesInitialised;
erg = curs_set(visibility);
if (erg == ERR) return PyCursesCheckERR(erg, "curs_set");
return PyLong_FromLong((long) erg);
}
/*[clinic input]
_curses.def_prog_mode
Save the current terminal mode as the "program" mode.
The "program" mode is the mode when the running program is using curses.
Subsequent calls to reset_prog_mode() will restore this mode.
[clinic start generated code]*/
static PyObject *
_curses_def_prog_mode_impl(PyObject *module)
/*[clinic end generated code: output=05d5a351fff874aa input=768b9cace620dda5]*/
NoArgNoReturnFunctionBody(def_prog_mode)
/*[clinic input]
_curses.def_shell_mode
Save the current terminal mode as the "shell" mode.
The "shell" mode is the mode when the running program is not using curses.
Subsequent calls to reset_shell_mode() will restore this mode.
[clinic start generated code]*/
static PyObject *
_curses_def_shell_mode_impl(PyObject *module)
/*[clinic end generated code: output=d6e42f5c768f860f input=5ead21f6f0baa894]*/
NoArgNoReturnFunctionBody(def_shell_mode)
/*[clinic input]
_curses.delay_output
ms: int
Duration in milliseconds.
/
Insert a pause in output.
[clinic start generated code]*/
static PyObject *
_curses_delay_output_impl(PyObject *module, int ms)
/*[clinic end generated code: output=b6613a67f17fa4f4 input=5316457f5f59196c]*/
{
PyCursesInitialised;
return PyCursesCheckERR(delay_output(ms), "delay_output");
}
/*[clinic input]
_curses.doupdate
Update the physical screen to match the virtual screen.
[clinic start generated code]*/
static PyObject *
_curses_doupdate_impl(PyObject *module)
/*[clinic end generated code: output=f34536975a75680c input=8da80914432a6489]*/
NoArgNoReturnFunctionBody(doupdate)
/*[clinic input]
_curses.echo
flag: bool(accept={int}) = True
If false, the effect is the same as calling noecho().
/
Enter echo mode.
In echo mode, each character input is echoed to the screen as it is entered.
[clinic start generated code]*/
static PyObject *
_curses_echo_impl(PyObject *module, int flag)
/*[clinic end generated code: output=03acb2ddfa6c8729 input=2e9e891d637eac5d]*/
NoArgOrFlagNoReturnFunctionBody(echo, flag)
/*[clinic input]
_curses.endwin
De-initialize the library, and return terminal to normal status.
[clinic start generated code]*/
static PyObject *
_curses_endwin_impl(PyObject *module)
/*[clinic end generated code: output=c0150cd96d2f4128 input=e172cfa43062f3fa]*/
NoArgNoReturnFunctionBody(endwin)
/*[clinic input]
_curses.erasechar
Return the user's current erase character.
[clinic start generated code]*/
static PyObject *
_curses_erasechar_impl(PyObject *module)
/*[clinic end generated code: output=3df305dc6b926b3f input=628c136c3c5758d3]*/
{
char ch;
PyCursesInitialised;
ch = erasechar();
return PyBytes_FromStringAndSize(&ch, 1);
}
/*[clinic input]
_curses.flash
Flash the screen.
That is, change it to reverse-video and then change it back in a short interval.
[clinic start generated code]*/
static PyObject *
_curses_flash_impl(PyObject *module)
/*[clinic end generated code: output=488b8a0ebd9ea9b8 input=02fdfb06c8fc3171]*/
NoArgNoReturnFunctionBody(flash)
/*[clinic input]
_curses.flushinp
Flush all input buffers.
This throws away any typeahead that has been typed by the user and has not
yet been processed by the program.
[clinic start generated code]*/
static PyObject *
_curses_flushinp_impl(PyObject *module)
/*[clinic end generated code: output=7e7a1fc1473960f5 input=59d042e705cef5ec]*/
NoArgNoReturnVoidFunctionBody(flushinp)
#ifdef getsyx
/*[clinic input]
_curses.getsyx
Return the current coordinates of the virtual screen cursor.
Return a (y, x) tuple. If leaveok is currently true, return (-1, -1).
[clinic start generated code]*/
static PyObject *
_curses_getsyx_impl(PyObject *module)
/*[clinic end generated code: output=c8e6c3f42349a038 input=9e1f862f3b4f7cba]*/
{
int x = 0;
int y = 0;
PyCursesInitialised;
getsyx(y, x);
return Py_BuildValue("(ii)", y, x);
}
#endif
#ifdef NCURSES_MOUSE_VERSION
/*[clinic input]
_curses.getmouse
Retrieve the queued mouse event.
After getch() returns KEY_MOUSE to signal a mouse event, this function
returns a 5-tuple (id, x, y, z, bstate).
[clinic start generated code]*/
static PyObject *
_curses_getmouse_impl(PyObject *module)
/*[clinic end generated code: output=ccf4242546b9cfa8 input=5b756ee6f5b481b1]*/
{
int rtn;
MEVENT event;
PyCursesInitialised;
rtn = getmouse( &event );
if (rtn == ERR) {
PyErr_SetString(PyCursesError, "getmouse() returned ERR");
return NULL;
}
return Py_BuildValue("(hiiik)",
(short)event.id,
(int)event.x, (int)event.y, (int)event.z,
(unsigned long) event.bstate);
}
/*[clinic input]
_curses.ungetmouse
id: short
x: int
y: int
z: int
bstate: unsigned_long(bitwise=True)
/
Push a KEY_MOUSE event onto the input queue.
The following getmouse() will return the given state data.
[clinic start generated code]*/
static PyObject *
_curses_ungetmouse_impl(PyObject *module, short id, int x, int y, int z,
unsigned long bstate)
/*[clinic end generated code: output=3430c9b0fc5c4341 input=fd650b2ca5a01e8f]*/
{
MEVENT event;
PyCursesInitialised;
event.id = id;
event.x = x;
event.y = y;
event.z = z;
event.bstate = bstate;
return PyCursesCheckERR(ungetmouse(&event), "ungetmouse");
}
#endif
/*[clinic input]
_curses.getwin
file: object
/
Read window related data stored in the file by an earlier putwin() call.
The routine then creates and initializes a new window using that data,
returning the new window object.
[clinic start generated code]*/
static PyObject *
_curses_getwin(PyObject *module, PyObject *file)
/*[clinic end generated code: output=a79e0df3379af756 input=f713d2bba0e4c929]*/
{
FILE *fp;
PyObject *data;
size_t datalen;
WINDOW *win;
_Py_IDENTIFIER(read);
PyObject *res = NULL;
PyCursesInitialised;
fp = tmpfile();
if (fp == NULL)
return PyErr_SetFromErrno(PyExc_OSError);
if (_Py_set_inheritable(fileno(fp), 0, NULL) < 0)
goto error;
data = _PyObject_CallMethodIdNoArgs(file, &PyId_read);
if (data == NULL)
goto error;
if (!PyBytes_Check(data)) {
PyErr_Format(PyExc_TypeError,
"f.read() returned %.100s instead of bytes",
Py_TYPE(data)->tp_name);
Py_DECREF(data);
goto error;
}
datalen = PyBytes_GET_SIZE(data);
if (fwrite(PyBytes_AS_STRING(data), 1, datalen, fp) != datalen) {
Py_DECREF(data);
PyErr_SetFromErrno(PyExc_OSError);
goto error;
}
Py_DECREF(data);
fseek(fp, 0, 0);
win = getwin(fp);
if (win == NULL) {
PyErr_SetString(PyCursesError, catchall_NULL);
goto error;
}
res = PyCursesWindow_New(win, NULL);
error:
fclose(fp);
return res;
}
/*[clinic input]
_curses.halfdelay
tenths: byte
Maximal blocking delay in tenths of seconds (1 - 255).
/
Enter half-delay mode.
Use nocbreak() to leave half-delay mode.
[clinic start generated code]*/
static PyObject *
_curses_halfdelay_impl(PyObject *module, unsigned char tenths)
/*[clinic end generated code: output=e92cdf0ef33c0663 input=e42dce7259c15100]*/
{
PyCursesInitialised;
return PyCursesCheckERR(halfdelay(tenths), "halfdelay");
}
/*[clinic input]
_curses.has_colors
Return True if the terminal can display colors; otherwise, return False.
[clinic start generated code]*/
static PyObject *
_curses_has_colors_impl(PyObject *module)
/*[clinic end generated code: output=db5667483139e3e2 input=b2ec41b739d896c6]*/
NoArgTrueFalseFunctionBody(has_colors)
/*[clinic input]
_curses.has_ic
Return True if the terminal has insert- and delete-character capabilities.
[clinic start generated code]*/
static PyObject *
_curses_has_ic_impl(PyObject *module)
/*[clinic end generated code: output=6be24da9cb1268fe input=9bc2d3a797cc7324]*/
NoArgTrueFalseFunctionBody(has_ic)
/*[clinic input]
_curses.has_il
Return True if the terminal has insert- and delete-line capabilities.
[clinic start generated code]*/
static PyObject *
_curses_has_il_impl(PyObject *module)
/*[clinic end generated code: output=d45bd7788ff9f5f4 input=cd939d5607ee5427]*/
NoArgTrueFalseFunctionBody(has_il)
#ifdef HAVE_CURSES_HAS_KEY
/*[clinic input]
_curses.has_key
key: int
Key number.
/
Return True if the current terminal type recognizes a key with that value.
[clinic start generated code]*/
static PyObject *
_curses_has_key_impl(PyObject *module, int key)
/*[clinic end generated code: output=19ad48319414d0b1 input=78bd44acf1a4997c]*/
{
PyCursesInitialised;
return PyBool_FromLong(has_key(key));
}
#endif
/*[clinic input]
_curses.init_color
color_number: color
The number of the color to be changed (0 - COLORS).
r: component
Red component (0 - 1000).
g: component
Green component (0 - 1000).
b: component
Blue component (0 - 1000).
/
Change the definition of a color.
When init_color() is used, all occurrences of that color on the screen
immediately change to the new definition. This function is a no-op on
most terminals; it is active only if can_change_color() returns 1.
[clinic start generated code]*/
static PyObject *
_curses_init_color_impl(PyObject *module, int color_number, short r, short g,
short b)
/*[clinic end generated code: output=d7ed71b2d818cdf2 input=8a2fe94ca9204aa5]*/
{
PyCursesInitialised;
PyCursesInitialisedColor;
return PyCursesCheckERR(_CURSES_INIT_COLOR_FUNC(color_number, r, g, b), _CURSES_INIT_COLOR_FUNC_NAME);
}
/*[clinic input]
_curses.init_pair
pair_number: pair
The number of the color-pair to be changed (1 - (COLOR_PAIRS-1)).
fg: color
Foreground color number (0 - COLORS).
bg: color
Background color number (0 - COLORS).
/
Change the definition of a color-pair.
If the color-pair was previously initialized, the screen is refreshed and
all occurrences of that color-pair are changed to the new definition.
[clinic start generated code]*/
static PyObject *
_curses_init_pair_impl(PyObject *module, int pair_number, int fg, int bg)
/*[clinic end generated code: output=a0bba03d2bbc3ee6 input=b865583a18061c1f]*/
{
PyCursesInitialised;
PyCursesInitialisedColor;
return PyCursesCheckERR(_CURSES_INIT_PAIR_FUNC(pair_number, fg, bg), _CURSES_INIT_PAIR_FUNC_NAME);
}
static PyObject *ModDict;
/*[clinic input]
_curses.initscr
Initialize the library.
Return a WindowObject which represents the whole screen.
[clinic start generated code]*/
static PyObject *
_curses_initscr_impl(PyObject *module)
/*[clinic end generated code: output=619fb68443810b7b input=514f4bce1821f6b5]*/
{
WINDOW *win;
PyCursesWindowObject *winobj;
if (initialised) {
wrefresh(stdscr);
return (PyObject *)PyCursesWindow_New(stdscr, NULL);
}
win = initscr();
if (win == NULL) {
PyErr_SetString(PyCursesError, catchall_NULL);
return NULL;
}
initialised = initialised_setupterm = TRUE;
/* This was moved from initcurses() because it core dumped on SGI,
where they're not defined until you've called initscr() */
#define SetDictInt(string,ch) \
do { \
PyObject *o = PyLong_FromLong((long) (ch)); \
if (o && PyDict_SetItemString(ModDict, string, o) == 0) { \
Py_DECREF(o); \
} \
} while (0)
/* Here are some graphic symbols you can use */
SetDictInt("ACS_ULCORNER", (ACS_ULCORNER));
SetDictInt("ACS_LLCORNER", (ACS_LLCORNER));
SetDictInt("ACS_URCORNER", (ACS_URCORNER));
SetDictInt("ACS_LRCORNER", (ACS_LRCORNER));
SetDictInt("ACS_LTEE", (ACS_LTEE));
SetDictInt("ACS_RTEE", (ACS_RTEE));
SetDictInt("ACS_BTEE", (ACS_BTEE));
SetDictInt("ACS_TTEE", (ACS_TTEE));
SetDictInt("ACS_HLINE", (ACS_HLINE));
SetDictInt("ACS_VLINE", (ACS_VLINE));
SetDictInt("ACS_PLUS", (ACS_PLUS));
#if !defined(__hpux) || defined(HAVE_NCURSES_H)
/* On HP/UX 11, these are of type cchar_t, which is not an
integral type. If this is a problem on more platforms, a
configure test should be added to determine whether ACS_S1
is of integral type. */
SetDictInt("ACS_S1", (ACS_S1));
SetDictInt("ACS_S9", (ACS_S9));
SetDictInt("ACS_DIAMOND", (ACS_DIAMOND));
SetDictInt("ACS_CKBOARD", (ACS_CKBOARD));
SetDictInt("ACS_DEGREE", (ACS_DEGREE));
SetDictInt("ACS_PLMINUS", (ACS_PLMINUS));
SetDictInt("ACS_BULLET", (ACS_BULLET));
SetDictInt("ACS_LARROW", (ACS_LARROW));
SetDictInt("ACS_RARROW", (ACS_RARROW));
SetDictInt("ACS_DARROW", (ACS_DARROW));
SetDictInt("ACS_UARROW", (ACS_UARROW));
SetDictInt("ACS_BOARD", (ACS_BOARD));
SetDictInt("ACS_LANTERN", (ACS_LANTERN));
SetDictInt("ACS_BLOCK", (ACS_BLOCK));
#endif
SetDictInt("ACS_BSSB", (ACS_ULCORNER));
SetDictInt("ACS_SSBB", (ACS_LLCORNER));
SetDictInt("ACS_BBSS", (ACS_URCORNER));
SetDictInt("ACS_SBBS", (ACS_LRCORNER));
SetDictInt("ACS_SBSS", (ACS_RTEE));
SetDictInt("ACS_SSSB", (ACS_LTEE));
SetDictInt("ACS_SSBS", (ACS_BTEE));
SetDictInt("ACS_BSSS", (ACS_TTEE));
SetDictInt("ACS_BSBS", (ACS_HLINE));
SetDictInt("ACS_SBSB", (ACS_VLINE));
SetDictInt("ACS_SSSS", (ACS_PLUS));
/* The following are never available with strict SYSV curses */
#ifdef ACS_S3
SetDictInt("ACS_S3", (ACS_S3));
#endif
#ifdef ACS_S7
SetDictInt("ACS_S7", (ACS_S7));
#endif
#ifdef ACS_LEQUAL
SetDictInt("ACS_LEQUAL", (ACS_LEQUAL));
#endif
#ifdef ACS_GEQUAL
SetDictInt("ACS_GEQUAL", (ACS_GEQUAL));
#endif
#ifdef ACS_PI
SetDictInt("ACS_PI", (ACS_PI));
#endif
#ifdef ACS_NEQUAL
SetDictInt("ACS_NEQUAL", (ACS_NEQUAL));
#endif
#ifdef ACS_STERLING
SetDictInt("ACS_STERLING", (ACS_STERLING));
#endif
SetDictInt("LINES", LINES);
SetDictInt("COLS", COLS);
winobj = (PyCursesWindowObject *)PyCursesWindow_New(win, NULL);
screen_encoding = winobj->encoding;
return (PyObject *)winobj;
}
/*[clinic input]
_curses.setupterm
term: str(accept={str, NoneType}) = None
Terminal name.
If omitted, the value of the TERM environment variable will be used.
fd: int = -1
File descriptor to which any initialization sequences will be sent.
If not supplied, the file descriptor for sys.stdout will be used.
Initialize the terminal.
[clinic start generated code]*/
static PyObject *
_curses_setupterm_impl(PyObject *module, const char *term, int fd)
/*[clinic end generated code: output=4584e587350f2848 input=4511472766af0c12]*/
{
int err;
if (fd == -1) {
PyObject* sys_stdout;
sys_stdout = PySys_GetObject("stdout");
if (sys_stdout == NULL || sys_stdout == Py_None) {
PyErr_SetString(
PyCursesError,
"lost sys.stdout");
return NULL;
}
fd = PyObject_AsFileDescriptor(sys_stdout);
if (fd == -1) {
return NULL;
}
}
if (!initialised_setupterm && setupterm((char *)term, fd, &err) == ERR) {
const char* s = "setupterm: unknown error";
if (err == 0) {
s = "setupterm: could not find terminal";
} else if (err == -1) {
s = "setupterm: could not find terminfo database";
}
PyErr_SetString(PyCursesError,s);
return NULL;
}
initialised_setupterm = TRUE;
Py_RETURN_NONE;
}
#if defined(NCURSES_EXT_FUNCS) && NCURSES_EXT_FUNCS >= 20081102
// https://invisible-island.net/ncurses/NEWS.html#index-t20080119
/*[clinic input]
_curses.get_escdelay
Gets the curses ESCDELAY setting.
Gets the number of milliseconds to wait after reading an escape character,
to distinguish between an individual escape character entered on the
keyboard from escape sequences sent by cursor and function keys.
[clinic start generated code]*/
static PyObject *
_curses_get_escdelay_impl(PyObject *module)
/*[clinic end generated code: output=222fa1a822555d60 input=be2d5b3dd974d0a4]*/
{
return PyLong_FromLong(ESCDELAY);
}
/*[clinic input]
_curses.set_escdelay
ms: int
length of the delay in milliseconds.
/
Sets the curses ESCDELAY setting.
Sets the number of milliseconds to wait after reading an escape character,
to distinguish between an individual escape character entered on the
keyboard from escape sequences sent by cursor and function keys.
[clinic start generated code]*/
static PyObject *
_curses_set_escdelay_impl(PyObject *module, int ms)
/*[clinic end generated code: output=43818efbf7980ac4 input=7796fe19f111e250]*/
{
if (ms <= 0) {
PyErr_SetString(PyExc_ValueError, "ms must be > 0");
return NULL;
}
return PyCursesCheckERR(set_escdelay(ms), "set_escdelay");
}
/*[clinic input]
_curses.get_tabsize
Gets the curses TABSIZE setting.
Gets the number of columns used by the curses library when converting a tab
character to spaces as it adds the tab to a window.
[clinic start generated code]*/
static PyObject *
_curses_get_tabsize_impl(PyObject *module)
/*[clinic end generated code: output=7e9e51fb6126fbdf input=74af86bf6c9f5d7e]*/
{
return PyLong_FromLong(TABSIZE);
}
/*[clinic input]
_curses.set_tabsize
size: int
rendered cell width of a tab character.
/
Sets the curses TABSIZE setting.
Sets the number of columns used by the curses library when converting a tab
character to spaces as it adds the tab to a window.
[clinic start generated code]*/
static PyObject *
_curses_set_tabsize_impl(PyObject *module, int size)
/*[clinic end generated code: output=c1de5a76c0daab1e input=78cba6a3021ad061]*/
{
if (size <= 0) {
PyErr_SetString(PyExc_ValueError, "size must be > 0");
return NULL;
}
return PyCursesCheckERR(set_tabsize(size), "set_tabsize");
}
#endif
/*[clinic input]
_curses.intrflush
flag: bool(accept={int})
/
[clinic start generated code]*/
static PyObject *
_curses_intrflush_impl(PyObject *module, int flag)
/*[clinic end generated code: output=c1986df35e999a0f input=fcba57bb28dfd795]*/
{
PyCursesInitialised;
return PyCursesCheckERR(intrflush(NULL, flag), "intrflush");
}
/*[clinic input]
_curses.isendwin
Return True if endwin() has been called.
[clinic start generated code]*/
static PyObject *
_curses_isendwin_impl(PyObject *module)
/*[clinic end generated code: output=d73179e4a7e1eb8c input=6cdb01a7ebf71397]*/
NoArgTrueFalseFunctionBody(isendwin)
#ifdef HAVE_CURSES_IS_TERM_RESIZED
/*[clinic input]
_curses.is_term_resized
nlines: int
Height.
ncols: int
Width.
/
Return True if resize_term() would modify the window structure, False otherwise.
[clinic start generated code]*/
static PyObject *
_curses_is_term_resized_impl(PyObject *module, int nlines, int ncols)
/*[clinic end generated code: output=aafe04afe50f1288 input=ca9c0bd0fb8ab444]*/
{
PyCursesInitialised;
return PyBool_FromLong(is_term_resized(nlines, ncols));
}
#endif /* HAVE_CURSES_IS_TERM_RESIZED */
/*[clinic input]
_curses.keyname
key: int
Key number.
/
Return the name of specified key.
[clinic start generated code]*/
static PyObject *
_curses_keyname_impl(PyObject *module, int key)
/*[clinic end generated code: output=fa2675ab3f4e056b input=ee4b1d0f243a2a2b]*/
{
const char *knp;
PyCursesInitialised;
if (key < 0) {
PyErr_SetString(PyExc_ValueError, "invalid key number");
return NULL;
}
knp = keyname(key);
return PyBytes_FromString((knp == NULL) ? "" : knp);
}
/*[clinic input]
_curses.killchar
Return the user's current line kill character.
[clinic start generated code]*/
static PyObject *
_curses_killchar_impl(PyObject *module)
/*[clinic end generated code: output=31c3a45b2c528269 input=1ff171c38df5ccad]*/
{
char ch;
ch = killchar();
return PyBytes_FromStringAndSize(&ch, 1);
}
/*[clinic input]
_curses.longname
Return the terminfo long name field describing the current terminal.
The maximum length of a verbose description is 128 characters. It is defined
only after the call to initscr().
[clinic start generated code]*/
static PyObject *
_curses_longname_impl(PyObject *module)
/*[clinic end generated code: output=fdf30433727ef568 input=84c3f20201b1098e]*/
NoArgReturnStringFunctionBody(longname)
/*[clinic input]
_curses.meta
yes: bool(accept={int})
/
Enable/disable meta keys.
If yes is True, allow 8-bit characters to be input. If yes is False,
allow only 7-bit characters.
[clinic start generated code]*/
static PyObject *
_curses_meta_impl(PyObject *module, int yes)
/*[clinic end generated code: output=22f5abda46a605d8 input=af9892e3a74f35db]*/
{
PyCursesInitialised;
return PyCursesCheckERR(meta(stdscr, yes), "meta");
}
#ifdef NCURSES_MOUSE_VERSION
/*[clinic input]
_curses.mouseinterval
interval: int
Time in milliseconds.
/
Set and retrieve the maximum time between press and release in a click.
Set the maximum time that can elapse between press and release events in
order for them to be recognized as a click, and return the previous interval
value.
[clinic start generated code]*/
static PyObject *
_curses_mouseinterval_impl(PyObject *module, int interval)
/*[clinic end generated code: output=c4f5ff04354634c5 input=75aaa3f0db10ac4e]*/
{
PyCursesInitialised;
return PyCursesCheckERR(mouseinterval(interval), "mouseinterval");
}
/*[clinic input]
_curses.mousemask
newmask: unsigned_long(bitwise=True)
/
Set the mouse events to be reported, and return a tuple (availmask, oldmask).
Return a tuple (availmask, oldmask). availmask indicates which of the
specified mouse events can be reported; on complete failure it returns 0.
oldmask is the previous value of the given window's mouse event mask.
If this function is never called, no mouse events are ever reported.
[clinic start generated code]*/
static PyObject *
_curses_mousemask_impl(PyObject *module, unsigned long newmask)
/*[clinic end generated code: output=9406cf1b8a36e485 input=bdf76b7568a3c541]*/
{
mmask_t oldmask, availmask;
PyCursesInitialised;
availmask = mousemask((mmask_t)newmask, &oldmask);
return Py_BuildValue("(kk)",
(unsigned long)availmask, (unsigned long)oldmask);
}
#endif
/*[clinic input]
_curses.napms
ms: int
Duration in milliseconds.
/
Sleep for specified time.
[clinic start generated code]*/
static PyObject *
_curses_napms_impl(PyObject *module, int ms)
/*[clinic end generated code: output=a40a1da2e39ea438 input=20cd3af2b6900f56]*/
{
PyCursesInitialised;
return Py_BuildValue("i", napms(ms));
}
/*[clinic input]
_curses.newpad
nlines: int
Height.
ncols: int
Width.
/
Create and return a pointer to a new pad data structure.
[clinic start generated code]*/
static PyObject *
_curses_newpad_impl(PyObject *module, int nlines, int ncols)
/*[clinic end generated code: output=de52a56eb1098ec9 input=93f1272f240d8894]*/
{
WINDOW *win;
PyCursesInitialised;
win = newpad(nlines, ncols);
if (win == NULL) {
PyErr_SetString(PyCursesError, catchall_NULL);
return NULL;
}
return (PyObject *)PyCursesWindow_New(win, NULL);
}
/*[clinic input]
_curses.newwin
nlines: int
Height.
ncols: int
Width.
[
begin_y: int = 0
Top side y-coordinate.
begin_x: int = 0
Left side x-coordinate.
]
/
Return a new window.
By default, the window will extend from the specified position to the lower
right corner of the screen.
[clinic start generated code]*/
static PyObject *
_curses_newwin_impl(PyObject *module, int nlines, int ncols,
int group_right_1, int begin_y, int begin_x)
/*[clinic end generated code: output=c1e0a8dc8ac2826c input=29312c15a72a003d]*/
{
WINDOW *win;
PyCursesInitialised;
win = newwin(nlines,ncols,begin_y,begin_x);
if (win == NULL) {
PyErr_SetString(PyCursesError, catchall_NULL);
return NULL;
}
return (PyObject *)PyCursesWindow_New(win, NULL);
}
/*[clinic input]
_curses.nl
flag: bool(accept={int}) = True
If false, the effect is the same as calling nonl().
/
Enter newline mode.
This mode translates the return key into newline on input, and translates
newline into return and line-feed on output. Newline mode is initially on.
[clinic start generated code]*/
static PyObject *
_curses_nl_impl(PyObject *module, int flag)
/*[clinic end generated code: output=b39cc0ffc9015003 input=cf36a63f7b86e28a]*/
NoArgOrFlagNoReturnFunctionBody(nl, flag)
/*[clinic input]
_curses.nocbreak
Leave cbreak mode.
Return to normal "cooked" mode with line buffering.
[clinic start generated code]*/
static PyObject *
_curses_nocbreak_impl(PyObject *module)
/*[clinic end generated code: output=eabf3833a4fbf620 input=e4b65f7d734af400]*/
NoArgNoReturnFunctionBody(nocbreak)
/*[clinic input]
_curses.noecho
Leave echo mode.
Echoing of input characters is turned off.
[clinic start generated code]*/
static PyObject *
_curses_noecho_impl(PyObject *module)
/*[clinic end generated code: output=cc95ab45bc98f41b input=76714df529e614c3]*/
NoArgNoReturnFunctionBody(noecho)
/*[clinic input]
_curses.nonl
Leave newline mode.
Disable translation of return into newline on input, and disable low-level
translation of newline into newline/return on output.
[clinic start generated code]*/
static PyObject *
_curses_nonl_impl(PyObject *module)
/*[clinic end generated code: output=99e917e9715770c6 input=9d37dd122d3022fc]*/
NoArgNoReturnFunctionBody(nonl)
/*[clinic input]
_curses.noqiflush
Disable queue flushing.
When queue flushing is disabled, normal flush of input and output queues
associated with the INTR, QUIT and SUSP characters will not be done.
[clinic start generated code]*/
static PyObject *
_curses_noqiflush_impl(PyObject *module)
/*[clinic end generated code: output=8b95a4229bbf0877 input=ba3e6b2e3e54c4df]*/
NoArgNoReturnVoidFunctionBody(noqiflush)
/*[clinic input]
_curses.noraw
Leave raw mode.
Return to normal "cooked" mode with line buffering.
[clinic start generated code]*/
static PyObject *
_curses_noraw_impl(PyObject *module)
/*[clinic end generated code: output=39894e5524c430cc input=6ec86692096dffb5]*/
NoArgNoReturnFunctionBody(noraw)
/*[clinic input]
_curses.pair_content
pair_number: pair
The number of the color pair (1 - (COLOR_PAIRS-1)).
/
Return a tuple (fg, bg) containing the colors for the requested color pair.
[clinic start generated code]*/
static PyObject *
_curses_pair_content_impl(PyObject *module, int pair_number)
/*[clinic end generated code: output=4a726dd0e6885f3f input=b42eacf8a4103852]*/
{
_NCURSES_COLOR_VAL_TYPE f, b;
PyCursesInitialised;
PyCursesInitialisedColor;
if (_CURSES_PAIR_NUMBER_FUNC(pair_number, &f, &b)==ERR) {
PyErr_SetString(PyCursesError,
"Argument 1 was out of range. (1..COLOR_PAIRS-1)");
return NULL;
}
return Py_BuildValue("(ii)", f, b);
}
/*[clinic input]
_curses.pair_number
attr: int
/
Return the number of the color-pair set by the specified attribute value.
color_pair() is the counterpart to this function.
[clinic start generated code]*/
static PyObject *
_curses_pair_number_impl(PyObject *module, int attr)
/*[clinic end generated code: output=85bce7d65c0aa3f4 input=d478548e33f5e61a]*/
{
PyCursesInitialised;
PyCursesInitialisedColor;
return PyLong_FromLong(attr_to_color_pair(attr));
}
/*[clinic input]
_curses.putp
string: str(accept={robuffer})
/
Emit the value of a specified terminfo capability for the current terminal.
Note that the output of putp() always goes to standard output.
[clinic start generated code]*/
static PyObject *
_curses_putp_impl(PyObject *module, const char *string)
/*[clinic end generated code: output=e98081d1b8eb5816 input=1601faa828b44cb3]*/
{
return PyCursesCheckERR(putp(string), "putp");
}
/*[clinic input]
_curses.qiflush
flag: bool(accept={int}) = True
If false, the effect is the same as calling noqiflush().
/
Enable queue flushing.
If queue flushing is enabled, all output in the display driver queue
will be flushed when the INTR, QUIT and SUSP characters are read.
[clinic start generated code]*/
static PyObject *
_curses_qiflush_impl(PyObject *module, int flag)
/*[clinic end generated code: output=9167e862f760ea30 input=e9e4a389946a0dbc]*/
{
PyCursesInitialised;
if (flag) {
qiflush();
}
else {
noqiflush();
}
Py_RETURN_NONE;
}
/* Internal helper used for updating curses.LINES, curses.COLS, _curses.LINES
* and _curses.COLS */
#if defined(HAVE_CURSES_RESIZETERM) || defined(HAVE_CURSES_RESIZE_TERM)
static int
update_lines_cols(void)
{
PyObject *o;
PyObject *m = PyImport_ImportModuleNoBlock("curses");
_Py_IDENTIFIER(LINES);
_Py_IDENTIFIER(COLS);
if (!m)
return 0;
o = PyLong_FromLong(LINES);
if (!o) {
Py_DECREF(m);
return 0;
}
if (_PyObject_SetAttrId(m, &PyId_LINES, o)) {
Py_DECREF(m);
Py_DECREF(o);
return 0;
}
/* PyId_LINES.object will be initialized here. */
if (PyDict_SetItem(ModDict, _PyUnicode_FromId(&PyId_LINES), o)) {
Py_DECREF(m);
Py_DECREF(o);
return 0;
}
Py_DECREF(o);
o = PyLong_FromLong(COLS);
if (!o) {
Py_DECREF(m);
return 0;
}
if (_PyObject_SetAttrId(m, &PyId_COLS, o)) {
Py_DECREF(m);
Py_DECREF(o);
return 0;
}
if (PyDict_SetItem(ModDict, _PyUnicode_FromId(&PyId_COLS), o)) {
Py_DECREF(m);
Py_DECREF(o);
return 0;
}
Py_DECREF(o);
Py_DECREF(m);
return 1;
}
/*[clinic input]
_curses.update_lines_cols
[clinic start generated code]*/
static PyObject *
_curses_update_lines_cols_impl(PyObject *module)
/*[clinic end generated code: output=423f2b1e63ed0f75 input=5f065ab7a28a5d90]*/
{
if (!update_lines_cols()) {
return NULL;
}
Py_RETURN_NONE;
}
#endif
/*[clinic input]
_curses.raw
flag: bool(accept={int}) = True
If false, the effect is the same as calling noraw().
/
Enter raw mode.
In raw mode, normal line buffering and processing of interrupt, quit,
suspend, and flow control keys are turned off; characters are presented to
curses input functions one by one.
[clinic start generated code]*/
static PyObject *
_curses_raw_impl(PyObject *module, int flag)
/*[clinic end generated code: output=a750e4b342be015b input=e36d8db27832b848]*/
NoArgOrFlagNoReturnFunctionBody(raw, flag)
/*[clinic input]
_curses.reset_prog_mode
Restore the terminal to "program" mode, as previously saved by def_prog_mode().
[clinic start generated code]*/
static PyObject *
_curses_reset_prog_mode_impl(PyObject *module)
/*[clinic end generated code: output=15eb765abf0b6575 input=3d82bea2b3243471]*/
NoArgNoReturnFunctionBody(reset_prog_mode)
/*[clinic input]
_curses.reset_shell_mode
Restore the terminal to "shell" mode, as previously saved by def_shell_mode().
[clinic start generated code]*/
static PyObject *
_curses_reset_shell_mode_impl(PyObject *module)
/*[clinic end generated code: output=0238de2962090d33 input=1c738fa64bd1a24f]*/
NoArgNoReturnFunctionBody(reset_shell_mode)
/*[clinic input]
_curses.resetty
Restore terminal mode.
[clinic start generated code]*/
static PyObject *
_curses_resetty_impl(PyObject *module)
/*[clinic end generated code: output=ff4b448e80a7cd63 input=940493de03624bb0]*/
NoArgNoReturnFunctionBody(resetty)
#ifdef HAVE_CURSES_RESIZETERM
/*[clinic input]
_curses.resizeterm
nlines: int
Height.
ncols: int
Width.
/
Resize the standard and current windows to the specified dimensions.
Adjusts other bookkeeping data used by the curses library that record the
window dimensions (in particular the SIGWINCH handler).
[clinic start generated code]*/
static PyObject *
_curses_resizeterm_impl(PyObject *module, int nlines, int ncols)
/*[clinic end generated code: output=56d6bcc5194ad055 input=0fca02ebad5ffa82]*/
{
PyObject *result;
PyCursesInitialised;
result = PyCursesCheckERR(resizeterm(nlines, ncols), "resizeterm");
if (!result)
return NULL;
if (!update_lines_cols()) {
Py_DECREF(result);
return NULL;
}
return result;
}
#endif
#ifdef HAVE_CURSES_RESIZE_TERM
/*[clinic input]
_curses.resize_term
nlines: int
Height.
ncols: int
Width.
/
Backend function used by resizeterm(), performing most of the work.
When resizing the windows, resize_term() blank-fills the areas that are
extended. The calling application should fill in these areas with appropriate
data. The resize_term() function attempts to resize all windows. However,
due to the calling convention of pads, it is not possible to resize these
without additional interaction with the application.
[clinic start generated code]*/
static PyObject *
_curses_resize_term_impl(PyObject *module, int nlines, int ncols)
/*[clinic end generated code: output=9e26d8b9ea311ed2 input=2197edd05b049ed4]*/
{
PyObject *result;
PyCursesInitialised;
result = PyCursesCheckERR(resize_term(nlines, ncols), "resize_term");
if (!result)
return NULL;
if (!update_lines_cols()) {
Py_DECREF(result);
return NULL;
}
return result;
}
#endif /* HAVE_CURSES_RESIZE_TERM */
/*[clinic input]
_curses.savetty
Save terminal mode.
[clinic start generated code]*/
static PyObject *
_curses_savetty_impl(PyObject *module)
/*[clinic end generated code: output=6babc49f12b42199 input=fce6b2b7d2200102]*/
NoArgNoReturnFunctionBody(savetty)
#ifdef getsyx
/*[clinic input]
_curses.setsyx
y: int
Y-coordinate.
x: int
X-coordinate.
/
Set the virtual screen cursor.
If y and x are both -1, then leaveok is set.
[clinic start generated code]*/
static PyObject *
_curses_setsyx_impl(PyObject *module, int y, int x)
/*[clinic end generated code: output=23dcf753511a2464 input=fa7f2b208e10a557]*/
{
PyCursesInitialised;
setsyx(y,x);
Py_RETURN_NONE;
}
#endif
/*[clinic input]
_curses.start_color
Initializes eight basic colors and global variables COLORS and COLOR_PAIRS.
Must be called if the programmer wants to use colors, and before any other
color manipulation routine is called. It is good practice to call this
routine right after initscr().
It also restores the colors on the terminal to the values they had when the
terminal was just turned on.
[clinic start generated code]*/
static PyObject *
_curses_start_color_impl(PyObject *module)
/*[clinic end generated code: output=8b772b41d8090ede input=0ca0ecb2b77e1a12]*/
{
int code;
PyObject *c, *cp;
PyCursesInitialised;
code = start_color();
if (code != ERR) {
initialisedcolors = TRUE;
c = PyLong_FromLong((long) COLORS);
if (c == NULL)
return NULL;
if (PyDict_SetItemString(ModDict, "COLORS", c) < 0) {
Py_DECREF(c);
return NULL;
}
Py_DECREF(c);
cp = PyLong_FromLong((long) COLOR_PAIRS);
if (cp == NULL)
return NULL;
if (PyDict_SetItemString(ModDict, "COLOR_PAIRS", cp) < 0) {
Py_DECREF(cp);
return NULL;
}
Py_DECREF(cp);
Py_RETURN_NONE;
} else {
PyErr_SetString(PyCursesError, "start_color() returned ERR");
return NULL;
}
}
/*[clinic input]
_curses.termattrs
Return a logical OR of all video attributes supported by the terminal.
[clinic start generated code]*/
static PyObject *
_curses_termattrs_impl(PyObject *module)
/*[clinic end generated code: output=b06f437fce1b6fc4 input=0559882a04f84d1d]*/
NoArgReturnIntFunctionBody(termattrs)
/*[clinic input]
_curses.termname
Return the value of the environment variable TERM, truncated to 14 characters.
[clinic start generated code]*/
static PyObject *
_curses_termname_impl(PyObject *module)
/*[clinic end generated code: output=96375577ebbd67fd input=33c08d000944f33f]*/
NoArgReturnStringFunctionBody(termname)
/*[clinic input]
_curses.tigetflag
capname: str
The terminfo capability name.
/
Return the value of the Boolean capability.
The value -1 is returned if capname is not a Boolean capability, or 0 if
it is canceled or absent from the terminal description.
[clinic start generated code]*/
static PyObject *
_curses_tigetflag_impl(PyObject *module, const char *capname)
/*[clinic end generated code: output=8853c0e55542195b input=b0787af9e3e9a6ce]*/
{
PyCursesSetupTermCalled;
return PyLong_FromLong( (long) tigetflag( (char *)capname ) );
}
/*[clinic input]
_curses.tigetnum
capname: str
The terminfo capability name.
/
Return the value of the numeric capability.
The value -2 is returned if capname is not a numeric capability, or -1 if
it is canceled or absent from the terminal description.
[clinic start generated code]*/
static PyObject *
_curses_tigetnum_impl(PyObject *module, const char *capname)
/*[clinic end generated code: output=46f8b0a1b5dff42f input=5cdf2f410b109720]*/
{
PyCursesSetupTermCalled;
return PyLong_FromLong( (long) tigetnum( (char *)capname ) );
}
/*[clinic input]
_curses.tigetstr
capname: str
The terminfo capability name.
/
Return the value of the string capability.
None is returned if capname is not a string capability, or is canceled or
absent from the terminal description.
[clinic start generated code]*/
static PyObject *
_curses_tigetstr_impl(PyObject *module, const char *capname)
/*[clinic end generated code: output=f22b576ad60248f3 input=36644df25c73c0a7]*/
{
PyCursesSetupTermCalled;
capname = tigetstr( (char *)capname );
if (capname == NULL || capname == (char*) -1) {
Py_RETURN_NONE;
}
return PyBytes_FromString( capname );
}
/*[clinic input]
_curses.tparm
str: str(accept={robuffer})
Parameterized byte string obtained from the terminfo database.
i1: int = 0
i2: int = 0
i3: int = 0
i4: int = 0
i5: int = 0
i6: int = 0
i7: int = 0
i8: int = 0
i9: int = 0
/
Instantiate the specified byte string with the supplied parameters.
[clinic start generated code]*/
static PyObject *
_curses_tparm_impl(PyObject *module, const char *str, int i1, int i2, int i3,
int i4, int i5, int i6, int i7, int i8, int i9)
/*[clinic end generated code: output=599f62b615c667ff input=5e30b15786f032aa]*/
{
char* result = NULL;
PyCursesSetupTermCalled;
result = tparm((char *)str,i1,i2,i3,i4,i5,i6,i7,i8,i9);
if (!result) {
PyErr_SetString(PyCursesError, "tparm() returned NULL");
return NULL;
}
return PyBytes_FromString(result);
}
#ifdef HAVE_CURSES_TYPEAHEAD
/*[clinic input]
_curses.typeahead
fd: int
File descriptor.
/
Specify that the file descriptor fd be used for typeahead checking.
If fd is -1, then no typeahead checking is done.
[clinic start generated code]*/
static PyObject *
_curses_typeahead_impl(PyObject *module, int fd)
/*[clinic end generated code: output=084bb649d7066583 input=f2968d8e1805051b]*/
{
PyCursesInitialised;
return PyCursesCheckERR(typeahead( fd ), "typeahead");
}
#endif
/*[clinic input]
_curses.unctrl
ch: object
/
Return a string which is a printable representation of the character ch.
Control characters are displayed as a caret followed by the character,
for example as ^C. Printing characters are left as they are.
[clinic start generated code]*/
static PyObject *
_curses_unctrl(PyObject *module, PyObject *ch)
/*[clinic end generated code: output=8e07fafc430c9434 input=cd1e35e16cd1ace4]*/
{
chtype ch_;
PyCursesInitialised;
if (!PyCurses_ConvertToChtype(NULL, ch, &ch_))
return NULL;
return PyBytes_FromString(unctrl(ch_));
}
/*[clinic input]
_curses.ungetch
ch: object
/
Push ch so the next getch() will return it.
[clinic start generated code]*/
static PyObject *
_curses_ungetch(PyObject *module, PyObject *ch)
/*[clinic end generated code: output=9b19d8268376d887 input=6681e6ae4c42e5eb]*/
{
chtype ch_;
PyCursesInitialised;
if (!PyCurses_ConvertToChtype(NULL, ch, &ch_))
return NULL;
return PyCursesCheckERR(ungetch(ch_), "ungetch");
}
#ifdef HAVE_NCURSESW
/* Convert an object to a character (wchar_t):
- int
- str of length 1
Return 1 on success, 0 on error. */
static int
PyCurses_ConvertToWchar_t(PyObject *obj,
wchar_t *wch)
{
if (PyUnicode_Check(obj)) {
wchar_t buffer[2];
if (PyUnicode_AsWideChar(obj, buffer, 2) != 1) {
PyErr_Format(PyExc_TypeError,
"expect str of length 1 or int, "
"got a str of length %zi",
PyUnicode_GET_LENGTH(obj));
return 0;
}
*wch = buffer[0];
return 2;
}
else if (PyLong_CheckExact(obj)) {
long value;
int overflow;
value = PyLong_AsLongAndOverflow(obj, &overflow);
if (overflow) {
PyErr_SetString(PyExc_OverflowError,
"int doesn't fit in long");
return 0;
}
*wch = (wchar_t)value;
if ((long)*wch != value) {
PyErr_Format(PyExc_OverflowError,
"character doesn't fit in wchar_t");
return 0;
}
return 1;
}
else {
PyErr_Format(PyExc_TypeError,
"expect str of length 1 or int, got %s",
Py_TYPE(obj)->tp_name);
return 0;
}
}
/*[clinic input]
_curses.unget_wch
ch: object
/
Push ch so the next get_wch() will return it.
[clinic start generated code]*/
static PyObject *
_curses_unget_wch(PyObject *module, PyObject *ch)
/*[clinic end generated code: output=1974c9fb01d37863 input=0d56dc65a46feebb]*/
{
wchar_t wch;
PyCursesInitialised;
if (!PyCurses_ConvertToWchar_t(ch, &wch))
return NULL;
return PyCursesCheckERR(unget_wch(wch), "unget_wch");
}
#endif
#ifdef HAVE_CURSES_USE_ENV
/*[clinic input]
_curses.use_env
flag: bool(accept={int})
/
Use environment variables LINES and COLUMNS.
If used, this function should be called before initscr() or newterm() are
called.
When flag is False, the values of lines and columns specified in the terminfo
database will be used, even if environment variables LINES and COLUMNS (used
by default) are set, or if curses is running in a window (in which case
default behavior would be to use the window size if LINES and COLUMNS are
not set).
[clinic start generated code]*/
static PyObject *
_curses_use_env_impl(PyObject *module, int flag)
/*[clinic end generated code: output=b2c445e435c0b164 input=1778eb1e9151ea37]*/
{
use_env(flag);
Py_RETURN_NONE;
}
#endif
#ifndef STRICT_SYSV_CURSES
/*[clinic input]
_curses.use_default_colors
Allow use of default values for colors on terminals supporting this feature.
Use this to support transparency in your application. The default color
is assigned to the color number -1.
[clinic start generated code]*/
static PyObject *
_curses_use_default_colors_impl(PyObject *module)
/*[clinic end generated code: output=a3b81ff71dd901be input=656844367470e8fc]*/
{
int code;
PyCursesInitialised;
PyCursesInitialisedColor;
code = use_default_colors();
if (code != ERR) {
Py_RETURN_NONE;
} else {
PyErr_SetString(PyCursesError, "use_default_colors() returned ERR");
return NULL;
}
}
#endif /* STRICT_SYSV_CURSES */
#ifdef NCURSES_VERSION
PyDoc_STRVAR(ncurses_version__doc__,
"curses.ncurses_version\n\
\n\
Ncurses version information as a named tuple.");
static PyTypeObject NcursesVersionType;
static PyStructSequence_Field ncurses_version_fields[] = {
{"major", "Major release number"},
{"minor", "Minor release number"},
{"patch", "Patch release number"},
{0}
};
static PyStructSequence_Desc ncurses_version_desc = {
"curses.ncurses_version", /* name */
ncurses_version__doc__, /* doc */
ncurses_version_fields, /* fields */
3
};
static PyObject *
make_ncurses_version(void)
{
PyObject *ncurses_version;
int pos = 0;
ncurses_version = PyStructSequence_New(&NcursesVersionType);
if (ncurses_version == NULL) {
return NULL;
}
#define SetIntItem(flag) \
PyStructSequence_SET_ITEM(ncurses_version, pos++, PyLong_FromLong(flag)); \
if (PyErr_Occurred()) { \
Py_CLEAR(ncurses_version); \
return NULL; \
}
SetIntItem(NCURSES_VERSION_MAJOR)
SetIntItem(NCURSES_VERSION_MINOR)
SetIntItem(NCURSES_VERSION_PATCH)
#undef SetIntItem
return ncurses_version;
}
#endif /* NCURSES_VERSION */
/*[clinic input]
_curses.has_extended_color_support
Return True if the module supports extended colors; otherwise, return False.
Extended color support allows more than 256 color-pairs for terminals
that support more than 16 colors (e.g. xterm-256color).
[clinic start generated code]*/
static PyObject *
_curses_has_extended_color_support_impl(PyObject *module)
/*[clinic end generated code: output=68f1be2b57d92e22 input=4b905f046e35ee9f]*/
{
return PyBool_FromLong(_NCURSES_EXTENDED_COLOR_FUNCS);
}
/* List of functions defined in the module */
static PyMethodDef PyCurses_methods[] = {
_CURSES_BAUDRATE_METHODDEF
_CURSES_BEEP_METHODDEF
_CURSES_CAN_CHANGE_COLOR_METHODDEF
_CURSES_CBREAK_METHODDEF
_CURSES_COLOR_CONTENT_METHODDEF
_CURSES_COLOR_PAIR_METHODDEF
_CURSES_CURS_SET_METHODDEF
_CURSES_DEF_PROG_MODE_METHODDEF
_CURSES_DEF_SHELL_MODE_METHODDEF
_CURSES_DELAY_OUTPUT_METHODDEF
_CURSES_DOUPDATE_METHODDEF
_CURSES_ECHO_METHODDEF
_CURSES_ENDWIN_METHODDEF
_CURSES_ERASECHAR_METHODDEF
_CURSES_FILTER_METHODDEF
_CURSES_FLASH_METHODDEF
_CURSES_FLUSHINP_METHODDEF
_CURSES_GETMOUSE_METHODDEF
_CURSES_UNGETMOUSE_METHODDEF
_CURSES_GETSYX_METHODDEF
_CURSES_GETWIN_METHODDEF
_CURSES_HAS_COLORS_METHODDEF
_CURSES_HAS_EXTENDED_COLOR_SUPPORT_METHODDEF
_CURSES_HAS_IC_METHODDEF
_CURSES_HAS_IL_METHODDEF
_CURSES_HAS_KEY_METHODDEF
_CURSES_HALFDELAY_METHODDEF
_CURSES_INIT_COLOR_METHODDEF
_CURSES_INIT_PAIR_METHODDEF
_CURSES_INITSCR_METHODDEF
_CURSES_INTRFLUSH_METHODDEF
_CURSES_ISENDWIN_METHODDEF
_CURSES_IS_TERM_RESIZED_METHODDEF
_CURSES_KEYNAME_METHODDEF
_CURSES_KILLCHAR_METHODDEF
_CURSES_LONGNAME_METHODDEF
_CURSES_META_METHODDEF
_CURSES_MOUSEINTERVAL_METHODDEF
_CURSES_MOUSEMASK_METHODDEF
_CURSES_NAPMS_METHODDEF
_CURSES_NEWPAD_METHODDEF
_CURSES_NEWWIN_METHODDEF
_CURSES_NL_METHODDEF
_CURSES_NOCBREAK_METHODDEF
_CURSES_NOECHO_METHODDEF
_CURSES_NONL_METHODDEF
_CURSES_NOQIFLUSH_METHODDEF
_CURSES_NORAW_METHODDEF
_CURSES_PAIR_CONTENT_METHODDEF
_CURSES_PAIR_NUMBER_METHODDEF
_CURSES_PUTP_METHODDEF
_CURSES_QIFLUSH_METHODDEF
_CURSES_RAW_METHODDEF
_CURSES_RESET_PROG_MODE_METHODDEF
_CURSES_RESET_SHELL_MODE_METHODDEF
_CURSES_RESETTY_METHODDEF
_CURSES_RESIZETERM_METHODDEF
_CURSES_RESIZE_TERM_METHODDEF
_CURSES_SAVETTY_METHODDEF
#if defined(NCURSES_EXT_FUNCS) && NCURSES_EXT_FUNCS >= 20081102
_CURSES_GET_ESCDELAY_METHODDEF
_CURSES_SET_ESCDELAY_METHODDEF
#endif
_CURSES_GET_TABSIZE_METHODDEF
_CURSES_SET_TABSIZE_METHODDEF
_CURSES_SETSYX_METHODDEF
_CURSES_SETUPTERM_METHODDEF
_CURSES_START_COLOR_METHODDEF
_CURSES_TERMATTRS_METHODDEF
_CURSES_TERMNAME_METHODDEF
_CURSES_TIGETFLAG_METHODDEF
_CURSES_TIGETNUM_METHODDEF
_CURSES_TIGETSTR_METHODDEF
_CURSES_TPARM_METHODDEF
_CURSES_TYPEAHEAD_METHODDEF
_CURSES_UNCTRL_METHODDEF
_CURSES_UNGETCH_METHODDEF
_CURSES_UPDATE_LINES_COLS_METHODDEF
_CURSES_UNGET_WCH_METHODDEF
_CURSES_USE_ENV_METHODDEF
_CURSES_USE_DEFAULT_COLORS_METHODDEF
{NULL, NULL} /* sentinel */
};
/* Initialization function for the module */
static struct PyModuleDef _cursesmodule = {
PyModuleDef_HEAD_INIT,
"_curses",
NULL,
-1,
PyCurses_methods,
NULL,
NULL,
NULL,
NULL
};
PyMODINIT_FUNC
PyInit__curses(void)
{
PyObject *m, *d, *v, *c_api_object;
static void *PyCurses_API[PyCurses_API_pointers];
/* Initialize object type */
if (PyType_Ready(&PyCursesWindow_Type) < 0)
return NULL;
/* Initialize the C API pointer array */
PyCurses_API[0] = (void *)&PyCursesWindow_Type;
PyCurses_API[1] = (void *)func_PyCursesSetupTermCalled;
PyCurses_API[2] = (void *)func_PyCursesInitialised;
PyCurses_API[3] = (void *)func_PyCursesInitialisedColor;
/* Create the module and add the functions */
m = PyModule_Create(&_cursesmodule);
if (m == NULL)
return NULL;
/* Add some symbolic constants to the module */
d = PyModule_GetDict(m);
if (d == NULL)
return NULL;
ModDict = d; /* For PyCurses_InitScr to use later */
/* Add a capsule for the C API */
c_api_object = PyCapsule_New(PyCurses_API, PyCurses_CAPSULE_NAME, NULL);
PyDict_SetItemString(d, "_C_API", c_api_object);
Py_DECREF(c_api_object);
/* For exception curses.error */
PyCursesError = PyErr_NewException("_curses.error", NULL, NULL);
PyDict_SetItemString(d, "error", PyCursesError);
/* Make the version available */
v = PyBytes_FromString(PyCursesVersion);
PyDict_SetItemString(d, "version", v);
PyDict_SetItemString(d, "__version__", v);
Py_DECREF(v);
#ifdef NCURSES_VERSION
/* ncurses_version */
if (NcursesVersionType.tp_name == NULL) {
if (PyStructSequence_InitType2(&NcursesVersionType,
&ncurses_version_desc) < 0)
return NULL;
}
v = make_ncurses_version();
if (v == NULL) {
return NULL;
}
PyDict_SetItemString(d, "ncurses_version", v);
Py_DECREF(v);
/* prevent user from creating new instances */
NcursesVersionType.tp_init = NULL;
NcursesVersionType.tp_new = NULL;
if (PyDict_DelItemString(NcursesVersionType.tp_dict, "__new__") < 0 &&
PyErr_ExceptionMatches(PyExc_KeyError))
{
PyErr_Clear();
}
#endif /* NCURSES_VERSION */
SetDictInt("ERR", ERR);
SetDictInt("OK", OK);
/* Here are some attributes you can add to chars to print */
SetDictInt("A_ATTRIBUTES", A_ATTRIBUTES);
SetDictInt("A_NORMAL", A_NORMAL);
SetDictInt("A_STANDOUT", A_STANDOUT);
SetDictInt("A_UNDERLINE", A_UNDERLINE);
SetDictInt("A_REVERSE", A_REVERSE);
SetDictInt("A_BLINK", A_BLINK);
SetDictInt("A_DIM", A_DIM);
SetDictInt("A_BOLD", A_BOLD);
SetDictInt("A_ALTCHARSET", A_ALTCHARSET);
SetDictInt("A_INVIS", A_INVIS);
SetDictInt("A_PROTECT", A_PROTECT);
SetDictInt("A_CHARTEXT", A_CHARTEXT);
SetDictInt("A_COLOR", A_COLOR);
/* The following are never available with strict SYSV curses */
#ifdef A_HORIZONTAL
SetDictInt("A_HORIZONTAL", A_HORIZONTAL);
#endif
#ifdef A_LEFT
SetDictInt("A_LEFT", A_LEFT);
#endif
#ifdef A_LOW
SetDictInt("A_LOW", A_LOW);
#endif
#ifdef A_RIGHT
SetDictInt("A_RIGHT", A_RIGHT);
#endif
#ifdef A_TOP
SetDictInt("A_TOP", A_TOP);
#endif
#ifdef A_VERTICAL
SetDictInt("A_VERTICAL", A_VERTICAL);
#endif
/* ncurses extension */
#ifdef A_ITALIC
SetDictInt("A_ITALIC", A_ITALIC);
#endif
SetDictInt("COLOR_BLACK", COLOR_BLACK);
SetDictInt("COLOR_RED", COLOR_RED);
SetDictInt("COLOR_GREEN", COLOR_GREEN);
SetDictInt("COLOR_YELLOW", COLOR_YELLOW);
SetDictInt("COLOR_BLUE", COLOR_BLUE);
SetDictInt("COLOR_MAGENTA", COLOR_MAGENTA);
SetDictInt("COLOR_CYAN", COLOR_CYAN);
SetDictInt("COLOR_WHITE", COLOR_WHITE);
#ifdef NCURSES_MOUSE_VERSION
/* Mouse-related constants */
SetDictInt("BUTTON1_PRESSED", BUTTON1_PRESSED);
SetDictInt("BUTTON1_RELEASED", BUTTON1_RELEASED);
SetDictInt("BUTTON1_CLICKED", BUTTON1_CLICKED);
SetDictInt("BUTTON1_DOUBLE_CLICKED", BUTTON1_DOUBLE_CLICKED);
SetDictInt("BUTTON1_TRIPLE_CLICKED", BUTTON1_TRIPLE_CLICKED);
SetDictInt("BUTTON2_PRESSED", BUTTON2_PRESSED);
SetDictInt("BUTTON2_RELEASED", BUTTON2_RELEASED);
SetDictInt("BUTTON2_CLICKED", BUTTON2_CLICKED);
SetDictInt("BUTTON2_DOUBLE_CLICKED", BUTTON2_DOUBLE_CLICKED);
SetDictInt("BUTTON2_TRIPLE_CLICKED", BUTTON2_TRIPLE_CLICKED);
SetDictInt("BUTTON3_PRESSED", BUTTON3_PRESSED);
SetDictInt("BUTTON3_RELEASED", BUTTON3_RELEASED);
SetDictInt("BUTTON3_CLICKED", BUTTON3_CLICKED);
SetDictInt("BUTTON3_DOUBLE_CLICKED", BUTTON3_DOUBLE_CLICKED);
SetDictInt("BUTTON3_TRIPLE_CLICKED", BUTTON3_TRIPLE_CLICKED);
SetDictInt("BUTTON4_PRESSED", BUTTON4_PRESSED);
SetDictInt("BUTTON4_RELEASED", BUTTON4_RELEASED);
SetDictInt("BUTTON4_CLICKED", BUTTON4_CLICKED);
SetDictInt("BUTTON4_DOUBLE_CLICKED", BUTTON4_DOUBLE_CLICKED);
SetDictInt("BUTTON4_TRIPLE_CLICKED", BUTTON4_TRIPLE_CLICKED);
SetDictInt("BUTTON_SHIFT", BUTTON_SHIFT);
SetDictInt("BUTTON_CTRL", BUTTON_CTRL);
SetDictInt("BUTTON_ALT", BUTTON_ALT);
SetDictInt("ALL_MOUSE_EVENTS", ALL_MOUSE_EVENTS);
SetDictInt("REPORT_MOUSE_POSITION", REPORT_MOUSE_POSITION);
#endif
/* Now set everything up for KEY_ variables */
{
int key;
char *key_n;
char *key_n2;
for (key=KEY_MIN;key < KEY_MAX; key++) {
key_n = (char *)keyname(key);
if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0)
continue;
if (strncmp(key_n,"KEY_F(",6)==0) {
char *p1, *p2;
key_n2 = PyMem_Malloc(strlen(key_n)+1);
if (!key_n2) {
PyErr_NoMemory();
break;
}
p1 = key_n;
p2 = key_n2;
while (*p1) {
if (*p1 != '(' && *p1 != ')') {
*p2 = *p1;
p2++;
}
p1++;
}
*p2 = (char)0;
} else
key_n2 = key_n;
SetDictInt(key_n2,key);
if (key_n2 != key_n)
PyMem_Free(key_n2);
}
SetDictInt("KEY_MIN", KEY_MIN);
SetDictInt("KEY_MAX", KEY_MAX);
}
if (PyModule_AddType(m, &PyCursesWindow_Type) < 0) {
return NULL;
}
return m;
}
|