blob: e485936d4f69dbaa87006226af4a55ebf150fb63 [file] [log] [blame]
Guido van Rossumf6971e21994-08-30 12:25:20 +00001/***********************************************************
2Copyright 1994 by Lance Ellinghouse,
3Cathedral City, California Republic, United States of America.
4
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the name of Lance Ellinghouse
12not be used in advertising or publicity pertaining to distribution
13of the software without specific, written prior permission.
14
15LANCE ELLINGHOUSE DISCLAIMS ALL WARRANTIES WITH REGARD TO
16THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17FITNESS, IN NO EVENT SHALL LANCE ELLINGHOUSE BE LIABLE FOR ANY SPECIAL,
18INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
19FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
23******************************************************************/
24
Guido van Rossumfbea2f31994-08-31 22:05:27 +000025/******************************************************************
Guido van Rossum56bf2351994-08-31 22:06:24 +000026This is a curses implementation. I have tried to be as complete
Guido van Rossumfbea2f31994-08-31 22:05:27 +000027as possible. If there are functions you need that are not included,
28please let me know and/or send me some diffs.
29
30There are 3 basic types exported by this module:
31 1) Screen - This is not currently used
32 2) Window - This is the basic type. This is equivalent to "WINDOW *".
33 3) Pad - This is similar to Window, but works with Pads as defined
34 in curses.
35
36Most of the routines can be looked up using the curses man page.
37
38Here is a list of the currently supported methods and attributes
39in the curses module:
40
41Return Value Func/Attr Description
42--------------------------------------------------------------------------
43StringObject __version__ This returns a string representing
44 the current version of this module
45WindowObject initscr() This initializes the screen for use
46None endwin() Closes down the screen and returns
47 things as they were before calling
48 initscr()
49True/FalseObject isendwin() Has endwin() been called?
50IntObject doupdate() Updates screen and returns number
51 of bytes written to screen
52WindowObject newwin(nlines,ncols,begin_y,begin_x)
53 newwin(begin_y,begin_x)
54 newwin() creates and returns
55 a new window.
56None beep() Beep the screen if possible
57None flash() Flash the screen if possible
58None ungetch(int) Push the int back so next getch()
59 will return it.
60 Note: argument is an INT, not a CHAR
61None flushinp() Flush all input buffers
62None cbreak() Enter cbreak mode
63None nocbreak() Leave cbreak mode
64None echo() Enter echo mode
65None noecho() Leave echo mode
66None nl() Enter nl mode
67None nonl() Leave nl mode
68None raw() Enter raw mode
69None noraw() Leave raw mode
70None intrflush(int) Set or reset interruptable flush
71 mode, int=1 if set, 0 if notset.
72None meta(int) Allow 8 bit or 7 bit chars.
73 int=1 is 8 bit, int=0 is 7 bit
74StringObject keyname(int) return the text representation
75 of a KEY_ value. (see below)
76
77Here is a list of the currently supported methods and attributes
78in the WindowObject:
79
80Return Value Func/Attr Description
81--------------------------------------------------------------------------
82IntObject refresh() Do refresh
83IntObject nooutrefresh() Mark for refresh but wait
84True/False mvwin(new_y,new_x) Move Window
85True/False move(new_y,new_x) Move Cursor
86WindowObject subwin(nlines,ncols,begin_y,begin_x)
87 subwin(begin_y,begin_x)
88True/False addch(y,x,ch,attr)
89 addch(y,x,ch)
90 addch(ch,attr)
91 addch(ch)
92True/False insch(y,x,ch,attr)
93 insch(y,x,ch)
94 insch(ch,attr)
95 insch(ch)
96True/False delch(y,x)
97 delch()
98True/False echochar(ch,attr)
99 echochar(ch)
100True/False addstr(y,x,str,attr)
101 addstr(y,x,str)
102 addstr(str,attr)
103 addstr(str)
104True/False attron(attr)
105True/False attroff(attr)
106True/False attrset(sttr)
107True/False standend()
108True/False standout()
109True/False box(vertch,horch) vertch and horch are INTS
110 box()
111None erase()
112None deleteln()
113None insertln()
114(y,x) getyx()
115(y,x) getbegyx()
116(y,x) getmaxyx()
117None clear()
118None clrtobot()
119None clrtoeol()
120None scroll()
121None touchwin()
122None touchline(start,count)
123IntObject getch(y,x)
124 getch()
125StringObject getstr(y,x)
126 getstr()
127IntObject inch(y,x)
128 inch()
129None clearok(int) int=0 or int=1
130None idlok(int) int=0 or int=1
131None leaveok(int) int=0 or int=1
132None scrollok(int) int=0 or int=1
133None setscrreg(top,bottom)
134None nodelay(int) int=0 or int=1
135None notimeout(int) int=0 or int=1
136******************************************************************/
137
138
Guido van Rossumf6971e21994-08-30 12:25:20 +0000139/* curses module */
140
141#include "allobjects.h"
142#include "fileobject.h"
143#include "modsupport.h"
144
145#include <curses.h>
146
147#include "rename1.h"
148
149typedef struct {
150 PyObject_HEAD
151 SCREEN *scr;
152} PyCursesScreenObject;
153
154typedef struct {
155 PyObject_HEAD
156 WINDOW *win;
157 WINDOW *parent;
158} PyCursesWindowObject;
159
160typedef struct {
161 PyObject_HEAD
162 WINDOW *pad;
163} PyCursesPadObject;
164
165staticforward PyTypeObject PyCursesScreen_Type;
166staticforward PyTypeObject PyCursesWindow_Type;
167staticforward PyTypeObject PyCursesPad_Type;
168
169#define PyCursesScreen_Check(v) ((v)->ob_type == &PyCursesScreen_Type)
170#define PyCursesWindow_Check(v) ((v)->ob_type == &PyCursesWindow_Type)
171#define PyCursesPad_Check(v) ((v)->ob_type == &PyCursesPad_Type)
172
173/* Defines */
174PyObject *PyCurses_OK;
175PyObject *PyCurses_ERR;
176
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000177/******************************************************************
178
179Change Log:
180
Guido van Rossum56bf2351994-08-31 22:06:24 +0000181Version 1.1: 94/08/31:
182 Minor fixes given by Guido.
183 Changed 'ncurses' to 'curses'
184 Changed '__version__' to 'version'
185 Added PyErr_Clear() where needed
186 Moved ACS_* attribute initialization to PyCurses_InitScr() to fix
187 crash on SGI
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000188Version 1.0: 94/08/30:
189 This is the first release of this software.
190 Released to the Internet via python-list@cwi.nl
191
192******************************************************************/
Guido van Rossum56bf2351994-08-31 22:06:24 +0000193char *PyCursesVersion = "1.1";
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000194
Guido van Rossumf6971e21994-08-30 12:25:20 +0000195/* ------------- SCREEN routines --------------- */
196#ifdef NOT_YET
197static PyObject *
198PyCursesScreen_New(arg)
199 PyObject * arg;
200{
201 char *term_type;
202 PyFileObject *in_fo;
203 PyFileObject *out_fo;
204 PyCursesScreenObject *xp;
205 xp = (PyObject *)PyObject_NEW(PyCursesScreenObject, &PyCursesScreen_Type);
206 if (xp == NULL)
207 return NULL;
208 return (PyObject *)xp;
209}
210#endif
211/* ------------- WINDOW routines --------------- */
212static PyObject *
213PyCursesWindow_New(win)
214 WINDOW *win;
215{
216 PyCursesWindowObject *wo;
217 wo = (PyCursesWindowObject *)PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type);
218 if (wo == NULL)
219 return NULL;
220 wo->win = win;
221 wo->parent = (WINDOW *)NULL;
222 return (PyObject *)wo;
223}
224
225static void
226PyCursesWindow_Dealloc(wo)
227 PyCursesWindowObject *wo;
228{
229 if (wo->win != stdscr)
230 delwin(wo->win);
231 PyMem_DEL(wo);
232}
233
234static PyObject *
235PyCursesWindow_Refresh(self,arg)
236 PyCursesWindowObject *self;
237 PyObject * arg;
238{
239 if (!PyArg_NoArgs(arg))
240 return (PyObject *)NULL;
241 return (PyObject *)PyInt_FromLong(wrefresh(self->win));
242}
243
244static PyObject *
245PyCursesWindow_NoOutRefresh(self,arg)
246 PyCursesWindowObject *self;
247 PyObject * arg;
248{
249 if (!PyArg_NoArgs(arg))
250 return (PyObject *)NULL;
251 return (PyObject *)PyInt_FromLong(wnoutrefresh(self->win));
252}
253
254static PyObject *
255PyCursesWindow_MoveWin(self,arg)
256 PyCursesWindowObject *self;
257 PyObject * arg;
258{
259 int rtn;
260 int x, y;
261 if (!PyArg_Parse(arg,"(ii)", &y, &x))
262 return (PyObject *)NULL;
263 rtn = mvwin(self->win,y,x);
264 if (rtn == OK) {
265 Py_INCREF(PyCurses_OK);
266 return (PyObject *)PyCurses_OK;
267 }
268 Py_INCREF(PyCurses_ERR);
269 return (PyObject *)PyCurses_ERR;
270}
271
272static PyObject *
273PyCursesWindow_Move(self,arg)
274 PyCursesWindowObject *self;
275 PyObject * arg;
276{
277 int rtn;
278 int x, y;
279 if (!PyArg_Parse(arg,"(ii)", &y, &x))
280 return (PyObject *)NULL;
281 rtn = wmove(self->win,y,x);
282 if (rtn == OK) {
283 Py_INCREF(PyCurses_OK);
284 return (PyObject *)PyCurses_OK;
285 }
286 Py_INCREF(PyCurses_ERR);
287 return (PyObject *)PyCurses_ERR;
288}
289
290static PyObject *
291PyCursesWindow_SubWin(self,arg)
292 PyCursesWindowObject *self;
293 PyObject * arg;
294{
295 WINDOW *win;
296 PyCursesWindowObject *rtn_win;
297 int nlines, ncols, begin_y, begin_x;
298 nlines = 0;
299 ncols = 0;
300 if (!PyArg_Parse(arg,
301 "(iiii);nlines,ncols,begin_y,begin_x",
302 &nlines,&ncols,&begin_y,&begin_x))
303 if (!PyArg_Parse(arg,"(ii)",&begin_y,&begin_x))
304 return (PyObject *)NULL;
305 win = subwin(self->win,nlines,ncols,begin_y,begin_x);
306 if (win == NULL) {
307 Py_INCREF(Py_None);
308 return (PyObject *)Py_None;
309 }
310 rtn_win = (PyCursesWindowObject *)PyCursesWindow_New(win);
311 rtn_win->parent = self->win;
312 return (PyObject *)rtn_win;
313}
314
315static PyObject *
316PyCursesWindow_AddCh(self,arg)
317 PyCursesWindowObject *self;
318 PyObject * arg;
319{
320 int rtn;
321 int x, y;
322 int ch;
323 int attr;
324 int attr_old;
325 int use_xy = TRUE;
326 int use_attr = TRUE;
327 switch (PyTuple_Size(arg)) {
328 case 2:
329 case 4:
330 use_attr = TRUE;
331 break;
332 default:
333 use_attr = FALSE;
334 }
335 if (!PyArg_Parse(arg,"(iiii);y,x,ch,attr", &y, &x, &ch, &attr)) {
336 if (!PyArg_Parse(arg,"(iii);y,x,ch", &y, &x, &ch)) {
337 use_xy = FALSE;
338 if (!PyArg_Parse(arg,"(ii);ch,attr", &ch, &attr))
339 if (!PyArg_Parse(arg,"i;ch", &ch))
340 return (PyObject *)NULL;
341 }
342 }
343 if (use_attr == TRUE) {
344 attr_old = getattrs(self->win);
345 wattrset(self->win,attr);
346 }
347 if (use_xy == TRUE)
348 rtn = mvwaddch(self->win,y,x,ch);
349 else
350 rtn = waddch(self->win,ch);
351 if (use_attr == TRUE)
352 wattrset(self->win,attr_old);
353 if (rtn == OK) {
354 Py_INCREF(PyCurses_OK);
355 return (PyObject *)PyCurses_OK;
356 }
357 Py_INCREF(PyCurses_ERR);
358 return (PyObject *)PyCurses_ERR;
359}
360
361static PyObject *
362PyCursesWindow_InsCh(self,arg)
363 PyCursesWindowObject *self;
364 PyObject * arg;
365{
366 int rtn;
367 int x, y;
368 int ch;
369 int use_xy = TRUE;
370 int attr, attr_old, use_attr = FALSE;
371 switch (PyTuple_Size(arg)) {
372 case 2:
373 case 4:
374 use_attr = TRUE;
375 break;
376 default:
377 use_attr = FALSE;
378 }
379 if (!PyArg_Parse(arg,"(iiii);y,x,ch,attr", &y, &x, &ch, &attr)) {
380 if (!PyArg_Parse(arg,"(iii);y,x,ch", &y, &x, &ch)) {
381 use_xy = FALSE;
382 if (!PyArg_Parse(arg,"(ii);ch,attr", &ch, &attr))
383 if (!PyArg_Parse(arg,"i;ch", &ch))
384 return (PyObject *)NULL;
385 }
386 }
387 if (use_attr == TRUE) {
388 attr_old = getattrs(self->win);
389 wattrset(self->win,attr);
390 }
391 if (use_xy == TRUE)
392 rtn = mvwinsch(self->win,y,x,ch);
393 else
394 rtn = winsch(self->win,ch);
395 if (use_attr == TRUE)
396 wattrset(self->win,attr_old);
397 if (rtn == OK) {
398 Py_INCREF(PyCurses_OK);
399 return (PyObject *)PyCurses_OK;
400 }
401 Py_INCREF(PyCurses_ERR);
402 return (PyObject *)PyCurses_ERR;
403}
404
405static PyObject *
406PyCursesWindow_DelCh(self,arg)
407 PyCursesWindowObject *self;
408 PyObject * arg;
409{
410 int rtn;
411 int x, y;
412 int use_xy = TRUE;
413 if (!PyArg_Parse(arg,"(ii);y,x", &y, &x))
414 use_xy = FALSE;
Guido van Rossum56bf2351994-08-31 22:06:24 +0000415 PyErr_Clear();
Guido van Rossumf6971e21994-08-30 12:25:20 +0000416 if (use_xy == TRUE)
417 rtn = mvwdelch(self->win,y,x);
418 else
419 rtn = wdelch(self->win);
420 if (rtn == OK) {
421 Py_INCREF(PyCurses_OK);
422 return (PyObject *)PyCurses_OK;
423 }
424 Py_INCREF(PyCurses_ERR);
425 return (PyObject *)PyCurses_ERR;
426}
427
428static PyObject *
429PyCursesWindow_EchoChar(self,arg)
430 PyCursesWindowObject *self;
431 PyObject * arg;
432{
433 int rtn;
434 int ch;
435 int attr, attr_old, use_attr = TRUE;
436 if (!PyArg_Parse(arg,"(ii);ch,attr", &ch, &attr)) {
437 use_attr = FALSE;
438 if (!PyArg_Parse(arg,"i;ch", &ch))
439 return (PyObject *)NULL;
440 }
441 if (use_attr == TRUE) {
442 attr_old = getattrs(self->win);
443 wattrset(self->win,attr);
444 }
445 rtn = wechochar(self->win,ch);
446 if (use_attr == TRUE)
447 wattrset(self->win,attr_old);
448 if (rtn == OK) {
449 Py_INCREF(PyCurses_OK);
450 return (PyObject *)PyCurses_OK;
451 }
452 Py_INCREF(PyCurses_ERR);
453 return (PyObject *)PyCurses_ERR;
454}
455
456static PyObject *
457PyCursesWindow_AddStr(self,arg)
458 PyCursesWindowObject *self;
459 PyObject * arg;
460{
461 int rtn;
462 int x, y;
463 char *str;
464 int use_xy = TRUE;
465 int attr, attr_old, use_attr = TRUE;
466 switch (PyTuple_Size(arg)) {
467 case 2:
468 case 4:
469 use_attr = TRUE;
470 break;
471 default:
472 use_attr = FALSE;
473 }
474 if (!PyArg_Parse(arg,"(iisi);y,x,str,attr", &y, &x, &str, &attr)) {
475 if (!PyArg_Parse(arg,"(iis);y,x,str", &y, &x, &str)) {
476 use_xy = FALSE;
477 if (!PyArg_Parse(arg,"(si);str,attr", &str, &attr))
478 if (!PyArg_Parse(arg,"s;str", &str))
479 return (PyObject *)NULL;
480 }
481 }
482 if (use_attr == TRUE) {
483 attr_old = getattrs(self->win);
484 wattrset(self->win,attr);
485 }
486 if (use_xy == TRUE)
487 rtn = mvwaddstr(self->win,y,x,str);
488 else
489 rtn = waddstr(self->win,str);
490 if (use_attr == TRUE)
491 wattrset(self->win,attr_old);
492 if (rtn == OK) {
493 Py_INCREF(PyCurses_OK);
494 return (PyObject *)PyCurses_OK;
495 }
496 Py_INCREF(PyCurses_ERR);
497 return (PyObject *)PyCurses_ERR;
498}
499
500static PyObject *
501PyCursesWindow_AttrOn(self,arg)
502 PyCursesWindowObject *self;
503 PyObject * arg;
504{
505 int rtn;
506 int ch;
507 if (!PyArg_Parse(arg,"i;attr", &ch))
508 return (PyObject *)NULL;
509 rtn = wattron(self->win,ch);
510 if (rtn == OK) {
511 Py_INCREF(PyCurses_OK);
512 return (PyObject *)PyCurses_OK;
513 }
514 Py_INCREF(PyCurses_ERR);
515 return (PyObject *)PyCurses_ERR;
516}
517
518static PyObject *
519PyCursesWindow_AttrOff(self,arg)
520 PyCursesWindowObject *self;
521 PyObject * arg;
522{
523 int rtn;
524 int ch;
525 if (!PyArg_Parse(arg,"i;attr", &ch))
526 return (PyObject *)NULL;
527 rtn = wattroff(self->win,ch);
528 if (rtn == OK) {
529 Py_INCREF(PyCurses_OK);
530 return (PyObject *)PyCurses_OK;
531 }
532 Py_INCREF(PyCurses_ERR);
533 return (PyObject *)PyCurses_ERR;
534}
535
536static PyObject *
537PyCursesWindow_AttrSet(self,arg)
538 PyCursesWindowObject *self;
539 PyObject * arg;
540{
541 int rtn;
542 int ch;
543 if (!PyArg_Parse(arg,"i;attr", &ch))
544 return (PyObject *)NULL;
545 rtn = wattrset(self->win,ch);
546 if (rtn == OK) {
547 Py_INCREF(PyCurses_OK);
548 return (PyObject *)PyCurses_OK;
549 }
550 Py_INCREF(PyCurses_ERR);
551 return (PyObject *)PyCurses_ERR;
552}
553
554static PyObject *
555PyCursesWindow_StandEnd(self,arg)
556 PyCursesWindowObject *self;
557 PyObject * arg;
558{
559 int rtn;
560 if (!PyArg_NoArgs(arg))
561 return (PyObject *)NULL;
562 rtn = wstandend(self->win);
563 if (rtn == OK) {
564 Py_INCREF(PyCurses_OK);
565 return (PyObject *)PyCurses_OK;
566 }
567 Py_INCREF(PyCurses_ERR);
568 return (PyObject *)PyCurses_ERR;
569}
570
571static PyObject *
572PyCursesWindow_StandOut(self,arg)
573 PyCursesWindowObject *self;
574 PyObject * arg;
575{
576 int rtn;
577 if (!PyArg_NoArgs(arg))
578 return (PyObject *)NULL;
579 rtn = wstandout(self->win);
580 if (rtn == OK) {
581 Py_INCREF(PyCurses_OK);
582 return (PyObject *)PyCurses_OK;
583 }
584 Py_INCREF(PyCurses_ERR);
585 return (PyObject *)PyCurses_ERR;
586}
587
588static PyObject *
589PyCursesWindow_Box(self,arg)
590 PyCursesWindowObject *self;
591 PyObject * arg;
592{
593 int rtn;
594 int ch1=0,ch2=0;
595 if (!PyArg_Parse(arg,"(ii);vertch,horch", &ch1, &ch2))
596 PyErr_Clear();
597 rtn = box(self->win,ch1,ch2);
598 if (rtn == OK) {
599 Py_INCREF(PyCurses_OK);
600 return (PyObject *)PyCurses_OK;
601 }
602 Py_INCREF(PyCurses_ERR);
603 return (PyObject *)PyCurses_ERR;
604}
605
606static PyObject *
607PyCursesWindow_Erase(self,arg)
608 PyCursesWindowObject *self;
609 PyObject * arg;
610{
611 if (!PyArg_NoArgs(arg))
612 return (PyObject *)NULL;
613 werase(self->win);
614 Py_INCREF(Py_None);
615 return (PyObject *)Py_None;
616}
617
618static PyObject *
619PyCursesWindow_DeleteLine(self,arg)
620 PyCursesWindowObject *self;
621 PyObject * arg;
622{
623 if (!PyArg_NoArgs(arg))
624 return (PyObject *)NULL;
625 wdeleteln(self->win);
626 Py_INCREF(Py_None);
627 return (PyObject *)Py_None;
628}
629
630static PyObject *
631PyCursesWindow_InsertLine(self,arg)
632 PyCursesWindowObject *self;
633 PyObject * arg;
634{
635 if (!PyArg_NoArgs(arg))
636 return (PyObject *)NULL;
637 winsertln(self->win);
638 Py_INCREF(Py_None);
639 return (PyObject *)Py_None;
640}
641
642static PyObject *
643PyCursesWindow_GetYX(self,arg)
644 PyCursesWindowObject *self;
645 PyObject * arg;
646{
647 int x, y;
648 if (!PyArg_NoArgs(arg))
649 return (PyObject *)NULL;
650 getyx(self->win,y,x);
651 return (PyObject *)Py_BuildValue("(ii)", y, x);
652}
653
654static PyObject *
655PyCursesWindow_GetBegYX(self,arg)
656 PyCursesWindowObject *self;
657 PyObject * arg;
658{
659 int x, y;
660 if (!PyArg_NoArgs(arg))
661 return (PyObject *)NULL;
662 getbegyx(self->win,y,x);
663 return (PyObject *)Py_BuildValue("(ii)", y, x);
664}
665
666static PyObject *
667PyCursesWindow_GetMaxYX(self,arg)
668 PyCursesWindowObject *self;
669 PyObject * arg;
670{
671 int x, y;
672 if (!PyArg_NoArgs(arg))
673 return (PyObject *)NULL;
674 getmaxyx(self->win,y,x);
675 return (PyObject *)Py_BuildValue("(ii)", y, x);
676}
677
678static PyObject *
679PyCursesWindow_Clear(self,arg)
680 PyCursesWindowObject *self;
681 PyObject * arg;
682{
683 if (!PyArg_NoArgs(arg))
684 return (PyObject *)NULL;
685 wclear(self->win);
686 Py_INCREF(Py_None);
687 return (PyObject *)Py_None;
688}
689
690static PyObject *
691PyCursesWindow_ClearToBottom(self,arg)
692 PyCursesWindowObject *self;
693 PyObject * arg;
694{
695 if (!PyArg_NoArgs(arg))
696 return (PyObject *)NULL;
697 wclrtobot(self->win);
698 Py_INCREF(Py_None);
699 return (PyObject *)Py_None;
700}
701
702static PyObject *
703PyCursesWindow_ClearToEOL(self,arg)
704 PyCursesWindowObject *self;
705 PyObject * arg;
706{
707 if (!PyArg_NoArgs(arg))
708 return (PyObject *)NULL;
709 wclrtoeol(self->win);
710 Py_INCREF(Py_None);
711 return (PyObject *)Py_None;
712}
713
714static PyObject *
715PyCursesWindow_Scroll(self,arg)
716 PyCursesWindowObject *self;
717 PyObject * arg;
718{
719 if (!PyArg_NoArgs(arg))
720 return (PyObject *)NULL;
721 scroll(self->win);
722 Py_INCREF(Py_None);
723 return (PyObject *)Py_None;
724}
725
726static PyObject *
727PyCursesWindow_TouchWin(self,arg)
728 PyCursesWindowObject *self;
729 PyObject * arg;
730{
731 if (!PyArg_NoArgs(arg))
732 return (PyObject *)NULL;
733 touchwin(self->win);
734 Py_INCREF(Py_None);
735 return (PyObject *)Py_None;
736}
737
738static PyObject *
739PyCursesWindow_TouchLine(self,arg)
740 PyCursesWindowObject *self;
741 PyObject * arg;
742{
743 int st, cnt;
744 if (!PyArg_Parse(arg,"(ii);start, count",&st,&cnt))
745 return (PyObject *)NULL;
746 touchline(self->win,st,cnt);
747 Py_INCREF(Py_None);
748 return (PyObject *)Py_None;
749}
750
751static PyObject *
752PyCursesWindow_GetCh(self,arg)
753 PyCursesWindowObject *self;
754 PyObject * arg;
755{
756 int x, y;
757 int use_xy = TRUE;
758 int rtn;
759 if (!PyArg_Parse(arg,"(ii);y,x",&y,&x))
760 use_xy = FALSE;
Guido van Rossum56bf2351994-08-31 22:06:24 +0000761 PyErr_Clear();
Guido van Rossumf6971e21994-08-30 12:25:20 +0000762 if (use_xy == TRUE)
763 rtn = mvwgetch(self->win,y,x);
764 else
765 rtn = wgetch(self->win);
766 return (PyObject *)PyInt_FromLong(rtn);
767}
768
769static PyObject *
770PyCursesWindow_GetStr(self,arg)
771 PyCursesWindowObject *self;
772 PyObject * arg;
773{
774 int x, y;
775 int use_xy = TRUE;
776 char rtn[1024]; /* This should be big enough.. I hope */
777 int rtn2;
778 if (!PyArg_Parse(arg,"(ii);y,x",&y,&x))
779 use_xy = FALSE;
Guido van Rossum56bf2351994-08-31 22:06:24 +0000780 PyErr_Clear();
Guido van Rossumf6971e21994-08-30 12:25:20 +0000781 if (use_xy == TRUE)
782 rtn2 = mvwgetstr(self->win,y,x,rtn);
783 else
784 rtn2 = wgetstr(self->win,rtn);
785 if (rtn2 == ERR)
786 rtn[0] = 0;
787 return (PyObject *)PyString_FromString(rtn);
788}
789
790static PyObject *
791PyCursesWindow_InCh(self,arg)
792 PyCursesWindowObject *self;
793 PyObject * arg;
794{
795 int x, y;
796 int use_xy = TRUE;
797 int rtn;
798 if (!PyArg_Parse(arg,"(ii);y,x",&y,&x))
799 use_xy = FALSE;
Guido van Rossum56bf2351994-08-31 22:06:24 +0000800 PyErr_Clear();
Guido van Rossumf6971e21994-08-30 12:25:20 +0000801 if (use_xy == TRUE)
802 rtn = mvwinch(self->win,y,x);
803 else
804 rtn = winch(self->win);
805 return (PyObject *)PyInt_FromLong(rtn);
806}
807
808static PyObject *
809PyCursesWindow_ClearOk(self,arg)
810 PyCursesWindowObject *self;
811 PyObject * arg;
812{
813 int val;
814 if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val))
815 return (PyObject *)NULL;
816 clearok(self->win,val);
817 Py_INCREF(Py_None);
818 return (PyObject *)Py_None;
819}
820
821static PyObject *
822PyCursesWindow_IdlOk(self,arg)
823 PyCursesWindowObject *self;
824 PyObject * arg;
825{
826 int val;
827 if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val))
828 return (PyObject *)NULL;
829 idlok(self->win,val);
830 Py_INCREF(Py_None);
831 return (PyObject *)Py_None;
832}
833
834static PyObject *
835PyCursesWindow_LeaveOk(self,arg)
836 PyCursesWindowObject *self;
837 PyObject * arg;
838{
839 int val;
840 if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val))
841 return (PyObject *)NULL;
842 leaveok(self->win,val);
843 Py_INCREF(Py_None);
844 return (PyObject *)Py_None;
845}
846
847static PyObject *
848PyCursesWindow_ScrollOk(self,arg)
849 PyCursesWindowObject *self;
850 PyObject * arg;
851{
852 int val;
853 if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val))
854 return (PyObject *)NULL;
855 scrollok(self->win,val);
856 Py_INCREF(Py_None);
857 return (PyObject *)Py_None;
858}
859
860static PyObject *
861PyCursesWindow_SetScrollRegion(self,arg)
862 PyCursesWindowObject *self;
863 PyObject * arg;
864{
865 int x, y;
866 if (!PyArg_Parse(arg,"(ii);top, bottom",&y,&x))
867 return (PyObject *)NULL;
868 wsetscrreg(self->win,y,x);
869 Py_INCREF(Py_None);
870 return (PyObject *)Py_None;
871}
872
873static PyObject *
874PyCursesWindow_KeyPad(self,arg)
875 PyCursesWindowObject * self;
876 PyObject * arg;
877{
878 int ch;
879 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
880 return (PyObject *)NULL;
881 keypad(self->win,ch);
882 Py_INCREF(Py_None);
883 return (PyObject *)Py_None;
884}
885
886static PyObject *
887PyCursesWindow_NoDelay(self,arg)
888 PyCursesWindowObject * self;
889 PyObject * arg;
890{
891 int ch;
892 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
893 return (PyObject *)NULL;
894 nodelay(self->win,ch);
895 Py_INCREF(Py_None);
896 return (PyObject *)Py_None;
897}
898
899static PyObject *
900PyCursesWindow_NoTimeout(self,arg)
901 PyCursesWindowObject * self;
902 PyObject * arg;
903{
904 int ch;
905 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
906 return (PyObject *)NULL;
907 notimeout(self->win,ch);
908 Py_INCREF(Py_None);
909 return (PyObject *)Py_None;
910}
911
912static PyMethodDef PyCursesWindow_Methods[] = {
913 {"refresh", (PyCFunction)PyCursesWindow_Refresh},
914 {"nooutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh},
915 {"mvwin", (PyCFunction)PyCursesWindow_MoveWin},
916 {"move", (PyCFunction)PyCursesWindow_Move},
917 {"subwin", (PyCFunction)PyCursesWindow_SubWin},
918 {"addch", (PyCFunction)PyCursesWindow_AddCh},
919 {"insch", (PyCFunction)PyCursesWindow_InsCh},
920 {"delch", (PyCFunction)PyCursesWindow_DelCh},
921 {"echochar", (PyCFunction)PyCursesWindow_EchoChar},
922 {"addstr", (PyCFunction)PyCursesWindow_AddStr},
923 {"attron", (PyCFunction)PyCursesWindow_AttrOn},
924 {"attroff", (PyCFunction)PyCursesWindow_AttrOff},
925 {"attrset", (PyCFunction)PyCursesWindow_AttrSet},
926 {"standend", (PyCFunction)PyCursesWindow_StandEnd},
927 {"standout", (PyCFunction)PyCursesWindow_StandOut},
928 {"box", (PyCFunction)PyCursesWindow_Box},
929 {"erase", (PyCFunction)PyCursesWindow_Erase},
930 {"deleteln", (PyCFunction)PyCursesWindow_DeleteLine},
931 {"insertln", (PyCFunction)PyCursesWindow_InsertLine},
932 {"getyx", (PyCFunction)PyCursesWindow_GetYX},
933 {"getbegyx", (PyCFunction)PyCursesWindow_GetBegYX},
934 {"getmaxyx", (PyCFunction)PyCursesWindow_GetMaxYX},
935 {"clear", (PyCFunction)PyCursesWindow_Clear},
936 {"clrtobot", (PyCFunction)PyCursesWindow_ClearToBottom},
937 {"clrtoeol", (PyCFunction)PyCursesWindow_ClearToEOL},
938 {"scroll", (PyCFunction)PyCursesWindow_Scroll},
939 {"touchwin", (PyCFunction)PyCursesWindow_TouchWin},
940 {"touchline", (PyCFunction)PyCursesWindow_TouchLine},
941 {"getch", (PyCFunction)PyCursesWindow_GetCh},
942 {"getstr", (PyCFunction)PyCursesWindow_GetStr},
943 {"inch", (PyCFunction)PyCursesWindow_InCh},
944 {"clearok", (PyCFunction)PyCursesWindow_ClearOk},
945 {"idlok", (PyCFunction)PyCursesWindow_IdlOk},
946 {"leaveok", (PyCFunction)PyCursesWindow_LeaveOk},
947 {"scrollok", (PyCFunction)PyCursesWindow_ScrollOk},
948 {"setscrreg", (PyCFunction)PyCursesWindow_SetScrollRegion},
949 {"keypad", (PyCFunction)PyCursesWindow_KeyPad},
950 {"nodelay", (PyCFunction)PyCursesWindow_NoDelay},
951 {"notimeout", (PyCFunction)PyCursesWindow_NoTimeout},
952 {NULL, (PyCFunction)NULL} /* sentinel */
953};
954
955static PyObject *
956PyCursesWindow_GetAttr(self, name)
957 PyCursesWindowObject *self;
958 char *name;
959{
960 return findmethod(PyCursesWindow_Methods, (PyObject *)self, name);
961}
962
963/* --------------- PAD routines ---------------- */
964static PyObject *
965PyCursesPad_New(pad)
966 WINDOW *pad;
967{
968 PyCursesPadObject *po;
969 po = (PyCursesPadObject *)PyObject_NEW(PyCursesPadObject, &PyCursesPad_Type);
970 if (po == NULL)
971 return NULL;
972 po->pad = pad;
973 return (PyObject *)po;
974}
975
976/* -------------------------------------------------------*/
977static PyTypeObject PyCursesScreen_Type = {
978 PyObject_HEAD_INIT(&PyType_Type)
979 0, /*ob_size*/
980 "curses screen", /*tp_name*/
981 sizeof(PyCursesScreenObject), /*tp_basicsize*/
982 0, /*tp_itemsize*/
983 /* methods */
984 (destructor)0 /*PyCursesScreen_Dealloc*/, /*tp_dealloc*/
985 0, /*tp_print*/
986 (getattrfunc)0, /*tp_getattr*/
987 (setattrfunc)0, /*tp_setattr*/
988 0, /*tp_compare*/
989 0, /*tp_repr*/
990 0, /*tp_as_number*/
991 0, /*tp_as_sequence*/
992 0, /*tp_as_mapping*/
993 0, /*tp_hash*/
994};
995
996static PyTypeObject PyCursesWindow_Type = {
997 PyObject_HEAD_INIT(&PyType_Type)
998 0, /*ob_size*/
999 "curses window", /*tp_name*/
1000 sizeof(PyCursesWindowObject), /*tp_basicsize*/
1001 0, /*tp_itemsize*/
1002 /* methods */
1003 (destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/
1004 0, /*tp_print*/
1005 (getattrfunc)PyCursesWindow_GetAttr, /*tp_getattr*/
1006 (setattrfunc)0, /*tp_setattr*/
1007 0, /*tp_compare*/
1008 0, /*tp_repr*/
1009 0, /*tp_as_number*/
1010 0, /*tp_as_sequence*/
1011 0, /*tp_as_mapping*/
1012 0, /*tp_hash*/
1013};
1014
1015static PyTypeObject PyCursesPad_Type = {
1016 PyObject_HEAD_INIT(&PyType_Type)
1017 0, /*ob_size*/
1018 "curses pad", /*tp_name*/
1019 sizeof(PyCursesPadObject), /*tp_basicsize*/
1020 0, /*tp_itemsize*/
1021 /* methods */
1022 (destructor)0 /*PyCursesPad_Dealloc*/, /*tp_dealloc*/
1023 0, /*tp_print*/
1024 (getattrfunc)0, /*tp_getattr*/
1025 (setattrfunc)0, /*tp_setattr*/
1026 0, /*tp_compare*/
1027 0, /*tp_repr*/
1028 0, /*tp_as_number*/
1029 0, /*tp_as_sequence*/
1030 0, /*tp_as_mapping*/
1031 0, /*tp_hash*/
1032};
1033
1034/* -------------------------------------------------------*/
1035
1036static PyObject *
1037PyCurses_InitScr(self, args)
1038 PyObject * self;
1039 PyObject * args;
1040{
1041 static int already_inited = FALSE;
Guido van Rossum56bf2351994-08-31 22:06:24 +00001042 WINDOW *win;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001043 if (!PyArg_NoArgs(args))
1044 return (PyObject *)NULL;
1045 if (already_inited == TRUE) {
1046 wrefresh(stdscr);
1047 return (PyObject *)PyCursesWindow_New(stdscr);
1048 }
1049 already_inited = TRUE;
Guido van Rossum56bf2351994-08-31 22:06:24 +00001050
1051 win = initscr();
1052
1053/* This was moved from initcurses() because core dumped on SGI */
1054#define SetDictChar(string,ch) \
1055 PyDict_SetItemString(d,string,PyInt_FromLong(ch));
1056
1057 /* Here are some graphic symbols you can use */
1058 SetDictChar("ACS_ULCORNER",(ACS_ULCORNER));
1059 SetDictChar("ACS_ULCORNER",(ACS_ULCORNER));
1060 SetDictChar("ACS_LLCORNER",(ACS_LLCORNER));
1061 SetDictChar("ACS_URCORNER",(ACS_URCORNER));
1062 SetDictChar("ACS_LRCORNER",(ACS_LRCORNER));
1063 SetDictChar("ACS_RTEE", (ACS_RTEE));
1064 SetDictChar("ACS_LTEE", (ACS_LTEE));
1065 SetDictChar("ACS_BTEE", (ACS_BTEE));
1066 SetDictChar("ACS_TTEE", (ACS_TTEE));
1067 SetDictChar("ACS_HLINE", (ACS_HLINE));
1068 SetDictChar("ACS_VLINE", (ACS_VLINE));
1069 SetDictChar("ACS_PLUS", (ACS_PLUS));
1070 SetDictChar("ACS_S1", (ACS_S1));
1071 SetDictChar("ACS_S9", (ACS_S9));
1072 SetDictChar("ACS_DIAMOND", (ACS_DIAMOND));
1073 SetDictChar("ACS_CKBOARD", (ACS_CKBOARD));
1074 SetDictChar("ACS_DEGREE", (ACS_DEGREE));
1075 SetDictChar("ACS_PLMINUS", (ACS_PLMINUS));
1076 SetDictChar("ACS_BULLET", (ACS_BULLET));
1077 SetDictChar("ACS_LARROW", (ACS_RARROW));
1078 SetDictChar("ACS_DARROW", (ACS_DARROW));
1079 SetDictChar("ACS_UARROW", (ACS_UARROW));
1080 SetDictChar("ACS_BOARD", (ACS_BOARD));
1081 SetDictChar("ACS_LANTERN", (ACS_LANTERN));
1082 SetDictChar("ACS_BLOCK", (ACS_BLOCK));
1083
1084 return (PyObject *)PyCursesWindow_New(win);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001085}
1086
1087static PyObject *
1088PyCurses_EndWin(self, args)
1089 PyObject * self;
1090 PyObject * args;
1091{
1092 if (!PyArg_NoArgs(args))
1093 return (PyObject *)NULL;
1094 endwin();
1095 Py_INCREF(Py_None);
1096 return Py_None;
1097}
1098
1099static PyObject *
1100PyCurses_IsEndWin(self, args)
1101 PyObject * self;
1102 PyObject * args;
1103{
1104 if (!PyArg_NoArgs(args))
1105 return (PyObject *)NULL;
1106 if (isendwin() == FALSE) {
1107 Py_INCREF(Py_False);
1108 return Py_False;
1109 }
1110 Py_INCREF(Py_True);
1111 return Py_True;
1112}
1113
1114static PyObject *
1115PyCurses_DoUpdate(self,arg)
1116 PyObject * self;
1117 PyObject * arg;
1118{
1119 if (!PyArg_NoArgs(arg))
1120 return (PyObject *)NULL;
1121 return (PyObject *)PyInt_FromLong(doupdate());
1122}
1123
1124static PyObject *
1125PyCurses_NewWindow(self,arg)
1126 PyObject * self;
1127 PyObject * arg;
1128{
1129 WINDOW *win;
1130 int nlines, ncols, begin_y, begin_x;
1131 nlines = 0;
1132 ncols = 0;
1133 if (!PyArg_Parse(arg,
1134 "(iiii);nlines,ncols,begin_y,begin_x",
1135 &nlines,&ncols,&begin_y,&begin_x))
1136 if (!PyArg_Parse(arg,"(ii)",&begin_y,&begin_x))
1137 return (PyObject *)NULL;
1138 win = newwin(nlines,ncols,begin_y,begin_x);
1139 if (win == NULL) {
1140 Py_INCREF(Py_None);
1141 return (PyObject *)Py_None;
1142 }
1143 return (PyObject *)PyCursesWindow_New(win);
1144}
1145
1146static PyObject *
1147PyCurses_Beep(self,arg)
1148 PyObject * self;
1149 PyObject * arg;
1150{
1151 if (!PyArg_NoArgs(arg))
1152 return (PyObject *)NULL;
1153 beep();
1154 Py_INCREF(Py_None);
1155 return (PyObject *)Py_None;
1156}
1157
1158static PyObject *
1159PyCurses_Flash(self,arg)
1160 PyObject * self;
1161 PyObject * arg;
1162{
1163 if (!PyArg_NoArgs(arg))
1164 return (PyObject *)NULL;
1165 flash();
1166 Py_INCREF(Py_None);
1167 return (PyObject *)Py_None;
1168}
1169
1170static PyObject *
1171PyCurses_UngetCh(self,arg)
1172 PyObject * self;
1173 PyObject * arg;
1174{
1175 int ch;
1176 if (!PyArg_Parse(arg,"i;integer",&ch))
1177 return (PyObject *)NULL;
1178 ungetch(ch);
1179 Py_INCREF(Py_None);
1180 return (PyObject *)Py_None;
1181}
1182
1183static PyObject *
1184PyCurses_FlushInp(self,arg)
1185 PyObject * self;
1186 PyObject * arg;
1187{
1188 if (!PyArg_NoArgs(arg))
1189 return (PyObject *)NULL;
1190 flushinp();
1191 Py_INCREF(Py_None);
1192 return (PyObject *)Py_None;
1193}
1194
1195static PyObject *
1196PyCurses_CBreak(self,arg)
1197 PyObject * self;
1198 PyObject * arg;
1199{
1200 if (!PyArg_NoArgs(arg))
1201 return (PyObject *)NULL;
1202 cbreak();
1203 Py_INCREF(Py_None);
1204 return (PyObject *)Py_None;
1205}
1206
1207static PyObject *
1208PyCurses_NoCBreak(self,arg)
1209 PyObject * self;
1210 PyObject * arg;
1211{
1212 if (!PyArg_NoArgs(arg))
1213 return (PyObject *)NULL;
1214 nocbreak();
1215 Py_INCREF(Py_None);
1216 return (PyObject *)Py_None;
1217}
1218
1219static PyObject *
1220PyCurses_Echo(self,arg)
1221 PyObject * self;
1222 PyObject * arg;
1223{
1224 if (!PyArg_NoArgs(arg))
1225 return (PyObject *)NULL;
1226 echo();
1227 Py_INCREF(Py_None);
1228 return (PyObject *)Py_None;
1229}
1230
1231static PyObject *
1232PyCurses_NoEcho(self,arg)
1233 PyObject * self;
1234 PyObject * arg;
1235{
1236 if (!PyArg_NoArgs(arg))
1237 return (PyObject *)NULL;
1238 noecho();
1239 Py_INCREF(Py_None);
1240 return (PyObject *)Py_None;
1241}
1242
1243static PyObject *
1244PyCurses_Nl(self,arg)
1245 PyObject * self;
1246 PyObject * arg;
1247{
1248 if (!PyArg_NoArgs(arg))
1249 return (PyObject *)NULL;
1250 nl();
1251 Py_INCREF(Py_None);
1252 return (PyObject *)Py_None;
1253}
1254
1255static PyObject *
1256PyCurses_NoNl(self,arg)
1257 PyObject * self;
1258 PyObject * arg;
1259{
1260 if (!PyArg_NoArgs(arg))
1261 return (PyObject *)NULL;
1262 nonl();
1263 Py_INCREF(Py_None);
1264 return (PyObject *)Py_None;
1265}
1266
1267static PyObject *
1268PyCurses_Raw(self,arg)
1269 PyObject * self;
1270 PyObject * arg;
1271{
1272 if (!PyArg_NoArgs(arg))
1273 return (PyObject *)NULL;
1274 raw();
1275 Py_INCREF(Py_None);
1276 return (PyObject *)Py_None;
1277}
1278
1279static PyObject *
1280PyCurses_NoRaw(self,arg)
1281 PyObject * self;
1282 PyObject * arg;
1283{
1284 if (!PyArg_NoArgs(arg))
1285 return (PyObject *)NULL;
1286 noraw();
1287 Py_INCREF(Py_None);
1288 return (PyObject *)Py_None;
1289}
1290
1291static PyObject *
1292PyCurses_IntrFlush(self,arg)
1293 PyObject * self;
1294 PyObject * arg;
1295{
1296 int ch;
1297 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
1298 return (PyObject *)NULL;
1299 intrflush(NULL,ch);
1300 Py_INCREF(Py_None);
1301 return (PyObject *)Py_None;
1302}
1303
1304static PyObject *
1305PyCurses_Meta(self,arg)
1306 PyObject * self;
1307 PyObject * arg;
1308{
1309 int ch;
1310 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
1311 return (PyObject *)NULL;
1312 meta(NULL,ch);
1313 Py_INCREF(Py_None);
1314 return (PyObject *)Py_None;
1315}
1316
1317static PyObject *
1318PyCurses_KeyName(self,arg)
1319 PyObject * self;
1320 PyObject * arg;
1321{
1322 int ch;
1323 if (!PyArg_Parse(arg,"i",&ch))
1324 return (PyObject *)NULL;
1325 return PyString_FromString((char *)keyname(ch));
1326}
1327
1328#ifdef NOT_YET
1329static PyObject *
1330PyCurses_NewTerm(self, args)
1331 PyObject * self;
1332 PyObject * args;
1333{
1334}
1335
1336static PyObject *
1337PyCurses_SetTerm(self, args)
1338 PyObject * self;
1339 PyObject * args;
1340{
1341}
1342#endif
1343
1344/* List of functions defined in the module */
1345
1346static PyMethodDef PyCurses_methods[] = {
1347 {"initscr", (PyCFunction)PyCurses_InitScr},
1348 {"endwin", (PyCFunction)PyCurses_EndWin},
1349 {"isendwin", (PyCFunction)PyCurses_IsEndWin},
1350 {"doupdate", (PyCFunction)PyCurses_DoUpdate},
1351 {"newwin", (PyCFunction)PyCurses_NewWindow},
1352 {"beep", (PyCFunction)PyCurses_Beep},
1353 {"flash", (PyCFunction)PyCurses_Flash},
1354 {"ungetch", (PyCFunction)PyCurses_UngetCh},
1355 {"flushinp", (PyCFunction)PyCurses_FlushInp},
1356 {"cbreak", (PyCFunction)PyCurses_CBreak},
1357 {"nocbreak", (PyCFunction)PyCurses_NoCBreak},
1358 {"echo", (PyCFunction)PyCurses_Echo},
1359 {"noecho", (PyCFunction)PyCurses_NoEcho},
1360 {"nl", (PyCFunction)PyCurses_Nl},
1361 {"nonl", (PyCFunction)PyCurses_NoNl},
1362 {"raw", (PyCFunction)PyCurses_Raw},
1363 {"noraw", (PyCFunction)PyCurses_NoRaw},
1364 {"intrflush", (PyCFunction)PyCurses_IntrFlush},
1365 {"meta", (PyCFunction)PyCurses_Meta},
1366 {"keyname", (PyCFunction)PyCurses_KeyName},
1367#ifdef NOT_YET
1368 {"newterm", (PyCFunction)PyCurses_NewTerm},
1369 {"set_term", (PyCFunction)PyCurses_SetTerm},
1370#endif
1371 {NULL, NULL} /* sentinel */
1372};
1373
1374/* Initialization function for the module */
1375
1376void
Guido van Rossum56bf2351994-08-31 22:06:24 +00001377initcurses()
Guido van Rossumf6971e21994-08-30 12:25:20 +00001378{
1379 PyObject *m, *d, *x;
1380
1381 /* Create the module and add the functions */
Guido van Rossum56bf2351994-08-31 22:06:24 +00001382 m = Py_InitModule("curses", PyCurses_methods);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001383
1384 PyCurses_OK = Py_True;
1385 PyCurses_ERR = Py_False;
1386 Py_INCREF(PyCurses_OK);
1387 Py_INCREF(PyCurses_ERR);
1388 /* Add some symbolic constants to the module */
1389 d = PyModule_GetDict(m);
Guido van Rossumfbea2f31994-08-31 22:05:27 +00001390
1391 /* Make the version available */
Guido van Rossum56bf2351994-08-31 22:06:24 +00001392 PyDict_SetItemString(d,"version",
Guido van Rossumfbea2f31994-08-31 22:05:27 +00001393 PyString_FromString(PyCursesVersion));
1394
Guido van Rossumf6971e21994-08-30 12:25:20 +00001395 /* Here are some defines */
1396 PyDict_SetItemString(d,"OK", PyCurses_OK);
1397 PyDict_SetItemString(d,"ERR",PyCurses_ERR);
1398
Guido van Rossumf6971e21994-08-30 12:25:20 +00001399 /* Here are some attributes you can add to chars to print */
1400 PyDict_SetItemString(d, "A_NORMAL", PyInt_FromLong(A_NORMAL));
1401 PyDict_SetItemString(d, "A_STANDOUT", PyInt_FromLong(A_STANDOUT));
1402 PyDict_SetItemString(d, "A_UNDERLINE", PyInt_FromLong(A_UNDERLINE));
1403 PyDict_SetItemString(d, "A_REVERSE", PyInt_FromLong(A_REVERSE));
1404 PyDict_SetItemString(d, "A_BLINK", PyInt_FromLong(A_BLINK));
1405 PyDict_SetItemString(d, "A_DIM", PyInt_FromLong(A_DIM));
1406 PyDict_SetItemString(d, "A_BOLD", PyInt_FromLong(A_BOLD));
1407 PyDict_SetItemString(d, "A_ALTCHARSET",PyInt_FromLong(A_ALTCHARSET));
1408
1409 /* Now set everything up for KEY_ variables */
1410 {
1411 int key;
1412 char *key_n;
1413 char *key_n2;
1414 for (key=KEY_MIN;key < KEY_MAX; key++) {
1415 key_n = (char *)keyname(key);
1416 if (strcmp(key_n,"UNKNOWN KEY")==0)
1417 continue;
1418 if (strncmp(key_n,"KEY_F(",6)==0) {
1419 char *p1, *p2;
1420 key_n2 = malloc(strlen(key_n)+1);
1421 p1 = key_n;
1422 p2 = key_n2;
1423 while (*p1) {
1424 if (*p1 != '(' && *p1 != ')') {
1425 *p2 = *p1;
1426 p2++;
1427 }
1428 p1++;
1429 }
1430 *p2 = (char)0;
1431 } else
1432 key_n2 = key_n;
1433 PyDict_SetItemString(d,key_n2,PyInt_FromLong(key));
1434 if (key_n2 != key_n)
1435 free(key_n2);
1436 }
1437 SetDictChar("KEY_MIN",KEY_MIN);
1438 SetDictChar("KEY_MAX",KEY_MAX);
1439 }
1440
1441 /* Check for errors */
1442 if (PyErr_Occurred())
1443 Py_FatalError("can't initialize module syslog");
1444}