Fix an amazing number of typos & malformed sentences reported by Detlef
[python/dscho.git] / Modules / _cursesmodule.c
blobf76bf036fecaceb2099285d131ed2dc10b6ee8b9
1 /***********************************************************
2 Copyright 1994 by Lance Ellinghouse,
3 Cathedral City, California Republic, United States of America.
5 All Rights Reserved
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the name of Lance Ellinghouse
12 not be used in advertising or publicity pertaining to distribution
13 of the software without specific, written prior permission.
15 LANCE ELLINGHOUSE DISCLAIMS ALL WARRANTIES WITH REGARD TO
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 FITNESS, IN NO EVENT SHALL LANCE ELLINGHOUSE BE LIABLE FOR ANY SPECIAL,
18 INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
19 FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20 NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 ******************************************************************/
25 /******************************************************************
26 This is a curses implementation. I have tried to be as complete
27 as possible. If there are functions you need that are not included,
28 please let me know and/or send me some diffs.
30 There 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.
36 Most of the routines can be looked up using the curses man page.
38 Here is a list of the currently supported methods and attributes
39 in the curses module:
41 Return Value Func/Attr Description
42 --------------------------------------------------------------------------
43 StringObject version A string representing the current
44 version of this module.
45 WindowObject initscr() This initializes the screen for use
46 None endwin() Closes down the screen and returns
47 things as they were before calling
48 initscr()
49 True/FalseObject isendwin() Has endwin() been called?
50 None doupdate() Updates screen
51 WindowObject newwin(nlines,ncols,begin_y,begin_x)
52 newwin(begin_y,begin_x)
53 newwin() creates and returns
54 a new window.
55 None beep() Beep the screen if possible
56 None flash() Flash the screen if possible
57 None ungetch(int) Push the int back so next getch()
58 will return it.
59 Note: argument is an INT, not a CHAR
60 None flushinp() Flush all input buffers
61 None cbreak() Enter cbreak mode
62 None nocbreak() Leave cbreak mode
63 None echo() Enter echo mode
64 None noecho() Leave echo mode
65 None nl() Enter nl mode
66 None nonl() Leave nl mode
67 None raw() Enter raw mode
68 None noraw() Leave raw mode
69 None intrflush(int) Set or reset interruptable flush
70 mode, int=1 if set, 0 if notset.
71 None meta(int) Allow 8 bit or 7 bit chars.
72 int=1 is 8 bit, int=0 is 7 bit
73 StringObject keyname(int) return the text representation
74 of a KEY_ value. (see below)
76 Here is a list of the currently supported methods and attributes
77 in the WindowObject:
79 Return Value Func/Attr Description
80 --------------------------------------------------------------------------
81 None refresh() Do refresh
82 None nooutrefresh() Mark for refresh but wait
83 None mvwin(new_y,new_x) Move Window
84 None move(new_y,new_x) Move Cursor
85 WindowObject subwin(nlines,ncols,begin_y,begin_x)
86 subwin(begin_y,begin_x)
87 None addch(y,x,ch,attr)
88 addch(y,x,ch)
89 addch(ch,attr)
90 addch(ch)
91 None insch(y,x,ch,attr)
92 insch(y,x,ch)
93 insch(ch,attr)
94 insch(ch)
95 None delch(y,x)
96 delch()
97 None echochar(ch,attr)
98 echochar(ch)
99 None addstr(y,x,str,attr)
100 addstr(y,x,str)
101 addstr(str,attr)
102 addstr(str)
103 None attron(attr)
104 None attroff(attr)
105 None attrset(sttr)
106 None standend()
107 None standout()
108 None border(ls,rs,ts,bs,tl,tr,bl,br) (accepts 0-8 INT args)
109 None box(vertch,horch) vertch and horch are INTS
110 box()
111 None hline(y,x,ch,n)
112 hline(ch,n)
113 None vline(y,x,ch,n)
114 vline(ch,n)
115 None erase()
116 None deleteln()
117 None insertln()
118 (y,x) getyx()
119 (y,x) getbegyx()
120 (y,x) getmaxyx()
121 None clear()
122 None clrtobot()
123 None clrtoeol()
124 None scroll()
125 scroll(nlines)
126 None touchwin()
127 None touchline(start,count)
128 IntObject getch(y,x)
129 getch()
130 StringObject getstr(y,x)
131 getstr()
132 IntObject inch(y,x)
133 inch()
134 None clearok(int) int=0 or int=1
135 None idlok(int) int=0 or int=1
136 None leaveok(int) int=0 or int=1
137 None scrollok(int) int=0 or int=1
138 None setscrreg(top,bottom)
139 None keypad(int) int=0 or int=1
140 None nodelay(int) int=0 or int=1
141 None notimeout(int) int=0 or int=1
142 ******************************************************************/
145 /* curses module */
147 #include "Python.h"
149 #ifdef HAVE_NCURSES_H
150 /* Now let's hope there aren't systems that have a broken ncurses.h */
151 #include <ncurses.h>
152 #else
153 #include <curses.h>
154 #endif
156 typedef struct {
157 PyObject_HEAD
158 SCREEN *scr;
159 } PyCursesScreenObject;
161 typedef struct {
162 PyObject_HEAD
163 WINDOW *win;
164 WINDOW *parent;
165 } PyCursesWindowObject;
167 typedef struct {
168 PyObject_HEAD
169 WINDOW *pad;
170 } PyCursesPadObject;
172 #if 0
173 staticforward PyTypeObject PyCursesScreen_Type;
174 #endif
175 staticforward PyTypeObject PyCursesWindow_Type;
176 #if 0
177 staticforward PyTypeObject PyCursesPad_Type;
178 #endif
180 #define PyCursesScreen_Check(v) ((v)->ob_type == &PyCursesScreen_Type)
181 #define PyCursesWindow_Check(v) ((v)->ob_type == &PyCursesWindow_Type)
182 #define PyCursesPad_Check(v) ((v)->ob_type == &PyCursesPad_Type)
184 /* Defines */
185 static PyObject *PyCursesError; /* For exception curses.error */
187 /* Catch-all error messages */
188 static char *catchall_ERR = "curses function returned ERR";
189 static char *catchall_NULL = "curses function returned NULL";
191 /* Tells whether initscr() has been called to initialise curses */
192 static int initialised = FALSE;
194 #define ARG_COUNT(X) \
195 (((X) == NULL) ? 0 : (PyTuple_Check(X) ? PyTuple_Size(X) : 1))
197 /******************************************************************
199 Change Log:
201 Version 1.2: 95/02/23 (Steve Clift)
202 Fixed several potential core-dumping bugs.
203 Reworked arg parsing where variable arg lists are used.
204 Generate exceptions when ERR or NULL is returned by curses functions.
205 Changed return types to match SysV Curses manual descriptions.
206 Added keypad() to window method list.
207 Added border(), hline() and vline() window methods.
209 Version 1.1: 94/08/31:
210 Minor fixes given by Guido.
211 Changed 'ncurses' to 'curses'
212 Changed '__version__' to 'version'
213 Added PyErr_Clear() where needed
214 Moved ACS_* attribute initialization to PyCurses_InitScr() to fix
215 crash on SGI
217 Version 1.0: 94/08/30:
218 This is the first release of this software.
219 Released to the Internet via python-list@cwi.nl
221 ******************************************************************/
223 static char *PyCursesVersion = "1.2";
226 * Check the return code from a curses function and return None
227 * or raise an exception as appropriate.
230 static PyObject *
231 PyCursesCheckERR(code, fname)
232 int code;
233 char *fname;
235 char buf[100];
237 if (code != ERR) {
238 Py_INCREF(Py_None);
239 return Py_None;
240 } else {
241 if (fname == NULL) {
242 PyErr_SetString(PyCursesError, catchall_ERR);
243 } else {
244 strcpy(buf, fname);
245 strcat(buf, "() returned ERR");
246 PyErr_SetString(PyCursesError, buf);
248 return NULL;
253 static int
254 PyCursesInitialised()
256 if (initialised == TRUE)
257 return 1;
258 else {
259 PyErr_SetString(PyCursesError, "must call initscr() first");
260 return 0;
265 /* ------------- SCREEN routines --------------- */
267 #ifdef NOT_YET
268 static PyObject *
269 PyCursesScreen_New(arg)
270 PyObject * arg;
272 char *term_type;
273 PyFileObject *in_fo;
274 PyFileObject *out_fo;
275 PyCursesScreenObject *xp;
276 xp = PyObject_NEW(PyCursesScreenObject, &PyCursesScreen_Type);
277 if (xp == NULL)
278 return NULL;
279 return (PyObject *)xp;
281 #endif
284 /* ------------- WINDOW routines --------------- */
286 static PyObject *
287 PyCursesWindow_New(win)
288 WINDOW *win;
290 PyCursesWindowObject *wo;
292 wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type);
293 if (wo == NULL)
294 return NULL;
295 wo->win = win;
296 wo->parent = (WINDOW *)NULL;
297 return (PyObject *)wo;
300 static void
301 PyCursesWindow_Dealloc(wo)
302 PyCursesWindowObject *wo;
304 if (wo->win != stdscr)
305 delwin(wo->win);
306 PyMem_DEL(wo);
309 static PyObject *
310 PyCursesWindow_Refresh(self,arg)
311 PyCursesWindowObject *self;
312 PyObject * arg;
314 if (!PyArg_NoArgs(arg))
315 return NULL;
316 return PyCursesCheckERR(wrefresh(self->win), "wrefresh");
319 static PyObject *
320 PyCursesWindow_NoOutRefresh(self,arg)
321 PyCursesWindowObject *self;
322 PyObject * arg;
324 if (!PyArg_NoArgs(arg))
325 return NULL;
326 return PyCursesCheckERR(wnoutrefresh(self->win), "wnoutrefresh");
329 static PyObject *
330 PyCursesWindow_MoveWin(self,arg)
331 PyCursesWindowObject *self;
332 PyObject * arg;
334 int x, y;
335 if (!PyArg_Parse(arg,"(ii);y,x", &y, &x))
336 return NULL;
337 return PyCursesCheckERR(mvwin(self->win,y,x), "mvwin");
340 static PyObject *
341 PyCursesWindow_Move(self,arg)
342 PyCursesWindowObject *self;
343 PyObject * arg;
345 int x, y;
346 if (!PyArg_Parse(arg,"(ii);y,x", &y, &x))
347 return NULL;
348 return PyCursesCheckERR(wmove(self->win,y,x), "wmove");
351 static PyObject *
352 PyCursesWindow_SubWin(self,arg)
353 PyCursesWindowObject *self;
354 PyObject * arg;
356 WINDOW *win;
357 PyCursesWindowObject *rtn_win;
358 int nlines, ncols, begin_y, begin_x;
360 nlines = 0;
361 ncols = 0;
362 switch (ARG_COUNT(arg)) {
363 case 2:
364 if (!PyArg_Parse(arg,"(ii);begin_y,begin_x",&begin_y,&begin_x))
365 return NULL;
366 break;
367 case 4:
368 if (!PyArg_Parse(arg, "(iiii);nlines,ncols,begin_y,begin_x",
369 &nlines,&ncols,&begin_y,&begin_x))
370 return NULL;
371 break;
372 default:
373 PyErr_SetString(PyExc_TypeError, "subwin requires 2 or 4 arguments");
374 return NULL;
376 win = subwin(self->win,nlines,ncols,begin_y,begin_x);
377 if (win == NULL) {
378 PyErr_SetString(PyCursesError, catchall_NULL);
379 return NULL;
381 rtn_win = (PyCursesWindowObject *)PyCursesWindow_New(win);
382 rtn_win->parent = self->win;
383 return (PyObject *)rtn_win;
386 static PyObject *
387 PyCursesWindow_AddCh(self,arg)
388 PyCursesWindowObject *self;
389 PyObject * arg;
391 int rtn;
392 int x, y;
393 int ch;
394 int attr, attr_old = 0;
395 int use_xy = FALSE, use_attr = FALSE;
397 switch (ARG_COUNT(arg)) {
398 case 1:
399 if (!PyArg_Parse(arg, "i;ch", &ch))
400 return NULL;
401 break;
402 case 2:
403 if (!PyArg_Parse(arg,"(ii);ch,attr", &ch, &attr))
404 return NULL;
405 use_attr = TRUE;
406 break;
407 case 3:
408 if (!PyArg_Parse(arg,"(iii);y,x,ch", &y, &x, &ch))
409 return NULL;
410 use_xy = TRUE;
411 break;
412 case 4:
413 if (!PyArg_Parse(arg,"(iiii);y,x,ch,attr", &y, &x, &ch, &attr))
414 return NULL;
415 use_xy = use_attr = TRUE;
416 break;
417 default:
418 PyErr_SetString(PyExc_TypeError, "addch requires 1 to 4 arguments");
419 return NULL;
422 if (use_attr == TRUE) {
423 attr_old = getattrs(self->win);
424 wattrset(self->win,attr);
426 if (use_xy == TRUE)
427 rtn = mvwaddch(self->win,y,x,ch);
428 else
429 rtn = waddch(self->win,ch);
430 if (use_attr == TRUE)
431 wattrset(self->win,attr_old);
433 return PyCursesCheckERR(rtn, "[mv]waddch");
436 static PyObject *
437 PyCursesWindow_InsCh(self,arg)
438 PyCursesWindowObject *self;
439 PyObject * arg;
441 int rtn;
442 int x, y;
443 int ch;
444 int attr, attr_old = 0;
445 int use_xy = TRUE, use_attr = FALSE;
447 switch (ARG_COUNT(arg)) {
448 case 1:
449 if (!PyArg_Parse(arg, "i;ch", &ch))
450 return NULL;
451 break;
452 case 2:
453 if (!PyArg_Parse(arg,"(ii);ch,attr", &ch, &attr))
454 return NULL;
455 use_attr = TRUE;
456 break;
457 case 3:
458 if (!PyArg_Parse(arg,"(iii);y,x,ch", &y, &x, &ch))
459 return NULL;
460 use_xy = TRUE;
461 break;
462 case 4:
463 if (!PyArg_Parse(arg,"(iiii);y,x,ch,attr", &y, &x, &ch, &attr))
464 return NULL;
465 use_xy = use_attr = TRUE;
466 break;
467 default:
468 PyErr_SetString(PyExc_TypeError, "insch requires 1 to 4 arguments");
469 return NULL;
472 if (use_attr == TRUE) {
473 attr_old = getattrs(self->win);
474 wattrset(self->win,attr);
476 if (use_xy == TRUE)
477 rtn = mvwinsch(self->win,y,x,ch);
478 else
479 rtn = winsch(self->win,ch);
480 if (use_attr == TRUE)
481 wattrset(self->win,attr_old);
483 return PyCursesCheckERR(rtn, "[mv]winsch");
486 static PyObject *
487 PyCursesWindow_DelCh(self,arg)
488 PyCursesWindowObject *self;
489 PyObject * arg;
491 int rtn;
492 int x, y;
494 switch (ARG_COUNT(arg)) {
495 case 0:
496 rtn = wdelch(self->win);
497 break;
498 case 2:
499 if (!PyArg_Parse(arg,"(ii);y,x", &y, &x))
500 return NULL;
501 rtn = mvwdelch(self->win,y,x);
502 break;
503 default:
504 PyErr_SetString(PyExc_TypeError, "delch requires 0 or 2 arguments");
505 return NULL;
508 return PyCursesCheckERR(rtn, "[mv]wdelch");
511 static PyObject *
512 PyCursesWindow_EchoChar(self,arg)
513 PyCursesWindowObject *self;
514 PyObject * arg;
516 int rtn;
517 int ch;
518 int attr, attr_old;
520 switch (ARG_COUNT(arg)) {
521 case 1:
522 if (!PyArg_Parse(arg,"i;ch", &ch))
523 return NULL;
524 rtn = wechochar(self->win,ch);
525 break;
526 case 2:
527 if (!PyArg_Parse(arg,"(ii);ch,attr", &ch, &attr))
528 return NULL;
529 attr_old = getattrs(self->win);
530 wattrset(self->win,attr);
531 rtn = wechochar(self->win,ch);
532 wattrset(self->win,attr_old);
533 break;
534 default:
535 PyErr_SetString(PyExc_TypeError, "echochar requires 1 or 2 arguments");
536 return NULL;
539 return PyCursesCheckERR(rtn, "wechochar");
542 static PyObject *
543 PyCursesWindow_AddStr(self,arg)
544 PyCursesWindowObject *self;
545 PyObject * arg;
547 int rtn;
548 int x, y;
549 char *str;
550 int attr, attr_old = 0;
551 int use_xy = FALSE, use_attr = FALSE;
553 switch (ARG_COUNT(arg)) {
554 case 1:
555 if (!PyArg_Parse(arg,"s;str", &str))
556 return NULL;
557 break;
558 case 2:
559 if (!PyArg_Parse(arg,"(si);str,attr", &str, &attr))
560 return NULL;
561 use_attr = TRUE;
562 break;
563 case 3:
564 if (!PyArg_Parse(arg,"(iis);y,x,str", &y, &x, &str))
565 return NULL;
566 use_xy = TRUE;
567 break;
568 case 4:
569 if (!PyArg_Parse(arg,"(iisi);y,x,str,attr", &y, &x, &str, &attr))
570 return NULL;
571 use_xy = use_attr = TRUE;
572 break;
573 default:
574 PyErr_SetString(PyExc_TypeError, "addstr requires 1 to 4 arguments");
575 return NULL;
578 if (use_attr == TRUE) {
579 attr_old = getattrs(self->win);
580 wattrset(self->win,attr);
582 if (use_xy == TRUE)
583 rtn = mvwaddstr(self->win,y,x,str);
584 else
585 rtn = waddstr(self->win,str);
586 if (use_attr == TRUE)
587 wattrset(self->win,attr_old);
589 return PyCursesCheckERR(rtn, "[mv]waddstr");
592 static PyObject *
593 PyCursesWindow_AttrOn(self,arg)
594 PyCursesWindowObject *self;
595 PyObject * arg;
597 int ch;
598 if (!PyArg_Parse(arg,"i;attr", &ch))
599 return NULL;
600 wattron(self->win,ch);
601 Py_INCREF(Py_None);
602 return Py_None;
605 static PyObject *
606 PyCursesWindow_AttrOff(self,arg)
607 PyCursesWindowObject *self;
608 PyObject * arg;
610 int ch;
611 if (!PyArg_Parse(arg,"i;attr", &ch))
612 return NULL;
613 wattroff(self->win,ch);
614 Py_INCREF(Py_None);
615 return Py_None;
618 static PyObject *
619 PyCursesWindow_AttrSet(self,arg)
620 PyCursesWindowObject *self;
621 PyObject * arg;
623 int ch;
624 if (!PyArg_Parse(arg,"i;attr", &ch))
625 return NULL;
626 wattrset(self->win,ch);
627 Py_INCREF(Py_None);
628 return Py_None;
631 static PyObject *
632 PyCursesWindow_StandEnd(self,arg)
633 PyCursesWindowObject *self;
634 PyObject * arg;
636 if (!PyArg_NoArgs(arg))
637 return NULL;
638 wstandend(self->win);
639 Py_INCREF(Py_None);
640 return Py_None;
643 static PyObject *
644 PyCursesWindow_StandOut(self,arg)
645 PyCursesWindowObject *self;
646 PyObject * arg;
648 if (!PyArg_NoArgs(arg))
649 return NULL;
650 wstandout(self->win);
651 Py_INCREF(Py_None);
652 return Py_None;
655 static PyObject *
656 PyCursesWindow_Border(self, args)
657 PyCursesWindowObject *self;
658 PyObject *args;
660 int ls, rs, ts, bs, tl, tr, bl, br;
661 ls = rs = ts = bs = tl = tr = bl = br = 0;
662 if (!PyArg_ParseTuple(args,"|iiiiiiii;ls,rs,ts,bs,tl,tr,bl,br",
663 &ls, &rs, &ts, &bs, &tl, &tr, &bl, &br))
664 return NULL;
665 wborder(self->win, ls, rs, ts, bs, tl, tr, bl, br);
666 Py_INCREF(Py_None);
667 return Py_None;
670 static PyObject *
671 PyCursesWindow_Box(self,arg)
672 PyCursesWindowObject *self;
673 PyObject * arg;
675 int ch1=0,ch2=0;
676 if (!PyArg_NoArgs(arg)) {
677 PyErr_Clear();
678 if (!PyArg_Parse(arg,"(ii);vertch,horch", &ch1, &ch2))
679 return NULL;
681 box(self->win,ch1,ch2);
682 Py_INCREF(Py_None);
683 return Py_None;
686 static PyObject *
687 PyCursesWindow_Hline(self, args)
688 PyCursesWindowObject *self;
689 PyObject *args;
691 int ch, n, x, y, code = OK;
692 switch (ARG_COUNT(args)) {
693 case 2:
694 if (!PyArg_Parse(args, "(ii);ch,n", &ch, &n))
695 return NULL;
696 break;
697 case 4:
698 if (!PyArg_Parse(args, "(iiii);y,x,ch,n", &y, &x, &ch, &n))
699 return NULL;
700 code = wmove(self->win, y, x);
701 break;
702 default:
703 PyErr_SetString(PyExc_TypeError, "hline requires 2 or 4 arguments");
704 return NULL;
706 if (code != ERR)
707 whline(self->win, ch, n);
708 return PyCursesCheckERR(code, "wmove");
711 static PyObject *
712 PyCursesWindow_Vline(self, args)
713 PyCursesWindowObject *self;
714 PyObject *args;
716 int ch, n, x, y, code = OK;
717 switch (ARG_COUNT(args)) {
718 case 2:
719 if (!PyArg_Parse(args, "(ii);ch,n", &ch, &n))
720 return NULL;
721 break;
722 case 4:
723 if (!PyArg_Parse(args, "(iiii);y,x,ch,n", &y, &x, &ch, &n))
724 return NULL;
725 code = wmove(self->win, y, x);
726 break;
727 default:
728 PyErr_SetString(PyExc_TypeError, "vline requires 2 or 4 arguments");
729 return NULL;
731 if (code != ERR)
732 wvline(self->win, ch, n);
733 return PyCursesCheckERR(code, "wmove");
736 static PyObject *
737 PyCursesWindow_Erase(self,arg)
738 PyCursesWindowObject *self;
739 PyObject * arg;
741 if (!PyArg_NoArgs(arg))
742 return NULL;
743 werase(self->win);
744 Py_INCREF(Py_None);
745 return Py_None;
748 static PyObject *
749 PyCursesWindow_DeleteLine(self,arg)
750 PyCursesWindowObject *self;
751 PyObject * arg;
753 if (!PyArg_NoArgs(arg))
754 return NULL;
755 return PyCursesCheckERR(wdeleteln(self->win), "wdeleteln");
758 static PyObject *
759 PyCursesWindow_InsertLine(self,arg)
760 PyCursesWindowObject *self;
761 PyObject * arg;
763 if (!PyArg_NoArgs(arg))
764 return NULL;
765 return PyCursesCheckERR(winsertln(self->win), "winsertln");
768 static PyObject *
769 PyCursesWindow_GetYX(self,arg)
770 PyCursesWindowObject *self;
771 PyObject * arg;
773 int x, y;
774 if (!PyArg_NoArgs(arg))
775 return NULL;
776 getyx(self->win,y,x);
777 return Py_BuildValue("(ii)", y, x);
780 static PyObject *
781 PyCursesWindow_GetBegYX(self,arg)
782 PyCursesWindowObject *self;
783 PyObject * arg;
785 int x, y;
786 if (!PyArg_NoArgs(arg))
787 return NULL;
788 getbegyx(self->win,y,x);
789 return Py_BuildValue("(ii)", y, x);
792 static PyObject *
793 PyCursesWindow_GetMaxYX(self,arg)
794 PyCursesWindowObject *self;
795 PyObject * arg;
797 int x, y;
798 if (!PyArg_NoArgs(arg))
799 return NULL;
800 getmaxyx(self->win,y,x);
801 return Py_BuildValue("(ii)", y, x);
804 static PyObject *
805 PyCursesWindow_Clear(self,arg)
806 PyCursesWindowObject *self;
807 PyObject * arg;
809 if (!PyArg_NoArgs(arg))
810 return NULL;
811 wclear(self->win);
812 Py_INCREF(Py_None);
813 return Py_None;
816 static PyObject *
817 PyCursesWindow_ClearToBottom(self,arg)
818 PyCursesWindowObject *self;
819 PyObject * arg;
821 if (!PyArg_NoArgs(arg))
822 return NULL;
823 wclrtobot(self->win);
824 Py_INCREF(Py_None);
825 return Py_None;
828 static PyObject *
829 PyCursesWindow_ClearToEOL(self,arg)
830 PyCursesWindowObject *self;
831 PyObject * arg;
833 if (!PyArg_NoArgs(arg))
834 return NULL;
835 wclrtoeol(self->win);
836 Py_INCREF(Py_None);
837 return Py_None;
840 static PyObject *
841 PyCursesWindow_Scroll(self,arg)
842 PyCursesWindowObject *self;
843 PyObject * arg;
845 int nlines;
846 int use_nlines = FALSE;
847 switch (ARG_COUNT(arg)) {
848 case 0:
849 break;
850 case 1:
851 if (!PyArg_Parse(arg, "i;nlines", &nlines))
852 return NULL;
853 use_nlines = TRUE;
854 break;
855 default:
856 PyErr_SetString(PyExc_TypeError, "scroll requires 0 or 1 arguments");
857 return NULL;
859 if (use_nlines)
860 return PyCursesCheckERR(wscrl(self->win, nlines), "scroll");
861 else
862 return PyCursesCheckERR(scroll(self->win), "scroll");
865 static PyObject *
866 PyCursesWindow_TouchWin(self,arg)
867 PyCursesWindowObject *self;
868 PyObject * arg;
870 if (!PyArg_NoArgs(arg))
871 return NULL;
872 return PyCursesCheckERR(touchwin(self->win), "touchwin");
875 static PyObject *
876 PyCursesWindow_TouchLine(self,arg)
877 PyCursesWindowObject *self;
878 PyObject * arg;
880 int st, cnt;
881 if (!PyArg_Parse(arg,"(ii);start,count",&st,&cnt))
882 return NULL;
883 return PyCursesCheckERR(touchline(self->win,st,cnt), "touchline");
886 static PyObject *
887 PyCursesWindow_GetCh(self,arg)
888 PyCursesWindowObject *self;
889 PyObject * arg;
891 int x, y;
892 int rtn;
894 switch (ARG_COUNT(arg)) {
895 case 0:
896 rtn = wgetch(self->win);
897 break;
898 case 2:
899 if (!PyArg_Parse(arg,"(ii);y,x",&y,&x))
900 return NULL;
901 rtn = mvwgetch(self->win,y,x);
902 break;
903 default:
904 PyErr_SetString(PyExc_TypeError, "getch requires 0 or 2 arguments");
905 return NULL;
908 return PyInt_FromLong((long) rtn);
911 static PyObject *
912 PyCursesWindow_GetStr(self,arg)
913 PyCursesWindowObject *self;
914 PyObject * arg;
916 int x, y;
917 char rtn[1024]; /* This should be big enough.. I hope */
918 int rtn2;
920 switch (ARG_COUNT(arg)) {
921 case 0:
922 rtn2 = wgetstr(self->win,rtn);
923 break;
924 case 2:
925 if (!PyArg_Parse(arg,"(ii);y,x",&y,&x))
926 return NULL;
927 rtn2 = mvwgetstr(self->win,y,x,rtn);
928 break;
929 default:
930 PyErr_SetString(PyExc_TypeError, "getstr requires 0 or 2 arguments");
931 return NULL;
934 if (rtn2 == ERR)
935 rtn[0] = 0;
936 return PyString_FromString(rtn);
939 static PyObject *
940 PyCursesWindow_InCh(self,arg)
941 PyCursesWindowObject *self;
942 PyObject * arg;
944 int x, y, rtn;
946 switch (ARG_COUNT(arg)) {
947 case 0:
948 rtn = winch(self->win);
949 break;
950 case 2:
951 if (!PyArg_Parse(arg,"(ii);y,x",&y,&x))
952 return NULL;
953 rtn = mvwinch(self->win,y,x);
954 break;
955 default:
956 PyErr_SetString(PyExc_TypeError, "inch requires 0 or 2 arguments");
957 return NULL;
960 return PyInt_FromLong((long) rtn);
963 static PyObject *
964 PyCursesWindow_ClearOk(self,arg)
965 PyCursesWindowObject *self;
966 PyObject * arg;
968 int val;
969 if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val))
970 return NULL;
971 clearok(self->win,val);
972 Py_INCREF(Py_None);
973 return Py_None;
976 static PyObject *
977 PyCursesWindow_IdlOk(self,arg)
978 PyCursesWindowObject *self;
979 PyObject * arg;
981 int val;
982 if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val))
983 return NULL;
984 idlok(self->win,val);
985 Py_INCREF(Py_None);
986 return Py_None;
989 static PyObject *
990 PyCursesWindow_LeaveOk(self,arg)
991 PyCursesWindowObject *self;
992 PyObject * arg;
994 int val;
995 if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val))
996 return NULL;
997 leaveok(self->win,val);
998 Py_INCREF(Py_None);
999 return Py_None;
1002 static PyObject *
1003 PyCursesWindow_ScrollOk(self,arg)
1004 PyCursesWindowObject *self;
1005 PyObject * arg;
1007 int val;
1008 if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val))
1009 return NULL;
1010 scrollok(self->win,val);
1011 Py_INCREF(Py_None);
1012 return Py_None;
1015 static PyObject *
1016 PyCursesWindow_SetScrollRegion(self,arg)
1017 PyCursesWindowObject *self;
1018 PyObject * arg;
1020 int x, y;
1021 if (!PyArg_Parse(arg,"(ii);top, bottom",&y,&x))
1022 return NULL;
1023 return PyCursesCheckERR(wsetscrreg(self->win,y,x), "wsetscrreg");
1026 static PyObject *
1027 PyCursesWindow_KeyPad(self,arg)
1028 PyCursesWindowObject * self;
1029 PyObject * arg;
1031 int ch;
1032 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
1033 return NULL;
1034 keypad(self->win,ch);
1035 Py_INCREF(Py_None);
1036 return Py_None;
1039 static PyObject *
1040 PyCursesWindow_NoDelay(self,arg)
1041 PyCursesWindowObject * self;
1042 PyObject * arg;
1044 int ch;
1045 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
1046 return NULL;
1047 nodelay(self->win,ch);
1048 Py_INCREF(Py_None);
1049 return Py_None;
1052 static PyObject *
1053 PyCursesWindow_NoTimeout(self,arg)
1054 PyCursesWindowObject * self;
1055 PyObject * arg;
1057 int ch;
1058 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
1059 return NULL;
1060 notimeout(self->win,ch);
1061 Py_INCREF(Py_None);
1062 return Py_None;
1065 static PyMethodDef PyCursesWindow_Methods[] = {
1066 {"refresh", (PyCFunction)PyCursesWindow_Refresh},
1067 {"nooutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh},
1068 {"mvwin", (PyCFunction)PyCursesWindow_MoveWin},
1069 {"move", (PyCFunction)PyCursesWindow_Move},
1070 {"subwin", (PyCFunction)PyCursesWindow_SubWin},
1071 {"addch", (PyCFunction)PyCursesWindow_AddCh},
1072 {"insch", (PyCFunction)PyCursesWindow_InsCh},
1073 {"delch", (PyCFunction)PyCursesWindow_DelCh},
1074 {"echochar", (PyCFunction)PyCursesWindow_EchoChar},
1075 {"addstr", (PyCFunction)PyCursesWindow_AddStr},
1076 {"attron", (PyCFunction)PyCursesWindow_AttrOn},
1077 {"attroff", (PyCFunction)PyCursesWindow_AttrOff},
1078 {"attrset", (PyCFunction)PyCursesWindow_AttrSet},
1079 {"standend", (PyCFunction)PyCursesWindow_StandEnd},
1080 {"standout", (PyCFunction)PyCursesWindow_StandOut},
1081 {"border", (PyCFunction)PyCursesWindow_Border, METH_VARARGS},
1082 {"box", (PyCFunction)PyCursesWindow_Box},
1083 {"hline", (PyCFunction)PyCursesWindow_Hline},
1084 {"vline", (PyCFunction)PyCursesWindow_Vline},
1085 {"erase", (PyCFunction)PyCursesWindow_Erase},
1086 {"deleteln", (PyCFunction)PyCursesWindow_DeleteLine},
1087 {"insertln", (PyCFunction)PyCursesWindow_InsertLine},
1088 {"getyx", (PyCFunction)PyCursesWindow_GetYX},
1089 {"getbegyx", (PyCFunction)PyCursesWindow_GetBegYX},
1090 {"getmaxyx", (PyCFunction)PyCursesWindow_GetMaxYX},
1091 {"clear", (PyCFunction)PyCursesWindow_Clear},
1092 {"clrtobot", (PyCFunction)PyCursesWindow_ClearToBottom},
1093 {"clrtoeol", (PyCFunction)PyCursesWindow_ClearToEOL},
1094 {"scroll", (PyCFunction)PyCursesWindow_Scroll},
1095 {"touchwin", (PyCFunction)PyCursesWindow_TouchWin},
1096 {"touchline", (PyCFunction)PyCursesWindow_TouchLine},
1097 {"getch", (PyCFunction)PyCursesWindow_GetCh},
1098 {"getstr", (PyCFunction)PyCursesWindow_GetStr},
1099 {"inch", (PyCFunction)PyCursesWindow_InCh},
1100 {"clearok", (PyCFunction)PyCursesWindow_ClearOk},
1101 {"idlok", (PyCFunction)PyCursesWindow_IdlOk},
1102 {"leaveok", (PyCFunction)PyCursesWindow_LeaveOk},
1103 {"scrollok", (PyCFunction)PyCursesWindow_ScrollOk},
1104 {"setscrreg", (PyCFunction)PyCursesWindow_SetScrollRegion},
1105 {"keypad", (PyCFunction)PyCursesWindow_KeyPad},
1106 {"nodelay", (PyCFunction)PyCursesWindow_NoDelay},
1107 {"notimeout", (PyCFunction)PyCursesWindow_NoTimeout},
1108 {NULL, NULL} /* sentinel */
1111 static PyObject *
1112 PyCursesWindow_GetAttr(self, name)
1113 PyCursesWindowObject *self;
1114 char *name;
1116 return Py_FindMethod(PyCursesWindow_Methods, (PyObject *)self, name);
1120 /* --------------- PAD routines ---------------- */
1122 #ifdef NOT_YET
1123 static PyObject *
1124 PyCursesPad_New(pad)
1125 WINDOW *pad;
1127 PyCursesPadObject *po;
1128 po = PyObject_NEW(PyCursesPadObject, &PyCursesPad_Type);
1129 if (po == NULL)
1130 return NULL;
1131 po->pad = pad;
1132 return (PyObject *)po;
1134 #endif
1137 /* -------------------------------------------------------*/
1139 #if 0
1140 static PyTypeObject PyCursesScreen_Type = {
1141 PyObject_HEAD_INIT(&PyType_Type)
1142 0, /*ob_size*/
1143 "curses screen", /*tp_name*/
1144 sizeof(PyCursesScreenObject), /*tp_basicsize*/
1145 0, /*tp_itemsize*/
1146 /* methods */
1147 (destructor)0 /*PyCursesScreen_Dealloc*/, /*tp_dealloc*/
1148 0, /*tp_print*/
1149 (getattrfunc)0, /*tp_getattr*/
1150 (setattrfunc)0, /*tp_setattr*/
1151 0, /*tp_compare*/
1152 0, /*tp_repr*/
1153 0, /*tp_as_number*/
1154 0, /*tp_as_sequence*/
1155 0, /*tp_as_mapping*/
1156 0, /*tp_hash*/
1158 #endif
1160 static PyTypeObject PyCursesWindow_Type = {
1161 PyObject_HEAD_INIT(&PyType_Type)
1162 0, /*ob_size*/
1163 "curses window", /*tp_name*/
1164 sizeof(PyCursesWindowObject), /*tp_basicsize*/
1165 0, /*tp_itemsize*/
1166 /* methods */
1167 (destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/
1168 0, /*tp_print*/
1169 (getattrfunc)PyCursesWindow_GetAttr, /*tp_getattr*/
1170 (setattrfunc)0, /*tp_setattr*/
1171 0, /*tp_compare*/
1172 0, /*tp_repr*/
1173 0, /*tp_as_number*/
1174 0, /*tp_as_sequence*/
1175 0, /*tp_as_mapping*/
1176 0, /*tp_hash*/
1179 #if 0
1180 static PyTypeObject PyCursesPad_Type = {
1181 PyObject_HEAD_INIT(&PyType_Type)
1182 0, /*ob_size*/
1183 "curses pad", /*tp_name*/
1184 sizeof(PyCursesPadObject), /*tp_basicsize*/
1185 0, /*tp_itemsize*/
1186 /* methods */
1187 (destructor)0 /*PyCursesPad_Dealloc*/, /*tp_dealloc*/
1188 0, /*tp_print*/
1189 (getattrfunc)0, /*tp_getattr*/
1190 (setattrfunc)0, /*tp_setattr*/
1191 0, /*tp_compare*/
1192 0, /*tp_repr*/
1193 0, /*tp_as_number*/
1194 0, /*tp_as_sequence*/
1195 0, /*tp_as_mapping*/
1196 0, /*tp_hash*/
1198 #endif
1201 /* -------------------------------------------------------*/
1203 static PyObject *ModDict;
1205 static PyObject *
1206 PyCurses_InitScr(self, args)
1207 PyObject * self;
1208 PyObject * args;
1210 WINDOW *win;
1211 if (!PyArg_NoArgs(args))
1212 return NULL;
1213 if (initialised == TRUE) {
1214 wrefresh(stdscr);
1215 return (PyObject *)PyCursesWindow_New(stdscr);
1218 win = initscr();
1219 if (win == NULL) {
1220 PyErr_SetString(PyCursesError, catchall_NULL);
1221 return NULL;
1224 initialised = TRUE;
1226 /* This was moved from initcurses() because core dumped on SGI */
1227 /* Also, they are probably not defined until you've called initscr() */
1228 #define SetDictInt(string,ch) \
1229 PyDict_SetItemString(ModDict,string,PyInt_FromLong((long) (ch)));
1231 /* Here are some graphic symbols you can use */
1232 SetDictInt("ACS_ULCORNER",(ACS_ULCORNER));
1233 SetDictInt("ACS_ULCORNER",(ACS_ULCORNER));
1234 SetDictInt("ACS_LLCORNER",(ACS_LLCORNER));
1235 SetDictInt("ACS_URCORNER",(ACS_URCORNER));
1236 SetDictInt("ACS_LRCORNER",(ACS_LRCORNER));
1237 SetDictInt("ACS_RTEE", (ACS_RTEE));
1238 SetDictInt("ACS_LTEE", (ACS_LTEE));
1239 SetDictInt("ACS_BTEE", (ACS_BTEE));
1240 SetDictInt("ACS_TTEE", (ACS_TTEE));
1241 SetDictInt("ACS_HLINE", (ACS_HLINE));
1242 SetDictInt("ACS_VLINE", (ACS_VLINE));
1243 SetDictInt("ACS_PLUS", (ACS_PLUS));
1244 SetDictInt("ACS_S1", (ACS_S1));
1245 SetDictInt("ACS_S9", (ACS_S9));
1246 SetDictInt("ACS_DIAMOND", (ACS_DIAMOND));
1247 SetDictInt("ACS_CKBOARD", (ACS_CKBOARD));
1248 SetDictInt("ACS_DEGREE", (ACS_DEGREE));
1249 SetDictInt("ACS_PLMINUS", (ACS_PLMINUS));
1250 SetDictInt("ACS_BULLET", (ACS_BULLET));
1251 SetDictInt("ACS_LARROW", (ACS_LARROW));
1252 SetDictInt("ACS_RARROW", (ACS_RARROW));
1253 SetDictInt("ACS_DARROW", (ACS_DARROW));
1254 SetDictInt("ACS_UARROW", (ACS_UARROW));
1255 SetDictInt("ACS_BOARD", (ACS_BOARD));
1256 SetDictInt("ACS_LANTERN", (ACS_LANTERN));
1257 SetDictInt("ACS_BLOCK", (ACS_BLOCK));
1259 return (PyObject *)PyCursesWindow_New(win);
1262 static PyObject *
1263 PyCurses_EndWin(self, args)
1264 PyObject * self;
1265 PyObject * args;
1267 if (!PyArg_NoArgs(args) || !PyCursesInitialised())
1268 return NULL;
1269 return PyCursesCheckERR(endwin(), "endwin");
1272 static PyObject *
1273 PyCurses_IsEndWin(self, args)
1274 PyObject * self;
1275 PyObject * args;
1277 if (!PyArg_NoArgs(args))
1278 return NULL;
1279 if (isendwin() == FALSE) {
1280 Py_INCREF(Py_False);
1281 return Py_False;
1283 Py_INCREF(Py_True);
1284 return Py_True;
1287 static PyObject *
1288 PyCurses_DoUpdate(self,arg)
1289 PyObject * self;
1290 PyObject * arg;
1292 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
1293 return NULL;
1294 return PyCursesCheckERR(doupdate(), "doupdate");
1297 static PyObject *
1298 PyCurses_NewWindow(self,arg)
1299 PyObject * self;
1300 PyObject * arg;
1302 WINDOW *win;
1303 int nlines, ncols, begin_y, begin_x;
1305 if (!PyCursesInitialised())
1306 return NULL;
1307 nlines = ncols = 0;
1308 switch (ARG_COUNT(arg)) {
1309 case 2:
1310 if (!PyArg_Parse(arg,"(ii);begin)_y,begin_x",&begin_y,&begin_x))
1311 return NULL;
1312 break;
1313 case 4:
1314 if (!PyArg_Parse(arg, "(iiii);nlines,ncols,begin_y,begin_x",
1315 &nlines,&ncols,&begin_y,&begin_x))
1316 return NULL;
1317 break;
1318 default:
1319 PyErr_SetString(PyExc_TypeError, "newwin requires 2 or 4 arguments");
1320 return NULL;
1323 win = newwin(nlines,ncols,begin_y,begin_x);
1324 if (win == NULL) {
1325 PyErr_SetString(PyCursesError, catchall_NULL);
1326 return NULL;
1329 return (PyObject *)PyCursesWindow_New(win);
1332 static PyObject *
1333 PyCurses_Beep(self,arg)
1334 PyObject * self;
1335 PyObject * arg;
1337 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
1338 return NULL;
1339 beep();
1340 Py_INCREF(Py_None);
1341 return Py_None;
1344 static PyObject *
1345 PyCurses_Flash(self,arg)
1346 PyObject * self;
1347 PyObject * arg;
1349 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
1350 return NULL;
1351 flash();
1352 Py_INCREF(Py_None);
1353 return Py_None;
1356 static PyObject *
1357 PyCurses_UngetCh(self,arg)
1358 PyObject * self;
1359 PyObject * arg;
1361 int ch;
1362 if (!PyArg_Parse(arg,"i;integer",&ch) || !PyCursesInitialised())
1363 return NULL;
1364 return PyCursesCheckERR(ungetch(ch), "ungetch");
1367 static PyObject *
1368 PyCurses_FlushInp(self,arg)
1369 PyObject * self;
1370 PyObject * arg;
1372 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
1373 return NULL;
1374 flushinp();
1375 Py_INCREF(Py_None);
1376 return Py_None;
1379 static PyObject *
1380 PyCurses_CBreak(self,arg)
1381 PyObject * self;
1382 PyObject * arg;
1384 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
1385 return NULL;
1386 return PyCursesCheckERR(cbreak(), "cbreak");
1389 static PyObject *
1390 PyCurses_NoCBreak(self,arg)
1391 PyObject * self;
1392 PyObject * arg;
1394 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
1395 return NULL;
1396 return PyCursesCheckERR(nocbreak(), "nocbreak");
1399 static PyObject *
1400 PyCurses_Echo(self,arg)
1401 PyObject * self;
1402 PyObject * arg;
1404 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
1405 return NULL;
1406 return PyCursesCheckERR(echo(), "echo");
1409 static PyObject *
1410 PyCurses_NoEcho(self,arg)
1411 PyObject * self;
1412 PyObject * arg;
1414 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
1415 return NULL;
1416 return PyCursesCheckERR(noecho(), "noecho");
1419 static PyObject *
1420 PyCurses_Nl(self,arg)
1421 PyObject * self;
1422 PyObject * arg;
1424 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
1425 return NULL;
1426 return PyCursesCheckERR(nl(), "nl");
1429 static PyObject *
1430 PyCurses_NoNl(self,arg)
1431 PyObject * self;
1432 PyObject * arg;
1434 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
1435 return NULL;
1436 return PyCursesCheckERR(nonl(), "nonl");
1439 static PyObject *
1440 PyCurses_Raw(self,arg)
1441 PyObject * self;
1442 PyObject * arg;
1444 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
1445 return NULL;
1446 return PyCursesCheckERR(raw(), "raw");
1449 static PyObject *
1450 PyCurses_NoRaw(self,arg)
1451 PyObject * self;
1452 PyObject * arg;
1454 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
1455 return NULL;
1456 return PyCursesCheckERR(noraw(), "noraw");
1459 static PyObject *
1460 PyCurses_IntrFlush(self,arg)
1461 PyObject * self;
1462 PyObject * arg;
1464 int ch;
1465 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
1466 return NULL;
1467 return PyCursesCheckERR(intrflush(NULL,ch), "intrflush");
1470 static PyObject *
1471 PyCurses_Meta(self,arg)
1472 PyObject * self;
1473 PyObject * arg;
1475 int ch;
1476 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch) || !PyCursesInitialised())
1477 return NULL;
1478 return PyCursesCheckERR(meta(stdscr, ch), "meta");
1481 static PyObject *
1482 PyCurses_KeyName(self,arg)
1483 PyObject * self;
1484 PyObject * arg;
1486 const char *knp;
1487 int ch;
1488 if (!PyArg_Parse(arg,"i",&ch))
1489 return NULL;
1490 knp = keyname(ch);
1491 return PyString_FromString((knp == NULL) ? "" : knp);
1494 #ifdef NOT_YET
1495 static PyObject *
1496 PyCurses_NewTerm(self, args)
1497 PyObject * self;
1498 PyObject * args;
1502 static PyObject *
1503 PyCurses_SetTerm(self, args)
1504 PyObject * self;
1505 PyObject * args;
1508 #endif
1510 /* List of functions defined in the module */
1512 static PyMethodDef PyCurses_methods[] = {
1513 {"initscr", (PyCFunction)PyCurses_InitScr},
1514 {"endwin", (PyCFunction)PyCurses_EndWin},
1515 {"isendwin", (PyCFunction)PyCurses_IsEndWin},
1516 {"doupdate", (PyCFunction)PyCurses_DoUpdate},
1517 {"newwin", (PyCFunction)PyCurses_NewWindow},
1518 {"beep", (PyCFunction)PyCurses_Beep},
1519 {"flash", (PyCFunction)PyCurses_Flash},
1520 {"ungetch", (PyCFunction)PyCurses_UngetCh},
1521 {"flushinp", (PyCFunction)PyCurses_FlushInp},
1522 {"cbreak", (PyCFunction)PyCurses_CBreak},
1523 {"nocbreak", (PyCFunction)PyCurses_NoCBreak},
1524 {"echo", (PyCFunction)PyCurses_Echo},
1525 {"noecho", (PyCFunction)PyCurses_NoEcho},
1526 {"nl", (PyCFunction)PyCurses_Nl},
1527 {"nonl", (PyCFunction)PyCurses_NoNl},
1528 {"raw", (PyCFunction)PyCurses_Raw},
1529 {"noraw", (PyCFunction)PyCurses_NoRaw},
1530 {"intrflush", (PyCFunction)PyCurses_IntrFlush},
1531 {"meta", (PyCFunction)PyCurses_Meta},
1532 {"keyname", (PyCFunction)PyCurses_KeyName},
1533 #ifdef NOT_YET
1534 {"newterm", (PyCFunction)PyCurses_NewTerm},
1535 {"set_term", (PyCFunction)PyCurses_SetTerm},
1536 #endif
1537 {NULL, NULL} /* sentinel */
1540 /* Initialization function for the module */
1542 DL_EXPORT(void)
1543 initcurses()
1545 PyObject *m, *d, *v;
1547 /* Create the module and add the functions */
1548 m = Py_InitModule("curses", PyCurses_methods);
1550 /* Add some symbolic constants to the module */
1551 d = PyModule_GetDict(m);
1552 ModDict = d; /* For PyCurses_InitScr */
1554 /* For exception curses.error */
1555 PyCursesError = PyErr_NewException("curses.error", NULL, NULL);
1556 PyDict_SetItemString(d, "error", PyCursesError);
1558 /* Make the version available */
1559 v = PyString_FromString(PyCursesVersion);
1560 PyDict_SetItemString(d, "version", v);
1561 PyDict_SetItemString(d, "__version__", v);
1562 Py_DECREF(v);
1564 /* Here are some attributes you can add to chars to print */
1565 SetDictInt("A_NORMAL", A_NORMAL);
1566 SetDictInt("A_STANDOUT", A_STANDOUT);
1567 SetDictInt("A_UNDERLINE", A_UNDERLINE);
1568 SetDictInt("A_REVERSE", A_REVERSE);
1569 SetDictInt("A_BLINK", A_BLINK);
1570 SetDictInt("A_DIM", A_DIM);
1571 SetDictInt("A_BOLD", A_BOLD);
1572 SetDictInt("A_ALTCHARSET", A_ALTCHARSET);
1574 /* Now set everything up for KEY_ variables */
1576 int key;
1577 char *key_n;
1578 char *key_n2;
1579 for (key=KEY_MIN;key < KEY_MAX; key++) {
1580 key_n = (char *)keyname(key);
1581 if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0)
1582 continue;
1583 if (strncmp(key_n,"KEY_F(",6)==0) {
1584 char *p1, *p2;
1585 key_n2 = malloc(strlen(key_n)+1);
1586 p1 = key_n;
1587 p2 = key_n2;
1588 while (*p1) {
1589 if (*p1 != '(' && *p1 != ')') {
1590 *p2 = *p1;
1591 p2++;
1593 p1++;
1595 *p2 = (char)0;
1596 } else
1597 key_n2 = key_n;
1598 PyDict_SetItemString(d,key_n2,PyInt_FromLong((long) key));
1599 if (key_n2 != key_n)
1600 free(key_n2);
1602 SetDictInt("KEY_MIN", KEY_MIN);
1603 SetDictInt("KEY_MAX", KEY_MAX);