GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — cpython/Modules/_cursesmodule.c at 3.13 · python/cpython Expand file tree/ Copy path_cursesmodule.cMore file actions 5255 lines (4395 loc) · 146 KB / Copy path_cursesmodule.cFile metadata and controls5255 lines (4395 loc) · 146 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 /* * This is a curses module for Python. * * Based on prior work by Lance Ellinghaus and Oliver Andrich * Version 1.2 of this module: Copyright 1994 by Lance Ellinghouse, * Cathedral City, California Republic, United States of America. * * Version 1.5b1, heavily extended for ncurses by Oliver Andrich: * Copyright 1996,1997 by Oliver Andrich, Koblenz, Germany. * * Tidied for Python 1.6, and currently maintained by <[email protected]>. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this source file to use, copy, modify, merge, or publish it * subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or in any new file that contains a substantial portion of * this file. * * THE AUTHOR MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF * THE SOFTWARE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT * EXPRESS OR IMPLIED WARRANTY. THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NON-INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE * AUTHOR BE LIABLE TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL, * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE, STRICT LIABILITY OR * ANY OTHER ACTION ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. */ /* A number of SysV or ncurses functions don't have wrappers yet; if you need a given function, add it and send a patch. See https://www.python.org/dev/patches/ for instructions on how to submit patches to Python. Here's a list of currently unsupported functions: addchnstr addchstr color_set define_key del_curterm delscreen dupwin inchnstr inchstr innstr keyok mcprint mvaddchnstr mvaddchstr mvcur mvinchnstr mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr mvwinchnstr mvwinchstr mvwinnstr newterm restartterm ripoffline scr_dump scr_init scr_restore scr_set scrl set_curterm set_term setterm tgetent tgetflag tgetnum tgetstr tgoto timeout tputs vidattr vidputs waddchnstr waddchstr wcolor_set winchnstr winchstr winnstr wmouse_trafo wscrl Low-priority: slk_attr slk_attr_off slk_attr_on slk_attr_set slk_attroff slk_attron slk_attrset slk_clear slk_color slk_init slk_label slk_noutrefresh slk_refresh slk_restore slk_set slk_touch Menu extension (ncurses and probably SYSV): current_item free_item free_menu item_count item_description item_index item_init item_name item_opts item_opts_off item_opts_on item_term item_userptr item_value item_visible menu_back menu_driver menu_fore menu_format menu_grey menu_init menu_items menu_mark menu_opts menu_opts_off menu_opts_on menu_pad menu_pattern menu_request_by_name menu_request_name menu_spacing menu_sub menu_term menu_userptr menu_win new_item new_menu pos_menu_cursor post_menu scale_menu set_current_item set_item_init set_item_opts set_item_term set_item_userptr set_item_value set_menu_back set_menu_fore set_menu_format set_menu_grey set_menu_init set_menu_items set_menu_mark set_menu_opts set_menu_pad set_menu_pattern set_menu_spacing set_menu_sub set_menu_term set_menu_userptr set_menu_win set_top_row top_row unpost_menu Form extension (ncurses and probably SYSV): current_field data_ahead data_behind dup_field dynamic_fieldinfo field_arg field_back field_buffer field_count field_fore field_index field_info field_init field_just field_opts field_opts_off field_opts_on field_pad field_status field_term field_type field_userptr form_driver form_fields form_init form_opts form_opts_off form_opts_on form_page form_request_by_name form_request_name form_sub form_term form_userptr form_win free_field free_form link_field link_fieldtype move_field new_field new_form new_page pos_form_cursor post_form scale_form set_current_field set_field_back set_field_buffer set_field_fore set_field_init set_field_just set_field_opts set_field_pad set_field_status set_field_term set_field_type set_field_userptr set_fieldtype_arg set_fieldtype_choice set_form_fields set_form_init set_form_opts set_form_page set_form_sub set_form_term set_form_userptr set_form_win set_max_field set_new_page unpost_form */ /* Release Number */ static const char PyCursesVersion[] = "2.2"; /* Includes */ #ifndef Py_BUILD_CORE_BUILTIN # define Py_BUILD_CORE_MODULE 1 #endif #include "Python.h" #include "pycore_long.h" // _PyLong_GetZero() #include "pycore_structseq.h" // _PyStructSequence_NewType() #include "pycore_sysmodule.h" // _PySys_GetOptionalAttrString() #ifdef __hpux #define STRICT_SYSV_CURSES #endif #define CURSES_MODULE #include "py_curses.h" #if defined(HAVE_TERM_H) || defined(__sgi) /* For termname, longname, putp, tigetflag, tigetnum, tigetstr, tparm which are not declared in SysV curses and for setupterm. */ #include <term.h> /* Including <term.h> #defines many common symbols. */ #undef lines #undef columns #endif #ifdef HAVE_LANGINFO_H #include <langinfo.h> #endif #if !defined(NCURSES_VERSION) && (defined(sgi) || defined(__sun) || defined(SCO5)) #define STRICT_SYSV_CURSES /* Don't use ncurses extensions */ typedef chtype attr_t; /* No attr_t type is available */ #endif #if defined(_AIX) #define STRICT_SYSV_CURSES #endif #if defined(HAVE_NCURSESW) && NCURSES_EXT_FUNCS+0 >= 20170401 && NCURSES_EXT_COLORS+0 >= 20170401 #define _NCURSES_EXTENDED_COLOR_FUNCS 1 #else #define _NCURSES_EXTENDED_COLOR_FUNCS 0 #endif #if _NCURSES_EXTENDED_COLOR_FUNCS #define _CURSES_COLOR_VAL_TYPE int #define _CURSES_COLOR_NUM_TYPE int #define _CURSES_INIT_COLOR_FUNC init_extended_color #define _CURSES_INIT_PAIR_FUNC init_extended_pair #define _COLOR_CONTENT_FUNC extended_color_content #define _CURSES_PAIR_CONTENT_FUNC extended_pair_content #else #define _CURSES_COLOR_VAL_TYPE short #define _CURSES_COLOR_NUM_TYPE short #define _CURSES_INIT_COLOR_FUNC init_color #define _CURSES_INIT_PAIR_FUNC init_pair #define _COLOR_CONTENT_FUNC color_content #define _CURSES_PAIR_CONTENT_FUNC pair_content #endif /* _NCURSES_EXTENDED_COLOR_FUNCS */ /*[clinic input] module _curses class _curses.window "PyCursesWindowObject *" "&PyCursesWindow_Type" [clinic start generated code]*/ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=43265c372c2887d6]*/ /* Definition of exception curses.error */ static PyObject *PyCursesError; /* Tells whether setupterm() has been called to initialise terminfo. */ static int initialised_setupterm = FALSE; /* Tells whether initscr() has been called to initialise curses. */ static int initialised = FALSE; /* Tells whether start_color() has been called to initialise color usage. */ static int initialisedcolors = FALSE; /* Encoding of the initial screen, used by module-level functions that have no window object to take it from (e.g. unctrl(), ungetch()). This is a private copy: the window object that initscr() returns may be deallocated while these functions are still in use. */ static char *screen_encoding = NULL; /* ncurses and PDCurses store n characters and add a terminator; NetBSD curses counts the terminator in n. Ask an unknown library for one more. */ #if defined(NCURSES_VERSION) || defined(PDCURSES) # define CURSES_STR_EXTRA 0 #else # define CURSES_STR_EXTRA 1 #endif /* Utility Macros */ #define PyCursesSetupTermCalled \ if (initialised_setupterm != TRUE) { \ PyErr_SetString(PyCursesError, \ "must call (at least) setupterm() first"); \ return 0; } #define PyCursesInitialised \ if (initialised != TRUE) { \ PyErr_SetString(PyCursesError, \ "must call initscr() first"); \ return 0; } #define PyCursesInitialisedColor \ if (initialisedcolors != TRUE) { \ PyErr_SetString(PyCursesError, \ "must call start_color() first"); \ return 0; } /* Utility Functions */ /* * Check the return code from a curses function and return None * or raise an exception as appropriate. These are exported using the * capsule API. */ static PyObject * PyCursesCheckERR(int code, const char *fname) { if (code != ERR) { Py_RETURN_NONE; } else { if (fname == NULL) { PyErr_SetString(PyCursesError, catchall_ERR); } else { PyErr_Format(PyCursesError, "%s() returned ERR", fname); } return NULL; } } /* Convert an object to a byte (an integer of type chtype): - int - bytes of length 1 - str of length 1 Return 1 on success, 0 on error (invalid type or integer overflow). */ static int PyCurses_ConvertToChtype(PyCursesWindowObject *win, PyObject *obj, chtype *ch) { long value; if(PyBytes_Check(obj) && PyBytes_Size(obj) == 1) { value = (unsigned char)PyBytes_AsString(obj)[0]; } else if (PyUnicode_Check(obj)) { if (PyUnicode_GetLength(obj) != 1) { PyErr_Format(PyExc_TypeError, "expect bytes or str of length 1, or int, " "got a str of length %zi", PyUnicode_GET_LENGTH(obj)); return 0; } value = PyUnicode_READ_CHAR(obj, 0); if (128 < value) { PyObject *bytes; const char *encoding; if (win) encoding = win->encoding; else encoding = screen_encoding; bytes = PyUnicode_AsEncodedString(obj, encoding, NULL); if (bytes == NULL) return 0; if (PyBytes_GET_SIZE(bytes) == 1) value = (unsigned char)PyBytes_AS_STRING(bytes)[0]; else value = -1; Py_DECREF(bytes); if (value < 0) goto overflow; } } else if (PyLong_CheckExact(obj)) { int long_overflow; value = PyLong_AsLongAndOverflow(obj, &long_overflow); if (long_overflow) goto overflow; } else { PyErr_Format(PyExc_TypeError, "expect bytes or str of length 1, or int, got %s", Py_TYPE(obj)->tp_name); return 0; } *ch = (chtype)value; if ((long)*ch != value) goto overflow; return 1; overflow: PyErr_SetString(PyExc_OverflowError, "byte doesn't fit in chtype"); return 0; } /* Convert an object to a byte (chtype) or a character (cchar_t): - int - bytes of length 1 - str of length 1 Return: - 2 if obj is a character (written into *wch) - 1 if obj is a byte (written into *ch) - 0 on error: raise an exception */ static int PyCurses_ConvertToCchar_t(PyCursesWindowObject *win, PyObject *obj, chtype *ch #ifdef HAVE_NCURSESW , wchar_t *wch #endif ) { long value; #ifdef HAVE_NCURSESW wchar_t buffer[2]; #endif if (PyUnicode_Check(obj)) { #ifdef HAVE_NCURSESW if (PyUnicode_AsWideChar(obj, buffer, 2) != 1) { PyErr_Format(PyExc_TypeError, "expect bytes or str of length 1, or int, " "got a str of length %zi", PyUnicode_GET_LENGTH(obj)); return 0; } *wch = buffer[0]; return 2; #else return PyCurses_ConvertToChtype(win, obj, ch); #endif } else if(PyBytes_Check(obj) && PyBytes_Size(obj) == 1) { value = (unsigned char)PyBytes_AsString(obj)[0]; } else if (PyLong_CheckExact(obj)) { int overflow; value = PyLong_AsLongAndOverflow(obj, &overflow); if (overflow) { PyErr_SetString(PyExc_OverflowError, "int doesn't fit in long"); return 0; } } else { PyErr_Format(PyExc_TypeError, "expect bytes or str of length 1, or int, got %s", Py_TYPE(obj)->tp_name); return 0; } *ch = (chtype)value; if ((long)*ch != value) { PyErr_Format(PyExc_OverflowError, "byte doesn't fit in chtype"); return 0; } return 1; } /* Convert an object to a byte string (char*) or a wide character string (wchar_t*). Return: - 2 if obj is a character string (written into *wch) - 1 if obj is a byte string (written into *bytes) - 0 on error: raise an exception */ static int PyCurses_ConvertToString(PyCursesWindowObject *win, PyObject *obj, PyObject **bytes, wchar_t **wstr) { char *str; if (PyUnicode_Check(obj)) { #ifdef HAVE_NCURSESW assert (wstr != NULL); *wstr = PyUnicode_AsWideCharString(obj, NULL); if (*wstr == NULL) return 0; return 2; #else assert (wstr == NULL); *bytes = PyUnicode_AsEncodedString(obj, win->encoding, NULL); if (*bytes == NULL) return 0; /* check for embedded null bytes */ if (PyBytes_AsStringAndSize(*bytes, &str, NULL) < 0) { Py_CLEAR(*bytes); return 0; } return 1; #endif } else if (PyBytes_Check(obj)) { *bytes = Py_NewRef(obj); /* check for embedded null bytes */ if (PyBytes_AsStringAndSize(*bytes, &str, NULL) < 0) { Py_DECREF(obj); return 0; } return 1; } PyErr_Format(PyExc_TypeError, "expect bytes or str, got %s", Py_TYPE(obj)->tp_name); return 0; } static int color_allow_default_converter(PyObject *arg, void *ptr) { long color_number; int overflow; color_number = PyLong_AsLongAndOverflow(arg, &overflow); if (color_number == -1 && PyErr_Occurred()) return 0; if (overflow > 0 || color_number >= COLORS) { PyErr_Format(PyExc_ValueError, "Color number is greater than COLORS-1 (%d).", COLORS - 1); return 0; } else if (overflow < 0 || color_number < 0) { color_number = -1; } *(int *)ptr = (int)color_number; return 1; } static int color_converter(PyObject *arg, void *ptr) { if (!color_allow_default_converter(arg, ptr)) { return 0; } if (*(int *)ptr < 0) { PyErr_SetString(PyExc_ValueError, "Color number is less than 0."); return 0; } return 1; } /*[python input] class color_converter(CConverter): type = 'int' converter = 'color_converter' [python start generated code]*/ /*[python end generated code: output=da39a3ee5e6b4b0d input=4260d2b6e66b3709]*/ /*[python input] class color_allow_default_converter(CConverter): type = 'int' converter = 'color_allow_default_converter' [python start generated code]*/ /*[python end generated code: output=da39a3ee5e6b4b0d input=975602bc058a872d]*/ static int pair_converter(PyObject *arg, void *ptr) { long pair_number; int overflow; pair_number = PyLong_AsLongAndOverflow(arg, &overflow); if (pair_number == -1 && PyErr_Occurred()) return 0; #if _NCURSES_EXTENDED_COLOR_FUNCS if (overflow > 0 || pair_number > INT_MAX) { PyErr_Format(PyExc_ValueError, "Color pair is greater than maximum (%d).", INT_MAX); return 0; } #else if (overflow > 0 || pair_number >= COLOR_PAIRS) { PyErr_Format(PyExc_ValueError, "Color pair is greater than COLOR_PAIRS-1 (%d).", COLOR_PAIRS - 1); return 0; } #endif else if (overflow < 0 || pair_number < 0) { PyErr_SetString(PyExc_ValueError, "Color pair is less than 0."); return 0; } *(int *)ptr = (int)pair_number; return 1; } /*[python input] class pair_converter(CConverter): type = 'int' converter = 'pair_converter' [python start generated code]*/ /*[python end generated code: output=da39a3ee5e6b4b0d input=1a918ae6a1b32af7]*/ static int component_converter(PyObject *arg, void *ptr) { long component; int overflow; component = PyLong_AsLongAndOverflow(arg, &overflow); if (component == -1 && PyErr_Occurred()) return 0; if (overflow > 0 || component > 1000) { PyErr_SetString(PyExc_ValueError, "Color component is greater than 1000"); return 0; } else if (overflow < 0 || component < 0) { PyErr_SetString(PyExc_ValueError, "Color component is less than 0"); return 0; } *(short *)ptr = (short)component; return 1; } /*[python input] class component_converter(CConverter): type = 'short' converter = 'component_converter' [python start generated code]*/ /*[python end generated code: output=da39a3ee5e6b4b0d input=38e9be01d33927fb]*/ /* Function versions of the 3 functions for testing whether curses has been initialised or not. */ static int func_PyCursesSetupTermCalled(void) { PyCursesSetupTermCalled; return 1; } static int func_PyCursesInitialised(void) { PyCursesInitialised; return 1; } static int func_PyCursesInitialisedColor(void) { PyCursesInitialisedColor; return 1; } /***************************************************************************** The Window Object ******************************************************************************/ /* Definition of the window type */ PyTypeObject PyCursesWindow_Type; /* Function prototype macros for Window object X - function name TYPE - parameter Type ERGSTR - format string for construction of the return value PARSESTR - format string for argument parsing */ #define Window_NoArgNoReturnFunction(X) \ static PyObject *PyCursesWindow_ ## X \ (PyCursesWindowObject *self, PyObject *Py_UNUSED(ignored)) \ { return PyCursesCheckERR(X(self->win), # X); } #define Window_NoArgTrueFalseFunction(X) \ static PyObject * PyCursesWindow_ ## X \ (PyCursesWindowObject *self, PyObject *Py_UNUSED(ignored)) \ { \ return PyBool_FromLong(X(self->win)); } #define Window_NoArgNoReturnVoidFunction(X) \ static PyObject * PyCursesWindow_ ## X \ (PyCursesWindowObject *self, PyObject *Py_UNUSED(ignored)) \ { \ X(self->win); Py_RETURN_NONE; } #define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR) \ static PyObject * PyCursesWindow_ ## X \ (PyCursesWindowObject *self, PyObject *Py_UNUSED(ignored)) \ { \ TYPE arg1, arg2; \ X(self->win,arg1,arg2); return Py_BuildValue(ERGSTR, arg1, arg2); } #define Window_OneArgNoReturnVoidFunction(X, TYPE, PARSESTR) \ static PyObject * PyCursesWindow_ ## X \ (PyCursesWindowObject *self, PyObject *args) \ { \ TYPE arg1; \ if (!PyArg_ParseTuple(args, PARSESTR, &arg1)) return NULL; \ X(self->win,arg1); Py_RETURN_NONE; } #define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR) \ static PyObject * PyCursesWindow_ ## X \ (PyCursesWindowObject *self, PyObject *args) \ { \ TYPE arg1; \ if (!PyArg_ParseTuple(args,PARSESTR, &arg1)) return NULL; \ return PyCursesCheckERR(X(self->win, arg1), # X); } #define Window_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \ static PyObject * PyCursesWindow_ ## X \ (PyCursesWindowObject *self, PyObject *args) \ { \ TYPE arg1, arg2; \ if (!PyArg_ParseTuple(args,PARSESTR, &arg1, &arg2)) return NULL; \ return PyCursesCheckERR(X(self->win, arg1, arg2), # X); } /* ------------- WINDOW routines --------------- */ Window_NoArgNoReturnFunction(untouchwin) Window_NoArgNoReturnFunction(touchwin) Window_NoArgNoReturnFunction(redrawwin) Window_NoArgNoReturnFunction(winsertln) Window_NoArgNoReturnFunction(werase) Window_NoArgNoReturnFunction(wdeleteln) Window_NoArgTrueFalseFunction(is_wintouched) Window_NoArgNoReturnVoidFunction(wsyncup) Window_NoArgNoReturnVoidFunction(wsyncdown) Window_NoArgNoReturnVoidFunction(wstandend) Window_NoArgNoReturnVoidFunction(wstandout) Window_NoArgNoReturnVoidFunction(wcursyncup) Window_NoArgNoReturnVoidFunction(wclrtoeol) Window_NoArgNoReturnVoidFunction(wclrtobot) Window_NoArgNoReturnVoidFunction(wclear) Window_OneArgNoReturnVoidFunction(idcok, int, "i;True(1) or False(0)") #ifdef HAVE_CURSES_IMMEDOK Window_OneArgNoReturnVoidFunction(immedok, int, "i;True(1) or False(0)") #endif Window_OneArgNoReturnVoidFunction(wtimeout, int, "i;delay") Window_NoArg2TupleReturnFunction(getyx, int, "ii") Window_NoArg2TupleReturnFunction(getbegyx, int, "ii") Window_NoArg2TupleReturnFunction(getmaxyx, int, "ii") Window_NoArg2TupleReturnFunction(getparyx, int, "ii") Window_OneArgNoReturnFunction(clearok, int, "i;True(1) or False(0)") Window_OneArgNoReturnFunction(idlok, int, "i;True(1) or False(0)") Window_OneArgNoReturnFunction(keypad, int, "i;True(1) or False(0)") Window_OneArgNoReturnFunction(leaveok, int, "i;True(1) or False(0)") Window_OneArgNoReturnFunction(nodelay, int, "i;True(1) or False(0)") Window_OneArgNoReturnFunction(notimeout, int, "i;True(1) or False(0)") Window_OneArgNoReturnFunction(scrollok, int, "i;True(1) or False(0)") Window_OneArgNoReturnFunction(winsdelln, int, "i;nlines") #ifdef HAVE_CURSES_SYNCOK Window_OneArgNoReturnFunction(syncok, int, "i;True(1) or False(0)") #endif Window_TwoArgNoReturnFunction(mvwin, int, "ii;y,x") Window_TwoArgNoReturnFunction(mvderwin, int, "ii;y,x") Window_TwoArgNoReturnFunction(wmove, int, "ii;y,x") #ifndef STRICT_SYSV_CURSES Window_TwoArgNoReturnFunction(wresize, int, "ii;lines,columns") #endif /* Allocation and deallocation of Window Objects */ static PyObject * PyCursesWindow_New(WINDOW *win, const char *encoding, PyCursesWindowObject *orig) { PyCursesWindowObject *wo; if (encoding == NULL) { #if defined(MS_WINDOWS) char buffer[100]; UINT cp; cp = GetConsoleOutputCP(); if (cp != 0) { PyOS_snprintf(buffer, sizeof(buffer), "cp%u", cp); encoding = buffer; } #elif defined(CODESET) const char *codeset = nl_langinfo(CODESET); if (codeset != NULL && codeset[0] != 0) encoding = codeset; #endif if (encoding == NULL) encoding = "utf-8"; } wo = PyObject_New(PyCursesWindowObject, &PyCursesWindow_Type); if (wo == NULL) return NULL; wo->win = win; wo->encoding = _PyMem_Strdup(encoding); if (wo->encoding == NULL) { Py_DECREF(wo); PyErr_NoMemory(); return NULL; } wo->orig = orig; Py_XINCREF(orig); return (PyObject *)wo; } static void PyCursesWindow_Dealloc(PyCursesWindowObject *wo) { if (wo->win != stdscr) delwin(wo->win); if (wo->encoding != NULL) PyMem_Free(wo->encoding); Py_XDECREF(wo->orig); PyObject_Free(wo); } /* Addch, Addstr, Addnstr */ /*[clinic input] _curses.window.addch [ y: int Y-coordinate. x: int X-coordinate. ] ch: object Character to add. [ attr: long(c_default="A_NORMAL") = _curses.A_NORMAL Attributes for the character. ] / Paint the character. Paint character ch at (y, x) with attributes attr, overwriting any character previously painted at that location. By default, the character position and attributes are the current settings for the window object. [clinic start generated code]*/ static PyObject * _curses_window_addch_impl(PyCursesWindowObject *self, int group_left_1, int y, int x, PyObject *ch, int group_right_1, long attr) /*[clinic end generated code: output=00f4c37af3378f45 input=95ce131578458196]*/ { int coordinates_group = group_left_1; int rtn; int type; chtype cch = 0; #ifdef HAVE_NCURSESW wchar_t wstr[2]; cchar_t wcval; #endif const char *funcname; #ifdef HAVE_NCURSESW type = PyCurses_ConvertToCchar_t(self, ch, &cch, wstr); if (type == 2) { funcname = "add_wch"; wstr[1] = L'\0'; setcchar(&wcval, wstr, attr, PAIR_NUMBER(attr), NULL); if (coordinates_group) rtn = mvwadd_wch(self->win,y,x, &wcval); else { rtn = wadd_wch(self->win, &wcval); } } else #else type = PyCurses_ConvertToCchar_t(self, ch, &cch); #endif if (type == 1) { funcname = "addch"; if (coordinates_group) rtn = mvwaddch(self->win,y,x, cch | (attr_t) attr); else { rtn = waddch(self->win, cch | (attr_t) attr); } } else { return NULL; } return PyCursesCheckERR(rtn, funcname); } /*[clinic input] _curses.window.addstr [ y: int Y-coordinate. x: int X-coordinate. ] str: object String to add. [ attr: long Attributes for characters. ] / Paint the string. Paint the string str at (y, x) with attributes attr, overwriting anything previously on the display. By default, the character position and attributes are the current settings for the window object. [clinic start generated code]*/ static PyObject * _curses_window_addstr_impl(PyCursesWindowObject *self, int group_left_1, int y, int x, PyObject *str, int group_right_1, long attr) /*[clinic end generated code: output=65a928ea85ff3115 input=ff6cbb91448a22a3]*/ { int rtn; int strtype; PyObject *bytesobj = NULL; #ifdef HAVE_NCURSESW wchar_t *wstr = NULL; #endif attr_t attr_old = A_NORMAL; int use_xy = group_left_1, use_attr = group_right_1; const char *funcname; #ifdef HAVE_NCURSESW strtype = PyCurses_ConvertToString(self, str, &bytesobj, &wstr); #else strtype = PyCurses_ConvertToString(self, str, &bytesobj, NULL); #endif if (strtype == 0) { return NULL; } if (use_attr) { attr_old = getattrs(self->win); (void)wattrset(self->win,attr); } #ifdef HAVE_NCURSESW if (strtype == 2) { funcname = "addwstr"; if (use_xy) rtn = mvwaddwstr(self->win,y,x,wstr); else rtn = waddwstr(self->win,wstr); PyMem_Free(wstr); } else #endif { const char *str = PyBytes_AS_STRING(bytesobj); funcname = "addstr"; if (use_xy) rtn = mvwaddstr(self->win,y,x,str); else rtn = waddstr(self->win,str); Py_DECREF(bytesobj); } if (use_attr) (void)wattrset(self->win,attr_old); return PyCursesCheckERR(rtn, funcname); } /*[clinic input] _curses.window.addnstr [ y: int Y-coordinate. x: int X-coordinate. ] str: object String to add. n: int Maximal number of characters. [ attr: long Attributes for characters. ] / Paint at most n characters of the string. Paint at most n characters of the string str at (y, x) with attributes attr, overwriting anything previously on the display. By default, the character position and attributes are the current settings for the window object. [clinic start generated code]*/ static PyObject * _curses_window_addnstr_impl(PyCursesWindowObject *self, int group_left_1, int y, int x, PyObject *str, int n, int group_right_1, long attr) /*[clinic end generated code: output=6d21cee2ce6876d9 input=72718415c2744a2a]*/ { int rtn; int strtype; PyObject *bytesobj = NULL; #ifdef HAVE_NCURSESW wchar_t *wstr = NULL; #endif attr_t attr_old = A_NORMAL; int use_xy = group_left_1, use_attr = group_right_1; const char *funcname; #ifdef HAVE_NCURSESW strtype = PyCurses_ConvertToString(self, str, &bytesobj, &wstr); #else strtype = PyCurses_ConvertToString(self, str, &bytesobj, NULL); #endif if (strtype == 0) return NULL; if (use_attr) { attr_old = getattrs(self->win); (void)wattrset(self->win,attr); } #ifdef HAVE_NCURSESW if (strtype == 2) { funcname = "addnwstr"; if (use_xy) rtn = mvwaddnwstr(self->win,y,x,wstr,n); else rtn = waddnwstr(self->win,wstr,n); PyMem_Free(wstr); } else #endif { const char *str = PyBytes_AS_STRING(bytesobj); funcname = "addnstr"; if (use_xy) rtn = mvwaddnstr(self->win,y,x,str,n); else rtn = waddnstr(self->win,str,n); Py_DECREF(bytesobj); } if (use_attr) (void)wattrset(self->win,attr_old); return PyCursesCheckERR(rtn, funcname); } /*[clinic input] _curses.window.bkgd ch: object Background character. attr: long(c_default="A_NORMAL") = _curses.A_NORMAL Background attributes. / Set the background property of the window. [clinic start generated code]*/ static PyObject * _curses_window_bkgd_impl(PyCursesWindowObject *self, PyObject *ch, long attr) /*[clinic end generated code: output=058290afb2cf4034 input=634015bcb339283d]*/ { chtype bkgd; if (!PyCurses_ConvertToChtype(self, ch, &bkgd)) return NULL; return PyCursesCheckERR(wbkgd(self->win, bkgd | attr), "bkgd"); } /*[clinic input] _curses.window.attroff attr: long / Remove attribute attr from the "background" set. [clinic start generated code]*/ static PyObject * _curses_window_attroff_impl(PyCursesWindowObject *self, long attr) |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |