/*1* This is a curses module for Python.2*3* Based on prior work by Lance Ellinghaus and Oliver Andrich4* Version 1.2 of this module: Copyright 1994 by Lance Ellinghouse,5* Cathedral City, California Republic, United States of America.6*7* Version 1.5b1, heavily extended for ncurses by Oliver Andrich:8* Copyright 1996,1997 by Oliver Andrich, Koblenz, Germany.9*10* Tidied for Python 1.6, and currently maintained by <[email protected]>.11*12* Permission is hereby granted, free of charge, to any person obtaining13* a copy of this source file to use, copy, modify, merge, or publish it14* subject to the following conditions:15*16* The above copyright notice and this permission notice shall be included17* in all copies or in any new file that contains a substantial portion of18* this file.19*20* THE AUTHOR MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF21* THE SOFTWARE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT22* EXPRESS OR IMPLIED WARRANTY. THE AUTHOR DISCLAIMS ALL WARRANTIES23* WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES24* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND25* NON-INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE26* AUTHOR BE LIABLE TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL,27* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER28* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE, STRICT LIABILITY OR29* ANY OTHER ACTION ARISING OUT OF OR IN CONNECTION WITH THE USE OR30* PERFORMANCE OF THIS SOFTWARE.31*/3233/*3435A number of SysV or ncurses functions don't have wrappers yet; if you36need a given function, add it and send a patch. See37https://www.python.org/dev/patches/ for instructions on how to submit38patches to Python.3940Here's a list of currently unsupported functions:4142addchnstr addchstr color_set define_key43del_curterm delscreen dupwin inchnstr inchstr innstr keyok44mcprint mvaddchnstr mvaddchstr mvcur mvinchnstr45mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr46mvwinchnstr mvwinchstr mvwinnstr newterm47restartterm ripoffline scr_dump48scr_init scr_restore scr_set scrl set_curterm set_term setterm49tgetent tgetflag tgetnum tgetstr tgoto timeout tputs50vidattr vidputs waddchnstr waddchstr51wcolor_set winchnstr winchstr winnstr wmouse_trafo wscrl5253Low-priority:54slk_attr slk_attr_off slk_attr_on slk_attr_set slk_attroff55slk_attron slk_attrset slk_clear slk_color slk_init slk_label56slk_noutrefresh slk_refresh slk_restore slk_set slk_touch5758Menu extension (ncurses and probably SYSV):59current_item free_item free_menu item_count item_description60item_index item_init item_name item_opts item_opts_off61item_opts_on item_term item_userptr item_value item_visible62menu_back menu_driver menu_fore menu_format menu_grey63menu_init menu_items menu_mark menu_opts menu_opts_off64menu_opts_on menu_pad menu_pattern menu_request_by_name65menu_request_name menu_spacing menu_sub menu_term menu_userptr66menu_win new_item new_menu pos_menu_cursor post_menu67scale_menu set_current_item set_item_init set_item_opts68set_item_term set_item_userptr set_item_value set_menu_back69set_menu_fore set_menu_format set_menu_grey set_menu_init70set_menu_items set_menu_mark set_menu_opts set_menu_pad71set_menu_pattern set_menu_spacing set_menu_sub set_menu_term72set_menu_userptr set_menu_win set_top_row top_row unpost_menu7374Form extension (ncurses and probably SYSV):75current_field data_ahead data_behind dup_field76dynamic_fieldinfo field_arg field_back field_buffer77field_count field_fore field_index field_info field_init78field_just field_opts field_opts_off field_opts_on field_pad79field_status field_term field_type field_userptr form_driver80form_fields form_init form_opts form_opts_off form_opts_on81form_page form_request_by_name form_request_name form_sub82form_term form_userptr form_win free_field free_form83link_field link_fieldtype move_field new_field new_form84new_page pos_form_cursor post_form scale_form85set_current_field set_field_back set_field_buffer86set_field_fore set_field_init set_field_just set_field_opts87set_field_pad set_field_status set_field_term set_field_type88set_field_userptr set_fieldtype_arg set_fieldtype_choice89set_form_fields set_form_init set_form_opts set_form_page90set_form_sub set_form_term set_form_userptr set_form_win91set_max_field set_new_page unpost_form929394*/9596/* Release Number */9798static const char PyCursesVersion[] = "2.2";99100/* Includes */101102#ifndef Py_BUILD_CORE_BUILTIN103# define Py_BUILD_CORE_MODULE 1104#endif105106#include "Python.h"107#include "pycore_long.h" // _PyLong_GetZero()108#include "pycore_structseq.h" // _PyStructSequence_NewType()109110#ifdef __hpux111#define STRICT_SYSV_CURSES112#endif113114#define CURSES_MODULE115#include "py_curses.h"116117#if defined(HAVE_TERM_H) || defined(__sgi)118/* For termname, longname, putp, tigetflag, tigetnum, tigetstr, tparm119which are not declared in SysV curses and for setupterm. */120#include <term.h>121/* Including <term.h> #defines many common symbols. */122#undef lines123#undef columns124#endif125126#ifdef HAVE_LANGINFO_H127#include <langinfo.h>128#endif129130#if !defined(HAVE_NCURSES_H) && (defined(sgi) || defined(__sun) || defined(SCO5))131#define STRICT_SYSV_CURSES /* Don't use ncurses extensions */132typedef chtype attr_t; /* No attr_t type is available */133#endif134135#if defined(_AIX)136#define STRICT_SYSV_CURSES137#endif138139#if NCURSES_EXT_FUNCS+0 >= 20170401 && NCURSES_EXT_COLORS+0 >= 20170401140#define _NCURSES_EXTENDED_COLOR_FUNCS 1141#else142#define _NCURSES_EXTENDED_COLOR_FUNCS 0143#endif144145#if _NCURSES_EXTENDED_COLOR_FUNCS146#define _CURSES_COLOR_VAL_TYPE int147#define _CURSES_COLOR_NUM_TYPE int148#define _CURSES_INIT_COLOR_FUNC init_extended_color149#define _CURSES_INIT_PAIR_FUNC init_extended_pair150#define _COLOR_CONTENT_FUNC extended_color_content151#define _CURSES_PAIR_CONTENT_FUNC extended_pair_content152#else153#define _CURSES_COLOR_VAL_TYPE short154#define _CURSES_COLOR_NUM_TYPE short155#define _CURSES_INIT_COLOR_FUNC init_color156#define _CURSES_INIT_PAIR_FUNC init_pair157#define _COLOR_CONTENT_FUNC color_content158#define _CURSES_PAIR_CONTENT_FUNC pair_content159#endif /* _NCURSES_EXTENDED_COLOR_FUNCS */160161/*[clinic input]162module _curses163class _curses.window "PyCursesWindowObject *" "&PyCursesWindow_Type"164[clinic start generated code]*/165/*[clinic end generated code: output=da39a3ee5e6b4b0d input=43265c372c2887d6]*/166167/* Definition of exception curses.error */168169static PyObject *PyCursesError;170171/* Tells whether setupterm() has been called to initialise terminfo. */172static int initialised_setupterm = FALSE;173174/* Tells whether initscr() has been called to initialise curses. */175static int initialised = FALSE;176177/* Tells whether start_color() has been called to initialise color usage. */178static int initialisedcolors = FALSE;179180static char *screen_encoding = NULL;181182/* Utility Macros */183#define PyCursesSetupTermCalled \184if (initialised_setupterm != TRUE) { \185PyErr_SetString(PyCursesError, \186"must call (at least) setupterm() first"); \187return 0; }188189#define PyCursesInitialised \190if (initialised != TRUE) { \191PyErr_SetString(PyCursesError, \192"must call initscr() first"); \193return 0; }194195#define PyCursesInitialisedColor \196if (initialisedcolors != TRUE) { \197PyErr_SetString(PyCursesError, \198"must call start_color() first"); \199return 0; }200201/* Utility Functions */202203/*204* Check the return code from a curses function and return None205* or raise an exception as appropriate. These are exported using the206* capsule API.207*/208209static PyObject *210PyCursesCheckERR(int code, const char *fname)211{212if (code != ERR) {213Py_RETURN_NONE;214} else {215if (fname == NULL) {216PyErr_SetString(PyCursesError, catchall_ERR);217} else {218PyErr_Format(PyCursesError, "%s() returned ERR", fname);219}220return NULL;221}222}223224/* Convert an object to a byte (an integer of type chtype):225226- int227- bytes of length 1228- str of length 1229230Return 1 on success, 0 on error (invalid type or integer overflow). */231static int232PyCurses_ConvertToChtype(PyCursesWindowObject *win, PyObject *obj, chtype *ch)233{234long value;235if(PyBytes_Check(obj) && PyBytes_Size(obj) == 1) {236value = (unsigned char)PyBytes_AsString(obj)[0];237}238else if (PyUnicode_Check(obj)) {239if (PyUnicode_GetLength(obj) != 1) {240PyErr_Format(PyExc_TypeError,241"expect bytes or str of length 1, or int, "242"got a str of length %zi",243PyUnicode_GET_LENGTH(obj));244return 0;245}246value = PyUnicode_READ_CHAR(obj, 0);247if (128 < value) {248PyObject *bytes;249const char *encoding;250if (win)251encoding = win->encoding;252else253encoding = screen_encoding;254bytes = PyUnicode_AsEncodedString(obj, encoding, NULL);255if (bytes == NULL)256return 0;257if (PyBytes_GET_SIZE(bytes) == 1)258value = (unsigned char)PyBytes_AS_STRING(bytes)[0];259else260value = -1;261Py_DECREF(bytes);262if (value < 0)263goto overflow;264}265}266else if (PyLong_CheckExact(obj)) {267int long_overflow;268value = PyLong_AsLongAndOverflow(obj, &long_overflow);269if (long_overflow)270goto overflow;271}272else {273PyErr_Format(PyExc_TypeError,274"expect bytes or str of length 1, or int, got %s",275Py_TYPE(obj)->tp_name);276return 0;277}278*ch = (chtype)value;279if ((long)*ch != value)280goto overflow;281return 1;282283overflow:284PyErr_SetString(PyExc_OverflowError,285"byte doesn't fit in chtype");286return 0;287}288289/* Convert an object to a byte (chtype) or a character (cchar_t):290291- int292- bytes of length 1293- str of length 1294295Return:296297- 2 if obj is a character (written into *wch)298- 1 if obj is a byte (written into *ch)299- 0 on error: raise an exception */300static int301PyCurses_ConvertToCchar_t(PyCursesWindowObject *win, PyObject *obj,302chtype *ch303#ifdef HAVE_NCURSESW304, wchar_t *wch305#endif306)307{308long value;309#ifdef HAVE_NCURSESW310wchar_t buffer[2];311#endif312313if (PyUnicode_Check(obj)) {314#ifdef HAVE_NCURSESW315if (PyUnicode_AsWideChar(obj, buffer, 2) != 1) {316PyErr_Format(PyExc_TypeError,317"expect bytes or str of length 1, or int, "318"got a str of length %zi",319PyUnicode_GET_LENGTH(obj));320return 0;321}322*wch = buffer[0];323return 2;324#else325return PyCurses_ConvertToChtype(win, obj, ch);326#endif327}328else if(PyBytes_Check(obj) && PyBytes_Size(obj) == 1) {329value = (unsigned char)PyBytes_AsString(obj)[0];330}331else if (PyLong_CheckExact(obj)) {332int overflow;333value = PyLong_AsLongAndOverflow(obj, &overflow);334if (overflow) {335PyErr_SetString(PyExc_OverflowError,336"int doesn't fit in long");337return 0;338}339}340else {341PyErr_Format(PyExc_TypeError,342"expect bytes or str of length 1, or int, got %s",343Py_TYPE(obj)->tp_name);344return 0;345}346347*ch = (chtype)value;348if ((long)*ch != value) {349PyErr_Format(PyExc_OverflowError,350"byte doesn't fit in chtype");351return 0;352}353return 1;354}355356/* Convert an object to a byte string (char*) or a wide character string357(wchar_t*). Return:358359- 2 if obj is a character string (written into *wch)360- 1 if obj is a byte string (written into *bytes)361- 0 on error: raise an exception */362static int363PyCurses_ConvertToString(PyCursesWindowObject *win, PyObject *obj,364PyObject **bytes, wchar_t **wstr)365{366char *str;367if (PyUnicode_Check(obj)) {368#ifdef HAVE_NCURSESW369assert (wstr != NULL);370371*wstr = PyUnicode_AsWideCharString(obj, NULL);372if (*wstr == NULL)373return 0;374return 2;375#else376assert (wstr == NULL);377*bytes = PyUnicode_AsEncodedString(obj, win->encoding, NULL);378if (*bytes == NULL)379return 0;380/* check for embedded null bytes */381if (PyBytes_AsStringAndSize(*bytes, &str, NULL) < 0) {382Py_CLEAR(*bytes);383return 0;384}385return 1;386#endif387}388else if (PyBytes_Check(obj)) {389*bytes = Py_NewRef(obj);390/* check for embedded null bytes */391if (PyBytes_AsStringAndSize(*bytes, &str, NULL) < 0) {392Py_DECREF(obj);393return 0;394}395return 1;396}397398PyErr_Format(PyExc_TypeError, "expect bytes or str, got %s",399Py_TYPE(obj)->tp_name);400return 0;401}402403static int404color_allow_default_converter(PyObject *arg, void *ptr)405{406long color_number;407int overflow;408409color_number = PyLong_AsLongAndOverflow(arg, &overflow);410if (color_number == -1 && PyErr_Occurred())411return 0;412413if (overflow > 0 || color_number >= COLORS) {414PyErr_Format(PyExc_ValueError,415"Color number is greater than COLORS-1 (%d).",416COLORS - 1);417return 0;418}419else if (overflow < 0 || color_number < 0) {420color_number = -1;421}422423*(int *)ptr = (int)color_number;424return 1;425}426427static int428color_converter(PyObject *arg, void *ptr)429{430if (!color_allow_default_converter(arg, ptr)) {431return 0;432}433if (*(int *)ptr < 0) {434PyErr_SetString(PyExc_ValueError,435"Color number is less than 0.");436return 0;437}438return 1;439}440441/*[python input]442class color_converter(CConverter):443type = 'int'444converter = 'color_converter'445[python start generated code]*/446/*[python end generated code: output=da39a3ee5e6b4b0d input=4260d2b6e66b3709]*/447448/*[python input]449class color_allow_default_converter(CConverter):450type = 'int'451converter = 'color_allow_default_converter'452[python start generated code]*/453/*[python end generated code: output=da39a3ee5e6b4b0d input=975602bc058a872d]*/454455static int456pair_converter(PyObject *arg, void *ptr)457{458long pair_number;459int overflow;460461pair_number = PyLong_AsLongAndOverflow(arg, &overflow);462if (pair_number == -1 && PyErr_Occurred())463return 0;464465#if _NCURSES_EXTENDED_COLOR_FUNCS466if (overflow > 0 || pair_number > INT_MAX) {467PyErr_Format(PyExc_ValueError,468"Color pair is greater than maximum (%d).",469INT_MAX);470return 0;471}472#else473if (overflow > 0 || pair_number >= COLOR_PAIRS) {474PyErr_Format(PyExc_ValueError,475"Color pair is greater than COLOR_PAIRS-1 (%d).",476COLOR_PAIRS - 1);477return 0;478}479#endif480else if (overflow < 0 || pair_number < 0) {481PyErr_SetString(PyExc_ValueError,482"Color pair is less than 0.");483return 0;484}485486*(int *)ptr = (int)pair_number;487return 1;488}489490/*[python input]491class pair_converter(CConverter):492type = 'int'493converter = 'pair_converter'494[python start generated code]*/495/*[python end generated code: output=da39a3ee5e6b4b0d input=1a918ae6a1b32af7]*/496497static int498component_converter(PyObject *arg, void *ptr)499{500long component;501int overflow;502503component = PyLong_AsLongAndOverflow(arg, &overflow);504if (component == -1 && PyErr_Occurred())505return 0;506507if (overflow > 0 || component > 1000) {508PyErr_SetString(PyExc_ValueError,509"Color component is greater than 1000");510return 0;511}512else if (overflow < 0 || component < 0) {513PyErr_SetString(PyExc_ValueError,514"Color component is less than 0");515return 0;516}517518*(short *)ptr = (short)component;519return 1;520}521522/*[python input]523class component_converter(CConverter):524type = 'short'525converter = 'component_converter'526[python start generated code]*/527/*[python end generated code: output=da39a3ee5e6b4b0d input=38e9be01d33927fb]*/528529/* Function versions of the 3 functions for testing whether curses has been530initialised or not. */531532static int func_PyCursesSetupTermCalled(void)533{534PyCursesSetupTermCalled;535return 1;536}537538static int func_PyCursesInitialised(void)539{540PyCursesInitialised;541return 1;542}543544static int func_PyCursesInitialisedColor(void)545{546PyCursesInitialisedColor;547return 1;548}549550/*****************************************************************************551The Window Object552******************************************************************************/553554/* Definition of the window type */555556PyTypeObject PyCursesWindow_Type;557558/* Function prototype macros for Window object559560X - function name561TYPE - parameter Type562ERGSTR - format string for construction of the return value563PARSESTR - format string for argument parsing564*/565566#define Window_NoArgNoReturnFunction(X) \567static PyObject *PyCursesWindow_ ## X \568(PyCursesWindowObject *self, PyObject *Py_UNUSED(ignored)) \569{ return PyCursesCheckERR(X(self->win), # X); }570571#define Window_NoArgTrueFalseFunction(X) \572static PyObject * PyCursesWindow_ ## X \573(PyCursesWindowObject *self, PyObject *Py_UNUSED(ignored)) \574{ \575return PyBool_FromLong(X(self->win)); }576577#define Window_NoArgNoReturnVoidFunction(X) \578static PyObject * PyCursesWindow_ ## X \579(PyCursesWindowObject *self, PyObject *Py_UNUSED(ignored)) \580{ \581X(self->win); Py_RETURN_NONE; }582583#define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR) \584static PyObject * PyCursesWindow_ ## X \585(PyCursesWindowObject *self, PyObject *Py_UNUSED(ignored)) \586{ \587TYPE arg1, arg2; \588X(self->win,arg1,arg2); return Py_BuildValue(ERGSTR, arg1, arg2); }589590#define Window_OneArgNoReturnVoidFunction(X, TYPE, PARSESTR) \591static PyObject * PyCursesWindow_ ## X \592(PyCursesWindowObject *self, PyObject *args) \593{ \594TYPE arg1; \595if (!PyArg_ParseTuple(args, PARSESTR, &arg1)) return NULL; \596X(self->win,arg1); Py_RETURN_NONE; }597598#define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR) \599static PyObject * PyCursesWindow_ ## X \600(PyCursesWindowObject *self, PyObject *args) \601{ \602TYPE arg1; \603if (!PyArg_ParseTuple(args,PARSESTR, &arg1)) return NULL; \604return PyCursesCheckERR(X(self->win, arg1), # X); }605606#define Window_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \607static PyObject * PyCursesWindow_ ## X \608(PyCursesWindowObject *self, PyObject *args) \609{ \610TYPE arg1, arg2; \611if (!PyArg_ParseTuple(args,PARSESTR, &arg1, &arg2)) return NULL; \612return PyCursesCheckERR(X(self->win, arg1, arg2), # X); }613614/* ------------- WINDOW routines --------------- */615616Window_NoArgNoReturnFunction(untouchwin)617Window_NoArgNoReturnFunction(touchwin)618Window_NoArgNoReturnFunction(redrawwin)619Window_NoArgNoReturnFunction(winsertln)620Window_NoArgNoReturnFunction(werase)621Window_NoArgNoReturnFunction(wdeleteln)622623Window_NoArgTrueFalseFunction(is_wintouched)624625Window_NoArgNoReturnVoidFunction(wsyncup)626Window_NoArgNoReturnVoidFunction(wsyncdown)627Window_NoArgNoReturnVoidFunction(wstandend)628Window_NoArgNoReturnVoidFunction(wstandout)629Window_NoArgNoReturnVoidFunction(wcursyncup)630Window_NoArgNoReturnVoidFunction(wclrtoeol)631Window_NoArgNoReturnVoidFunction(wclrtobot)632Window_NoArgNoReturnVoidFunction(wclear)633634Window_OneArgNoReturnVoidFunction(idcok, int, "i;True(1) or False(0)")635#ifdef HAVE_CURSES_IMMEDOK636Window_OneArgNoReturnVoidFunction(immedok, int, "i;True(1) or False(0)")637#endif638Window_OneArgNoReturnVoidFunction(wtimeout, int, "i;delay")639640Window_NoArg2TupleReturnFunction(getyx, int, "ii")641Window_NoArg2TupleReturnFunction(getbegyx, int, "ii")642Window_NoArg2TupleReturnFunction(getmaxyx, int, "ii")643Window_NoArg2TupleReturnFunction(getparyx, int, "ii")644645Window_OneArgNoReturnFunction(clearok, int, "i;True(1) or False(0)")646Window_OneArgNoReturnFunction(idlok, int, "i;True(1) or False(0)")647Window_OneArgNoReturnFunction(keypad, int, "i;True(1) or False(0)")648Window_OneArgNoReturnFunction(leaveok, int, "i;True(1) or False(0)")649Window_OneArgNoReturnFunction(nodelay, int, "i;True(1) or False(0)")650Window_OneArgNoReturnFunction(notimeout, int, "i;True(1) or False(0)")651Window_OneArgNoReturnFunction(scrollok, int, "i;True(1) or False(0)")652Window_OneArgNoReturnFunction(winsdelln, int, "i;nlines")653#ifdef HAVE_CURSES_SYNCOK654Window_OneArgNoReturnFunction(syncok, int, "i;True(1) or False(0)")655#endif656657Window_TwoArgNoReturnFunction(mvwin, int, "ii;y,x")658Window_TwoArgNoReturnFunction(mvderwin, int, "ii;y,x")659Window_TwoArgNoReturnFunction(wmove, int, "ii;y,x")660#ifndef STRICT_SYSV_CURSES661Window_TwoArgNoReturnFunction(wresize, int, "ii;lines,columns")662#endif663664/* Allocation and deallocation of Window Objects */665666static PyObject *667PyCursesWindow_New(WINDOW *win, const char *encoding)668{669PyCursesWindowObject *wo;670671if (encoding == NULL) {672#if defined(MS_WINDOWS)673char *buffer[100];674UINT cp;675cp = GetConsoleOutputCP();676if (cp != 0) {677PyOS_snprintf(buffer, sizeof(buffer), "cp%u", cp);678encoding = buffer;679}680#elif defined(CODESET)681const char *codeset = nl_langinfo(CODESET);682if (codeset != NULL && codeset[0] != 0)683encoding = codeset;684#endif685if (encoding == NULL)686encoding = "utf-8";687}688689wo = PyObject_New(PyCursesWindowObject, &PyCursesWindow_Type);690if (wo == NULL) return NULL;691wo->win = win;692wo->encoding = _PyMem_Strdup(encoding);693if (wo->encoding == NULL) {694Py_DECREF(wo);695PyErr_NoMemory();696return NULL;697}698return (PyObject *)wo;699}700701static void702PyCursesWindow_Dealloc(PyCursesWindowObject *wo)703{704if (wo->win != stdscr) delwin(wo->win);705if (wo->encoding != NULL)706PyMem_Free(wo->encoding);707PyObject_Free(wo);708}709710/* Addch, Addstr, Addnstr */711712/*[clinic input]713_curses.window.addch714715[716y: int717Y-coordinate.718x: int719X-coordinate.720]721722ch: object723Character to add.724725[726attr: long(c_default="A_NORMAL") = _curses.A_NORMAL727Attributes for the character.728]729/730731Paint the character.732733Paint character ch at (y, x) with attributes attr,734overwriting any character previously painted at that location.735By default, the character position and attributes are the736current settings for the window object.737[clinic start generated code]*/738739static PyObject *740_curses_window_addch_impl(PyCursesWindowObject *self, int group_left_1,741int y, int x, PyObject *ch, int group_right_1,742long attr)743/*[clinic end generated code: output=00f4c37af3378f45 input=95ce131578458196]*/744{745int coordinates_group = group_left_1;746int rtn;747int type;748chtype cch = 0;749#ifdef HAVE_NCURSESW750wchar_t wstr[2];751cchar_t wcval;752#endif753const char *funcname;754755#ifdef HAVE_NCURSESW756type = PyCurses_ConvertToCchar_t(self, ch, &cch, wstr);757if (type == 2) {758funcname = "add_wch";759wstr[1] = L'\0';760setcchar(&wcval, wstr, attr, PAIR_NUMBER(attr), NULL);761if (coordinates_group)762rtn = mvwadd_wch(self->win,y,x, &wcval);763else {764rtn = wadd_wch(self->win, &wcval);765}766}767else768#else769type = PyCurses_ConvertToCchar_t(self, ch, &cch);770#endif771if (type == 1) {772funcname = "addch";773if (coordinates_group)774rtn = mvwaddch(self->win,y,x, cch | (attr_t) attr);775else {776rtn = waddch(self->win, cch | (attr_t) attr);777}778}779else {780return NULL;781}782return PyCursesCheckERR(rtn, funcname);783}784785/*[clinic input]786_curses.window.addstr787788[789y: int790Y-coordinate.791x: int792X-coordinate.793]794795str: object796String to add.797798[799attr: long800Attributes for characters.801]802/803804Paint the string.805806Paint the string str at (y, x) with attributes attr,807overwriting anything previously on the display.808By default, the character position and attributes are the809current settings for the window object.810[clinic start generated code]*/811812static PyObject *813_curses_window_addstr_impl(PyCursesWindowObject *self, int group_left_1,814int y, int x, PyObject *str, int group_right_1,815long attr)816/*[clinic end generated code: output=65a928ea85ff3115 input=ff6cbb91448a22a3]*/817{818int rtn;819int strtype;820PyObject *bytesobj = NULL;821#ifdef HAVE_NCURSESW822wchar_t *wstr = NULL;823#endif824attr_t attr_old = A_NORMAL;825int use_xy = group_left_1, use_attr = group_right_1;826const char *funcname;827828#ifdef HAVE_NCURSESW829strtype = PyCurses_ConvertToString(self, str, &bytesobj, &wstr);830#else831strtype = PyCurses_ConvertToString(self, str, &bytesobj, NULL);832#endif833if (strtype == 0) {834return NULL;835}836if (use_attr) {837attr_old = getattrs(self->win);838(void)wattrset(self->win,attr);839}840#ifdef HAVE_NCURSESW841if (strtype == 2) {842funcname = "addwstr";843if (use_xy)844rtn = mvwaddwstr(self->win,y,x,wstr);845else846rtn = waddwstr(self->win,wstr);847PyMem_Free(wstr);848}849else850#endif851{852const char *str = PyBytes_AS_STRING(bytesobj);853funcname = "addstr";854if (use_xy)855rtn = mvwaddstr(self->win,y,x,str);856else857rtn = waddstr(self->win,str);858Py_DECREF(bytesobj);859}860if (use_attr)861(void)wattrset(self->win,attr_old);862return PyCursesCheckERR(rtn, funcname);863}864865/*[clinic input]866_curses.window.addnstr867868[869y: int870Y-coordinate.871x: int872X-coordinate.873]874875str: object876String to add.877878n: int879Maximal number of characters.880881[882attr: long883Attributes for characters.884]885/886887Paint at most n characters of the string.888889Paint at most n characters of the string str at (y, x) with890attributes attr, overwriting anything previously on the display.891By default, the character position and attributes are the892current settings for the window object.893[clinic start generated code]*/894895static PyObject *896_curses_window_addnstr_impl(PyCursesWindowObject *self, int group_left_1,897int y, int x, PyObject *str, int n,898int group_right_1, long attr)899/*[clinic end generated code: output=6d21cee2ce6876d9 input=72718415c2744a2a]*/900{901int rtn;902int strtype;903PyObject *bytesobj = NULL;904#ifdef HAVE_NCURSESW905wchar_t *wstr = NULL;906#endif907attr_t attr_old = A_NORMAL;908int use_xy = group_left_1, use_attr = group_right_1;909const char *funcname;910911#ifdef HAVE_NCURSESW912strtype = PyCurses_ConvertToString(self, str, &bytesobj, &wstr);913#else914strtype = PyCurses_ConvertToString(self, str, &bytesobj, NULL);915#endif916if (strtype == 0)917return NULL;918919if (use_attr) {920attr_old = getattrs(self->win);921(void)wattrset(self->win,attr);922}923#ifdef HAVE_NCURSESW924if (strtype == 2) {925funcname = "addnwstr";926if (use_xy)927rtn = mvwaddnwstr(self->win,y,x,wstr,n);928else929rtn = waddnwstr(self->win,wstr,n);930PyMem_Free(wstr);931}932else933#endif934{935const char *str = PyBytes_AS_STRING(bytesobj);936funcname = "addnstr";937if (use_xy)938rtn = mvwaddnstr(self->win,y,x,str,n);939else940rtn = waddnstr(self->win,str,n);941Py_DECREF(bytesobj);942}943if (use_attr)944(void)wattrset(self->win,attr_old);945return PyCursesCheckERR(rtn, funcname);946}947948/*[clinic input]949_curses.window.bkgd950951ch: object952Background character.953attr: long(c_default="A_NORMAL") = _curses.A_NORMAL954Background attributes.955/956957Set the background property of the window.958[clinic start generated code]*/959960static PyObject *961_curses_window_bkgd_impl(PyCursesWindowObject *self, PyObject *ch, long attr)962/*[clinic end generated code: output=058290afb2cf4034 input=634015bcb339283d]*/963{964chtype bkgd;965966if (!PyCurses_ConvertToChtype(self, ch, &bkgd))967return NULL;968969return PyCursesCheckERR(wbkgd(self->win, bkgd | attr), "bkgd");970}971972/*[clinic input]973_curses.window.attroff974975attr: long976/977978Remove attribute attr from the "background" set.979[clinic start generated code]*/980981static PyObject *982_curses_window_attroff_impl(PyCursesWindowObject *self, long attr)983/*[clinic end generated code: output=8a2fcd4df682fc64 input=786beedf06a7befe]*/984{985return PyCursesCheckERR(wattroff(self->win, (attr_t)attr), "attroff");986}987988/*[clinic input]989_curses.window.attron990991attr: long992/993994Add attribute attr from the "background" set.995[clinic start generated code]*/996997static PyObject *998_curses_window_attron_impl(PyCursesWindowObject *self, long attr)999/*[clinic end generated code: output=7afea43b237fa870 input=5a88fba7b1524f32]*/1000{1001return PyCursesCheckERR(wattron(self->win, (attr_t)attr), "attron");1002}10031004/*[clinic input]1005_curses.window.attrset10061007attr: long1008/10091010Set the "background" set of attributes.1011[clinic start generated code]*/10121013static PyObject *1014_curses_window_attrset_impl(PyCursesWindowObject *self, long attr)1015/*[clinic end generated code: output=84e379bff20c0433 input=42e400c0d0154ab5]*/1016{1017return PyCursesCheckERR(wattrset(self->win, (attr_t)attr), "attrset");1018}10191020/*[clinic input]1021_curses.window.bkgdset10221023ch: object1024Background character.1025attr: long(c_default="A_NORMAL") = _curses.A_NORMAL1026Background attributes.1027/10281029Set the window's background.1030[clinic start generated code]*/10311032static PyObject *1033_curses_window_bkgdset_impl(PyCursesWindowObject *self, PyObject *ch,1034long attr)1035/*[clinic end generated code: output=8cb994fc4d7e2496 input=e09c682425c9e45b]*/1036{1037chtype bkgd;10381039if (!PyCurses_ConvertToChtype(self, ch, &bkgd))1040return NULL;10411042wbkgdset(self->win, bkgd | attr);1043return PyCursesCheckERR(0, "bkgdset");1044}10451046/*[clinic input]1047_curses.window.border10481049ls: object(c_default="NULL") = _curses.ACS_VLINE1050Left side.1051rs: object(c_default="NULL") = _curses.ACS_VLINE1052Right side.1053ts: object(c_default="NULL") = _curses.ACS_HLINE1054Top side.1055bs: object(c_default="NULL") = _curses.ACS_HLINE1056Bottom side.1057tl: object(c_default="NULL") = _curses.ACS_ULCORNER1058Upper-left corner.1059tr: object(c_default="NULL") = _curses.ACS_URCORNER1060Upper-right corner.1061bl: object(c_default="NULL") = _curses.ACS_LLCORNER1062Bottom-left corner.1063br: object(c_default="NULL") = _curses.ACS_LRCORNER1064Bottom-right corner.1065/10661067Draw a border around the edges of the window.10681069Each parameter specifies the character to use for a specific part of the1070border. The characters can be specified as integers or as one-character1071strings. A 0 value for any parameter will cause the default character to be1072used for that parameter.1073[clinic start generated code]*/10741075static PyObject *1076_curses_window_border_impl(PyCursesWindowObject *self, PyObject *ls,1077PyObject *rs, PyObject *ts, PyObject *bs,1078PyObject *tl, PyObject *tr, PyObject *bl,1079PyObject *br)1080/*[clinic end generated code: output=670ef38d3d7c2aa3 input=e015f735d67a240b]*/1081{1082chtype ch[8];1083int i;10841085/* Clear the array of parameters */1086for(i=0; i<8; i++)1087ch[i] = 0;10881089#define CONVERTTOCHTYPE(obj, i) \1090if ((obj) != NULL && !PyCurses_ConvertToChtype(self, (obj), &ch[(i)])) \1091return NULL;10921093CONVERTTOCHTYPE(ls, 0);1094CONVERTTOCHTYPE(rs, 1);1095CONVERTTOCHTYPE(ts, 2);1096CONVERTTOCHTYPE(bs, 3);1097CONVERTTOCHTYPE(tl, 4);1098CONVERTTOCHTYPE(tr, 5);1099CONVERTTOCHTYPE(bl, 6);1100CONVERTTOCHTYPE(br, 7);11011102#undef CONVERTTOCHTYPE11031104wborder(self->win,1105ch[0], ch[1], ch[2], ch[3],1106ch[4], ch[5], ch[6], ch[7]);1107Py_RETURN_NONE;1108}11091110/*[clinic input]1111_curses.window.box11121113[1114verch: object(c_default="_PyLong_GetZero()") = 01115Left and right side.1116horch: object(c_default="_PyLong_GetZero()") = 01117Top and bottom side.1118]1119/11201121Draw a border around the edges of the window.11221123Similar to border(), but both ls and rs are verch and both ts and bs are1124horch. The default corner characters are always used by this function.1125[clinic start generated code]*/11261127static PyObject *1128_curses_window_box_impl(PyCursesWindowObject *self, int group_right_1,1129PyObject *verch, PyObject *horch)1130/*[clinic end generated code: output=f3fcb038bb287192 input=f00435f9c8c98f60]*/1131{1132chtype ch1 = 0, ch2 = 0;1133if (group_right_1) {1134if (!PyCurses_ConvertToChtype(self, verch, &ch1)) {1135return NULL;1136}1137if (!PyCurses_ConvertToChtype(self, horch, &ch2)) {1138return NULL;1139}1140}1141box(self->win,ch1,ch2);1142Py_RETURN_NONE;1143}11441145#if defined(HAVE_NCURSES_H) || defined(MVWDELCH_IS_EXPRESSION)1146#define py_mvwdelch mvwdelch1147#else1148int py_mvwdelch(WINDOW *w, int y, int x)1149{1150mvwdelch(w,y,x);1151/* On HP/UX, mvwdelch already returns. On other systems,1152we may well run into this return statement. */1153return 0;1154}1155#endif11561157#if defined(HAVE_CURSES_IS_PAD)1158#define py_is_pad(win) is_pad(win)1159#elif defined(WINDOW_HAS_FLAGS)1160#define py_is_pad(win) ((win) ? ((win)->_flags & _ISPAD) != 0 : FALSE)1161#endif11621163/* chgat, added by Fabian Kreutz <fabian.kreutz at gmx.net> */1164#ifdef HAVE_CURSES_WCHGAT1165/*[-clinic input]1166_curses.window.chgat11671168[1169y: int1170Y-coordinate.1171x: int1172X-coordinate.1173]11741175n: int = -11176Number of characters.11771178attr: long1179Attributes for characters.1180/11811182Set the attributes of characters.11831184Set the attributes of num characters at the current cursor position, or at1185position (y, x) if supplied. If no value of num is given or num = -1, the1186attribute will be set on all the characters to the end of the line. This1187function does not move the cursor. The changed line will be touched using1188the touchline() method so that the contents will be redisplayed by the next1189window refresh.1190[-clinic start generated code]*/1191static PyObject *1192PyCursesWindow_ChgAt(PyCursesWindowObject *self, PyObject *args)1193{1194int rtn;1195int x, y;1196int num = -1;1197short color;1198attr_t attr = A_NORMAL;1199long lattr;1200int use_xy = FALSE;12011202switch (PyTuple_Size(args)) {1203case 1:1204if (!PyArg_ParseTuple(args,"l;attr", &lattr))1205return NULL;1206attr = lattr;1207break;1208case 2:1209if (!PyArg_ParseTuple(args,"il;n,attr", &num, &lattr))1210return NULL;1211attr = lattr;1212break;1213case 3:1214if (!PyArg_ParseTuple(args,"iil;int,int,attr", &y, &x, &lattr))1215return NULL;1216attr = lattr;1217use_xy = TRUE;1218break;1219case 4:1220if (!PyArg_ParseTuple(args,"iiil;int,int,n,attr", &y, &x, &num, &lattr))1221return NULL;1222attr = lattr;1223use_xy = TRUE;1224break;1225default:1226PyErr_SetString(PyExc_TypeError, "chgat requires 1 to 4 arguments");1227return NULL;1228}12291230color = (short) PAIR_NUMBER(attr);1231attr = attr & A_ATTRIBUTES;12321233if (use_xy) {1234rtn = mvwchgat(self->win,y,x,num,attr,color,NULL);1235touchline(self->win,y,1);1236} else {1237getyx(self->win,y,x);1238rtn = wchgat(self->win,num,attr,color,NULL);1239touchline(self->win,y,1);1240}1241return PyCursesCheckERR(rtn, "chgat");1242}1243#endif12441245/*[clinic input]1246_curses.window.delch12471248[1249y: int1250Y-coordinate.1251x: int1252X-coordinate.1253]1254/12551256Delete any character at (y, x).1257[clinic start generated code]*/12581259static PyObject *1260_curses_window_delch_impl(PyCursesWindowObject *self, int group_right_1,1261int y, int x)1262/*[clinic end generated code: output=22e77bb9fa11b461 input=d2f79e630a4fc6d0]*/1263{1264if (!group_right_1) {1265return PyCursesCheckERR(wdelch(self->win), "wdelch");1266}1267else {1268return PyCursesCheckERR(py_mvwdelch(self->win, y, x), "mvwdelch");1269}1270}12711272/*[clinic input]1273_curses.window.derwin12741275[1276nlines: int = 01277Height.1278ncols: int = 01279Width.1280]1281begin_y: int1282Top side y-coordinate.1283begin_x: int1284Left side x-coordinate.1285/12861287Create a sub-window (window-relative coordinates).12881289derwin() is the same as calling subwin(), except that begin_y and begin_x1290are relative to the origin of the window, rather than relative to the entire1291screen.1292[clinic start generated code]*/12931294static PyObject *1295_curses_window_derwin_impl(PyCursesWindowObject *self, int group_left_1,1296int nlines, int ncols, int begin_y, int begin_x)1297/*[clinic end generated code: output=7924b112d9f70d6e input=966d9481f7f5022e]*/1298{1299WINDOW *win;13001301win = derwin(self->win,nlines,ncols,begin_y,begin_x);13021303if (win == NULL) {1304PyErr_SetString(PyCursesError, catchall_NULL);1305return NULL;1306}13071308return (PyObject *)PyCursesWindow_New(win, NULL);1309}13101311/*[clinic input]1312_curses.window.echochar13131314ch: object1315Character to add.13161317attr: long(c_default="A_NORMAL") = _curses.A_NORMAL1318Attributes for the character.1319/13201321Add character ch with attribute attr, and refresh.1322[clinic start generated code]*/13231324static PyObject *1325_curses_window_echochar_impl(PyCursesWindowObject *self, PyObject *ch,1326long attr)1327/*[clinic end generated code: output=13e7dd875d4b9642 input=e7f34b964e92b156]*/1328{1329chtype ch_;13301331if (!PyCurses_ConvertToChtype(self, ch, &ch_))1332return NULL;13331334#ifdef py_is_pad1335if (py_is_pad(self->win)) {1336return PyCursesCheckERR(pechochar(self->win, ch_ | (attr_t)attr),1337"echochar");1338}1339else1340#endif1341return PyCursesCheckERR(wechochar(self->win, ch_ | (attr_t)attr),1342"echochar");1343}13441345#ifdef NCURSES_MOUSE_VERSION1346/*[clinic input]1347_curses.window.enclose13481349y: int1350Y-coordinate.1351x: int1352X-coordinate.1353/13541355Return True if the screen-relative coordinates are enclosed by the window.1356[clinic start generated code]*/13571358static PyObject *1359_curses_window_enclose_impl(PyCursesWindowObject *self, int y, int x)1360/*[clinic end generated code: output=8679beef50502648 input=4fd3355d723f7bc9]*/1361{1362return PyBool_FromLong(wenclose(self->win, y, x));1363}1364#endif13651366/*[clinic input]1367_curses.window.getbkgd -> long13681369Return the window's current background character/attribute pair.1370[clinic start generated code]*/13711372static long1373_curses_window_getbkgd_impl(PyCursesWindowObject *self)1374/*[clinic end generated code: output=c52b25dc16b215c3 input=a69db882fa35426c]*/1375{1376return (long) getbkgd(self->win);1377}13781379/*[clinic input]1380_curses.window.getch -> int13811382[1383y: int1384Y-coordinate.1385x: int1386X-coordinate.1387]1388/13891390Get a character code from terminal keyboard.13911392The integer returned does not have to be in ASCII range: function keys,1393keypad keys and so on return numbers higher than 256. In no-delay mode, -11394is returned if there is no input, else getch() waits until a key is pressed.1395[clinic start generated code]*/13961397static int1398_curses_window_getch_impl(PyCursesWindowObject *self, int group_right_1,1399int y, int x)1400/*[clinic end generated code: output=980aa6af0c0ca387 input=bb24ebfb379f991f]*/1401{1402int rtn;14031404Py_BEGIN_ALLOW_THREADS1405if (!group_right_1) {1406rtn = wgetch(self->win);1407}1408else {1409rtn = mvwgetch(self->win, y, x);1410}1411Py_END_ALLOW_THREADS14121413return rtn;1414}14151416/*[clinic input]1417_curses.window.getkey14181419[1420y: int1421Y-coordinate.1422x: int1423X-coordinate.1424]1425/14261427Get a character (string) from terminal keyboard.14281429Returning a string instead of an integer, as getch() does. Function keys,1430keypad keys and other special keys return a multibyte string containing the1431key name. In no-delay mode, an exception is raised if there is no input.1432[clinic start generated code]*/14331434static PyObject *1435_curses_window_getkey_impl(PyCursesWindowObject *self, int group_right_1,1436int y, int x)1437/*[clinic end generated code: output=8490a182db46b10f input=be2dee34f5cf57f8]*/1438{1439int rtn;14401441Py_BEGIN_ALLOW_THREADS1442if (!group_right_1) {1443rtn = wgetch(self->win);1444}1445else {1446rtn = mvwgetch(self->win, y, x);1447}1448Py_END_ALLOW_THREADS14491450if (rtn == ERR) {1451/* getch() returns ERR in nodelay mode */1452PyErr_CheckSignals();1453if (!PyErr_Occurred())1454PyErr_SetString(PyCursesError, "no input");1455return NULL;1456} else if (rtn <= 255) {1457#ifdef NCURSES_VERSION_MAJOR1458#if NCURSES_VERSION_MAJOR*100+NCURSES_VERSION_MINOR <= 5071459/* Work around a bug in ncurses 5.7 and earlier */1460if (rtn < 0) {1461rtn += 256;1462}1463#endif1464#endif1465return PyUnicode_FromOrdinal(rtn);1466} else {1467const char *knp = keyname(rtn);1468return PyUnicode_FromString((knp == NULL) ? "" : knp);1469}1470}14711472#ifdef HAVE_NCURSESW1473/*[clinic input]1474_curses.window.get_wch14751476[1477y: int1478Y-coordinate.1479x: int1480X-coordinate.1481]1482/14831484Get a wide character from terminal keyboard.14851486Return a character for most keys, or an integer for function keys,1487keypad keys, and other special keys.1488[clinic start generated code]*/14891490static PyObject *1491_curses_window_get_wch_impl(PyCursesWindowObject *self, int group_right_1,1492int y, int x)1493/*[clinic end generated code: output=9f4f86e91fe50ef3 input=dd7e5367fb49dc48]*/1494{1495int ct;1496wint_t rtn;14971498Py_BEGIN_ALLOW_THREADS1499if (!group_right_1) {1500ct = wget_wch(self->win ,&rtn);1501}1502else {1503ct = mvwget_wch(self->win, y, x, &rtn);1504}1505Py_END_ALLOW_THREADS15061507if (ct == ERR) {1508if (PyErr_CheckSignals())1509return NULL;15101511/* get_wch() returns ERR in nodelay mode */1512PyErr_SetString(PyCursesError, "no input");1513return NULL;1514}1515if (ct == KEY_CODE_YES)1516return PyLong_FromLong(rtn);1517else1518return PyUnicode_FromOrdinal(rtn);1519}1520#endif15211522/*[-clinic input]1523_curses.window.getstr15241525[1526y: int1527Y-coordinate.1528x: int1529X-coordinate.1530]1531n: int = 10231532Maximal number of characters.1533/15341535Read a string from the user, with primitive line editing capacity.1536[-clinic start generated code]*/15371538static PyObject *1539PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args)1540{1541int x, y, n;1542char rtn[1024]; /* This should be big enough.. I hope */1543int rtn2;15441545switch (PyTuple_Size(args)) {1546case 0:1547Py_BEGIN_ALLOW_THREADS1548rtn2 = wgetnstr(self->win,rtn, 1023);1549Py_END_ALLOW_THREADS1550break;1551case 1:1552if (!PyArg_ParseTuple(args,"i;n", &n))1553return NULL;1554if (n < 0) {1555PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");1556return NULL;1557}1558Py_BEGIN_ALLOW_THREADS1559rtn2 = wgetnstr(self->win, rtn, Py_MIN(n, 1023));1560Py_END_ALLOW_THREADS1561break;1562case 2:1563if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))1564return NULL;1565Py_BEGIN_ALLOW_THREADS1566#ifdef STRICT_SYSV_CURSES1567rtn2 = wmove(self->win,y,x)==ERR ? ERR : wgetnstr(self->win, rtn, 1023);1568#else1569rtn2 = mvwgetnstr(self->win,y,x,rtn, 1023);1570#endif1571Py_END_ALLOW_THREADS1572break;1573case 3:1574if (!PyArg_ParseTuple(args,"iii;y,x,n", &y, &x, &n))1575return NULL;1576if (n < 0) {1577PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");1578return NULL;1579}1580#ifdef STRICT_SYSV_CURSES1581Py_BEGIN_ALLOW_THREADS1582rtn2 = wmove(self->win,y,x)==ERR ? ERR :1583wgetnstr(self->win, rtn, Py_MIN(n, 1023));1584Py_END_ALLOW_THREADS1585#else1586Py_BEGIN_ALLOW_THREADS1587rtn2 = mvwgetnstr(self->win, y, x, rtn, Py_MIN(n, 1023));1588Py_END_ALLOW_THREADS1589#endif1590break;1591default:1592PyErr_SetString(PyExc_TypeError, "getstr requires 0 to 3 arguments");1593return NULL;1594}1595if (rtn2 == ERR)1596rtn[0] = 0;1597return PyBytes_FromString(rtn);1598}15991600/*[clinic input]1601_curses.window.hline16021603[1604y: int1605Starting Y-coordinate.1606x: int1607Starting X-coordinate.1608]16091610ch: object1611Character to draw.1612n: int1613Line length.16141615[1616attr: long(c_default="A_NORMAL") = _curses.A_NORMAL1617Attributes for the characters.1618]1619/16201621Display a horizontal line.1622[clinic start generated code]*/16231624static PyObject *1625_curses_window_hline_impl(PyCursesWindowObject *self, int group_left_1,1626int y, int x, PyObject *ch, int n,1627int group_right_1, long attr)1628/*[clinic end generated code: output=c00d489d61fc9eef input=81a4dea47268163e]*/1629{1630chtype ch_;16311632if (!PyCurses_ConvertToChtype(self, ch, &ch_))1633return NULL;1634if (group_left_1) {1635if (wmove(self->win, y, x) == ERR) {1636return PyCursesCheckERR(ERR, "wmove");1637}1638}1639return PyCursesCheckERR(whline(self->win, ch_ | (attr_t)attr, n), "hline");1640}16411642/*[clinic input]1643_curses.window.insch16441645[1646y: int1647Y-coordinate.1648x: int1649X-coordinate.1650]16511652ch: object1653Character to insert.16541655[1656attr: long(c_default="A_NORMAL") = _curses.A_NORMAL1657Attributes for the character.1658]1659/16601661Insert a character before the current or specified position.16621663All characters to the right of the cursor are shifted one position right, with1664the rightmost characters on the line being lost.1665[clinic start generated code]*/16661667static PyObject *1668_curses_window_insch_impl(PyCursesWindowObject *self, int group_left_1,1669int y, int x, PyObject *ch, int group_right_1,1670long attr)1671/*[clinic end generated code: output=ade8cfe3a3bf3e34 input=336342756ee19812]*/1672{1673int rtn;1674chtype ch_ = 0;16751676if (!PyCurses_ConvertToChtype(self, ch, &ch_))1677return NULL;16781679if (!group_left_1) {1680rtn = winsch(self->win, ch_ | (attr_t)attr);1681}1682else {1683rtn = mvwinsch(self->win, y, x, ch_ | (attr_t)attr);1684}16851686return PyCursesCheckERR(rtn, "insch");1687}16881689/*[clinic input]1690_curses.window.inch -> unsigned_long16911692[1693y: int1694Y-coordinate.1695x: int1696X-coordinate.1697]1698/16991700Return the character at the given position in the window.17011702The bottom 8 bits are the character proper, and upper bits are the attributes.1703[clinic start generated code]*/17041705static unsigned long1706_curses_window_inch_impl(PyCursesWindowObject *self, int group_right_1,1707int y, int x)1708/*[clinic end generated code: output=6c4719fe978fe86a input=fac23ee11e3b3a66]*/1709{1710unsigned long rtn;17111712if (!group_right_1) {1713rtn = winch(self->win);1714}1715else {1716rtn = mvwinch(self->win, y, x);1717}17181719return rtn;1720}17211722/*[-clinic input]1723_curses.window.instr17241725[1726y: int1727Y-coordinate.1728x: int1729X-coordinate.1730]1731n: int = 10231732Maximal number of characters.1733/17341735Return a string of characters, extracted from the window.17361737Return a string of characters, extracted from the window starting at the1738current cursor position, or at y, x if specified. Attributes are stripped1739from the characters. If n is specified, instr() returns a string at most1740n characters long (exclusive of the trailing NUL).1741[-clinic start generated code]*/1742static PyObject *1743PyCursesWindow_InStr(PyCursesWindowObject *self, PyObject *args)1744{1745int x, y, n;1746char rtn[1024]; /* This should be big enough.. I hope */1747int rtn2;17481749switch (PyTuple_Size(args)) {1750case 0:1751rtn2 = winnstr(self->win,rtn, 1023);1752break;1753case 1:1754if (!PyArg_ParseTuple(args,"i;n", &n))1755return NULL;1756if (n < 0) {1757PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");1758return NULL;1759}1760rtn2 = winnstr(self->win, rtn, Py_MIN(n, 1023));1761break;1762case 2:1763if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))1764return NULL;1765rtn2 = mvwinnstr(self->win,y,x,rtn,1023);1766break;1767case 3:1768if (!PyArg_ParseTuple(args, "iii;y,x,n", &y, &x, &n))1769return NULL;1770if (n < 0) {1771PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");1772return NULL;1773}1774rtn2 = mvwinnstr(self->win, y, x, rtn, Py_MIN(n,1023));1775break;1776default:1777PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments");1778return NULL;1779}1780if (rtn2 == ERR)1781rtn[0] = 0;1782return PyBytes_FromString(rtn);1783}17841785/*[clinic input]1786_curses.window.insstr17871788[1789y: int1790Y-coordinate.1791x: int1792X-coordinate.1793]17941795str: object1796String to insert.17971798[1799attr: long1800Attributes for characters.1801]1802/18031804Insert the string before the current or specified position.18051806Insert a character string (as many characters as will fit on the line)1807before the character under the cursor. All characters to the right of1808the cursor are shifted right, with the rightmost characters on the line1809being lost. The cursor position does not change (after moving to y, x,1810if specified).1811[clinic start generated code]*/18121813static PyObject *1814_curses_window_insstr_impl(PyCursesWindowObject *self, int group_left_1,1815int y, int x, PyObject *str, int group_right_1,1816long attr)1817/*[clinic end generated code: output=c259a5265ad0b777 input=6827cddc6340a7f3]*/1818{1819int rtn;1820int strtype;1821PyObject *bytesobj = NULL;1822#ifdef HAVE_NCURSESW1823wchar_t *wstr = NULL;1824#endif1825attr_t attr_old = A_NORMAL;1826int use_xy = group_left_1, use_attr = group_right_1;1827const char *funcname;18281829#ifdef HAVE_NCURSESW1830strtype = PyCurses_ConvertToString(self, str, &bytesobj, &wstr);1831#else1832strtype = PyCurses_ConvertToString(self, str, &bytesobj, NULL);1833#endif1834if (strtype == 0)1835return NULL;18361837if (use_attr) {1838attr_old = getattrs(self->win);1839(void)wattrset(self->win, (attr_t)attr);1840}1841#ifdef HAVE_NCURSESW1842if (strtype == 2) {1843funcname = "inswstr";1844if (use_xy)1845rtn = mvwins_wstr(self->win,y,x,wstr);1846else1847rtn = wins_wstr(self->win,wstr);1848PyMem_Free(wstr);1849}1850else1851#endif1852{1853const char *str = PyBytes_AS_STRING(bytesobj);1854funcname = "insstr";1855if (use_xy)1856rtn = mvwinsstr(self->win,y,x,str);1857else1858rtn = winsstr(self->win,str);1859Py_DECREF(bytesobj);1860}1861if (use_attr)1862(void)wattrset(self->win,attr_old);1863return PyCursesCheckERR(rtn, funcname);1864}18651866/*[clinic input]1867_curses.window.insnstr18681869[1870y: int1871Y-coordinate.1872x: int1873X-coordinate.1874]18751876str: object1877String to insert.18781879n: int1880Maximal number of characters.18811882[1883attr: long1884Attributes for characters.1885]1886/18871888Insert at most n characters of the string.18891890Insert a character string (as many characters as will fit on the line)1891before the character under the cursor, up to n characters. If n is zero1892or negative, the entire string is inserted. All characters to the right1893of the cursor are shifted right, with the rightmost characters on the line1894being lost. The cursor position does not change (after moving to y, x, if1895specified).1896[clinic start generated code]*/18971898static PyObject *1899_curses_window_insnstr_impl(PyCursesWindowObject *self, int group_left_1,1900int y, int x, PyObject *str, int n,1901int group_right_1, long attr)1902/*[clinic end generated code: output=971a32ea6328ec8b input=70fa0cd543901a4c]*/1903{1904int rtn;1905int strtype;1906PyObject *bytesobj = NULL;1907#ifdef HAVE_NCURSESW1908wchar_t *wstr = NULL;1909#endif1910attr_t attr_old = A_NORMAL;1911int use_xy = group_left_1, use_attr = group_right_1;1912const char *funcname;19131914#ifdef HAVE_NCURSESW1915strtype = PyCurses_ConvertToString(self, str, &bytesobj, &wstr);1916#else1917strtype = PyCurses_ConvertToString(self, str, &bytesobj, NULL);1918#endif1919if (strtype == 0)1920return NULL;19211922if (use_attr) {1923attr_old = getattrs(self->win);1924(void)wattrset(self->win, (attr_t)attr);1925}1926#ifdef HAVE_NCURSESW1927if (strtype == 2) {1928funcname = "insn_wstr";1929if (use_xy)1930rtn = mvwins_nwstr(self->win,y,x,wstr,n);1931else1932rtn = wins_nwstr(self->win,wstr,n);1933PyMem_Free(wstr);1934}1935else1936#endif1937{1938const char *str = PyBytes_AS_STRING(bytesobj);1939funcname = "insnstr";1940if (use_xy)1941rtn = mvwinsnstr(self->win,y,x,str,n);1942else1943rtn = winsnstr(self->win,str,n);1944Py_DECREF(bytesobj);1945}1946if (use_attr)1947(void)wattrset(self->win,attr_old);1948return PyCursesCheckERR(rtn, funcname);1949}19501951/*[clinic input]1952_curses.window.is_linetouched19531954line: int1955Line number.1956/19571958Return True if the specified line was modified, otherwise return False.19591960Raise a curses.error exception if line is not valid for the given window.1961[clinic start generated code]*/19621963static PyObject *1964_curses_window_is_linetouched_impl(PyCursesWindowObject *self, int line)1965/*[clinic end generated code: output=ad4a4edfee2db08c input=a7be0c189f243914]*/1966{1967int erg;1968erg = is_linetouched(self->win, line);1969if (erg == ERR) {1970PyErr_SetString(PyExc_TypeError,1971"is_linetouched: line number outside of boundaries");1972return NULL;1973}1974return PyBool_FromLong(erg);1975}19761977#ifdef py_is_pad1978/*[clinic input]1979_curses.window.noutrefresh19801981[1982pminrow: int1983pmincol: int1984sminrow: int1985smincol: int1986smaxrow: int1987smaxcol: int1988]1989/19901991Mark for refresh but wait.19921993This function updates the data structure representing the desired state of the1994window, but does not force an update of the physical screen. To accomplish1995that, call doupdate().1996[clinic start generated code]*/19971998static PyObject *1999_curses_window_noutrefresh_impl(PyCursesWindowObject *self,2000int group_right_1, int pminrow, int pmincol,2001int sminrow, int smincol, int smaxrow,2002int smaxcol)2003/*[clinic end generated code: output=809a1f3c6a03e23e input=3e56898388cd739e]*/2004#else2005/*[clinic input]2006_curses.window.noutrefresh20072008Mark for refresh but wait.20092010This function updates the data structure representing the desired state of the2011window, but does not force an update of the physical screen. To accomplish2012that, call doupdate().2013[clinic start generated code]*/20142015static PyObject *2016_curses_window_noutrefresh_impl(PyCursesWindowObject *self)2017/*[clinic end generated code: output=6ef6dec666643fee input=876902e3fa431dbd]*/2018#endif2019{2020int rtn;20212022#ifdef py_is_pad2023if (py_is_pad(self->win)) {2024if (!group_right_1) {2025PyErr_SetString(PyCursesError,2026"noutrefresh() called for a pad "2027"requires 6 arguments");2028return NULL;2029}2030Py_BEGIN_ALLOW_THREADS2031rtn = pnoutrefresh(self->win, pminrow, pmincol,2032sminrow, smincol, smaxrow, smaxcol);2033Py_END_ALLOW_THREADS2034return PyCursesCheckERR(rtn, "pnoutrefresh");2035}2036if (group_right_1) {2037PyErr_SetString(PyExc_TypeError,2038"noutrefresh() takes no arguments (6 given)");2039return NULL;2040}2041#endif2042Py_BEGIN_ALLOW_THREADS2043rtn = wnoutrefresh(self->win);2044Py_END_ALLOW_THREADS2045return PyCursesCheckERR(rtn, "wnoutrefresh");2046}20472048/*[clinic input]2049_curses.window.overlay20502051destwin: object(type="PyCursesWindowObject *", subclass_of="&PyCursesWindow_Type")20522053[2054sminrow: int2055smincol: int2056dminrow: int2057dmincol: int2058dmaxrow: int2059dmaxcol: int2060]2061/20622063Overlay the window on top of destwin.20642065The windows need not be the same size, only the overlapping region is copied.2066This copy is non-destructive, which means that the current background2067character does not overwrite the old contents of destwin.20682069To get fine-grained control over the copied region, the second form of2070overlay() can be used. sminrow and smincol are the upper-left coordinates2071of the source window, and the other variables mark a rectangle in the2072destination window.2073[clinic start generated code]*/20742075static PyObject *2076_curses_window_overlay_impl(PyCursesWindowObject *self,2077PyCursesWindowObject *destwin, int group_right_1,2078int sminrow, int smincol, int dminrow,2079int dmincol, int dmaxrow, int dmaxcol)2080/*[clinic end generated code: output=82bb2c4cb443ca58 input=7edd23ad22cc1984]*/2081{2082int rtn;20832084if (group_right_1) {2085rtn = copywin(self->win, destwin->win, sminrow, smincol,2086dminrow, dmincol, dmaxrow, dmaxcol, TRUE);2087return PyCursesCheckERR(rtn, "copywin");2088}2089else {2090rtn = overlay(self->win, destwin->win);2091return PyCursesCheckERR(rtn, "overlay");2092}2093}20942095/*[clinic input]2096_curses.window.overwrite20972098destwin: object(type="PyCursesWindowObject *", subclass_of="&PyCursesWindow_Type")20992100[2101sminrow: int2102smincol: int2103dminrow: int2104dmincol: int2105dmaxrow: int2106dmaxcol: int2107]2108/21092110Overwrite the window on top of destwin.21112112The windows need not be the same size, in which case only the overlapping2113region is copied. This copy is destructive, which means that the current2114background character overwrites the old contents of destwin.21152116To get fine-grained control over the copied region, the second form of2117overwrite() can be used. sminrow and smincol are the upper-left coordinates2118of the source window, the other variables mark a rectangle in the destination2119window.2120[clinic start generated code]*/21212122static PyObject *2123_curses_window_overwrite_impl(PyCursesWindowObject *self,2124PyCursesWindowObject *destwin,2125int group_right_1, int sminrow, int smincol,2126int dminrow, int dmincol, int dmaxrow,2127int dmaxcol)2128/*[clinic end generated code: output=12ae007d1681be28 input=ea5de1b35cd948e0]*/2129{2130int rtn;21312132if (group_right_1) {2133rtn = copywin(self->win, destwin->win, sminrow, smincol,2134dminrow, dmincol, dmaxrow, dmaxcol, FALSE);2135return PyCursesCheckERR(rtn, "copywin");2136}2137else {2138rtn = overwrite(self->win, destwin->win);2139return PyCursesCheckERR(rtn, "overwrite");2140}2141}21422143/*[clinic input]2144_curses.window.putwin21452146file: object2147/21482149Write all data associated with the window into the provided file object.21502151This information can be later retrieved using the getwin() function.2152[clinic start generated code]*/21532154static PyObject *2155_curses_window_putwin(PyCursesWindowObject *self, PyObject *file)2156/*[clinic end generated code: output=3a25e2a5e7a040ac input=0608648e09c8ea0a]*/2157{2158/* We have to simulate this by writing to a temporary FILE*,2159then reading back, then writing to the argument file. */2160FILE *fp;2161PyObject *res = NULL;21622163fp = tmpfile();2164if (fp == NULL)2165return PyErr_SetFromErrno(PyExc_OSError);2166if (_Py_set_inheritable(fileno(fp), 0, NULL) < 0)2167goto exit;2168res = PyCursesCheckERR(putwin(self->win, fp), "putwin");2169if (res == NULL)2170goto exit;2171fseek(fp, 0, 0);2172while (1) {2173char buf[BUFSIZ];2174Py_ssize_t n = fread(buf, 1, BUFSIZ, fp);21752176if (n <= 0)2177break;2178Py_DECREF(res);2179res = PyObject_CallMethod(file, "write", "y#", buf, n);2180if (res == NULL)2181break;2182}21832184exit:2185fclose(fp);2186return res;2187}21882189/*[clinic input]2190_curses.window.redrawln21912192beg: int2193Starting line number.2194num: int2195The number of lines.2196/21972198Mark the specified lines corrupted.21992200They should be completely redrawn on the next refresh() call.2201[clinic start generated code]*/22022203static PyObject *2204_curses_window_redrawln_impl(PyCursesWindowObject *self, int beg, int num)2205/*[clinic end generated code: output=ea216e334f9ce1b4 input=152155e258a77a7a]*/2206{2207return PyCursesCheckERR(wredrawln(self->win,beg,num), "redrawln");2208}22092210/*[clinic input]2211_curses.window.refresh22122213[2214pminrow: int2215pmincol: int2216sminrow: int2217smincol: int2218smaxrow: int2219smaxcol: int2220]2221/22222223Update the display immediately.22242225Synchronize actual screen with previous drawing/deleting methods.2226The 6 optional arguments can only be specified when the window is a pad2227created with newpad(). The additional parameters are needed to indicate2228what part of the pad and screen are involved. pminrow and pmincol specify2229the upper left-hand corner of the rectangle to be displayed in the pad.2230sminrow, smincol, smaxrow, and smaxcol specify the edges of the rectangle to2231be displayed on the screen. The lower right-hand corner of the rectangle to2232be displayed in the pad is calculated from the screen coordinates, since the2233rectangles must be the same size. Both rectangles must be entirely contained2234within their respective structures. Negative values of pminrow, pmincol,2235sminrow, or smincol are treated as if they were zero.2236[clinic start generated code]*/22372238static PyObject *2239_curses_window_refresh_impl(PyCursesWindowObject *self, int group_right_1,2240int pminrow, int pmincol, int sminrow,2241int smincol, int smaxrow, int smaxcol)2242/*[clinic end generated code: output=42199543115e6e63 input=95e01cb5ffc635d0]*/2243{2244int rtn;22452246#ifdef py_is_pad2247if (py_is_pad(self->win)) {2248if (!group_right_1) {2249PyErr_SetString(PyCursesError,2250"refresh() for a pad requires 6 arguments");2251return NULL;2252}2253Py_BEGIN_ALLOW_THREADS2254rtn = prefresh(self->win, pminrow, pmincol,2255sminrow, smincol, smaxrow, smaxcol);2256Py_END_ALLOW_THREADS2257return PyCursesCheckERR(rtn, "prefresh");2258}2259#endif2260if (group_right_1) {2261PyErr_SetString(PyExc_TypeError,2262"refresh() takes no arguments (6 given)");2263return NULL;2264}2265Py_BEGIN_ALLOW_THREADS2266rtn = wrefresh(self->win);2267Py_END_ALLOW_THREADS2268return PyCursesCheckERR(rtn, "prefresh");2269}22702271/*[clinic input]2272_curses.window.setscrreg22732274top: int2275First line number.2276bottom: int2277Last line number.2278/22792280Define a software scrolling region.22812282All scrolling actions will take place in this region.2283[clinic start generated code]*/22842285static PyObject *2286_curses_window_setscrreg_impl(PyCursesWindowObject *self, int top,2287int bottom)2288/*[clinic end generated code: output=486ab5db218d2b1a input=1b517b986838bf0e]*/2289{2290return PyCursesCheckERR(wsetscrreg(self->win, top, bottom), "wsetscrreg");2291}22922293/*[clinic input]2294_curses.window.subwin22952296[2297nlines: int = 02298Height.2299ncols: int = 02300Width.2301]2302begin_y: int2303Top side y-coordinate.2304begin_x: int2305Left side x-coordinate.2306/23072308Create a sub-window (screen-relative coordinates).23092310By default, the sub-window will extend from the specified position to the2311lower right corner of the window.2312[clinic start generated code]*/23132314static PyObject *2315_curses_window_subwin_impl(PyCursesWindowObject *self, int group_left_1,2316int nlines, int ncols, int begin_y, int begin_x)2317/*[clinic end generated code: output=93e898afc348f59a input=2129fa47fd57721c]*/2318{2319WINDOW *win;23202321/* printf("Subwin: %i %i %i %i \n", nlines, ncols, begin_y, begin_x); */2322#ifdef py_is_pad2323if (py_is_pad(self->win)) {2324win = subpad(self->win, nlines, ncols, begin_y, begin_x);2325}2326else2327#endif2328win = subwin(self->win, nlines, ncols, begin_y, begin_x);23292330if (win == NULL) {2331PyErr_SetString(PyCursesError, catchall_NULL);2332return NULL;2333}23342335return (PyObject *)PyCursesWindow_New(win, self->encoding);2336}23372338/*[clinic input]2339_curses.window.scroll23402341[2342lines: int = 12343Number of lines to scroll.2344]2345/23462347Scroll the screen or scrolling region.23482349Scroll upward if the argument is positive and downward if it is negative.2350[clinic start generated code]*/23512352static PyObject *2353_curses_window_scroll_impl(PyCursesWindowObject *self, int group_right_1,2354int lines)2355/*[clinic end generated code: output=4541a8a11852d360 input=c969ca0cfabbdbec]*/2356{2357if (!group_right_1) {2358return PyCursesCheckERR(scroll(self->win), "scroll");2359}2360else {2361return PyCursesCheckERR(wscrl(self->win, lines), "scroll");2362}2363}23642365/*[clinic input]2366_curses.window.touchline23672368start: int2369count: int2370[2371changed: bool = True2372]2373/23742375Pretend count lines have been changed, starting with line start.23762377If changed is supplied, it specifies whether the affected lines are marked2378as having been changed (changed=True) or unchanged (changed=False).2379[clinic start generated code]*/23802381static PyObject *2382_curses_window_touchline_impl(PyCursesWindowObject *self, int start,2383int count, int group_right_1, int changed)2384/*[clinic end generated code: output=65d05b3f7438c61d input=a98aa4f79b6be845]*/2385{2386if (!group_right_1) {2387return PyCursesCheckERR(touchline(self->win, start, count), "touchline");2388}2389else {2390return PyCursesCheckERR(wtouchln(self->win, start, count, changed), "touchline");2391}2392}23932394/*[clinic input]2395_curses.window.vline23962397[2398y: int2399Starting Y-coordinate.2400x: int2401Starting X-coordinate.2402]24032404ch: object2405Character to draw.2406n: int2407Line length.24082409[2410attr: long(c_default="A_NORMAL") = _curses.A_NORMAL2411Attributes for the character.2412]2413/24142415Display a vertical line.2416[clinic start generated code]*/24172418static PyObject *2419_curses_window_vline_impl(PyCursesWindowObject *self, int group_left_1,2420int y, int x, PyObject *ch, int n,2421int group_right_1, long attr)2422/*[clinic end generated code: output=287ad1cc8982217f input=a6f2dc86a4648b32]*/2423{2424chtype ch_;24252426if (!PyCurses_ConvertToChtype(self, ch, &ch_))2427return NULL;2428if (group_left_1) {2429if (wmove(self->win, y, x) == ERR)2430return PyCursesCheckERR(ERR, "wmove");2431}2432return PyCursesCheckERR(wvline(self->win, ch_ | (attr_t)attr, n), "vline");2433}24342435static PyObject *2436PyCursesWindow_get_encoding(PyCursesWindowObject *self, void *closure)2437{2438return PyUnicode_FromString(self->encoding);2439}24402441static int2442PyCursesWindow_set_encoding(PyCursesWindowObject *self, PyObject *value, void *Py_UNUSED(ignored))2443{2444PyObject *ascii;2445char *encoding;24462447/* It is illegal to del win.encoding */2448if (value == NULL) {2449PyErr_SetString(PyExc_TypeError,2450"encoding may not be deleted");2451return -1;2452}24532454if (!PyUnicode_Check(value)) {2455PyErr_SetString(PyExc_TypeError,2456"setting encoding to a non-string");2457return -1;2458}2459ascii = PyUnicode_AsASCIIString(value);2460if (ascii == NULL)2461return -1;2462encoding = _PyMem_Strdup(PyBytes_AS_STRING(ascii));2463Py_DECREF(ascii);2464if (encoding == NULL) {2465PyErr_NoMemory();2466return -1;2467}2468PyMem_Free(self->encoding);2469self->encoding = encoding;2470return 0;2471}24722473#include "clinic/_cursesmodule.c.h"24742475static PyMethodDef PyCursesWindow_Methods[] = {2476_CURSES_WINDOW_ADDCH_METHODDEF2477_CURSES_WINDOW_ADDNSTR_METHODDEF2478_CURSES_WINDOW_ADDSTR_METHODDEF2479_CURSES_WINDOW_ATTROFF_METHODDEF2480_CURSES_WINDOW_ATTRON_METHODDEF2481_CURSES_WINDOW_ATTRSET_METHODDEF2482_CURSES_WINDOW_BKGD_METHODDEF2483#ifdef HAVE_CURSES_WCHGAT2484{"chgat", (PyCFunction)PyCursesWindow_ChgAt, METH_VARARGS},2485#endif2486_CURSES_WINDOW_BKGDSET_METHODDEF2487_CURSES_WINDOW_BORDER_METHODDEF2488_CURSES_WINDOW_BOX_METHODDEF2489{"clear", (PyCFunction)PyCursesWindow_wclear, METH_NOARGS},2490{"clearok", (PyCFunction)PyCursesWindow_clearok, METH_VARARGS},2491{"clrtobot", (PyCFunction)PyCursesWindow_wclrtobot, METH_NOARGS},2492{"clrtoeol", (PyCFunction)PyCursesWindow_wclrtoeol, METH_NOARGS},2493{"cursyncup", (PyCFunction)PyCursesWindow_wcursyncup, METH_NOARGS},2494_CURSES_WINDOW_DELCH_METHODDEF2495{"deleteln", (PyCFunction)PyCursesWindow_wdeleteln, METH_NOARGS},2496_CURSES_WINDOW_DERWIN_METHODDEF2497_CURSES_WINDOW_ECHOCHAR_METHODDEF2498_CURSES_WINDOW_ENCLOSE_METHODDEF2499{"erase", (PyCFunction)PyCursesWindow_werase, METH_NOARGS},2500{"getbegyx", (PyCFunction)PyCursesWindow_getbegyx, METH_NOARGS},2501_CURSES_WINDOW_GETBKGD_METHODDEF2502_CURSES_WINDOW_GETCH_METHODDEF2503_CURSES_WINDOW_GETKEY_METHODDEF2504_CURSES_WINDOW_GET_WCH_METHODDEF2505{"getmaxyx", (PyCFunction)PyCursesWindow_getmaxyx, METH_NOARGS},2506{"getparyx", (PyCFunction)PyCursesWindow_getparyx, METH_NOARGS},2507{"getstr", (PyCFunction)PyCursesWindow_GetStr, METH_VARARGS},2508{"getyx", (PyCFunction)PyCursesWindow_getyx, METH_NOARGS},2509_CURSES_WINDOW_HLINE_METHODDEF2510{"idcok", (PyCFunction)PyCursesWindow_idcok, METH_VARARGS},2511{"idlok", (PyCFunction)PyCursesWindow_idlok, METH_VARARGS},2512#ifdef HAVE_CURSES_IMMEDOK2513{"immedok", (PyCFunction)PyCursesWindow_immedok, METH_VARARGS},2514#endif2515_CURSES_WINDOW_INCH_METHODDEF2516_CURSES_WINDOW_INSCH_METHODDEF2517{"insdelln", (PyCFunction)PyCursesWindow_winsdelln, METH_VARARGS},2518{"insertln", (PyCFunction)PyCursesWindow_winsertln, METH_NOARGS},2519_CURSES_WINDOW_INSNSTR_METHODDEF2520_CURSES_WINDOW_INSSTR_METHODDEF2521{"instr", (PyCFunction)PyCursesWindow_InStr, METH_VARARGS},2522_CURSES_WINDOW_IS_LINETOUCHED_METHODDEF2523{"is_wintouched", (PyCFunction)PyCursesWindow_is_wintouched, METH_NOARGS},2524{"keypad", (PyCFunction)PyCursesWindow_keypad, METH_VARARGS},2525{"leaveok", (PyCFunction)PyCursesWindow_leaveok, METH_VARARGS},2526{"move", (PyCFunction)PyCursesWindow_wmove, METH_VARARGS},2527{"mvderwin", (PyCFunction)PyCursesWindow_mvderwin, METH_VARARGS},2528{"mvwin", (PyCFunction)PyCursesWindow_mvwin, METH_VARARGS},2529{"nodelay", (PyCFunction)PyCursesWindow_nodelay, METH_VARARGS},2530{"notimeout", (PyCFunction)PyCursesWindow_notimeout, METH_VARARGS},2531_CURSES_WINDOW_NOUTREFRESH_METHODDEF2532_CURSES_WINDOW_OVERLAY_METHODDEF2533_CURSES_WINDOW_OVERWRITE_METHODDEF2534_CURSES_WINDOW_PUTWIN_METHODDEF2535_CURSES_WINDOW_REDRAWLN_METHODDEF2536{"redrawwin", (PyCFunction)PyCursesWindow_redrawwin, METH_NOARGS},2537_CURSES_WINDOW_REFRESH_METHODDEF2538#ifndef STRICT_SYSV_CURSES2539{"resize", (PyCFunction)PyCursesWindow_wresize, METH_VARARGS},2540#endif2541_CURSES_WINDOW_SCROLL_METHODDEF2542{"scrollok", (PyCFunction)PyCursesWindow_scrollok, METH_VARARGS},2543_CURSES_WINDOW_SETSCRREG_METHODDEF2544{"standend", (PyCFunction)PyCursesWindow_wstandend, METH_NOARGS},2545{"standout", (PyCFunction)PyCursesWindow_wstandout, METH_NOARGS},2546{"subpad", (PyCFunction)_curses_window_subwin, METH_VARARGS, _curses_window_subwin__doc__},2547_CURSES_WINDOW_SUBWIN_METHODDEF2548{"syncdown", (PyCFunction)PyCursesWindow_wsyncdown, METH_NOARGS},2549#ifdef HAVE_CURSES_SYNCOK2550{"syncok", (PyCFunction)PyCursesWindow_syncok, METH_VARARGS},2551#endif2552{"syncup", (PyCFunction)PyCursesWindow_wsyncup, METH_NOARGS},2553{"timeout", (PyCFunction)PyCursesWindow_wtimeout, METH_VARARGS},2554_CURSES_WINDOW_TOUCHLINE_METHODDEF2555{"touchwin", (PyCFunction)PyCursesWindow_touchwin, METH_NOARGS},2556{"untouchwin", (PyCFunction)PyCursesWindow_untouchwin, METH_NOARGS},2557_CURSES_WINDOW_VLINE_METHODDEF2558{NULL, NULL} /* sentinel */2559};25602561static PyGetSetDef PyCursesWindow_getsets[] = {2562{"encoding",2563(getter)PyCursesWindow_get_encoding,2564(setter)PyCursesWindow_set_encoding,2565"the typecode character used to create the array"},2566{NULL, NULL, NULL, NULL } /* sentinel */2567};25682569/* -------------------------------------------------------*/25702571PyTypeObject PyCursesWindow_Type = {2572PyVarObject_HEAD_INIT(NULL, 0)2573"_curses.window", /*tp_name*/2574sizeof(PyCursesWindowObject), /*tp_basicsize*/25750, /*tp_itemsize*/2576/* methods */2577(destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/25780, /*tp_vectorcall_offset*/2579(getattrfunc)0, /*tp_getattr*/2580(setattrfunc)0, /*tp_setattr*/25810, /*tp_as_async*/25820, /*tp_repr*/25830, /*tp_as_number*/25840, /*tp_as_sequence*/25850, /*tp_as_mapping*/25860, /*tp_hash*/25870, /*tp_call*/25880, /*tp_str*/25890, /*tp_getattro*/25900, /*tp_setattro*/25910, /*tp_as_buffer*/2592Py_TPFLAGS_DEFAULT, /*tp_flags*/25930, /*tp_doc*/25940, /*tp_traverse*/25950, /*tp_clear*/25960, /*tp_richcompare*/25970, /*tp_weaklistoffset*/25980, /*tp_iter*/25990, /*tp_iternext*/2600PyCursesWindow_Methods, /*tp_methods*/26010, /* tp_members */2602PyCursesWindow_getsets, /* tp_getset */2603};26042605/* Function Prototype Macros - They are ugly but very, very useful. ;-)26062607X - function name2608TYPE - parameter Type2609ERGSTR - format string for construction of the return value2610PARSESTR - format string for argument parsing2611*/26122613#define NoArgNoReturnFunctionBody(X) \2614{ \2615PyCursesInitialised \2616return PyCursesCheckERR(X(), # X); }26172618#define NoArgOrFlagNoReturnFunctionBody(X, flag) \2619{ \2620PyCursesInitialised \2621if (flag) \2622return PyCursesCheckERR(X(), # X); \2623else \2624return PyCursesCheckERR(no ## X(), # X); \2625}26262627#define NoArgReturnIntFunctionBody(X) \2628{ \2629PyCursesInitialised \2630return PyLong_FromLong((long) X()); }263126322633#define NoArgReturnStringFunctionBody(X) \2634{ \2635PyCursesInitialised \2636return PyBytes_FromString(X()); }26372638#define NoArgTrueFalseFunctionBody(X) \2639{ \2640PyCursesInitialised \2641return PyBool_FromLong(X()); }26422643#define NoArgNoReturnVoidFunctionBody(X) \2644{ \2645PyCursesInitialised \2646X(); \2647Py_RETURN_NONE; }26482649/*********************************************************************2650Global Functions2651**********************************************************************/26522653#ifdef HAVE_CURSES_FILTER2654/*[clinic input]2655_curses.filter26562657[clinic start generated code]*/26582659static PyObject *2660_curses_filter_impl(PyObject *module)2661/*[clinic end generated code: output=fb5b8a3642eb70b5 input=668c75a6992d3624]*/2662{2663/* not checking for PyCursesInitialised here since filter() must2664be called before initscr() */2665filter();2666Py_RETURN_NONE;2667}2668#endif26692670/*[clinic input]2671_curses.baudrate26722673Return the output speed of the terminal in bits per second.2674[clinic start generated code]*/26752676static PyObject *2677_curses_baudrate_impl(PyObject *module)2678/*[clinic end generated code: output=3c63c6c401d7d9c0 input=921f022ed04a0fd9]*/2679NoArgReturnIntFunctionBody(baudrate)26802681/*[clinic input]2682_curses.beep26832684Emit a short attention sound.2685[clinic start generated code]*/26862687static PyObject *2688_curses_beep_impl(PyObject *module)2689/*[clinic end generated code: output=425274962abe49a2 input=a35698ca7d0162bc]*/2690NoArgNoReturnFunctionBody(beep)26912692/*[clinic input]2693_curses.can_change_color26942695Return True if the programmer can change the colors displayed by the terminal.2696[clinic start generated code]*/26972698static PyObject *2699_curses_can_change_color_impl(PyObject *module)2700/*[clinic end generated code: output=359df8c3c77d8bf1 input=d7718884de0092f2]*/2701NoArgTrueFalseFunctionBody(can_change_color)27022703/*[clinic input]2704_curses.cbreak27052706flag: bool = True2707If false, the effect is the same as calling nocbreak().2708/27092710Enter cbreak mode.27112712In cbreak mode (sometimes called "rare" mode) normal tty line buffering is2713turned off and characters are available to be read one by one. However,2714unlike raw mode, special characters (interrupt, quit, suspend, and flow2715control) retain their effects on the tty driver and calling program.2716Calling first raw() then cbreak() leaves the terminal in cbreak mode.2717[clinic start generated code]*/27182719static PyObject *2720_curses_cbreak_impl(PyObject *module, int flag)2721/*[clinic end generated code: output=9f9dee9664769751 input=c7d0bddda93016c1]*/2722NoArgOrFlagNoReturnFunctionBody(cbreak, flag)27232724/*[clinic input]2725_curses.color_content27262727color_number: color2728The number of the color (0 - (COLORS-1)).2729/27302731Return the red, green, and blue (RGB) components of the specified color.27322733A 3-tuple is returned, containing the R, G, B values for the given color,2734which will be between 0 (no component) and 1000 (maximum amount of component).2735[clinic start generated code]*/27362737static PyObject *2738_curses_color_content_impl(PyObject *module, int color_number)2739/*[clinic end generated code: output=17b466df7054e0de input=03b5ed0472662aea]*/2740{2741_CURSES_COLOR_VAL_TYPE r,g,b;27422743PyCursesInitialised;2744PyCursesInitialisedColor;27452746if (_COLOR_CONTENT_FUNC(color_number, &r, &g, &b) == ERR) {2747PyErr_Format(PyCursesError, "%s() returned ERR",2748Py_STRINGIFY(_COLOR_CONTENT_FUNC));2749return NULL;2750}27512752return Py_BuildValue("(iii)", r, g, b);2753}27542755/*[clinic input]2756_curses.color_pair27572758pair_number: int2759The number of the color pair.2760/27612762Return the attribute value for displaying text in the specified color.27632764This attribute value can be combined with A_STANDOUT, A_REVERSE, and the2765other A_* attributes. pair_number() is the counterpart to this function.2766[clinic start generated code]*/27672768static PyObject *2769_curses_color_pair_impl(PyObject *module, int pair_number)2770/*[clinic end generated code: output=60718abb10ce9feb input=6034e9146f343802]*/2771{2772PyCursesInitialised;2773PyCursesInitialisedColor;27742775return PyLong_FromLong(COLOR_PAIR(pair_number));2776}27772778/*[clinic input]2779_curses.curs_set27802781visibility: int27820 for invisible, 1 for normal visible, or 2 for very visible.2783/27842785Set the cursor state.27862787If the terminal supports the visibility requested, the previous cursor2788state is returned; otherwise, an exception is raised. On many terminals,2789the "visible" mode is an underline cursor and the "very visible" mode is2790a block cursor.2791[clinic start generated code]*/27922793static PyObject *2794_curses_curs_set_impl(PyObject *module, int visibility)2795/*[clinic end generated code: output=ee8e62483b1d6cd4 input=81a7924a65d29504]*/2796{2797int erg;27982799PyCursesInitialised;28002801erg = curs_set(visibility);2802if (erg == ERR) return PyCursesCheckERR(erg, "curs_set");28032804return PyLong_FromLong((long) erg);2805}28062807/*[clinic input]2808_curses.def_prog_mode28092810Save the current terminal mode as the "program" mode.28112812The "program" mode is the mode when the running program is using curses.28132814Subsequent calls to reset_prog_mode() will restore this mode.2815[clinic start generated code]*/28162817static PyObject *2818_curses_def_prog_mode_impl(PyObject *module)2819/*[clinic end generated code: output=05d5a351fff874aa input=768b9cace620dda5]*/2820NoArgNoReturnFunctionBody(def_prog_mode)28212822/*[clinic input]2823_curses.def_shell_mode28242825Save the current terminal mode as the "shell" mode.28262827The "shell" mode is the mode when the running program is not using curses.28282829Subsequent calls to reset_shell_mode() will restore this mode.2830[clinic start generated code]*/28312832static PyObject *2833_curses_def_shell_mode_impl(PyObject *module)2834/*[clinic end generated code: output=d6e42f5c768f860f input=5ead21f6f0baa894]*/2835NoArgNoReturnFunctionBody(def_shell_mode)28362837/*[clinic input]2838_curses.delay_output28392840ms: int2841Duration in milliseconds.2842/28432844Insert a pause in output.2845[clinic start generated code]*/28462847static PyObject *2848_curses_delay_output_impl(PyObject *module, int ms)2849/*[clinic end generated code: output=b6613a67f17fa4f4 input=5316457f5f59196c]*/2850{2851PyCursesInitialised;28522853return PyCursesCheckERR(delay_output(ms), "delay_output");2854}28552856/*[clinic input]2857_curses.doupdate28582859Update the physical screen to match the virtual screen.2860[clinic start generated code]*/28612862static PyObject *2863_curses_doupdate_impl(PyObject *module)2864/*[clinic end generated code: output=f34536975a75680c input=8da80914432a6489]*/2865NoArgNoReturnFunctionBody(doupdate)28662867/*[clinic input]2868_curses.echo28692870flag: bool = True2871If false, the effect is the same as calling noecho().2872/28732874Enter echo mode.28752876In echo mode, each character input is echoed to the screen as it is entered.2877[clinic start generated code]*/28782879static PyObject *2880_curses_echo_impl(PyObject *module, int flag)2881/*[clinic end generated code: output=03acb2ddfa6c8729 input=86cd4d5bb1d569c0]*/2882NoArgOrFlagNoReturnFunctionBody(echo, flag)28832884/*[clinic input]2885_curses.endwin28862887De-initialize the library, and return terminal to normal status.2888[clinic start generated code]*/28892890static PyObject *2891_curses_endwin_impl(PyObject *module)2892/*[clinic end generated code: output=c0150cd96d2f4128 input=e172cfa43062f3fa]*/2893NoArgNoReturnFunctionBody(endwin)28942895/*[clinic input]2896_curses.erasechar28972898Return the user's current erase character.2899[clinic start generated code]*/29002901static PyObject *2902_curses_erasechar_impl(PyObject *module)2903/*[clinic end generated code: output=3df305dc6b926b3f input=628c136c3c5758d3]*/2904{2905char ch;29062907PyCursesInitialised;29082909ch = erasechar();29102911return PyBytes_FromStringAndSize(&ch, 1);2912}29132914/*[clinic input]2915_curses.flash29162917Flash the screen.29182919That is, change it to reverse-video and then change it back in a short interval.2920[clinic start generated code]*/29212922static PyObject *2923_curses_flash_impl(PyObject *module)2924/*[clinic end generated code: output=488b8a0ebd9ea9b8 input=02fdfb06c8fc3171]*/2925NoArgNoReturnFunctionBody(flash)29262927/*[clinic input]2928_curses.flushinp29292930Flush all input buffers.29312932This throws away any typeahead that has been typed by the user and has not2933yet been processed by the program.2934[clinic start generated code]*/29352936static PyObject *2937_curses_flushinp_impl(PyObject *module)2938/*[clinic end generated code: output=7e7a1fc1473960f5 input=59d042e705cef5ec]*/2939NoArgNoReturnVoidFunctionBody(flushinp)29402941#ifdef getsyx2942/*[clinic input]2943_curses.getsyx29442945Return the current coordinates of the virtual screen cursor.29462947Return a (y, x) tuple. If leaveok is currently true, return (-1, -1).2948[clinic start generated code]*/29492950static PyObject *2951_curses_getsyx_impl(PyObject *module)2952/*[clinic end generated code: output=c8e6c3f42349a038 input=9e1f862f3b4f7cba]*/2953{2954int x = 0;2955int y = 0;29562957PyCursesInitialised;29582959getsyx(y, x);29602961return Py_BuildValue("(ii)", y, x);2962}2963#endif29642965#ifdef NCURSES_MOUSE_VERSION2966/*[clinic input]2967_curses.getmouse29682969Retrieve the queued mouse event.29702971After getch() returns KEY_MOUSE to signal a mouse event, this function2972returns a 5-tuple (id, x, y, z, bstate).2973[clinic start generated code]*/29742975static PyObject *2976_curses_getmouse_impl(PyObject *module)2977/*[clinic end generated code: output=ccf4242546b9cfa8 input=5b756ee6f5b481b1]*/2978{2979int rtn;2980MEVENT event;29812982PyCursesInitialised;29832984rtn = getmouse( &event );2985if (rtn == ERR) {2986PyErr_SetString(PyCursesError, "getmouse() returned ERR");2987return NULL;2988}2989return Py_BuildValue("(hiiik)",2990(short)event.id,2991(int)event.x, (int)event.y, (int)event.z,2992(unsigned long) event.bstate);2993}29942995/*[clinic input]2996_curses.ungetmouse29972998id: short2999x: int3000y: int3001z: int3002bstate: unsigned_long(bitwise=True)3003/30043005Push a KEY_MOUSE event onto the input queue.30063007The following getmouse() will return the given state data.3008[clinic start generated code]*/30093010static PyObject *3011_curses_ungetmouse_impl(PyObject *module, short id, int x, int y, int z,3012unsigned long bstate)3013/*[clinic end generated code: output=3430c9b0fc5c4341 input=fd650b2ca5a01e8f]*/3014{3015MEVENT event;30163017PyCursesInitialised;30183019event.id = id;3020event.x = x;3021event.y = y;3022event.z = z;3023event.bstate = bstate;3024return PyCursesCheckERR(ungetmouse(&event), "ungetmouse");3025}3026#endif30273028/*[clinic input]3029_curses.getwin30303031file: object3032/30333034Read window related data stored in the file by an earlier putwin() call.30353036The routine then creates and initializes a new window using that data,3037returning the new window object.3038[clinic start generated code]*/30393040static PyObject *3041_curses_getwin(PyObject *module, PyObject *file)3042/*[clinic end generated code: output=a79e0df3379af756 input=f713d2bba0e4c929]*/3043{3044FILE *fp;3045PyObject *data;3046size_t datalen;3047WINDOW *win;3048PyObject *res = NULL;30493050PyCursesInitialised;30513052fp = tmpfile();3053if (fp == NULL)3054return PyErr_SetFromErrno(PyExc_OSError);30553056if (_Py_set_inheritable(fileno(fp), 0, NULL) < 0)3057goto error;30583059data = PyObject_CallMethod(file, "read", NULL);3060if (data == NULL)3061goto error;3062if (!PyBytes_Check(data)) {3063PyErr_Format(PyExc_TypeError,3064"f.read() returned %.100s instead of bytes",3065Py_TYPE(data)->tp_name);3066Py_DECREF(data);3067goto error;3068}3069datalen = PyBytes_GET_SIZE(data);3070if (fwrite(PyBytes_AS_STRING(data), 1, datalen, fp) != datalen) {3071Py_DECREF(data);3072PyErr_SetFromErrno(PyExc_OSError);3073goto error;3074}3075Py_DECREF(data);30763077fseek(fp, 0, 0);3078win = getwin(fp);3079if (win == NULL) {3080PyErr_SetString(PyCursesError, catchall_NULL);3081goto error;3082}3083res = PyCursesWindow_New(win, NULL);30843085error:3086fclose(fp);3087return res;3088}30893090/*[clinic input]3091_curses.halfdelay30923093tenths: byte3094Maximal blocking delay in tenths of seconds (1 - 255).3095/30963097Enter half-delay mode.30983099Use nocbreak() to leave half-delay mode.3100[clinic start generated code]*/31013102static PyObject *3103_curses_halfdelay_impl(PyObject *module, unsigned char tenths)3104/*[clinic end generated code: output=e92cdf0ef33c0663 input=e42dce7259c15100]*/3105{3106PyCursesInitialised;31073108return PyCursesCheckERR(halfdelay(tenths), "halfdelay");3109}31103111/*[clinic input]3112_curses.has_colors31133114Return True if the terminal can display colors; otherwise, return False.3115[clinic start generated code]*/31163117static PyObject *3118_curses_has_colors_impl(PyObject *module)3119/*[clinic end generated code: output=db5667483139e3e2 input=b2ec41b739d896c6]*/3120NoArgTrueFalseFunctionBody(has_colors)31213122/*[clinic input]3123_curses.has_ic31243125Return True if the terminal has insert- and delete-character capabilities.3126[clinic start generated code]*/31273128static PyObject *3129_curses_has_ic_impl(PyObject *module)3130/*[clinic end generated code: output=6be24da9cb1268fe input=9bc2d3a797cc7324]*/3131NoArgTrueFalseFunctionBody(has_ic)31323133/*[clinic input]3134_curses.has_il31353136Return True if the terminal has insert- and delete-line capabilities.3137[clinic start generated code]*/31383139static PyObject *3140_curses_has_il_impl(PyObject *module)3141/*[clinic end generated code: output=d45bd7788ff9f5f4 input=cd939d5607ee5427]*/3142NoArgTrueFalseFunctionBody(has_il)31433144#ifdef HAVE_CURSES_HAS_KEY3145/*[clinic input]3146_curses.has_key31473148key: int3149Key number.3150/31513152Return True if the current terminal type recognizes a key with that value.3153[clinic start generated code]*/31543155static PyObject *3156_curses_has_key_impl(PyObject *module, int key)3157/*[clinic end generated code: output=19ad48319414d0b1 input=78bd44acf1a4997c]*/3158{3159PyCursesInitialised;31603161return PyBool_FromLong(has_key(key));3162}3163#endif31643165/*[clinic input]3166_curses.init_color31673168color_number: color3169The number of the color to be changed (0 - (COLORS-1)).3170r: component3171Red component (0 - 1000).3172g: component3173Green component (0 - 1000).3174b: component3175Blue component (0 - 1000).3176/31773178Change the definition of a color.31793180When init_color() is used, all occurrences of that color on the screen3181immediately change to the new definition. This function is a no-op on3182most terminals; it is active only if can_change_color() returns true.3183[clinic start generated code]*/31843185static PyObject *3186_curses_init_color_impl(PyObject *module, int color_number, short r, short g,3187short b)3188/*[clinic end generated code: output=d7ed71b2d818cdf2 input=ae2b8bea0f152c80]*/3189{3190PyCursesInitialised;3191PyCursesInitialisedColor;31923193return PyCursesCheckERR(_CURSES_INIT_COLOR_FUNC(color_number, r, g, b),3194Py_STRINGIFY(_CURSES_INIT_COLOR_FUNC));3195}31963197/*[clinic input]3198_curses.init_pair31993200pair_number: pair3201The number of the color-pair to be changed (1 - (COLOR_PAIRS-1)).3202fg: color_allow_default3203Foreground color number (-1 - (COLORS-1)).3204bg: color_allow_default3205Background color number (-1 - (COLORS-1)).3206/32073208Change the definition of a color-pair.32093210If the color-pair was previously initialized, the screen is refreshed and3211all occurrences of that color-pair are changed to the new definition.3212[clinic start generated code]*/32133214static PyObject *3215_curses_init_pair_impl(PyObject *module, int pair_number, int fg, int bg)3216/*[clinic end generated code: output=a0bba03d2bbc3ee6 input=54b421b44c12c389]*/3217{3218PyCursesInitialised;3219PyCursesInitialisedColor;32203221if (_CURSES_INIT_PAIR_FUNC(pair_number, fg, bg) == ERR) {3222if (pair_number >= COLOR_PAIRS) {3223PyErr_Format(PyExc_ValueError,3224"Color pair is greater than COLOR_PAIRS-1 (%d).",3225COLOR_PAIRS - 1);3226}3227else {3228PyErr_Format(PyCursesError, "%s() returned ERR",3229Py_STRINGIFY(_CURSES_INIT_PAIR_FUNC));3230}3231return NULL;3232}32333234Py_RETURN_NONE;3235}32363237static PyObject *ModDict;32383239/*[clinic input]3240_curses.initscr32413242Initialize the library.32433244Return a WindowObject which represents the whole screen.3245[clinic start generated code]*/32463247static PyObject *3248_curses_initscr_impl(PyObject *module)3249/*[clinic end generated code: output=619fb68443810b7b input=514f4bce1821f6b5]*/3250{3251WINDOW *win;3252PyCursesWindowObject *winobj;32533254if (initialised) {3255wrefresh(stdscr);3256return (PyObject *)PyCursesWindow_New(stdscr, NULL);3257}32583259win = initscr();32603261if (win == NULL) {3262PyErr_SetString(PyCursesError, catchall_NULL);3263return NULL;3264}32653266initialised = initialised_setupterm = TRUE;32673268/* This was moved from initcurses() because it core dumped on SGI,3269where they're not defined until you've called initscr() */3270#define SetDictInt(string,ch) \3271do { \3272PyObject *o = PyLong_FromLong((long) (ch)); \3273if (o && PyDict_SetItemString(ModDict, string, o) == 0) { \3274Py_DECREF(o); \3275} \3276} while (0)32773278/* Here are some graphic symbols you can use */3279SetDictInt("ACS_ULCORNER", (ACS_ULCORNER));3280SetDictInt("ACS_LLCORNER", (ACS_LLCORNER));3281SetDictInt("ACS_URCORNER", (ACS_URCORNER));3282SetDictInt("ACS_LRCORNER", (ACS_LRCORNER));3283SetDictInt("ACS_LTEE", (ACS_LTEE));3284SetDictInt("ACS_RTEE", (ACS_RTEE));3285SetDictInt("ACS_BTEE", (ACS_BTEE));3286SetDictInt("ACS_TTEE", (ACS_TTEE));3287SetDictInt("ACS_HLINE", (ACS_HLINE));3288SetDictInt("ACS_VLINE", (ACS_VLINE));3289SetDictInt("ACS_PLUS", (ACS_PLUS));3290#if !defined(__hpux) || defined(HAVE_NCURSES_H)3291/* On HP/UX 11, these are of type cchar_t, which is not an3292integral type. If this is a problem on more platforms, a3293configure test should be added to determine whether ACS_S13294is of integral type. */3295SetDictInt("ACS_S1", (ACS_S1));3296SetDictInt("ACS_S9", (ACS_S9));3297SetDictInt("ACS_DIAMOND", (ACS_DIAMOND));3298SetDictInt("ACS_CKBOARD", (ACS_CKBOARD));3299SetDictInt("ACS_DEGREE", (ACS_DEGREE));3300SetDictInt("ACS_PLMINUS", (ACS_PLMINUS));3301SetDictInt("ACS_BULLET", (ACS_BULLET));3302SetDictInt("ACS_LARROW", (ACS_LARROW));3303SetDictInt("ACS_RARROW", (ACS_RARROW));3304SetDictInt("ACS_DARROW", (ACS_DARROW));3305SetDictInt("ACS_UARROW", (ACS_UARROW));3306SetDictInt("ACS_BOARD", (ACS_BOARD));3307SetDictInt("ACS_LANTERN", (ACS_LANTERN));3308SetDictInt("ACS_BLOCK", (ACS_BLOCK));3309#endif3310SetDictInt("ACS_BSSB", (ACS_ULCORNER));3311SetDictInt("ACS_SSBB", (ACS_LLCORNER));3312SetDictInt("ACS_BBSS", (ACS_URCORNER));3313SetDictInt("ACS_SBBS", (ACS_LRCORNER));3314SetDictInt("ACS_SBSS", (ACS_RTEE));3315SetDictInt("ACS_SSSB", (ACS_LTEE));3316SetDictInt("ACS_SSBS", (ACS_BTEE));3317SetDictInt("ACS_BSSS", (ACS_TTEE));3318SetDictInt("ACS_BSBS", (ACS_HLINE));3319SetDictInt("ACS_SBSB", (ACS_VLINE));3320SetDictInt("ACS_SSSS", (ACS_PLUS));33213322/* The following are never available with strict SYSV curses */3323#ifdef ACS_S33324SetDictInt("ACS_S3", (ACS_S3));3325#endif3326#ifdef ACS_S73327SetDictInt("ACS_S7", (ACS_S7));3328#endif3329#ifdef ACS_LEQUAL3330SetDictInt("ACS_LEQUAL", (ACS_LEQUAL));3331#endif3332#ifdef ACS_GEQUAL3333SetDictInt("ACS_GEQUAL", (ACS_GEQUAL));3334#endif3335#ifdef ACS_PI3336SetDictInt("ACS_PI", (ACS_PI));3337#endif3338#ifdef ACS_NEQUAL3339SetDictInt("ACS_NEQUAL", (ACS_NEQUAL));3340#endif3341#ifdef ACS_STERLING3342SetDictInt("ACS_STERLING", (ACS_STERLING));3343#endif33443345SetDictInt("LINES", LINES);3346SetDictInt("COLS", COLS);33473348winobj = (PyCursesWindowObject *)PyCursesWindow_New(win, NULL);3349screen_encoding = winobj->encoding;3350return (PyObject *)winobj;3351}33523353/*[clinic input]3354_curses.setupterm33553356term: str(accept={str, NoneType}) = None3357Terminal name.3358If omitted, the value of the TERM environment variable will be used.3359fd: int = -13360File descriptor to which any initialization sequences will be sent.3361If not supplied, the file descriptor for sys.stdout will be used.33623363Initialize the terminal.3364[clinic start generated code]*/33653366static PyObject *3367_curses_setupterm_impl(PyObject *module, const char *term, int fd)3368/*[clinic end generated code: output=4584e587350f2848 input=4511472766af0c12]*/3369{3370int err;33713372if (fd == -1) {3373PyObject* sys_stdout;33743375sys_stdout = PySys_GetObject("stdout");33763377if (sys_stdout == NULL || sys_stdout == Py_None) {3378PyErr_SetString(3379PyCursesError,3380"lost sys.stdout");3381return NULL;3382}33833384fd = PyObject_AsFileDescriptor(sys_stdout);33853386if (fd == -1) {3387return NULL;3388}3389}33903391if (!initialised_setupterm && setupterm((char *)term, fd, &err) == ERR) {3392const char* s = "setupterm: unknown error";33933394if (err == 0) {3395s = "setupterm: could not find terminal";3396} else if (err == -1) {3397s = "setupterm: could not find terminfo database";3398}33993400PyErr_SetString(PyCursesError,s);3401return NULL;3402}34033404initialised_setupterm = TRUE;34053406Py_RETURN_NONE;3407}34083409#if defined(NCURSES_EXT_FUNCS) && NCURSES_EXT_FUNCS >= 200811023410// https://invisible-island.net/ncurses/NEWS.html#index-t2008011934113412/*[clinic input]3413_curses.get_escdelay34143415Gets the curses ESCDELAY setting.34163417Gets the number of milliseconds to wait after reading an escape character,3418to distinguish between an individual escape character entered on the3419keyboard from escape sequences sent by cursor and function keys.3420[clinic start generated code]*/34213422static PyObject *3423_curses_get_escdelay_impl(PyObject *module)3424/*[clinic end generated code: output=222fa1a822555d60 input=be2d5b3dd974d0a4]*/3425{3426return PyLong_FromLong(ESCDELAY);3427}3428/*[clinic input]3429_curses.set_escdelay3430ms: int3431length of the delay in milliseconds.3432/34333434Sets the curses ESCDELAY setting.34353436Sets the number of milliseconds to wait after reading an escape character,3437to distinguish between an individual escape character entered on the3438keyboard from escape sequences sent by cursor and function keys.3439[clinic start generated code]*/34403441static PyObject *3442_curses_set_escdelay_impl(PyObject *module, int ms)3443/*[clinic end generated code: output=43818efbf7980ac4 input=7796fe19f111e250]*/3444{3445if (ms <= 0) {3446PyErr_SetString(PyExc_ValueError, "ms must be > 0");3447return NULL;3448}34493450return PyCursesCheckERR(set_escdelay(ms), "set_escdelay");3451}34523453/*[clinic input]3454_curses.get_tabsize34553456Gets the curses TABSIZE setting.34573458Gets the number of columns used by the curses library when converting a tab3459character to spaces as it adds the tab to a window.3460[clinic start generated code]*/34613462static PyObject *3463_curses_get_tabsize_impl(PyObject *module)3464/*[clinic end generated code: output=7e9e51fb6126fbdf input=74af86bf6c9f5d7e]*/3465{3466return PyLong_FromLong(TABSIZE);3467}3468/*[clinic input]3469_curses.set_tabsize3470size: int3471rendered cell width of a tab character.3472/34733474Sets the curses TABSIZE setting.34753476Sets the number of columns used by the curses library when converting a tab3477character to spaces as it adds the tab to a window.3478[clinic start generated code]*/34793480static PyObject *3481_curses_set_tabsize_impl(PyObject *module, int size)3482/*[clinic end generated code: output=c1de5a76c0daab1e input=78cba6a3021ad061]*/3483{3484if (size <= 0) {3485PyErr_SetString(PyExc_ValueError, "size must be > 0");3486return NULL;3487}34883489return PyCursesCheckERR(set_tabsize(size), "set_tabsize");3490}3491#endif34923493/*[clinic input]3494_curses.intrflush34953496flag: bool3497/34983499[clinic start generated code]*/35003501static PyObject *3502_curses_intrflush_impl(PyObject *module, int flag)3503/*[clinic end generated code: output=c1986df35e999a0f input=c65fe2ef973fe40a]*/3504{3505PyCursesInitialised;35063507return PyCursesCheckERR(intrflush(NULL, flag), "intrflush");3508}35093510/*[clinic input]3511_curses.isendwin35123513Return True if endwin() has been called.3514[clinic start generated code]*/35153516static PyObject *3517_curses_isendwin_impl(PyObject *module)3518/*[clinic end generated code: output=d73179e4a7e1eb8c input=6cdb01a7ebf71397]*/3519NoArgTrueFalseFunctionBody(isendwin)35203521#ifdef HAVE_CURSES_IS_TERM_RESIZED3522/*[clinic input]3523_curses.is_term_resized35243525nlines: int3526Height.3527ncols: int3528Width.3529/35303531Return True if resize_term() would modify the window structure, False otherwise.3532[clinic start generated code]*/35333534static PyObject *3535_curses_is_term_resized_impl(PyObject *module, int nlines, int ncols)3536/*[clinic end generated code: output=aafe04afe50f1288 input=ca9c0bd0fb8ab444]*/3537{3538PyCursesInitialised;35393540return PyBool_FromLong(is_term_resized(nlines, ncols));3541}3542#endif /* HAVE_CURSES_IS_TERM_RESIZED */35433544/*[clinic input]3545_curses.keyname35463547key: int3548Key number.3549/35503551Return the name of specified key.3552[clinic start generated code]*/35533554static PyObject *3555_curses_keyname_impl(PyObject *module, int key)3556/*[clinic end generated code: output=fa2675ab3f4e056b input=ee4b1d0f243a2a2b]*/3557{3558const char *knp;35593560PyCursesInitialised;35613562if (key < 0) {3563PyErr_SetString(PyExc_ValueError, "invalid key number");3564return NULL;3565}3566knp = keyname(key);35673568return PyBytes_FromString((knp == NULL) ? "" : knp);3569}35703571/*[clinic input]3572_curses.killchar35733574Return the user's current line kill character.3575[clinic start generated code]*/35763577static PyObject *3578_curses_killchar_impl(PyObject *module)3579/*[clinic end generated code: output=31c3a45b2c528269 input=1ff171c38df5ccad]*/3580{3581char ch;35823583ch = killchar();35843585return PyBytes_FromStringAndSize(&ch, 1);3586}35873588/*[clinic input]3589_curses.longname35903591Return the terminfo long name field describing the current terminal.35923593The maximum length of a verbose description is 128 characters. It is defined3594only after the call to initscr().3595[clinic start generated code]*/35963597static PyObject *3598_curses_longname_impl(PyObject *module)3599/*[clinic end generated code: output=fdf30433727ef568 input=84c3f20201b1098e]*/3600NoArgReturnStringFunctionBody(longname)36013602/*[clinic input]3603_curses.meta36043605yes: bool3606/36073608Enable/disable meta keys.36093610If yes is True, allow 8-bit characters to be input. If yes is False,3611allow only 7-bit characters.3612[clinic start generated code]*/36133614static PyObject *3615_curses_meta_impl(PyObject *module, int yes)3616/*[clinic end generated code: output=22f5abda46a605d8 input=cfe7da79f51d0e30]*/3617{3618PyCursesInitialised;36193620return PyCursesCheckERR(meta(stdscr, yes), "meta");3621}36223623#ifdef NCURSES_MOUSE_VERSION3624/*[clinic input]3625_curses.mouseinterval36263627interval: int3628Time in milliseconds.3629/36303631Set and retrieve the maximum time between press and release in a click.36323633Set the maximum time that can elapse between press and release events in3634order for them to be recognized as a click, and return the previous interval3635value.3636[clinic start generated code]*/36373638static PyObject *3639_curses_mouseinterval_impl(PyObject *module, int interval)3640/*[clinic end generated code: output=c4f5ff04354634c5 input=75aaa3f0db10ac4e]*/3641{3642PyCursesInitialised;36433644return PyCursesCheckERR(mouseinterval(interval), "mouseinterval");3645}36463647/*[clinic input]3648_curses.mousemask36493650newmask: unsigned_long(bitwise=True)3651/36523653Set the mouse events to be reported, and return a tuple (availmask, oldmask).36543655Return a tuple (availmask, oldmask). availmask indicates which of the3656specified mouse events can be reported; on complete failure it returns 0.3657oldmask is the previous value of the given window's mouse event mask.3658If this function is never called, no mouse events are ever reported.3659[clinic start generated code]*/36603661static PyObject *3662_curses_mousemask_impl(PyObject *module, unsigned long newmask)3663/*[clinic end generated code: output=9406cf1b8a36e485 input=bdf76b7568a3c541]*/3664{3665mmask_t oldmask, availmask;36663667PyCursesInitialised;3668availmask = mousemask((mmask_t)newmask, &oldmask);3669return Py_BuildValue("(kk)",3670(unsigned long)availmask, (unsigned long)oldmask);3671}3672#endif36733674/*[clinic input]3675_curses.napms36763677ms: int3678Duration in milliseconds.3679/36803681Sleep for specified time.3682[clinic start generated code]*/36833684static PyObject *3685_curses_napms_impl(PyObject *module, int ms)3686/*[clinic end generated code: output=a40a1da2e39ea438 input=20cd3af2b6900f56]*/3687{3688PyCursesInitialised;36893690return Py_BuildValue("i", napms(ms));3691}369236933694/*[clinic input]3695_curses.newpad36963697nlines: int3698Height.3699ncols: int3700Width.3701/37023703Create and return a pointer to a new pad data structure.3704[clinic start generated code]*/37053706static PyObject *3707_curses_newpad_impl(PyObject *module, int nlines, int ncols)3708/*[clinic end generated code: output=de52a56eb1098ec9 input=93f1272f240d8894]*/3709{3710WINDOW *win;37113712PyCursesInitialised;37133714win = newpad(nlines, ncols);37153716if (win == NULL) {3717PyErr_SetString(PyCursesError, catchall_NULL);3718return NULL;3719}37203721return (PyObject *)PyCursesWindow_New(win, NULL);3722}37233724/*[clinic input]3725_curses.newwin37263727nlines: int3728Height.3729ncols: int3730Width.3731[3732begin_y: int = 03733Top side y-coordinate.3734begin_x: int = 03735Left side x-coordinate.3736]3737/37383739Return a new window.37403741By default, the window will extend from the specified position to the lower3742right corner of the screen.3743[clinic start generated code]*/37443745static PyObject *3746_curses_newwin_impl(PyObject *module, int nlines, int ncols,3747int group_right_1, int begin_y, int begin_x)3748/*[clinic end generated code: output=c1e0a8dc8ac2826c input=29312c15a72a003d]*/3749{3750WINDOW *win;37513752PyCursesInitialised;37533754win = newwin(nlines,ncols,begin_y,begin_x);3755if (win == NULL) {3756PyErr_SetString(PyCursesError, catchall_NULL);3757return NULL;3758}37593760return (PyObject *)PyCursesWindow_New(win, NULL);3761}37623763/*[clinic input]3764_curses.nl37653766flag: bool = True3767If false, the effect is the same as calling nonl().3768/37693770Enter newline mode.37713772This mode translates the return key into newline on input, and translates3773newline into return and line-feed on output. Newline mode is initially on.3774[clinic start generated code]*/37753776static PyObject *3777_curses_nl_impl(PyObject *module, int flag)3778/*[clinic end generated code: output=b39cc0ffc9015003 input=18e3e9c6e8cfcf6f]*/3779NoArgOrFlagNoReturnFunctionBody(nl, flag)37803781/*[clinic input]3782_curses.nocbreak37833784Leave cbreak mode.37853786Return to normal "cooked" mode with line buffering.3787[clinic start generated code]*/37883789static PyObject *3790_curses_nocbreak_impl(PyObject *module)3791/*[clinic end generated code: output=eabf3833a4fbf620 input=e4b65f7d734af400]*/3792NoArgNoReturnFunctionBody(nocbreak)37933794/*[clinic input]3795_curses.noecho37963797Leave echo mode.37983799Echoing of input characters is turned off.3800[clinic start generated code]*/38013802static PyObject *3803_curses_noecho_impl(PyObject *module)3804/*[clinic end generated code: output=cc95ab45bc98f41b input=76714df529e614c3]*/3805NoArgNoReturnFunctionBody(noecho)38063807/*[clinic input]3808_curses.nonl38093810Leave newline mode.38113812Disable translation of return into newline on input, and disable low-level3813translation of newline into newline/return on output.3814[clinic start generated code]*/38153816static PyObject *3817_curses_nonl_impl(PyObject *module)3818/*[clinic end generated code: output=99e917e9715770c6 input=9d37dd122d3022fc]*/3819NoArgNoReturnFunctionBody(nonl)38203821/*[clinic input]3822_curses.noqiflush38233824Disable queue flushing.38253826When queue flushing is disabled, normal flush of input and output queues3827associated with the INTR, QUIT and SUSP characters will not be done.3828[clinic start generated code]*/38293830static PyObject *3831_curses_noqiflush_impl(PyObject *module)3832/*[clinic end generated code: output=8b95a4229bbf0877 input=ba3e6b2e3e54c4df]*/3833NoArgNoReturnVoidFunctionBody(noqiflush)38343835/*[clinic input]3836_curses.noraw38373838Leave raw mode.38393840Return to normal "cooked" mode with line buffering.3841[clinic start generated code]*/38423843static PyObject *3844_curses_noraw_impl(PyObject *module)3845/*[clinic end generated code: output=39894e5524c430cc input=6ec86692096dffb5]*/3846NoArgNoReturnFunctionBody(noraw)38473848/*[clinic input]3849_curses.pair_content38503851pair_number: pair3852The number of the color pair (0 - (COLOR_PAIRS-1)).3853/38543855Return a tuple (fg, bg) containing the colors for the requested color pair.3856[clinic start generated code]*/38573858static PyObject *3859_curses_pair_content_impl(PyObject *module, int pair_number)3860/*[clinic end generated code: output=4a726dd0e6885f3f input=03970f840fc7b739]*/3861{3862_CURSES_COLOR_NUM_TYPE f, b;38633864PyCursesInitialised;3865PyCursesInitialisedColor;38663867if (_CURSES_PAIR_CONTENT_FUNC(pair_number, &f, &b) == ERR) {3868if (pair_number >= COLOR_PAIRS) {3869PyErr_Format(PyExc_ValueError,3870"Color pair is greater than COLOR_PAIRS-1 (%d).",3871COLOR_PAIRS - 1);3872}3873else {3874PyErr_Format(PyCursesError, "%s() returned ERR",3875Py_STRINGIFY(_CURSES_PAIR_CONTENT_FUNC));3876}3877return NULL;3878}38793880return Py_BuildValue("(ii)", f, b);3881}38823883/*[clinic input]3884_curses.pair_number38853886attr: int3887/38883889Return the number of the color-pair set by the specified attribute value.38903891color_pair() is the counterpart to this function.3892[clinic start generated code]*/38933894static PyObject *3895_curses_pair_number_impl(PyObject *module, int attr)3896/*[clinic end generated code: output=85bce7d65c0aa3f4 input=d478548e33f5e61a]*/3897{3898PyCursesInitialised;3899PyCursesInitialisedColor;39003901return PyLong_FromLong(PAIR_NUMBER(attr));3902}39033904/*[clinic input]3905_curses.putp39063907string: str(accept={robuffer})3908/39093910Emit the value of a specified terminfo capability for the current terminal.39113912Note that the output of putp() always goes to standard output.3913[clinic start generated code]*/39143915static PyObject *3916_curses_putp_impl(PyObject *module, const char *string)3917/*[clinic end generated code: output=e98081d1b8eb5816 input=1601faa828b44cb3]*/3918{3919return PyCursesCheckERR(putp(string), "putp");3920}39213922/*[clinic input]3923_curses.qiflush39243925flag: bool = True3926If false, the effect is the same as calling noqiflush().3927/39283929Enable queue flushing.39303931If queue flushing is enabled, all output in the display driver queue3932will be flushed when the INTR, QUIT and SUSP characters are read.3933[clinic start generated code]*/39343935static PyObject *3936_curses_qiflush_impl(PyObject *module, int flag)3937/*[clinic end generated code: output=9167e862f760ea30 input=6ec8b3e2b717ec40]*/3938{3939PyCursesInitialised;39403941if (flag) {3942qiflush();3943}3944else {3945noqiflush();3946}3947Py_RETURN_NONE;3948}39493950/* Internal helper used for updating curses.LINES, curses.COLS, _curses.LINES3951* and _curses.COLS */3952#if defined(HAVE_CURSES_RESIZETERM) || defined(HAVE_CURSES_RESIZE_TERM)3953static int3954update_lines_cols(void)3955{3956PyObject *o;3957PyObject *m = PyImport_ImportModule("curses");39583959if (!m)3960return 0;39613962o = PyLong_FromLong(LINES);3963if (!o) {3964Py_DECREF(m);3965return 0;3966}3967if (PyObject_SetAttrString(m, "LINES", o)) {3968Py_DECREF(m);3969Py_DECREF(o);3970return 0;3971}3972if (PyDict_SetItemString(ModDict, "LINES", o)) {3973Py_DECREF(m);3974Py_DECREF(o);3975return 0;3976}3977Py_DECREF(o);3978o = PyLong_FromLong(COLS);3979if (!o) {3980Py_DECREF(m);3981return 0;3982}3983if (PyObject_SetAttrString(m, "COLS", o)) {3984Py_DECREF(m);3985Py_DECREF(o);3986return 0;3987}3988if (PyDict_SetItemString(ModDict, "COLS", o)) {3989Py_DECREF(m);3990Py_DECREF(o);3991return 0;3992}3993Py_DECREF(o);3994Py_DECREF(m);3995return 1;3996}39973998/*[clinic input]3999_curses.update_lines_cols40004001[clinic start generated code]*/40024003static PyObject *4004_curses_update_lines_cols_impl(PyObject *module)4005/*[clinic end generated code: output=423f2b1e63ed0f75 input=5f065ab7a28a5d90]*/4006{4007if (!update_lines_cols()) {4008return NULL;4009}4010Py_RETURN_NONE;4011}40124013#endif40144015/*[clinic input]4016_curses.raw40174018flag: bool = True4019If false, the effect is the same as calling noraw().4020/40214022Enter raw mode.40234024In raw mode, normal line buffering and processing of interrupt, quit,4025suspend, and flow control keys are turned off; characters are presented to4026curses input functions one by one.4027[clinic start generated code]*/40284029static PyObject *4030_curses_raw_impl(PyObject *module, int flag)4031/*[clinic end generated code: output=a750e4b342be015b input=4b447701389fb4df]*/4032NoArgOrFlagNoReturnFunctionBody(raw, flag)40334034/*[clinic input]4035_curses.reset_prog_mode40364037Restore the terminal to "program" mode, as previously saved by def_prog_mode().4038[clinic start generated code]*/40394040static PyObject *4041_curses_reset_prog_mode_impl(PyObject *module)4042/*[clinic end generated code: output=15eb765abf0b6575 input=3d82bea2b3243471]*/4043NoArgNoReturnFunctionBody(reset_prog_mode)40444045/*[clinic input]4046_curses.reset_shell_mode40474048Restore the terminal to "shell" mode, as previously saved by def_shell_mode().4049[clinic start generated code]*/40504051static PyObject *4052_curses_reset_shell_mode_impl(PyObject *module)4053/*[clinic end generated code: output=0238de2962090d33 input=1c738fa64bd1a24f]*/4054NoArgNoReturnFunctionBody(reset_shell_mode)40554056/*[clinic input]4057_curses.resetty40584059Restore terminal mode.4060[clinic start generated code]*/40614062static PyObject *4063_curses_resetty_impl(PyObject *module)4064/*[clinic end generated code: output=ff4b448e80a7cd63 input=940493de03624bb0]*/4065NoArgNoReturnFunctionBody(resetty)40664067#ifdef HAVE_CURSES_RESIZETERM4068/*[clinic input]4069_curses.resizeterm40704071nlines: int4072Height.4073ncols: int4074Width.4075/40764077Resize the standard and current windows to the specified dimensions.40784079Adjusts other bookkeeping data used by the curses library that record the4080window dimensions (in particular the SIGWINCH handler).4081[clinic start generated code]*/40824083static PyObject *4084_curses_resizeterm_impl(PyObject *module, int nlines, int ncols)4085/*[clinic end generated code: output=56d6bcc5194ad055 input=0fca02ebad5ffa82]*/4086{4087PyObject *result;40884089PyCursesInitialised;40904091result = PyCursesCheckERR(resizeterm(nlines, ncols), "resizeterm");4092if (!result)4093return NULL;4094if (!update_lines_cols()) {4095Py_DECREF(result);4096return NULL;4097}4098return result;4099}41004101#endif41024103#ifdef HAVE_CURSES_RESIZE_TERM4104/*[clinic input]4105_curses.resize_term41064107nlines: int4108Height.4109ncols: int4110Width.4111/41124113Backend function used by resizeterm(), performing most of the work.41144115When resizing the windows, resize_term() blank-fills the areas that are4116extended. The calling application should fill in these areas with appropriate4117data. The resize_term() function attempts to resize all windows. However,4118due to the calling convention of pads, it is not possible to resize these4119without additional interaction with the application.4120[clinic start generated code]*/41214122static PyObject *4123_curses_resize_term_impl(PyObject *module, int nlines, int ncols)4124/*[clinic end generated code: output=9e26d8b9ea311ed2 input=2197edd05b049ed4]*/4125{4126PyObject *result;41274128PyCursesInitialised;41294130result = PyCursesCheckERR(resize_term(nlines, ncols), "resize_term");4131if (!result)4132return NULL;4133if (!update_lines_cols()) {4134Py_DECREF(result);4135return NULL;4136}4137return result;4138}4139#endif /* HAVE_CURSES_RESIZE_TERM */41404141/*[clinic input]4142_curses.savetty41434144Save terminal mode.4145[clinic start generated code]*/41464147static PyObject *4148_curses_savetty_impl(PyObject *module)4149/*[clinic end generated code: output=6babc49f12b42199 input=fce6b2b7d2200102]*/4150NoArgNoReturnFunctionBody(savetty)41514152#ifdef getsyx4153/*[clinic input]4154_curses.setsyx41554156y: int4157Y-coordinate.4158x: int4159X-coordinate.4160/41614162Set the virtual screen cursor.41634164If y and x are both -1, then leaveok is set.4165[clinic start generated code]*/41664167static PyObject *4168_curses_setsyx_impl(PyObject *module, int y, int x)4169/*[clinic end generated code: output=23dcf753511a2464 input=fa7f2b208e10a557]*/4170{4171PyCursesInitialised;41724173setsyx(y,x);41744175Py_RETURN_NONE;4176}4177#endif41784179/*[clinic input]4180_curses.start_color41814182Initializes eight basic colors and global variables COLORS and COLOR_PAIRS.41834184Must be called if the programmer wants to use colors, and before any other4185color manipulation routine is called. It is good practice to call this4186routine right after initscr().41874188It also restores the colors on the terminal to the values they had when the4189terminal was just turned on.4190[clinic start generated code]*/41914192static PyObject *4193_curses_start_color_impl(PyObject *module)4194/*[clinic end generated code: output=8b772b41d8090ede input=0ca0ecb2b77e1a12]*/4195{4196int code;4197PyObject *c, *cp;41984199PyCursesInitialised;42004201code = start_color();4202if (code != ERR) {4203initialisedcolors = TRUE;4204c = PyLong_FromLong((long) COLORS);4205if (c == NULL)4206return NULL;4207if (PyDict_SetItemString(ModDict, "COLORS", c) < 0) {4208Py_DECREF(c);4209return NULL;4210}4211Py_DECREF(c);4212cp = PyLong_FromLong((long) COLOR_PAIRS);4213if (cp == NULL)4214return NULL;4215if (PyDict_SetItemString(ModDict, "COLOR_PAIRS", cp) < 0) {4216Py_DECREF(cp);4217return NULL;4218}4219Py_DECREF(cp);4220Py_RETURN_NONE;4221} else {4222PyErr_SetString(PyCursesError, "start_color() returned ERR");4223return NULL;4224}4225}42264227/*[clinic input]4228_curses.termattrs42294230Return a logical OR of all video attributes supported by the terminal.4231[clinic start generated code]*/42324233static PyObject *4234_curses_termattrs_impl(PyObject *module)4235/*[clinic end generated code: output=b06f437fce1b6fc4 input=0559882a04f84d1d]*/4236NoArgReturnIntFunctionBody(termattrs)42374238/*[clinic input]4239_curses.termname42404241Return the value of the environment variable TERM, truncated to 14 characters.4242[clinic start generated code]*/42434244static PyObject *4245_curses_termname_impl(PyObject *module)4246/*[clinic end generated code: output=96375577ebbd67fd input=33c08d000944f33f]*/4247NoArgReturnStringFunctionBody(termname)42484249/*[clinic input]4250_curses.tigetflag42514252capname: str4253The terminfo capability name.4254/42554256Return the value of the Boolean capability.42574258The value -1 is returned if capname is not a Boolean capability, or 0 if4259it is canceled or absent from the terminal description.4260[clinic start generated code]*/42614262static PyObject *4263_curses_tigetflag_impl(PyObject *module, const char *capname)4264/*[clinic end generated code: output=8853c0e55542195b input=b0787af9e3e9a6ce]*/4265{4266PyCursesSetupTermCalled;42674268return PyLong_FromLong( (long) tigetflag( (char *)capname ) );4269}42704271/*[clinic input]4272_curses.tigetnum42734274capname: str4275The terminfo capability name.4276/42774278Return the value of the numeric capability.42794280The value -2 is returned if capname is not a numeric capability, or -1 if4281it is canceled or absent from the terminal description.4282[clinic start generated code]*/42834284static PyObject *4285_curses_tigetnum_impl(PyObject *module, const char *capname)4286/*[clinic end generated code: output=46f8b0a1b5dff42f input=5cdf2f410b109720]*/4287{4288PyCursesSetupTermCalled;42894290return PyLong_FromLong( (long) tigetnum( (char *)capname ) );4291}42924293/*[clinic input]4294_curses.tigetstr42954296capname: str4297The terminfo capability name.4298/42994300Return the value of the string capability.43014302None is returned if capname is not a string capability, or is canceled or4303absent from the terminal description.4304[clinic start generated code]*/43054306static PyObject *4307_curses_tigetstr_impl(PyObject *module, const char *capname)4308/*[clinic end generated code: output=f22b576ad60248f3 input=36644df25c73c0a7]*/4309{4310PyCursesSetupTermCalled;43114312capname = tigetstr( (char *)capname );4313if (capname == NULL || capname == (char*) -1) {4314Py_RETURN_NONE;4315}4316return PyBytes_FromString( capname );4317}43184319/*[clinic input]4320_curses.tparm43214322str: str(accept={robuffer})4323Parameterized byte string obtained from the terminfo database.4324i1: int = 04325i2: int = 04326i3: int = 04327i4: int = 04328i5: int = 04329i6: int = 04330i7: int = 04331i8: int = 04332i9: int = 04333/43344335Instantiate the specified byte string with the supplied parameters.4336[clinic start generated code]*/43374338static PyObject *4339_curses_tparm_impl(PyObject *module, const char *str, int i1, int i2, int i3,4340int i4, int i5, int i6, int i7, int i8, int i9)4341/*[clinic end generated code: output=599f62b615c667ff input=5e30b15786f032aa]*/4342{4343char* result = NULL;43444345PyCursesSetupTermCalled;43464347result = tparm((char *)str,i1,i2,i3,i4,i5,i6,i7,i8,i9);4348if (!result) {4349PyErr_SetString(PyCursesError, "tparm() returned NULL");4350return NULL;4351}43524353return PyBytes_FromString(result);4354}43554356#ifdef HAVE_CURSES_TYPEAHEAD4357/*[clinic input]4358_curses.typeahead43594360fd: int4361File descriptor.4362/43634364Specify that the file descriptor fd be used for typeahead checking.43654366If fd is -1, then no typeahead checking is done.4367[clinic start generated code]*/43684369static PyObject *4370_curses_typeahead_impl(PyObject *module, int fd)4371/*[clinic end generated code: output=084bb649d7066583 input=f2968d8e1805051b]*/4372{4373PyCursesInitialised;43744375return PyCursesCheckERR(typeahead( fd ), "typeahead");4376}4377#endif43784379/*[clinic input]4380_curses.unctrl43814382ch: object4383/43844385Return a string which is a printable representation of the character ch.43864387Control characters are displayed as a caret followed by the character,4388for example as ^C. Printing characters are left as they are.4389[clinic start generated code]*/43904391static PyObject *4392_curses_unctrl(PyObject *module, PyObject *ch)4393/*[clinic end generated code: output=8e07fafc430c9434 input=cd1e35e16cd1ace4]*/4394{4395chtype ch_;43964397PyCursesInitialised;43984399if (!PyCurses_ConvertToChtype(NULL, ch, &ch_))4400return NULL;44014402return PyBytes_FromString(unctrl(ch_));4403}44044405/*[clinic input]4406_curses.ungetch44074408ch: object4409/44104411Push ch so the next getch() will return it.4412[clinic start generated code]*/44134414static PyObject *4415_curses_ungetch(PyObject *module, PyObject *ch)4416/*[clinic end generated code: output=9b19d8268376d887 input=6681e6ae4c42e5eb]*/4417{4418chtype ch_;44194420PyCursesInitialised;44214422if (!PyCurses_ConvertToChtype(NULL, ch, &ch_))4423return NULL;44244425return PyCursesCheckERR(ungetch(ch_), "ungetch");4426}44274428#ifdef HAVE_NCURSESW4429/* Convert an object to a character (wchar_t):44304431- int4432- str of length 144334434Return 1 on success, 0 on error. */4435static int4436PyCurses_ConvertToWchar_t(PyObject *obj,4437wchar_t *wch)4438{4439if (PyUnicode_Check(obj)) {4440wchar_t buffer[2];4441if (PyUnicode_AsWideChar(obj, buffer, 2) != 1) {4442PyErr_Format(PyExc_TypeError,4443"expect str of length 1 or int, "4444"got a str of length %zi",4445PyUnicode_GET_LENGTH(obj));4446return 0;4447}4448*wch = buffer[0];4449return 2;4450}4451else if (PyLong_CheckExact(obj)) {4452long value;4453int overflow;4454value = PyLong_AsLongAndOverflow(obj, &overflow);4455if (overflow) {4456PyErr_SetString(PyExc_OverflowError,4457"int doesn't fit in long");4458return 0;4459}4460*wch = (wchar_t)value;4461if ((long)*wch != value) {4462PyErr_Format(PyExc_OverflowError,4463"character doesn't fit in wchar_t");4464return 0;4465}4466return 1;4467}4468else {4469PyErr_Format(PyExc_TypeError,4470"expect str of length 1 or int, got %s",4471Py_TYPE(obj)->tp_name);4472return 0;4473}4474}44754476/*[clinic input]4477_curses.unget_wch44784479ch: object4480/44814482Push ch so the next get_wch() will return it.4483[clinic start generated code]*/44844485static PyObject *4486_curses_unget_wch(PyObject *module, PyObject *ch)4487/*[clinic end generated code: output=1974c9fb01d37863 input=0d56dc65a46feebb]*/4488{4489wchar_t wch;44904491PyCursesInitialised;44924493if (!PyCurses_ConvertToWchar_t(ch, &wch))4494return NULL;4495return PyCursesCheckERR(unget_wch(wch), "unget_wch");4496}4497#endif44984499#ifdef HAVE_CURSES_USE_ENV4500/*[clinic input]4501_curses.use_env45024503flag: bool4504/45054506Use environment variables LINES and COLUMNS.45074508If used, this function should be called before initscr() or newterm() are4509called.45104511When flag is False, the values of lines and columns specified in the terminfo4512database will be used, even if environment variables LINES and COLUMNS (used4513by default) are set, or if curses is running in a window (in which case4514default behavior would be to use the window size if LINES and COLUMNS are4515not set).4516[clinic start generated code]*/45174518static PyObject *4519_curses_use_env_impl(PyObject *module, int flag)4520/*[clinic end generated code: output=b2c445e435c0b164 input=06ac30948f2d78e4]*/4521{4522use_env(flag);4523Py_RETURN_NONE;4524}4525#endif45264527#ifndef STRICT_SYSV_CURSES4528/*[clinic input]4529_curses.use_default_colors45304531Allow use of default values for colors on terminals supporting this feature.45324533Use this to support transparency in your application. The default color4534is assigned to the color number -1.4535[clinic start generated code]*/45364537static PyObject *4538_curses_use_default_colors_impl(PyObject *module)4539/*[clinic end generated code: output=a3b81ff71dd901be input=656844367470e8fc]*/4540{4541int code;45424543PyCursesInitialised;4544PyCursesInitialisedColor;45454546code = use_default_colors();4547if (code != ERR) {4548Py_RETURN_NONE;4549} else {4550PyErr_SetString(PyCursesError, "use_default_colors() returned ERR");4551return NULL;4552}4553}4554#endif /* STRICT_SYSV_CURSES */455545564557#ifdef NCURSES_VERSION45584559PyDoc_STRVAR(ncurses_version__doc__,4560"curses.ncurses_version\n\4561\n\4562Ncurses version information as a named tuple.");45634564static PyStructSequence_Field ncurses_version_fields[] = {4565{"major", "Major release number"},4566{"minor", "Minor release number"},4567{"patch", "Patch release number"},4568{0}4569};45704571static PyStructSequence_Desc ncurses_version_desc = {4572"curses.ncurses_version", /* name */4573ncurses_version__doc__, /* doc */4574ncurses_version_fields, /* fields */457534576};45774578static PyObject *4579make_ncurses_version(PyTypeObject *type)4580{4581PyObject *ncurses_version;4582int pos = 0;45834584ncurses_version = PyStructSequence_New(type);4585if (ncurses_version == NULL) {4586return NULL;4587}45884589#define SetIntItem(flag) \4590PyStructSequence_SET_ITEM(ncurses_version, pos++, PyLong_FromLong(flag)); \4591if (PyErr_Occurred()) { \4592Py_CLEAR(ncurses_version); \4593return NULL; \4594}45954596SetIntItem(NCURSES_VERSION_MAJOR)4597SetIntItem(NCURSES_VERSION_MINOR)4598SetIntItem(NCURSES_VERSION_PATCH)4599#undef SetIntItem46004601return ncurses_version;4602}46034604#endif /* NCURSES_VERSION */46054606/*[clinic input]4607_curses.has_extended_color_support46084609Return True if the module supports extended colors; otherwise, return False.46104611Extended color support allows more than 256 color-pairs for terminals4612that support more than 16 colors (e.g. xterm-256color).4613[clinic start generated code]*/46144615static PyObject *4616_curses_has_extended_color_support_impl(PyObject *module)4617/*[clinic end generated code: output=68f1be2b57d92e22 input=4b905f046e35ee9f]*/4618{4619return PyBool_FromLong(_NCURSES_EXTENDED_COLOR_FUNCS);4620}46214622/* List of functions defined in the module */46234624static PyMethodDef PyCurses_methods[] = {4625_CURSES_BAUDRATE_METHODDEF4626_CURSES_BEEP_METHODDEF4627_CURSES_CAN_CHANGE_COLOR_METHODDEF4628_CURSES_CBREAK_METHODDEF4629_CURSES_COLOR_CONTENT_METHODDEF4630_CURSES_COLOR_PAIR_METHODDEF4631_CURSES_CURS_SET_METHODDEF4632_CURSES_DEF_PROG_MODE_METHODDEF4633_CURSES_DEF_SHELL_MODE_METHODDEF4634_CURSES_DELAY_OUTPUT_METHODDEF4635_CURSES_DOUPDATE_METHODDEF4636_CURSES_ECHO_METHODDEF4637_CURSES_ENDWIN_METHODDEF4638_CURSES_ERASECHAR_METHODDEF4639_CURSES_FILTER_METHODDEF4640_CURSES_FLASH_METHODDEF4641_CURSES_FLUSHINP_METHODDEF4642_CURSES_GETMOUSE_METHODDEF4643_CURSES_UNGETMOUSE_METHODDEF4644_CURSES_GETSYX_METHODDEF4645_CURSES_GETWIN_METHODDEF4646_CURSES_HAS_COLORS_METHODDEF4647_CURSES_HAS_EXTENDED_COLOR_SUPPORT_METHODDEF4648_CURSES_HAS_IC_METHODDEF4649_CURSES_HAS_IL_METHODDEF4650_CURSES_HAS_KEY_METHODDEF4651_CURSES_HALFDELAY_METHODDEF4652_CURSES_INIT_COLOR_METHODDEF4653_CURSES_INIT_PAIR_METHODDEF4654_CURSES_INITSCR_METHODDEF4655_CURSES_INTRFLUSH_METHODDEF4656_CURSES_ISENDWIN_METHODDEF4657_CURSES_IS_TERM_RESIZED_METHODDEF4658_CURSES_KEYNAME_METHODDEF4659_CURSES_KILLCHAR_METHODDEF4660_CURSES_LONGNAME_METHODDEF4661_CURSES_META_METHODDEF4662_CURSES_MOUSEINTERVAL_METHODDEF4663_CURSES_MOUSEMASK_METHODDEF4664_CURSES_NAPMS_METHODDEF4665_CURSES_NEWPAD_METHODDEF4666_CURSES_NEWWIN_METHODDEF4667_CURSES_NL_METHODDEF4668_CURSES_NOCBREAK_METHODDEF4669_CURSES_NOECHO_METHODDEF4670_CURSES_NONL_METHODDEF4671_CURSES_NOQIFLUSH_METHODDEF4672_CURSES_NORAW_METHODDEF4673_CURSES_PAIR_CONTENT_METHODDEF4674_CURSES_PAIR_NUMBER_METHODDEF4675_CURSES_PUTP_METHODDEF4676_CURSES_QIFLUSH_METHODDEF4677_CURSES_RAW_METHODDEF4678_CURSES_RESET_PROG_MODE_METHODDEF4679_CURSES_RESET_SHELL_MODE_METHODDEF4680_CURSES_RESETTY_METHODDEF4681_CURSES_RESIZETERM_METHODDEF4682_CURSES_RESIZE_TERM_METHODDEF4683_CURSES_SAVETTY_METHODDEF4684#if defined(NCURSES_EXT_FUNCS) && NCURSES_EXT_FUNCS >= 200811024685_CURSES_GET_ESCDELAY_METHODDEF4686_CURSES_SET_ESCDELAY_METHODDEF4687#endif4688_CURSES_GET_TABSIZE_METHODDEF4689_CURSES_SET_TABSIZE_METHODDEF4690_CURSES_SETSYX_METHODDEF4691_CURSES_SETUPTERM_METHODDEF4692_CURSES_START_COLOR_METHODDEF4693_CURSES_TERMATTRS_METHODDEF4694_CURSES_TERMNAME_METHODDEF4695_CURSES_TIGETFLAG_METHODDEF4696_CURSES_TIGETNUM_METHODDEF4697_CURSES_TIGETSTR_METHODDEF4698_CURSES_TPARM_METHODDEF4699_CURSES_TYPEAHEAD_METHODDEF4700_CURSES_UNCTRL_METHODDEF4701_CURSES_UNGETCH_METHODDEF4702_CURSES_UPDATE_LINES_COLS_METHODDEF4703_CURSES_UNGET_WCH_METHODDEF4704_CURSES_USE_ENV_METHODDEF4705_CURSES_USE_DEFAULT_COLORS_METHODDEF4706{NULL, NULL} /* sentinel */4707};47084709/* Initialization function for the module */471047114712static struct PyModuleDef _cursesmodule = {4713PyModuleDef_HEAD_INIT,4714"_curses",4715NULL,4716-1,4717PyCurses_methods,4718NULL,4719NULL,4720NULL,4721NULL4722};47234724static void4725curses_destructor(PyObject *op)4726{4727void *ptr = PyCapsule_GetPointer(op, PyCurses_CAPSULE_NAME);4728Py_DECREF(*(void **)ptr);4729PyMem_Free(ptr);4730}47314732PyMODINIT_FUNC4733PyInit__curses(void)4734{4735PyObject *m, *d, *v, *c_api_object;47364737/* Initialize object type */4738if (PyType_Ready(&PyCursesWindow_Type) < 0)4739return NULL;47404741/* Create the module and add the functions */4742m = PyModule_Create(&_cursesmodule);4743if (m == NULL)4744return NULL;47454746/* Add some symbolic constants to the module */4747d = PyModule_GetDict(m);4748if (d == NULL)4749return NULL;4750ModDict = d; /* For PyCurses_InitScr to use later */47514752void **PyCurses_API = PyMem_Calloc(PyCurses_API_pointers, sizeof(void *));4753if (PyCurses_API == NULL) {4754PyErr_NoMemory();4755return NULL;4756}4757/* Initialize the C API pointer array */4758PyCurses_API[0] = (void *)Py_NewRef(&PyCursesWindow_Type);4759PyCurses_API[1] = (void *)func_PyCursesSetupTermCalled;4760PyCurses_API[2] = (void *)func_PyCursesInitialised;4761PyCurses_API[3] = (void *)func_PyCursesInitialisedColor;47624763/* Add a capsule for the C API */4764c_api_object = PyCapsule_New(PyCurses_API, PyCurses_CAPSULE_NAME,4765curses_destructor);4766if (c_api_object == NULL) {4767Py_DECREF(PyCurses_API[0]);4768PyMem_Free(PyCurses_API);4769return NULL;4770}4771if (PyDict_SetItemString(d, "_C_API", c_api_object) < 0) {4772Py_DECREF(c_api_object);4773return NULL;4774}4775Py_DECREF(c_api_object);47764777/* For exception curses.error */4778PyCursesError = PyErr_NewException("_curses.error", NULL, NULL);4779PyDict_SetItemString(d, "error", PyCursesError);47804781/* Make the version available */4782v = PyBytes_FromString(PyCursesVersion);4783PyDict_SetItemString(d, "version", v);4784PyDict_SetItemString(d, "__version__", v);4785Py_DECREF(v);47864787#ifdef NCURSES_VERSION4788/* ncurses_version */4789PyTypeObject *version_type;4790version_type = _PyStructSequence_NewType(&ncurses_version_desc,4791Py_TPFLAGS_DISALLOW_INSTANTIATION);4792if (version_type == NULL) {4793return NULL;4794}4795v = make_ncurses_version(version_type);4796Py_DECREF(version_type);4797if (v == NULL) {4798return NULL;4799}4800PyDict_SetItemString(d, "ncurses_version", v);4801Py_DECREF(v);4802#endif /* NCURSES_VERSION */48034804SetDictInt("ERR", ERR);4805SetDictInt("OK", OK);48064807/* Here are some attributes you can add to chars to print */48084809SetDictInt("A_ATTRIBUTES", A_ATTRIBUTES);4810SetDictInt("A_NORMAL", A_NORMAL);4811SetDictInt("A_STANDOUT", A_STANDOUT);4812SetDictInt("A_UNDERLINE", A_UNDERLINE);4813SetDictInt("A_REVERSE", A_REVERSE);4814SetDictInt("A_BLINK", A_BLINK);4815SetDictInt("A_DIM", A_DIM);4816SetDictInt("A_BOLD", A_BOLD);4817SetDictInt("A_ALTCHARSET", A_ALTCHARSET);4818SetDictInt("A_INVIS", A_INVIS);4819SetDictInt("A_PROTECT", A_PROTECT);4820SetDictInt("A_CHARTEXT", A_CHARTEXT);4821SetDictInt("A_COLOR", A_COLOR);48224823/* The following are never available with strict SYSV curses */4824#ifdef A_HORIZONTAL4825SetDictInt("A_HORIZONTAL", A_HORIZONTAL);4826#endif4827#ifdef A_LEFT4828SetDictInt("A_LEFT", A_LEFT);4829#endif4830#ifdef A_LOW4831SetDictInt("A_LOW", A_LOW);4832#endif4833#ifdef A_RIGHT4834SetDictInt("A_RIGHT", A_RIGHT);4835#endif4836#ifdef A_TOP4837SetDictInt("A_TOP", A_TOP);4838#endif4839#ifdef A_VERTICAL4840SetDictInt("A_VERTICAL", A_VERTICAL);4841#endif48424843/* ncurses extension */4844#ifdef A_ITALIC4845SetDictInt("A_ITALIC", A_ITALIC);4846#endif48474848SetDictInt("COLOR_BLACK", COLOR_BLACK);4849SetDictInt("COLOR_RED", COLOR_RED);4850SetDictInt("COLOR_GREEN", COLOR_GREEN);4851SetDictInt("COLOR_YELLOW", COLOR_YELLOW);4852SetDictInt("COLOR_BLUE", COLOR_BLUE);4853SetDictInt("COLOR_MAGENTA", COLOR_MAGENTA);4854SetDictInt("COLOR_CYAN", COLOR_CYAN);4855SetDictInt("COLOR_WHITE", COLOR_WHITE);48564857#ifdef NCURSES_MOUSE_VERSION4858/* Mouse-related constants */4859SetDictInt("BUTTON1_PRESSED", BUTTON1_PRESSED);4860SetDictInt("BUTTON1_RELEASED", BUTTON1_RELEASED);4861SetDictInt("BUTTON1_CLICKED", BUTTON1_CLICKED);4862SetDictInt("BUTTON1_DOUBLE_CLICKED", BUTTON1_DOUBLE_CLICKED);4863SetDictInt("BUTTON1_TRIPLE_CLICKED", BUTTON1_TRIPLE_CLICKED);48644865SetDictInt("BUTTON2_PRESSED", BUTTON2_PRESSED);4866SetDictInt("BUTTON2_RELEASED", BUTTON2_RELEASED);4867SetDictInt("BUTTON2_CLICKED", BUTTON2_CLICKED);4868SetDictInt("BUTTON2_DOUBLE_CLICKED", BUTTON2_DOUBLE_CLICKED);4869SetDictInt("BUTTON2_TRIPLE_CLICKED", BUTTON2_TRIPLE_CLICKED);48704871SetDictInt("BUTTON3_PRESSED", BUTTON3_PRESSED);4872SetDictInt("BUTTON3_RELEASED", BUTTON3_RELEASED);4873SetDictInt("BUTTON3_CLICKED", BUTTON3_CLICKED);4874SetDictInt("BUTTON3_DOUBLE_CLICKED", BUTTON3_DOUBLE_CLICKED);4875SetDictInt("BUTTON3_TRIPLE_CLICKED", BUTTON3_TRIPLE_CLICKED);48764877SetDictInt("BUTTON4_PRESSED", BUTTON4_PRESSED);4878SetDictInt("BUTTON4_RELEASED", BUTTON4_RELEASED);4879SetDictInt("BUTTON4_CLICKED", BUTTON4_CLICKED);4880SetDictInt("BUTTON4_DOUBLE_CLICKED", BUTTON4_DOUBLE_CLICKED);4881SetDictInt("BUTTON4_TRIPLE_CLICKED", BUTTON4_TRIPLE_CLICKED);48824883#if NCURSES_MOUSE_VERSION > 14884SetDictInt("BUTTON5_PRESSED", BUTTON5_PRESSED);4885SetDictInt("BUTTON5_RELEASED", BUTTON5_RELEASED);4886SetDictInt("BUTTON5_CLICKED", BUTTON5_CLICKED);4887SetDictInt("BUTTON5_DOUBLE_CLICKED", BUTTON5_DOUBLE_CLICKED);4888SetDictInt("BUTTON5_TRIPLE_CLICKED", BUTTON5_TRIPLE_CLICKED);4889#endif48904891SetDictInt("BUTTON_SHIFT", BUTTON_SHIFT);4892SetDictInt("BUTTON_CTRL", BUTTON_CTRL);4893SetDictInt("BUTTON_ALT", BUTTON_ALT);48944895SetDictInt("ALL_MOUSE_EVENTS", ALL_MOUSE_EVENTS);4896SetDictInt("REPORT_MOUSE_POSITION", REPORT_MOUSE_POSITION);4897#endif4898/* Now set everything up for KEY_ variables */4899{4900int key;4901char *key_n;4902char *key_n2;4903for (key=KEY_MIN;key < KEY_MAX; key++) {4904key_n = (char *)keyname(key);4905if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0)4906continue;4907if (strncmp(key_n,"KEY_F(",6)==0) {4908char *p1, *p2;4909key_n2 = PyMem_Malloc(strlen(key_n)+1);4910if (!key_n2) {4911PyErr_NoMemory();4912break;4913}4914p1 = key_n;4915p2 = key_n2;4916while (*p1) {4917if (*p1 != '(' && *p1 != ')') {4918*p2 = *p1;4919p2++;4920}4921p1++;4922}4923*p2 = (char)0;4924} else4925key_n2 = key_n;4926SetDictInt(key_n2,key);4927if (key_n2 != key_n)4928PyMem_Free(key_n2);4929}4930SetDictInt("KEY_MIN", KEY_MIN);4931SetDictInt("KEY_MAX", KEY_MAX);4932}49334934if (PyModule_AddType(m, &PyCursesWindow_Type) < 0) {4935return NULL;4936}4937return m;4938}493949404941