forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_cursesmodule.c
2619 lines (2266 loc) · 70.3 KB
/
_cursesmodule.c
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
/*
* 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 ([email protected])
*
* 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.
*/
/* CVS: $Id$ */
/*
A number of SysV or ncurses functions don't have wrappers yet; if you need
a given function, add it and send a patch. Here's a list of currently
unsupported functions:
addchnstr addchstr chgat color_set define_key
del_curterm delscreen dupwin inchnstr inchstr innstr keyok
mcprint mvaddchnstr mvaddchstr mvchgat mvcur mvinchnstr
mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr mvwchgat
mvwgetnstr mvwinchnstr mvwinchstr mvwinnstr newterm
resizeterm restartterm ripoffline scr_dump
scr_init scr_restore scr_set scrl set_curterm set_term setterm
tgetent tgetflag tgetnum tgetstr tgoto timeout tputs
use_default_colors vidattr vidputs waddchnstr waddchstr wchgat
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 */
char *PyCursesVersion = "2.1";
/* Includes */
#include "Python.h"
#define CURSES_MODULE
#include "py_curses.h"
#ifdef __osf__
#define _XOPEN_SOURCE_EXTENDED /* Define macro for OSF/1 */
#define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
#endif
/* These prototypes are in <term.h>, but including this header
#defines many common symbols (such as "lines") which breaks the
curses module in other ways. So the code will just specify
explicit prototypes here. */
extern int setupterm(char *,int,int *);
#ifdef sgi
extern char *tigetstr(char *);
extern char *tparm(char *instring, ...);
#endif
#if defined(sgi) || defined(__sun__)
#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
/* 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;
/* 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 */
/*
* Check the return code from a curses function and return None
* or raise an exception as appropriate. These are exported using the
* CObject API.
*/
static PyObject *
PyCursesCheckERR(int code, char *fname)
{
if (code != ERR) {
Py_INCREF(Py_None);
return Py_None;
} else {
if (fname == NULL) {
PyErr_SetString(PyCursesError, catchall_ERR);
} else {
PyErr_Format(PyCursesError, "%s() returned ERR", fname);
}
return NULL;
}
}
static int
PyCurses_ConvertToChtype(PyObject *obj, chtype *ch)
{
if (PyInt_Check(obj)) {
*ch = (chtype) PyInt_AsLong(obj);
} else if(PyString_Check(obj) &
(PyString_Size(obj) == 1)) {
*ch = (chtype) *PyString_AsString(obj);
} else {
return 0;
}
return 1;
}
/* Function versions of the 3 functions for tested 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 *args) \
{ if (!PyArg_NoArgs(args)) return NULL; \
return PyCursesCheckERR(X(self->win), # X); }
#define Window_NoArgTrueFalseFunction(X) \
static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
{ \
if (!PyArg_NoArgs(args)) return NULL; \
if (X (self->win) == FALSE) { Py_INCREF(Py_False); return Py_False; } \
else { Py_INCREF(Py_True); return Py_True; } }
#define Window_NoArgNoReturnVoidFunction(X) \
static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
{ \
if (!PyArg_NoArgs(args)) return NULL; \
X(self->win); Py_INCREF(Py_None); return Py_None; }
#define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR) \
static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
{ \
TYPE arg1, arg2; \
if (!PyArg_NoArgs(args)) return NULL; \
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_Parse(args, PARSESTR, &arg1)) return NULL; \
X(self->win,arg1); Py_INCREF(Py_None); return Py_None; }
#define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR) \
static PyObject * PyCursesWindow_ ## X (PyCursesWindowObject *self, PyObject *args) \
{ \
TYPE arg1; \
if (!PyArg_Parse(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_Parse(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)")
Window_OneArgNoReturnVoidFunction(immedok, int, "i;True(1) or False(0)")
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(wattron, attr_t, "l;attr")
Window_OneArgNoReturnFunction(wattroff, attr_t, "l;attr")
Window_OneArgNoReturnFunction(wattrset, attr_t, "l;attr")
Window_OneArgNoReturnFunction(clearok, int, "i;True(1) or False(0)")
Window_OneArgNoReturnFunction(idlok, int, "i;True(1) or False(0)")
#if defined(__NetBSD__)
Window_OneArgNoReturnVoidFunction(keypad, int, "i;True(1) or False(0)")
#else
Window_OneArgNoReturnFunction(keypad, int, "i;True(1) or False(0)")
#endif
Window_OneArgNoReturnFunction(leaveok, int, "i;True(1) or False(0)")
#if defined(__NetBSD__)
Window_OneArgNoReturnVoidFunction(nodelay, int, "i;True(1) or False(0)")
#else
Window_OneArgNoReturnFunction(nodelay, int, "i;True(1) or False(0)")
#endif
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")
Window_OneArgNoReturnFunction(syncok, int, "i;True(1) or False(0)")
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)
{
PyCursesWindowObject *wo;
wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type);
if (wo == NULL) return NULL;
wo->win = win;
return (PyObject *)wo;
}
static void
PyCursesWindow_Dealloc(PyCursesWindowObject *wo)
{
if (wo->win != stdscr) delwin(wo->win);
PyMem_DEL(wo);
}
/* Addch, Addstr, Addnstr */
static PyObject *
PyCursesWindow_AddCh(PyCursesWindowObject *self, PyObject *args)
{
int rtn, x, y, use_xy = FALSE;
PyObject *temp;
chtype ch = 0;
attr_t attr = A_NORMAL;
switch (ARG_COUNT(args)) {
case 1:
if (!PyArg_Parse(args, "O;ch or int", &temp))
return NULL;
break;
case 2:
if (!PyArg_Parse(args, "(Ol);ch or int,attr", &temp, &attr))
return NULL;
break;
case 3:
if (!PyArg_Parse(args,"(iiO);y,x,ch or int", &y, &x, &temp))
return NULL;
use_xy = TRUE;
break;
case 4:
if (!PyArg_Parse(args,"(iiOl);y,x,ch or int, attr",
&y, &x, &temp, &attr))
return NULL;
use_xy = TRUE;
break;
default:
PyErr_SetString(PyExc_TypeError, "addch requires 1 or 4 arguments");
return NULL;
}
if (!PyCurses_ConvertToChtype(temp, &ch)) {
PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int");
return NULL;
}
if (use_xy == TRUE)
rtn = mvwaddch(self->win,y,x, ch | attr);
else {
rtn = waddch(self->win, ch | attr);
}
return PyCursesCheckERR(rtn, "addch");
}
static PyObject *
PyCursesWindow_AddStr(PyCursesWindowObject *self, PyObject *args)
{
int rtn;
int x, y;
char *str;
attr_t attr = A_NORMAL , attr_old = A_NORMAL;
int use_xy = FALSE, use_attr = FALSE;
switch (ARG_COUNT(args)) {
case 1:
if (!PyArg_Parse(args,"s;str", &str))
return NULL;
break;
case 2:
if (!PyArg_Parse(args,"(sl);str,attr", &str, &attr))
return NULL;
use_attr = TRUE;
break;
case 3:
if (!PyArg_Parse(args,"(iis);int,int,str", &y, &x, &str))
return NULL;
use_xy = TRUE;
break;
case 4:
if (!PyArg_Parse(args,"(iisl);int,int,str,attr", &y, &x, &str, &attr))
return NULL;
use_xy = use_attr = TRUE;
break;
default:
PyErr_SetString(PyExc_TypeError, "addstr requires 1 to 4 arguments");
return NULL;
}
if (use_attr == TRUE) {
attr_old = getattrs(self->win);
wattrset(self->win,attr);
}
if (use_xy == TRUE)
rtn = mvwaddstr(self->win,y,x,str);
else
rtn = waddstr(self->win,str);
if (use_attr == TRUE)
wattrset(self->win,attr_old);
return PyCursesCheckERR(rtn, "addstr");
}
static PyObject *
PyCursesWindow_AddNStr(PyCursesWindowObject *self, PyObject *args)
{
int rtn, x, y, n;
char *str;
attr_t attr = A_NORMAL , attr_old = A_NORMAL;
int use_xy = FALSE, use_attr = FALSE;
switch (ARG_COUNT(args)) {
case 2:
if (!PyArg_Parse(args,"(si);str,n", &str, &n))
return NULL;
break;
case 3:
if (!PyArg_Parse(args,"(sil);str,n,attr", &str, &n, &attr))
return NULL;
use_attr = TRUE;
break;
case 4:
if (!PyArg_Parse(args,"(iisi);y,x,str,n", &y, &x, &str, &n))
return NULL;
use_xy = TRUE;
break;
case 5:
if (!PyArg_Parse(args,"(iisil);y,x,str,n,attr", &y, &x, &str, &n, &attr))
return NULL;
use_xy = use_attr = TRUE;
break;
default:
PyErr_SetString(PyExc_TypeError, "addnstr requires 2 to 5 arguments");
return NULL;
}
if (use_attr == TRUE) {
attr_old = getattrs(self->win);
wattrset(self->win,attr);
}
if (use_xy == TRUE)
rtn = mvwaddnstr(self->win,y,x,str,n);
else
rtn = waddnstr(self->win,str,n);
if (use_attr == TRUE)
wattrset(self->win,attr_old);
return PyCursesCheckERR(rtn, "addnstr");
}
static PyObject *
PyCursesWindow_Bkgd(PyCursesWindowObject *self, PyObject *args)
{
PyObject *temp;
chtype bkgd;
attr_t attr = A_NORMAL;
switch (ARG_COUNT(args)) {
case 1:
if (!PyArg_Parse(args, "O;ch or int", &temp))
return NULL;
break;
case 2:
if (!PyArg_Parse(args,"(Ol);ch or int,attr", &temp, &attr))
return NULL;
break;
default:
PyErr_SetString(PyExc_TypeError, "bkgd requires 1 or 2 arguments");
return NULL;
}
if (!PyCurses_ConvertToChtype(temp, &bkgd)) {
PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int");
return NULL;
}
return PyCursesCheckERR(wbkgd(self->win, bkgd | A_NORMAL), "bkgd");
}
static PyObject *
PyCursesWindow_BkgdSet(PyCursesWindowObject *self, PyObject *args)
{
PyObject *temp;
chtype bkgd;
attr_t attr = A_NORMAL;
switch (ARG_COUNT(args)) {
case 1:
if (!PyArg_Parse(args, "O;ch or int", &temp))
return NULL;
break;
case 2:
if (!PyArg_Parse(args,"(Ol);ch or int,attr", &temp, &attr))
return NULL;
break;
default:
PyErr_SetString(PyExc_TypeError, "bkgdset requires 1 or 2 arguments");
return NULL;
}
if (!PyCurses_ConvertToChtype(temp, &bkgd)) {
PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int");
return NULL;
}
wbkgdset(self->win, bkgd | attr);
return PyCursesCheckERR(0, "bkgdset");
}
static PyObject *
PyCursesWindow_Border(PyCursesWindowObject *self, PyObject *args)
{
chtype ls, rs, ts, bs, tl, tr, bl, br;
ls = rs = ts = bs = tl = tr = bl = br = 0;
if (!PyArg_Parse(args,"|llllllll;ls,rs,ts,bs,tl,tr,bl,br",
&ls, &rs, &ts, &bs, &tl, &tr, &bl, &br))
return NULL;
wborder(self->win, ls, rs, ts, bs, tl, tr, bl, br);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *
PyCursesWindow_Box(PyCursesWindowObject *self, PyObject *args)
{
chtype ch1=0,ch2=0;
if (!PyArg_NoArgs(args)) {
PyErr_Clear();
if (!PyArg_Parse(args,"(ll);vertint,horint", &ch1, &ch2))
return NULL;
}
box(self->win,ch1,ch2);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *
PyCursesWindow_DelCh(PyCursesWindowObject *self, PyObject *args)
{
int rtn;
int x, y;
switch (ARG_COUNT(args)) {
case 0:
rtn = wdelch(self->win);
break;
case 2:
if (!PyArg_Parse(args,"(ii);y,x", &y, &x))
return NULL;
rtn = mvwdelch(self->win,y,x);
break;
default:
PyErr_SetString(PyExc_TypeError, "delch requires 0 or 2 arguments");
return NULL;
}
return PyCursesCheckERR(rtn, "[mv]wdelch");
}
static PyObject *
PyCursesWindow_DerWin(PyCursesWindowObject *self, PyObject *args)
{
WINDOW *win;
int nlines, ncols, begin_y, begin_x;
nlines = 0;
ncols = 0;
switch (ARG_COUNT(args)) {
case 2:
if (!PyArg_Parse(args,"(ii);begin_y,begin_x",&begin_y,&begin_x))
return NULL;
break;
case 4:
if (!PyArg_Parse(args, "(iiii);nlines,ncols,begin_y,begin_x",
&nlines,&ncols,&begin_y,&begin_x))
return NULL;
break;
default:
PyErr_SetString(PyExc_TypeError, "derwin requires 2 or 4 arguments");
return NULL;
}
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);
}
static PyObject *
PyCursesWindow_EchoChar(PyCursesWindowObject *self, PyObject *args)
{
PyObject *temp;
chtype ch;
attr_t attr = A_NORMAL;
switch (ARG_COUNT(args)) {
case 1:
if (!PyArg_Parse(args,"O;ch or int", &temp))
return NULL;
break;
case 2:
if (!PyArg_Parse(args,"(Ol);ch or int,attr", &temp, &attr))
return NULL;
break;
default:
PyErr_SetString(PyExc_TypeError, "echochar requires 1 or 2 arguments");
return NULL;
}
if (!PyCurses_ConvertToChtype(temp, &ch)) {
PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int");
return NULL;
}
#if !defined(__NetBSD__)
if (self->win->_flags & _ISPAD)
return PyCursesCheckERR(pechochar(self->win, ch | attr),
"echochar");
else
#endif
return PyCursesCheckERR(wechochar(self->win, ch | attr),
"echochar");
}
#ifdef NCURSES_MOUSE_VERSION
static PyObject *
PyCursesWindow_Enclose(PyCursesWindowObject *self, PyObject *args)
{
int x, y;
if (!PyArg_Parse(args,"(ii);y,x", &y, &x))
return NULL;
return PyInt_FromLong( wenclose(self->win,y,x) );
}
#endif
static PyObject *
PyCursesWindow_GetBkgd(PyCursesWindowObject *self, PyObject *args)
{
if (!PyArg_NoArgs(args))
return NULL;
return PyInt_FromLong((long) getbkgd(self->win));
}
static PyObject *
PyCursesWindow_GetCh(PyCursesWindowObject *self, PyObject *args)
{
int x, y;
chtype rtn;
switch (ARG_COUNT(args)) {
case 0:
Py_BEGIN_ALLOW_THREADS
rtn = wgetch(self->win);
Py_END_ALLOW_THREADS
break;
case 2:
if (!PyArg_Parse(args,"(ii);y,x",&y,&x))
return NULL;
Py_BEGIN_ALLOW_THREADS
rtn = mvwgetch(self->win,y,x);
Py_END_ALLOW_THREADS
break;
default:
PyErr_SetString(PyExc_TypeError, "getch requires 0 or 2 arguments");
return NULL;
}
return PyInt_FromLong(rtn);
}
static PyObject *
PyCursesWindow_GetKey(PyCursesWindowObject *self, PyObject *args)
{
int x, y;
chtype rtn;
switch (ARG_COUNT(args)) {
case 0:
Py_BEGIN_ALLOW_THREADS
rtn = wgetch(self->win);
Py_END_ALLOW_THREADS
break;
case 2:
if (!PyArg_Parse(args,"(ii);y,x",&y,&x))
return NULL;
Py_BEGIN_ALLOW_THREADS
rtn = mvwgetch(self->win,y,x);
Py_END_ALLOW_THREADS
break;
default:
PyErr_SetString(PyExc_TypeError, "getkey requires 0 or 2 arguments");
return NULL;
}
if (rtn<=255)
return Py_BuildValue("c", rtn);
else
#if defined(__NetBSD__)
return PyString_FromString(unctrl(rtn));
#else
return PyString_FromString((char *)keyname(rtn));
#endif
}
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 (ARG_COUNT(args)) {
case 0:
Py_BEGIN_ALLOW_THREADS
rtn2 = wgetstr(self->win,rtn);
Py_END_ALLOW_THREADS
break;
case 1:
if (!PyArg_Parse(args,"i;n", &n))
return NULL;
Py_BEGIN_ALLOW_THREADS
rtn2 = wgetnstr(self->win,rtn,n);
Py_END_ALLOW_THREADS
break;
case 2:
if (!PyArg_Parse(args,"(ii);y,x",&y,&x))
return NULL;
Py_BEGIN_ALLOW_THREADS
rtn2 = mvwgetstr(self->win,y,x,rtn);
Py_END_ALLOW_THREADS
break;
case 3:
if (!PyArg_Parse(args,"(iii);y,x,n", &y, &x, &n))
return NULL;
#ifdef STRICT_SYSV_CURSES
/* Untested */
Py_BEGIN_ALLOW_THREADS
rtn2 = wmove(self->win,y,x)==ERR ? ERR :
wgetnstr(self->win, rtn, n);
Py_END_ALLOW_THREADS
#else
Py_BEGIN_ALLOW_THREADS
rtn2 = mvwgetnstr(self->win, y, x, rtn, n);
Py_END_ALLOW_THREADS
#endif
break;
default:
PyErr_SetString(PyExc_TypeError, "getstr requires 0 to 2 arguments");
return NULL;
}
if (rtn2 == ERR)
rtn[0] = 0;
return PyString_FromString(rtn);
}
static PyObject *
PyCursesWindow_Hline(PyCursesWindowObject *self, PyObject *args)
{
PyObject *temp;
chtype ch;
int n, x, y, code = OK;
attr_t attr = A_NORMAL;
switch (ARG_COUNT(args)) {
case 2:
if (!PyArg_Parse(args, "(Oi);ch or int,n", &temp, &n))
return NULL;
break;
case 3:
if (!PyArg_Parse(args, "(Oil);ch or int,n,attr", &temp, &n, &attr))
return NULL;
break;
case 4:
if (!PyArg_Parse(args, "(iiOi);y,x,ch or int,n", &y, &x, &temp, &n))
return NULL;
code = wmove(self->win, y, x);
break;
case 5:
if (!PyArg_Parse(args, "(iiOil); y,x,ch or int,n,attr",
&y, &x, &temp, &n, &attr))
return NULL;
code = wmove(self->win, y, x);
default:
PyErr_SetString(PyExc_TypeError, "hline requires 2 or 5 arguments");
return NULL;
}
if (code != ERR) {
if (!PyCurses_ConvertToChtype(temp, &ch)) {
PyErr_SetString(PyExc_TypeError,
"argument 1 or 3 must be a ch or an int");
return NULL;
}
return PyCursesCheckERR(whline(self->win, ch | attr, n), "hline");
} else
return PyCursesCheckERR(code, "wmove");
}
static PyObject *
PyCursesWindow_InsCh(PyCursesWindowObject *self, PyObject *args)
{
int rtn, x, y, use_xy = FALSE;
PyObject *temp;
chtype ch = 0;
attr_t attr = A_NORMAL;
switch (ARG_COUNT(args)) {
case 1:
if (!PyArg_Parse(args, "O;ch or int", &temp))
return NULL;
break;
case 2:
if (!PyArg_Parse(args, "(Ol);ch or int,attr", &temp, &attr))
return NULL;
break;
case 3:
if (!PyArg_Parse(args,"(iiO);y,x,ch or int", &y, &x, &temp))
return NULL;
use_xy = TRUE;
break;
case 4:
if (!PyArg_Parse(args,"(iiOl);y,x,ch or int, attr", &y, &x, &temp, &attr))
return NULL;
use_xy = TRUE;
break;
default:
PyErr_SetString(PyExc_TypeError, "insch requires 1 or 4 arguments");
return NULL;
}
if (!PyCurses_ConvertToChtype(temp, &ch)) {
PyErr_SetString(PyExc_TypeError,
"argument 1 or 3 must be a ch or an int");
return NULL;
}
if (use_xy == TRUE)
rtn = mvwinsch(self->win,y,x, ch | attr);
else {
rtn = winsch(self->win, ch | attr);
}
return PyCursesCheckERR(rtn, "insch");
}
static PyObject *
PyCursesWindow_InCh(PyCursesWindowObject *self, PyObject *args)
{
int x, y, rtn;
switch (ARG_COUNT(args)) {
case 0:
rtn = winch(self->win);
break;
case 2:
if (!PyArg_Parse(args,"(ii);y,x",&y,&x))
return NULL;
rtn = mvwinch(self->win,y,x);
break;
default:
PyErr_SetString(PyExc_TypeError, "inch requires 0 or 2 arguments");
return NULL;
}
return PyInt_FromLong((long) rtn);
}
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 (ARG_COUNT(args)) {
case 0:
rtn2 = winstr(self->win,rtn);
break;
case 1:
if (!PyArg_Parse(args,"i;n", &n))
return NULL;
rtn2 = winnstr(self->win,rtn,n);
break;
case 2:
if (!PyArg_Parse(args,"(ii);y,x",&y,&x))
return NULL;
rtn2 = mvwinstr(self->win,y,x,rtn);
break;
case 3:
if (!PyArg_Parse(args, "(iii);y,x,n", &y, &x, &n))
return NULL;
rtn2 = mvwinnstr(self->win, y, x, rtn, n);
break;
default:
PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments");
return NULL;
}
if (rtn2 == ERR)
rtn[0] = 0;
return PyString_FromString(rtn);
}
static PyObject *
PyCursesWindow_InsStr(PyCursesWindowObject *self, PyObject *args)
{
int rtn;
int x, y;
char *str;
attr_t attr = A_NORMAL , attr_old = A_NORMAL;
int use_xy = FALSE, use_attr = FALSE;
switch (ARG_COUNT(args)) {
case 1:
if (!PyArg_Parse(args,"s;str", &str))
return NULL;
break;
case 2:
if (!PyArg_Parse(args,"(sl);str,attr", &str, &attr))
return NULL;
use_attr = TRUE;
break;
case 3:
if (!PyArg_Parse(args,"(iis);y,x,str", &y, &x, &str))
return NULL;
use_xy = TRUE;
break;
case 4:
if (!PyArg_Parse(args,"(iisl);y,x,str,attr", &y, &x, &str, &attr))
return NULL;
use_xy = use_attr = TRUE;
break;
default:
PyErr_SetString(PyExc_TypeError, "insstr requires 1 to 4 arguments");
return NULL;
}
if (use_attr == TRUE) {
attr_old = getattrs(self->win);
wattrset(self->win,attr);
}
if (use_xy == TRUE)
rtn = mvwinsstr(self->win,y,x,str);
else
rtn = winsstr(self->win,str);
if (use_attr == TRUE)
wattrset(self->win,attr_old);
return PyCursesCheckERR(rtn, "insstr");
}