ยปCore Development>Code coverage>Modules/_cursesmodule.c

Python code coverage for Modules/_cursesmodule.c

#countcontent
1n/a/*
2n/a * This is a curses module for Python.
3n/a *
4n/a * Based on prior work by Lance Ellinghaus and Oliver Andrich
5n/a * Version 1.2 of this module: Copyright 1994 by Lance Ellinghouse,
6n/a * Cathedral City, California Republic, United States of America.
7n/a *
8n/a * Version 1.5b1, heavily extended for ncurses by Oliver Andrich:
9n/a * Copyright 1996,1997 by Oliver Andrich, Koblenz, Germany.
10n/a *
11n/a * Tidied for Python 1.6, and currently maintained by <amk@amk.ca>.
12n/a *
13n/a * Permission is hereby granted, free of charge, to any person obtaining
14n/a * a copy of this source file to use, copy, modify, merge, or publish it
15n/a * subject to the following conditions:
16n/a *
17n/a * The above copyright notice and this permission notice shall be included
18n/a * in all copies or in any new file that contains a substantial portion of
19n/a * this file.
20n/a *
21n/a * THE AUTHOR MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF
22n/a * THE SOFTWARE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT
23n/a * EXPRESS OR IMPLIED WARRANTY. THE AUTHOR DISCLAIMS ALL WARRANTIES
24n/a * WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
25n/a * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26n/a * NON-INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE
27n/a * AUTHOR BE LIABLE TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL,
28n/a * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
29n/a * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE, STRICT LIABILITY OR
30n/a * ANY OTHER ACTION ARISING OUT OF OR IN CONNECTION WITH THE USE OR
31n/a * PERFORMANCE OF THIS SOFTWARE.
32n/a */
33n/a
34n/a/*
35n/a
36n/a A number of SysV or ncurses functions don't have wrappers yet; if you
37n/a need a given function, add it and send a patch. See
38n/a http://www.python.org/dev/patches/ for instructions on how to submit
39n/a patches to Python.
40n/a
41n/a Here's a list of currently unsupported functions:
42n/a
43n/a addchnstr addchstr color_set define_key
44n/a del_curterm delscreen dupwin inchnstr inchstr innstr keyok
45n/a mcprint mvaddchnstr mvaddchstr mvcur mvinchnstr
46n/a mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr
47n/a mvwinchnstr mvwinchstr mvwinnstr newterm
48n/a restartterm ripoffline scr_dump
49n/a scr_init scr_restore scr_set scrl set_curterm set_term setterm
50n/a tgetent tgetflag tgetnum tgetstr tgoto timeout tputs
51n/a vidattr vidputs waddchnstr waddchstr
52n/a wcolor_set winchnstr winchstr winnstr wmouse_trafo wscrl
53n/a
54n/a Low-priority:
55n/a slk_attr slk_attr_off slk_attr_on slk_attr_set slk_attroff
56n/a slk_attron slk_attrset slk_clear slk_color slk_init slk_label
57n/a slk_noutrefresh slk_refresh slk_restore slk_set slk_touch
58n/a
59n/a Menu extension (ncurses and probably SYSV):
60n/a current_item free_item free_menu item_count item_description
61n/a item_index item_init item_name item_opts item_opts_off
62n/a item_opts_on item_term item_userptr item_value item_visible
63n/a menu_back menu_driver menu_fore menu_format menu_grey
64n/a menu_init menu_items menu_mark menu_opts menu_opts_off
65n/a menu_opts_on menu_pad menu_pattern menu_request_by_name
66n/a menu_request_name menu_spacing menu_sub menu_term menu_userptr
67n/a menu_win new_item new_menu pos_menu_cursor post_menu
68n/a scale_menu set_current_item set_item_init set_item_opts
69n/a set_item_term set_item_userptr set_item_value set_menu_back
70n/a set_menu_fore set_menu_format set_menu_grey set_menu_init
71n/a set_menu_items set_menu_mark set_menu_opts set_menu_pad
72n/a set_menu_pattern set_menu_spacing set_menu_sub set_menu_term
73n/a set_menu_userptr set_menu_win set_top_row top_row unpost_menu
74n/a
75n/a Form extension (ncurses and probably SYSV):
76n/a current_field data_ahead data_behind dup_field
77n/a dynamic_fieldinfo field_arg field_back field_buffer
78n/a field_count field_fore field_index field_info field_init
79n/a field_just field_opts field_opts_off field_opts_on field_pad
80n/a field_status field_term field_type field_userptr form_driver
81n/a form_fields form_init form_opts form_opts_off form_opts_on
82n/a form_page form_request_by_name form_request_name form_sub
83n/a form_term form_userptr form_win free_field free_form
84n/a link_field link_fieldtype move_field new_field new_form
85n/a new_page pos_form_cursor post_form scale_form
86n/a set_current_field set_field_back set_field_buffer
87n/a set_field_fore set_field_init set_field_just set_field_opts
88n/a set_field_pad set_field_status set_field_term set_field_type
89n/a set_field_userptr set_fieldtype_arg set_fieldtype_choice
90n/a set_form_fields set_form_init set_form_opts set_form_page
91n/a set_form_sub set_form_term set_form_userptr set_form_win
92n/a set_max_field set_new_page unpost_form
93n/a
94n/a
95n/a*/
96n/a
97n/a/* Release Number */
98n/a
99n/achar *PyCursesVersion = "2.2";
100n/a
101n/a/* Includes */
102n/a
103n/a#define PY_SSIZE_T_CLEAN
104n/a
105n/a#include "Python.h"
106n/a
107n/a
108n/a#ifdef __hpux
109n/a#define STRICT_SYSV_CURSES
110n/a#endif
111n/a
112n/a#define CURSES_MODULE
113n/a#include "py_curses.h"
114n/a
115n/a/* These prototypes are in <term.h>, but including this header
116n/a #defines many common symbols (such as "lines") which breaks the
117n/a curses module in other ways. So the code will just specify
118n/a explicit prototypes here. */
119n/aextern int setupterm(char *,int,int *);
120n/a#ifdef __sgi
121n/a#include <term.h>
122n/a#endif
123n/a
124n/a#ifdef HAVE_LANGINFO_H
125n/a#include <langinfo.h>
126n/a#endif
127n/a
128n/a#if !defined(HAVE_NCURSES_H) && (defined(sgi) || defined(__sun) || defined(SCO5))
129n/a#define STRICT_SYSV_CURSES /* Don't use ncurses extensions */
130n/atypedef chtype attr_t; /* No attr_t type is available */
131n/a#endif
132n/a
133n/a#if defined(_AIX)
134n/a#define STRICT_SYSV_CURSES
135n/a#endif
136n/a
137n/a/*[clinic input]
138n/amodule curses
139n/aclass curses.window "PyCursesWindowObject *" "&PyCursesWindow_Type"
140n/a[clinic start generated code]*/
141n/a/*[clinic end generated code: output=da39a3ee5e6b4b0d input=88c860abdbb50e0c]*/
142n/a
143n/a#include "clinic/_cursesmodule.c.h"
144n/a
145n/a/* Definition of exception curses.error */
146n/a
147n/astatic PyObject *PyCursesError;
148n/a
149n/a/* Tells whether setupterm() has been called to initialise terminfo. */
150n/astatic int initialised_setupterm = FALSE;
151n/a
152n/a/* Tells whether initscr() has been called to initialise curses. */
153n/astatic int initialised = FALSE;
154n/a
155n/a/* Tells whether start_color() has been called to initialise color usage. */
156n/astatic int initialisedcolors = FALSE;
157n/a
158n/astatic char *screen_encoding = NULL;
159n/a
160n/a/* Utility Macros */
161n/a#define PyCursesSetupTermCalled \
162n/a if (initialised_setupterm != TRUE) { \
163n/a PyErr_SetString(PyCursesError, \
164n/a "must call (at least) setupterm() first"); \
165n/a return 0; }
166n/a
167n/a#define PyCursesInitialised \
168n/a if (initialised != TRUE) { \
169n/a PyErr_SetString(PyCursesError, \
170n/a "must call initscr() first"); \
171n/a return 0; }
172n/a
173n/a#define PyCursesInitialisedColor \
174n/a if (initialisedcolors != TRUE) { \
175n/a PyErr_SetString(PyCursesError, \
176n/a "must call start_color() first"); \
177n/a return 0; }
178n/a
179n/a/* Utility Functions */
180n/a
181n/a/*
182n/a * Check the return code from a curses function and return None
183n/a * or raise an exception as appropriate. These are exported using the
184n/a * capsule API.
185n/a */
186n/a
187n/astatic PyObject *
188n/aPyCursesCheckERR(int code, const char *fname)
189n/a{
190n/a if (code != ERR) {
191n/a Py_RETURN_NONE;
192n/a } else {
193n/a if (fname == NULL) {
194n/a PyErr_SetString(PyCursesError, catchall_ERR);
195n/a } else {
196n/a PyErr_Format(PyCursesError, "%s() returned ERR", fname);
197n/a }
198n/a return NULL;
199n/a }
200n/a}
201n/a
202n/a/* Convert an object to a byte (an integer of type chtype):
203n/a
204n/a - int
205n/a - bytes of length 1
206n/a - str of length 1
207n/a
208n/a Return 1 on success, 0 on error (invalid type or integer overflow). */
209n/astatic int
210n/aPyCurses_ConvertToChtype(PyCursesWindowObject *win, PyObject *obj, chtype *ch)
211n/a{
212n/a long value;
213n/a if(PyBytes_Check(obj) && PyBytes_Size(obj) == 1) {
214n/a value = (unsigned char)PyBytes_AsString(obj)[0];
215n/a }
216n/a else if (PyUnicode_Check(obj)) {
217n/a if (PyUnicode_GetLength(obj) != 1) {
218n/a PyErr_Format(PyExc_TypeError,
219n/a "expect bytes or str of length 1, or int, "
220n/a "got a str of length %zi",
221n/a PyUnicode_GET_LENGTH(obj));
222n/a return 0;
223n/a }
224n/a value = PyUnicode_READ_CHAR(obj, 0);
225n/a if (128 < value) {
226n/a PyObject *bytes;
227n/a const char *encoding;
228n/a if (win)
229n/a encoding = win->encoding;
230n/a else
231n/a encoding = screen_encoding;
232n/a bytes = PyUnicode_AsEncodedString(obj, encoding, NULL);
233n/a if (bytes == NULL)
234n/a return 0;
235n/a if (PyBytes_GET_SIZE(bytes) == 1)
236n/a value = (unsigned char)PyBytes_AS_STRING(bytes)[0];
237n/a else
238n/a value = -1;
239n/a Py_DECREF(bytes);
240n/a if (value < 0)
241n/a goto overflow;
242n/a }
243n/a }
244n/a else if (PyLong_CheckExact(obj)) {
245n/a int long_overflow;
246n/a value = PyLong_AsLongAndOverflow(obj, &long_overflow);
247n/a if (long_overflow)
248n/a goto overflow;
249n/a }
250n/a else {
251n/a PyErr_Format(PyExc_TypeError,
252n/a "expect bytes or str of length 1, or int, got %s",
253n/a Py_TYPE(obj)->tp_name);
254n/a return 0;
255n/a }
256n/a *ch = (chtype)value;
257n/a if ((long)*ch != value)
258n/a goto overflow;
259n/a return 1;
260n/a
261n/aoverflow:
262n/a PyErr_SetString(PyExc_OverflowError,
263n/a "byte doesn't fit in chtype");
264n/a return 0;
265n/a}
266n/a
267n/a/* Convert an object to a byte (chtype) or a character (cchar_t):
268n/a
269n/a - int
270n/a - bytes of length 1
271n/a - str of length 1
272n/a
273n/a Return:
274n/a
275n/a - 2 if obj is a character (written into *wch)
276n/a - 1 if obj is a byte (written into *ch)
277n/a - 0 on error: raise an exception */
278n/astatic int
279n/aPyCurses_ConvertToCchar_t(PyCursesWindowObject *win, PyObject *obj,
280n/a chtype *ch
281n/a#ifdef HAVE_NCURSESW
282n/a , wchar_t *wch
283n/a#endif
284n/a )
285n/a{
286n/a long value;
287n/a#ifdef HAVE_NCURSESW
288n/a wchar_t buffer[2];
289n/a#endif
290n/a
291n/a if (PyUnicode_Check(obj)) {
292n/a#ifdef HAVE_NCURSESW
293n/a if (PyUnicode_AsWideChar(obj, buffer, 2) != 1) {
294n/a PyErr_Format(PyExc_TypeError,
295n/a "expect bytes or str of length 1, or int, "
296n/a "got a str of length %zi",
297n/a PyUnicode_GET_LENGTH(obj));
298n/a return 0;
299n/a }
300n/a *wch = buffer[0];
301n/a return 2;
302n/a#else
303n/a return PyCurses_ConvertToChtype(win, obj, ch);
304n/a#endif
305n/a }
306n/a else if(PyBytes_Check(obj) && PyBytes_Size(obj) == 1) {
307n/a value = (unsigned char)PyBytes_AsString(obj)[0];
308n/a }
309n/a else if (PyLong_CheckExact(obj)) {
310n/a int overflow;
311n/a value = PyLong_AsLongAndOverflow(obj, &overflow);
312n/a if (overflow) {
313n/a PyErr_SetString(PyExc_OverflowError,
314n/a "int doesn't fit in long");
315n/a return 0;
316n/a }
317n/a }
318n/a else {
319n/a PyErr_Format(PyExc_TypeError,
320n/a "expect bytes or str of length 1, or int, got %s",
321n/a Py_TYPE(obj)->tp_name);
322n/a return 0;
323n/a }
324n/a
325n/a *ch = (chtype)value;
326n/a if ((long)*ch != value) {
327n/a PyErr_Format(PyExc_OverflowError,
328n/a "byte doesn't fit in chtype");
329n/a return 0;
330n/a }
331n/a return 1;
332n/a}
333n/a
334n/a/* Convert an object to a byte string (char*) or a wide character string
335n/a (wchar_t*). Return:
336n/a
337n/a - 2 if obj is a character string (written into *wch)
338n/a - 1 if obj is a byte string (written into *bytes)
339n/a - 0 on error: raise an exception */
340n/astatic int
341n/aPyCurses_ConvertToString(PyCursesWindowObject *win, PyObject *obj,
342n/a PyObject **bytes, wchar_t **wstr)
343n/a{
344n/a if (PyUnicode_Check(obj)) {
345n/a#ifdef HAVE_NCURSESW
346n/a assert (wstr != NULL);
347n/a *wstr = PyUnicode_AsWideCharString(obj, NULL);
348n/a if (*wstr == NULL)
349n/a return 0;
350n/a return 2;
351n/a#else
352n/a assert (wstr == NULL);
353n/a *bytes = PyUnicode_AsEncodedString(obj, win->encoding, NULL);
354n/a if (*bytes == NULL)
355n/a return 0;
356n/a return 1;
357n/a#endif
358n/a }
359n/a else if (PyBytes_Check(obj)) {
360n/a Py_INCREF(obj);
361n/a *bytes = obj;
362n/a return 1;
363n/a }
364n/a
365n/a PyErr_Format(PyExc_TypeError, "expect bytes or str, got %s",
366n/a Py_TYPE(obj)->tp_name);
367n/a return 0;
368n/a}
369n/a
370n/a/* Function versions of the 3 functions for testing whether curses has been
371n/a initialised or not. */
372n/a
373n/astatic int func_PyCursesSetupTermCalled(void)
374n/a{
375n/a PyCursesSetupTermCalled;
376n/a return 1;
377n/a}
378n/a
379n/astatic int func_PyCursesInitialised(void)
380n/a{
381n/a PyCursesInitialised;
382n/a return 1;
383n/a}
384n/a
385n/astatic int func_PyCursesInitialisedColor(void)
386n/a{
387n/a PyCursesInitialisedColor;
388n/a return 1;
389n/a}
390n/a
391n/a/*****************************************************************************
392n/a The Window Object
393n/a******************************************************************************/
394n/a
395n/a/* Definition of the window type */
396n/a
397n/aPyTypeObject PyCursesWindow_Type;
398n/a
399n/a/* Function prototype macros for Window object
400n/a
401n/a X - function name
402n/a TYPE - parameter Type
403n/a ERGSTR - format string for construction of the return value
404n/a PARSESTR - format string for argument parsing
405n/a*/
406n/a
407n/a#define Window_NoArgNoReturnFunction(X) \
408n/a static PyObject *PyCursesWindow_ ## X \
409n/a (PyCursesWindowObject *self, PyObject *args) \
410n/a { return PyCursesCheckERR(X(self->win), # X); }
411n/a
412n/a#define Window_NoArgTrueFalseFunction(X) \
413n/a static PyObject * PyCursesWindow_ ## X \
414n/a (PyCursesWindowObject *self) \
415n/a { \
416n/a if (X (self->win) == FALSE) { Py_RETURN_FALSE; } \
417n/a else { Py_RETURN_TRUE; } }
418n/a
419n/a#define Window_NoArgNoReturnVoidFunction(X) \
420n/a static PyObject * PyCursesWindow_ ## X \
421n/a (PyCursesWindowObject *self) \
422n/a { \
423n/a X(self->win); Py_RETURN_NONE; }
424n/a
425n/a#define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR) \
426n/a static PyObject * PyCursesWindow_ ## X \
427n/a (PyCursesWindowObject *self) \
428n/a { \
429n/a TYPE arg1, arg2; \
430n/a X(self->win,arg1,arg2); return Py_BuildValue(ERGSTR, arg1, arg2); }
431n/a
432n/a#define Window_OneArgNoReturnVoidFunction(X, TYPE, PARSESTR) \
433n/a static PyObject * PyCursesWindow_ ## X \
434n/a (PyCursesWindowObject *self, PyObject *args) \
435n/a { \
436n/a TYPE arg1; \
437n/a if (!PyArg_ParseTuple(args, PARSESTR, &arg1)) return NULL; \
438n/a X(self->win,arg1); Py_RETURN_NONE; }
439n/a
440n/a#define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR) \
441n/a static PyObject * PyCursesWindow_ ## X \
442n/a (PyCursesWindowObject *self, PyObject *args) \
443n/a { \
444n/a TYPE arg1; \
445n/a if (!PyArg_ParseTuple(args,PARSESTR, &arg1)) return NULL; \
446n/a return PyCursesCheckERR(X(self->win, arg1), # X); }
447n/a
448n/a#define Window_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \
449n/a static PyObject * PyCursesWindow_ ## X \
450n/a (PyCursesWindowObject *self, PyObject *args) \
451n/a { \
452n/a TYPE arg1, arg2; \
453n/a if (!PyArg_ParseTuple(args,PARSESTR, &arg1, &arg2)) return NULL; \
454n/a return PyCursesCheckERR(X(self->win, arg1, arg2), # X); }
455n/a
456n/a/* ------------- WINDOW routines --------------- */
457n/a
458n/aWindow_NoArgNoReturnFunction(untouchwin)
459n/aWindow_NoArgNoReturnFunction(touchwin)
460n/aWindow_NoArgNoReturnFunction(redrawwin)
461n/aWindow_NoArgNoReturnFunction(winsertln)
462n/aWindow_NoArgNoReturnFunction(werase)
463n/aWindow_NoArgNoReturnFunction(wdeleteln)
464n/a
465n/aWindow_NoArgTrueFalseFunction(is_wintouched)
466n/a
467n/aWindow_NoArgNoReturnVoidFunction(wsyncup)
468n/aWindow_NoArgNoReturnVoidFunction(wsyncdown)
469n/aWindow_NoArgNoReturnVoidFunction(wstandend)
470n/aWindow_NoArgNoReturnVoidFunction(wstandout)
471n/aWindow_NoArgNoReturnVoidFunction(wcursyncup)
472n/aWindow_NoArgNoReturnVoidFunction(wclrtoeol)
473n/aWindow_NoArgNoReturnVoidFunction(wclrtobot)
474n/aWindow_NoArgNoReturnVoidFunction(wclear)
475n/a
476n/aWindow_OneArgNoReturnVoidFunction(idcok, int, "i;True(1) or False(0)")
477n/aWindow_OneArgNoReturnVoidFunction(immedok, int, "i;True(1) or False(0)")
478n/aWindow_OneArgNoReturnVoidFunction(wtimeout, int, "i;delay")
479n/a
480n/aWindow_NoArg2TupleReturnFunction(getyx, int, "ii")
481n/aWindow_NoArg2TupleReturnFunction(getbegyx, int, "ii")
482n/aWindow_NoArg2TupleReturnFunction(getmaxyx, int, "ii")
483n/aWindow_NoArg2TupleReturnFunction(getparyx, int, "ii")
484n/a
485n/aWindow_OneArgNoReturnFunction(clearok, int, "i;True(1) or False(0)")
486n/aWindow_OneArgNoReturnFunction(idlok, int, "i;True(1) or False(0)")
487n/a#if defined(__NetBSD__)
488n/aWindow_OneArgNoReturnVoidFunction(keypad, int, "i;True(1) or False(0)")
489n/a#else
490n/aWindow_OneArgNoReturnFunction(keypad, int, "i;True(1) or False(0)")
491n/a#endif
492n/aWindow_OneArgNoReturnFunction(leaveok, int, "i;True(1) or False(0)")
493n/a#if defined(__NetBSD__)
494n/aWindow_OneArgNoReturnVoidFunction(nodelay, int, "i;True(1) or False(0)")
495n/a#else
496n/aWindow_OneArgNoReturnFunction(nodelay, int, "i;True(1) or False(0)")
497n/a#endif
498n/aWindow_OneArgNoReturnFunction(notimeout, int, "i;True(1) or False(0)")
499n/aWindow_OneArgNoReturnFunction(scrollok, int, "i;True(1) or False(0)")
500n/aWindow_OneArgNoReturnFunction(winsdelln, int, "i;nlines")
501n/aWindow_OneArgNoReturnFunction(syncok, int, "i;True(1) or False(0)")
502n/a
503n/aWindow_TwoArgNoReturnFunction(mvwin, int, "ii;y,x")
504n/aWindow_TwoArgNoReturnFunction(mvderwin, int, "ii;y,x")
505n/aWindow_TwoArgNoReturnFunction(wmove, int, "ii;y,x")
506n/a#ifndef STRICT_SYSV_CURSES
507n/aWindow_TwoArgNoReturnFunction(wresize, int, "ii;lines,columns")
508n/a#endif
509n/a
510n/a/* Allocation and deallocation of Window Objects */
511n/a
512n/astatic PyObject *
513n/aPyCursesWindow_New(WINDOW *win, const char *encoding)
514n/a{
515n/a PyCursesWindowObject *wo;
516n/a
517n/a if (encoding == NULL) {
518n/a#if defined(MS_WINDOWS)
519n/a char *buffer[100];
520n/a UINT cp;
521n/a cp = GetConsoleOutputCP();
522n/a if (cp != 0) {
523n/a PyOS_snprintf(buffer, sizeof(buffer), "cp%u", cp);
524n/a encoding = buffer;
525n/a }
526n/a#elif defined(CODESET)
527n/a const char *codeset = nl_langinfo(CODESET);
528n/a if (codeset != NULL && codeset[0] != 0)
529n/a encoding = codeset;
530n/a#endif
531n/a if (encoding == NULL)
532n/a encoding = "utf-8";
533n/a }
534n/a
535n/a wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type);
536n/a if (wo == NULL) return NULL;
537n/a wo->win = win;
538n/a wo->encoding = _PyMem_Strdup(encoding);
539n/a if (wo->encoding == NULL) {
540n/a Py_DECREF(wo);
541n/a PyErr_NoMemory();
542n/a return NULL;
543n/a }
544n/a return (PyObject *)wo;
545n/a}
546n/a
547n/astatic void
548n/aPyCursesWindow_Dealloc(PyCursesWindowObject *wo)
549n/a{
550n/a if (wo->win != stdscr) delwin(wo->win);
551n/a if (wo->encoding != NULL)
552n/a PyMem_Free(wo->encoding);
553n/a PyObject_DEL(wo);
554n/a}
555n/a
556n/a/* Addch, Addstr, Addnstr */
557n/a
558n/a/*[clinic input]
559n/a
560n/acurses.window.addch
561n/a
562n/a [
563n/a y: int
564n/a Y-coordinate.
565n/a x: int
566n/a X-coordinate.
567n/a ]
568n/a
569n/a ch: object
570n/a Character to add.
571n/a
572n/a [
573n/a attr: long
574n/a Attributes for the character.
575n/a ]
576n/a /
577n/a
578n/aPaint character ch at (y, x) with attributes attr.
579n/a
580n/aPaint character ch at (y, x) with attributes attr,
581n/aoverwriting any character previously painted at that location.
582n/aBy default, the character position and attributes are the
583n/acurrent settings for the window object.
584n/a[clinic start generated code]*/
585n/a
586n/astatic PyObject *
587n/acurses_window_addch_impl(PyCursesWindowObject *self, int group_left_1, int y,
588n/a int x, PyObject *ch, int group_right_1, long attr)
589n/a/*[clinic end generated code: output=99f7f85078ec06c3 input=5a41efb34a2de338]*/
590n/a{
591n/a PyCursesWindowObject *cwself = (PyCursesWindowObject *)self;
592n/a int coordinates_group = group_left_1;
593n/a int attr_group = group_right_1;
594n/a int rtn;
595n/a int type;
596n/a chtype cch = 0;
597n/a#ifdef HAVE_NCURSESW
598n/a wchar_t wstr[2];
599n/a cchar_t wcval;
600n/a#endif
601n/a const char *funcname;
602n/a
603n/a if (!attr_group)
604n/a attr = A_NORMAL;
605n/a
606n/a#ifdef HAVE_NCURSESW
607n/a type = PyCurses_ConvertToCchar_t(cwself, ch, &cch, wstr);
608n/a if (type == 2) {
609n/a funcname = "add_wch";
610n/a wstr[1] = L'\0';
611n/a setcchar(&wcval, wstr, attr, 0, NULL);
612n/a if (coordinates_group)
613n/a rtn = mvwadd_wch(cwself->win,y,x, &wcval);
614n/a else {
615n/a rtn = wadd_wch(cwself->win, &wcval);
616n/a }
617n/a }
618n/a else
619n/a#else
620n/a type = PyCurses_ConvertToCchar_t(cwself, ch, &cch);
621n/a#endif
622n/a if (type == 1) {
623n/a funcname = "addch";
624n/a if (coordinates_group)
625n/a rtn = mvwaddch(cwself->win,y,x, cch | attr);
626n/a else {
627n/a rtn = waddch(cwself->win, cch | attr);
628n/a }
629n/a }
630n/a else {
631n/a return NULL;
632n/a }
633n/a return PyCursesCheckERR(rtn, funcname);
634n/a}
635n/a
636n/astatic PyObject *
637n/aPyCursesWindow_AddStr(PyCursesWindowObject *self, PyObject *args)
638n/a{
639n/a int rtn;
640n/a int x, y;
641n/a int strtype;
642n/a PyObject *strobj, *bytesobj = NULL;
643n/a#ifdef HAVE_NCURSESW
644n/a wchar_t *wstr = NULL;
645n/a#endif
646n/a attr_t attr = A_NORMAL , attr_old = A_NORMAL;
647n/a long lattr;
648n/a int use_xy = FALSE, use_attr = FALSE;
649n/a const char *funcname;
650n/a
651n/a switch (PyTuple_Size(args)) {
652n/a case 1:
653n/a if (!PyArg_ParseTuple(args,"O;str", &strobj))
654n/a return NULL;
655n/a break;
656n/a case 2:
657n/a if (!PyArg_ParseTuple(args,"Ol;str,attr", &strobj, &lattr))
658n/a return NULL;
659n/a attr = lattr;
660n/a use_attr = TRUE;
661n/a break;
662n/a case 3:
663n/a if (!PyArg_ParseTuple(args,"iiO;int,int,str", &y, &x, &strobj))
664n/a return NULL;
665n/a use_xy = TRUE;
666n/a break;
667n/a case 4:
668n/a if (!PyArg_ParseTuple(args,"iiOl;int,int,str,attr", &y, &x, &strobj, &lattr))
669n/a return NULL;
670n/a attr = lattr;
671n/a use_xy = use_attr = TRUE;
672n/a break;
673n/a default:
674n/a PyErr_SetString(PyExc_TypeError, "addstr requires 1 to 4 arguments");
675n/a return NULL;
676n/a }
677n/a#ifdef HAVE_NCURSESW
678n/a strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, &wstr);
679n/a#else
680n/a strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, NULL);
681n/a#endif
682n/a if (strtype == 0)
683n/a return NULL;
684n/a if (use_attr == TRUE) {
685n/a attr_old = getattrs(self->win);
686n/a (void)wattrset(self->win,attr);
687n/a }
688n/a#ifdef HAVE_NCURSESW
689n/a if (strtype == 2) {
690n/a funcname = "addwstr";
691n/a if (use_xy == TRUE)
692n/a rtn = mvwaddwstr(self->win,y,x,wstr);
693n/a else
694n/a rtn = waddwstr(self->win,wstr);
695n/a PyMem_Free(wstr);
696n/a }
697n/a else
698n/a#endif
699n/a {
700n/a char *str = PyBytes_AS_STRING(bytesobj);
701n/a funcname = "addstr";
702n/a if (use_xy == TRUE)
703n/a rtn = mvwaddstr(self->win,y,x,str);
704n/a else
705n/a rtn = waddstr(self->win,str);
706n/a Py_DECREF(bytesobj);
707n/a }
708n/a if (use_attr == TRUE)
709n/a (void)wattrset(self->win,attr_old);
710n/a return PyCursesCheckERR(rtn, funcname);
711n/a}
712n/a
713n/astatic PyObject *
714n/aPyCursesWindow_AddNStr(PyCursesWindowObject *self, PyObject *args)
715n/a{
716n/a int rtn, x, y, n;
717n/a int strtype;
718n/a PyObject *strobj, *bytesobj = NULL;
719n/a#ifdef HAVE_NCURSESW
720n/a wchar_t *wstr = NULL;
721n/a#endif
722n/a attr_t attr = A_NORMAL , attr_old = A_NORMAL;
723n/a long lattr;
724n/a int use_xy = FALSE, use_attr = FALSE;
725n/a const char *funcname;
726n/a
727n/a switch (PyTuple_Size(args)) {
728n/a case 2:
729n/a if (!PyArg_ParseTuple(args,"Oi;str,n", &strobj, &n))
730n/a return NULL;
731n/a break;
732n/a case 3:
733n/a if (!PyArg_ParseTuple(args,"Oil;str,n,attr", &strobj, &n, &lattr))
734n/a return NULL;
735n/a attr = lattr;
736n/a use_attr = TRUE;
737n/a break;
738n/a case 4:
739n/a if (!PyArg_ParseTuple(args,"iiOi;y,x,str,n", &y, &x, &strobj, &n))
740n/a return NULL;
741n/a use_xy = TRUE;
742n/a break;
743n/a case 5:
744n/a if (!PyArg_ParseTuple(args,"iiOil;y,x,str,n,attr", &y, &x, &strobj, &n, &lattr))
745n/a return NULL;
746n/a attr = lattr;
747n/a use_xy = use_attr = TRUE;
748n/a break;
749n/a default:
750n/a PyErr_SetString(PyExc_TypeError, "addnstr requires 2 to 5 arguments");
751n/a return NULL;
752n/a }
753n/a#ifdef HAVE_NCURSESW
754n/a strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, &wstr);
755n/a#else
756n/a strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, NULL);
757n/a#endif
758n/a if (strtype == 0)
759n/a return NULL;
760n/a
761n/a if (use_attr == TRUE) {
762n/a attr_old = getattrs(self->win);
763n/a (void)wattrset(self->win,attr);
764n/a }
765n/a#ifdef HAVE_NCURSESW
766n/a if (strtype == 2) {
767n/a funcname = "addnwstr";
768n/a if (use_xy == TRUE)
769n/a rtn = mvwaddnwstr(self->win,y,x,wstr,n);
770n/a else
771n/a rtn = waddnwstr(self->win,wstr,n);
772n/a PyMem_Free(wstr);
773n/a }
774n/a else
775n/a#endif
776n/a {
777n/a char *str = PyBytes_AS_STRING(bytesobj);
778n/a funcname = "addnstr";
779n/a if (use_xy == TRUE)
780n/a rtn = mvwaddnstr(self->win,y,x,str,n);
781n/a else
782n/a rtn = waddnstr(self->win,str,n);
783n/a Py_DECREF(bytesobj);
784n/a }
785n/a if (use_attr == TRUE)
786n/a (void)wattrset(self->win,attr_old);
787n/a return PyCursesCheckERR(rtn, funcname);
788n/a}
789n/a
790n/astatic PyObject *
791n/aPyCursesWindow_Bkgd(PyCursesWindowObject *self, PyObject *args)
792n/a{
793n/a PyObject *temp;
794n/a chtype bkgd;
795n/a attr_t attr = A_NORMAL;
796n/a long lattr;
797n/a
798n/a switch (PyTuple_Size(args)) {
799n/a case 1:
800n/a if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
801n/a return NULL;
802n/a break;
803n/a case 2:
804n/a if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr))
805n/a return NULL;
806n/a attr = lattr;
807n/a break;
808n/a default:
809n/a PyErr_SetString(PyExc_TypeError, "bkgd requires 1 or 2 arguments");
810n/a return NULL;
811n/a }
812n/a
813n/a if (!PyCurses_ConvertToChtype(self, temp, &bkgd))
814n/a return NULL;
815n/a
816n/a return PyCursesCheckERR(wbkgd(self->win, bkgd | attr), "bkgd");
817n/a}
818n/a
819n/astatic PyObject *
820n/aPyCursesWindow_AttrOff(PyCursesWindowObject *self, PyObject *args)
821n/a{
822n/a long lattr;
823n/a if (!PyArg_ParseTuple(args,"l;attr", &lattr))
824n/a return NULL;
825n/a return PyCursesCheckERR(wattroff(self->win, (attr_t)lattr), "attroff");
826n/a}
827n/a
828n/astatic PyObject *
829n/aPyCursesWindow_AttrOn(PyCursesWindowObject *self, PyObject *args)
830n/a{
831n/a long lattr;
832n/a if (!PyArg_ParseTuple(args,"l;attr", &lattr))
833n/a return NULL;
834n/a return PyCursesCheckERR(wattron(self->win, (attr_t)lattr), "attron");
835n/a}
836n/a
837n/astatic PyObject *
838n/aPyCursesWindow_AttrSet(PyCursesWindowObject *self, PyObject *args)
839n/a{
840n/a long lattr;
841n/a if (!PyArg_ParseTuple(args,"l;attr", &lattr))
842n/a return NULL;
843n/a return PyCursesCheckERR(wattrset(self->win, (attr_t)lattr), "attrset");
844n/a}
845n/a
846n/astatic PyObject *
847n/aPyCursesWindow_BkgdSet(PyCursesWindowObject *self, PyObject *args)
848n/a{
849n/a PyObject *temp;
850n/a chtype bkgd;
851n/a attr_t attr = A_NORMAL;
852n/a long lattr;
853n/a
854n/a switch (PyTuple_Size(args)) {
855n/a case 1:
856n/a if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
857n/a return NULL;
858n/a break;
859n/a case 2:
860n/a if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr))
861n/a return NULL;
862n/a attr = lattr;
863n/a break;
864n/a default:
865n/a PyErr_SetString(PyExc_TypeError, "bkgdset requires 1 or 2 arguments");
866n/a return NULL;
867n/a }
868n/a
869n/a if (!PyCurses_ConvertToChtype(self, temp, &bkgd))
870n/a return NULL;
871n/a
872n/a wbkgdset(self->win, bkgd | attr);
873n/a return PyCursesCheckERR(0, "bkgdset");
874n/a}
875n/a
876n/astatic PyObject *
877n/aPyCursesWindow_Border(PyCursesWindowObject *self, PyObject *args)
878n/a{
879n/a PyObject *temp[8];
880n/a chtype ch[8];
881n/a int i;
882n/a
883n/a /* Clear the array of parameters */
884n/a for(i=0; i<8; i++) {
885n/a temp[i] = NULL;
886n/a ch[i] = 0;
887n/a }
888n/a
889n/a if (!PyArg_ParseTuple(args,"|OOOOOOOO;ls,rs,ts,bs,tl,tr,bl,br",
890n/a &temp[0], &temp[1], &temp[2], &temp[3],
891n/a &temp[4], &temp[5], &temp[6], &temp[7]))
892n/a return NULL;
893n/a
894n/a for(i=0; i<8; i++) {
895n/a if (temp[i] != NULL && !PyCurses_ConvertToChtype(self, temp[i], &ch[i]))
896n/a return NULL;
897n/a }
898n/a
899n/a wborder(self->win,
900n/a ch[0], ch[1], ch[2], ch[3],
901n/a ch[4], ch[5], ch[6], ch[7]);
902n/a Py_RETURN_NONE;
903n/a}
904n/a
905n/astatic PyObject *
906n/aPyCursesWindow_Box(PyCursesWindowObject *self, PyObject *args)
907n/a{
908n/a chtype ch1=0,ch2=0;
909n/a switch(PyTuple_Size(args)){
910n/a case 0: break;
911n/a default:
912n/a if (!PyArg_ParseTuple(args,"ll;vertint,horint", &ch1, &ch2))
913n/a return NULL;
914n/a }
915n/a box(self->win,ch1,ch2);
916n/a Py_RETURN_NONE;
917n/a}
918n/a
919n/a#if defined(HAVE_NCURSES_H) || defined(MVWDELCH_IS_EXPRESSION)
920n/a#define py_mvwdelch mvwdelch
921n/a#else
922n/aint py_mvwdelch(WINDOW *w, int y, int x)
923n/a{
924n/a mvwdelch(w,y,x);
925n/a /* On HP/UX, mvwdelch already returns. On other systems,
926n/a we may well run into this return statement. */
927n/a return 0;
928n/a}
929n/a#endif
930n/a
931n/a/* chgat, added by Fabian Kreutz <fabian.kreutz at gmx.net> */
932n/a
933n/astatic PyObject *
934n/aPyCursesWindow_ChgAt(PyCursesWindowObject *self, PyObject *args)
935n/a{
936n/a int rtn;
937n/a int x, y;
938n/a int num = -1;
939n/a short color;
940n/a attr_t attr = A_NORMAL;
941n/a long lattr;
942n/a int use_xy = FALSE;
943n/a
944n/a switch (PyTuple_Size(args)) {
945n/a case 1:
946n/a if (!PyArg_ParseTuple(args,"l;attr", &lattr))
947n/a return NULL;
948n/a attr = lattr;
949n/a break;
950n/a case 2:
951n/a if (!PyArg_ParseTuple(args,"il;n,attr", &num, &lattr))
952n/a return NULL;
953n/a attr = lattr;
954n/a break;
955n/a case 3:
956n/a if (!PyArg_ParseTuple(args,"iil;int,int,attr", &y, &x, &lattr))
957n/a return NULL;
958n/a attr = lattr;
959n/a use_xy = TRUE;
960n/a break;
961n/a case 4:
962n/a if (!PyArg_ParseTuple(args,"iiil;int,int,n,attr", &y, &x, &num, &lattr))
963n/a return NULL;
964n/a attr = lattr;
965n/a use_xy = TRUE;
966n/a break;
967n/a default:
968n/a PyErr_SetString(PyExc_TypeError, "chgat requires 1 to 4 arguments");
969n/a return NULL;
970n/a }
971n/a
972n/a color = (short)((attr >> 8) & 0xff);
973n/a attr = attr - (color << 8);
974n/a
975n/a if (use_xy == TRUE) {
976n/a rtn = mvwchgat(self->win,y,x,num,attr,color,NULL);
977n/a touchline(self->win,y,1);
978n/a } else {
979n/a getyx(self->win,y,x);
980n/a rtn = wchgat(self->win,num,attr,color,NULL);
981n/a touchline(self->win,y,1);
982n/a }
983n/a return PyCursesCheckERR(rtn, "chgat");
984n/a}
985n/a
986n/a
987n/astatic PyObject *
988n/aPyCursesWindow_DelCh(PyCursesWindowObject *self, PyObject *args)
989n/a{
990n/a int rtn;
991n/a int x, y;
992n/a
993n/a switch (PyTuple_Size(args)) {
994n/a case 0:
995n/a rtn = wdelch(self->win);
996n/a break;
997n/a case 2:
998n/a if (!PyArg_ParseTuple(args,"ii;y,x", &y, &x))
999n/a return NULL;
1000n/a rtn = py_mvwdelch(self->win,y,x);
1001n/a break;
1002n/a default:
1003n/a PyErr_SetString(PyExc_TypeError, "delch requires 0 or 2 arguments");
1004n/a return NULL;
1005n/a }
1006n/a return PyCursesCheckERR(rtn, "[mv]wdelch");
1007n/a}
1008n/a
1009n/astatic PyObject *
1010n/aPyCursesWindow_DerWin(PyCursesWindowObject *self, PyObject *args)
1011n/a{
1012n/a WINDOW *win;
1013n/a int nlines, ncols, begin_y, begin_x;
1014n/a
1015n/a nlines = 0;
1016n/a ncols = 0;
1017n/a switch (PyTuple_Size(args)) {
1018n/a case 2:
1019n/a if (!PyArg_ParseTuple(args,"ii;begin_y,begin_x",&begin_y,&begin_x))
1020n/a return NULL;
1021n/a break;
1022n/a case 4:
1023n/a if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x",
1024n/a &nlines,&ncols,&begin_y,&begin_x))
1025n/a return NULL;
1026n/a break;
1027n/a default:
1028n/a PyErr_SetString(PyExc_TypeError, "derwin requires 2 or 4 arguments");
1029n/a return NULL;
1030n/a }
1031n/a
1032n/a win = derwin(self->win,nlines,ncols,begin_y,begin_x);
1033n/a
1034n/a if (win == NULL) {
1035n/a PyErr_SetString(PyCursesError, catchall_NULL);
1036n/a return NULL;
1037n/a }
1038n/a
1039n/a return (PyObject *)PyCursesWindow_New(win, NULL);
1040n/a}
1041n/a
1042n/astatic PyObject *
1043n/aPyCursesWindow_EchoChar(PyCursesWindowObject *self, PyObject *args)
1044n/a{
1045n/a PyObject *temp;
1046n/a chtype ch;
1047n/a attr_t attr = A_NORMAL;
1048n/a long lattr;
1049n/a
1050n/a switch (PyTuple_Size(args)) {
1051n/a case 1:
1052n/a if (!PyArg_ParseTuple(args,"O;ch or int", &temp))
1053n/a return NULL;
1054n/a break;
1055n/a case 2:
1056n/a if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr))
1057n/a return NULL;
1058n/a attr = lattr;
1059n/a break;
1060n/a default:
1061n/a PyErr_SetString(PyExc_TypeError, "echochar requires 1 or 2 arguments");
1062n/a
1063n/a
1064n/a return NULL;
1065n/a }
1066n/a
1067n/a if (!PyCurses_ConvertToChtype(self, temp, &ch))
1068n/a return NULL;
1069n/a
1070n/a#ifdef WINDOW_HAS_FLAGS
1071n/a if (self->win->_flags & _ISPAD)
1072n/a return PyCursesCheckERR(pechochar(self->win, ch | attr),
1073n/a "echochar");
1074n/a else
1075n/a#endif
1076n/a return PyCursesCheckERR(wechochar(self->win, ch | attr),
1077n/a "echochar");
1078n/a}
1079n/a
1080n/a#ifdef NCURSES_MOUSE_VERSION
1081n/astatic PyObject *
1082n/aPyCursesWindow_Enclose(PyCursesWindowObject *self, PyObject *args)
1083n/a{
1084n/a int x, y;
1085n/a if (!PyArg_ParseTuple(args,"ii;y,x", &y, &x))
1086n/a return NULL;
1087n/a
1088n/a return PyLong_FromLong( wenclose(self->win,y,x) );
1089n/a}
1090n/a#endif
1091n/a
1092n/astatic PyObject *
1093n/aPyCursesWindow_GetBkgd(PyCursesWindowObject *self)
1094n/a{
1095n/a return PyLong_FromLong((long) getbkgd(self->win));
1096n/a}
1097n/a
1098n/astatic PyObject *
1099n/aPyCursesWindow_GetCh(PyCursesWindowObject *self, PyObject *args)
1100n/a{
1101n/a int x, y;
1102n/a int rtn;
1103n/a
1104n/a switch (PyTuple_Size(args)) {
1105n/a case 0:
1106n/a Py_BEGIN_ALLOW_THREADS
1107n/a rtn = wgetch(self->win);
1108n/a Py_END_ALLOW_THREADS
1109n/a break;
1110n/a case 2:
1111n/a if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
1112n/a return NULL;
1113n/a Py_BEGIN_ALLOW_THREADS
1114n/a rtn = mvwgetch(self->win,y,x);
1115n/a Py_END_ALLOW_THREADS
1116n/a break;
1117n/a default:
1118n/a PyErr_SetString(PyExc_TypeError, "getch requires 0 or 2 arguments");
1119n/a return NULL;
1120n/a }
1121n/a return PyLong_FromLong((long)rtn);
1122n/a}
1123n/a
1124n/astatic PyObject *
1125n/aPyCursesWindow_GetKey(PyCursesWindowObject *self, PyObject *args)
1126n/a{
1127n/a int x, y;
1128n/a int rtn;
1129n/a
1130n/a switch (PyTuple_Size(args)) {
1131n/a case 0:
1132n/a Py_BEGIN_ALLOW_THREADS
1133n/a rtn = wgetch(self->win);
1134n/a Py_END_ALLOW_THREADS
1135n/a break;
1136n/a case 2:
1137n/a if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
1138n/a return NULL;
1139n/a Py_BEGIN_ALLOW_THREADS
1140n/a rtn = mvwgetch(self->win,y,x);
1141n/a Py_END_ALLOW_THREADS
1142n/a break;
1143n/a default:
1144n/a PyErr_SetString(PyExc_TypeError, "getkey requires 0 or 2 arguments");
1145n/a return NULL;
1146n/a }
1147n/a if (rtn == ERR) {
1148n/a /* getch() returns ERR in nodelay mode */
1149n/a PyErr_CheckSignals();
1150n/a if (!PyErr_Occurred())
1151n/a PyErr_SetString(PyCursesError, "no input");
1152n/a return NULL;
1153n/a } else if (rtn<=255) {
1154n/a return Py_BuildValue("C", rtn);
1155n/a } else {
1156n/a const char *knp;
1157n/a#if defined(__NetBSD__)
1158n/a knp = unctrl(rtn);
1159n/a#else
1160n/a knp = keyname(rtn);
1161n/a#endif
1162n/a return PyUnicode_FromString((knp == NULL) ? "" : knp);
1163n/a }
1164n/a}
1165n/a
1166n/a#ifdef HAVE_NCURSESW
1167n/astatic PyObject *
1168n/aPyCursesWindow_Get_WCh(PyCursesWindowObject *self, PyObject *args)
1169n/a{
1170n/a int x, y;
1171n/a int ct;
1172n/a wint_t rtn;
1173n/a
1174n/a switch (PyTuple_Size(args)) {
1175n/a case 0:
1176n/a Py_BEGIN_ALLOW_THREADS
1177n/a ct = wget_wch(self->win,&rtn);
1178n/a Py_END_ALLOW_THREADS
1179n/a break;
1180n/a case 2:
1181n/a if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
1182n/a return NULL;
1183n/a Py_BEGIN_ALLOW_THREADS
1184n/a ct = mvwget_wch(self->win,y,x,&rtn);
1185n/a Py_END_ALLOW_THREADS
1186n/a break;
1187n/a default:
1188n/a PyErr_SetString(PyExc_TypeError, "get_wch requires 0 or 2 arguments");
1189n/a return NULL;
1190n/a }
1191n/a if (ct == ERR) {
1192n/a if (PyErr_CheckSignals())
1193n/a return NULL;
1194n/a
1195n/a /* get_wch() returns ERR in nodelay mode */
1196n/a PyErr_SetString(PyCursesError, "no input");
1197n/a return NULL;
1198n/a }
1199n/a if (ct == KEY_CODE_YES)
1200n/a return PyLong_FromLong(rtn);
1201n/a else
1202n/a return PyUnicode_FromOrdinal(rtn);
1203n/a}
1204n/a#endif
1205n/a
1206n/astatic PyObject *
1207n/aPyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args)
1208n/a{
1209n/a int x, y, n;
1210n/a char rtn[1024]; /* This should be big enough.. I hope */
1211n/a int rtn2;
1212n/a
1213n/a switch (PyTuple_Size(args)) {
1214n/a case 0:
1215n/a Py_BEGIN_ALLOW_THREADS
1216n/a rtn2 = wgetnstr(self->win,rtn, 1023);
1217n/a Py_END_ALLOW_THREADS
1218n/a break;
1219n/a case 1:
1220n/a if (!PyArg_ParseTuple(args,"i;n", &n))
1221n/a return NULL;
1222n/a if (n < 0) {
1223n/a PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");
1224n/a return NULL;
1225n/a }
1226n/a Py_BEGIN_ALLOW_THREADS
1227n/a rtn2 = wgetnstr(self->win, rtn, Py_MIN(n, 1023));
1228n/a Py_END_ALLOW_THREADS
1229n/a break;
1230n/a case 2:
1231n/a if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
1232n/a return NULL;
1233n/a Py_BEGIN_ALLOW_THREADS
1234n/a#ifdef STRICT_SYSV_CURSES
1235n/a rtn2 = wmove(self->win,y,x)==ERR ? ERR : wgetnstr(self->win, rtn, 1023);
1236n/a#else
1237n/a rtn2 = mvwgetnstr(self->win,y,x,rtn, 1023);
1238n/a#endif
1239n/a Py_END_ALLOW_THREADS
1240n/a break;
1241n/a case 3:
1242n/a if (!PyArg_ParseTuple(args,"iii;y,x,n", &y, &x, &n))
1243n/a return NULL;
1244n/a if (n < 0) {
1245n/a PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");
1246n/a return NULL;
1247n/a }
1248n/a#ifdef STRICT_SYSV_CURSES
1249n/a Py_BEGIN_ALLOW_THREADS
1250n/a rtn2 = wmove(self->win,y,x)==ERR ? ERR :
1251n/a wgetnstr(self->win, rtn, Py_MIN(n, 1023));
1252n/a Py_END_ALLOW_THREADS
1253n/a#else
1254n/a Py_BEGIN_ALLOW_THREADS
1255n/a rtn2 = mvwgetnstr(self->win, y, x, rtn, Py_MIN(n, 1023));
1256n/a Py_END_ALLOW_THREADS
1257n/a#endif
1258n/a break;
1259n/a default:
1260n/a PyErr_SetString(PyExc_TypeError, "getstr requires 0 to 3 arguments");
1261n/a return NULL;
1262n/a }
1263n/a if (rtn2 == ERR)
1264n/a rtn[0] = 0;
1265n/a return PyBytes_FromString(rtn);
1266n/a}
1267n/a
1268n/astatic PyObject *
1269n/aPyCursesWindow_Hline(PyCursesWindowObject *self, PyObject *args)
1270n/a{
1271n/a PyObject *temp;
1272n/a chtype ch;
1273n/a int n, x, y, code = OK;
1274n/a attr_t attr = A_NORMAL;
1275n/a long lattr;
1276n/a
1277n/a switch (PyTuple_Size(args)) {
1278n/a case 2:
1279n/a if (!PyArg_ParseTuple(args, "Oi;ch or int,n", &temp, &n))
1280n/a return NULL;
1281n/a break;
1282n/a case 3:
1283n/a if (!PyArg_ParseTuple(args, "Oil;ch or int,n,attr", &temp, &n, &lattr))
1284n/a return NULL;
1285n/a attr = lattr;
1286n/a break;
1287n/a case 4:
1288n/a if (!PyArg_ParseTuple(args, "iiOi;y,x,ch or int,n", &y, &x, &temp, &n))
1289n/a return NULL;
1290n/a code = wmove(self->win, y, x);
1291n/a break;
1292n/a case 5:
1293n/a if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr",
1294n/a &y, &x, &temp, &n, &lattr))
1295n/a return NULL;
1296n/a attr = lattr;
1297n/a code = wmove(self->win, y, x);
1298n/a break;
1299n/a default:
1300n/a PyErr_SetString(PyExc_TypeError, "hline requires 2 to 5 arguments");
1301n/a return NULL;
1302n/a }
1303n/a
1304n/a if (code != ERR) {
1305n/a if (!PyCurses_ConvertToChtype(self, temp, &ch))
1306n/a return NULL;
1307n/a return PyCursesCheckERR(whline(self->win, ch | attr, n), "hline");
1308n/a } else
1309n/a return PyCursesCheckERR(code, "wmove");
1310n/a}
1311n/a
1312n/astatic PyObject *
1313n/aPyCursesWindow_InsCh(PyCursesWindowObject *self, PyObject *args)
1314n/a{
1315n/a int rtn, x, y, use_xy = FALSE;
1316n/a PyObject *temp;
1317n/a chtype ch = 0;
1318n/a attr_t attr = A_NORMAL;
1319n/a long lattr;
1320n/a
1321n/a switch (PyTuple_Size(args)) {
1322n/a case 1:
1323n/a if (!PyArg_ParseTuple(args, "O;ch or int", &temp))
1324n/a return NULL;
1325n/a break;
1326n/a case 2:
1327n/a if (!PyArg_ParseTuple(args, "Ol;ch or int,attr", &temp, &lattr))
1328n/a return NULL;
1329n/a attr = lattr;
1330n/a break;
1331n/a case 3:
1332n/a if (!PyArg_ParseTuple(args,"iiO;y,x,ch or int", &y, &x, &temp))
1333n/a return NULL;
1334n/a use_xy = TRUE;
1335n/a break;
1336n/a case 4:
1337n/a if (!PyArg_ParseTuple(args,"iiOl;y,x,ch or int, attr", &y, &x, &temp, &lattr))
1338n/a return NULL;
1339n/a attr = lattr;
1340n/a use_xy = TRUE;
1341n/a break;
1342n/a default:
1343n/a PyErr_SetString(PyExc_TypeError, "insch requires 1 or 4 arguments");
1344n/a return NULL;
1345n/a }
1346n/a
1347n/a if (!PyCurses_ConvertToChtype(self, temp, &ch))
1348n/a return NULL;
1349n/a
1350n/a if (use_xy == TRUE)
1351n/a rtn = mvwinsch(self->win,y,x, ch | attr);
1352n/a else {
1353n/a rtn = winsch(self->win, ch | attr);
1354n/a }
1355n/a return PyCursesCheckERR(rtn, "insch");
1356n/a}
1357n/a
1358n/astatic PyObject *
1359n/aPyCursesWindow_InCh(PyCursesWindowObject *self, PyObject *args)
1360n/a{
1361n/a int x, y;
1362n/a unsigned long rtn;
1363n/a
1364n/a switch (PyTuple_Size(args)) {
1365n/a case 0:
1366n/a rtn = winch(self->win);
1367n/a break;
1368n/a case 2:
1369n/a if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
1370n/a return NULL;
1371n/a rtn = mvwinch(self->win,y,x);
1372n/a break;
1373n/a default:
1374n/a PyErr_SetString(PyExc_TypeError, "inch requires 0 or 2 arguments");
1375n/a return NULL;
1376n/a }
1377n/a return PyLong_FromUnsignedLong(rtn);
1378n/a}
1379n/a
1380n/astatic PyObject *
1381n/aPyCursesWindow_InStr(PyCursesWindowObject *self, PyObject *args)
1382n/a{
1383n/a int x, y, n;
1384n/a char rtn[1024]; /* This should be big enough.. I hope */
1385n/a int rtn2;
1386n/a
1387n/a switch (PyTuple_Size(args)) {
1388n/a case 0:
1389n/a rtn2 = winnstr(self->win,rtn, 1023);
1390n/a break;
1391n/a case 1:
1392n/a if (!PyArg_ParseTuple(args,"i;n", &n))
1393n/a return NULL;
1394n/a if (n < 0) {
1395n/a PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");
1396n/a return NULL;
1397n/a }
1398n/a rtn2 = winnstr(self->win, rtn, Py_MIN(n, 1023));
1399n/a break;
1400n/a case 2:
1401n/a if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
1402n/a return NULL;
1403n/a rtn2 = mvwinnstr(self->win,y,x,rtn,1023);
1404n/a break;
1405n/a case 3:
1406n/a if (!PyArg_ParseTuple(args, "iii;y,x,n", &y, &x, &n))
1407n/a return NULL;
1408n/a if (n < 0) {
1409n/a PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");
1410n/a return NULL;
1411n/a }
1412n/a rtn2 = mvwinnstr(self->win, y, x, rtn, Py_MIN(n,1023));
1413n/a break;
1414n/a default:
1415n/a PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments");
1416n/a return NULL;
1417n/a }
1418n/a if (rtn2 == ERR)
1419n/a rtn[0] = 0;
1420n/a return PyBytes_FromString(rtn);
1421n/a}
1422n/a
1423n/astatic PyObject *
1424n/aPyCursesWindow_InsStr(PyCursesWindowObject *self, PyObject *args)
1425n/a{
1426n/a int rtn;
1427n/a int x, y;
1428n/a int strtype;
1429n/a PyObject *strobj, *bytesobj = NULL;
1430n/a#ifdef HAVE_NCURSESW
1431n/a wchar_t *wstr = NULL;
1432n/a#endif
1433n/a attr_t attr = A_NORMAL , attr_old = A_NORMAL;
1434n/a long lattr;
1435n/a int use_xy = FALSE, use_attr = FALSE;
1436n/a const char *funcname;
1437n/a
1438n/a switch (PyTuple_Size(args)) {
1439n/a case 1:
1440n/a if (!PyArg_ParseTuple(args,"O;str", &strobj))
1441n/a return NULL;
1442n/a break;
1443n/a case 2:
1444n/a if (!PyArg_ParseTuple(args,"Ol;str,attr", &strobj, &lattr))
1445n/a return NULL;
1446n/a attr = lattr;
1447n/a use_attr = TRUE;
1448n/a break;
1449n/a case 3:
1450n/a if (!PyArg_ParseTuple(args,"iiO;y,x,str", &y, &x, &strobj))
1451n/a return NULL;
1452n/a use_xy = TRUE;
1453n/a break;
1454n/a case 4:
1455n/a if (!PyArg_ParseTuple(args,"iiOl;y,x,str,attr", &y, &x, &strobj, &lattr))
1456n/a return NULL;
1457n/a attr = lattr;
1458n/a use_xy = use_attr = TRUE;
1459n/a break;
1460n/a default:
1461n/a PyErr_SetString(PyExc_TypeError, "insstr requires 1 to 4 arguments");
1462n/a return NULL;
1463n/a }
1464n/a
1465n/a#ifdef HAVE_NCURSESW
1466n/a strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, &wstr);
1467n/a#else
1468n/a strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, NULL);
1469n/a#endif
1470n/a if (strtype == 0)
1471n/a return NULL;
1472n/a
1473n/a if (use_attr == TRUE) {
1474n/a attr_old = getattrs(self->win);
1475n/a (void)wattrset(self->win,attr);
1476n/a }
1477n/a#ifdef HAVE_NCURSESW
1478n/a if (strtype == 2) {
1479n/a funcname = "inswstr";
1480n/a if (use_xy == TRUE)
1481n/a rtn = mvwins_wstr(self->win,y,x,wstr);
1482n/a else
1483n/a rtn = wins_wstr(self->win,wstr);
1484n/a PyMem_Free(wstr);
1485n/a }
1486n/a else
1487n/a#endif
1488n/a {
1489n/a char *str = PyBytes_AS_STRING(bytesobj);
1490n/a funcname = "insstr";
1491n/a if (use_xy == TRUE)
1492n/a rtn = mvwinsstr(self->win,y,x,str);
1493n/a else
1494n/a rtn = winsstr(self->win,str);
1495n/a Py_DECREF(bytesobj);
1496n/a }
1497n/a if (use_attr == TRUE)
1498n/a (void)wattrset(self->win,attr_old);
1499n/a return PyCursesCheckERR(rtn, funcname);
1500n/a}
1501n/a
1502n/astatic PyObject *
1503n/aPyCursesWindow_InsNStr(PyCursesWindowObject *self, PyObject *args)
1504n/a{
1505n/a int rtn, x, y, n;
1506n/a int strtype;
1507n/a PyObject *strobj, *bytesobj = NULL;
1508n/a#ifdef HAVE_NCURSESW
1509n/a wchar_t *wstr = NULL;
1510n/a#endif
1511n/a attr_t attr = A_NORMAL , attr_old = A_NORMAL;
1512n/a long lattr;
1513n/a int use_xy = FALSE, use_attr = FALSE;
1514n/a const char *funcname;
1515n/a
1516n/a switch (PyTuple_Size(args)) {
1517n/a case 2:
1518n/a if (!PyArg_ParseTuple(args,"Oi;str,n", &strobj, &n))
1519n/a return NULL;
1520n/a break;
1521n/a case 3:
1522n/a if (!PyArg_ParseTuple(args,"Oil;str,n,attr", &strobj, &n, &lattr))
1523n/a return NULL;
1524n/a attr = lattr;
1525n/a use_attr = TRUE;
1526n/a break;
1527n/a case 4:
1528n/a if (!PyArg_ParseTuple(args,"iiOi;y,x,str,n", &y, &x, &strobj, &n))
1529n/a return NULL;
1530n/a use_xy = TRUE;
1531n/a break;
1532n/a case 5:
1533n/a if (!PyArg_ParseTuple(args,"iiOil;y,x,str,n,attr", &y, &x, &strobj, &n, &lattr))
1534n/a return NULL;
1535n/a attr = lattr;
1536n/a use_xy = use_attr = TRUE;
1537n/a break;
1538n/a default:
1539n/a PyErr_SetString(PyExc_TypeError, "insnstr requires 2 to 5 arguments");
1540n/a return NULL;
1541n/a }
1542n/a
1543n/a#ifdef HAVE_NCURSESW
1544n/a strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, &wstr);
1545n/a#else
1546n/a strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, NULL);
1547n/a#endif
1548n/a if (strtype == 0)
1549n/a return NULL;
1550n/a
1551n/a if (use_attr == TRUE) {
1552n/a attr_old = getattrs(self->win);
1553n/a (void)wattrset(self->win,attr);
1554n/a }
1555n/a#ifdef HAVE_NCURSESW
1556n/a if (strtype == 2) {
1557n/a funcname = "insn_wstr";
1558n/a if (use_xy == TRUE)
1559n/a rtn = mvwins_nwstr(self->win,y,x,wstr,n);
1560n/a else
1561n/a rtn = wins_nwstr(self->win,wstr,n);
1562n/a PyMem_Free(wstr);
1563n/a }
1564n/a else
1565n/a#endif
1566n/a {
1567n/a char *str = PyBytes_AS_STRING(bytesobj);
1568n/a funcname = "insnstr";
1569n/a if (use_xy == TRUE)
1570n/a rtn = mvwinsnstr(self->win,y,x,str,n);
1571n/a else
1572n/a rtn = winsnstr(self->win,str,n);
1573n/a Py_DECREF(bytesobj);
1574n/a }
1575n/a if (use_attr == TRUE)
1576n/a (void)wattrset(self->win,attr_old);
1577n/a return PyCursesCheckERR(rtn, funcname);
1578n/a}
1579n/a
1580n/astatic PyObject *
1581n/aPyCursesWindow_Is_LineTouched(PyCursesWindowObject *self, PyObject *args)
1582n/a{
1583n/a int line, erg;
1584n/a if (!PyArg_ParseTuple(args,"i;line", &line))
1585n/a return NULL;
1586n/a erg = is_linetouched(self->win, line);
1587n/a if (erg == ERR) {
1588n/a PyErr_SetString(PyExc_TypeError,
1589n/a "is_linetouched: line number outside of boundaries");
1590n/a return NULL;
1591n/a } else
1592n/a if (erg == FALSE) {
1593n/a Py_RETURN_FALSE;
1594n/a } else {
1595n/a Py_RETURN_TRUE;
1596n/a }
1597n/a}
1598n/a
1599n/astatic PyObject *
1600n/aPyCursesWindow_NoOutRefresh(PyCursesWindowObject *self, PyObject *args)
1601n/a{
1602n/a int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol;
1603n/a int rtn;
1604n/a
1605n/a#ifndef WINDOW_HAS_FLAGS
1606n/a if (0)
1607n/a#else
1608n/a if (self->win->_flags & _ISPAD)
1609n/a#endif
1610n/a {
1611n/a switch(PyTuple_Size(args)) {
1612n/a case 6:
1613n/a if (!PyArg_ParseTuple(args,
1614n/a "iiiiii;" \
1615n/a "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
1616n/a &pminrow, &pmincol, &sminrow,
1617n/a &smincol, &smaxrow, &smaxcol))
1618n/a return NULL;
1619n/a Py_BEGIN_ALLOW_THREADS
1620n/a rtn = pnoutrefresh(self->win,
1621n/a pminrow, pmincol, sminrow,
1622n/a smincol, smaxrow, smaxcol);
1623n/a Py_END_ALLOW_THREADS
1624n/a return PyCursesCheckERR(rtn, "pnoutrefresh");
1625n/a default:
1626n/a PyErr_SetString(PyCursesError,
1627n/a "noutrefresh() called for a pad "
1628n/a "requires 6 arguments");
1629n/a return NULL;
1630n/a }
1631n/a } else {
1632n/a if (!PyArg_ParseTuple(args, ":noutrefresh"))
1633n/a return NULL;
1634n/a
1635n/a Py_BEGIN_ALLOW_THREADS
1636n/a rtn = wnoutrefresh(self->win);
1637n/a Py_END_ALLOW_THREADS
1638n/a return PyCursesCheckERR(rtn, "wnoutrefresh");
1639n/a }
1640n/a}
1641n/a
1642n/astatic PyObject *
1643n/aPyCursesWindow_Overlay(PyCursesWindowObject *self, PyObject *args)
1644n/a{
1645n/a PyCursesWindowObject *temp;
1646n/a int use_copywin = FALSE;
1647n/a int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol;
1648n/a int rtn;
1649n/a
1650n/a switch (PyTuple_Size(args)) {
1651n/a case 1:
1652n/a if (!PyArg_ParseTuple(args, "O!;window object",
1653n/a &PyCursesWindow_Type, &temp))
1654n/a return NULL;
1655n/a break;
1656n/a case 7:
1657n/a if (!PyArg_ParseTuple(args, "O!iiiiii;window object, int, int, int, int, int, int",
1658n/a &PyCursesWindow_Type, &temp, &sminrow, &smincol,
1659n/a &dminrow, &dmincol, &dmaxrow, &dmaxcol))
1660n/a return NULL;
1661n/a use_copywin = TRUE;
1662n/a break;
1663n/a default:
1664n/a PyErr_SetString(PyExc_TypeError,
1665n/a "overlay requires one or seven arguments");
1666n/a return NULL;
1667n/a }
1668n/a
1669n/a if (use_copywin == TRUE) {
1670n/a rtn = copywin(self->win, temp->win, sminrow, smincol,
1671n/a dminrow, dmincol, dmaxrow, dmaxcol, TRUE);
1672n/a return PyCursesCheckERR(rtn, "copywin");
1673n/a }
1674n/a else {
1675n/a rtn = overlay(self->win, temp->win);
1676n/a return PyCursesCheckERR(rtn, "overlay");
1677n/a }
1678n/a}
1679n/a
1680n/astatic PyObject *
1681n/aPyCursesWindow_Overwrite(PyCursesWindowObject *self, PyObject *args)
1682n/a{
1683n/a PyCursesWindowObject *temp;
1684n/a int use_copywin = FALSE;
1685n/a int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol;
1686n/a int rtn;
1687n/a
1688n/a switch (PyTuple_Size(args)) {
1689n/a case 1:
1690n/a if (!PyArg_ParseTuple(args, "O!;window object",
1691n/a &PyCursesWindow_Type, &temp))
1692n/a return NULL;
1693n/a break;
1694n/a case 7:
1695n/a if (!PyArg_ParseTuple(args, "O!iiiiii;window object, int, int, int, int, int, int",
1696n/a &PyCursesWindow_Type, &temp, &sminrow, &smincol,
1697n/a &dminrow, &dmincol, &dmaxrow, &dmaxcol))
1698n/a return NULL;
1699n/a use_copywin = TRUE;
1700n/a break;
1701n/a default:
1702n/a PyErr_SetString(PyExc_TypeError,
1703n/a "overwrite requires one or seven arguments");
1704n/a return NULL;
1705n/a }
1706n/a
1707n/a if (use_copywin == TRUE) {
1708n/a rtn = copywin(self->win, temp->win, sminrow, smincol,
1709n/a dminrow, dmincol, dmaxrow, dmaxcol, FALSE);
1710n/a return PyCursesCheckERR(rtn, "copywin");
1711n/a }
1712n/a else {
1713n/a rtn = overwrite(self->win, temp->win);
1714n/a return PyCursesCheckERR(rtn, "overwrite");
1715n/a }
1716n/a}
1717n/a
1718n/astatic PyObject *
1719n/aPyCursesWindow_PutWin(PyCursesWindowObject *self, PyObject *stream)
1720n/a{
1721n/a /* We have to simulate this by writing to a temporary FILE*,
1722n/a then reading back, then writing to the argument stream. */
1723n/a char fn[100];
1724n/a int fd = -1;
1725n/a FILE *fp = NULL;
1726n/a PyObject *res = NULL;
1727n/a
1728n/a strcpy(fn, "/tmp/py.curses.putwin.XXXXXX");
1729n/a fd = mkstemp(fn);
1730n/a if (fd < 0)
1731n/a return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn);
1732n/a if (_Py_set_inheritable(fd, 0, NULL) < 0)
1733n/a goto exit;
1734n/a fp = fdopen(fd, "wb+");
1735n/a if (fp == NULL) {
1736n/a PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn);
1737n/a goto exit;
1738n/a }
1739n/a res = PyCursesCheckERR(putwin(self->win, fp), "putwin");
1740n/a if (res == NULL)
1741n/a goto exit;
1742n/a fseek(fp, 0, 0);
1743n/a while (1) {
1744n/a char buf[BUFSIZ];
1745n/a Py_ssize_t n = fread(buf, 1, BUFSIZ, fp);
1746n/a _Py_IDENTIFIER(write);
1747n/a
1748n/a if (n <= 0)
1749n/a break;
1750n/a Py_DECREF(res);
1751n/a res = _PyObject_CallMethodId(stream, &PyId_write, "y#", buf, n);
1752n/a if (res == NULL)
1753n/a break;
1754n/a }
1755n/a
1756n/aexit:
1757n/a if (fp != NULL)
1758n/a fclose(fp);
1759n/a else if (fd != -1)
1760n/a close(fd);
1761n/a remove(fn);
1762n/a return res;
1763n/a}
1764n/a
1765n/astatic PyObject *
1766n/aPyCursesWindow_RedrawLine(PyCursesWindowObject *self, PyObject *args)
1767n/a{
1768n/a int beg, num;
1769n/a if (!PyArg_ParseTuple(args, "ii;beg,num", &beg, &num))
1770n/a return NULL;
1771n/a return PyCursesCheckERR(wredrawln(self->win,beg,num), "redrawln");
1772n/a}
1773n/a
1774n/astatic PyObject *
1775n/aPyCursesWindow_Refresh(PyCursesWindowObject *self, PyObject *args)
1776n/a{
1777n/a int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol;
1778n/a int rtn;
1779n/a
1780n/a#ifndef WINDOW_HAS_FLAGS
1781n/a if (0)
1782n/a#else
1783n/a if (self->win->_flags & _ISPAD)
1784n/a#endif
1785n/a {
1786n/a switch(PyTuple_Size(args)) {
1787n/a case 6:
1788n/a if (!PyArg_ParseTuple(args,
1789n/a "iiiiii;" \
1790n/a "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol",
1791n/a &pminrow, &pmincol, &sminrow,
1792n/a &smincol, &smaxrow, &smaxcol))
1793n/a return NULL;
1794n/a
1795n/a Py_BEGIN_ALLOW_THREADS
1796n/a rtn = prefresh(self->win,
1797n/a pminrow, pmincol, sminrow,
1798n/a smincol, smaxrow, smaxcol);
1799n/a Py_END_ALLOW_THREADS
1800n/a return PyCursesCheckERR(rtn, "prefresh");
1801n/a default:
1802n/a PyErr_SetString(PyCursesError,
1803n/a "refresh() for a pad requires 6 arguments");
1804n/a return NULL;
1805n/a }
1806n/a } else {
1807n/a if (!PyArg_ParseTuple(args, ":refresh"))
1808n/a return NULL;
1809n/a Py_BEGIN_ALLOW_THREADS
1810n/a rtn = wrefresh(self->win);
1811n/a Py_END_ALLOW_THREADS
1812n/a return PyCursesCheckERR(rtn, "prefresh");
1813n/a }
1814n/a}
1815n/a
1816n/astatic PyObject *
1817n/aPyCursesWindow_SetScrollRegion(PyCursesWindowObject *self, PyObject *args)
1818n/a{
1819n/a int x, y;
1820n/a if (!PyArg_ParseTuple(args,"ii;top, bottom",&y,&x))
1821n/a return NULL;
1822n/a return PyCursesCheckERR(wsetscrreg(self->win,y,x), "wsetscrreg");
1823n/a}
1824n/a
1825n/astatic PyObject *
1826n/aPyCursesWindow_SubWin(PyCursesWindowObject *self, PyObject *args)
1827n/a{
1828n/a WINDOW *win;
1829n/a int nlines, ncols, begin_y, begin_x;
1830n/a
1831n/a nlines = 0;
1832n/a ncols = 0;
1833n/a switch (PyTuple_Size(args)) {
1834n/a case 2:
1835n/a if (!PyArg_ParseTuple(args,"ii;begin_y,begin_x",&begin_y,&begin_x))
1836n/a return NULL;
1837n/a break;
1838n/a case 4:
1839n/a if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x",
1840n/a &nlines,&ncols,&begin_y,&begin_x))
1841n/a return NULL;
1842n/a break;
1843n/a default:
1844n/a PyErr_SetString(PyExc_TypeError, "subwin requires 2 or 4 arguments");
1845n/a return NULL;
1846n/a }
1847n/a
1848n/a /* printf("Subwin: %i %i %i %i \n", nlines, ncols, begin_y, begin_x); */
1849n/a#ifdef WINDOW_HAS_FLAGS
1850n/a if (self->win->_flags & _ISPAD)
1851n/a win = subpad(self->win, nlines, ncols, begin_y, begin_x);
1852n/a else
1853n/a#endif
1854n/a win = subwin(self->win, nlines, ncols, begin_y, begin_x);
1855n/a
1856n/a if (win == NULL) {
1857n/a PyErr_SetString(PyCursesError, catchall_NULL);
1858n/a return NULL;
1859n/a }
1860n/a
1861n/a return (PyObject *)PyCursesWindow_New(win, self->encoding);
1862n/a}
1863n/a
1864n/astatic PyObject *
1865n/aPyCursesWindow_Scroll(PyCursesWindowObject *self, PyObject *args)
1866n/a{
1867n/a int nlines;
1868n/a switch(PyTuple_Size(args)) {
1869n/a case 0:
1870n/a return PyCursesCheckERR(scroll(self->win), "scroll");
1871n/a case 1:
1872n/a if (!PyArg_ParseTuple(args, "i;nlines", &nlines))
1873n/a return NULL;
1874n/a return PyCursesCheckERR(wscrl(self->win, nlines), "scroll");
1875n/a default:
1876n/a PyErr_SetString(PyExc_TypeError, "scroll requires 0 or 1 arguments");
1877n/a return NULL;
1878n/a }
1879n/a}
1880n/a
1881n/astatic PyObject *
1882n/aPyCursesWindow_TouchLine(PyCursesWindowObject *self, PyObject *args)
1883n/a{
1884n/a int st, cnt, val;
1885n/a switch (PyTuple_Size(args)) {
1886n/a case 2:
1887n/a if (!PyArg_ParseTuple(args,"ii;start,count",&st,&cnt))
1888n/a return NULL;
1889n/a return PyCursesCheckERR(touchline(self->win,st,cnt), "touchline");
1890n/a case 3:
1891n/a if (!PyArg_ParseTuple(args, "iii;start,count,val", &st, &cnt, &val))
1892n/a return NULL;
1893n/a return PyCursesCheckERR(wtouchln(self->win, st, cnt, val), "touchline");
1894n/a default:
1895n/a PyErr_SetString(PyExc_TypeError, "touchline requires 2 or 3 arguments");
1896n/a return NULL;
1897n/a }
1898n/a}
1899n/a
1900n/astatic PyObject *
1901n/aPyCursesWindow_Vline(PyCursesWindowObject *self, PyObject *args)
1902n/a{
1903n/a PyObject *temp;
1904n/a chtype ch;
1905n/a int n, x, y, code = OK;
1906n/a attr_t attr = A_NORMAL;
1907n/a long lattr;
1908n/a
1909n/a switch (PyTuple_Size(args)) {
1910n/a case 2:
1911n/a if (!PyArg_ParseTuple(args, "Oi;ch or int,n", &temp, &n))
1912n/a return NULL;
1913n/a break;
1914n/a case 3:
1915n/a if (!PyArg_ParseTuple(args, "Oil;ch or int,n,attr", &temp, &n, &lattr))
1916n/a return NULL;
1917n/a attr = lattr;
1918n/a break;
1919n/a case 4:
1920n/a if (!PyArg_ParseTuple(args, "iiOi;y,x,ch or int,n", &y, &x, &temp, &n))
1921n/a return NULL;
1922n/a code = wmove(self->win, y, x);
1923n/a break;
1924n/a case 5:
1925n/a if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr",
1926n/a &y, &x, &temp, &n, &lattr))
1927n/a return NULL;
1928n/a attr = lattr;
1929n/a code = wmove(self->win, y, x);
1930n/a break;
1931n/a default:
1932n/a PyErr_SetString(PyExc_TypeError, "vline requires 2 to 5 arguments");
1933n/a return NULL;
1934n/a }
1935n/a
1936n/a if (code != ERR) {
1937n/a if (!PyCurses_ConvertToChtype(self, temp, &ch))
1938n/a return NULL;
1939n/a return PyCursesCheckERR(wvline(self->win, ch | attr, n), "vline");
1940n/a } else
1941n/a return PyCursesCheckERR(code, "wmove");
1942n/a}
1943n/a
1944n/astatic PyObject *
1945n/aPyCursesWindow_get_encoding(PyCursesWindowObject *self, void *closure)
1946n/a{
1947n/a return PyUnicode_FromString(self->encoding);
1948n/a}
1949n/a
1950n/astatic int
1951n/aPyCursesWindow_set_encoding(PyCursesWindowObject *self, PyObject *value)
1952n/a{
1953n/a PyObject *ascii;
1954n/a char *encoding;
1955n/a
1956n/a /* It is illegal to del win.encoding */
1957n/a if (value == NULL) {
1958n/a PyErr_SetString(PyExc_TypeError,
1959n/a "encoding may not be deleted");
1960n/a return -1;
1961n/a }
1962n/a
1963n/a if (!PyUnicode_Check(value)) {
1964n/a PyErr_SetString(PyExc_TypeError,
1965n/a "setting encoding to a non-string");
1966n/a return -1;
1967n/a }
1968n/a ascii = PyUnicode_AsASCIIString(value);
1969n/a if (ascii == NULL)
1970n/a return -1;
1971n/a encoding = _PyMem_Strdup(PyBytes_AS_STRING(ascii));
1972n/a Py_DECREF(ascii);
1973n/a if (encoding == NULL) {
1974n/a PyErr_NoMemory();
1975n/a return -1;
1976n/a }
1977n/a PyMem_Free(self->encoding);
1978n/a self->encoding = encoding;
1979n/a return 0;
1980n/a}
1981n/a
1982n/a
1983n/astatic PyMethodDef PyCursesWindow_Methods[] = {
1984n/a CURSES_WINDOW_ADDCH_METHODDEF
1985n/a {"addnstr", (PyCFunction)PyCursesWindow_AddNStr, METH_VARARGS},
1986n/a {"addstr", (PyCFunction)PyCursesWindow_AddStr, METH_VARARGS},
1987n/a {"attroff", (PyCFunction)PyCursesWindow_AttrOff, METH_VARARGS},
1988n/a {"attron", (PyCFunction)PyCursesWindow_AttrOn, METH_VARARGS},
1989n/a {"attrset", (PyCFunction)PyCursesWindow_AttrSet, METH_VARARGS},
1990n/a {"bkgd", (PyCFunction)PyCursesWindow_Bkgd, METH_VARARGS},
1991n/a {"chgat", (PyCFunction)PyCursesWindow_ChgAt, METH_VARARGS},
1992n/a {"bkgdset", (PyCFunction)PyCursesWindow_BkgdSet, METH_VARARGS},
1993n/a {"border", (PyCFunction)PyCursesWindow_Border, METH_VARARGS},
1994n/a {"box", (PyCFunction)PyCursesWindow_Box, METH_VARARGS},
1995n/a {"clear", (PyCFunction)PyCursesWindow_wclear, METH_NOARGS},
1996n/a {"clearok", (PyCFunction)PyCursesWindow_clearok, METH_VARARGS},
1997n/a {"clrtobot", (PyCFunction)PyCursesWindow_wclrtobot, METH_NOARGS},
1998n/a {"clrtoeol", (PyCFunction)PyCursesWindow_wclrtoeol, METH_NOARGS},
1999n/a {"cursyncup", (PyCFunction)PyCursesWindow_wcursyncup, METH_NOARGS},
2000n/a {"delch", (PyCFunction)PyCursesWindow_DelCh, METH_VARARGS},
2001n/a {"deleteln", (PyCFunction)PyCursesWindow_wdeleteln, METH_NOARGS},
2002n/a {"derwin", (PyCFunction)PyCursesWindow_DerWin, METH_VARARGS},
2003n/a {"echochar", (PyCFunction)PyCursesWindow_EchoChar, METH_VARARGS},
2004n/a#ifdef NCURSES_MOUSE_VERSION
2005n/a {"enclose", (PyCFunction)PyCursesWindow_Enclose, METH_VARARGS},
2006n/a#endif
2007n/a {"erase", (PyCFunction)PyCursesWindow_werase, METH_NOARGS},
2008n/a {"getbegyx", (PyCFunction)PyCursesWindow_getbegyx, METH_NOARGS},
2009n/a {"getbkgd", (PyCFunction)PyCursesWindow_GetBkgd, METH_NOARGS},
2010n/a {"getch", (PyCFunction)PyCursesWindow_GetCh, METH_VARARGS},
2011n/a {"getkey", (PyCFunction)PyCursesWindow_GetKey, METH_VARARGS},
2012n/a#ifdef HAVE_NCURSESW
2013n/a {"get_wch", (PyCFunction)PyCursesWindow_Get_WCh, METH_VARARGS},
2014n/a#endif
2015n/a {"getmaxyx", (PyCFunction)PyCursesWindow_getmaxyx, METH_NOARGS},
2016n/a {"getparyx", (PyCFunction)PyCursesWindow_getparyx, METH_NOARGS},
2017n/a {"getstr", (PyCFunction)PyCursesWindow_GetStr, METH_VARARGS},
2018n/a {"getyx", (PyCFunction)PyCursesWindow_getyx, METH_NOARGS},
2019n/a {"hline", (PyCFunction)PyCursesWindow_Hline, METH_VARARGS},
2020n/a {"idcok", (PyCFunction)PyCursesWindow_idcok, METH_VARARGS},
2021n/a {"idlok", (PyCFunction)PyCursesWindow_idlok, METH_VARARGS},
2022n/a {"immedok", (PyCFunction)PyCursesWindow_immedok, METH_VARARGS},
2023n/a {"inch", (PyCFunction)PyCursesWindow_InCh, METH_VARARGS},
2024n/a {"insch", (PyCFunction)PyCursesWindow_InsCh, METH_VARARGS},
2025n/a {"insdelln", (PyCFunction)PyCursesWindow_winsdelln, METH_VARARGS},
2026n/a {"insertln", (PyCFunction)PyCursesWindow_winsertln, METH_NOARGS},
2027n/a {"insnstr", (PyCFunction)PyCursesWindow_InsNStr, METH_VARARGS},
2028n/a {"insstr", (PyCFunction)PyCursesWindow_InsStr, METH_VARARGS},
2029n/a {"instr", (PyCFunction)PyCursesWindow_InStr, METH_VARARGS},
2030n/a {"is_linetouched", (PyCFunction)PyCursesWindow_Is_LineTouched, METH_VARARGS},
2031n/a {"is_wintouched", (PyCFunction)PyCursesWindow_is_wintouched, METH_NOARGS},
2032n/a {"keypad", (PyCFunction)PyCursesWindow_keypad, METH_VARARGS},
2033n/a {"leaveok", (PyCFunction)PyCursesWindow_leaveok, METH_VARARGS},
2034n/a {"move", (PyCFunction)PyCursesWindow_wmove, METH_VARARGS},
2035n/a {"mvderwin", (PyCFunction)PyCursesWindow_mvderwin, METH_VARARGS},
2036n/a {"mvwin", (PyCFunction)PyCursesWindow_mvwin, METH_VARARGS},
2037n/a {"nodelay", (PyCFunction)PyCursesWindow_nodelay, METH_VARARGS},
2038n/a {"notimeout", (PyCFunction)PyCursesWindow_notimeout, METH_VARARGS},
2039n/a {"noutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh, METH_VARARGS},
2040n/a {"overlay", (PyCFunction)PyCursesWindow_Overlay, METH_VARARGS},
2041n/a {"overwrite", (PyCFunction)PyCursesWindow_Overwrite,
2042n/a METH_VARARGS},
2043n/a {"putwin", (PyCFunction)PyCursesWindow_PutWin, METH_O},
2044n/a {"redrawln", (PyCFunction)PyCursesWindow_RedrawLine, METH_VARARGS},
2045n/a {"redrawwin", (PyCFunction)PyCursesWindow_redrawwin, METH_NOARGS},
2046n/a {"refresh", (PyCFunction)PyCursesWindow_Refresh, METH_VARARGS},
2047n/a#ifndef STRICT_SYSV_CURSES
2048n/a {"resize", (PyCFunction)PyCursesWindow_wresize, METH_VARARGS},
2049n/a#endif
2050n/a {"scroll", (PyCFunction)PyCursesWindow_Scroll, METH_VARARGS},
2051n/a {"scrollok", (PyCFunction)PyCursesWindow_scrollok, METH_VARARGS},
2052n/a {"setscrreg", (PyCFunction)PyCursesWindow_SetScrollRegion, METH_VARARGS},
2053n/a {"standend", (PyCFunction)PyCursesWindow_wstandend, METH_NOARGS},
2054n/a {"standout", (PyCFunction)PyCursesWindow_wstandout, METH_NOARGS},
2055n/a {"subpad", (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS},
2056n/a {"subwin", (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS},
2057n/a {"syncdown", (PyCFunction)PyCursesWindow_wsyncdown, METH_NOARGS},
2058n/a {"syncok", (PyCFunction)PyCursesWindow_syncok, METH_VARARGS},
2059n/a {"syncup", (PyCFunction)PyCursesWindow_wsyncup, METH_NOARGS},
2060n/a {"timeout", (PyCFunction)PyCursesWindow_wtimeout, METH_VARARGS},
2061n/a {"touchline", (PyCFunction)PyCursesWindow_TouchLine, METH_VARARGS},
2062n/a {"touchwin", (PyCFunction)PyCursesWindow_touchwin, METH_NOARGS},
2063n/a {"untouchwin", (PyCFunction)PyCursesWindow_untouchwin, METH_NOARGS},
2064n/a {"vline", (PyCFunction)PyCursesWindow_Vline, METH_VARARGS},
2065n/a {NULL, NULL} /* sentinel */
2066n/a};
2067n/a
2068n/astatic PyGetSetDef PyCursesWindow_getsets[] = {
2069n/a {"encoding",
2070n/a (getter)PyCursesWindow_get_encoding,
2071n/a (setter)PyCursesWindow_set_encoding,
2072n/a "the typecode character used to create the array"},
2073n/a {NULL, NULL, NULL, NULL } /* sentinel */
2074n/a};
2075n/a
2076n/a/* -------------------------------------------------------*/
2077n/a
2078n/aPyTypeObject PyCursesWindow_Type = {
2079n/a PyVarObject_HEAD_INIT(NULL, 0)
2080n/a "_curses.curses window", /*tp_name*/
2081n/a sizeof(PyCursesWindowObject), /*tp_basicsize*/
2082n/a 0, /*tp_itemsize*/
2083n/a /* methods */
2084n/a (destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/
2085n/a 0, /*tp_print*/
2086n/a (getattrfunc)0, /*tp_getattr*/
2087n/a (setattrfunc)0, /*tp_setattr*/
2088n/a 0, /*tp_reserved*/
2089n/a 0, /*tp_repr*/
2090n/a 0, /*tp_as_number*/
2091n/a 0, /*tp_as_sequence*/
2092n/a 0, /*tp_as_mapping*/
2093n/a 0, /*tp_hash*/
2094n/a 0, /*tp_call*/
2095n/a 0, /*tp_str*/
2096n/a 0, /*tp_getattro*/
2097n/a 0, /*tp_setattro*/
2098n/a 0, /*tp_as_buffer*/
2099n/a Py_TPFLAGS_DEFAULT, /*tp_flags*/
2100n/a 0, /*tp_doc*/
2101n/a 0, /*tp_traverse*/
2102n/a 0, /*tp_clear*/
2103n/a 0, /*tp_richcompare*/
2104n/a 0, /*tp_weaklistoffset*/
2105n/a 0, /*tp_iter*/
2106n/a 0, /*tp_iternext*/
2107n/a PyCursesWindow_Methods, /*tp_methods*/
2108n/a 0, /* tp_members */
2109n/a PyCursesWindow_getsets, /* tp_getset */
2110n/a};
2111n/a
2112n/a/*********************************************************************
2113n/a Global Functions
2114n/a**********************************************************************/
2115n/a
2116n/aNoArgNoReturnFunction(beep)
2117n/aNoArgNoReturnFunction(def_prog_mode)
2118n/aNoArgNoReturnFunction(def_shell_mode)
2119n/aNoArgNoReturnFunction(doupdate)
2120n/aNoArgNoReturnFunction(endwin)
2121n/aNoArgNoReturnFunction(flash)
2122n/aNoArgNoReturnFunction(nocbreak)
2123n/aNoArgNoReturnFunction(noecho)
2124n/aNoArgNoReturnFunction(nonl)
2125n/aNoArgNoReturnFunction(noraw)
2126n/aNoArgNoReturnFunction(reset_prog_mode)
2127n/aNoArgNoReturnFunction(reset_shell_mode)
2128n/aNoArgNoReturnFunction(resetty)
2129n/aNoArgNoReturnFunction(savetty)
2130n/a
2131n/aNoArgOrFlagNoReturnFunction(cbreak)
2132n/aNoArgOrFlagNoReturnFunction(echo)
2133n/aNoArgOrFlagNoReturnFunction(nl)
2134n/aNoArgOrFlagNoReturnFunction(raw)
2135n/a
2136n/aNoArgReturnIntFunction(baudrate)
2137n/aNoArgReturnIntFunction(termattrs)
2138n/a
2139n/aNoArgReturnStringFunction(termname)
2140n/aNoArgReturnStringFunction(longname)
2141n/a
2142n/aNoArgTrueFalseFunction(can_change_color)
2143n/aNoArgTrueFalseFunction(has_colors)
2144n/aNoArgTrueFalseFunction(has_ic)
2145n/aNoArgTrueFalseFunction(has_il)
2146n/aNoArgTrueFalseFunction(isendwin)
2147n/aNoArgNoReturnVoidFunction(flushinp)
2148n/aNoArgNoReturnVoidFunction(noqiflush)
2149n/a
2150n/astatic PyObject *
2151n/aPyCurses_filter(PyObject *self)
2152n/a{
2153n/a /* not checking for PyCursesInitialised here since filter() must
2154n/a be called before initscr() */
2155n/a filter();
2156n/a Py_RETURN_NONE;
2157n/a}
2158n/a
2159n/astatic PyObject *
2160n/aPyCurses_Color_Content(PyObject *self, PyObject *args)
2161n/a{
2162n/a short color,r,g,b;
2163n/a
2164n/a PyCursesInitialised;
2165n/a PyCursesInitialisedColor;
2166n/a
2167n/a if (!PyArg_ParseTuple(args, "h:color_content", &color)) return NULL;
2168n/a
2169n/a if (color_content(color, &r, &g, &b) != ERR)
2170n/a return Py_BuildValue("(iii)", r, g, b);
2171n/a else {
2172n/a PyErr_SetString(PyCursesError,
2173n/a "Argument 1 was out of range. Check value of COLORS.");
2174n/a return NULL;
2175n/a }
2176n/a}
2177n/a
2178n/astatic PyObject *
2179n/aPyCurses_color_pair(PyObject *self, PyObject *args)
2180n/a{
2181n/a int n;
2182n/a
2183n/a PyCursesInitialised;
2184n/a PyCursesInitialisedColor;
2185n/a
2186n/a if (!PyArg_ParseTuple(args, "i:color_pair", &n)) return NULL;
2187n/a return PyLong_FromLong((long) (n << 8));
2188n/a}
2189n/a
2190n/astatic PyObject *
2191n/aPyCurses_Curs_Set(PyObject *self, PyObject *args)
2192n/a{
2193n/a int vis,erg;
2194n/a
2195n/a PyCursesInitialised;
2196n/a
2197n/a if (!PyArg_ParseTuple(args, "i:curs_set", &vis)) return NULL;
2198n/a
2199n/a erg = curs_set(vis);
2200n/a if (erg == ERR) return PyCursesCheckERR(erg, "curs_set");
2201n/a
2202n/a return PyLong_FromLong((long) erg);
2203n/a}
2204n/a
2205n/astatic PyObject *
2206n/aPyCurses_Delay_Output(PyObject *self, PyObject *args)
2207n/a{
2208n/a int ms;
2209n/a
2210n/a PyCursesInitialised;
2211n/a
2212n/a if (!PyArg_ParseTuple(args, "i:delay_output", &ms)) return NULL;
2213n/a
2214n/a return PyCursesCheckERR(delay_output(ms), "delay_output");
2215n/a}
2216n/a
2217n/astatic PyObject *
2218n/aPyCurses_EraseChar(PyObject *self)
2219n/a{
2220n/a char ch;
2221n/a
2222n/a PyCursesInitialised;
2223n/a
2224n/a ch = erasechar();
2225n/a
2226n/a return PyBytes_FromStringAndSize(&ch, 1);
2227n/a}
2228n/a
2229n/astatic PyObject *
2230n/aPyCurses_getsyx(PyObject *self)
2231n/a{
2232n/a int x = 0;
2233n/a int y = 0;
2234n/a
2235n/a PyCursesInitialised;
2236n/a
2237n/a getsyx(y, x);
2238n/a
2239n/a return Py_BuildValue("(ii)", y, x);
2240n/a}
2241n/a
2242n/a#ifdef NCURSES_MOUSE_VERSION
2243n/astatic PyObject *
2244n/aPyCurses_GetMouse(PyObject *self)
2245n/a{
2246n/a int rtn;
2247n/a MEVENT event;
2248n/a
2249n/a PyCursesInitialised;
2250n/a
2251n/a rtn = getmouse( &event );
2252n/a if (rtn == ERR) {
2253n/a PyErr_SetString(PyCursesError, "getmouse() returned ERR");
2254n/a return NULL;
2255n/a }
2256n/a return Py_BuildValue("(hiiil)",
2257n/a (short)event.id,
2258n/a event.x, event.y, event.z,
2259n/a (long) event.bstate);
2260n/a}
2261n/a
2262n/astatic PyObject *
2263n/aPyCurses_UngetMouse(PyObject *self, PyObject *args)
2264n/a{
2265n/a MEVENT event;
2266n/a
2267n/a PyCursesInitialised;
2268n/a if (!PyArg_ParseTuple(args, "hiiil",
2269n/a &event.id,
2270n/a &event.x, &event.y, &event.z,
2271n/a (int *) &event.bstate))
2272n/a return NULL;
2273n/a
2274n/a return PyCursesCheckERR(ungetmouse(&event), "ungetmouse");
2275n/a}
2276n/a#endif
2277n/a
2278n/astatic PyObject *
2279n/aPyCurses_GetWin(PyCursesWindowObject *self, PyObject *stream)
2280n/a{
2281n/a char fn[100];
2282n/a int fd = -1;
2283n/a FILE *fp = NULL;
2284n/a PyObject *data;
2285n/a size_t datalen;
2286n/a WINDOW *win;
2287n/a _Py_IDENTIFIER(read);
2288n/a PyObject *res = NULL;
2289n/a
2290n/a PyCursesInitialised;
2291n/a
2292n/a strcpy(fn, "/tmp/py.curses.getwin.XXXXXX");
2293n/a fd = mkstemp(fn);
2294n/a if (fd < 0)
2295n/a return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn);
2296n/a if (_Py_set_inheritable(fd, 0, NULL) < 0)
2297n/a goto error;
2298n/a fp = fdopen(fd, "wb+");
2299n/a if (fp == NULL) {
2300n/a PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn);
2301n/a goto error;
2302n/a }
2303n/a
2304n/a data = _PyObject_CallMethodId(stream, &PyId_read, NULL);
2305n/a if (data == NULL)
2306n/a goto error;
2307n/a if (!PyBytes_Check(data)) {
2308n/a PyErr_Format(PyExc_TypeError,
2309n/a "f.read() returned %.100s instead of bytes",
2310n/a data->ob_type->tp_name);
2311n/a Py_DECREF(data);
2312n/a goto error;
2313n/a }
2314n/a datalen = PyBytes_GET_SIZE(data);
2315n/a if (fwrite(PyBytes_AS_STRING(data), 1, datalen, fp) != datalen) {
2316n/a Py_DECREF(data);
2317n/a PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn);
2318n/a goto error;
2319n/a }
2320n/a Py_DECREF(data);
2321n/a
2322n/a fseek(fp, 0, 0);
2323n/a win = getwin(fp);
2324n/a if (win == NULL) {
2325n/a PyErr_SetString(PyCursesError, catchall_NULL);
2326n/a goto error;
2327n/a }
2328n/a res = PyCursesWindow_New(win, NULL);
2329n/a
2330n/aerror:
2331n/a if (fp != NULL)
2332n/a fclose(fp);
2333n/a else if (fd != -1)
2334n/a close(fd);
2335n/a remove(fn);
2336n/a return res;
2337n/a}
2338n/a
2339n/astatic PyObject *
2340n/aPyCurses_HalfDelay(PyObject *self, PyObject *args)
2341n/a{
2342n/a unsigned char tenths;
2343n/a
2344n/a PyCursesInitialised;
2345n/a
2346n/a if (!PyArg_ParseTuple(args, "b:halfdelay", &tenths)) return NULL;
2347n/a
2348n/a return PyCursesCheckERR(halfdelay(tenths), "halfdelay");
2349n/a}
2350n/a
2351n/a#ifndef STRICT_SYSV_CURSES
2352n/a/* No has_key! */
2353n/astatic PyObject * PyCurses_has_key(PyObject *self, PyObject *args)
2354n/a{
2355n/a int ch;
2356n/a
2357n/a PyCursesInitialised;
2358n/a
2359n/a if (!PyArg_ParseTuple(args,"i",&ch)) return NULL;
2360n/a
2361n/a if (has_key(ch) == FALSE) {
2362n/a Py_RETURN_FALSE;
2363n/a }
2364n/a Py_RETURN_TRUE;
2365n/a}
2366n/a#endif /* STRICT_SYSV_CURSES */
2367n/a
2368n/astatic PyObject *
2369n/aPyCurses_Init_Color(PyObject *self, PyObject *args)
2370n/a{
2371n/a short color, r, g, b;
2372n/a
2373n/a PyCursesInitialised;
2374n/a PyCursesInitialisedColor;
2375n/a
2376n/a switch(PyTuple_Size(args)) {
2377n/a case 4:
2378n/a if (!PyArg_ParseTuple(args, "hhhh;color,r,g,b", &color, &r, &g, &b)) return NULL;
2379n/a break;
2380n/a default:
2381n/a PyErr_SetString(PyExc_TypeError, "init_color requires 4 arguments");
2382n/a return NULL;
2383n/a }
2384n/a
2385n/a return PyCursesCheckERR(init_color(color, r, g, b), "init_color");
2386n/a}
2387n/a
2388n/astatic PyObject *
2389n/aPyCurses_Init_Pair(PyObject *self, PyObject *args)
2390n/a{
2391n/a short pair, f, b;
2392n/a
2393n/a PyCursesInitialised;
2394n/a PyCursesInitialisedColor;
2395n/a
2396n/a if (PyTuple_Size(args) != 3) {
2397n/a PyErr_SetString(PyExc_TypeError, "init_pair requires 3 arguments");
2398n/a return NULL;
2399n/a }
2400n/a
2401n/a if (!PyArg_ParseTuple(args, "hhh;pair, f, b", &pair, &f, &b)) return NULL;
2402n/a
2403n/a return PyCursesCheckERR(init_pair(pair, f, b), "init_pair");
2404n/a}
2405n/a
2406n/astatic PyObject *ModDict;
2407n/a
2408n/astatic PyObject *
2409n/aPyCurses_InitScr(PyObject *self)
2410n/a{
2411n/a WINDOW *win;
2412n/a PyCursesWindowObject *winobj;
2413n/a
2414n/a if (initialised == TRUE) {
2415n/a wrefresh(stdscr);
2416n/a return (PyObject *)PyCursesWindow_New(stdscr, NULL);
2417n/a }
2418n/a
2419n/a win = initscr();
2420n/a
2421n/a if (win == NULL) {
2422n/a PyErr_SetString(PyCursesError, catchall_NULL);
2423n/a return NULL;
2424n/a }
2425n/a
2426n/a initialised = initialised_setupterm = TRUE;
2427n/a
2428n/a/* This was moved from initcurses() because it core dumped on SGI,
2429n/a where they're not defined until you've called initscr() */
2430n/a#define SetDictInt(string,ch) \
2431n/a do { \
2432n/a PyObject *o = PyLong_FromLong((long) (ch)); \
2433n/a if (o && PyDict_SetItemString(ModDict, string, o) == 0) { \
2434n/a Py_DECREF(o); \
2435n/a } \
2436n/a } while (0)
2437n/a
2438n/a /* Here are some graphic symbols you can use */
2439n/a SetDictInt("ACS_ULCORNER", (ACS_ULCORNER));
2440n/a SetDictInt("ACS_LLCORNER", (ACS_LLCORNER));
2441n/a SetDictInt("ACS_URCORNER", (ACS_URCORNER));
2442n/a SetDictInt("ACS_LRCORNER", (ACS_LRCORNER));
2443n/a SetDictInt("ACS_LTEE", (ACS_LTEE));
2444n/a SetDictInt("ACS_RTEE", (ACS_RTEE));
2445n/a SetDictInt("ACS_BTEE", (ACS_BTEE));
2446n/a SetDictInt("ACS_TTEE", (ACS_TTEE));
2447n/a SetDictInt("ACS_HLINE", (ACS_HLINE));
2448n/a SetDictInt("ACS_VLINE", (ACS_VLINE));
2449n/a SetDictInt("ACS_PLUS", (ACS_PLUS));
2450n/a#if !defined(__hpux) || defined(HAVE_NCURSES_H)
2451n/a /* On HP/UX 11, these are of type cchar_t, which is not an
2452n/a integral type. If this is a problem on more platforms, a
2453n/a configure test should be added to determine whether ACS_S1
2454n/a is of integral type. */
2455n/a SetDictInt("ACS_S1", (ACS_S1));
2456n/a SetDictInt("ACS_S9", (ACS_S9));
2457n/a SetDictInt("ACS_DIAMOND", (ACS_DIAMOND));
2458n/a SetDictInt("ACS_CKBOARD", (ACS_CKBOARD));
2459n/a SetDictInt("ACS_DEGREE", (ACS_DEGREE));
2460n/a SetDictInt("ACS_PLMINUS", (ACS_PLMINUS));
2461n/a SetDictInt("ACS_BULLET", (ACS_BULLET));
2462n/a SetDictInt("ACS_LARROW", (ACS_LARROW));
2463n/a SetDictInt("ACS_RARROW", (ACS_RARROW));
2464n/a SetDictInt("ACS_DARROW", (ACS_DARROW));
2465n/a SetDictInt("ACS_UARROW", (ACS_UARROW));
2466n/a SetDictInt("ACS_BOARD", (ACS_BOARD));
2467n/a SetDictInt("ACS_LANTERN", (ACS_LANTERN));
2468n/a SetDictInt("ACS_BLOCK", (ACS_BLOCK));
2469n/a#endif
2470n/a SetDictInt("ACS_BSSB", (ACS_ULCORNER));
2471n/a SetDictInt("ACS_SSBB", (ACS_LLCORNER));
2472n/a SetDictInt("ACS_BBSS", (ACS_URCORNER));
2473n/a SetDictInt("ACS_SBBS", (ACS_LRCORNER));
2474n/a SetDictInt("ACS_SBSS", (ACS_RTEE));
2475n/a SetDictInt("ACS_SSSB", (ACS_LTEE));
2476n/a SetDictInt("ACS_SSBS", (ACS_BTEE));
2477n/a SetDictInt("ACS_BSSS", (ACS_TTEE));
2478n/a SetDictInt("ACS_BSBS", (ACS_HLINE));
2479n/a SetDictInt("ACS_SBSB", (ACS_VLINE));
2480n/a SetDictInt("ACS_SSSS", (ACS_PLUS));
2481n/a
2482n/a /* The following are never available with strict SYSV curses */
2483n/a#ifdef ACS_S3
2484n/a SetDictInt("ACS_S3", (ACS_S3));
2485n/a#endif
2486n/a#ifdef ACS_S7
2487n/a SetDictInt("ACS_S7", (ACS_S7));
2488n/a#endif
2489n/a#ifdef ACS_LEQUAL
2490n/a SetDictInt("ACS_LEQUAL", (ACS_LEQUAL));
2491n/a#endif
2492n/a#ifdef ACS_GEQUAL
2493n/a SetDictInt("ACS_GEQUAL", (ACS_GEQUAL));
2494n/a#endif
2495n/a#ifdef ACS_PI
2496n/a SetDictInt("ACS_PI", (ACS_PI));
2497n/a#endif
2498n/a#ifdef ACS_NEQUAL
2499n/a SetDictInt("ACS_NEQUAL", (ACS_NEQUAL));
2500n/a#endif
2501n/a#ifdef ACS_STERLING
2502n/a SetDictInt("ACS_STERLING", (ACS_STERLING));
2503n/a#endif
2504n/a
2505n/a SetDictInt("LINES", LINES);
2506n/a SetDictInt("COLS", COLS);
2507n/a
2508n/a winobj = (PyCursesWindowObject *)PyCursesWindow_New(win, NULL);
2509n/a screen_encoding = winobj->encoding;
2510n/a return (PyObject *)winobj;
2511n/a}
2512n/a
2513n/astatic PyObject *
2514n/aPyCurses_setupterm(PyObject* self, PyObject *args, PyObject* keywds)
2515n/a{
2516n/a int fd = -1;
2517n/a int err;
2518n/a char* termstr = NULL;
2519n/a
2520n/a static char *kwlist[] = {"term", "fd", NULL};
2521n/a
2522n/a if (!PyArg_ParseTupleAndKeywords(
2523n/a args, keywds, "|zi:setupterm", kwlist, &termstr, &fd)) {
2524n/a return NULL;
2525n/a }
2526n/a
2527n/a if (fd == -1) {
2528n/a PyObject* sys_stdout;
2529n/a
2530n/a sys_stdout = PySys_GetObject("stdout");
2531n/a
2532n/a if (sys_stdout == NULL || sys_stdout == Py_None) {
2533n/a PyErr_SetString(
2534n/a PyCursesError,
2535n/a "lost sys.stdout");
2536n/a return NULL;
2537n/a }
2538n/a
2539n/a fd = PyObject_AsFileDescriptor(sys_stdout);
2540n/a
2541n/a if (fd == -1) {
2542n/a return NULL;
2543n/a }
2544n/a }
2545n/a
2546n/a if (!initialised_setupterm && setupterm(termstr,fd,&err) == ERR) {
2547n/a char* s = "setupterm: unknown error";
2548n/a
2549n/a if (err == 0) {
2550n/a s = "setupterm: could not find terminal";
2551n/a } else if (err == -1) {
2552n/a s = "setupterm: could not find terminfo database";
2553n/a }
2554n/a
2555n/a PyErr_SetString(PyCursesError,s);
2556n/a return NULL;
2557n/a }
2558n/a
2559n/a initialised_setupterm = TRUE;
2560n/a
2561n/a Py_RETURN_NONE;
2562n/a}
2563n/a
2564n/astatic PyObject *
2565n/aPyCurses_IntrFlush(PyObject *self, PyObject *args)
2566n/a{
2567n/a int ch;
2568n/a
2569n/a PyCursesInitialised;
2570n/a
2571n/a switch(PyTuple_Size(args)) {
2572n/a case 1:
2573n/a if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&ch)) return NULL;
2574n/a break;
2575n/a default:
2576n/a PyErr_SetString(PyExc_TypeError, "intrflush requires 1 argument");
2577n/a return NULL;
2578n/a }
2579n/a
2580n/a return PyCursesCheckERR(intrflush(NULL,ch), "intrflush");
2581n/a}
2582n/a
2583n/a#ifdef HAVE_CURSES_IS_TERM_RESIZED
2584n/astatic PyObject *
2585n/aPyCurses_Is_Term_Resized(PyObject *self, PyObject *args)
2586n/a{
2587n/a int lines;
2588n/a int columns;
2589n/a int result;
2590n/a
2591n/a PyCursesInitialised;
2592n/a
2593n/a if (!PyArg_ParseTuple(args,"ii:is_term_resized", &lines, &columns))
2594n/a return NULL;
2595n/a result = is_term_resized(lines, columns);
2596n/a if (result == TRUE) {
2597n/a Py_RETURN_TRUE;
2598n/a } else {
2599n/a Py_RETURN_FALSE;
2600n/a }
2601n/a}
2602n/a#endif /* HAVE_CURSES_IS_TERM_RESIZED */
2603n/a
2604n/a#if !defined(__NetBSD__)
2605n/astatic PyObject *
2606n/aPyCurses_KeyName(PyObject *self, PyObject *args)
2607n/a{
2608n/a const char *knp;
2609n/a int ch;
2610n/a
2611n/a PyCursesInitialised;
2612n/a
2613n/a if (!PyArg_ParseTuple(args,"i",&ch)) return NULL;
2614n/a
2615n/a if (ch < 0) {
2616n/a PyErr_SetString(PyExc_ValueError, "invalid key number");
2617n/a return NULL;
2618n/a }
2619n/a knp = keyname(ch);
2620n/a
2621n/a return PyBytes_FromString((knp == NULL) ? "" : knp);
2622n/a}
2623n/a#endif
2624n/a
2625n/astatic PyObject *
2626n/aPyCurses_KillChar(PyObject *self)
2627n/a{
2628n/a char ch;
2629n/a
2630n/a ch = killchar();
2631n/a
2632n/a return PyBytes_FromStringAndSize(&ch, 1);
2633n/a}
2634n/a
2635n/astatic PyObject *
2636n/aPyCurses_Meta(PyObject *self, PyObject *args)
2637n/a{
2638n/a int ch;
2639n/a
2640n/a PyCursesInitialised;
2641n/a
2642n/a switch(PyTuple_Size(args)) {
2643n/a case 1:
2644n/a if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&ch)) return NULL;
2645n/a break;
2646n/a default:
2647n/a PyErr_SetString(PyExc_TypeError, "meta requires 1 argument");
2648n/a return NULL;
2649n/a }
2650n/a
2651n/a return PyCursesCheckERR(meta(stdscr, ch), "meta");
2652n/a}
2653n/a
2654n/a#ifdef NCURSES_MOUSE_VERSION
2655n/astatic PyObject *
2656n/aPyCurses_MouseInterval(PyObject *self, PyObject *args)
2657n/a{
2658n/a int interval;
2659n/a PyCursesInitialised;
2660n/a
2661n/a if (!PyArg_ParseTuple(args,"i;interval",&interval))
2662n/a return NULL;
2663n/a return PyCursesCheckERR(mouseinterval(interval), "mouseinterval");
2664n/a}
2665n/a
2666n/astatic PyObject *
2667n/aPyCurses_MouseMask(PyObject *self, PyObject *args)
2668n/a{
2669n/a int newmask;
2670n/a mmask_t oldmask, availmask;
2671n/a
2672n/a PyCursesInitialised;
2673n/a if (!PyArg_ParseTuple(args,"i;mousemask",&newmask))
2674n/a return NULL;
2675n/a availmask = mousemask(newmask, &oldmask);
2676n/a return Py_BuildValue("(ll)", (long)availmask, (long)oldmask);
2677n/a}
2678n/a#endif
2679n/a
2680n/astatic PyObject *
2681n/aPyCurses_Napms(PyObject *self, PyObject *args)
2682n/a{
2683n/a int ms;
2684n/a
2685n/a PyCursesInitialised;
2686n/a if (!PyArg_ParseTuple(args, "i;ms", &ms)) return NULL;
2687n/a
2688n/a return Py_BuildValue("i", napms(ms));
2689n/a}
2690n/a
2691n/a
2692n/astatic PyObject *
2693n/aPyCurses_NewPad(PyObject *self, PyObject *args)
2694n/a{
2695n/a WINDOW *win;
2696n/a int nlines, ncols;
2697n/a
2698n/a PyCursesInitialised;
2699n/a
2700n/a if (!PyArg_ParseTuple(args,"ii;nlines,ncols",&nlines,&ncols)) return NULL;
2701n/a
2702n/a win = newpad(nlines, ncols);
2703n/a
2704n/a if (win == NULL) {
2705n/a PyErr_SetString(PyCursesError, catchall_NULL);
2706n/a return NULL;
2707n/a }
2708n/a
2709n/a return (PyObject *)PyCursesWindow_New(win, NULL);
2710n/a}
2711n/a
2712n/astatic PyObject *
2713n/aPyCurses_NewWindow(PyObject *self, PyObject *args)
2714n/a{
2715n/a WINDOW *win;
2716n/a int nlines, ncols, begin_y=0, begin_x=0;
2717n/a
2718n/a PyCursesInitialised;
2719n/a
2720n/a switch (PyTuple_Size(args)) {
2721n/a case 2:
2722n/a if (!PyArg_ParseTuple(args,"ii;nlines,ncols",&nlines,&ncols))
2723n/a return NULL;
2724n/a break;
2725n/a case 4:
2726n/a if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x",
2727n/a &nlines,&ncols,&begin_y,&begin_x))
2728n/a return NULL;
2729n/a break;
2730n/a default:
2731n/a PyErr_SetString(PyExc_TypeError, "newwin requires 2 or 4 arguments");
2732n/a return NULL;
2733n/a }
2734n/a
2735n/a win = newwin(nlines,ncols,begin_y,begin_x);
2736n/a if (win == NULL) {
2737n/a PyErr_SetString(PyCursesError, catchall_NULL);
2738n/a return NULL;
2739n/a }
2740n/a
2741n/a return (PyObject *)PyCursesWindow_New(win, NULL);
2742n/a}
2743n/a
2744n/astatic PyObject *
2745n/aPyCurses_Pair_Content(PyObject *self, PyObject *args)
2746n/a{
2747n/a short pair,f,b;
2748n/a
2749n/a PyCursesInitialised;
2750n/a PyCursesInitialisedColor;
2751n/a
2752n/a switch(PyTuple_Size(args)) {
2753n/a case 1:
2754n/a if (!PyArg_ParseTuple(args, "h;pair", &pair)) return NULL;
2755n/a break;
2756n/a default:
2757n/a PyErr_SetString(PyExc_TypeError, "pair_content requires 1 argument");
2758n/a return NULL;
2759n/a }
2760n/a
2761n/a if (pair_content(pair, &f, &b)==ERR) {
2762n/a PyErr_SetString(PyCursesError,
2763n/a "Argument 1 was out of range. (1..COLOR_PAIRS-1)");
2764n/a return NULL;
2765n/a }
2766n/a
2767n/a return Py_BuildValue("(ii)", f, b);
2768n/a}
2769n/a
2770n/astatic PyObject *
2771n/aPyCurses_pair_number(PyObject *self, PyObject *args)
2772n/a{
2773n/a int n;
2774n/a
2775n/a PyCursesInitialised;
2776n/a PyCursesInitialisedColor;
2777n/a
2778n/a switch(PyTuple_Size(args)) {
2779n/a case 1:
2780n/a if (!PyArg_ParseTuple(args, "i;pairvalue", &n)) return NULL;
2781n/a break;
2782n/a default:
2783n/a PyErr_SetString(PyExc_TypeError,
2784n/a "pair_number requires 1 argument");
2785n/a return NULL;
2786n/a }
2787n/a
2788n/a return PyLong_FromLong((long) ((n & A_COLOR) >> 8));
2789n/a}
2790n/a
2791n/astatic PyObject *
2792n/aPyCurses_Putp(PyObject *self, PyObject *args)
2793n/a{
2794n/a char *str;
2795n/a
2796n/a if (!PyArg_ParseTuple(args,"y;str", &str))
2797n/a return NULL;
2798n/a return PyCursesCheckERR(putp(str), "putp");
2799n/a}
2800n/a
2801n/astatic PyObject *
2802n/aPyCurses_QiFlush(PyObject *self, PyObject *args)
2803n/a{
2804n/a int flag = 0;
2805n/a
2806n/a PyCursesInitialised;
2807n/a
2808n/a switch(PyTuple_Size(args)) {
2809n/a case 0:
2810n/a qiflush();
2811n/a Py_RETURN_NONE;
2812n/a case 1:
2813n/a if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL;
2814n/a if (flag) qiflush();
2815n/a else noqiflush();
2816n/a Py_RETURN_NONE;
2817n/a default:
2818n/a PyErr_SetString(PyExc_TypeError, "qiflush requires 0 or 1 arguments");
2819n/a return NULL;
2820n/a }
2821n/a}
2822n/a
2823n/a/* Internal helper used for updating curses.LINES, curses.COLS, _curses.LINES
2824n/a * and _curses.COLS */
2825n/a#if defined(HAVE_CURSES_RESIZETERM) || defined(HAVE_CURSES_RESIZE_TERM)
2826n/astatic int
2827n/aupdate_lines_cols(void)
2828n/a{
2829n/a PyObject *o;
2830n/a PyObject *m = PyImport_ImportModuleNoBlock("curses");
2831n/a _Py_IDENTIFIER(LINES);
2832n/a _Py_IDENTIFIER(COLS);
2833n/a
2834n/a if (!m)
2835n/a return 0;
2836n/a
2837n/a o = PyLong_FromLong(LINES);
2838n/a if (!o) {
2839n/a Py_DECREF(m);
2840n/a return 0;
2841n/a }
2842n/a if (_PyObject_SetAttrId(m, &PyId_LINES, o)) {
2843n/a Py_DECREF(m);
2844n/a Py_DECREF(o);
2845n/a return 0;
2846n/a }
2847n/a /* PyId_LINES.object will be initialized here. */
2848n/a if (PyDict_SetItem(ModDict, PyId_LINES.object, o)) {
2849n/a Py_DECREF(m);
2850n/a Py_DECREF(o);
2851n/a return 0;
2852n/a }
2853n/a Py_DECREF(o);
2854n/a o = PyLong_FromLong(COLS);
2855n/a if (!o) {
2856n/a Py_DECREF(m);
2857n/a return 0;
2858n/a }
2859n/a if (_PyObject_SetAttrId(m, &PyId_COLS, o)) {
2860n/a Py_DECREF(m);
2861n/a Py_DECREF(o);
2862n/a return 0;
2863n/a }
2864n/a if (PyDict_SetItem(ModDict, PyId_COLS.object, o)) {
2865n/a Py_DECREF(m);
2866n/a Py_DECREF(o);
2867n/a return 0;
2868n/a }
2869n/a Py_DECREF(o);
2870n/a Py_DECREF(m);
2871n/a return 1;
2872n/a}
2873n/a
2874n/astatic PyObject *
2875n/aPyCurses_update_lines_cols(PyObject *self)
2876n/a{
2877n/a return PyLong_FromLong((long) update_lines_cols());
2878n/a}
2879n/a
2880n/a#endif
2881n/a
2882n/a#ifdef HAVE_CURSES_RESIZETERM
2883n/astatic PyObject *
2884n/aPyCurses_ResizeTerm(PyObject *self, PyObject *args)
2885n/a{
2886n/a int lines;
2887n/a int columns;
2888n/a PyObject *result;
2889n/a
2890n/a PyCursesInitialised;
2891n/a
2892n/a if (!PyArg_ParseTuple(args,"ii:resizeterm", &lines, &columns))
2893n/a return NULL;
2894n/a
2895n/a result = PyCursesCheckERR(resizeterm(lines, columns), "resizeterm");
2896n/a if (!result)
2897n/a return NULL;
2898n/a if (!update_lines_cols())
2899n/a return NULL;
2900n/a return result;
2901n/a}
2902n/a
2903n/a#endif
2904n/a
2905n/a#ifdef HAVE_CURSES_RESIZE_TERM
2906n/astatic PyObject *
2907n/aPyCurses_Resize_Term(PyObject *self, PyObject *args)
2908n/a{
2909n/a int lines;
2910n/a int columns;
2911n/a
2912n/a PyObject *result;
2913n/a
2914n/a PyCursesInitialised;
2915n/a
2916n/a if (!PyArg_ParseTuple(args,"ii:resize_term", &lines, &columns))
2917n/a return NULL;
2918n/a
2919n/a result = PyCursesCheckERR(resize_term(lines, columns), "resize_term");
2920n/a if (!result)
2921n/a return NULL;
2922n/a if (!update_lines_cols())
2923n/a return NULL;
2924n/a return result;
2925n/a}
2926n/a#endif /* HAVE_CURSES_RESIZE_TERM */
2927n/a
2928n/astatic PyObject *
2929n/aPyCurses_setsyx(PyObject *self, PyObject *args)
2930n/a{
2931n/a int y,x;
2932n/a
2933n/a PyCursesInitialised;
2934n/a
2935n/a if (PyTuple_Size(args)!=2) {
2936n/a PyErr_SetString(PyExc_TypeError, "setsyx requires 2 arguments");
2937n/a return NULL;
2938n/a }
2939n/a
2940n/a if (!PyArg_ParseTuple(args, "ii;y, x", &y, &x)) return NULL;
2941n/a
2942n/a setsyx(y,x);
2943n/a
2944n/a Py_RETURN_NONE;
2945n/a}
2946n/a
2947n/astatic PyObject *
2948n/aPyCurses_Start_Color(PyObject *self)
2949n/a{
2950n/a int code;
2951n/a PyObject *c, *cp;
2952n/a
2953n/a PyCursesInitialised;
2954n/a
2955n/a code = start_color();
2956n/a if (code != ERR) {
2957n/a initialisedcolors = TRUE;
2958n/a c = PyLong_FromLong((long) COLORS);
2959n/a if (c == NULL)
2960n/a return NULL;
2961n/a PyDict_SetItemString(ModDict, "COLORS", c);
2962n/a Py_DECREF(c);
2963n/a cp = PyLong_FromLong((long) COLOR_PAIRS);
2964n/a if (cp == NULL)
2965n/a return NULL;
2966n/a PyDict_SetItemString(ModDict, "COLOR_PAIRS", cp);
2967n/a Py_DECREF(cp);
2968n/a Py_RETURN_NONE;
2969n/a } else {
2970n/a PyErr_SetString(PyCursesError, "start_color() returned ERR");
2971n/a return NULL;
2972n/a }
2973n/a}
2974n/a
2975n/astatic PyObject *
2976n/aPyCurses_tigetflag(PyObject *self, PyObject *args)
2977n/a{
2978n/a char *capname;
2979n/a
2980n/a PyCursesSetupTermCalled;
2981n/a
2982n/a if (!PyArg_ParseTuple(args, "s", &capname))
2983n/a return NULL;
2984n/a
2985n/a return PyLong_FromLong( (long) tigetflag( capname ) );
2986n/a}
2987n/a
2988n/astatic PyObject *
2989n/aPyCurses_tigetnum(PyObject *self, PyObject *args)
2990n/a{
2991n/a char *capname;
2992n/a
2993n/a PyCursesSetupTermCalled;
2994n/a
2995n/a if (!PyArg_ParseTuple(args, "s", &capname))
2996n/a return NULL;
2997n/a
2998n/a return PyLong_FromLong( (long) tigetnum( capname ) );
2999n/a}
3000n/a
3001n/astatic PyObject *
3002n/aPyCurses_tigetstr(PyObject *self, PyObject *args)
3003n/a{
3004n/a char *capname;
3005n/a
3006n/a PyCursesSetupTermCalled;
3007n/a
3008n/a if (!PyArg_ParseTuple(args, "s", &capname))
3009n/a return NULL;
3010n/a
3011n/a capname = tigetstr( capname );
3012n/a if (capname == 0 || capname == (char*) -1) {
3013n/a Py_RETURN_NONE;
3014n/a }
3015n/a return PyBytes_FromString( capname );
3016n/a}
3017n/a
3018n/astatic PyObject *
3019n/aPyCurses_tparm(PyObject *self, PyObject *args)
3020n/a{
3021n/a char* fmt;
3022n/a char* result = NULL;
3023n/a int i1=0,i2=0,i3=0,i4=0,i5=0,i6=0,i7=0,i8=0,i9=0;
3024n/a
3025n/a PyCursesSetupTermCalled;
3026n/a
3027n/a if (!PyArg_ParseTuple(args, "y|iiiiiiiii:tparm",
3028n/a &fmt, &i1, &i2, &i3, &i4,
3029n/a &i5, &i6, &i7, &i8, &i9)) {
3030n/a return NULL;
3031n/a }
3032n/a
3033n/a result = tparm(fmt,i1,i2,i3,i4,i5,i6,i7,i8,i9);
3034n/a if (!result) {
3035n/a PyErr_SetString(PyCursesError, "tparm() returned NULL");
3036n/a return NULL;
3037n/a }
3038n/a
3039n/a return PyBytes_FromString(result);
3040n/a}
3041n/a
3042n/astatic PyObject *
3043n/aPyCurses_TypeAhead(PyObject *self, PyObject *args)
3044n/a{
3045n/a int fd;
3046n/a
3047n/a PyCursesInitialised;
3048n/a
3049n/a if (!PyArg_ParseTuple(args,"i;fd",&fd)) return NULL;
3050n/a
3051n/a return PyCursesCheckERR(typeahead( fd ), "typeahead");
3052n/a}
3053n/a
3054n/astatic PyObject *
3055n/aPyCurses_UnCtrl(PyObject *self, PyObject *args)
3056n/a{
3057n/a PyObject *temp;
3058n/a chtype ch;
3059n/a
3060n/a PyCursesInitialised;
3061n/a
3062n/a if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL;
3063n/a
3064n/a if (!PyCurses_ConvertToChtype(NULL, temp, &ch))
3065n/a return NULL;
3066n/a
3067n/a return PyBytes_FromString(unctrl(ch));
3068n/a}
3069n/a
3070n/astatic PyObject *
3071n/aPyCurses_UngetCh(PyObject *self, PyObject *args)
3072n/a{
3073n/a PyObject *temp;
3074n/a chtype ch;
3075n/a
3076n/a PyCursesInitialised;
3077n/a
3078n/a if (!PyArg_ParseTuple(args,"O;ch or int",&temp))
3079n/a return NULL;
3080n/a
3081n/a if (!PyCurses_ConvertToChtype(NULL, temp, &ch))
3082n/a return NULL;
3083n/a
3084n/a return PyCursesCheckERR(ungetch(ch), "ungetch");
3085n/a}
3086n/a
3087n/a#ifdef HAVE_NCURSESW
3088n/a/* Convert an object to a character (wchar_t):
3089n/a
3090n/a - int
3091n/a - str of length 1
3092n/a
3093n/a Return 1 on success, 0 on error. */
3094n/astatic int
3095n/aPyCurses_ConvertToWchar_t(PyObject *obj,
3096n/a wchar_t *wch)
3097n/a{
3098n/a if (PyUnicode_Check(obj)) {
3099n/a wchar_t buffer[2];
3100n/a if (PyUnicode_AsWideChar(obj, buffer, 2) != 1) {
3101n/a PyErr_Format(PyExc_TypeError,
3102n/a "expect bytes or str of length 1, or int, "
3103n/a "got a str of length %zi",
3104n/a PyUnicode_GET_LENGTH(obj));
3105n/a return 0;
3106n/a }
3107n/a *wch = buffer[0];
3108n/a return 2;
3109n/a }
3110n/a else if (PyLong_CheckExact(obj)) {
3111n/a long value;
3112n/a int overflow;
3113n/a value = PyLong_AsLongAndOverflow(obj, &overflow);
3114n/a if (overflow) {
3115n/a PyErr_SetString(PyExc_OverflowError,
3116n/a "int doesn't fit in long");
3117n/a return 0;
3118n/a }
3119n/a *wch = (wchar_t)value;
3120n/a if ((long)*wch != value) {
3121n/a PyErr_Format(PyExc_OverflowError,
3122n/a "character doesn't fit in wchar_t");
3123n/a return 0;
3124n/a }
3125n/a return 1;
3126n/a }
3127n/a else {
3128n/a PyErr_Format(PyExc_TypeError,
3129n/a "expect bytes or str of length 1, or int, got %s",
3130n/a Py_TYPE(obj)->tp_name);
3131n/a return 0;
3132n/a }
3133n/a}
3134n/a
3135n/astatic PyObject *
3136n/aPyCurses_Unget_Wch(PyObject *self, PyObject *args)
3137n/a{
3138n/a PyObject *obj;
3139n/a wchar_t wch;
3140n/a
3141n/a PyCursesInitialised;
3142n/a
3143n/a if (!PyArg_ParseTuple(args,"O", &obj))
3144n/a return NULL;
3145n/a
3146n/a if (!PyCurses_ConvertToWchar_t(obj, &wch))
3147n/a return NULL;
3148n/a return PyCursesCheckERR(unget_wch(wch), "unget_wch");
3149n/a}
3150n/a#endif
3151n/a
3152n/astatic PyObject *
3153n/aPyCurses_Use_Env(PyObject *self, PyObject *args)
3154n/a{
3155n/a int flag;
3156n/a
3157n/a switch(PyTuple_Size(args)) {
3158n/a case 1:
3159n/a if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&flag))
3160n/a return NULL;
3161n/a break;
3162n/a default:
3163n/a PyErr_SetString(PyExc_TypeError, "use_env requires 1 argument");
3164n/a return NULL;
3165n/a }
3166n/a use_env(flag);
3167n/a Py_RETURN_NONE;
3168n/a}
3169n/a
3170n/a#ifndef STRICT_SYSV_CURSES
3171n/astatic PyObject *
3172n/aPyCurses_Use_Default_Colors(PyObject *self)
3173n/a{
3174n/a int code;
3175n/a
3176n/a PyCursesInitialised;
3177n/a PyCursesInitialisedColor;
3178n/a
3179n/a code = use_default_colors();
3180n/a if (code != ERR) {
3181n/a Py_RETURN_NONE;
3182n/a } else {
3183n/a PyErr_SetString(PyCursesError, "use_default_colors() returned ERR");
3184n/a return NULL;
3185n/a }
3186n/a}
3187n/a#endif /* STRICT_SYSV_CURSES */
3188n/a
3189n/a/* List of functions defined in the module */
3190n/a
3191n/astatic PyMethodDef PyCurses_methods[] = {
3192n/a {"baudrate", (PyCFunction)PyCurses_baudrate, METH_NOARGS},
3193n/a {"beep", (PyCFunction)PyCurses_beep, METH_NOARGS},
3194n/a {"can_change_color", (PyCFunction)PyCurses_can_change_color, METH_NOARGS},
3195n/a {"cbreak", (PyCFunction)PyCurses_cbreak, METH_VARARGS},
3196n/a {"color_content", (PyCFunction)PyCurses_Color_Content, METH_VARARGS},
3197n/a {"color_pair", (PyCFunction)PyCurses_color_pair, METH_VARARGS},
3198n/a {"curs_set", (PyCFunction)PyCurses_Curs_Set, METH_VARARGS},
3199n/a {"def_prog_mode", (PyCFunction)PyCurses_def_prog_mode, METH_NOARGS},
3200n/a {"def_shell_mode", (PyCFunction)PyCurses_def_shell_mode, METH_NOARGS},
3201n/a {"delay_output", (PyCFunction)PyCurses_Delay_Output, METH_VARARGS},
3202n/a {"doupdate", (PyCFunction)PyCurses_doupdate, METH_NOARGS},
3203n/a {"echo", (PyCFunction)PyCurses_echo, METH_VARARGS},
3204n/a {"endwin", (PyCFunction)PyCurses_endwin, METH_NOARGS},
3205n/a {"erasechar", (PyCFunction)PyCurses_EraseChar, METH_NOARGS},
3206n/a {"filter", (PyCFunction)PyCurses_filter, METH_NOARGS},
3207n/a {"flash", (PyCFunction)PyCurses_flash, METH_NOARGS},
3208n/a {"flushinp", (PyCFunction)PyCurses_flushinp, METH_NOARGS},
3209n/a#ifdef NCURSES_MOUSE_VERSION
3210n/a {"getmouse", (PyCFunction)PyCurses_GetMouse, METH_NOARGS},
3211n/a {"ungetmouse", (PyCFunction)PyCurses_UngetMouse, METH_VARARGS},
3212n/a#endif
3213n/a {"getsyx", (PyCFunction)PyCurses_getsyx, METH_NOARGS},
3214n/a {"getwin", (PyCFunction)PyCurses_GetWin, METH_O},
3215n/a {"has_colors", (PyCFunction)PyCurses_has_colors, METH_NOARGS},
3216n/a {"has_ic", (PyCFunction)PyCurses_has_ic, METH_NOARGS},
3217n/a {"has_il", (PyCFunction)PyCurses_has_il, METH_NOARGS},
3218n/a#ifndef STRICT_SYSV_CURSES
3219n/a {"has_key", (PyCFunction)PyCurses_has_key, METH_VARARGS},
3220n/a#endif
3221n/a {"halfdelay", (PyCFunction)PyCurses_HalfDelay, METH_VARARGS},
3222n/a {"init_color", (PyCFunction)PyCurses_Init_Color, METH_VARARGS},
3223n/a {"init_pair", (PyCFunction)PyCurses_Init_Pair, METH_VARARGS},
3224n/a {"initscr", (PyCFunction)PyCurses_InitScr, METH_NOARGS},
3225n/a {"intrflush", (PyCFunction)PyCurses_IntrFlush, METH_VARARGS},
3226n/a {"isendwin", (PyCFunction)PyCurses_isendwin, METH_NOARGS},
3227n/a#ifdef HAVE_CURSES_IS_TERM_RESIZED
3228n/a {"is_term_resized", (PyCFunction)PyCurses_Is_Term_Resized, METH_VARARGS},
3229n/a#endif
3230n/a#if !defined(__NetBSD__)
3231n/a {"keyname", (PyCFunction)PyCurses_KeyName, METH_VARARGS},
3232n/a#endif
3233n/a {"killchar", (PyCFunction)PyCurses_KillChar, METH_NOARGS},
3234n/a {"longname", (PyCFunction)PyCurses_longname, METH_NOARGS},
3235n/a {"meta", (PyCFunction)PyCurses_Meta, METH_VARARGS},
3236n/a#ifdef NCURSES_MOUSE_VERSION
3237n/a {"mouseinterval", (PyCFunction)PyCurses_MouseInterval, METH_VARARGS},
3238n/a {"mousemask", (PyCFunction)PyCurses_MouseMask, METH_VARARGS},
3239n/a#endif
3240n/a {"napms", (PyCFunction)PyCurses_Napms, METH_VARARGS},
3241n/a {"newpad", (PyCFunction)PyCurses_NewPad, METH_VARARGS},
3242n/a {"newwin", (PyCFunction)PyCurses_NewWindow, METH_VARARGS},
3243n/a {"nl", (PyCFunction)PyCurses_nl, METH_VARARGS},
3244n/a {"nocbreak", (PyCFunction)PyCurses_nocbreak, METH_NOARGS},
3245n/a {"noecho", (PyCFunction)PyCurses_noecho, METH_NOARGS},
3246n/a {"nonl", (PyCFunction)PyCurses_nonl, METH_NOARGS},
3247n/a {"noqiflush", (PyCFunction)PyCurses_noqiflush, METH_NOARGS},
3248n/a {"noraw", (PyCFunction)PyCurses_noraw, METH_NOARGS},
3249n/a {"pair_content", (PyCFunction)PyCurses_Pair_Content, METH_VARARGS},
3250n/a {"pair_number", (PyCFunction)PyCurses_pair_number, METH_VARARGS},
3251n/a {"putp", (PyCFunction)PyCurses_Putp, METH_VARARGS},
3252n/a {"qiflush", (PyCFunction)PyCurses_QiFlush, METH_VARARGS},
3253n/a {"raw", (PyCFunction)PyCurses_raw, METH_VARARGS},
3254n/a {"reset_prog_mode", (PyCFunction)PyCurses_reset_prog_mode, METH_NOARGS},
3255n/a {"reset_shell_mode", (PyCFunction)PyCurses_reset_shell_mode, METH_NOARGS},
3256n/a {"resetty", (PyCFunction)PyCurses_resetty, METH_NOARGS},
3257n/a#ifdef HAVE_CURSES_RESIZETERM
3258n/a {"resizeterm", (PyCFunction)PyCurses_ResizeTerm, METH_VARARGS},
3259n/a#endif
3260n/a#ifdef HAVE_CURSES_RESIZE_TERM
3261n/a {"resize_term", (PyCFunction)PyCurses_Resize_Term, METH_VARARGS},
3262n/a#endif
3263n/a {"savetty", (PyCFunction)PyCurses_savetty, METH_NOARGS},
3264n/a {"setsyx", (PyCFunction)PyCurses_setsyx, METH_VARARGS},
3265n/a {"setupterm", (PyCFunction)PyCurses_setupterm,
3266n/a METH_VARARGS|METH_KEYWORDS},
3267n/a {"start_color", (PyCFunction)PyCurses_Start_Color, METH_NOARGS},
3268n/a {"termattrs", (PyCFunction)PyCurses_termattrs, METH_NOARGS},
3269n/a {"termname", (PyCFunction)PyCurses_termname, METH_NOARGS},
3270n/a {"tigetflag", (PyCFunction)PyCurses_tigetflag, METH_VARARGS},
3271n/a {"tigetnum", (PyCFunction)PyCurses_tigetnum, METH_VARARGS},
3272n/a {"tigetstr", (PyCFunction)PyCurses_tigetstr, METH_VARARGS},
3273n/a {"tparm", (PyCFunction)PyCurses_tparm, METH_VARARGS},
3274n/a {"typeahead", (PyCFunction)PyCurses_TypeAhead, METH_VARARGS},
3275n/a {"unctrl", (PyCFunction)PyCurses_UnCtrl, METH_VARARGS},
3276n/a {"ungetch", (PyCFunction)PyCurses_UngetCh, METH_VARARGS},
3277n/a#if defined(HAVE_CURSES_RESIZETERM) || defined(HAVE_CURSES_RESIZE_TERM)
3278n/a {"update_lines_cols", (PyCFunction)PyCurses_update_lines_cols, METH_NOARGS},
3279n/a#endif
3280n/a#ifdef HAVE_NCURSESW
3281n/a {"unget_wch", (PyCFunction)PyCurses_Unget_Wch, METH_VARARGS},
3282n/a#endif
3283n/a {"use_env", (PyCFunction)PyCurses_Use_Env, METH_VARARGS},
3284n/a#ifndef STRICT_SYSV_CURSES
3285n/a {"use_default_colors", (PyCFunction)PyCurses_Use_Default_Colors, METH_NOARGS},
3286n/a#endif
3287n/a {NULL, NULL} /* sentinel */
3288n/a};
3289n/a
3290n/a/* Initialization function for the module */
3291n/a
3292n/a
3293n/astatic struct PyModuleDef _cursesmodule = {
3294n/a PyModuleDef_HEAD_INIT,
3295n/a "_curses",
3296n/a NULL,
3297n/a -1,
3298n/a PyCurses_methods,
3299n/a NULL,
3300n/a NULL,
3301n/a NULL,
3302n/a NULL
3303n/a};
3304n/a
3305n/aPyMODINIT_FUNC
3306n/aPyInit__curses(void)
3307n/a{
3308n/a PyObject *m, *d, *v, *c_api_object;
3309n/a static void *PyCurses_API[PyCurses_API_pointers];
3310n/a
3311n/a /* Initialize object type */
3312n/a if (PyType_Ready(&PyCursesWindow_Type) < 0)
3313n/a return NULL;
3314n/a
3315n/a /* Initialize the C API pointer array */
3316n/a PyCurses_API[0] = (void *)&PyCursesWindow_Type;
3317n/a PyCurses_API[1] = (void *)func_PyCursesSetupTermCalled;
3318n/a PyCurses_API[2] = (void *)func_PyCursesInitialised;
3319n/a PyCurses_API[3] = (void *)func_PyCursesInitialisedColor;
3320n/a
3321n/a /* Create the module and add the functions */
3322n/a m = PyModule_Create(&_cursesmodule);
3323n/a if (m == NULL)
3324n/a return NULL;
3325n/a
3326n/a /* Add some symbolic constants to the module */
3327n/a d = PyModule_GetDict(m);
3328n/a if (d == NULL)
3329n/a return NULL;
3330n/a ModDict = d; /* For PyCurses_InitScr to use later */
3331n/a
3332n/a /* Add a capsule for the C API */
3333n/a c_api_object = PyCapsule_New(PyCurses_API, PyCurses_CAPSULE_NAME, NULL);
3334n/a PyDict_SetItemString(d, "_C_API", c_api_object);
3335n/a Py_DECREF(c_api_object);
3336n/a
3337n/a /* For exception curses.error */
3338n/a PyCursesError = PyErr_NewException("_curses.error", NULL, NULL);
3339n/a PyDict_SetItemString(d, "error", PyCursesError);
3340n/a
3341n/a /* Make the version available */
3342n/a v = PyBytes_FromString(PyCursesVersion);
3343n/a PyDict_SetItemString(d, "version", v);
3344n/a PyDict_SetItemString(d, "__version__", v);
3345n/a Py_DECREF(v);
3346n/a
3347n/a SetDictInt("ERR", ERR);
3348n/a SetDictInt("OK", OK);
3349n/a
3350n/a /* Here are some attributes you can add to chars to print */
3351n/a
3352n/a SetDictInt("A_ATTRIBUTES", A_ATTRIBUTES);
3353n/a SetDictInt("A_NORMAL", A_NORMAL);
3354n/a SetDictInt("A_STANDOUT", A_STANDOUT);
3355n/a SetDictInt("A_UNDERLINE", A_UNDERLINE);
3356n/a SetDictInt("A_REVERSE", A_REVERSE);
3357n/a SetDictInt("A_BLINK", A_BLINK);
3358n/a SetDictInt("A_DIM", A_DIM);
3359n/a SetDictInt("A_BOLD", A_BOLD);
3360n/a SetDictInt("A_ALTCHARSET", A_ALTCHARSET);
3361n/a#if !defined(__NetBSD__)
3362n/a SetDictInt("A_INVIS", A_INVIS);
3363n/a#endif
3364n/a SetDictInt("A_PROTECT", A_PROTECT);
3365n/a SetDictInt("A_CHARTEXT", A_CHARTEXT);
3366n/a SetDictInt("A_COLOR", A_COLOR);
3367n/a
3368n/a /* The following are never available with strict SYSV curses */
3369n/a#ifdef A_HORIZONTAL
3370n/a SetDictInt("A_HORIZONTAL", A_HORIZONTAL);
3371n/a#endif
3372n/a#ifdef A_LEFT
3373n/a SetDictInt("A_LEFT", A_LEFT);
3374n/a#endif
3375n/a#ifdef A_LOW
3376n/a SetDictInt("A_LOW", A_LOW);
3377n/a#endif
3378n/a#ifdef A_RIGHT
3379n/a SetDictInt("A_RIGHT", A_RIGHT);
3380n/a#endif
3381n/a#ifdef A_TOP
3382n/a SetDictInt("A_TOP", A_TOP);
3383n/a#endif
3384n/a#ifdef A_VERTICAL
3385n/a SetDictInt("A_VERTICAL", A_VERTICAL);
3386n/a#endif
3387n/a
3388n/a SetDictInt("COLOR_BLACK", COLOR_BLACK);
3389n/a SetDictInt("COLOR_RED", COLOR_RED);
3390n/a SetDictInt("COLOR_GREEN", COLOR_GREEN);
3391n/a SetDictInt("COLOR_YELLOW", COLOR_YELLOW);
3392n/a SetDictInt("COLOR_BLUE", COLOR_BLUE);
3393n/a SetDictInt("COLOR_MAGENTA", COLOR_MAGENTA);
3394n/a SetDictInt("COLOR_CYAN", COLOR_CYAN);
3395n/a SetDictInt("COLOR_WHITE", COLOR_WHITE);
3396n/a
3397n/a#ifdef NCURSES_MOUSE_VERSION
3398n/a /* Mouse-related constants */
3399n/a SetDictInt("BUTTON1_PRESSED", BUTTON1_PRESSED);
3400n/a SetDictInt("BUTTON1_RELEASED", BUTTON1_RELEASED);
3401n/a SetDictInt("BUTTON1_CLICKED", BUTTON1_CLICKED);
3402n/a SetDictInt("BUTTON1_DOUBLE_CLICKED", BUTTON1_DOUBLE_CLICKED);
3403n/a SetDictInt("BUTTON1_TRIPLE_CLICKED", BUTTON1_TRIPLE_CLICKED);
3404n/a
3405n/a SetDictInt("BUTTON2_PRESSED", BUTTON2_PRESSED);
3406n/a SetDictInt("BUTTON2_RELEASED", BUTTON2_RELEASED);
3407n/a SetDictInt("BUTTON2_CLICKED", BUTTON2_CLICKED);
3408n/a SetDictInt("BUTTON2_DOUBLE_CLICKED", BUTTON2_DOUBLE_CLICKED);
3409n/a SetDictInt("BUTTON2_TRIPLE_CLICKED", BUTTON2_TRIPLE_CLICKED);
3410n/a
3411n/a SetDictInt("BUTTON3_PRESSED", BUTTON3_PRESSED);
3412n/a SetDictInt("BUTTON3_RELEASED", BUTTON3_RELEASED);
3413n/a SetDictInt("BUTTON3_CLICKED", BUTTON3_CLICKED);
3414n/a SetDictInt("BUTTON3_DOUBLE_CLICKED", BUTTON3_DOUBLE_CLICKED);
3415n/a SetDictInt("BUTTON3_TRIPLE_CLICKED", BUTTON3_TRIPLE_CLICKED);
3416n/a
3417n/a SetDictInt("BUTTON4_PRESSED", BUTTON4_PRESSED);
3418n/a SetDictInt("BUTTON4_RELEASED", BUTTON4_RELEASED);
3419n/a SetDictInt("BUTTON4_CLICKED", BUTTON4_CLICKED);
3420n/a SetDictInt("BUTTON4_DOUBLE_CLICKED", BUTTON4_DOUBLE_CLICKED);
3421n/a SetDictInt("BUTTON4_TRIPLE_CLICKED", BUTTON4_TRIPLE_CLICKED);
3422n/a
3423n/a SetDictInt("BUTTON_SHIFT", BUTTON_SHIFT);
3424n/a SetDictInt("BUTTON_CTRL", BUTTON_CTRL);
3425n/a SetDictInt("BUTTON_ALT", BUTTON_ALT);
3426n/a
3427n/a SetDictInt("ALL_MOUSE_EVENTS", ALL_MOUSE_EVENTS);
3428n/a SetDictInt("REPORT_MOUSE_POSITION", REPORT_MOUSE_POSITION);
3429n/a#endif
3430n/a /* Now set everything up for KEY_ variables */
3431n/a {
3432n/a int key;
3433n/a char *key_n;
3434n/a char *key_n2;
3435n/a#if !defined(__NetBSD__)
3436n/a for (key=KEY_MIN;key < KEY_MAX; key++) {
3437n/a key_n = (char *)keyname(key);
3438n/a if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0)
3439n/a continue;
3440n/a if (strncmp(key_n,"KEY_F(",6)==0) {
3441n/a char *p1, *p2;
3442n/a key_n2 = PyMem_Malloc(strlen(key_n)+1);
3443n/a if (!key_n2) {
3444n/a PyErr_NoMemory();
3445n/a break;
3446n/a }
3447n/a p1 = key_n;
3448n/a p2 = key_n2;
3449n/a while (*p1) {
3450n/a if (*p1 != '(' && *p1 != ')') {
3451n/a *p2 = *p1;
3452n/a p2++;
3453n/a }
3454n/a p1++;
3455n/a }
3456n/a *p2 = (char)0;
3457n/a } else
3458n/a key_n2 = key_n;
3459n/a SetDictInt(key_n2,key);
3460n/a if (key_n2 != key_n)
3461n/a PyMem_Free(key_n2);
3462n/a }
3463n/a#endif
3464n/a SetDictInt("KEY_MIN", KEY_MIN);
3465n/a SetDictInt("KEY_MAX", KEY_MAX);
3466n/a }
3467n/a return m;
3468n/a}