blob: f76bf036fecaceb2099285d131ed2dc10b6ee8b9 [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--------------------------------------------------------------------------
Guido van Rossum85738471995-02-17 13:50:17 +000043StringObject version A string representing the current
44 version of this module.
Guido van Rossumfbea2f31994-08-31 22:05:27 +000045WindowObject 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?
Guido van Rossum85738471995-02-17 13:50:17 +000050None doupdate() Updates screen
Guido van Rossumfbea2f31994-08-31 22:05:27 +000051WindowObject newwin(nlines,ncols,begin_y,begin_x)
52 newwin(begin_y,begin_x)
53 newwin() creates and returns
54 a new window.
55None beep() Beep the screen if possible
56None flash() Flash the screen if possible
57None ungetch(int) Push the int back so next getch()
58 will return it.
59 Note: argument is an INT, not a CHAR
60None flushinp() Flush all input buffers
61None cbreak() Enter cbreak mode
62None nocbreak() Leave cbreak mode
63None echo() Enter echo mode
64None noecho() Leave echo mode
65None nl() Enter nl mode
66None nonl() Leave nl mode
67None raw() Enter raw mode
68None noraw() Leave raw mode
69None intrflush(int) Set or reset interruptable flush
70 mode, int=1 if set, 0 if notset.
71None meta(int) Allow 8 bit or 7 bit chars.
72 int=1 is 8 bit, int=0 is 7 bit
73StringObject keyname(int) return the text representation
74 of a KEY_ value. (see below)
75
76Here is a list of the currently supported methods and attributes
77in the WindowObject:
78
79Return Value Func/Attr Description
80--------------------------------------------------------------------------
Guido van Rossum85738471995-02-17 13:50:17 +000081None refresh() Do refresh
82None nooutrefresh() Mark for refresh but wait
83None mvwin(new_y,new_x) Move Window
84None move(new_y,new_x) Move Cursor
Guido van Rossumfbea2f31994-08-31 22:05:27 +000085WindowObject subwin(nlines,ncols,begin_y,begin_x)
86 subwin(begin_y,begin_x)
Guido van Rossum85738471995-02-17 13:50:17 +000087None addch(y,x,ch,attr)
Guido van Rossumfbea2f31994-08-31 22:05:27 +000088 addch(y,x,ch)
89 addch(ch,attr)
90 addch(ch)
Guido van Rossum85738471995-02-17 13:50:17 +000091None insch(y,x,ch,attr)
Guido van Rossumfbea2f31994-08-31 22:05:27 +000092 insch(y,x,ch)
93 insch(ch,attr)
94 insch(ch)
Guido van Rossum85738471995-02-17 13:50:17 +000095None delch(y,x)
Guido van Rossumfbea2f31994-08-31 22:05:27 +000096 delch()
Guido van Rossum85738471995-02-17 13:50:17 +000097None echochar(ch,attr)
Guido van Rossumfbea2f31994-08-31 22:05:27 +000098 echochar(ch)
Guido van Rossum85738471995-02-17 13:50:17 +000099None addstr(y,x,str,attr)
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000100 addstr(y,x,str)
101 addstr(str,attr)
102 addstr(str)
Guido van Rossum85738471995-02-17 13:50:17 +0000103None attron(attr)
104None attroff(attr)
105None attrset(sttr)
106None standend()
107None standout()
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000108None border(ls,rs,ts,bs,tl,tr,bl,br) (accepts 0-8 INT args)
Guido van Rossum85738471995-02-17 13:50:17 +0000109None box(vertch,horch) vertch and horch are INTS
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000110 box()
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000111None hline(y,x,ch,n)
112 hline(ch,n)
113None vline(y,x,ch,n)
114 vline(ch,n)
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000115None erase()
116None deleteln()
117None insertln()
118(y,x) getyx()
119(y,x) getbegyx()
120(y,x) getmaxyx()
121None clear()
122None clrtobot()
123None clrtoeol()
124None scroll()
Guido van Rossum716a89c1999-01-05 17:16:46 +0000125 scroll(nlines)
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000126None touchwin()
127None touchline(start,count)
128IntObject getch(y,x)
129 getch()
130StringObject getstr(y,x)
131 getstr()
132IntObject inch(y,x)
133 inch()
134None clearok(int) int=0 or int=1
135None idlok(int) int=0 or int=1
136None leaveok(int) int=0 or int=1
137None scrollok(int) int=0 or int=1
138None setscrreg(top,bottom)
Guido van Rossum8fbf82b1995-02-17 13:54:04 +0000139None keypad(int) int=0 or int=1
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000140None nodelay(int) int=0 or int=1
141None notimeout(int) int=0 or int=1
142******************************************************************/
143
144
Guido van Rossumf6971e21994-08-30 12:25:20 +0000145/* curses module */
146
Guido van Rossum602099a1994-09-14 13:32:22 +0000147#include "Python.h"
Guido van Rossumf6971e21994-08-30 12:25:20 +0000148
Guido van Rossum1266a011996-02-25 04:50:31 +0000149#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
Guido van Rossumf6971e21994-08-30 12:25:20 +0000153#include <curses.h>
Guido van Rossum1266a011996-02-25 04:50:31 +0000154#endif
Guido van Rossumf6971e21994-08-30 12:25:20 +0000155
Guido van Rossumf6971e21994-08-30 12:25:20 +0000156typedef struct {
157 PyObject_HEAD
158 SCREEN *scr;
159} PyCursesScreenObject;
160
161typedef struct {
162 PyObject_HEAD
163 WINDOW *win;
164 WINDOW *parent;
165} PyCursesWindowObject;
166
167typedef struct {
168 PyObject_HEAD
169 WINDOW *pad;
170} PyCursesPadObject;
171
Guido van Rossuma376cc51996-12-05 23:43:35 +0000172#if 0
Guido van Rossumf6971e21994-08-30 12:25:20 +0000173staticforward PyTypeObject PyCursesScreen_Type;
Guido van Rossuma376cc51996-12-05 23:43:35 +0000174#endif
Guido van Rossumf6971e21994-08-30 12:25:20 +0000175staticforward PyTypeObject PyCursesWindow_Type;
Guido van Rossuma376cc51996-12-05 23:43:35 +0000176#if 0
Guido van Rossumf6971e21994-08-30 12:25:20 +0000177staticforward PyTypeObject PyCursesPad_Type;
Guido van Rossuma376cc51996-12-05 23:43:35 +0000178#endif
Guido van Rossumf6971e21994-08-30 12:25:20 +0000179
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)
183
184/* Defines */
Guido van Rossum85738471995-02-17 13:50:17 +0000185static PyObject *PyCursesError; /* For exception curses.error */
186
187/* Catch-all error messages */
188static char *catchall_ERR = "curses function returned ERR";
189static char *catchall_NULL = "curses function returned NULL";
190
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000191/* Tells whether initscr() has been called to initialise curses */
192static int initialised = FALSE;
193
Guido van Rossum85738471995-02-17 13:50:17 +0000194#define ARG_COUNT(X) \
195 (((X) == NULL) ? 0 : (PyTuple_Check(X) ? PyTuple_Size(X) : 1))
Guido van Rossumf6971e21994-08-30 12:25:20 +0000196
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000197/******************************************************************
198
199Change Log:
200
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000201Version 1.2: 95/02/23 (Steve Clift)
Guido van Rossum85738471995-02-17 13:50:17 +0000202 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.
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000206 Added keypad() to window method list.
207 Added border(), hline() and vline() window methods.
Guido van Rossum85738471995-02-17 13:50:17 +0000208
Guido van Rossum56bf2351994-08-31 22:06:24 +0000209Version 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
Guido van Rossum85738471995-02-17 13:50:17 +0000216
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000217Version 1.0: 94/08/30:
218 This is the first release of this software.
219 Released to the Internet via python-list@cwi.nl
220
221******************************************************************/
Guido van Rossum85738471995-02-17 13:50:17 +0000222
Guido van Rossumd5f6c221998-10-07 14:48:53 +0000223static char *PyCursesVersion = "1.2";
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000224
Guido van Rossum85738471995-02-17 13:50:17 +0000225/*
226 * Check the return code from a curses function and return None
227 * or raise an exception as appropriate.
228 */
229
230static PyObject *
231PyCursesCheckERR(code, fname)
232 int code;
233 char *fname;
234{
235 char buf[100];
236
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);
247 }
248 return NULL;
249 }
250}
251
252
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000253static int
254PyCursesInitialised()
255{
256 if (initialised == TRUE)
257 return 1;
258 else {
259 PyErr_SetString(PyCursesError, "must call initscr() first");
260 return 0;
261 }
262}
263
264
Guido van Rossumf6971e21994-08-30 12:25:20 +0000265/* ------------- SCREEN routines --------------- */
Guido van Rossum85738471995-02-17 13:50:17 +0000266
Guido van Rossumf6971e21994-08-30 12:25:20 +0000267#ifdef NOT_YET
268static PyObject *
269PyCursesScreen_New(arg)
270 PyObject * arg;
271{
272 char *term_type;
273 PyFileObject *in_fo;
274 PyFileObject *out_fo;
275 PyCursesScreenObject *xp;
Guido van Rossum85738471995-02-17 13:50:17 +0000276 xp = PyObject_NEW(PyCursesScreenObject, &PyCursesScreen_Type);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000277 if (xp == NULL)
278 return NULL;
279 return (PyObject *)xp;
280}
281#endif
Guido van Rossum85738471995-02-17 13:50:17 +0000282
283
Guido van Rossumf6971e21994-08-30 12:25:20 +0000284/* ------------- WINDOW routines --------------- */
Guido van Rossum85738471995-02-17 13:50:17 +0000285
Guido van Rossumf6971e21994-08-30 12:25:20 +0000286static PyObject *
287PyCursesWindow_New(win)
288 WINDOW *win;
289{
290 PyCursesWindowObject *wo;
Guido van Rossum85738471995-02-17 13:50:17 +0000291
292 wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000293 if (wo == NULL)
294 return NULL;
295 wo->win = win;
296 wo->parent = (WINDOW *)NULL;
297 return (PyObject *)wo;
298}
299
300static void
301PyCursesWindow_Dealloc(wo)
302 PyCursesWindowObject *wo;
303{
304 if (wo->win != stdscr)
305 delwin(wo->win);
306 PyMem_DEL(wo);
307}
308
309static PyObject *
310PyCursesWindow_Refresh(self,arg)
311 PyCursesWindowObject *self;
312 PyObject * arg;
313{
314 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000315 return NULL;
316 return PyCursesCheckERR(wrefresh(self->win), "wrefresh");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000317}
318
319static PyObject *
320PyCursesWindow_NoOutRefresh(self,arg)
321 PyCursesWindowObject *self;
322 PyObject * arg;
323{
324 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000325 return NULL;
326 return PyCursesCheckERR(wnoutrefresh(self->win), "wnoutrefresh");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000327}
328
329static PyObject *
330PyCursesWindow_MoveWin(self,arg)
331 PyCursesWindowObject *self;
332 PyObject * arg;
333{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000334 int x, y;
Guido van Rossum85738471995-02-17 13:50:17 +0000335 if (!PyArg_Parse(arg,"(ii);y,x", &y, &x))
336 return NULL;
337 return PyCursesCheckERR(mvwin(self->win,y,x), "mvwin");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000338}
339
340static PyObject *
341PyCursesWindow_Move(self,arg)
342 PyCursesWindowObject *self;
343 PyObject * arg;
344{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000345 int x, y;
Guido van Rossum85738471995-02-17 13:50:17 +0000346 if (!PyArg_Parse(arg,"(ii);y,x", &y, &x))
347 return NULL;
348 return PyCursesCheckERR(wmove(self->win,y,x), "wmove");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000349}
350
351static PyObject *
352PyCursesWindow_SubWin(self,arg)
353 PyCursesWindowObject *self;
354 PyObject * arg;
355{
356 WINDOW *win;
357 PyCursesWindowObject *rtn_win;
358 int nlines, ncols, begin_y, begin_x;
Guido van Rossum85738471995-02-17 13:50:17 +0000359
Guido van Rossumf6971e21994-08-30 12:25:20 +0000360 nlines = 0;
361 ncols = 0;
Guido van Rossum85738471995-02-17 13:50:17 +0000362 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",
Guido van Rossumf6971e21994-08-30 12:25:20 +0000369 &nlines,&ncols,&begin_y,&begin_x))
Guido van Rossum85738471995-02-17 13:50:17 +0000370 return NULL;
371 break;
372 default:
373 PyErr_SetString(PyExc_TypeError, "subwin requires 2 or 4 arguments");
374 return NULL;
375 }
Guido van Rossumf6971e21994-08-30 12:25:20 +0000376 win = subwin(self->win,nlines,ncols,begin_y,begin_x);
377 if (win == NULL) {
Guido van Rossum85738471995-02-17 13:50:17 +0000378 PyErr_SetString(PyCursesError, catchall_NULL);
379 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000380 }
381 rtn_win = (PyCursesWindowObject *)PyCursesWindow_New(win);
382 rtn_win->parent = self->win;
383 return (PyObject *)rtn_win;
384}
385
386static PyObject *
387PyCursesWindow_AddCh(self,arg)
388 PyCursesWindowObject *self;
389 PyObject * arg;
390{
391 int rtn;
392 int x, y;
393 int ch;
Guido van Rossuma376cc51996-12-05 23:43:35 +0000394 int attr, attr_old = 0;
Guido van Rossum85738471995-02-17 13:50:17 +0000395 int use_xy = FALSE, use_attr = FALSE;
396
397 switch (ARG_COUNT(arg)) {
398 case 1:
399 if (!PyArg_Parse(arg, "i;ch", &ch))
400 return NULL;
401 break;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000402 case 2:
Guido van Rossum85738471995-02-17 13:50:17 +0000403 if (!PyArg_Parse(arg,"(ii);ch,attr", &ch, &attr))
404 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000405 use_attr = TRUE;
406 break;
Guido van Rossum85738471995-02-17 13:50:17 +0000407 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;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000417 default:
Guido van Rossum85738471995-02-17 13:50:17 +0000418 PyErr_SetString(PyExc_TypeError, "addch requires 1 to 4 arguments");
419 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000420 }
Guido van Rossum85738471995-02-17 13:50:17 +0000421
Guido van Rossumf6971e21994-08-30 12:25:20 +0000422 if (use_attr == TRUE) {
423 attr_old = getattrs(self->win);
424 wattrset(self->win,attr);
425 }
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);
Guido van Rossum85738471995-02-17 13:50:17 +0000432
433 return PyCursesCheckERR(rtn, "[mv]waddch");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000434}
435
436static PyObject *
437PyCursesWindow_InsCh(self,arg)
438 PyCursesWindowObject *self;
439 PyObject * arg;
440{
441 int rtn;
442 int x, y;
443 int ch;
Guido van Rossuma376cc51996-12-05 23:43:35 +0000444 int attr, attr_old = 0;
Guido van Rossum85738471995-02-17 13:50:17 +0000445 int use_xy = TRUE, use_attr = FALSE;
446
447 switch (ARG_COUNT(arg)) {
448 case 1:
449 if (!PyArg_Parse(arg, "i;ch", &ch))
450 return NULL;
451 break;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000452 case 2:
Guido van Rossum85738471995-02-17 13:50:17 +0000453 if (!PyArg_Parse(arg,"(ii);ch,attr", &ch, &attr))
454 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000455 use_attr = TRUE;
456 break;
Guido van Rossum85738471995-02-17 13:50:17 +0000457 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;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000467 default:
Guido van Rossum85738471995-02-17 13:50:17 +0000468 PyErr_SetString(PyExc_TypeError, "insch requires 1 to 4 arguments");
469 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000470 }
Guido van Rossum85738471995-02-17 13:50:17 +0000471
Guido van Rossumf6971e21994-08-30 12:25:20 +0000472 if (use_attr == TRUE) {
473 attr_old = getattrs(self->win);
474 wattrset(self->win,attr);
475 }
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);
Guido van Rossum85738471995-02-17 13:50:17 +0000482
483 return PyCursesCheckERR(rtn, "[mv]winsch");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000484}
485
486static PyObject *
487PyCursesWindow_DelCh(self,arg)
488 PyCursesWindowObject *self;
489 PyObject * arg;
490{
491 int rtn;
492 int x, y;
Guido van Rossum85738471995-02-17 13:50:17 +0000493
494 switch (ARG_COUNT(arg)) {
495 case 0:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000496 rtn = wdelch(self->win);
Guido van Rossum85738471995-02-17 13:50:17 +0000497 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;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000506 }
Guido van Rossum85738471995-02-17 13:50:17 +0000507
508 return PyCursesCheckERR(rtn, "[mv]wdelch");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000509}
510
511static PyObject *
512PyCursesWindow_EchoChar(self,arg)
513 PyCursesWindowObject *self;
514 PyObject * arg;
515{
516 int rtn;
517 int ch;
Guido van Rossum85738471995-02-17 13:50:17 +0000518 int attr, attr_old;
519
520 switch (ARG_COUNT(arg)) {
521 case 1:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000522 if (!PyArg_Parse(arg,"i;ch", &ch))
Guido van Rossum85738471995-02-17 13:50:17 +0000523 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;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000529 attr_old = getattrs(self->win);
530 wattrset(self->win,attr);
Guido van Rossum85738471995-02-17 13:50:17 +0000531 rtn = wechochar(self->win,ch);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000532 wattrset(self->win,attr_old);
Guido van Rossum85738471995-02-17 13:50:17 +0000533 break;
534 default:
535 PyErr_SetString(PyExc_TypeError, "echochar requires 1 or 2 arguments");
536 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000537 }
Guido van Rossum85738471995-02-17 13:50:17 +0000538
539 return PyCursesCheckERR(rtn, "wechochar");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000540}
541
542static PyObject *
543PyCursesWindow_AddStr(self,arg)
544 PyCursesWindowObject *self;
545 PyObject * arg;
546{
547 int rtn;
548 int x, y;
549 char *str;
Guido van Rossuma376cc51996-12-05 23:43:35 +0000550 int attr, attr_old = 0;
Guido van Rossum85738471995-02-17 13:50:17 +0000551 int use_xy = FALSE, use_attr = FALSE;
552
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;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000576 }
Guido van Rossum85738471995-02-17 13:50:17 +0000577
Guido van Rossumf6971e21994-08-30 12:25:20 +0000578 if (use_attr == TRUE) {
579 attr_old = getattrs(self->win);
580 wattrset(self->win,attr);
581 }
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);
Guido van Rossum85738471995-02-17 13:50:17 +0000588
589 return PyCursesCheckERR(rtn, "[mv]waddstr");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000590}
591
592static PyObject *
593PyCursesWindow_AttrOn(self,arg)
594 PyCursesWindowObject *self;
595 PyObject * arg;
596{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000597 int ch;
598 if (!PyArg_Parse(arg,"i;attr", &ch))
Guido van Rossum85738471995-02-17 13:50:17 +0000599 return NULL;
600 wattron(self->win,ch);
601 Py_INCREF(Py_None);
602 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000603}
604
605static PyObject *
606PyCursesWindow_AttrOff(self,arg)
607 PyCursesWindowObject *self;
608 PyObject * arg;
609{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000610 int ch;
611 if (!PyArg_Parse(arg,"i;attr", &ch))
Guido van Rossum85738471995-02-17 13:50:17 +0000612 return NULL;
613 wattroff(self->win,ch);
614 Py_INCREF(Py_None);
615 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000616}
617
618static PyObject *
619PyCursesWindow_AttrSet(self,arg)
620 PyCursesWindowObject *self;
621 PyObject * arg;
622{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000623 int ch;
624 if (!PyArg_Parse(arg,"i;attr", &ch))
Guido van Rossum85738471995-02-17 13:50:17 +0000625 return NULL;
626 wattrset(self->win,ch);
627 Py_INCREF(Py_None);
628 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000629}
630
631static PyObject *
632PyCursesWindow_StandEnd(self,arg)
633 PyCursesWindowObject *self;
634 PyObject * arg;
635{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000636 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000637 return NULL;
638 wstandend(self->win);
639 Py_INCREF(Py_None);
640 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000641}
642
643static PyObject *
644PyCursesWindow_StandOut(self,arg)
645 PyCursesWindowObject *self;
646 PyObject * arg;
647{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000648 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000649 return NULL;
650 wstandout(self->win);
651 Py_INCREF(Py_None);
652 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000653}
654
655static PyObject *
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000656PyCursesWindow_Border(self, args)
657 PyCursesWindowObject *self;
658 PyObject *args;
659{
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;
668}
669
670static PyObject *
Guido van Rossumf6971e21994-08-30 12:25:20 +0000671PyCursesWindow_Box(self,arg)
672 PyCursesWindowObject *self;
673 PyObject * arg;
674{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000675 int ch1=0,ch2=0;
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000676 if (!PyArg_NoArgs(arg)) {
Guido van Rossumf6971e21994-08-30 12:25:20 +0000677 PyErr_Clear();
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000678 if (!PyArg_Parse(arg,"(ii);vertch,horch", &ch1, &ch2))
679 return NULL;
680 }
Guido van Rossum85738471995-02-17 13:50:17 +0000681 box(self->win,ch1,ch2);
682 Py_INCREF(Py_None);
683 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000684}
685
686static PyObject *
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000687PyCursesWindow_Hline(self, args)
688 PyCursesWindowObject *self;
689 PyObject *args;
690{
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;
705 }
706 if (code != ERR)
707 whline(self->win, ch, n);
708 return PyCursesCheckERR(code, "wmove");
709}
710
711static PyObject *
712PyCursesWindow_Vline(self, args)
713 PyCursesWindowObject *self;
714 PyObject *args;
715{
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;
730 }
731 if (code != ERR)
732 wvline(self->win, ch, n);
733 return PyCursesCheckERR(code, "wmove");
734}
735
736static PyObject *
Guido van Rossumf6971e21994-08-30 12:25:20 +0000737PyCursesWindow_Erase(self,arg)
738 PyCursesWindowObject *self;
739 PyObject * arg;
740{
741 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000742 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000743 werase(self->win);
744 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000745 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000746}
747
748static PyObject *
749PyCursesWindow_DeleteLine(self,arg)
750 PyCursesWindowObject *self;
751 PyObject * arg;
752{
753 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000754 return NULL;
755 return PyCursesCheckERR(wdeleteln(self->win), "wdeleteln");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000756}
757
758static PyObject *
759PyCursesWindow_InsertLine(self,arg)
760 PyCursesWindowObject *self;
761 PyObject * arg;
762{
763 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000764 return NULL;
765 return PyCursesCheckERR(winsertln(self->win), "winsertln");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000766}
767
768static PyObject *
769PyCursesWindow_GetYX(self,arg)
770 PyCursesWindowObject *self;
771 PyObject * arg;
772{
773 int x, y;
774 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000775 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000776 getyx(self->win,y,x);
Guido van Rossum85738471995-02-17 13:50:17 +0000777 return Py_BuildValue("(ii)", y, x);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000778}
779
780static PyObject *
781PyCursesWindow_GetBegYX(self,arg)
782 PyCursesWindowObject *self;
783 PyObject * arg;
784{
785 int x, y;
786 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000787 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000788 getbegyx(self->win,y,x);
Guido van Rossum85738471995-02-17 13:50:17 +0000789 return Py_BuildValue("(ii)", y, x);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000790}
791
792static PyObject *
793PyCursesWindow_GetMaxYX(self,arg)
794 PyCursesWindowObject *self;
795 PyObject * arg;
796{
797 int x, y;
798 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000799 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000800 getmaxyx(self->win,y,x);
Guido van Rossum85738471995-02-17 13:50:17 +0000801 return Py_BuildValue("(ii)", y, x);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000802}
803
804static PyObject *
805PyCursesWindow_Clear(self,arg)
806 PyCursesWindowObject *self;
807 PyObject * arg;
808{
809 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000810 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000811 wclear(self->win);
812 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000813 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000814}
815
816static PyObject *
817PyCursesWindow_ClearToBottom(self,arg)
818 PyCursesWindowObject *self;
819 PyObject * arg;
820{
821 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000822 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000823 wclrtobot(self->win);
824 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000825 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000826}
827
828static PyObject *
829PyCursesWindow_ClearToEOL(self,arg)
830 PyCursesWindowObject *self;
831 PyObject * arg;
832{
833 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000834 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000835 wclrtoeol(self->win);
836 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000837 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000838}
839
840static PyObject *
841PyCursesWindow_Scroll(self,arg)
842 PyCursesWindowObject *self;
843 PyObject * arg;
844{
Guido van Rossum716a89c1999-01-05 17:16:46 +0000845 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))
Guido van Rossum85738471995-02-17 13:50:17 +0000852 return NULL;
Guido van Rossum716a89c1999-01-05 17:16:46 +0000853 use_nlines = TRUE;
854 break;
855 default:
856 PyErr_SetString(PyExc_TypeError, "scroll requires 0 or 1 arguments");
857 return NULL;
858 }
859 if (use_nlines)
860 return PyCursesCheckERR(wscrl(self->win, nlines), "scroll");
861 else
862 return PyCursesCheckERR(scroll(self->win), "scroll");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000863}
864
865static PyObject *
866PyCursesWindow_TouchWin(self,arg)
867 PyCursesWindowObject *self;
868 PyObject * arg;
869{
870 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000871 return NULL;
872 return PyCursesCheckERR(touchwin(self->win), "touchwin");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000873}
874
875static PyObject *
876PyCursesWindow_TouchLine(self,arg)
877 PyCursesWindowObject *self;
878 PyObject * arg;
879{
880 int st, cnt;
Guido van Rossum85738471995-02-17 13:50:17 +0000881 if (!PyArg_Parse(arg,"(ii);start,count",&st,&cnt))
882 return NULL;
883 return PyCursesCheckERR(touchline(self->win,st,cnt), "touchline");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000884}
885
886static PyObject *
887PyCursesWindow_GetCh(self,arg)
888 PyCursesWindowObject *self;
889 PyObject * arg;
890{
891 int x, y;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000892 int rtn;
Guido van Rossum85738471995-02-17 13:50:17 +0000893
894 switch (ARG_COUNT(arg)) {
895 case 0:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000896 rtn = wgetch(self->win);
Guido van Rossum85738471995-02-17 13:50:17 +0000897 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;
906 }
907
908 return PyInt_FromLong((long) rtn);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000909}
910
911static PyObject *
912PyCursesWindow_GetStr(self,arg)
913 PyCursesWindowObject *self;
914 PyObject * arg;
915{
916 int x, y;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000917 char rtn[1024]; /* This should be big enough.. I hope */
918 int rtn2;
Guido van Rossum85738471995-02-17 13:50:17 +0000919
920 switch (ARG_COUNT(arg)) {
921 case 0:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000922 rtn2 = wgetstr(self->win,rtn);
Guido van Rossum85738471995-02-17 13:50:17 +0000923 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;
932 }
933
Guido van Rossumf6971e21994-08-30 12:25:20 +0000934 if (rtn2 == ERR)
935 rtn[0] = 0;
Guido van Rossum85738471995-02-17 13:50:17 +0000936 return PyString_FromString(rtn);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000937}
938
939static PyObject *
940PyCursesWindow_InCh(self,arg)
941 PyCursesWindowObject *self;
942 PyObject * arg;
943{
Guido van Rossum85738471995-02-17 13:50:17 +0000944 int x, y, rtn;
945
946 switch (ARG_COUNT(arg)) {
947 case 0:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000948 rtn = winch(self->win);
Guido van Rossum85738471995-02-17 13:50:17 +0000949 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;
958 }
959
960 return PyInt_FromLong((long) rtn);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000961}
962
963static PyObject *
964PyCursesWindow_ClearOk(self,arg)
965 PyCursesWindowObject *self;
966 PyObject * arg;
967{
968 int val;
969 if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val))
Guido van Rossum85738471995-02-17 13:50:17 +0000970 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000971 clearok(self->win,val);
972 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000973 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000974}
975
976static PyObject *
977PyCursesWindow_IdlOk(self,arg)
978 PyCursesWindowObject *self;
979 PyObject * arg;
980{
981 int val;
982 if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val))
Guido van Rossum85738471995-02-17 13:50:17 +0000983 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000984 idlok(self->win,val);
985 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000986 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000987}
988
989static PyObject *
990PyCursesWindow_LeaveOk(self,arg)
991 PyCursesWindowObject *self;
992 PyObject * arg;
993{
994 int val;
995 if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val))
Guido van Rossum85738471995-02-17 13:50:17 +0000996 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000997 leaveok(self->win,val);
998 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000999 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001000}
1001
1002static PyObject *
1003PyCursesWindow_ScrollOk(self,arg)
1004 PyCursesWindowObject *self;
1005 PyObject * arg;
1006{
1007 int val;
1008 if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val))
Guido van Rossum85738471995-02-17 13:50:17 +00001009 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001010 scrollok(self->win,val);
1011 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00001012 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001013}
1014
1015static PyObject *
1016PyCursesWindow_SetScrollRegion(self,arg)
1017 PyCursesWindowObject *self;
1018 PyObject * arg;
1019{
1020 int x, y;
1021 if (!PyArg_Parse(arg,"(ii);top, bottom",&y,&x))
Guido van Rossum85738471995-02-17 13:50:17 +00001022 return NULL;
1023 return PyCursesCheckERR(wsetscrreg(self->win,y,x), "wsetscrreg");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001024}
1025
1026static PyObject *
1027PyCursesWindow_KeyPad(self,arg)
1028 PyCursesWindowObject * self;
1029 PyObject * arg;
1030{
1031 int ch;
1032 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
Guido van Rossum85738471995-02-17 13:50:17 +00001033 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001034 keypad(self->win,ch);
1035 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00001036 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001037}
1038
1039static PyObject *
1040PyCursesWindow_NoDelay(self,arg)
1041 PyCursesWindowObject * self;
1042 PyObject * arg;
1043{
1044 int ch;
1045 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
Guido van Rossum85738471995-02-17 13:50:17 +00001046 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001047 nodelay(self->win,ch);
1048 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00001049 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001050}
1051
1052static PyObject *
1053PyCursesWindow_NoTimeout(self,arg)
1054 PyCursesWindowObject * self;
1055 PyObject * arg;
1056{
1057 int ch;
1058 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
Guido van Rossum85738471995-02-17 13:50:17 +00001059 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001060 notimeout(self->win,ch);
1061 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00001062 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001063}
1064
1065static PyMethodDef PyCursesWindow_Methods[] = {
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001066 {"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},
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001108 {NULL, NULL} /* sentinel */
Guido van Rossumf6971e21994-08-30 12:25:20 +00001109};
1110
1111static PyObject *
1112PyCursesWindow_GetAttr(self, name)
1113 PyCursesWindowObject *self;
1114 char *name;
1115{
Guido van Rossuma597dde1995-01-10 20:56:29 +00001116 return Py_FindMethod(PyCursesWindow_Methods, (PyObject *)self, name);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001117}
1118
Guido van Rossum85738471995-02-17 13:50:17 +00001119
Guido van Rossumf6971e21994-08-30 12:25:20 +00001120/* --------------- PAD routines ---------------- */
Guido van Rossum85738471995-02-17 13:50:17 +00001121
1122#ifdef NOT_YET
Guido van Rossumf6971e21994-08-30 12:25:20 +00001123static PyObject *
1124PyCursesPad_New(pad)
1125 WINDOW *pad;
1126{
1127 PyCursesPadObject *po;
Guido van Rossum85738471995-02-17 13:50:17 +00001128 po = PyObject_NEW(PyCursesPadObject, &PyCursesPad_Type);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001129 if (po == NULL)
1130 return NULL;
1131 po->pad = pad;
1132 return (PyObject *)po;
1133}
Guido van Rossum85738471995-02-17 13:50:17 +00001134#endif
1135
Guido van Rossumf6971e21994-08-30 12:25:20 +00001136
1137/* -------------------------------------------------------*/
Guido van Rossum85738471995-02-17 13:50:17 +00001138
Guido van Rossuma376cc51996-12-05 23:43:35 +00001139#if 0
Guido van Rossumf6971e21994-08-30 12:25:20 +00001140static 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*/
1157};
Guido van Rossuma376cc51996-12-05 23:43:35 +00001158#endif
Guido van Rossumf6971e21994-08-30 12:25:20 +00001159
1160static 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*/
1177};
1178
Guido van Rossuma376cc51996-12-05 23:43:35 +00001179#if 0
Guido van Rossumf6971e21994-08-30 12:25:20 +00001180static 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*/
1197};
Guido van Rossuma376cc51996-12-05 23:43:35 +00001198#endif
Guido van Rossumf6971e21994-08-30 12:25:20 +00001199
Guido van Rossum85738471995-02-17 13:50:17 +00001200
Guido van Rossumf6971e21994-08-30 12:25:20 +00001201/* -------------------------------------------------------*/
1202
Guido van Rossume4485b01994-09-07 14:32:49 +00001203static PyObject *ModDict;
1204
Guido van Rossumf6971e21994-08-30 12:25:20 +00001205static PyObject *
1206PyCurses_InitScr(self, args)
1207 PyObject * self;
1208 PyObject * args;
1209{
Guido van Rossum56bf2351994-08-31 22:06:24 +00001210 WINDOW *win;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001211 if (!PyArg_NoArgs(args))
Guido van Rossum85738471995-02-17 13:50:17 +00001212 return NULL;
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001213 if (initialised == TRUE) {
Guido van Rossumf6971e21994-08-30 12:25:20 +00001214 wrefresh(stdscr);
1215 return (PyObject *)PyCursesWindow_New(stdscr);
1216 }
Guido van Rossum56bf2351994-08-31 22:06:24 +00001217
1218 win = initscr();
Guido van Rossum85738471995-02-17 13:50:17 +00001219 if (win == NULL) {
1220 PyErr_SetString(PyCursesError, catchall_NULL);
1221 return NULL;
1222 }
1223
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001224 initialised = TRUE;
Guido van Rossum56bf2351994-08-31 22:06:24 +00001225
1226/* This was moved from initcurses() because core dumped on SGI */
Guido van Rossum85738471995-02-17 13:50:17 +00001227/* 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)));
Guido van Rossum56bf2351994-08-31 22:06:24 +00001230
1231 /* Here are some graphic symbols you can use */
Guido van Rossum85738471995-02-17 13:50:17 +00001232 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));
Guido van Rossum11847891998-12-23 04:45:04 +00001251 SetDictInt("ACS_LARROW", (ACS_LARROW));
1252 SetDictInt("ACS_RARROW", (ACS_RARROW));
Guido van Rossum85738471995-02-17 13:50:17 +00001253 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));
Guido van Rossum56bf2351994-08-31 22:06:24 +00001258
1259 return (PyObject *)PyCursesWindow_New(win);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001260}
1261
1262static PyObject *
1263PyCurses_EndWin(self, args)
1264 PyObject * self;
1265 PyObject * args;
1266{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001267 if (!PyArg_NoArgs(args) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001268 return NULL;
1269 return PyCursesCheckERR(endwin(), "endwin");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001270}
1271
1272static PyObject *
1273PyCurses_IsEndWin(self, args)
1274 PyObject * self;
1275 PyObject * args;
1276{
1277 if (!PyArg_NoArgs(args))
Guido van Rossum85738471995-02-17 13:50:17 +00001278 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001279 if (isendwin() == FALSE) {
1280 Py_INCREF(Py_False);
1281 return Py_False;
1282 }
1283 Py_INCREF(Py_True);
1284 return Py_True;
1285}
1286
1287static PyObject *
1288PyCurses_DoUpdate(self,arg)
1289 PyObject * self;
1290 PyObject * arg;
1291{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001292 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001293 return NULL;
1294 return PyCursesCheckERR(doupdate(), "doupdate");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001295}
1296
1297static PyObject *
1298PyCurses_NewWindow(self,arg)
1299 PyObject * self;
1300 PyObject * arg;
1301{
1302 WINDOW *win;
1303 int nlines, ncols, begin_y, begin_x;
Guido van Rossum85738471995-02-17 13:50:17 +00001304
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001305 if (!PyCursesInitialised())
1306 return NULL;
Guido van Rossum85738471995-02-17 13:50:17 +00001307 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",
Guido van Rossumf6971e21994-08-30 12:25:20 +00001315 &nlines,&ncols,&begin_y,&begin_x))
Guido van Rossum85738471995-02-17 13:50:17 +00001316 return NULL;
1317 break;
1318 default:
1319 PyErr_SetString(PyExc_TypeError, "newwin requires 2 or 4 arguments");
1320 return NULL;
1321 }
1322
Guido van Rossumf6971e21994-08-30 12:25:20 +00001323 win = newwin(nlines,ncols,begin_y,begin_x);
1324 if (win == NULL) {
Guido van Rossum85738471995-02-17 13:50:17 +00001325 PyErr_SetString(PyCursesError, catchall_NULL);
1326 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001327 }
Guido van Rossum85738471995-02-17 13:50:17 +00001328
Guido van Rossumf6971e21994-08-30 12:25:20 +00001329 return (PyObject *)PyCursesWindow_New(win);
1330}
1331
1332static PyObject *
1333PyCurses_Beep(self,arg)
1334 PyObject * self;
1335 PyObject * arg;
1336{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001337 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001338 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001339 beep();
1340 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00001341 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001342}
1343
1344static PyObject *
1345PyCurses_Flash(self,arg)
1346 PyObject * self;
1347 PyObject * arg;
1348{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001349 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001350 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001351 flash();
1352 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00001353 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001354}
1355
1356static PyObject *
1357PyCurses_UngetCh(self,arg)
1358 PyObject * self;
1359 PyObject * arg;
1360{
1361 int ch;
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001362 if (!PyArg_Parse(arg,"i;integer",&ch) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001363 return NULL;
1364 return PyCursesCheckERR(ungetch(ch), "ungetch");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001365}
1366
1367static PyObject *
1368PyCurses_FlushInp(self,arg)
1369 PyObject * self;
1370 PyObject * arg;
1371{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001372 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001373 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001374 flushinp();
1375 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00001376 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001377}
1378
1379static PyObject *
1380PyCurses_CBreak(self,arg)
1381 PyObject * self;
1382 PyObject * arg;
1383{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001384 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001385 return NULL;
1386 return PyCursesCheckERR(cbreak(), "cbreak");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001387}
1388
1389static PyObject *
1390PyCurses_NoCBreak(self,arg)
1391 PyObject * self;
1392 PyObject * arg;
1393{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001394 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001395 return NULL;
1396 return PyCursesCheckERR(nocbreak(), "nocbreak");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001397}
1398
1399static PyObject *
1400PyCurses_Echo(self,arg)
1401 PyObject * self;
1402 PyObject * arg;
1403{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001404 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001405 return NULL;
1406 return PyCursesCheckERR(echo(), "echo");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001407}
1408
1409static PyObject *
1410PyCurses_NoEcho(self,arg)
1411 PyObject * self;
1412 PyObject * arg;
1413{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001414 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001415 return NULL;
1416 return PyCursesCheckERR(noecho(), "noecho");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001417}
1418
1419static PyObject *
1420PyCurses_Nl(self,arg)
1421 PyObject * self;
1422 PyObject * arg;
1423{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001424 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001425 return NULL;
1426 return PyCursesCheckERR(nl(), "nl");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001427}
1428
1429static PyObject *
1430PyCurses_NoNl(self,arg)
1431 PyObject * self;
1432 PyObject * arg;
1433{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001434 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001435 return NULL;
1436 return PyCursesCheckERR(nonl(), "nonl");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001437}
1438
1439static PyObject *
1440PyCurses_Raw(self,arg)
1441 PyObject * self;
1442 PyObject * arg;
1443{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001444 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001445 return NULL;
1446 return PyCursesCheckERR(raw(), "raw");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001447}
1448
1449static PyObject *
1450PyCurses_NoRaw(self,arg)
1451 PyObject * self;
1452 PyObject * arg;
1453{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001454 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001455 return NULL;
1456 return PyCursesCheckERR(noraw(), "noraw");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001457}
1458
1459static PyObject *
1460PyCurses_IntrFlush(self,arg)
1461 PyObject * self;
1462 PyObject * arg;
1463{
1464 int ch;
1465 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
Guido van Rossum85738471995-02-17 13:50:17 +00001466 return NULL;
1467 return PyCursesCheckERR(intrflush(NULL,ch), "intrflush");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001468}
1469
1470static PyObject *
1471PyCurses_Meta(self,arg)
1472 PyObject * self;
1473 PyObject * arg;
1474{
1475 int ch;
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001476 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001477 return NULL;
1478 return PyCursesCheckERR(meta(stdscr, ch), "meta");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001479}
1480
1481static PyObject *
1482PyCurses_KeyName(self,arg)
1483 PyObject * self;
1484 PyObject * arg;
1485{
Guido van Rossumdb4a6291997-05-09 02:17:12 +00001486 const char *knp;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001487 int ch;
1488 if (!PyArg_Parse(arg,"i",&ch))
Guido van Rossum85738471995-02-17 13:50:17 +00001489 return NULL;
1490 knp = keyname(ch);
1491 return PyString_FromString((knp == NULL) ? "" : knp);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001492}
1493
1494#ifdef NOT_YET
1495static PyObject *
1496PyCurses_NewTerm(self, args)
1497 PyObject * self;
1498 PyObject * args;
1499{
1500}
1501
1502static PyObject *
1503PyCurses_SetTerm(self, args)
1504 PyObject * self;
1505 PyObject * args;
1506{
1507}
1508#endif
1509
1510/* List of functions defined in the module */
1511
1512static 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 */
1538};
1539
1540/* Initialization function for the module */
1541
Guido van Rossum3886bb61998-12-04 18:50:17 +00001542DL_EXPORT(void)
Guido van Rossum56bf2351994-08-31 22:06:24 +00001543initcurses()
Guido van Rossumf6971e21994-08-30 12:25:20 +00001544{
Guido van Rossum8fbf82b1995-02-17 13:54:04 +00001545 PyObject *m, *d, *v;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001546
1547 /* Create the module and add the functions */
Guido van Rossum56bf2351994-08-31 22:06:24 +00001548 m = Py_InitModule("curses", PyCurses_methods);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001549
Guido van Rossumf6971e21994-08-30 12:25:20 +00001550 /* Add some symbolic constants to the module */
1551 d = PyModule_GetDict(m);
Guido van Rossume4485b01994-09-07 14:32:49 +00001552 ModDict = d; /* For PyCurses_InitScr */
Guido van Rossumfbea2f31994-08-31 22:05:27 +00001553
Guido van Rossum85738471995-02-17 13:50:17 +00001554 /* For exception curses.error */
Guido van Rossum0cb96de1997-10-01 04:29:29 +00001555 PyCursesError = PyErr_NewException("curses.error", NULL, NULL);
Guido van Rossum85738471995-02-17 13:50:17 +00001556 PyDict_SetItemString(d, "error", PyCursesError);
Guido van Rossumfbea2f31994-08-31 22:05:27 +00001557
Guido van Rossum85738471995-02-17 13:50:17 +00001558 /* Make the version available */
Guido van Rossum8fbf82b1995-02-17 13:54:04 +00001559 v = PyString_FromString(PyCursesVersion);
1560 PyDict_SetItemString(d, "version", v);
1561 PyDict_SetItemString(d, "__version__", v);
1562 Py_DECREF(v);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001563
Guido van Rossumf6971e21994-08-30 12:25:20 +00001564 /* Here are some attributes you can add to chars to print */
Guido van Rossum85738471995-02-17 13:50:17 +00001565 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);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001573
1574 /* Now set everything up for KEY_ variables */
1575 {
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);
Guido van Rossumf5c6d471995-02-07 15:38:32 +00001581 if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001582 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++;
1592 }
1593 p1++;
1594 }
1595 *p2 = (char)0;
1596 } else
1597 key_n2 = key_n;
Guido van Rossum85738471995-02-17 13:50:17 +00001598 PyDict_SetItemString(d,key_n2,PyInt_FromLong((long) key));
Guido van Rossumf6971e21994-08-30 12:25:20 +00001599 if (key_n2 != key_n)
1600 free(key_n2);
1601 }
Guido van Rossum85738471995-02-17 13:50:17 +00001602 SetDictInt("KEY_MIN", KEY_MIN);
1603 SetDictInt("KEY_MAX", KEY_MAX);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001604 }
Guido van Rossumf6971e21994-08-30 12:25:20 +00001605}