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