blob: f46b0bcec3496949d1079955002f0d3ceb5f9f76 [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()
125None touchwin()
126None touchline(start,count)
127IntObject getch(y,x)
128 getch()
129StringObject getstr(y,x)
130 getstr()
131IntObject inch(y,x)
132 inch()
133None clearok(int) int=0 or int=1
134None idlok(int) int=0 or int=1
135None leaveok(int) int=0 or int=1
136None scrollok(int) int=0 or int=1
137None setscrreg(top,bottom)
Guido van Rossum8fbf82b1995-02-17 13:54:04 +0000138None keypad(int) int=0 or int=1
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000139None nodelay(int) int=0 or int=1
140None notimeout(int) int=0 or int=1
141******************************************************************/
142
143
Guido van Rossumf6971e21994-08-30 12:25:20 +0000144/* curses module */
145
Guido van Rossum602099a1994-09-14 13:32:22 +0000146#include "Python.h"
Guido van Rossumf6971e21994-08-30 12:25:20 +0000147
Guido van Rossum1266a011996-02-25 04:50:31 +0000148#ifdef HAVE_NCURSES_H
149/* Now let's hope there aren't systems that have a broken ncurses.h */
150#include <ncurses.h>
151#else
Guido van Rossumf6971e21994-08-30 12:25:20 +0000152#include <curses.h>
Guido van Rossum1266a011996-02-25 04:50:31 +0000153#endif
Guido van Rossumf6971e21994-08-30 12:25:20 +0000154
Guido van Rossumf6971e21994-08-30 12:25:20 +0000155typedef struct {
156 PyObject_HEAD
157 SCREEN *scr;
158} PyCursesScreenObject;
159
160typedef struct {
161 PyObject_HEAD
162 WINDOW *win;
163 WINDOW *parent;
164} PyCursesWindowObject;
165
166typedef struct {
167 PyObject_HEAD
168 WINDOW *pad;
169} PyCursesPadObject;
170
Guido van Rossuma376cc51996-12-05 23:43:35 +0000171#if 0
Guido van Rossumf6971e21994-08-30 12:25:20 +0000172staticforward PyTypeObject PyCursesScreen_Type;
Guido van Rossuma376cc51996-12-05 23:43:35 +0000173#endif
Guido van Rossumf6971e21994-08-30 12:25:20 +0000174staticforward PyTypeObject PyCursesWindow_Type;
Guido van Rossuma376cc51996-12-05 23:43:35 +0000175#if 0
Guido van Rossumf6971e21994-08-30 12:25:20 +0000176staticforward PyTypeObject PyCursesPad_Type;
Guido van Rossuma376cc51996-12-05 23:43:35 +0000177#endif
Guido van Rossumf6971e21994-08-30 12:25:20 +0000178
179#define PyCursesScreen_Check(v) ((v)->ob_type == &PyCursesScreen_Type)
180#define PyCursesWindow_Check(v) ((v)->ob_type == &PyCursesWindow_Type)
181#define PyCursesPad_Check(v) ((v)->ob_type == &PyCursesPad_Type)
182
183/* Defines */
Guido van Rossum85738471995-02-17 13:50:17 +0000184static PyObject *PyCursesError; /* For exception curses.error */
185
186/* Catch-all error messages */
187static char *catchall_ERR = "curses function returned ERR";
188static char *catchall_NULL = "curses function returned NULL";
189
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000190/* Tells whether initscr() has been called to initialise curses */
191static int initialised = FALSE;
192
Guido van Rossum85738471995-02-17 13:50:17 +0000193#define ARG_COUNT(X) \
194 (((X) == NULL) ? 0 : (PyTuple_Check(X) ? PyTuple_Size(X) : 1))
Guido van Rossumf6971e21994-08-30 12:25:20 +0000195
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000196/******************************************************************
197
198Change Log:
199
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000200Version 1.2: 95/02/23 (Steve Clift)
Guido van Rossum85738471995-02-17 13:50:17 +0000201 Fixed several potential core-dumping bugs.
202 Reworked arg parsing where variable arg lists are used.
203 Generate exceptions when ERR or NULL is returned by curses functions.
204 Changed return types to match SysV Curses manual descriptions.
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000205 Added keypad() to window method list.
206 Added border(), hline() and vline() window methods.
Guido van Rossum85738471995-02-17 13:50:17 +0000207
Guido van Rossum56bf2351994-08-31 22:06:24 +0000208Version 1.1: 94/08/31:
209 Minor fixes given by Guido.
210 Changed 'ncurses' to 'curses'
211 Changed '__version__' to 'version'
212 Added PyErr_Clear() where needed
213 Moved ACS_* attribute initialization to PyCurses_InitScr() to fix
214 crash on SGI
Guido van Rossum85738471995-02-17 13:50:17 +0000215
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000216Version 1.0: 94/08/30:
217 This is the first release of this software.
218 Released to the Internet via python-list@cwi.nl
219
220******************************************************************/
Guido van Rossum85738471995-02-17 13:50:17 +0000221
Guido van Rossumd5f6c221998-10-07 14:48:53 +0000222static char *PyCursesVersion = "1.2";
Guido van Rossumfbea2f31994-08-31 22:05:27 +0000223
Guido van Rossum85738471995-02-17 13:50:17 +0000224/*
225 * Check the return code from a curses function and return None
226 * or raise an exception as appropriate.
227 */
228
229static PyObject *
230PyCursesCheckERR(code, fname)
231 int code;
232 char *fname;
233{
234 char buf[100];
235
236 if (code != ERR) {
237 Py_INCREF(Py_None);
238 return Py_None;
239 } else {
240 if (fname == NULL) {
241 PyErr_SetString(PyCursesError, catchall_ERR);
242 } else {
243 strcpy(buf, fname);
244 strcat(buf, "() returned ERR");
245 PyErr_SetString(PyCursesError, buf);
246 }
247 return NULL;
248 }
249}
250
251
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000252static int
253PyCursesInitialised()
254{
255 if (initialised == TRUE)
256 return 1;
257 else {
258 PyErr_SetString(PyCursesError, "must call initscr() first");
259 return 0;
260 }
261}
262
263
Guido van Rossumf6971e21994-08-30 12:25:20 +0000264/* ------------- SCREEN routines --------------- */
Guido van Rossum85738471995-02-17 13:50:17 +0000265
Guido van Rossumf6971e21994-08-30 12:25:20 +0000266#ifdef NOT_YET
267static PyObject *
268PyCursesScreen_New(arg)
269 PyObject * arg;
270{
271 char *term_type;
272 PyFileObject *in_fo;
273 PyFileObject *out_fo;
274 PyCursesScreenObject *xp;
Guido van Rossum85738471995-02-17 13:50:17 +0000275 xp = PyObject_NEW(PyCursesScreenObject, &PyCursesScreen_Type);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000276 if (xp == NULL)
277 return NULL;
278 return (PyObject *)xp;
279}
280#endif
Guido van Rossum85738471995-02-17 13:50:17 +0000281
282
Guido van Rossumf6971e21994-08-30 12:25:20 +0000283/* ------------- WINDOW routines --------------- */
Guido van Rossum85738471995-02-17 13:50:17 +0000284
Guido van Rossumf6971e21994-08-30 12:25:20 +0000285static PyObject *
286PyCursesWindow_New(win)
287 WINDOW *win;
288{
289 PyCursesWindowObject *wo;
Guido van Rossum85738471995-02-17 13:50:17 +0000290
291 wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000292 if (wo == NULL)
293 return NULL;
294 wo->win = win;
295 wo->parent = (WINDOW *)NULL;
296 return (PyObject *)wo;
297}
298
299static void
300PyCursesWindow_Dealloc(wo)
301 PyCursesWindowObject *wo;
302{
303 if (wo->win != stdscr)
304 delwin(wo->win);
305 PyMem_DEL(wo);
306}
307
308static PyObject *
309PyCursesWindow_Refresh(self,arg)
310 PyCursesWindowObject *self;
311 PyObject * arg;
312{
313 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000314 return NULL;
315 return PyCursesCheckERR(wrefresh(self->win), "wrefresh");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000316}
317
318static PyObject *
319PyCursesWindow_NoOutRefresh(self,arg)
320 PyCursesWindowObject *self;
321 PyObject * arg;
322{
323 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000324 return NULL;
325 return PyCursesCheckERR(wnoutrefresh(self->win), "wnoutrefresh");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000326}
327
328static PyObject *
329PyCursesWindow_MoveWin(self,arg)
330 PyCursesWindowObject *self;
331 PyObject * arg;
332{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000333 int x, y;
Guido van Rossum85738471995-02-17 13:50:17 +0000334 if (!PyArg_Parse(arg,"(ii);y,x", &y, &x))
335 return NULL;
336 return PyCursesCheckERR(mvwin(self->win,y,x), "mvwin");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000337}
338
339static PyObject *
340PyCursesWindow_Move(self,arg)
341 PyCursesWindowObject *self;
342 PyObject * arg;
343{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000344 int x, y;
Guido van Rossum85738471995-02-17 13:50:17 +0000345 if (!PyArg_Parse(arg,"(ii);y,x", &y, &x))
346 return NULL;
347 return PyCursesCheckERR(wmove(self->win,y,x), "wmove");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000348}
349
350static PyObject *
351PyCursesWindow_SubWin(self,arg)
352 PyCursesWindowObject *self;
353 PyObject * arg;
354{
355 WINDOW *win;
356 PyCursesWindowObject *rtn_win;
357 int nlines, ncols, begin_y, begin_x;
Guido van Rossum85738471995-02-17 13:50:17 +0000358
Guido van Rossumf6971e21994-08-30 12:25:20 +0000359 nlines = 0;
360 ncols = 0;
Guido van Rossum85738471995-02-17 13:50:17 +0000361 switch (ARG_COUNT(arg)) {
362 case 2:
363 if (!PyArg_Parse(arg,"(ii);begin_y,begin_x",&begin_y,&begin_x))
364 return NULL;
365 break;
366 case 4:
367 if (!PyArg_Parse(arg, "(iiii);nlines,ncols,begin_y,begin_x",
Guido van Rossumf6971e21994-08-30 12:25:20 +0000368 &nlines,&ncols,&begin_y,&begin_x))
Guido van Rossum85738471995-02-17 13:50:17 +0000369 return NULL;
370 break;
371 default:
372 PyErr_SetString(PyExc_TypeError, "subwin requires 2 or 4 arguments");
373 return NULL;
374 }
Guido van Rossumf6971e21994-08-30 12:25:20 +0000375 win = subwin(self->win,nlines,ncols,begin_y,begin_x);
376 if (win == NULL) {
Guido van Rossum85738471995-02-17 13:50:17 +0000377 PyErr_SetString(PyCursesError, catchall_NULL);
378 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000379 }
380 rtn_win = (PyCursesWindowObject *)PyCursesWindow_New(win);
381 rtn_win->parent = self->win;
382 return (PyObject *)rtn_win;
383}
384
385static PyObject *
386PyCursesWindow_AddCh(self,arg)
387 PyCursesWindowObject *self;
388 PyObject * arg;
389{
390 int rtn;
391 int x, y;
392 int ch;
Guido van Rossuma376cc51996-12-05 23:43:35 +0000393 int attr, attr_old = 0;
Guido van Rossum85738471995-02-17 13:50:17 +0000394 int use_xy = FALSE, use_attr = FALSE;
395
396 switch (ARG_COUNT(arg)) {
397 case 1:
398 if (!PyArg_Parse(arg, "i;ch", &ch))
399 return NULL;
400 break;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000401 case 2:
Guido van Rossum85738471995-02-17 13:50:17 +0000402 if (!PyArg_Parse(arg,"(ii);ch,attr", &ch, &attr))
403 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000404 use_attr = TRUE;
405 break;
Guido van Rossum85738471995-02-17 13:50:17 +0000406 case 3:
407 if (!PyArg_Parse(arg,"(iii);y,x,ch", &y, &x, &ch))
408 return NULL;
409 use_xy = TRUE;
410 break;
411 case 4:
412 if (!PyArg_Parse(arg,"(iiii);y,x,ch,attr", &y, &x, &ch, &attr))
413 return NULL;
414 use_xy = use_attr = TRUE;
415 break;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000416 default:
Guido van Rossum85738471995-02-17 13:50:17 +0000417 PyErr_SetString(PyExc_TypeError, "addch requires 1 to 4 arguments");
418 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000419 }
Guido van Rossum85738471995-02-17 13:50:17 +0000420
Guido van Rossumf6971e21994-08-30 12:25:20 +0000421 if (use_attr == TRUE) {
422 attr_old = getattrs(self->win);
423 wattrset(self->win,attr);
424 }
425 if (use_xy == TRUE)
426 rtn = mvwaddch(self->win,y,x,ch);
427 else
428 rtn = waddch(self->win,ch);
429 if (use_attr == TRUE)
430 wattrset(self->win,attr_old);
Guido van Rossum85738471995-02-17 13:50:17 +0000431
432 return PyCursesCheckERR(rtn, "[mv]waddch");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000433}
434
435static PyObject *
436PyCursesWindow_InsCh(self,arg)
437 PyCursesWindowObject *self;
438 PyObject * arg;
439{
440 int rtn;
441 int x, y;
442 int ch;
Guido van Rossuma376cc51996-12-05 23:43:35 +0000443 int attr, attr_old = 0;
Guido van Rossum85738471995-02-17 13:50:17 +0000444 int use_xy = TRUE, use_attr = FALSE;
445
446 switch (ARG_COUNT(arg)) {
447 case 1:
448 if (!PyArg_Parse(arg, "i;ch", &ch))
449 return NULL;
450 break;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000451 case 2:
Guido van Rossum85738471995-02-17 13:50:17 +0000452 if (!PyArg_Parse(arg,"(ii);ch,attr", &ch, &attr))
453 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000454 use_attr = TRUE;
455 break;
Guido van Rossum85738471995-02-17 13:50:17 +0000456 case 3:
457 if (!PyArg_Parse(arg,"(iii);y,x,ch", &y, &x, &ch))
458 return NULL;
459 use_xy = TRUE;
460 break;
461 case 4:
462 if (!PyArg_Parse(arg,"(iiii);y,x,ch,attr", &y, &x, &ch, &attr))
463 return NULL;
464 use_xy = use_attr = TRUE;
465 break;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000466 default:
Guido van Rossum85738471995-02-17 13:50:17 +0000467 PyErr_SetString(PyExc_TypeError, "insch requires 1 to 4 arguments");
468 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000469 }
Guido van Rossum85738471995-02-17 13:50:17 +0000470
Guido van Rossumf6971e21994-08-30 12:25:20 +0000471 if (use_attr == TRUE) {
472 attr_old = getattrs(self->win);
473 wattrset(self->win,attr);
474 }
475 if (use_xy == TRUE)
476 rtn = mvwinsch(self->win,y,x,ch);
477 else
478 rtn = winsch(self->win,ch);
479 if (use_attr == TRUE)
480 wattrset(self->win,attr_old);
Guido van Rossum85738471995-02-17 13:50:17 +0000481
482 return PyCursesCheckERR(rtn, "[mv]winsch");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000483}
484
485static PyObject *
486PyCursesWindow_DelCh(self,arg)
487 PyCursesWindowObject *self;
488 PyObject * arg;
489{
490 int rtn;
491 int x, y;
Guido van Rossum85738471995-02-17 13:50:17 +0000492
493 switch (ARG_COUNT(arg)) {
494 case 0:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000495 rtn = wdelch(self->win);
Guido van Rossum85738471995-02-17 13:50:17 +0000496 break;
497 case 2:
498 if (!PyArg_Parse(arg,"(ii);y,x", &y, &x))
499 return NULL;
500 rtn = mvwdelch(self->win,y,x);
501 break;
502 default:
503 PyErr_SetString(PyExc_TypeError, "delch requires 0 or 2 arguments");
504 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000505 }
Guido van Rossum85738471995-02-17 13:50:17 +0000506
507 return PyCursesCheckERR(rtn, "[mv]wdelch");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000508}
509
510static PyObject *
511PyCursesWindow_EchoChar(self,arg)
512 PyCursesWindowObject *self;
513 PyObject * arg;
514{
515 int rtn;
516 int ch;
Guido van Rossum85738471995-02-17 13:50:17 +0000517 int attr, attr_old;
518
519 switch (ARG_COUNT(arg)) {
520 case 1:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000521 if (!PyArg_Parse(arg,"i;ch", &ch))
Guido van Rossum85738471995-02-17 13:50:17 +0000522 return NULL;
523 rtn = wechochar(self->win,ch);
524 break;
525 case 2:
526 if (!PyArg_Parse(arg,"(ii);ch,attr", &ch, &attr))
527 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000528 attr_old = getattrs(self->win);
529 wattrset(self->win,attr);
Guido van Rossum85738471995-02-17 13:50:17 +0000530 rtn = wechochar(self->win,ch);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000531 wattrset(self->win,attr_old);
Guido van Rossum85738471995-02-17 13:50:17 +0000532 break;
533 default:
534 PyErr_SetString(PyExc_TypeError, "echochar requires 1 or 2 arguments");
535 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000536 }
Guido van Rossum85738471995-02-17 13:50:17 +0000537
538 return PyCursesCheckERR(rtn, "wechochar");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000539}
540
541static PyObject *
542PyCursesWindow_AddStr(self,arg)
543 PyCursesWindowObject *self;
544 PyObject * arg;
545{
546 int rtn;
547 int x, y;
548 char *str;
Guido van Rossuma376cc51996-12-05 23:43:35 +0000549 int attr, attr_old = 0;
Guido van Rossum85738471995-02-17 13:50:17 +0000550 int use_xy = FALSE, use_attr = FALSE;
551
552 switch (ARG_COUNT(arg)) {
553 case 1:
554 if (!PyArg_Parse(arg,"s;str", &str))
555 return NULL;
556 break;
557 case 2:
558 if (!PyArg_Parse(arg,"(si);str,attr", &str, &attr))
559 return NULL;
560 use_attr = TRUE;
561 break;
562 case 3:
563 if (!PyArg_Parse(arg,"(iis);y,x,str", &y, &x, &str))
564 return NULL;
565 use_xy = TRUE;
566 break;
567 case 4:
568 if (!PyArg_Parse(arg,"(iisi);y,x,str,attr", &y, &x, &str, &attr))
569 return NULL;
570 use_xy = use_attr = TRUE;
571 break;
572 default:
573 PyErr_SetString(PyExc_TypeError, "addstr requires 1 to 4 arguments");
574 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000575 }
Guido van Rossum85738471995-02-17 13:50:17 +0000576
Guido van Rossumf6971e21994-08-30 12:25:20 +0000577 if (use_attr == TRUE) {
578 attr_old = getattrs(self->win);
579 wattrset(self->win,attr);
580 }
581 if (use_xy == TRUE)
582 rtn = mvwaddstr(self->win,y,x,str);
583 else
584 rtn = waddstr(self->win,str);
585 if (use_attr == TRUE)
586 wattrset(self->win,attr_old);
Guido van Rossum85738471995-02-17 13:50:17 +0000587
588 return PyCursesCheckERR(rtn, "[mv]waddstr");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000589}
590
591static PyObject *
592PyCursesWindow_AttrOn(self,arg)
593 PyCursesWindowObject *self;
594 PyObject * arg;
595{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000596 int ch;
597 if (!PyArg_Parse(arg,"i;attr", &ch))
Guido van Rossum85738471995-02-17 13:50:17 +0000598 return NULL;
599 wattron(self->win,ch);
600 Py_INCREF(Py_None);
601 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000602}
603
604static PyObject *
605PyCursesWindow_AttrOff(self,arg)
606 PyCursesWindowObject *self;
607 PyObject * arg;
608{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000609 int ch;
610 if (!PyArg_Parse(arg,"i;attr", &ch))
Guido van Rossum85738471995-02-17 13:50:17 +0000611 return NULL;
612 wattroff(self->win,ch);
613 Py_INCREF(Py_None);
614 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000615}
616
617static PyObject *
618PyCursesWindow_AttrSet(self,arg)
619 PyCursesWindowObject *self;
620 PyObject * arg;
621{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000622 int ch;
623 if (!PyArg_Parse(arg,"i;attr", &ch))
Guido van Rossum85738471995-02-17 13:50:17 +0000624 return NULL;
625 wattrset(self->win,ch);
626 Py_INCREF(Py_None);
627 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000628}
629
630static PyObject *
631PyCursesWindow_StandEnd(self,arg)
632 PyCursesWindowObject *self;
633 PyObject * arg;
634{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000635 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000636 return NULL;
637 wstandend(self->win);
638 Py_INCREF(Py_None);
639 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000640}
641
642static PyObject *
643PyCursesWindow_StandOut(self,arg)
644 PyCursesWindowObject *self;
645 PyObject * arg;
646{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000647 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000648 return NULL;
649 wstandout(self->win);
650 Py_INCREF(Py_None);
651 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000652}
653
654static PyObject *
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000655PyCursesWindow_Border(self, args)
656 PyCursesWindowObject *self;
657 PyObject *args;
658{
659 int ls, rs, ts, bs, tl, tr, bl, br;
660 ls = rs = ts = bs = tl = tr = bl = br = 0;
661 if (!PyArg_ParseTuple(args,"|iiiiiiii;ls,rs,ts,bs,tl,tr,bl,br",
662 &ls, &rs, &ts, &bs, &tl, &tr, &bl, &br))
663 return NULL;
664 wborder(self->win, ls, rs, ts, bs, tl, tr, bl, br);
665 Py_INCREF(Py_None);
666 return Py_None;
667}
668
669static PyObject *
Guido van Rossumf6971e21994-08-30 12:25:20 +0000670PyCursesWindow_Box(self,arg)
671 PyCursesWindowObject *self;
672 PyObject * arg;
673{
Guido van Rossumf6971e21994-08-30 12:25:20 +0000674 int ch1=0,ch2=0;
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000675 if (!PyArg_NoArgs(arg)) {
Guido van Rossumf6971e21994-08-30 12:25:20 +0000676 PyErr_Clear();
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000677 if (!PyArg_Parse(arg,"(ii);vertch,horch", &ch1, &ch2))
678 return NULL;
679 }
Guido van Rossum85738471995-02-17 13:50:17 +0000680 box(self->win,ch1,ch2);
681 Py_INCREF(Py_None);
682 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000683}
684
685static PyObject *
Guido van Rossum585c6dc1995-02-24 13:45:43 +0000686PyCursesWindow_Hline(self, args)
687 PyCursesWindowObject *self;
688 PyObject *args;
689{
690 int ch, n, x, y, code = OK;
691 switch (ARG_COUNT(args)) {
692 case 2:
693 if (!PyArg_Parse(args, "(ii);ch,n", &ch, &n))
694 return NULL;
695 break;
696 case 4:
697 if (!PyArg_Parse(args, "(iiii);y,x,ch,n", &y, &x, &ch, &n))
698 return NULL;
699 code = wmove(self->win, y, x);
700 break;
701 default:
702 PyErr_SetString(PyExc_TypeError, "hline requires 2 or 4 arguments");
703 return NULL;
704 }
705 if (code != ERR)
706 whline(self->win, ch, n);
707 return PyCursesCheckERR(code, "wmove");
708}
709
710static PyObject *
711PyCursesWindow_Vline(self, args)
712 PyCursesWindowObject *self;
713 PyObject *args;
714{
715 int ch, n, x, y, code = OK;
716 switch (ARG_COUNT(args)) {
717 case 2:
718 if (!PyArg_Parse(args, "(ii);ch,n", &ch, &n))
719 return NULL;
720 break;
721 case 4:
722 if (!PyArg_Parse(args, "(iiii);y,x,ch,n", &y, &x, &ch, &n))
723 return NULL;
724 code = wmove(self->win, y, x);
725 break;
726 default:
727 PyErr_SetString(PyExc_TypeError, "vline requires 2 or 4 arguments");
728 return NULL;
729 }
730 if (code != ERR)
731 wvline(self->win, ch, n);
732 return PyCursesCheckERR(code, "wmove");
733}
734
735static PyObject *
Guido van Rossumf6971e21994-08-30 12:25:20 +0000736PyCursesWindow_Erase(self,arg)
737 PyCursesWindowObject *self;
738 PyObject * arg;
739{
740 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000741 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000742 werase(self->win);
743 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000744 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000745}
746
747static PyObject *
748PyCursesWindow_DeleteLine(self,arg)
749 PyCursesWindowObject *self;
750 PyObject * arg;
751{
752 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000753 return NULL;
754 return PyCursesCheckERR(wdeleteln(self->win), "wdeleteln");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000755}
756
757static PyObject *
758PyCursesWindow_InsertLine(self,arg)
759 PyCursesWindowObject *self;
760 PyObject * arg;
761{
762 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000763 return NULL;
764 return PyCursesCheckERR(winsertln(self->win), "winsertln");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000765}
766
767static PyObject *
768PyCursesWindow_GetYX(self,arg)
769 PyCursesWindowObject *self;
770 PyObject * arg;
771{
772 int x, y;
773 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000774 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000775 getyx(self->win,y,x);
Guido van Rossum85738471995-02-17 13:50:17 +0000776 return Py_BuildValue("(ii)", y, x);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000777}
778
779static PyObject *
780PyCursesWindow_GetBegYX(self,arg)
781 PyCursesWindowObject *self;
782 PyObject * arg;
783{
784 int x, y;
785 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000786 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000787 getbegyx(self->win,y,x);
Guido van Rossum85738471995-02-17 13:50:17 +0000788 return Py_BuildValue("(ii)", y, x);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000789}
790
791static PyObject *
792PyCursesWindow_GetMaxYX(self,arg)
793 PyCursesWindowObject *self;
794 PyObject * arg;
795{
796 int x, y;
797 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000798 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000799 getmaxyx(self->win,y,x);
Guido van Rossum85738471995-02-17 13:50:17 +0000800 return Py_BuildValue("(ii)", y, x);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000801}
802
803static PyObject *
804PyCursesWindow_Clear(self,arg)
805 PyCursesWindowObject *self;
806 PyObject * arg;
807{
808 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000809 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000810 wclear(self->win);
811 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000812 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000813}
814
815static PyObject *
816PyCursesWindow_ClearToBottom(self,arg)
817 PyCursesWindowObject *self;
818 PyObject * arg;
819{
820 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000821 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000822 wclrtobot(self->win);
823 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000824 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000825}
826
827static PyObject *
828PyCursesWindow_ClearToEOL(self,arg)
829 PyCursesWindowObject *self;
830 PyObject * arg;
831{
832 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000833 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000834 wclrtoeol(self->win);
835 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000836 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000837}
838
839static PyObject *
840PyCursesWindow_Scroll(self,arg)
841 PyCursesWindowObject *self;
842 PyObject * arg;
843{
844 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000845 return NULL;
846 return PyCursesCheckERR(scroll(self->win), "scroll");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000847}
848
849static PyObject *
850PyCursesWindow_TouchWin(self,arg)
851 PyCursesWindowObject *self;
852 PyObject * arg;
853{
854 if (!PyArg_NoArgs(arg))
Guido van Rossum85738471995-02-17 13:50:17 +0000855 return NULL;
856 return PyCursesCheckERR(touchwin(self->win), "touchwin");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000857}
858
859static PyObject *
860PyCursesWindow_TouchLine(self,arg)
861 PyCursesWindowObject *self;
862 PyObject * arg;
863{
864 int st, cnt;
Guido van Rossum85738471995-02-17 13:50:17 +0000865 if (!PyArg_Parse(arg,"(ii);start,count",&st,&cnt))
866 return NULL;
867 return PyCursesCheckERR(touchline(self->win,st,cnt), "touchline");
Guido van Rossumf6971e21994-08-30 12:25:20 +0000868}
869
870static PyObject *
871PyCursesWindow_GetCh(self,arg)
872 PyCursesWindowObject *self;
873 PyObject * arg;
874{
875 int x, y;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000876 int rtn;
Guido van Rossum85738471995-02-17 13:50:17 +0000877
878 switch (ARG_COUNT(arg)) {
879 case 0:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000880 rtn = wgetch(self->win);
Guido van Rossum85738471995-02-17 13:50:17 +0000881 break;
882 case 2:
883 if (!PyArg_Parse(arg,"(ii);y,x",&y,&x))
884 return NULL;
885 rtn = mvwgetch(self->win,y,x);
886 break;
887 default:
888 PyErr_SetString(PyExc_TypeError, "getch requires 0 or 2 arguments");
889 return NULL;
890 }
891
892 return PyInt_FromLong((long) rtn);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000893}
894
895static PyObject *
896PyCursesWindow_GetStr(self,arg)
897 PyCursesWindowObject *self;
898 PyObject * arg;
899{
900 int x, y;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000901 char rtn[1024]; /* This should be big enough.. I hope */
902 int rtn2;
Guido van Rossum85738471995-02-17 13:50:17 +0000903
904 switch (ARG_COUNT(arg)) {
905 case 0:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000906 rtn2 = wgetstr(self->win,rtn);
Guido van Rossum85738471995-02-17 13:50:17 +0000907 break;
908 case 2:
909 if (!PyArg_Parse(arg,"(ii);y,x",&y,&x))
910 return NULL;
911 rtn2 = mvwgetstr(self->win,y,x,rtn);
912 break;
913 default:
914 PyErr_SetString(PyExc_TypeError, "getstr requires 0 or 2 arguments");
915 return NULL;
916 }
917
Guido van Rossumf6971e21994-08-30 12:25:20 +0000918 if (rtn2 == ERR)
919 rtn[0] = 0;
Guido van Rossum85738471995-02-17 13:50:17 +0000920 return PyString_FromString(rtn);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000921}
922
923static PyObject *
924PyCursesWindow_InCh(self,arg)
925 PyCursesWindowObject *self;
926 PyObject * arg;
927{
Guido van Rossum85738471995-02-17 13:50:17 +0000928 int x, y, rtn;
929
930 switch (ARG_COUNT(arg)) {
931 case 0:
Guido van Rossumf6971e21994-08-30 12:25:20 +0000932 rtn = winch(self->win);
Guido van Rossum85738471995-02-17 13:50:17 +0000933 break;
934 case 2:
935 if (!PyArg_Parse(arg,"(ii);y,x",&y,&x))
936 return NULL;
937 rtn = mvwinch(self->win,y,x);
938 break;
939 default:
940 PyErr_SetString(PyExc_TypeError, "inch requires 0 or 2 arguments");
941 return NULL;
942 }
943
944 return PyInt_FromLong((long) rtn);
Guido van Rossumf6971e21994-08-30 12:25:20 +0000945}
946
947static PyObject *
948PyCursesWindow_ClearOk(self,arg)
949 PyCursesWindowObject *self;
950 PyObject * arg;
951{
952 int val;
953 if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val))
Guido van Rossum85738471995-02-17 13:50:17 +0000954 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000955 clearok(self->win,val);
956 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000957 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000958}
959
960static PyObject *
961PyCursesWindow_IdlOk(self,arg)
962 PyCursesWindowObject *self;
963 PyObject * arg;
964{
965 int val;
966 if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val))
Guido van Rossum85738471995-02-17 13:50:17 +0000967 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000968 idlok(self->win,val);
969 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000970 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000971}
972
973static PyObject *
974PyCursesWindow_LeaveOk(self,arg)
975 PyCursesWindowObject *self;
976 PyObject * arg;
977{
978 int val;
979 if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val))
Guido van Rossum85738471995-02-17 13:50:17 +0000980 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000981 leaveok(self->win,val);
982 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000983 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000984}
985
986static PyObject *
987PyCursesWindow_ScrollOk(self,arg)
988 PyCursesWindowObject *self;
989 PyObject * arg;
990{
991 int val;
992 if (!PyArg_Parse(arg,"i;True(1) or False(0)",&val))
Guido van Rossum85738471995-02-17 13:50:17 +0000993 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000994 scrollok(self->win,val);
995 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +0000996 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +0000997}
998
999static PyObject *
1000PyCursesWindow_SetScrollRegion(self,arg)
1001 PyCursesWindowObject *self;
1002 PyObject * arg;
1003{
1004 int x, y;
1005 if (!PyArg_Parse(arg,"(ii);top, bottom",&y,&x))
Guido van Rossum85738471995-02-17 13:50:17 +00001006 return NULL;
1007 return PyCursesCheckERR(wsetscrreg(self->win,y,x), "wsetscrreg");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001008}
1009
1010static PyObject *
1011PyCursesWindow_KeyPad(self,arg)
1012 PyCursesWindowObject * self;
1013 PyObject * arg;
1014{
1015 int ch;
1016 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
Guido van Rossum85738471995-02-17 13:50:17 +00001017 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001018 keypad(self->win,ch);
1019 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00001020 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001021}
1022
1023static PyObject *
1024PyCursesWindow_NoDelay(self,arg)
1025 PyCursesWindowObject * self;
1026 PyObject * arg;
1027{
1028 int ch;
1029 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
Guido van Rossum85738471995-02-17 13:50:17 +00001030 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001031 nodelay(self->win,ch);
1032 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00001033 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001034}
1035
1036static PyObject *
1037PyCursesWindow_NoTimeout(self,arg)
1038 PyCursesWindowObject * self;
1039 PyObject * arg;
1040{
1041 int ch;
1042 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
Guido van Rossum85738471995-02-17 13:50:17 +00001043 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001044 notimeout(self->win,ch);
1045 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00001046 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001047}
1048
1049static PyMethodDef PyCursesWindow_Methods[] = {
Sjoerd Mullender14ece161995-03-17 12:18:38 +00001050 {"refresh", (PyCFunction)PyCursesWindow_Refresh},
1051 {"nooutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh},
1052 {"mvwin", (PyCFunction)PyCursesWindow_MoveWin},
1053 {"move", (PyCFunction)PyCursesWindow_Move},
1054 {"subwin", (PyCFunction)PyCursesWindow_SubWin},
1055 {"addch", (PyCFunction)PyCursesWindow_AddCh},
1056 {"insch", (PyCFunction)PyCursesWindow_InsCh},
1057 {"delch", (PyCFunction)PyCursesWindow_DelCh},
1058 {"echochar", (PyCFunction)PyCursesWindow_EchoChar},
1059 {"addstr", (PyCFunction)PyCursesWindow_AddStr},
1060 {"attron", (PyCFunction)PyCursesWindow_AttrOn},
1061 {"attroff", (PyCFunction)PyCursesWindow_AttrOff},
1062 {"attrset", (PyCFunction)PyCursesWindow_AttrSet},
1063 {"standend", (PyCFunction)PyCursesWindow_StandEnd},
1064 {"standout", (PyCFunction)PyCursesWindow_StandOut},
1065 {"border", (PyCFunction)PyCursesWindow_Border, METH_VARARGS},
1066 {"box", (PyCFunction)PyCursesWindow_Box},
1067 {"hline", (PyCFunction)PyCursesWindow_Hline},
1068 {"vline", (PyCFunction)PyCursesWindow_Vline},
1069 {"erase", (PyCFunction)PyCursesWindow_Erase},
1070 {"deleteln", (PyCFunction)PyCursesWindow_DeleteLine},
1071 {"insertln", (PyCFunction)PyCursesWindow_InsertLine},
1072 {"getyx", (PyCFunction)PyCursesWindow_GetYX},
1073 {"getbegyx", (PyCFunction)PyCursesWindow_GetBegYX},
1074 {"getmaxyx", (PyCFunction)PyCursesWindow_GetMaxYX},
1075 {"clear", (PyCFunction)PyCursesWindow_Clear},
1076 {"clrtobot", (PyCFunction)PyCursesWindow_ClearToBottom},
1077 {"clrtoeol", (PyCFunction)PyCursesWindow_ClearToEOL},
1078 {"scroll", (PyCFunction)PyCursesWindow_Scroll},
1079 {"touchwin", (PyCFunction)PyCursesWindow_TouchWin},
1080 {"touchline", (PyCFunction)PyCursesWindow_TouchLine},
1081 {"getch", (PyCFunction)PyCursesWindow_GetCh},
1082 {"getstr", (PyCFunction)PyCursesWindow_GetStr},
1083 {"inch", (PyCFunction)PyCursesWindow_InCh},
1084 {"clearok", (PyCFunction)PyCursesWindow_ClearOk},
1085 {"idlok", (PyCFunction)PyCursesWindow_IdlOk},
1086 {"leaveok", (PyCFunction)PyCursesWindow_LeaveOk},
1087 {"scrollok", (PyCFunction)PyCursesWindow_ScrollOk},
1088 {"setscrreg", (PyCFunction)PyCursesWindow_SetScrollRegion},
1089 {"keypad", (PyCFunction)PyCursesWindow_KeyPad},
1090 {"nodelay", (PyCFunction)PyCursesWindow_NoDelay},
1091 {"notimeout", (PyCFunction)PyCursesWindow_NoTimeout},
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001092 {NULL, NULL} /* sentinel */
Guido van Rossumf6971e21994-08-30 12:25:20 +00001093};
1094
1095static PyObject *
1096PyCursesWindow_GetAttr(self, name)
1097 PyCursesWindowObject *self;
1098 char *name;
1099{
Guido van Rossuma597dde1995-01-10 20:56:29 +00001100 return Py_FindMethod(PyCursesWindow_Methods, (PyObject *)self, name);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001101}
1102
Guido van Rossum85738471995-02-17 13:50:17 +00001103
Guido van Rossumf6971e21994-08-30 12:25:20 +00001104/* --------------- PAD routines ---------------- */
Guido van Rossum85738471995-02-17 13:50:17 +00001105
1106#ifdef NOT_YET
Guido van Rossumf6971e21994-08-30 12:25:20 +00001107static PyObject *
1108PyCursesPad_New(pad)
1109 WINDOW *pad;
1110{
1111 PyCursesPadObject *po;
Guido van Rossum85738471995-02-17 13:50:17 +00001112 po = PyObject_NEW(PyCursesPadObject, &PyCursesPad_Type);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001113 if (po == NULL)
1114 return NULL;
1115 po->pad = pad;
1116 return (PyObject *)po;
1117}
Guido van Rossum85738471995-02-17 13:50:17 +00001118#endif
1119
Guido van Rossumf6971e21994-08-30 12:25:20 +00001120
1121/* -------------------------------------------------------*/
Guido van Rossum85738471995-02-17 13:50:17 +00001122
Guido van Rossuma376cc51996-12-05 23:43:35 +00001123#if 0
Guido van Rossumf6971e21994-08-30 12:25:20 +00001124static PyTypeObject PyCursesScreen_Type = {
1125 PyObject_HEAD_INIT(&PyType_Type)
1126 0, /*ob_size*/
1127 "curses screen", /*tp_name*/
1128 sizeof(PyCursesScreenObject), /*tp_basicsize*/
1129 0, /*tp_itemsize*/
1130 /* methods */
1131 (destructor)0 /*PyCursesScreen_Dealloc*/, /*tp_dealloc*/
1132 0, /*tp_print*/
1133 (getattrfunc)0, /*tp_getattr*/
1134 (setattrfunc)0, /*tp_setattr*/
1135 0, /*tp_compare*/
1136 0, /*tp_repr*/
1137 0, /*tp_as_number*/
1138 0, /*tp_as_sequence*/
1139 0, /*tp_as_mapping*/
1140 0, /*tp_hash*/
1141};
Guido van Rossuma376cc51996-12-05 23:43:35 +00001142#endif
Guido van Rossumf6971e21994-08-30 12:25:20 +00001143
1144static PyTypeObject PyCursesWindow_Type = {
1145 PyObject_HEAD_INIT(&PyType_Type)
1146 0, /*ob_size*/
1147 "curses window", /*tp_name*/
1148 sizeof(PyCursesWindowObject), /*tp_basicsize*/
1149 0, /*tp_itemsize*/
1150 /* methods */
1151 (destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/
1152 0, /*tp_print*/
1153 (getattrfunc)PyCursesWindow_GetAttr, /*tp_getattr*/
1154 (setattrfunc)0, /*tp_setattr*/
1155 0, /*tp_compare*/
1156 0, /*tp_repr*/
1157 0, /*tp_as_number*/
1158 0, /*tp_as_sequence*/
1159 0, /*tp_as_mapping*/
1160 0, /*tp_hash*/
1161};
1162
Guido van Rossuma376cc51996-12-05 23:43:35 +00001163#if 0
Guido van Rossumf6971e21994-08-30 12:25:20 +00001164static PyTypeObject PyCursesPad_Type = {
1165 PyObject_HEAD_INIT(&PyType_Type)
1166 0, /*ob_size*/
1167 "curses pad", /*tp_name*/
1168 sizeof(PyCursesPadObject), /*tp_basicsize*/
1169 0, /*tp_itemsize*/
1170 /* methods */
1171 (destructor)0 /*PyCursesPad_Dealloc*/, /*tp_dealloc*/
1172 0, /*tp_print*/
1173 (getattrfunc)0, /*tp_getattr*/
1174 (setattrfunc)0, /*tp_setattr*/
1175 0, /*tp_compare*/
1176 0, /*tp_repr*/
1177 0, /*tp_as_number*/
1178 0, /*tp_as_sequence*/
1179 0, /*tp_as_mapping*/
1180 0, /*tp_hash*/
1181};
Guido van Rossuma376cc51996-12-05 23:43:35 +00001182#endif
Guido van Rossumf6971e21994-08-30 12:25:20 +00001183
Guido van Rossum85738471995-02-17 13:50:17 +00001184
Guido van Rossumf6971e21994-08-30 12:25:20 +00001185/* -------------------------------------------------------*/
1186
Guido van Rossume4485b01994-09-07 14:32:49 +00001187static PyObject *ModDict;
1188
Guido van Rossumf6971e21994-08-30 12:25:20 +00001189static PyObject *
1190PyCurses_InitScr(self, args)
1191 PyObject * self;
1192 PyObject * args;
1193{
Guido van Rossum56bf2351994-08-31 22:06:24 +00001194 WINDOW *win;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001195 if (!PyArg_NoArgs(args))
Guido van Rossum85738471995-02-17 13:50:17 +00001196 return NULL;
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001197 if (initialised == TRUE) {
Guido van Rossumf6971e21994-08-30 12:25:20 +00001198 wrefresh(stdscr);
1199 return (PyObject *)PyCursesWindow_New(stdscr);
1200 }
Guido van Rossum56bf2351994-08-31 22:06:24 +00001201
1202 win = initscr();
Guido van Rossum85738471995-02-17 13:50:17 +00001203 if (win == NULL) {
1204 PyErr_SetString(PyCursesError, catchall_NULL);
1205 return NULL;
1206 }
1207
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001208 initialised = TRUE;
Guido van Rossum56bf2351994-08-31 22:06:24 +00001209
1210/* This was moved from initcurses() because core dumped on SGI */
Guido van Rossum85738471995-02-17 13:50:17 +00001211/* Also, they are probably not defined until you've called initscr() */
1212#define SetDictInt(string,ch) \
1213 PyDict_SetItemString(ModDict,string,PyInt_FromLong((long) (ch)));
Guido van Rossum56bf2351994-08-31 22:06:24 +00001214
1215 /* Here are some graphic symbols you can use */
Guido van Rossum85738471995-02-17 13:50:17 +00001216 SetDictInt("ACS_ULCORNER",(ACS_ULCORNER));
1217 SetDictInt("ACS_ULCORNER",(ACS_ULCORNER));
1218 SetDictInt("ACS_LLCORNER",(ACS_LLCORNER));
1219 SetDictInt("ACS_URCORNER",(ACS_URCORNER));
1220 SetDictInt("ACS_LRCORNER",(ACS_LRCORNER));
1221 SetDictInt("ACS_RTEE", (ACS_RTEE));
1222 SetDictInt("ACS_LTEE", (ACS_LTEE));
1223 SetDictInt("ACS_BTEE", (ACS_BTEE));
1224 SetDictInt("ACS_TTEE", (ACS_TTEE));
1225 SetDictInt("ACS_HLINE", (ACS_HLINE));
1226 SetDictInt("ACS_VLINE", (ACS_VLINE));
1227 SetDictInt("ACS_PLUS", (ACS_PLUS));
1228 SetDictInt("ACS_S1", (ACS_S1));
1229 SetDictInt("ACS_S9", (ACS_S9));
1230 SetDictInt("ACS_DIAMOND", (ACS_DIAMOND));
1231 SetDictInt("ACS_CKBOARD", (ACS_CKBOARD));
1232 SetDictInt("ACS_DEGREE", (ACS_DEGREE));
1233 SetDictInt("ACS_PLMINUS", (ACS_PLMINUS));
1234 SetDictInt("ACS_BULLET", (ACS_BULLET));
Guido van Rossum11847891998-12-23 04:45:04 +00001235 SetDictInt("ACS_LARROW", (ACS_LARROW));
1236 SetDictInt("ACS_RARROW", (ACS_RARROW));
Guido van Rossum85738471995-02-17 13:50:17 +00001237 SetDictInt("ACS_DARROW", (ACS_DARROW));
1238 SetDictInt("ACS_UARROW", (ACS_UARROW));
1239 SetDictInt("ACS_BOARD", (ACS_BOARD));
1240 SetDictInt("ACS_LANTERN", (ACS_LANTERN));
1241 SetDictInt("ACS_BLOCK", (ACS_BLOCK));
Guido van Rossum56bf2351994-08-31 22:06:24 +00001242
1243 return (PyObject *)PyCursesWindow_New(win);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001244}
1245
1246static PyObject *
1247PyCurses_EndWin(self, args)
1248 PyObject * self;
1249 PyObject * args;
1250{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001251 if (!PyArg_NoArgs(args) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001252 return NULL;
1253 return PyCursesCheckERR(endwin(), "endwin");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001254}
1255
1256static PyObject *
1257PyCurses_IsEndWin(self, args)
1258 PyObject * self;
1259 PyObject * args;
1260{
1261 if (!PyArg_NoArgs(args))
Guido van Rossum85738471995-02-17 13:50:17 +00001262 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001263 if (isendwin() == FALSE) {
1264 Py_INCREF(Py_False);
1265 return Py_False;
1266 }
1267 Py_INCREF(Py_True);
1268 return Py_True;
1269}
1270
1271static PyObject *
1272PyCurses_DoUpdate(self,arg)
1273 PyObject * self;
1274 PyObject * arg;
1275{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001276 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001277 return NULL;
1278 return PyCursesCheckERR(doupdate(), "doupdate");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001279}
1280
1281static PyObject *
1282PyCurses_NewWindow(self,arg)
1283 PyObject * self;
1284 PyObject * arg;
1285{
1286 WINDOW *win;
1287 int nlines, ncols, begin_y, begin_x;
Guido van Rossum85738471995-02-17 13:50:17 +00001288
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001289 if (!PyCursesInitialised())
1290 return NULL;
Guido van Rossum85738471995-02-17 13:50:17 +00001291 nlines = ncols = 0;
1292 switch (ARG_COUNT(arg)) {
1293 case 2:
1294 if (!PyArg_Parse(arg,"(ii);begin)_y,begin_x",&begin_y,&begin_x))
1295 return NULL;
1296 break;
1297 case 4:
1298 if (!PyArg_Parse(arg, "(iiii);nlines,ncols,begin_y,begin_x",
Guido van Rossumf6971e21994-08-30 12:25:20 +00001299 &nlines,&ncols,&begin_y,&begin_x))
Guido van Rossum85738471995-02-17 13:50:17 +00001300 return NULL;
1301 break;
1302 default:
1303 PyErr_SetString(PyExc_TypeError, "newwin requires 2 or 4 arguments");
1304 return NULL;
1305 }
1306
Guido van Rossumf6971e21994-08-30 12:25:20 +00001307 win = newwin(nlines,ncols,begin_y,begin_x);
1308 if (win == NULL) {
Guido van Rossum85738471995-02-17 13:50:17 +00001309 PyErr_SetString(PyCursesError, catchall_NULL);
1310 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001311 }
Guido van Rossum85738471995-02-17 13:50:17 +00001312
Guido van Rossumf6971e21994-08-30 12:25:20 +00001313 return (PyObject *)PyCursesWindow_New(win);
1314}
1315
1316static PyObject *
1317PyCurses_Beep(self,arg)
1318 PyObject * self;
1319 PyObject * arg;
1320{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001321 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001322 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001323 beep();
1324 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00001325 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001326}
1327
1328static PyObject *
1329PyCurses_Flash(self,arg)
1330 PyObject * self;
1331 PyObject * arg;
1332{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001333 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001334 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001335 flash();
1336 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00001337 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001338}
1339
1340static PyObject *
1341PyCurses_UngetCh(self,arg)
1342 PyObject * self;
1343 PyObject * arg;
1344{
1345 int ch;
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001346 if (!PyArg_Parse(arg,"i;integer",&ch) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001347 return NULL;
1348 return PyCursesCheckERR(ungetch(ch), "ungetch");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001349}
1350
1351static PyObject *
1352PyCurses_FlushInp(self,arg)
1353 PyObject * self;
1354 PyObject * arg;
1355{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001356 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001357 return NULL;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001358 flushinp();
1359 Py_INCREF(Py_None);
Guido van Rossum85738471995-02-17 13:50:17 +00001360 return Py_None;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001361}
1362
1363static PyObject *
1364PyCurses_CBreak(self,arg)
1365 PyObject * self;
1366 PyObject * arg;
1367{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001368 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001369 return NULL;
1370 return PyCursesCheckERR(cbreak(), "cbreak");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001371}
1372
1373static PyObject *
1374PyCurses_NoCBreak(self,arg)
1375 PyObject * self;
1376 PyObject * arg;
1377{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001378 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001379 return NULL;
1380 return PyCursesCheckERR(nocbreak(), "nocbreak");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001381}
1382
1383static PyObject *
1384PyCurses_Echo(self,arg)
1385 PyObject * self;
1386 PyObject * arg;
1387{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001388 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001389 return NULL;
1390 return PyCursesCheckERR(echo(), "echo");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001391}
1392
1393static PyObject *
1394PyCurses_NoEcho(self,arg)
1395 PyObject * self;
1396 PyObject * arg;
1397{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001398 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001399 return NULL;
1400 return PyCursesCheckERR(noecho(), "noecho");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001401}
1402
1403static PyObject *
1404PyCurses_Nl(self,arg)
1405 PyObject * self;
1406 PyObject * arg;
1407{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001408 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001409 return NULL;
1410 return PyCursesCheckERR(nl(), "nl");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001411}
1412
1413static PyObject *
1414PyCurses_NoNl(self,arg)
1415 PyObject * self;
1416 PyObject * arg;
1417{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001418 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001419 return NULL;
1420 return PyCursesCheckERR(nonl(), "nonl");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001421}
1422
1423static PyObject *
1424PyCurses_Raw(self,arg)
1425 PyObject * self;
1426 PyObject * arg;
1427{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001428 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001429 return NULL;
1430 return PyCursesCheckERR(raw(), "raw");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001431}
1432
1433static PyObject *
1434PyCurses_NoRaw(self,arg)
1435 PyObject * self;
1436 PyObject * arg;
1437{
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001438 if (!PyArg_NoArgs(arg) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001439 return NULL;
1440 return PyCursesCheckERR(noraw(), "noraw");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001441}
1442
1443static PyObject *
1444PyCurses_IntrFlush(self,arg)
1445 PyObject * self;
1446 PyObject * arg;
1447{
1448 int ch;
1449 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch))
Guido van Rossum85738471995-02-17 13:50:17 +00001450 return NULL;
1451 return PyCursesCheckERR(intrflush(NULL,ch), "intrflush");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001452}
1453
1454static PyObject *
1455PyCurses_Meta(self,arg)
1456 PyObject * self;
1457 PyObject * arg;
1458{
1459 int ch;
Guido van Rossum585c6dc1995-02-24 13:45:43 +00001460 if (!PyArg_Parse(arg,"i;True(1), False(0)",&ch) || !PyCursesInitialised())
Guido van Rossum85738471995-02-17 13:50:17 +00001461 return NULL;
1462 return PyCursesCheckERR(meta(stdscr, ch), "meta");
Guido van Rossumf6971e21994-08-30 12:25:20 +00001463}
1464
1465static PyObject *
1466PyCurses_KeyName(self,arg)
1467 PyObject * self;
1468 PyObject * arg;
1469{
Guido van Rossumdb4a6291997-05-09 02:17:12 +00001470 const char *knp;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001471 int ch;
1472 if (!PyArg_Parse(arg,"i",&ch))
Guido van Rossum85738471995-02-17 13:50:17 +00001473 return NULL;
1474 knp = keyname(ch);
1475 return PyString_FromString((knp == NULL) ? "" : knp);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001476}
1477
1478#ifdef NOT_YET
1479static PyObject *
1480PyCurses_NewTerm(self, args)
1481 PyObject * self;
1482 PyObject * args;
1483{
1484}
1485
1486static PyObject *
1487PyCurses_SetTerm(self, args)
1488 PyObject * self;
1489 PyObject * args;
1490{
1491}
1492#endif
1493
1494/* List of functions defined in the module */
1495
1496static PyMethodDef PyCurses_methods[] = {
1497 {"initscr", (PyCFunction)PyCurses_InitScr},
1498 {"endwin", (PyCFunction)PyCurses_EndWin},
1499 {"isendwin", (PyCFunction)PyCurses_IsEndWin},
1500 {"doupdate", (PyCFunction)PyCurses_DoUpdate},
1501 {"newwin", (PyCFunction)PyCurses_NewWindow},
1502 {"beep", (PyCFunction)PyCurses_Beep},
1503 {"flash", (PyCFunction)PyCurses_Flash},
1504 {"ungetch", (PyCFunction)PyCurses_UngetCh},
1505 {"flushinp", (PyCFunction)PyCurses_FlushInp},
1506 {"cbreak", (PyCFunction)PyCurses_CBreak},
1507 {"nocbreak", (PyCFunction)PyCurses_NoCBreak},
1508 {"echo", (PyCFunction)PyCurses_Echo},
1509 {"noecho", (PyCFunction)PyCurses_NoEcho},
1510 {"nl", (PyCFunction)PyCurses_Nl},
1511 {"nonl", (PyCFunction)PyCurses_NoNl},
1512 {"raw", (PyCFunction)PyCurses_Raw},
1513 {"noraw", (PyCFunction)PyCurses_NoRaw},
1514 {"intrflush", (PyCFunction)PyCurses_IntrFlush},
1515 {"meta", (PyCFunction)PyCurses_Meta},
1516 {"keyname", (PyCFunction)PyCurses_KeyName},
1517#ifdef NOT_YET
1518 {"newterm", (PyCFunction)PyCurses_NewTerm},
1519 {"set_term", (PyCFunction)PyCurses_SetTerm},
1520#endif
1521 {NULL, NULL} /* sentinel */
1522};
1523
1524/* Initialization function for the module */
1525
Guido van Rossum3886bb61998-12-04 18:50:17 +00001526DL_EXPORT(void)
Guido van Rossum56bf2351994-08-31 22:06:24 +00001527initcurses()
Guido van Rossumf6971e21994-08-30 12:25:20 +00001528{
Guido van Rossum8fbf82b1995-02-17 13:54:04 +00001529 PyObject *m, *d, *v;
Guido van Rossumf6971e21994-08-30 12:25:20 +00001530
1531 /* Create the module and add the functions */
Guido van Rossum56bf2351994-08-31 22:06:24 +00001532 m = Py_InitModule("curses", PyCurses_methods);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001533
Guido van Rossumf6971e21994-08-30 12:25:20 +00001534 /* Add some symbolic constants to the module */
1535 d = PyModule_GetDict(m);
Guido van Rossume4485b01994-09-07 14:32:49 +00001536 ModDict = d; /* For PyCurses_InitScr */
Guido van Rossumfbea2f31994-08-31 22:05:27 +00001537
Guido van Rossum85738471995-02-17 13:50:17 +00001538 /* For exception curses.error */
Guido van Rossum0cb96de1997-10-01 04:29:29 +00001539 PyCursesError = PyErr_NewException("curses.error", NULL, NULL);
Guido van Rossum85738471995-02-17 13:50:17 +00001540 PyDict_SetItemString(d, "error", PyCursesError);
Guido van Rossumfbea2f31994-08-31 22:05:27 +00001541
Guido van Rossum85738471995-02-17 13:50:17 +00001542 /* Make the version available */
Guido van Rossum8fbf82b1995-02-17 13:54:04 +00001543 v = PyString_FromString(PyCursesVersion);
1544 PyDict_SetItemString(d, "version", v);
1545 PyDict_SetItemString(d, "__version__", v);
1546 Py_DECREF(v);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001547
Guido van Rossumf6971e21994-08-30 12:25:20 +00001548 /* Here are some attributes you can add to chars to print */
Guido van Rossum85738471995-02-17 13:50:17 +00001549 SetDictInt("A_NORMAL", A_NORMAL);
1550 SetDictInt("A_STANDOUT", A_STANDOUT);
1551 SetDictInt("A_UNDERLINE", A_UNDERLINE);
1552 SetDictInt("A_REVERSE", A_REVERSE);
1553 SetDictInt("A_BLINK", A_BLINK);
1554 SetDictInt("A_DIM", A_DIM);
1555 SetDictInt("A_BOLD", A_BOLD);
1556 SetDictInt("A_ALTCHARSET", A_ALTCHARSET);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001557
1558 /* Now set everything up for KEY_ variables */
1559 {
1560 int key;
1561 char *key_n;
1562 char *key_n2;
1563 for (key=KEY_MIN;key < KEY_MAX; key++) {
1564 key_n = (char *)keyname(key);
Guido van Rossumf5c6d471995-02-07 15:38:32 +00001565 if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0)
Guido van Rossumf6971e21994-08-30 12:25:20 +00001566 continue;
1567 if (strncmp(key_n,"KEY_F(",6)==0) {
1568 char *p1, *p2;
1569 key_n2 = malloc(strlen(key_n)+1);
1570 p1 = key_n;
1571 p2 = key_n2;
1572 while (*p1) {
1573 if (*p1 != '(' && *p1 != ')') {
1574 *p2 = *p1;
1575 p2++;
1576 }
1577 p1++;
1578 }
1579 *p2 = (char)0;
1580 } else
1581 key_n2 = key_n;
Guido van Rossum85738471995-02-17 13:50:17 +00001582 PyDict_SetItemString(d,key_n2,PyInt_FromLong((long) key));
Guido van Rossumf6971e21994-08-30 12:25:20 +00001583 if (key_n2 != key_n)
1584 free(key_n2);
1585 }
Guido van Rossum85738471995-02-17 13:50:17 +00001586 SetDictInt("KEY_MIN", KEY_MIN);
1587 SetDictInt("KEY_MAX", KEY_MAX);
Guido van Rossumf6971e21994-08-30 12:25:20 +00001588 }
Guido van Rossumf6971e21994-08-30 12:25:20 +00001589}