├── .gitignore ├── INSTALL.rst ├── LICENSE.rst ├── MANIFEST.in ├── Makefile ├── README.rst ├── _curses_panel.c ├── _cursesmodule.c ├── curses.h ├── curspriv.h ├── gen ├── distutils.cfg ├── libpython23.a ├── pdcurses-win32a.def ├── pdcurses-win32a.lib ├── pdcurses.def ├── pdcurses.lib ├── setup-win32a.py └── setup.py ├── panel.h ├── setup.py ├── setup.py_template └── term.h /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.pyd 3 | *.so 4 | *.o 5 | *.pyo 6 | *.pye 7 | *~ 8 | *.swp 9 | *.swo 10 | *.swd 11 | *.def 12 | *.dll 13 | *.lib 14 | pdcurses 15 | pdcurses-win32a 16 | -------------------------------------------------------------------------------- /INSTALL.rst: -------------------------------------------------------------------------------- 1 | ******* 2 | Install 3 | ******* 4 | 5 | From source 6 | =========== 7 | 8 | To install from source, please look in the `README.rst`_ file. 9 | 10 | From package 11 | ============ 12 | 13 | **Note: Python 3.0 packages are currently not uploaded due to an issue 14 | with the putwin/getwin functions.** 15 | 16 | If you are unsure what package to install, select the plain ``pdcurses`` 17 | package that matches your version of Python. 18 | 19 | pdcurses 20 | -------- 21 | 22 | On Windows, the following installers are available: 23 | 24 | - `pdcurses-0.3.4.win32-py2.7.exe`_ 25 | - `pdcurses-0.3.4.win32-py2.6.exe`_ 26 | - `pdcurses-0.3.4.win32-py2.5.exe`_ 27 | - `pdcurses-0.3.4.win32-py2.4.exe`_ 28 | - `pdcurses-0.3.4.win32-py2.3.exe`_ 29 | 30 | You can also download the source: 31 | 32 | - `pdcurses-0.3.4.zip`_ 33 | 34 | These contain everything required to use the ``curses`` module on 35 | Windows, including the ``pdcurses.dll`` file. 36 | 37 | pdcurses-win32a 38 | --------------- 39 | 40 | On Windows, the following installers are available: 41 | 42 | - `pdcurses-win32a-0.3.4.win32-py2.7.exe`_ 43 | - `pdcurses-win32a-0.3.4.win32-py2.6.exe`_ 44 | - `pdcurses-win32a-0.3.4.win32-py2.5.exe`_ 45 | - `pdcurses-win32a-0.3.4.win32-py2.4.exe`_ 46 | - `pdcurses-win32a-0.3.4.win32-py2.3.exe`_ 47 | 48 | You can also download the source: 49 | 50 | - `pdcurses-win32a-0.3.4.zip`_ 51 | 52 | These contain everything required to use the ``curses`` module on 53 | Windows, including the ``pdcurses.dll (win32a fork)`` file. 54 | 55 | .. _`README.rst`: https://github.com/jmcb/python-pdcurses/blob/master/README.rst 56 | .. _`pdcurses-win32a-0.3.4.win32-py2.7.exe`: http://github.com/downloads/jmcb/python-pdcurses/pdcurses-win32a-0.3.4.win32-py2.7.exe 57 | .. _`pdcurses-win32a-0.3.4.win32-py2.6.exe`: http://github.com/downloads/jmcb/python-pdcurses/pdcurses-win32a-0.3.4.win32-py2.6.exe 58 | .. _`pdcurses-win32a-0.3.4.win32-py2.5.exe`: http://github.com/downloads/jmcb/python-pdcurses/pdcurses-win32a-0.3.4.win32-py2.5.exe 59 | .. _`pdcurses-win32a-0.3.4.win32-py2.4.exe`: http://github.com/downloads/jmcb/python-pdcurses/pdcurses-win32a-0.3.4.win32-py2.4.exe 60 | .. _`pdcurses-win32a-0.3.4.win32-py2.3.exe`: http://github.com/downloads/jmcb/python-pdcurses/pdcurses-win32a-0.3.4.win32-py2.3.exe 61 | .. _`pdcurses-win32a-0.3.4.zip`: http://github.com/downloads/jmcb/python-pdcurses/pdcurses-win32a-0.3.4.zip 62 | .. _`pdcurses-0.3.4.win32-py2.7.exe`: http://github.com/downloads/jmcb/python-pdcurses/pdcurses-0.3.4.win32-py2.7.exe 63 | .. _`pdcurses-0.3.4.win32-py2.6.exe`: http://github.com/downloads/jmcb/python-pdcurses/pdcurses-0.3.4.win32-py2.6.exe 64 | .. _`pdcurses-0.3.4.win32-py2.5.exe`: http://github.com/downloads/jmcb/python-pdcurses/pdcurses-0.3.4.win32-py2.5.exe 65 | .. _`pdcurses-0.3.4.win32-py2.4.exe`: http://github.com/downloads/jmcb/python-pdcurses/pdcurses-0.3.4.win32-py2.4.exe 66 | .. _`pdcurses-0.3.4.win32-py2.3.exe`: http://github.com/downloads/jmcb/python-pdcurses/pdcurses-0.3.4.win32-py2.3.exe 67 | .. _`pdcurses-0.3.4.zip`: http://github.com/downloads/jmcb/python-pdcurses/pdcurses-0.3.4.zip 68 | -------------------------------------------------------------------------------- /LICENSE.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jmcb/python-pdcurses/a868ea7bd4cb6d13fde7eededa60f42fcb44ed51/LICENSE.rst -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include pdcurses.dll 2 | include pdcurses.def 3 | include pdcurses.lib 4 | include MANIFEST.in 5 | include term.h 6 | include curspriv.h 7 | include curses.h 8 | include panel.h 9 | include _cursesmodule.c 10 | include _curses_panel.c 11 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PEXPORTS=pexports 2 | ifeq ($(shell which $(PEXPORTS) > /dev/null 2> /dev/null && echo yes),yes) 3 | PEXPORTS_AVAILABLE=Yes 4 | endif 5 | PDCURSES_DIR=pdcurses 6 | PDCURSESW32_DIR=pdcurses-win32a 7 | PDCURSESDLL=$(PDCURSES_DIR)/pdcurses.dll 8 | PDCURSESDEF=$(PDCURSES_DIR)/pdcurses.def 9 | PDCURSESLIB=$(PDCURSES_DIR)/pdcurses.lib 10 | PDCURSESW32DLL=$(PDCURSESW32_DIR)/pdcurses.dll 11 | PDCURSESW32DEF=$(PDCURSESW32_DIR)/pdcurses.def 12 | PDCURSESW32LIB=$(PDCURSESW32_DIR)/pdcurses.lib 13 | SED=sed 14 | DLLTOOL=dlltool 15 | RM=rm 16 | CP=cp 17 | MKDIR=mkdir 18 | GEN_DIR=gen 19 | BUILD=build 20 | PDCURSES_BUILD=$(PDCURSES_DIR)/build 21 | PDCURSESW32_BUILD=$(PDCURSESW32_DIR)/build 22 | DIST=dist 23 | PDCURSES_DIST=$(PDCURSES_DIR)/dist 24 | PDCURSESW32_DIST=$(PDCURSESW32_DIR)/dist 25 | SETUP_TEMPLATE=setup.py_template 26 | MANIFEST=MANIFEST.in 27 | MAKE=make 28 | 29 | all: dirs gen setups gen-source 30 | 31 | all-pd-only: dirs gen-pd-only pdcurses-setup.py gen-source-pd-only 32 | all-w32-only: dirs gen-w32-only pdcurses-win32a-setup.py gen-source-w32-only 33 | 34 | dirs: $(PDCURSESW32_DIR) $(PDCURSES_DIR) 35 | 36 | $(PDCURSESW32_DIR): 37 | $(MKDIR) $(PDCURSEW32_DIR) 38 | 39 | $(PDCURSES_DIR): 40 | $(MKDIR) $(PDCURSE_DIR) 41 | 42 | $(PDCURSESDEF): 43 | ifdef PEXPORTS_AVAILABLE 44 | $(PEXPORTS) $(PDCURSESDLL) | $(SED) -e "s/^_//g" > $(PDCURSESDEF) 45 | else 46 | $(MAKE) use-gen-pd-only 47 | endif 48 | 49 | $(PDCURSESLIB): $(PDCURSESDEF) 50 | $(DLLTOOL) --dllname $(PDCURSESDLL) --def $(PDCURSESDEF) --output-lib $(PDCURSESLIB) 51 | 52 | $(PDCURSESW32DEF): 53 | ifdef PEXPORTS_AVAILABLE 54 | $(PEXPORTS) $(PDCURSESW32DLL) | $(SED) -e "s/^_//g" > $(PDCURSESW32DEF) 55 | else 56 | $(MAKE) use-gen-w32-only 57 | endif 58 | 59 | $(PDCURSESW32LIB): $(PDCURSESW32DEF) 60 | $(DLLTOOL) --dllname $(PDCURSESW32DLL) --def $(PDCURSESW32DEF) --output-lib $(PDCURSESW32LIB) 61 | 62 | pdcurses-setup.py: $(PDCURSES_DIR) 63 | $(SED) -e s/PDCURSES_FLAV// $(SETUP_TEMPLATE) > $(PDCURSES_DIR)/setup.py 64 | 65 | pdcurses-win32a-setup.py: $(PDCURSESW32_DIR) 66 | $(SED) -e s/PDCURSES_FLAV/-win32a/ $(SETUP_TEMPLATE) > $(PDCURSESW32_DIR)/setup.py 67 | 68 | gen-setups.py: pdcurses-setup.py pdcurses-win32a-setup.py 69 | $(CP) $(PDCURSESW32_DIR)/setup.py $(GEN_DIR)/setup-win32a.py 70 | $(CP) $(PDCURSES_DIR)/setup.py $(GEN_DIR)/setup.py 71 | 72 | setups: pdcurses-setup.py pdcurses-win32a-setup.py 73 | 74 | defs: $(PDCURSESDEF) $(PDCURSESW32DEF) 75 | 76 | libs: $(PDCURSESLIB) $(PDCURSESW32LIB) 77 | 78 | gen: defs libs 79 | 80 | gen-pd-only: $(PDCURSESLIB) $(PDCURSESDEF) 81 | 82 | gen-w32-only: $(PDCURSESW32LIB) $(PDCURSESW32LIB) 83 | 84 | gen-source: gen-source-w32-only gen-source-pd-only 85 | 86 | gen-source-w32-only: 87 | $(CP) *.h *.c $(MANIFEST) $(PDCURSESW32_DIR) 88 | 89 | gen-source-pd-only: 90 | $(CP) *.h *.c $(MANIFEST) $(PDCURSES_DIR) 91 | 92 | gen-save: defs libs 93 | $(CP) $(PDCURSESDEF) $(PDCURSESLIB) $(GEN_DIR) 94 | $(CP) $(PDCURSESW32DEF) $(GEN_DIR)/pdcurses-win32a.def 95 | $(CP) $(PDCURSESW32LIB) $(GEN_DIR)/pdcurses-win32a.lib 96 | 97 | use-gen: use-gen-pd-only use-gen-w32-only 98 | 99 | use-gen-pd-only: 100 | $(CP) $(GEN_DIR)/pdcurses.def $(PDCURSES_DIR) 101 | $(CP) $(GEN_DIR)/pdcurses.lib $(PDCURSES_DIR) 102 | 103 | use-gen-w32-only: 104 | $(CP) $(GEN_DIR)/pdcurses-win32a.def $(PDCURSESW32_DIR)/pdcurses.def 105 | $(CP) $(GEN_DIR)/pdcurses-win32a.lib $(PDCURSESW32_DIR)/pdcurses.lib 106 | 107 | clean: 108 | $(RM) -f $(PDCURSESDEF) $(PDCURSESLIB) 109 | $(RM) -f $(PDCURSESW32DEF) $(PDCURSESW32LIB) 110 | $(RM) -rf $(BUILD) $(PDCURSES_BUILD) $(PDCURSESW32_BUILD) 111 | $(RM) -rf $(DIST) $(PDCURSES_DIST) $(PDCURSESW32_DIST) 112 | $(RM) -f $(PDCURSESW32_DIR)/*.h $(PDCURSESW32_DIR)/*.c 113 | $(RM) -f $(PDCURSES_DIR)/*.h $(PDCURSES_DIR)/*.c 114 | $(RM) -f $(PDCURSESW32_DIR)/$(MANIFEST) $(PDCURSESW32_DIR)/MANIFEST 115 | $(RM) -f $(PDCURSES_DIR)/$(MANIFEST) $(PDCURSES_DIR)/MANIFEST 116 | $(RM) -f $(PDCURSES_DIR)/setup.py $(PDCURSESW32_DIR)/setup.py 117 | $(RM) -f pdcurses.def pdcurses.lib *.pyc 118 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jmcb/python-pdcurses/a868ea7bd4cb6d13fde7eededa60f42fcb44ed51/README.rst -------------------------------------------------------------------------------- /_curses_panel.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface to the ncurses panel library 3 | * 4 | * Original version by Thomas Gellekum 5 | */ 6 | 7 | /* Release Number */ 8 | 9 | static char *PyCursesVersion = "2.1"; 10 | 11 | /* Includes */ 12 | 13 | #include "Python.h" 14 | 15 | #include "py_curses.h" 16 | 17 | #include "panel.h" 18 | 19 | static PyObject *PyCursesError; 20 | 21 | /* Must define Py_TYPE for Python 2.5 or older */ 22 | #ifndef Py_TYPE 23 | # define Py_TYPE(o) ((o)->ob_type) 24 | #endif 25 | 26 | /* Must define PyVarObject_HEAD_INIT for Python 2.5 or older */ 27 | #ifndef PyVarObject_HEAD_INIT 28 | #define PyVarObject_HEAD_INIT(type, size) \ 29 | PyObject_HEAD_INIT(type) size, 30 | #endif 31 | 32 | /* Utility Functions */ 33 | 34 | /* 35 | * Check the return code from a curses function and return None 36 | * or raise an exception as appropriate. 37 | */ 38 | 39 | static PyObject * 40 | PyCursesCheckERR(int code, char *fname) 41 | { 42 | if (code != ERR) { 43 | Py_INCREF(Py_None); 44 | return Py_None; 45 | } else { 46 | if (fname == NULL) { 47 | PyErr_SetString(PyCursesError, catchall_ERR); 48 | } else { 49 | PyErr_Format(PyCursesError, "%s() returned ERR", fname); 50 | } 51 | return NULL; 52 | } 53 | } 54 | 55 | /***************************************************************************** 56 | The Panel Object 57 | ******************************************************************************/ 58 | 59 | /* Definition of the panel object and panel type */ 60 | 61 | typedef struct { 62 | PyObject_HEAD 63 | PANEL *pan; 64 | PyCursesWindowObject *wo; /* for reference counts */ 65 | } PyCursesPanelObject; 66 | 67 | PyTypeObject PyCursesPanel_Type; 68 | 69 | #define PyCursesPanel_Check(v) (Py_TYPE(v) == &PyCursesPanel_Type) 70 | 71 | /* Some helper functions. The problem is that there's always a window 72 | associated with a panel. To ensure that Python's GC doesn't pull 73 | this window from under our feet we need to keep track of references 74 | to the corresponding window object within Python. We can't use 75 | dupwin(oldwin) to keep a copy of the curses WINDOW because the 76 | contents of oldwin is copied only once; code like 77 | 78 | win = newwin(...) 79 | pan = win.panel() 80 | win.addstr(some_string) 81 | pan.window().addstr(other_string) 82 | 83 | will fail. */ 84 | 85 | /* We keep a linked list of PyCursesPanelObjects, lop. A list should 86 | suffice, I don't expect more than a handful or at most a few 87 | dozens of panel objects within a typical program. */ 88 | typedef struct _list_of_panels { 89 | PyCursesPanelObject *po; 90 | struct _list_of_panels *next; 91 | } list_of_panels; 92 | 93 | /* list anchor */ 94 | static list_of_panels *lop; 95 | 96 | /* Insert a new panel object into lop */ 97 | static int 98 | insert_lop(PyCursesPanelObject *po) 99 | { 100 | list_of_panels *new; 101 | 102 | if ((new = (list_of_panels *)malloc(sizeof(list_of_panels))) == NULL) { 103 | PyErr_NoMemory(); 104 | return -1; 105 | } 106 | new->po = po; 107 | new->next = lop; 108 | lop = new; 109 | return 0; 110 | } 111 | 112 | /* Remove the panel object from lop */ 113 | static void 114 | remove_lop(PyCursesPanelObject *po) 115 | { 116 | list_of_panels *temp, *n; 117 | 118 | temp = lop; 119 | if (temp->po == po) { 120 | lop = temp->next; 121 | free(temp); 122 | return; 123 | } 124 | while (temp->next == NULL || temp->next->po != po) { 125 | if (temp->next == NULL) { 126 | PyErr_SetString(PyExc_RuntimeError, 127 | "remove_lop: can't find Panel Object"); 128 | return; 129 | } 130 | temp = temp->next; 131 | } 132 | n = temp->next->next; 133 | free(temp->next); 134 | temp->next = n; 135 | return; 136 | } 137 | 138 | /* Return the panel object that corresponds to pan */ 139 | static PyCursesPanelObject * 140 | find_po(PANEL *pan) 141 | { 142 | list_of_panels *temp; 143 | for (temp = lop; temp->po->pan != pan; temp = temp->next) 144 | if (temp->next == NULL) return NULL; /* not found!? */ 145 | return temp->po; 146 | } 147 | 148 | /* Function Prototype Macros - They are ugly but very, very useful. ;-) 149 | 150 | X - function name 151 | TYPE - parameter Type 152 | ERGSTR - format string for construction of the return value 153 | PARSESTR - format string for argument parsing */ 154 | 155 | #define Panel_NoArgNoReturnFunction(X) \ 156 | static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self) \ 157 | { return PyCursesCheckERR(X(self->pan), # X); } 158 | 159 | #define Panel_NoArgTrueFalseFunction(X) \ 160 | static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self) \ 161 | { \ 162 | if (X (self->pan) == FALSE) { Py_INCREF(Py_False); return Py_False; } \ 163 | else { Py_INCREF(Py_True); return Py_True; } } 164 | 165 | #define Panel_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \ 166 | static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self, PyObject *args) \ 167 | { \ 168 | TYPE arg1, arg2; \ 169 | if (!PyArg_ParseTuple(args, PARSESTR, &arg1, &arg2)) return NULL; \ 170 | return PyCursesCheckERR(X(self->pan, arg1, arg2), # X); } 171 | 172 | /* ------------- PANEL routines --------------- */ 173 | 174 | Panel_NoArgNoReturnFunction(bottom_panel) 175 | Panel_NoArgNoReturnFunction(hide_panel) 176 | Panel_NoArgNoReturnFunction(show_panel) 177 | Panel_NoArgNoReturnFunction(top_panel) 178 | Panel_NoArgTrueFalseFunction(panel_hidden) 179 | Panel_TwoArgNoReturnFunction(move_panel, int, "ii;y,x") 180 | 181 | /* Allocation and deallocation of Panel Objects */ 182 | 183 | static PyObject * 184 | PyCursesPanel_New(PANEL *pan, PyCursesWindowObject *wo) 185 | { 186 | PyCursesPanelObject *po; 187 | 188 | po = PyObject_NEW(PyCursesPanelObject, &PyCursesPanel_Type); 189 | if (po == NULL) return NULL; 190 | po->pan = pan; 191 | if (insert_lop(po) < 0) { 192 | po->wo = NULL; 193 | Py_DECREF(po); 194 | return NULL; 195 | } 196 | po->wo = wo; 197 | Py_INCREF(wo); 198 | return (PyObject *)po; 199 | } 200 | 201 | static void 202 | PyCursesPanel_Dealloc(PyCursesPanelObject *po) 203 | { 204 | (void)del_panel(po->pan); 205 | if (po->wo != NULL) { 206 | Py_DECREF(po->wo); 207 | remove_lop(po); 208 | } 209 | PyObject_DEL(po); 210 | } 211 | 212 | /* panel_above(NULL) returns the bottom panel in the stack. To get 213 | this behaviour we use curses.panel.bottom_panel(). */ 214 | static PyObject * 215 | PyCursesPanel_above(PyCursesPanelObject *self) 216 | { 217 | PANEL *pan; 218 | PyCursesPanelObject *po; 219 | 220 | pan = panel_above(self->pan); 221 | 222 | if (pan == NULL) { /* valid output, it means the calling panel 223 | is on top of the stack */ 224 | Py_INCREF(Py_None); 225 | return Py_None; 226 | } 227 | po = find_po(pan); 228 | if (po == NULL) { 229 | PyErr_SetString(PyExc_RuntimeError, 230 | "panel_above: can't find Panel Object"); 231 | return NULL; 232 | } 233 | Py_INCREF(po); 234 | return (PyObject *)po; 235 | } 236 | 237 | /* panel_below(NULL) returns the top panel in the stack. To get 238 | this behaviour we use curses.panel.top_panel(). */ 239 | static PyObject * 240 | PyCursesPanel_below(PyCursesPanelObject *self) 241 | { 242 | PANEL *pan; 243 | PyCursesPanelObject *po; 244 | 245 | pan = panel_below(self->pan); 246 | 247 | if (pan == NULL) { /* valid output, it means the calling panel 248 | is on the bottom of the stack */ 249 | Py_INCREF(Py_None); 250 | return Py_None; 251 | } 252 | po = find_po(pan); 253 | if (po == NULL) { 254 | PyErr_SetString(PyExc_RuntimeError, 255 | "panel_below: can't find Panel Object"); 256 | return NULL; 257 | } 258 | Py_INCREF(po); 259 | return (PyObject *)po; 260 | } 261 | 262 | static PyObject * 263 | PyCursesPanel_window(PyCursesPanelObject *self) 264 | { 265 | Py_INCREF(self->wo); 266 | return (PyObject *)self->wo; 267 | } 268 | 269 | static PyObject * 270 | PyCursesPanel_replace_panel(PyCursesPanelObject *self, PyObject *args) 271 | { 272 | PyCursesPanelObject *po; 273 | PyCursesWindowObject *temp; 274 | int rtn; 275 | 276 | if (PyTuple_Size(args) != 1) { 277 | PyErr_SetString(PyExc_TypeError, "replace requires one argument"); 278 | return NULL; 279 | } 280 | if (!PyArg_ParseTuple(args, "O!;window object", 281 | &PyCursesWindow_Type, &temp)) 282 | return NULL; 283 | 284 | po = find_po(self->pan); 285 | if (po == NULL) { 286 | PyErr_SetString(PyExc_RuntimeError, 287 | "replace_panel: can't find Panel Object"); 288 | return NULL; 289 | } 290 | 291 | rtn = replace_panel(self->pan, temp->win); 292 | if (rtn == ERR) { 293 | PyErr_SetString(PyCursesError, "replace_panel() returned ERR"); 294 | return NULL; 295 | } 296 | Py_DECREF(po->wo); 297 | po->wo = temp; 298 | Py_INCREF(po->wo); 299 | Py_INCREF(Py_None); 300 | return Py_None; 301 | } 302 | 303 | static PyObject * 304 | PyCursesPanel_set_panel_userptr(PyCursesPanelObject *self, PyObject *obj) 305 | { 306 | Py_INCREF(obj); 307 | return PyCursesCheckERR(set_panel_userptr(self->pan, (void*)obj), 308 | "set_panel_userptr"); 309 | } 310 | 311 | static PyObject * 312 | PyCursesPanel_userptr(PyCursesPanelObject *self) 313 | { 314 | PyObject *obj; 315 | PyCursesInitialised; 316 | obj = (PyObject *) panel_userptr(self->pan); 317 | if (obj == NULL) { 318 | PyErr_SetString(PyCursesError, "no userptr set"); 319 | return NULL; 320 | } 321 | 322 | Py_INCREF(obj); 323 | return obj; 324 | } 325 | 326 | 327 | /* Module interface */ 328 | 329 | static PyMethodDef PyCursesPanel_Methods[] = { 330 | {"above", (PyCFunction)PyCursesPanel_above, METH_NOARGS}, 331 | {"below", (PyCFunction)PyCursesPanel_below, METH_NOARGS}, 332 | {"bottom", (PyCFunction)PyCursesPanel_bottom_panel, METH_NOARGS}, 333 | {"hidden", (PyCFunction)PyCursesPanel_panel_hidden, METH_NOARGS}, 334 | {"hide", (PyCFunction)PyCursesPanel_hide_panel, METH_NOARGS}, 335 | {"move", (PyCFunction)PyCursesPanel_move_panel, METH_VARARGS}, 336 | {"replace", (PyCFunction)PyCursesPanel_replace_panel, METH_VARARGS}, 337 | {"set_userptr", (PyCFunction)PyCursesPanel_set_panel_userptr, METH_O}, 338 | {"show", (PyCFunction)PyCursesPanel_show_panel, METH_NOARGS}, 339 | {"top", (PyCFunction)PyCursesPanel_top_panel, METH_NOARGS}, 340 | {"userptr", (PyCFunction)PyCursesPanel_userptr, METH_NOARGS}, 341 | {"window", (PyCFunction)PyCursesPanel_window, METH_NOARGS}, 342 | {NULL, NULL} /* sentinel */ 343 | }; 344 | 345 | #if PY_MAJOR_VERSION < 3 346 | static PyObject * 347 | PyCursesPanel_GetAttr(PyCursesPanelObject *self, char *name) 348 | { 349 | return Py_FindMethod(PyCursesPanel_Methods, (PyObject *)self, name); 350 | } 351 | #endif 352 | 353 | /* -------------------------------------------------------*/ 354 | 355 | PyTypeObject PyCursesPanel_Type = { 356 | PyVarObject_HEAD_INIT(NULL, 0) 357 | "_curses_panel.curses panel", /*tp_name*/ 358 | sizeof(PyCursesPanelObject), /*tp_basicsize*/ 359 | 0, /*tp_itemsize*/ 360 | /* methods */ 361 | (destructor)PyCursesPanel_Dealloc, /*tp_dealloc*/ 362 | 0, /*tp_print*/ 363 | #if PY_MAJOR_VERSION == 3 364 | 0, /*tp_getattr*/ 365 | 0, /*tp_setattr*/ 366 | #else 367 | (getattrfunc)PyCursesPanel_GetAttr, /*tp_getattr*/ 368 | (setattrfunc)0, /*tp_setattr*/ 369 | #endif 370 | 0, /*tp_compare/tp_reserved*/ 371 | 0, /*tp_repr*/ 372 | 0, /*tp_as_number*/ 373 | 0, /*tp_as_sequence*/ 374 | 0, /*tp_as_mapping*/ 375 | 0, /*tp_hash*/ 376 | #if PY_MAJOR_VERSION == 3 377 | 0, /*tp_call*/ 378 | 0, /*tp_str*/ 379 | 0, /*tp_getattro*/ 380 | 0, /*tp_setattro*/ 381 | 0, /*tp_as_buffer*/ 382 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ 383 | 0, /*tp_doc*/ 384 | 0, /*tp_traverse*/ 385 | 0, /*tp_clear*/ 386 | 0, /*tp_richcompare*/ 387 | 0, /*tp_weaklistoffset*/ 388 | 0, /*tp_iter*/ 389 | 0, /*tp_iternext*/ 390 | PyCursesPanel_Methods, /*tp_methods*/ 391 | #endif 392 | }; 393 | 394 | /* Wrapper for panel_above(NULL). This function returns the bottom 395 | panel of the stack, so it's renamed to bottom_panel(). 396 | panel.above() *requires* a panel object in the first place which 397 | may be undesirable. */ 398 | static PyObject * 399 | PyCurses_bottom_panel(PyObject *self) 400 | { 401 | PANEL *pan; 402 | PyCursesPanelObject *po; 403 | 404 | PyCursesInitialised; 405 | 406 | pan = panel_above(NULL); 407 | 408 | if (pan == NULL) { /* valid output, it means 409 | there's no panel at all */ 410 | Py_INCREF(Py_None); 411 | return Py_None; 412 | } 413 | po = find_po(pan); 414 | if (po == NULL) { 415 | PyErr_SetString(PyExc_RuntimeError, 416 | "panel_above: can't find Panel Object"); 417 | return NULL; 418 | } 419 | Py_INCREF(po); 420 | return (PyObject *)po; 421 | } 422 | 423 | static PyObject * 424 | PyCurses_new_panel(PyObject *self, PyObject *args) 425 | { 426 | PyCursesWindowObject *win; 427 | PANEL *pan; 428 | 429 | if (!PyArg_ParseTuple(args, "O!", &PyCursesWindow_Type, &win)) 430 | return NULL; 431 | pan = new_panel(win->win); 432 | if (pan == NULL) { 433 | PyErr_SetString(PyCursesError, catchall_NULL); 434 | return NULL; 435 | } 436 | return (PyObject *)PyCursesPanel_New(pan, win); 437 | } 438 | 439 | 440 | /* Wrapper for panel_below(NULL). This function returns the top panel 441 | of the stack, so it's renamed to top_panel(). panel.below() 442 | *requires* a panel object in the first place which may be 443 | undesirable. */ 444 | static PyObject * 445 | PyCurses_top_panel(PyObject *self) 446 | { 447 | PANEL *pan; 448 | PyCursesPanelObject *po; 449 | 450 | PyCursesInitialised; 451 | 452 | pan = panel_below(NULL); 453 | 454 | if (pan == NULL) { /* valid output, it means 455 | there's no panel at all */ 456 | Py_INCREF(Py_None); 457 | return Py_None; 458 | } 459 | po = find_po(pan); 460 | if (po == NULL) { 461 | PyErr_SetString(PyExc_RuntimeError, 462 | "panel_below: can't find Panel Object"); 463 | return NULL; 464 | } 465 | Py_INCREF(po); 466 | return (PyObject *)po; 467 | } 468 | 469 | static PyObject *PyCurses_update_panels(PyObject *self) 470 | { 471 | PyCursesInitialised; 472 | update_panels(); 473 | Py_INCREF(Py_None); 474 | return Py_None; 475 | } 476 | 477 | 478 | /* List of functions defined in the module */ 479 | 480 | static PyMethodDef PyCurses_methods[] = { 481 | {"bottom_panel", (PyCFunction)PyCurses_bottom_panel, METH_NOARGS}, 482 | {"new_panel", (PyCFunction)PyCurses_new_panel, METH_VARARGS}, 483 | {"top_panel", (PyCFunction)PyCurses_top_panel, METH_NOARGS}, 484 | {"update_panels", (PyCFunction)PyCurses_update_panels, METH_NOARGS}, 485 | {NULL, NULL} /* sentinel */ 486 | }; 487 | 488 | #if PY_MAJOR_VERSION == 3 489 | static struct PyModuleDef _curses_panelmodule = { 490 | PyModuleDef_HEAD_INIT, 491 | "_curses_panel", 492 | NULL, 493 | -1, 494 | PyCurses_methods, 495 | NULL, 496 | NULL, 497 | NULL, 498 | NULL 499 | }; 500 | #endif 501 | 502 | /* Initialization function for the module */ 503 | 504 | PyMODINIT_FUNC 505 | #if PY_MAJOR_VERSION == 3 506 | PyInit__curses_panel(void) 507 | #else 508 | init_curses_panel(void) 509 | #endif 510 | { 511 | PyObject *m, *d, *v; 512 | 513 | /* Initialize object type */ 514 | #if PY_MAJOR_VERSION == 3 515 | if (PyType_Ready(&PyCursesPanel_Type) < 0) 516 | return NULL; 517 | #else 518 | Py_TYPE(&PyCursesPanel_Type) = &PyType_Type; 519 | #endif 520 | 521 | import_curses(); 522 | 523 | /* Create the module and add the functions */ 524 | #if PY_MAJOR_VERSION == 3 525 | m = PyModule_Create(&_curses_panelmodule); 526 | #else 527 | m = Py_InitModule("_curses_panel", PyCurses_methods); 528 | #endif 529 | 530 | if (m == NULL) 531 | #if PY_MAJOR_VERSION == 3 532 | return NULL; 533 | #else 534 | return; 535 | #endif 536 | d = PyModule_GetDict(m); 537 | 538 | /* For exception _curses_panel.error */ 539 | PyCursesError = PyErr_NewException("_curses_panel.error", NULL, NULL); 540 | PyDict_SetItemString(d, "error", PyCursesError); 541 | 542 | /* Make the version available */ 543 | #if PY_MAJOR_VERSION == 3 544 | v = PyUnicode_FromString 545 | #else 546 | v = PyString_FromString 547 | #endif 548 | (PyCursesVersion); 549 | 550 | PyDict_SetItemString(d, "version", v); 551 | PyDict_SetItemString(d, "__version__", v); 552 | Py_DECREF(v); 553 | 554 | #if PY_MAJOR_VERSION == 3 555 | return m; 556 | #endif 557 | } 558 | -------------------------------------------------------------------------------- /_cursesmodule.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a curses module for Python. 3 | * 4 | * Based on prior work by Lance Ellinghaus and Oliver Andrich 5 | * Version 1.2 of this module: Copyright 1994 by Lance Ellinghouse, 6 | * Cathedral City, California Republic, United States of America. 7 | * 8 | * Version 1.5b1, heavily extended for ncurses by Oliver Andrich: 9 | * Copyright 1996,1997 by Oliver Andrich, Koblenz, Germany. 10 | * 11 | * Tidied for Python 1.6, and currently maintained by . 12 | * 13 | * Permission is hereby granted, free of charge, to any person obtaining 14 | * a copy of this source file to use, copy, modify, merge, or publish it 15 | * subject to the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be included 18 | * in all copies or in any new file that contains a substantial portion of 19 | * this file. 20 | * 21 | * THE AUTHOR MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF 22 | * THE SOFTWARE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT 23 | * EXPRESS OR IMPLIED WARRANTY. THE AUTHOR DISCLAIMS ALL WARRANTIES 24 | * WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 25 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26 | * NON-INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE 27 | * AUTHOR BE LIABLE TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL, 28 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER 29 | * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE, STRICT LIABILITY OR 30 | * ANY OTHER ACTION ARISING OUT OF OR IN CONNECTION WITH THE USE OR 31 | * PERFORMANCE OF THIS SOFTWARE. 32 | */ 33 | 34 | /* 35 | 36 | A number of SysV or ncurses functions don't have wrappers yet; if you 37 | need a given function, add it and send a patch. See 38 | http://www.python.org/dev/patches/ for instructions on how to submit 39 | patches to Python. 40 | 41 | Here's a list of currently unsupported functions: 42 | 43 | addchnstr addchstr color_set define_key 44 | del_curterm delscreen dupwin inchnstr inchstr innstr keyok 45 | mcprint mvaddchnstr mvaddchstr mvcur mvinchnstr 46 | mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr 47 | mvwinchnstr mvwinchstr mvwinnstr newterm 48 | restartterm ripoffline scr_dump 49 | scr_init scr_restore scr_set scrl set_curterm set_term setterm 50 | tgetent tgetflag tgetnum tgetstr tgoto timeout tputs 51 | vidattr vidputs waddchnstr waddchstr 52 | wcolor_set winchnstr winchstr winnstr wmouse_trafo wscrl 53 | 54 | Low-priority: 55 | slk_attr slk_attr_off slk_attr_on slk_attr_set slk_attroff 56 | slk_attron slk_attrset slk_clear slk_color slk_init slk_label 57 | slk_noutrefresh slk_refresh slk_restore slk_set slk_touch 58 | 59 | Menu extension (ncurses and probably SYSV): 60 | current_item free_item free_menu item_count item_description 61 | item_index item_init item_name item_opts item_opts_off 62 | item_opts_on item_term item_userptr item_value item_visible 63 | menu_back menu_driver menu_fore menu_format menu_grey 64 | menu_init menu_items menu_mark menu_opts menu_opts_off 65 | menu_opts_on menu_pad menu_pattern menu_request_by_name 66 | menu_request_name menu_spacing menu_sub menu_term menu_userptr 67 | menu_win new_item new_menu pos_menu_cursor post_menu 68 | scale_menu set_current_item set_item_init set_item_opts 69 | set_item_term set_item_userptr set_item_value set_menu_back 70 | set_menu_fore set_menu_format set_menu_grey set_menu_init 71 | set_menu_items set_menu_mark set_menu_opts set_menu_pad 72 | set_menu_pattern set_menu_spacing set_menu_sub set_menu_term 73 | set_menu_userptr set_menu_win set_top_row top_row unpost_menu 74 | 75 | Form extension (ncurses and probably SYSV): 76 | current_field data_ahead data_behind dup_field 77 | dynamic_fieldinfo field_arg field_back field_buffer 78 | field_count field_fore field_index field_info field_init 79 | field_just field_opts field_opts_off field_opts_on field_pad 80 | field_status field_term field_type field_userptr form_driver 81 | form_fields form_init form_opts form_opts_off form_opts_on 82 | form_page form_request_by_name form_request_name form_sub 83 | form_term form_userptr form_win free_field free_form 84 | link_field link_fieldtype move_field new_field new_form 85 | new_page pos_form_cursor post_form scale_form 86 | set_current_field set_field_back set_field_buffer 87 | set_field_fore set_field_init set_field_just set_field_opts 88 | set_field_pad set_field_status set_field_term set_field_type 89 | set_field_userptr set_fieldtype_arg set_fieldtype_choice 90 | set_form_fields set_form_init set_form_opts set_form_page 91 | set_form_sub set_form_term set_form_userptr set_form_win 92 | set_max_field set_new_page unpost_form 93 | 94 | 95 | */ 96 | 97 | /* Release Number */ 98 | 99 | char *PyCursesVersion = "2.2"; 100 | 101 | /* Includes */ 102 | 103 | #include "Python.h" 104 | 105 | #ifdef __osf__ 106 | #define STRICT_SYSV_CURSES /* Don't use ncurses extensions */ 107 | #endif 108 | 109 | #ifdef __hpux 110 | #define STRICT_SYSV_CURSES 111 | #endif 112 | 113 | #define CURSES_MODULE 114 | #include "py_curses.h" 115 | 116 | #include "term.h" 117 | 118 | #include "curspriv.h" 119 | 120 | #define _ISPAD _PAD 121 | 122 | #if PY_MAJOR_VERSION == 3 123 | #ifdef _WIN32 124 | #include "windows.h" 125 | #include "tchar.h" 126 | #endif 127 | #endif 128 | 129 | #if !defined(HAVE_NCURSES_H) && (defined(sgi) || defined(__sun) || defined(SCO5)) 130 | #define STRICT_SYSV_CURSES /* Don't use ncurses extensions */ 131 | typedef chtype attr_t; /* No attr_t type is available */ 132 | #endif 133 | 134 | #if defined(_AIX) 135 | #define STRICT_SYSV_CURSES 136 | #endif 137 | 138 | /* Must define Py_TYPE for Python 2.5 or older */ 139 | #ifndef Py_TYPE 140 | # define Py_TYPE(o) ((o)->ob_type) 141 | #endif 142 | 143 | /* Must define PyVarObject_HEAD_INIT for Python 2.5 or older */ 144 | #ifndef PyVarObject_HEAD_INIT 145 | #define PyVarObject_HEAD_INIT(type, size) \ 146 | PyObject_HEAD_INIT(type) size, 147 | #endif 148 | 149 | /* To quiet a compiler warning about an unused ERR variable: */ 150 | #ifndef UNUSED 151 | #define UNUSED(x) (void)(x) 152 | #endif 153 | 154 | /* Definition of exception curses.error */ 155 | 156 | static PyObject *PyCursesError; 157 | 158 | /* Tells whether setupterm() has been called to initialise terminfo. */ 159 | static int initialised_setupterm = FALSE; 160 | 161 | /* Tells whether initscr() has been called to initialise curses. */ 162 | static int initialised = FALSE; 163 | 164 | /* Tells whether start_color() has been called to initialise color usage. */ 165 | static int initialisedcolors = FALSE; 166 | 167 | /* Utility Macros */ 168 | #define PyCursesSetupTermCalled \ 169 | if (initialised_setupterm != TRUE) { \ 170 | PyErr_SetString(PyCursesError, \ 171 | "must call (at least) setupterm() first"); \ 172 | return 0; } 173 | 174 | #define PyCursesInitialised \ 175 | if (initialised != TRUE) { \ 176 | PyErr_SetString(PyCursesError, \ 177 | "must call initscr() first"); \ 178 | return 0; } 179 | 180 | #define PyCursesInitialisedColor \ 181 | if (initialisedcolors != TRUE) { \ 182 | PyErr_SetString(PyCursesError, \ 183 | "must call start_color() first"); \ 184 | return 0; } 185 | 186 | #ifndef MIN 187 | #define MIN(x,y) ((x) < (y) ? (x) : (y)) 188 | #endif 189 | 190 | /* Utility Functions */ 191 | 192 | /* 193 | * Check the return code from a curses function and return None 194 | * or raise an exception as appropriate. These are exported using the 195 | * capsule API. 196 | */ 197 | 198 | static PyObject * 199 | PyCursesCheckERR(int code, char *fname) 200 | { 201 | if (code != ERR) { 202 | Py_INCREF(Py_None); 203 | return Py_None; 204 | } else { 205 | if (fname == NULL) { 206 | PyErr_SetString(PyCursesError, catchall_ERR); 207 | } else { 208 | PyErr_Format(PyCursesError, "%s() returned ERR", fname); 209 | } 210 | return NULL; 211 | } 212 | } 213 | 214 | #if PY_MAJOR_VERSION == 3 215 | static int 216 | PyCurses_ConvertToChtype(PyObject *obj, chtype *ch) 217 | { 218 | if (PyLong_CheckExact(obj)) { 219 | int overflow; 220 | /* XXX should the truncation by the cast also be reported 221 | as an error? */ 222 | *ch = (chtype) PyLong_AsLongAndOverflow(obj, &overflow); 223 | if (overflow) 224 | return 0; 225 | } else if(PyBytes_Check(obj) 226 | && (PyBytes_Size(obj) == 1)) { 227 | *ch = (chtype) *PyBytes_AsString(obj); 228 | } else if (PyUnicode_Check(obj) && PyUnicode_GetSize(obj) == 1) { 229 | *ch = (chtype) *PyUnicode_AS_UNICODE(obj); 230 | } else { 231 | return 0; 232 | } 233 | return 1; 234 | } 235 | #else 236 | static int 237 | PyCurses_ConvertToChtype(PyObject *obj, chtype *ch) 238 | { 239 | if (PyInt_Check(obj)) { 240 | *ch = (chtype) PyInt_AsLong(obj); 241 | } else if(PyString_Check(obj) 242 | && (PyString_Size(obj) == 1)) { 243 | *ch = (chtype) *PyString_AsString(obj); 244 | } else { 245 | return 0; 246 | } 247 | return 1; 248 | } 249 | #endif 250 | /* Function versions of the 3 functions for testing whether curses has been 251 | initialised or not. */ 252 | 253 | static int func_PyCursesSetupTermCalled(void) 254 | { 255 | PyCursesSetupTermCalled; 256 | return 1; 257 | } 258 | 259 | static int func_PyCursesInitialised(void) 260 | { 261 | PyCursesInitialised; 262 | return 1; 263 | } 264 | 265 | static int func_PyCursesInitialisedColor(void) 266 | { 267 | PyCursesInitialisedColor; 268 | return 1; 269 | } 270 | 271 | /***************************************************************************** 272 | The Window Object 273 | ******************************************************************************/ 274 | 275 | /* Definition of the window type */ 276 | 277 | PyTypeObject PyCursesWindow_Type; 278 | 279 | /* Function prototype macros for Window object 280 | 281 | X - function name 282 | TYPE - parameter Type 283 | ERGSTR - format string for construction of the return value 284 | PARSESTR - format string for argument parsing 285 | */ 286 | 287 | #define Window_NoArgNoReturnFunction(X) \ 288 | static PyObject *PyCursesWindow_ ## X \ 289 | (PyCursesWindowObject *self, PyObject *args) \ 290 | { return PyCursesCheckERR(X(self->win), # X); } 291 | 292 | #define Window_NoArgTrueFalseFunction(X) \ 293 | static PyObject * PyCursesWindow_ ## X \ 294 | (PyCursesWindowObject *self) \ 295 | { \ 296 | if (X (self->win) == FALSE) { Py_INCREF(Py_False); return Py_False; } \ 297 | else { Py_INCREF(Py_True); return Py_True; } } 298 | 299 | #define Window_NoArgNoReturnVoidFunction(X) \ 300 | static PyObject * PyCursesWindow_ ## X \ 301 | (PyCursesWindowObject *self) \ 302 | { \ 303 | X(self->win); Py_INCREF(Py_None); return Py_None; } 304 | 305 | #define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR) \ 306 | static PyObject * PyCursesWindow_ ## X \ 307 | (PyCursesWindowObject *self) \ 308 | { \ 309 | TYPE arg1, arg2; \ 310 | X(self->win,arg1,arg2); return Py_BuildValue(ERGSTR, arg1, arg2); } 311 | 312 | #define Window_OneArgNoReturnVoidFunction(X, TYPE, PARSESTR) \ 313 | static PyObject * PyCursesWindow_ ## X \ 314 | (PyCursesWindowObject *self, PyObject *args) \ 315 | { \ 316 | TYPE arg1; \ 317 | if (!PyArg_ParseTuple(args, PARSESTR, &arg1)) return NULL; \ 318 | X(self->win,arg1); Py_INCREF(Py_None); return Py_None; } 319 | 320 | #define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR) \ 321 | static PyObject * PyCursesWindow_ ## X \ 322 | (PyCursesWindowObject *self, PyObject *args) \ 323 | { \ 324 | TYPE arg1; \ 325 | if (!PyArg_ParseTuple(args,PARSESTR, &arg1)) return NULL; \ 326 | return PyCursesCheckERR(X(self->win, arg1), # X); } 327 | 328 | #define Window_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \ 329 | static PyObject * PyCursesWindow_ ## X \ 330 | (PyCursesWindowObject *self, PyObject *args) \ 331 | { \ 332 | TYPE arg1, arg2; \ 333 | if (!PyArg_ParseTuple(args,PARSESTR, &arg1, &arg2)) return NULL; \ 334 | return PyCursesCheckERR(X(self->win, arg1, arg2), # X); } 335 | 336 | /* ------------- WINDOW routines --------------- */ 337 | 338 | Window_NoArgNoReturnFunction(untouchwin) 339 | Window_NoArgNoReturnFunction(touchwin) 340 | Window_NoArgNoReturnFunction(redrawwin) 341 | Window_NoArgNoReturnFunction(winsertln) 342 | Window_NoArgNoReturnFunction(werase) 343 | Window_NoArgNoReturnFunction(wdeleteln) 344 | 345 | Window_NoArgTrueFalseFunction(is_wintouched) 346 | 347 | Window_NoArgNoReturnVoidFunction(wsyncup) 348 | Window_NoArgNoReturnVoidFunction(wsyncdown) 349 | Window_NoArgNoReturnVoidFunction(wstandend) 350 | Window_NoArgNoReturnVoidFunction(wstandout) 351 | Window_NoArgNoReturnVoidFunction(wcursyncup) 352 | Window_NoArgNoReturnVoidFunction(wclrtoeol) 353 | Window_NoArgNoReturnVoidFunction(wclrtobot) 354 | Window_NoArgNoReturnVoidFunction(wclear) 355 | 356 | Window_OneArgNoReturnVoidFunction(idcok, int, "i;True(1) or False(0)") 357 | Window_OneArgNoReturnVoidFunction(immedok, int, "i;True(1) or False(0)") 358 | Window_OneArgNoReturnVoidFunction(wtimeout, int, "i;delay") 359 | 360 | Window_NoArg2TupleReturnFunction(getyx, int, "ii") 361 | Window_NoArg2TupleReturnFunction(getbegyx, int, "ii") 362 | Window_NoArg2TupleReturnFunction(getmaxyx, int, "ii") 363 | Window_NoArg2TupleReturnFunction(getparyx, int, "ii") 364 | 365 | Window_OneArgNoReturnFunction(clearok, int, "i;True(1) or False(0)") 366 | Window_OneArgNoReturnFunction(idlok, int, "i;True(1) or False(0)") 367 | #if defined(__NetBSD__) 368 | Window_OneArgNoReturnVoidFunction(keypad, int, "i;True(1) or False(0)") 369 | #else 370 | Window_OneArgNoReturnFunction(keypad, int, "i;True(1) or False(0)") 371 | #endif 372 | Window_OneArgNoReturnFunction(leaveok, int, "i;True(1) or False(0)") 373 | #if defined(__NetBSD__) 374 | Window_OneArgNoReturnVoidFunction(nodelay, int, "i;True(1) or False(0)") 375 | #else 376 | Window_OneArgNoReturnFunction(nodelay, int, "i;True(1) or False(0)") 377 | #endif 378 | Window_OneArgNoReturnFunction(notimeout, int, "i;True(1) or False(0)") 379 | Window_OneArgNoReturnFunction(scrollok, int, "i;True(1) or False(0)") 380 | Window_OneArgNoReturnFunction(winsdelln, int, "i;nlines") 381 | Window_OneArgNoReturnFunction(syncok, int, "i;True(1) or False(0)") 382 | 383 | Window_TwoArgNoReturnFunction(mvwin, int, "ii;y,x") 384 | Window_TwoArgNoReturnFunction(mvderwin, int, "ii;y,x") 385 | Window_TwoArgNoReturnFunction(wmove, int, "ii;y,x") 386 | #ifndef STRICT_SYSV_CURSES 387 | Window_TwoArgNoReturnFunction(wresize, int, "ii;lines,columns") 388 | #endif 389 | 390 | /* Allocation and deallocation of Window Objects */ 391 | 392 | static PyObject * 393 | PyCursesWindow_New(WINDOW *win) 394 | { 395 | PyCursesWindowObject *wo; 396 | 397 | wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type); 398 | if (wo == NULL) return NULL; 399 | wo->win = win; 400 | return (PyObject *)wo; 401 | } 402 | 403 | static void 404 | PyCursesWindow_Dealloc(PyCursesWindowObject *wo) 405 | { 406 | if (wo->win != stdscr) delwin(wo->win); 407 | PyObject_DEL(wo); 408 | } 409 | 410 | /* Addch, Addstr, Addnstr */ 411 | 412 | static PyObject * 413 | PyCursesWindow_AddCh(PyCursesWindowObject *self, PyObject *args) 414 | { 415 | int rtn, x, y, use_xy = FALSE; 416 | PyObject *temp; 417 | chtype ch = 0; 418 | attr_t attr = A_NORMAL; 419 | long lattr; 420 | 421 | switch (PyTuple_Size(args)) { 422 | case 1: 423 | if (!PyArg_ParseTuple(args, "O;ch or int", &temp)) 424 | return NULL; 425 | break; 426 | case 2: 427 | if (!PyArg_ParseTuple(args, "Ol;ch or int,attr", &temp, &lattr)) 428 | return NULL; 429 | attr = lattr; 430 | break; 431 | case 3: 432 | if (!PyArg_ParseTuple(args,"iiO;y,x,ch or int", &y, &x, &temp)) 433 | return NULL; 434 | use_xy = TRUE; 435 | break; 436 | case 4: 437 | if (!PyArg_ParseTuple(args,"iiOl;y,x,ch or int, attr", 438 | &y, &x, &temp, &lattr)) 439 | return NULL; 440 | attr = lattr; 441 | use_xy = TRUE; 442 | break; 443 | default: 444 | PyErr_SetString(PyExc_TypeError, "addch requires 1 to 4 arguments"); 445 | return NULL; 446 | } 447 | 448 | if (!PyCurses_ConvertToChtype(temp, &ch)) { 449 | PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int"); 450 | return NULL; 451 | } 452 | 453 | if (use_xy == TRUE) 454 | rtn = mvwaddch(self->win,y,x, ch | attr); 455 | else { 456 | rtn = waddch(self->win, ch | attr); 457 | } 458 | return PyCursesCheckERR(rtn, "addch"); 459 | } 460 | 461 | static PyObject * 462 | PyCursesWindow_AddStr(PyCursesWindowObject *self, PyObject *args) 463 | { 464 | int rtn; 465 | int x, y; 466 | char *str; 467 | attr_t attr = A_NORMAL , attr_old = A_NORMAL; 468 | long lattr; 469 | int use_xy = FALSE, use_attr = FALSE; 470 | 471 | switch (PyTuple_Size(args)) { 472 | case 1: 473 | if (!PyArg_ParseTuple(args,"s;str", &str)) 474 | return NULL; 475 | break; 476 | case 2: 477 | if (!PyArg_ParseTuple(args,"sl;str,attr", &str, &lattr)) 478 | return NULL; 479 | attr = lattr; 480 | use_attr = TRUE; 481 | break; 482 | case 3: 483 | if (!PyArg_ParseTuple(args,"iis;int,int,str", &y, &x, &str)) 484 | return NULL; 485 | use_xy = TRUE; 486 | break; 487 | case 4: 488 | if (!PyArg_ParseTuple(args,"iisl;int,int,str,attr", &y, &x, &str, &lattr)) 489 | return NULL; 490 | attr = lattr; 491 | use_xy = use_attr = TRUE; 492 | break; 493 | default: 494 | PyErr_SetString(PyExc_TypeError, "addstr requires 1 to 4 arguments"); 495 | return NULL; 496 | } 497 | 498 | if (use_attr == TRUE) { 499 | attr_old = getattrs(self->win); 500 | (void)wattrset(self->win,attr); 501 | } 502 | if (use_xy == TRUE) 503 | rtn = mvwaddstr(self->win,y,x,str); 504 | else 505 | rtn = waddstr(self->win,str); 506 | if (use_attr == TRUE) 507 | (void)wattrset(self->win,attr_old); 508 | return PyCursesCheckERR(rtn, "addstr"); 509 | } 510 | 511 | static PyObject * 512 | PyCursesWindow_AddNStr(PyCursesWindowObject *self, PyObject *args) 513 | { 514 | int rtn, x, y, n; 515 | char *str; 516 | attr_t attr = A_NORMAL , attr_old = A_NORMAL; 517 | long lattr; 518 | int use_xy = FALSE, use_attr = FALSE; 519 | 520 | switch (PyTuple_Size(args)) { 521 | case 2: 522 | if (!PyArg_ParseTuple(args,"si;str,n", &str, &n)) 523 | return NULL; 524 | break; 525 | case 3: 526 | if (!PyArg_ParseTuple(args,"sil;str,n,attr", &str, &n, &lattr)) 527 | return NULL; 528 | attr = lattr; 529 | use_attr = TRUE; 530 | break; 531 | case 4: 532 | if (!PyArg_ParseTuple(args,"iisi;y,x,str,n", &y, &x, &str, &n)) 533 | return NULL; 534 | use_xy = TRUE; 535 | break; 536 | case 5: 537 | if (!PyArg_ParseTuple(args,"iisil;y,x,str,n,attr", &y, &x, &str, &n, &lattr)) 538 | return NULL; 539 | attr = lattr; 540 | use_xy = use_attr = TRUE; 541 | break; 542 | default: 543 | PyErr_SetString(PyExc_TypeError, "addnstr requires 2 to 5 arguments"); 544 | return NULL; 545 | } 546 | 547 | if (use_attr == TRUE) { 548 | attr_old = getattrs(self->win); 549 | (void)wattrset(self->win,attr); 550 | } 551 | if (use_xy == TRUE) 552 | rtn = mvwaddnstr(self->win,y,x,str,n); 553 | else 554 | rtn = waddnstr(self->win,str,n); 555 | if (use_attr == TRUE) 556 | (void)wattrset(self->win,attr_old); 557 | return PyCursesCheckERR(rtn, "addnstr"); 558 | } 559 | 560 | static PyObject * 561 | PyCursesWindow_Bkgd(PyCursesWindowObject *self, PyObject *args) 562 | { 563 | PyObject *temp; 564 | chtype bkgd; 565 | attr_t attr = A_NORMAL; 566 | long lattr; 567 | 568 | switch (PyTuple_Size(args)) { 569 | case 1: 570 | if (!PyArg_ParseTuple(args, "O;ch or int", &temp)) 571 | return NULL; 572 | break; 573 | case 2: 574 | if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr)) 575 | return NULL; 576 | attr = lattr; 577 | break; 578 | default: 579 | PyErr_SetString(PyExc_TypeError, "bkgd requires 1 or 2 arguments"); 580 | return NULL; 581 | } 582 | 583 | if (!PyCurses_ConvertToChtype(temp, &bkgd)) { 584 | PyErr_SetString(PyExc_TypeError, "argument 1 or 3 must be a ch or an int"); 585 | return NULL; 586 | } 587 | 588 | return PyCursesCheckERR(wbkgd(self->win, bkgd | attr), "bkgd"); 589 | } 590 | 591 | static PyObject * 592 | PyCursesWindow_AttrOff(PyCursesWindowObject *self, PyObject *args) 593 | { 594 | long lattr; 595 | if (!PyArg_ParseTuple(args,"l;attr", &lattr)) 596 | return NULL; 597 | return PyCursesCheckERR(wattroff(self->win, (attr_t)lattr), "attroff"); 598 | } 599 | 600 | static PyObject * 601 | PyCursesWindow_AttrOn(PyCursesWindowObject *self, PyObject *args) 602 | { 603 | long lattr; 604 | if (!PyArg_ParseTuple(args,"l;attr", &lattr)) 605 | return NULL; 606 | return PyCursesCheckERR(wattron(self->win, (attr_t)lattr), "attron"); 607 | } 608 | 609 | static PyObject * 610 | PyCursesWindow_AttrSet(PyCursesWindowObject *self, PyObject *args) 611 | { 612 | long lattr; 613 | if (!PyArg_ParseTuple(args,"l;attr", &lattr)) 614 | return NULL; 615 | return PyCursesCheckERR(wattrset(self->win, (attr_t)lattr), "attrset"); 616 | } 617 | 618 | static PyObject * 619 | PyCursesWindow_BkgdSet(PyCursesWindowObject *self, PyObject *args) 620 | { 621 | PyObject *temp; 622 | chtype bkgd; 623 | attr_t attr = A_NORMAL; 624 | long lattr; 625 | 626 | switch (PyTuple_Size(args)) { 627 | case 1: 628 | if (!PyArg_ParseTuple(args, "O;ch or int", &temp)) 629 | return NULL; 630 | break; 631 | case 2: 632 | if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr)) 633 | return NULL; 634 | attr = lattr; 635 | break; 636 | default: 637 | PyErr_SetString(PyExc_TypeError, "bkgdset requires 1 or 2 arguments"); 638 | return NULL; 639 | } 640 | 641 | if (!PyCurses_ConvertToChtype(temp, &bkgd)) { 642 | PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int"); 643 | return NULL; 644 | } 645 | 646 | wbkgdset(self->win, bkgd | attr); 647 | return PyCursesCheckERR(0, "bkgdset"); 648 | } 649 | 650 | static PyObject * 651 | PyCursesWindow_Border(PyCursesWindowObject *self, PyObject *args) 652 | { 653 | PyObject *temp[8]; 654 | chtype ch[8]; 655 | int i; 656 | 657 | /* Clear the array of parameters */ 658 | for(i=0; i<8; i++) { 659 | temp[i] = NULL; 660 | ch[i] = 0; 661 | } 662 | 663 | if (!PyArg_ParseTuple(args,"|OOOOOOOO;ls,rs,ts,bs,tl,tr,bl,br", 664 | &temp[0], &temp[1], &temp[2], &temp[3], 665 | &temp[4], &temp[5], &temp[6], &temp[7])) 666 | return NULL; 667 | 668 | for(i=0; i<8; i++) { 669 | if (temp[i] != NULL && !PyCurses_ConvertToChtype(temp[i], &ch[i])) { 670 | PyErr_Format(PyExc_TypeError, 671 | "argument %i must be a ch or an int", i+1); 672 | return NULL; 673 | } 674 | } 675 | 676 | wborder(self->win, 677 | ch[0], ch[1], ch[2], ch[3], 678 | ch[4], ch[5], ch[6], ch[7]); 679 | Py_INCREF(Py_None); 680 | return Py_None; 681 | } 682 | 683 | static PyObject * 684 | PyCursesWindow_Box(PyCursesWindowObject *self, PyObject *args) 685 | { 686 | chtype ch1=0,ch2=0; 687 | switch(PyTuple_Size(args)){ 688 | case 0: break; 689 | default: 690 | if (!PyArg_ParseTuple(args,"ll;vertint,horint", &ch1, &ch2)) 691 | return NULL; 692 | } 693 | box(self->win,ch1,ch2); 694 | Py_INCREF(Py_None); 695 | return Py_None; 696 | } 697 | 698 | #if defined(HAVE_NCURSES_H) || defined(MVWDELCH_IS_EXPRESSION) 699 | #define py_mvwdelch mvwdelch 700 | #else 701 | int py_mvwdelch(WINDOW *w, int y, int x) 702 | { 703 | mvwdelch(w,y,x); 704 | /* On HP/UX, mvwdelch already returns. On other systems, 705 | we may well run into this return statement. */ 706 | return 0; 707 | } 708 | #endif 709 | 710 | /* chgat, added by Fabian Kreutz */ 711 | 712 | static PyObject * 713 | PyCursesWindow_ChgAt(PyCursesWindowObject *self, PyObject *args) 714 | { 715 | int rtn; 716 | int x, y; 717 | int num = -1; 718 | short color; 719 | attr_t attr = A_NORMAL; 720 | long lattr; 721 | int use_xy = FALSE; 722 | 723 | switch (PyTuple_Size(args)) { 724 | case 1: 725 | if (!PyArg_ParseTuple(args,"l;attr", &lattr)) 726 | return NULL; 727 | attr = lattr; 728 | break; 729 | case 2: 730 | if (!PyArg_ParseTuple(args,"il;n,attr", &num, &lattr)) 731 | return NULL; 732 | attr = lattr; 733 | break; 734 | case 3: 735 | if (!PyArg_ParseTuple(args,"iil;int,int,attr", &y, &x, &lattr)) 736 | return NULL; 737 | attr = lattr; 738 | use_xy = TRUE; 739 | break; 740 | case 4: 741 | if (!PyArg_ParseTuple(args,"iiil;int,int,n,attr", &y, &x, &num, &lattr)) 742 | return NULL; 743 | attr = lattr; 744 | use_xy = TRUE; 745 | break; 746 | default: 747 | PyErr_SetString(PyExc_TypeError, "chgat requires 1 to 4 arguments"); 748 | return NULL; 749 | } 750 | 751 | color = (short)((attr >> 8) & 0xff); 752 | attr = attr - (color << 8); 753 | 754 | if (use_xy == TRUE) { 755 | rtn = mvwchgat(self->win,y,x,num,attr,color,NULL); 756 | touchline(self->win,y,1); 757 | } else { 758 | getyx(self->win,y,x); 759 | rtn = wchgat(self->win,num,attr,color,NULL); 760 | touchline(self->win,y,1); 761 | } 762 | return PyCursesCheckERR(rtn, "chgat"); 763 | } 764 | 765 | 766 | static PyObject * 767 | PyCursesWindow_DelCh(PyCursesWindowObject *self, PyObject *args) 768 | { 769 | int rtn; 770 | int x, y; 771 | 772 | switch (PyTuple_Size(args)) { 773 | case 0: 774 | rtn = wdelch(self->win); 775 | break; 776 | case 2: 777 | if (!PyArg_ParseTuple(args,"ii;y,x", &y, &x)) 778 | return NULL; 779 | rtn = py_mvwdelch(self->win,y,x); 780 | break; 781 | default: 782 | PyErr_SetString(PyExc_TypeError, "delch requires 0 or 2 arguments"); 783 | return NULL; 784 | } 785 | return PyCursesCheckERR(rtn, "[mv]wdelch"); 786 | } 787 | 788 | static PyObject * 789 | PyCursesWindow_DerWin(PyCursesWindowObject *self, PyObject *args) 790 | { 791 | WINDOW *win; 792 | int nlines, ncols, begin_y, begin_x; 793 | 794 | nlines = 0; 795 | ncols = 0; 796 | switch (PyTuple_Size(args)) { 797 | case 2: 798 | if (!PyArg_ParseTuple(args,"ii;begin_y,begin_x",&begin_y,&begin_x)) 799 | return NULL; 800 | break; 801 | case 4: 802 | if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x", 803 | &nlines,&ncols,&begin_y,&begin_x)) 804 | return NULL; 805 | break; 806 | default: 807 | PyErr_SetString(PyExc_TypeError, "derwin requires 2 or 4 arguments"); 808 | return NULL; 809 | } 810 | 811 | win = derwin(self->win,nlines,ncols,begin_y,begin_x); 812 | 813 | if (win == NULL) { 814 | PyErr_SetString(PyCursesError, catchall_NULL); 815 | return NULL; 816 | } 817 | 818 | return (PyObject *)PyCursesWindow_New(win); 819 | } 820 | 821 | static PyObject * 822 | PyCursesWindow_EchoChar(PyCursesWindowObject *self, PyObject *args) 823 | { 824 | PyObject *temp; 825 | chtype ch; 826 | attr_t attr = A_NORMAL; 827 | long lattr; 828 | 829 | switch (PyTuple_Size(args)) { 830 | case 1: 831 | if (!PyArg_ParseTuple(args,"O;ch or int", &temp)) 832 | return NULL; 833 | break; 834 | case 2: 835 | if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr)) 836 | return NULL; 837 | attr = lattr; 838 | break; 839 | default: 840 | PyErr_SetString(PyExc_TypeError, "echochar requires 1 or 2 arguments"); 841 | 842 | 843 | return NULL; 844 | } 845 | 846 | if (!PyCurses_ConvertToChtype(temp, &ch)) { 847 | PyErr_SetString(PyExc_TypeError, "argument 1 must be a ch or an int"); 848 | return NULL; 849 | } 850 | 851 | #ifdef WINDOW_HAS_FLAGS 852 | if (self->win->_flags & _ISPAD) 853 | return PyCursesCheckERR(pechochar(self->win, ch | attr), 854 | "echochar"); 855 | else 856 | #endif 857 | return PyCursesCheckERR(wechochar(self->win, ch | attr), 858 | "echochar"); 859 | } 860 | 861 | #ifdef NCURSES_MOUSE_VERSION 862 | static PyObject * 863 | PyCursesWindow_Enclose(PyCursesWindowObject *self, PyObject *args) 864 | { 865 | int x, y; 866 | if (!PyArg_ParseTuple(args,"ii;y,x", &y, &x)) 867 | return NULL; 868 | 869 | #if PY_MAJOR_VERSION == 3 870 | return PyLong_FromLong 871 | #else 872 | return PyInt_FromLong 873 | #endif 874 | (wenclose(self->win,y,x)); 875 | } 876 | #endif 877 | 878 | static PyObject * 879 | PyCursesWindow_GetBkgd(PyCursesWindowObject *self) 880 | { 881 | #if PY_MAJOR_VERSION == 3 882 | return PyLong_FromLong 883 | #else 884 | return PyInt_FromLong 885 | #endif 886 | ((long) getbkgd(self->win)); 887 | } 888 | 889 | static PyObject * 890 | PyCursesWindow_GetCh(PyCursesWindowObject *self, PyObject *args) 891 | { 892 | int x, y; 893 | int rtn; 894 | 895 | switch (PyTuple_Size(args)) { 896 | case 0: 897 | Py_BEGIN_ALLOW_THREADS 898 | rtn = wgetch(self->win); 899 | Py_END_ALLOW_THREADS 900 | break; 901 | case 2: 902 | if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x)) 903 | return NULL; 904 | Py_BEGIN_ALLOW_THREADS 905 | rtn = mvwgetch(self->win,y,x); 906 | Py_END_ALLOW_THREADS 907 | break; 908 | default: 909 | PyErr_SetString(PyExc_TypeError, "getch requires 0 or 2 arguments"); 910 | return NULL; 911 | } 912 | #if PY_MAJOR_VERSION == 3 913 | return PyLong_FromLong 914 | #else 915 | return PyInt_FromLong 916 | #endif 917 | ((long)rtn); 918 | } 919 | 920 | static PyObject * 921 | PyCursesWindow_GetKey(PyCursesWindowObject *self, PyObject *args) 922 | { 923 | int x, y; 924 | int rtn; 925 | 926 | switch (PyTuple_Size(args)) { 927 | case 0: 928 | Py_BEGIN_ALLOW_THREADS 929 | rtn = wgetch(self->win); 930 | Py_END_ALLOW_THREADS 931 | break; 932 | case 2: 933 | if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x)) 934 | return NULL; 935 | Py_BEGIN_ALLOW_THREADS 936 | rtn = mvwgetch(self->win,y,x); 937 | Py_END_ALLOW_THREADS 938 | break; 939 | default: 940 | PyErr_SetString(PyExc_TypeError, "getkey requires 0 or 2 arguments"); 941 | return NULL; 942 | } 943 | if (rtn == ERR) { 944 | /* getch() returns ERR in nodelay mode */ 945 | PyErr_SetString(PyCursesError, "no input"); 946 | return NULL; 947 | } else if (rtn<=255) { 948 | #if PY_MAJOR_VERSION == 3 949 | return Py_BuildValue("C", rtn); 950 | #else 951 | return Py_BuildValue("c", rtn); 952 | #endif 953 | } else { 954 | const char *knp; 955 | #if defined(__NetBSD__) 956 | knp = unctrl(rtn); 957 | #else 958 | knp = keyname(rtn); 959 | #endif 960 | #if PY_MAJOR_VERSION == 3 961 | return PyUnicode_FromString 962 | #else 963 | return PyString_FromString 964 | #endif 965 | ((knp == NULL) ? "" : knp); 966 | } 967 | } 968 | 969 | static PyObject * 970 | PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args) 971 | { 972 | int x, y, n; 973 | char rtn[1024]; /* This should be big enough.. I hope */ 974 | int rtn2; 975 | 976 | switch (PyTuple_Size(args)) { 977 | case 0: 978 | Py_BEGIN_ALLOW_THREADS 979 | rtn2 = wgetnstr(self->win,rtn, 1023); 980 | Py_END_ALLOW_THREADS 981 | break; 982 | case 1: 983 | if (!PyArg_ParseTuple(args,"i;n", &n)) 984 | return NULL; 985 | Py_BEGIN_ALLOW_THREADS 986 | rtn2 = wgetnstr(self->win,rtn,MIN(n, 1023)); 987 | Py_END_ALLOW_THREADS 988 | break; 989 | case 2: 990 | if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x)) 991 | return NULL; 992 | Py_BEGIN_ALLOW_THREADS 993 | #ifdef STRICT_SYSV_CURSES 994 | rtn2 = wmove(self->win,y,x)==ERR ? ERR : wgetnstr(self->win, rtn, 1023); 995 | #else 996 | rtn2 = mvwgetnstr(self->win,y,x,rtn, 1023); 997 | #endif 998 | Py_END_ALLOW_THREADS 999 | break; 1000 | case 3: 1001 | if (!PyArg_ParseTuple(args,"iii;y,x,n", &y, &x, &n)) 1002 | return NULL; 1003 | #ifdef STRICT_SYSV_CURSES 1004 | Py_BEGIN_ALLOW_THREADS 1005 | rtn2 = wmove(self->win,y,x)==ERR ? ERR : 1006 | wgetnstr(self->win, rtn, MIN(n, 1023)); 1007 | Py_END_ALLOW_THREADS 1008 | #else 1009 | Py_BEGIN_ALLOW_THREADS 1010 | rtn2 = mvwgetnstr(self->win, y, x, rtn, MIN(n, 1023)); 1011 | Py_END_ALLOW_THREADS 1012 | #endif 1013 | break; 1014 | default: 1015 | PyErr_SetString(PyExc_TypeError, "getstr requires 0 to 3 arguments"); 1016 | return NULL; 1017 | } 1018 | if (rtn2 == ERR) 1019 | rtn[0] = 0; 1020 | #if PY_MAJOR_VERSION == 3 1021 | return PyBytes_FromString 1022 | #else 1023 | return PyString_FromString 1024 | #endif 1025 | (rtn); 1026 | } 1027 | 1028 | static PyObject * 1029 | PyCursesWindow_Hline(PyCursesWindowObject *self, PyObject *args) 1030 | { 1031 | PyObject *temp; 1032 | chtype ch; 1033 | int n, x, y, code = OK; 1034 | attr_t attr = A_NORMAL; 1035 | long lattr; 1036 | 1037 | switch (PyTuple_Size(args)) { 1038 | case 2: 1039 | if (!PyArg_ParseTuple(args, "Oi;ch or int,n", &temp, &n)) 1040 | return NULL; 1041 | break; 1042 | case 3: 1043 | if (!PyArg_ParseTuple(args, "Oil;ch or int,n,attr", &temp, &n, &lattr)) 1044 | return NULL; 1045 | attr = lattr; 1046 | break; 1047 | case 4: 1048 | if (!PyArg_ParseTuple(args, "iiOi;y,x,ch or int,n", &y, &x, &temp, &n)) 1049 | return NULL; 1050 | code = wmove(self->win, y, x); 1051 | break; 1052 | case 5: 1053 | if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr", 1054 | &y, &x, &temp, &n, &lattr)) 1055 | return NULL; 1056 | attr = lattr; 1057 | code = wmove(self->win, y, x); 1058 | break; 1059 | default: 1060 | PyErr_SetString(PyExc_TypeError, "hline requires 2 to 5 arguments"); 1061 | return NULL; 1062 | } 1063 | 1064 | if (code != ERR) { 1065 | if (!PyCurses_ConvertToChtype(temp, &ch)) { 1066 | PyErr_SetString(PyExc_TypeError, 1067 | "argument 1 or 3 must be a ch or an int"); 1068 | return NULL; 1069 | } 1070 | return PyCursesCheckERR(whline(self->win, ch | attr, n), "hline"); 1071 | } else 1072 | return PyCursesCheckERR(code, "wmove"); 1073 | } 1074 | 1075 | static PyObject * 1076 | PyCursesWindow_InsCh(PyCursesWindowObject *self, PyObject *args) 1077 | { 1078 | int rtn, x, y, use_xy = FALSE; 1079 | PyObject *temp; 1080 | chtype ch = 0; 1081 | attr_t attr = A_NORMAL; 1082 | long lattr; 1083 | 1084 | switch (PyTuple_Size(args)) { 1085 | case 1: 1086 | if (!PyArg_ParseTuple(args, "O;ch or int", &temp)) 1087 | return NULL; 1088 | break; 1089 | case 2: 1090 | if (!PyArg_ParseTuple(args, "Ol;ch or int,attr", &temp, &lattr)) 1091 | return NULL; 1092 | attr = lattr; 1093 | break; 1094 | case 3: 1095 | if (!PyArg_ParseTuple(args,"iiO;y,x,ch or int", &y, &x, &temp)) 1096 | return NULL; 1097 | use_xy = TRUE; 1098 | break; 1099 | case 4: 1100 | if (!PyArg_ParseTuple(args,"iiOl;y,x,ch or int, attr", &y, &x, &temp, &lattr)) 1101 | return NULL; 1102 | attr = lattr; 1103 | use_xy = TRUE; 1104 | break; 1105 | default: 1106 | PyErr_SetString(PyExc_TypeError, "insch requires 1 or 4 arguments"); 1107 | return NULL; 1108 | } 1109 | 1110 | if (!PyCurses_ConvertToChtype(temp, &ch)) { 1111 | PyErr_SetString(PyExc_TypeError, 1112 | "argument 1 or 3 must be a ch or an int"); 1113 | return NULL; 1114 | } 1115 | 1116 | if (use_xy == TRUE) 1117 | rtn = mvwinsch(self->win,y,x, ch | attr); 1118 | else { 1119 | rtn = winsch(self->win, ch | attr); 1120 | } 1121 | return PyCursesCheckERR(rtn, "insch"); 1122 | } 1123 | 1124 | static PyObject * 1125 | PyCursesWindow_InCh(PyCursesWindowObject *self, PyObject *args) 1126 | { 1127 | int x, y, rtn; 1128 | 1129 | switch (PyTuple_Size(args)) { 1130 | case 0: 1131 | rtn = winch(self->win); 1132 | break; 1133 | case 2: 1134 | if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x)) 1135 | return NULL; 1136 | rtn = mvwinch(self->win,y,x); 1137 | break; 1138 | default: 1139 | PyErr_SetString(PyExc_TypeError, "inch requires 0 or 2 arguments"); 1140 | return NULL; 1141 | } 1142 | #if PY_MAJOR_VERSION == 3 1143 | return PyLong_FromLong 1144 | #else 1145 | return PyInt_FromLong 1146 | #endif 1147 | ((long) rtn); 1148 | } 1149 | 1150 | static PyObject * 1151 | PyCursesWindow_InStr(PyCursesWindowObject *self, PyObject *args) 1152 | { 1153 | int x, y, n; 1154 | char rtn[1024]; /* This should be big enough.. I hope */ 1155 | int rtn2; 1156 | 1157 | switch (PyTuple_Size(args)) { 1158 | case 0: 1159 | rtn2 = winnstr(self->win,rtn, 1023); 1160 | break; 1161 | case 1: 1162 | if (!PyArg_ParseTuple(args,"i;n", &n)) 1163 | return NULL; 1164 | rtn2 = winnstr(self->win,rtn,MIN(n,1023)); 1165 | break; 1166 | case 2: 1167 | if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x)) 1168 | return NULL; 1169 | rtn2 = mvwinnstr(self->win,y,x,rtn,1023); 1170 | break; 1171 | case 3: 1172 | if (!PyArg_ParseTuple(args, "iii;y,x,n", &y, &x, &n)) 1173 | return NULL; 1174 | rtn2 = mvwinnstr(self->win, y, x, rtn, MIN(n,1023)); 1175 | break; 1176 | default: 1177 | PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments"); 1178 | return NULL; 1179 | } 1180 | if (rtn2 == ERR) 1181 | rtn[0] = 0; 1182 | #if PY_MAJOR_VERSION == 3 1183 | return PyBytes_FromString 1184 | #else 1185 | return PyString_FromString 1186 | #endif 1187 | (rtn); 1188 | } 1189 | 1190 | static PyObject * 1191 | PyCursesWindow_InsStr(PyCursesWindowObject *self, PyObject *args) 1192 | { 1193 | int rtn; 1194 | int x, y; 1195 | char *str; 1196 | attr_t attr = A_NORMAL , attr_old = A_NORMAL; 1197 | long lattr; 1198 | int use_xy = FALSE, use_attr = FALSE; 1199 | 1200 | switch (PyTuple_Size(args)) { 1201 | case 1: 1202 | if (!PyArg_ParseTuple(args,"s;str", &str)) 1203 | return NULL; 1204 | break; 1205 | case 2: 1206 | if (!PyArg_ParseTuple(args,"sl;str,attr", &str, &lattr)) 1207 | return NULL; 1208 | attr = lattr; 1209 | use_attr = TRUE; 1210 | break; 1211 | case 3: 1212 | if (!PyArg_ParseTuple(args,"iis;y,x,str", &y, &x, &str)) 1213 | return NULL; 1214 | use_xy = TRUE; 1215 | break; 1216 | case 4: 1217 | if (!PyArg_ParseTuple(args,"iisl;y,x,str,attr", &y, &x, &str, &lattr)) 1218 | return NULL; 1219 | attr = lattr; 1220 | use_xy = use_attr = TRUE; 1221 | break; 1222 | default: 1223 | PyErr_SetString(PyExc_TypeError, "insstr requires 1 to 4 arguments"); 1224 | return NULL; 1225 | } 1226 | 1227 | if (use_attr == TRUE) { 1228 | attr_old = getattrs(self->win); 1229 | (void)wattrset(self->win,attr); 1230 | } 1231 | if (use_xy == TRUE) 1232 | rtn = mvwinsstr(self->win,y,x,str); 1233 | else 1234 | rtn = winsstr(self->win,str); 1235 | if (use_attr == TRUE) 1236 | (void)wattrset(self->win,attr_old); 1237 | return PyCursesCheckERR(rtn, "insstr"); 1238 | } 1239 | 1240 | static PyObject * 1241 | PyCursesWindow_InsNStr(PyCursesWindowObject *self, PyObject *args) 1242 | { 1243 | int rtn, x, y, n; 1244 | char *str; 1245 | attr_t attr = A_NORMAL , attr_old = A_NORMAL; 1246 | long lattr; 1247 | int use_xy = FALSE, use_attr = FALSE; 1248 | 1249 | switch (PyTuple_Size(args)) { 1250 | case 2: 1251 | if (!PyArg_ParseTuple(args,"si;str,n", &str, &n)) 1252 | return NULL; 1253 | break; 1254 | case 3: 1255 | if (!PyArg_ParseTuple(args,"sil;str,n,attr", &str, &n, &lattr)) 1256 | return NULL; 1257 | attr = lattr; 1258 | use_attr = TRUE; 1259 | break; 1260 | case 4: 1261 | if (!PyArg_ParseTuple(args,"iisi;y,x,str,n", &y, &x, &str, &n)) 1262 | return NULL; 1263 | use_xy = TRUE; 1264 | break; 1265 | case 5: 1266 | if (!PyArg_ParseTuple(args,"iisil;y,x,str,n,attr", &y, &x, &str, &n, &lattr)) 1267 | return NULL; 1268 | attr = lattr; 1269 | use_xy = use_attr = TRUE; 1270 | break; 1271 | default: 1272 | PyErr_SetString(PyExc_TypeError, "insnstr requires 2 to 5 arguments"); 1273 | return NULL; 1274 | } 1275 | 1276 | if (use_attr == TRUE) { 1277 | attr_old = getattrs(self->win); 1278 | (void)wattrset(self->win,attr); 1279 | } 1280 | if (use_xy == TRUE) 1281 | rtn = mvwinsnstr(self->win,y,x,str,n); 1282 | else 1283 | rtn = winsnstr(self->win,str,n); 1284 | if (use_attr == TRUE) 1285 | (void)wattrset(self->win,attr_old); 1286 | return PyCursesCheckERR(rtn, "insnstr"); 1287 | } 1288 | 1289 | static PyObject * 1290 | PyCursesWindow_Is_LineTouched(PyCursesWindowObject *self, PyObject *args) 1291 | { 1292 | int line, erg; 1293 | if (!PyArg_ParseTuple(args,"i;line", &line)) 1294 | return NULL; 1295 | erg = is_linetouched(self->win, line); 1296 | if (erg == ERR) { 1297 | PyErr_SetString(PyExc_TypeError, 1298 | "is_linetouched: line number outside of boundaries"); 1299 | return NULL; 1300 | } else 1301 | if (erg == FALSE) { 1302 | Py_INCREF(Py_False); 1303 | return Py_False; 1304 | } else { 1305 | Py_INCREF(Py_True); 1306 | return Py_True; 1307 | } 1308 | } 1309 | 1310 | static PyObject * 1311 | PyCursesWindow_NoOutRefresh(PyCursesWindowObject *self, PyObject *args) 1312 | { 1313 | int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol; 1314 | int rtn; 1315 | 1316 | #ifndef WINDOW_HAS_FLAGS 1317 | if (0) 1318 | #else 1319 | if (self->win->_flags & _ISPAD) 1320 | #endif 1321 | { 1322 | switch(PyTuple_Size(args)) { 1323 | case 6: 1324 | if (!PyArg_ParseTuple(args, 1325 | "iiiiii;" \ 1326 | "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol", 1327 | &pminrow, &pmincol, &sminrow, 1328 | &smincol, &smaxrow, &smaxcol)) 1329 | return NULL; 1330 | Py_BEGIN_ALLOW_THREADS 1331 | rtn = pnoutrefresh(self->win, 1332 | pminrow, pmincol, sminrow, 1333 | smincol, smaxrow, smaxcol); 1334 | Py_END_ALLOW_THREADS 1335 | return PyCursesCheckERR(rtn, "pnoutrefresh"); 1336 | default: 1337 | PyErr_SetString(PyCursesError, 1338 | "noutrefresh() called for a pad " 1339 | "requires 6 arguments"); 1340 | return NULL; 1341 | } 1342 | } else { 1343 | if (!PyArg_ParseTuple(args, ":noutrefresh")) 1344 | return NULL; 1345 | 1346 | Py_BEGIN_ALLOW_THREADS 1347 | rtn = wnoutrefresh(self->win); 1348 | Py_END_ALLOW_THREADS 1349 | return PyCursesCheckERR(rtn, "wnoutrefresh"); 1350 | } 1351 | } 1352 | 1353 | static PyObject * 1354 | PyCursesWindow_Overlay(PyCursesWindowObject *self, PyObject *args) 1355 | { 1356 | PyCursesWindowObject *temp; 1357 | int use_copywin = FALSE; 1358 | int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol; 1359 | int rtn; 1360 | 1361 | switch (PyTuple_Size(args)) { 1362 | case 1: 1363 | if (!PyArg_ParseTuple(args, "O!;window object", 1364 | &PyCursesWindow_Type, &temp)) 1365 | return NULL; 1366 | break; 1367 | case 7: 1368 | if (!PyArg_ParseTuple(args, "O!iiiiii;window object, int, int, int, int, int, int", 1369 | &PyCursesWindow_Type, &temp, &sminrow, &smincol, 1370 | &dminrow, &dmincol, &dmaxrow, &dmaxcol)) 1371 | return NULL; 1372 | use_copywin = TRUE; 1373 | break; 1374 | default: 1375 | PyErr_SetString(PyExc_TypeError, 1376 | "overlay requires one or seven arguments"); 1377 | return NULL; 1378 | } 1379 | 1380 | if (use_copywin == TRUE) { 1381 | rtn = copywin(self->win, temp->win, sminrow, smincol, 1382 | dminrow, dmincol, dmaxrow, dmaxcol, TRUE); 1383 | return PyCursesCheckERR(rtn, "copywin"); 1384 | } 1385 | else { 1386 | rtn = overlay(self->win, temp->win); 1387 | return PyCursesCheckERR(rtn, "overlay"); 1388 | } 1389 | } 1390 | 1391 | static PyObject * 1392 | PyCursesWindow_Overwrite(PyCursesWindowObject *self, PyObject *args) 1393 | { 1394 | PyCursesWindowObject *temp; 1395 | int use_copywin = FALSE; 1396 | int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol; 1397 | int rtn; 1398 | 1399 | switch (PyTuple_Size(args)) { 1400 | case 1: 1401 | if (!PyArg_ParseTuple(args, "O!;window object", 1402 | &PyCursesWindow_Type, &temp)) 1403 | return NULL; 1404 | break; 1405 | case 7: 1406 | if (!PyArg_ParseTuple(args, "O!iiiiii;window object, int, int, int, int, int, int", 1407 | &PyCursesWindow_Type, &temp, &sminrow, &smincol, 1408 | &dminrow, &dmincol, &dmaxrow, &dmaxcol)) 1409 | return NULL; 1410 | use_copywin = TRUE; 1411 | break; 1412 | default: 1413 | PyErr_SetString(PyExc_TypeError, 1414 | "overwrite requires one or seven arguments"); 1415 | return NULL; 1416 | } 1417 | 1418 | if (use_copywin == TRUE) { 1419 | rtn = copywin(self->win, temp->win, sminrow, smincol, 1420 | dminrow, dmincol, dmaxrow, dmaxcol, FALSE); 1421 | return PyCursesCheckERR(rtn, "copywin"); 1422 | } 1423 | else { 1424 | rtn = overwrite(self->win, temp->win); 1425 | return PyCursesCheckERR(rtn, "overwrite"); 1426 | } 1427 | } 1428 | 1429 | #if PY_MAJOR_VERSION == 3 1430 | static PyObject * 1431 | PyCursesWindow_PutWin(PyCursesWindowObject *self, PyObject *stream) 1432 | { 1433 | /* We have to simulate this by writing to a temporary FILE*, 1434 | then reading back, then writing to the argument stream. */ 1435 | PyObject *res; 1436 | 1437 | #ifdef _WIN32 1438 | TCHAR path[MAX_PATH]; 1439 | DWORD retval; 1440 | retval = GetTempPath(MAX_PATH, path); 1441 | if (retval == 0 || retval > MAX_PATH) 1442 | { 1443 | PyErr_SetString(PyExc_IOError, "couldn't find the temporary file path"); 1444 | return NULL; 1445 | } 1446 | 1447 | TCHAR fn[MAX_PATH]; 1448 | retval = GetTempFileName(path, TEXT("PY_curses"), 0, fn); 1449 | if (retval == 0) 1450 | { 1451 | PyErr_SetString(PyExc_IOError, "couldn't find temporary file name"); 1452 | return NULL; 1453 | } 1454 | 1455 | FILE *fp = _tfopen(fn, "wb+"); 1456 | #else 1457 | char fn[100]; 1458 | int fd; 1459 | FILE *fp; 1460 | 1461 | strcpy(fn, "/tmp/py.curses.putwin.XXXXXX"); 1462 | fd = mkstemp(fn); 1463 | 1464 | if (fd < 0) 1465 | return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); 1466 | 1467 | fp = fdopen(fd, "wb+"); 1468 | #endif 1469 | 1470 | if (fp == NULL) { 1471 | 1472 | #ifdef _WIN32 1473 | _tremove(fn); 1474 | #else 1475 | close(fd); 1476 | remove(fn); 1477 | #endif 1478 | 1479 | return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); 1480 | } 1481 | res = PyCursesCheckERR(putwin(self->win, fp), "putwin"); 1482 | if (res == NULL) { 1483 | fclose(fp); 1484 | 1485 | #ifdef _WIN32 1486 | _tremove(fn); 1487 | #else 1488 | remove(fn); 1489 | #endif 1490 | 1491 | return res; 1492 | } 1493 | fseek(fp, 0, 0); 1494 | while (1) { 1495 | char buf[BUFSIZ]; 1496 | int n = fread(buf, 1, BUFSIZ, fp); 1497 | if (n <= 0) 1498 | break; 1499 | Py_DECREF(res); 1500 | res = PyObject_CallMethod(stream, "write", "y#", buf, n); 1501 | if (res == NULL) 1502 | break; 1503 | } 1504 | 1505 | fclose(fp); 1506 | 1507 | #ifdef _WIN32 1508 | _tremove(fn); 1509 | #else 1510 | remove(fn); 1511 | #endif 1512 | 1513 | return res; 1514 | } 1515 | #else 1516 | static PyObject * 1517 | PyCursesWindow_PutWin(PyCursesWindowObject *self, PyObject *args) 1518 | { 1519 | PyObject *temp; 1520 | 1521 | if (!PyArg_ParseTuple(args, "O;fileobj", &temp)) 1522 | return NULL; 1523 | if (!PyFile_Check(temp)) { 1524 | PyErr_SetString(PyExc_TypeError, "argument must be a file object"); 1525 | return NULL; 1526 | } 1527 | return PyCursesCheckERR(putwin(self->win, PyFile_AsFile(temp)), 1528 | "putwin"); 1529 | } 1530 | #endif 1531 | 1532 | static PyObject * 1533 | PyCursesWindow_RedrawLine(PyCursesWindowObject *self, PyObject *args) 1534 | { 1535 | int beg, num; 1536 | if (!PyArg_ParseTuple(args, "ii;beg,num", &beg, &num)) 1537 | return NULL; 1538 | return PyCursesCheckERR(wredrawln(self->win,beg,num), "redrawln"); 1539 | } 1540 | 1541 | static PyObject * 1542 | PyCursesWindow_Refresh(PyCursesWindowObject *self, PyObject *args) 1543 | { 1544 | int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol; 1545 | int rtn; 1546 | 1547 | #ifndef WINDOW_HAS_FLAGS 1548 | if (0) 1549 | #else 1550 | if (self->win->_flags & _ISPAD) 1551 | #endif 1552 | { 1553 | switch(PyTuple_Size(args)) { 1554 | case 6: 1555 | if (!PyArg_ParseTuple(args, 1556 | "iiiiii;" \ 1557 | "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol", 1558 | &pminrow, &pmincol, &sminrow, 1559 | &smincol, &smaxrow, &smaxcol)) 1560 | return NULL; 1561 | 1562 | Py_BEGIN_ALLOW_THREADS 1563 | rtn = prefresh(self->win, 1564 | pminrow, pmincol, sminrow, 1565 | smincol, smaxrow, smaxcol); 1566 | Py_END_ALLOW_THREADS 1567 | return PyCursesCheckERR(rtn, "prefresh"); 1568 | default: 1569 | PyErr_SetString(PyCursesError, 1570 | "refresh() for a pad requires 6 arguments"); 1571 | return NULL; 1572 | } 1573 | } else { 1574 | if (!PyArg_ParseTuple(args, ":refresh")) 1575 | return NULL; 1576 | Py_BEGIN_ALLOW_THREADS 1577 | rtn = wrefresh(self->win); 1578 | Py_END_ALLOW_THREADS 1579 | return PyCursesCheckERR(rtn, "prefresh"); 1580 | } 1581 | } 1582 | 1583 | static PyObject * 1584 | PyCursesWindow_SetScrollRegion(PyCursesWindowObject *self, PyObject *args) 1585 | { 1586 | int x, y; 1587 | if (!PyArg_ParseTuple(args,"ii;top, bottom",&y,&x)) 1588 | return NULL; 1589 | return PyCursesCheckERR(wsetscrreg(self->win,y,x), "wsetscrreg"); 1590 | } 1591 | 1592 | static PyObject * 1593 | PyCursesWindow_SubWin(PyCursesWindowObject *self, PyObject *args) 1594 | { 1595 | WINDOW *win; 1596 | int nlines, ncols, begin_y, begin_x; 1597 | 1598 | nlines = 0; 1599 | ncols = 0; 1600 | switch (PyTuple_Size(args)) { 1601 | case 2: 1602 | if (!PyArg_ParseTuple(args,"ii;begin_y,begin_x",&begin_y,&begin_x)) 1603 | return NULL; 1604 | break; 1605 | case 4: 1606 | if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x", 1607 | &nlines,&ncols,&begin_y,&begin_x)) 1608 | return NULL; 1609 | break; 1610 | default: 1611 | PyErr_SetString(PyExc_TypeError, "subwin requires 2 or 4 arguments"); 1612 | return NULL; 1613 | } 1614 | 1615 | /* printf("Subwin: %i %i %i %i \n", nlines, ncols, begin_y, begin_x); */ 1616 | #ifdef WINDOW_HAS_FLAGS 1617 | if (self->win->_flags & _ISPAD) 1618 | win = subpad(self->win, nlines, ncols, begin_y, begin_x); 1619 | else 1620 | #endif 1621 | win = subwin(self->win, nlines, ncols, begin_y, begin_x); 1622 | 1623 | if (win == NULL) { 1624 | PyErr_SetString(PyCursesError, catchall_NULL); 1625 | return NULL; 1626 | } 1627 | 1628 | return (PyObject *)PyCursesWindow_New(win); 1629 | } 1630 | 1631 | static PyObject * 1632 | PyCursesWindow_Scroll(PyCursesWindowObject *self, PyObject *args) 1633 | { 1634 | int nlines; 1635 | switch(PyTuple_Size(args)) { 1636 | case 0: 1637 | return PyCursesCheckERR(scroll(self->win), "scroll"); 1638 | case 1: 1639 | if (!PyArg_ParseTuple(args, "i;nlines", &nlines)) 1640 | return NULL; 1641 | return PyCursesCheckERR(wscrl(self->win, nlines), "scroll"); 1642 | default: 1643 | PyErr_SetString(PyExc_TypeError, "scroll requires 0 or 1 arguments"); 1644 | return NULL; 1645 | } 1646 | } 1647 | 1648 | static PyObject * 1649 | PyCursesWindow_TouchLine(PyCursesWindowObject *self, PyObject *args) 1650 | { 1651 | int st, cnt, val; 1652 | switch (PyTuple_Size(args)) { 1653 | case 2: 1654 | if (!PyArg_ParseTuple(args,"ii;start,count",&st,&cnt)) 1655 | return NULL; 1656 | return PyCursesCheckERR(touchline(self->win,st,cnt), "touchline"); 1657 | case 3: 1658 | if (!PyArg_ParseTuple(args, "iii;start,count,val", &st, &cnt, &val)) 1659 | return NULL; 1660 | return PyCursesCheckERR(wtouchln(self->win, st, cnt, val), "touchline"); 1661 | default: 1662 | PyErr_SetString(PyExc_TypeError, "touchline requires 2 or 3 arguments"); 1663 | return NULL; 1664 | } 1665 | } 1666 | 1667 | static PyObject * 1668 | PyCursesWindow_Vline(PyCursesWindowObject *self, PyObject *args) 1669 | { 1670 | PyObject *temp; 1671 | chtype ch; 1672 | int n, x, y, code = OK; 1673 | attr_t attr = A_NORMAL; 1674 | long lattr; 1675 | 1676 | switch (PyTuple_Size(args)) { 1677 | case 2: 1678 | if (!PyArg_ParseTuple(args, "Oi;ch or int,n", &temp, &n)) 1679 | return NULL; 1680 | break; 1681 | case 3: 1682 | if (!PyArg_ParseTuple(args, "Oil;ch or int,n,attr", &temp, &n, &lattr)) 1683 | return NULL; 1684 | attr = lattr; 1685 | break; 1686 | case 4: 1687 | if (!PyArg_ParseTuple(args, "iiOi;y,x,ch or int,n", &y, &x, &temp, &n)) 1688 | return NULL; 1689 | code = wmove(self->win, y, x); 1690 | break; 1691 | case 5: 1692 | if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr", 1693 | &y, &x, &temp, &n, &lattr)) 1694 | return NULL; 1695 | attr = lattr; 1696 | code = wmove(self->win, y, x); 1697 | break; 1698 | default: 1699 | PyErr_SetString(PyExc_TypeError, "vline requires 2 to 5 arguments"); 1700 | return NULL; 1701 | } 1702 | 1703 | if (code != ERR) { 1704 | if (!PyCurses_ConvertToChtype(temp, &ch)) { 1705 | PyErr_SetString(PyExc_TypeError, 1706 | "argument 1 or 3 must be a ch or an int"); 1707 | return NULL; 1708 | } 1709 | return PyCursesCheckERR(wvline(self->win, ch | attr, n), "vline"); 1710 | } else 1711 | return PyCursesCheckERR(code, "wmove"); 1712 | } 1713 | 1714 | static PyMethodDef PyCursesWindow_Methods[] = { 1715 | {"addch", (PyCFunction)PyCursesWindow_AddCh, METH_VARARGS}, 1716 | {"addnstr", (PyCFunction)PyCursesWindow_AddNStr, METH_VARARGS}, 1717 | {"addstr", (PyCFunction)PyCursesWindow_AddStr, METH_VARARGS}, 1718 | {"attroff", (PyCFunction)PyCursesWindow_AttrOff, METH_VARARGS}, 1719 | {"attron", (PyCFunction)PyCursesWindow_AttrOn, METH_VARARGS}, 1720 | {"attrset", (PyCFunction)PyCursesWindow_AttrSet, METH_VARARGS}, 1721 | {"bkgd", (PyCFunction)PyCursesWindow_Bkgd, METH_VARARGS}, 1722 | {"chgat", (PyCFunction)PyCursesWindow_ChgAt, METH_VARARGS}, 1723 | {"bkgdset", (PyCFunction)PyCursesWindow_BkgdSet, METH_VARARGS}, 1724 | {"border", (PyCFunction)PyCursesWindow_Border, METH_VARARGS}, 1725 | {"box", (PyCFunction)PyCursesWindow_Box, METH_VARARGS}, 1726 | {"clear", (PyCFunction)PyCursesWindow_wclear, METH_NOARGS}, 1727 | {"clearok", (PyCFunction)PyCursesWindow_clearok, METH_VARARGS}, 1728 | {"clrtobot", (PyCFunction)PyCursesWindow_wclrtobot, METH_NOARGS}, 1729 | {"clrtoeol", (PyCFunction)PyCursesWindow_wclrtoeol, METH_NOARGS}, 1730 | {"cursyncup", (PyCFunction)PyCursesWindow_wcursyncup, METH_NOARGS}, 1731 | {"delch", (PyCFunction)PyCursesWindow_DelCh, METH_VARARGS}, 1732 | {"deleteln", (PyCFunction)PyCursesWindow_wdeleteln, METH_NOARGS}, 1733 | {"derwin", (PyCFunction)PyCursesWindow_DerWin, METH_VARARGS}, 1734 | {"echochar", (PyCFunction)PyCursesWindow_EchoChar, METH_VARARGS}, 1735 | #ifdef NCURSES_MOUSE_VERSION 1736 | {"enclose", (PyCFunction)PyCursesWindow_Enclose, METH_VARARGS}, 1737 | #endif 1738 | {"erase", (PyCFunction)PyCursesWindow_werase, METH_NOARGS}, 1739 | {"getbegyx", (PyCFunction)PyCursesWindow_getbegyx, METH_NOARGS}, 1740 | {"getbkgd", (PyCFunction)PyCursesWindow_GetBkgd, METH_NOARGS}, 1741 | {"getch", (PyCFunction)PyCursesWindow_GetCh, METH_VARARGS}, 1742 | {"getkey", (PyCFunction)PyCursesWindow_GetKey, METH_VARARGS}, 1743 | {"getmaxyx", (PyCFunction)PyCursesWindow_getmaxyx, METH_NOARGS}, 1744 | {"getparyx", (PyCFunction)PyCursesWindow_getparyx, METH_NOARGS}, 1745 | {"getstr", (PyCFunction)PyCursesWindow_GetStr, METH_VARARGS}, 1746 | {"getyx", (PyCFunction)PyCursesWindow_getyx, METH_NOARGS}, 1747 | {"hline", (PyCFunction)PyCursesWindow_Hline, METH_VARARGS}, 1748 | {"idcok", (PyCFunction)PyCursesWindow_idcok, METH_VARARGS}, 1749 | {"idlok", (PyCFunction)PyCursesWindow_idlok, METH_VARARGS}, 1750 | {"immedok", (PyCFunction)PyCursesWindow_immedok, METH_VARARGS}, 1751 | {"inch", (PyCFunction)PyCursesWindow_InCh, METH_VARARGS}, 1752 | {"insch", (PyCFunction)PyCursesWindow_InsCh, METH_VARARGS}, 1753 | {"insdelln", (PyCFunction)PyCursesWindow_winsdelln, METH_VARARGS}, 1754 | {"insertln", (PyCFunction)PyCursesWindow_winsertln, METH_NOARGS}, 1755 | {"insnstr", (PyCFunction)PyCursesWindow_InsNStr, METH_VARARGS}, 1756 | {"insstr", (PyCFunction)PyCursesWindow_InsStr, METH_VARARGS}, 1757 | {"instr", (PyCFunction)PyCursesWindow_InStr, METH_VARARGS}, 1758 | {"is_linetouched", (PyCFunction)PyCursesWindow_Is_LineTouched, METH_VARARGS}, 1759 | {"is_wintouched", (PyCFunction)PyCursesWindow_is_wintouched, METH_NOARGS}, 1760 | {"keypad", (PyCFunction)PyCursesWindow_keypad, METH_VARARGS}, 1761 | {"leaveok", (PyCFunction)PyCursesWindow_leaveok, METH_VARARGS}, 1762 | {"move", (PyCFunction)PyCursesWindow_wmove, METH_VARARGS}, 1763 | {"mvderwin", (PyCFunction)PyCursesWindow_mvderwin, METH_VARARGS}, 1764 | {"mvwin", (PyCFunction)PyCursesWindow_mvwin, METH_VARARGS}, 1765 | {"nodelay", (PyCFunction)PyCursesWindow_nodelay, METH_VARARGS}, 1766 | {"notimeout", (PyCFunction)PyCursesWindow_notimeout, METH_VARARGS}, 1767 | {"noutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh, METH_VARARGS}, 1768 | /* Backward compatibility alias -- remove in Python 2.3 */ 1769 | {"nooutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh, METH_VARARGS}, 1770 | {"overlay", (PyCFunction)PyCursesWindow_Overlay, METH_VARARGS}, 1771 | {"overwrite", (PyCFunction)PyCursesWindow_Overwrite, 1772 | METH_VARARGS}, 1773 | {"putwin", (PyCFunction)PyCursesWindow_PutWin, METH_VARARGS}, 1774 | {"redrawln", (PyCFunction)PyCursesWindow_RedrawLine, METH_VARARGS}, 1775 | {"redrawwin", (PyCFunction)PyCursesWindow_redrawwin, METH_NOARGS}, 1776 | {"refresh", (PyCFunction)PyCursesWindow_Refresh, METH_VARARGS}, 1777 | #ifndef STRICT_SYSV_CURSES 1778 | {"resize", (PyCFunction)PyCursesWindow_wresize, METH_VARARGS}, 1779 | #endif 1780 | {"scroll", (PyCFunction)PyCursesWindow_Scroll, METH_VARARGS}, 1781 | {"scrollok", (PyCFunction)PyCursesWindow_scrollok, METH_VARARGS}, 1782 | {"setscrreg", (PyCFunction)PyCursesWindow_SetScrollRegion, METH_VARARGS}, 1783 | {"standend", (PyCFunction)PyCursesWindow_wstandend, METH_NOARGS}, 1784 | {"standout", (PyCFunction)PyCursesWindow_wstandout, METH_NOARGS}, 1785 | {"subpad", (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS}, 1786 | {"subwin", (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS}, 1787 | {"syncdown", (PyCFunction)PyCursesWindow_wsyncdown, METH_NOARGS}, 1788 | {"syncok", (PyCFunction)PyCursesWindow_syncok, METH_VARARGS}, 1789 | {"syncup", (PyCFunction)PyCursesWindow_wsyncup, METH_NOARGS}, 1790 | {"timeout", (PyCFunction)PyCursesWindow_wtimeout, METH_VARARGS}, 1791 | {"touchline", (PyCFunction)PyCursesWindow_TouchLine, METH_VARARGS}, 1792 | {"touchwin", (PyCFunction)PyCursesWindow_touchwin, METH_NOARGS}, 1793 | {"untouchwin", (PyCFunction)PyCursesWindow_untouchwin, METH_NOARGS}, 1794 | {"vline", (PyCFunction)PyCursesWindow_Vline, METH_VARARGS}, 1795 | {NULL, NULL} /* sentinel */ 1796 | }; 1797 | 1798 | #if PY_MAJOR_VERSION < 3 1799 | static PyObject * 1800 | PyCursesWindow_GetAttr(PyCursesWindowObject *self, char *name) 1801 | { 1802 | return Py_FindMethod(PyCursesWindow_Methods, (PyObject *)self, name); 1803 | } 1804 | #endif 1805 | 1806 | /* -------------------------------------------------------*/ 1807 | 1808 | PyTypeObject PyCursesWindow_Type = { 1809 | PyVarObject_HEAD_INIT(NULL, 0) 1810 | "_curses.curses window", /*tp_name*/ 1811 | sizeof(PyCursesWindowObject), /*tp_basicsize*/ 1812 | 0, /*tp_itemsize*/ 1813 | /* methods */ 1814 | (destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/ 1815 | 0, /*tp_print*/ 1816 | #if PY_MAJOR_VERSION == 3 1817 | (getattrfunc)0, /*tp_getattr*/ 1818 | #else 1819 | (getattrfunc)PyCursesWindow_GetAttr, /*tp_getattr*/ 1820 | #endif 1821 | (setattrfunc)0, /*tp_setattr*/ 1822 | 0, /*tp_compare/tp_reserved*/ 1823 | 0, /*tp_repr*/ 1824 | 0, /*tp_as_number*/ 1825 | 0, /*tp_as_sequence*/ 1826 | 0, /*tp_as_mapping*/ 1827 | 0, /*tp_hash*/ 1828 | #if PY_MAJOR_VERSION == 3 1829 | 0, /*tp_call*/ 1830 | 0, /*tp_str*/ 1831 | 0, /*tp_getattro*/ 1832 | 0, /*tp_setattro*/ 1833 | 0, /*tp_as_buffer*/ 1834 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ 1835 | 0, /*tp_doc*/ 1836 | 0, /*tp_traverse*/ 1837 | 0, /*tp_clear*/ 1838 | 0, /*tp_richcompare*/ 1839 | 0, /*tp_weaklistoffset*/ 1840 | 0, /*tp_iter*/ 1841 | 0, /*tp_iternext*/ 1842 | PyCursesWindow_Methods, /*tp_methods*/ 1843 | #endif 1844 | }; 1845 | 1846 | /********************************************************************* 1847 | Global Functions 1848 | **********************************************************************/ 1849 | 1850 | NoArgNoReturnFunction(beep) 1851 | NoArgNoReturnFunction(def_prog_mode) 1852 | NoArgNoReturnFunction(def_shell_mode) 1853 | NoArgNoReturnFunction(doupdate) 1854 | NoArgNoReturnFunction(endwin) 1855 | NoArgNoReturnFunction(flash) 1856 | NoArgNoReturnFunction(nocbreak) 1857 | NoArgNoReturnFunction(noecho) 1858 | NoArgNoReturnFunction(nonl) 1859 | NoArgNoReturnFunction(noraw) 1860 | NoArgNoReturnFunction(reset_prog_mode) 1861 | NoArgNoReturnFunction(reset_shell_mode) 1862 | NoArgNoReturnFunction(resetty) 1863 | NoArgNoReturnFunction(savetty) 1864 | 1865 | NoArgOrFlagNoReturnFunction(cbreak) 1866 | NoArgOrFlagNoReturnFunction(echo) 1867 | NoArgOrFlagNoReturnFunction(nl) 1868 | NoArgOrFlagNoReturnFunction(raw) 1869 | 1870 | NoArgReturnIntFunction(baudrate) 1871 | NoArgReturnIntFunction(termattrs) 1872 | 1873 | NoArgReturnStringFunction(termname) 1874 | NoArgReturnStringFunction(longname) 1875 | 1876 | NoArgTrueFalseFunction(can_change_color) 1877 | NoArgTrueFalseFunction(has_colors) 1878 | NoArgTrueFalseFunction(has_ic) 1879 | NoArgTrueFalseFunction(has_il) 1880 | NoArgTrueFalseFunction(isendwin) 1881 | NoArgNoReturnVoidFunction(flushinp) 1882 | NoArgNoReturnVoidFunction(noqiflush) 1883 | 1884 | static PyObject * 1885 | PyCurses_filter(PyObject *self) 1886 | { 1887 | /* not checking for PyCursesInitialised here since filter() must 1888 | be called before initscr() */ 1889 | filter(); 1890 | Py_INCREF(Py_None); 1891 | return Py_None; 1892 | } 1893 | 1894 | static PyObject * 1895 | PyCurses_Color_Content(PyObject *self, PyObject *args) 1896 | { 1897 | short color,r,g,b; 1898 | 1899 | PyCursesInitialised; 1900 | PyCursesInitialisedColor; 1901 | 1902 | if (!PyArg_ParseTuple(args, "h:color_content", &color)) return NULL; 1903 | 1904 | if (color_content(color, &r, &g, &b) != ERR) 1905 | return Py_BuildValue("(iii)", r, g, b); 1906 | else { 1907 | PyErr_SetString(PyCursesError, 1908 | "Argument 1 was out of range. Check value of COLORS."); 1909 | return NULL; 1910 | } 1911 | } 1912 | 1913 | static PyObject * 1914 | PyCurses_color_pair(PyObject *self, PyObject *args) 1915 | { 1916 | int n; 1917 | 1918 | PyCursesInitialised; 1919 | PyCursesInitialisedColor; 1920 | 1921 | if (!PyArg_ParseTuple(args, "i:color_pair", &n)) return NULL; 1922 | #if PY_MAJOR_VERSION == 3 1923 | return PyLong_FromLong 1924 | #else 1925 | return PyInt_FromLong 1926 | #endif 1927 | (COLOR_PAIR(n)); 1928 | } 1929 | 1930 | static PyObject * 1931 | PyCurses_Curs_Set(PyObject *self, PyObject *args) 1932 | { 1933 | int vis,erg; 1934 | 1935 | PyCursesInitialised; 1936 | 1937 | if (!PyArg_ParseTuple(args, "i:curs_set", &vis)) return NULL; 1938 | 1939 | erg = curs_set(vis); 1940 | if (erg == ERR) return PyCursesCheckERR(erg, "curs_set"); 1941 | 1942 | #if PY_MAJOR_VERSION == 3 1943 | return PyLong_FromLong 1944 | #else 1945 | return PyInt_FromLong 1946 | #endif 1947 | ((long) erg); 1948 | } 1949 | 1950 | static PyObject * 1951 | PyCurses_Delay_Output(PyObject *self, PyObject *args) 1952 | { 1953 | int ms; 1954 | 1955 | PyCursesInitialised; 1956 | 1957 | if (!PyArg_ParseTuple(args, "i:delay_output", &ms)) return NULL; 1958 | 1959 | return PyCursesCheckERR(delay_output(ms), "delay_output"); 1960 | } 1961 | 1962 | static PyObject * 1963 | PyCurses_EraseChar(PyObject *self) 1964 | { 1965 | char ch; 1966 | 1967 | PyCursesInitialised; 1968 | 1969 | ch = erasechar(); 1970 | 1971 | #if PY_MAJOR_VERSION == 3 1972 | return PyUnicode_FromStringAndSize 1973 | #else 1974 | return PyString_FromStringAndSize 1975 | #endif 1976 | (&ch, 1); 1977 | } 1978 | 1979 | static PyObject * 1980 | PyCurses_getsyx(PyObject *self) 1981 | { 1982 | int x = 0; 1983 | int y = 0; 1984 | 1985 | PyCursesInitialised; 1986 | 1987 | getsyx(y, x); 1988 | 1989 | return Py_BuildValue("(ii)", y, x); 1990 | } 1991 | 1992 | #ifdef NCURSES_MOUSE_VERSION 1993 | static PyObject * 1994 | PyCurses_GetMouse(PyObject *self) 1995 | { 1996 | int rtn; 1997 | MEVENT event; 1998 | 1999 | PyCursesInitialised; 2000 | 2001 | rtn = getmouse( &event ); 2002 | if (rtn == ERR) { 2003 | PyErr_SetString(PyCursesError, "getmouse() returned ERR"); 2004 | return NULL; 2005 | } 2006 | return Py_BuildValue("(hiiil)", 2007 | (short)event.id, 2008 | event.x, event.y, event.z, 2009 | (long) event.bstate); 2010 | } 2011 | 2012 | static PyObject * 2013 | PyCurses_UngetMouse(PyObject *self, PyObject *args) 2014 | { 2015 | MEVENT event; 2016 | 2017 | PyCursesInitialised; 2018 | if (!PyArg_ParseTuple(args, "hiiil", 2019 | &event.id, 2020 | &event.x, &event.y, &event.z, 2021 | (int *) &event.bstate)) 2022 | return NULL; 2023 | 2024 | return PyCursesCheckERR(ungetmouse(&event), "ungetmouse"); 2025 | } 2026 | #endif 2027 | 2028 | #if PY_MAJOR_VERSION == 3 2029 | static PyObject * 2030 | PyCurses_GetWin(PyCursesWindowObject *self, PyObject *stream) 2031 | { 2032 | PyObject *data; 2033 | size_t datalen; 2034 | WINDOW *win; 2035 | 2036 | #ifdef _WIN32 2037 | TCHAR path[MAX_PATH]; 2038 | DWORD retval; 2039 | retval = GetTempPath(MAX_PATH, path); 2040 | if (retval == 0 || retval > MAX_PATH) 2041 | { 2042 | PyErr_SetString(PyExc_IOError, "couldn't find the temporary file path"); 2043 | return NULL; 2044 | } 2045 | 2046 | TCHAR fn[MAX_PATH]; 2047 | retval = GetTempFileName(path, TEXT("PY_curses"), 0, fn); 2048 | if (retval == 0) 2049 | { 2050 | PyErr_SetString(PyExc_IOError, "couldn't find temporary file name"); 2051 | return NULL; 2052 | } 2053 | 2054 | FILE *fp = _tfopen(fn, "wb+"); 2055 | #else 2056 | char fn[100]; 2057 | int fd; 2058 | FILE *fp; 2059 | 2060 | PyCursesInitialised 2061 | 2062 | strcpy(fn, "/tmp/py.curses.getwin.XXXXXX"); 2063 | fd = mkstemp(fn); 2064 | if (fd < 0) 2065 | return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); 2066 | fp = fdopen(fd, "wb+"); 2067 | #endif 2068 | if (fp == NULL) { 2069 | #ifdef _WIN32 2070 | _tremove(fn); 2071 | #else 2072 | close(fd); 2073 | remove(fn); 2074 | #endif 2075 | return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); 2076 | } 2077 | data = PyObject_CallMethod(stream, "read", ""); 2078 | if (data == NULL) { 2079 | fclose(fp); 2080 | 2081 | #ifdef _WIN32 2082 | _tremove(fn); 2083 | #else 2084 | remove(fn); 2085 | #endif 2086 | 2087 | return NULL; 2088 | } 2089 | if (!PyBytes_Check(data)) { 2090 | PyErr_Format(PyExc_TypeError, 2091 | "f.read() returned %.100s instead of bytes", 2092 | data->ob_type->tp_name); 2093 | Py_DECREF(data); 2094 | fclose(fp); 2095 | 2096 | #ifdef _WIN32 2097 | _tremove(fn); 2098 | #else 2099 | remove(fn); 2100 | #endif 2101 | 2102 | return NULL; 2103 | } 2104 | datalen = PyBytes_GET_SIZE(data); 2105 | if (fwrite(PyBytes_AS_STRING(data), 1, datalen, fp) != datalen) { 2106 | Py_DECREF(data); 2107 | fclose(fp); 2108 | 2109 | #ifdef _WIN32 2110 | _tremove(fn); 2111 | #else 2112 | remove(fn); 2113 | #endif 2114 | 2115 | return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); 2116 | } 2117 | Py_DECREF(data); 2118 | fseek(fp, 0, 0); 2119 | win = getwin(fp); 2120 | fclose(fp); 2121 | 2122 | #ifdef _WIN32 2123 | _tremove(fn); 2124 | #else 2125 | remove(fn); 2126 | #endif 2127 | 2128 | if (win == NULL) { 2129 | PyErr_SetString(PyCursesError, catchall_NULL); 2130 | return NULL; 2131 | } 2132 | return PyCursesWindow_New(win); 2133 | } 2134 | #else 2135 | static PyObject * 2136 | PyCurses_GetWin(PyCursesWindowObject *self, PyObject *temp) 2137 | { 2138 | WINDOW *win; 2139 | 2140 | PyCursesInitialised; 2141 | 2142 | if (!PyFile_Check(temp)) { 2143 | PyErr_SetString(PyExc_TypeError, "argument must be a file object"); 2144 | return NULL; 2145 | } 2146 | 2147 | win = getwin(PyFile_AsFile(temp)); 2148 | 2149 | if (win == NULL) { 2150 | PyErr_SetString(PyCursesError, catchall_NULL); 2151 | return NULL; 2152 | } 2153 | 2154 | return PyCursesWindow_New(win); 2155 | } 2156 | #endif 2157 | 2158 | static PyObject * 2159 | PyCurses_HalfDelay(PyObject *self, PyObject *args) 2160 | { 2161 | unsigned char tenths; 2162 | 2163 | PyCursesInitialised; 2164 | 2165 | if (!PyArg_ParseTuple(args, "b:halfdelay", &tenths)) return NULL; 2166 | 2167 | return PyCursesCheckERR(halfdelay(tenths), "halfdelay"); 2168 | } 2169 | 2170 | #ifndef STRICT_SYSV_CURSES 2171 | /* No has_key! */ 2172 | static PyObject * PyCurses_has_key(PyObject *self, PyObject *args) 2173 | { 2174 | int ch; 2175 | 2176 | PyCursesInitialised; 2177 | 2178 | if (!PyArg_ParseTuple(args,"i",&ch)) return NULL; 2179 | 2180 | if (has_key(ch) == FALSE) { 2181 | Py_INCREF(Py_False); 2182 | return Py_False; 2183 | } 2184 | Py_INCREF(Py_True); 2185 | return Py_True; 2186 | } 2187 | #endif /* STRICT_SYSV_CURSES */ 2188 | 2189 | static PyObject * 2190 | PyCurses_Init_Color(PyObject *self, PyObject *args) 2191 | { 2192 | short color, r, g, b; 2193 | 2194 | PyCursesInitialised; 2195 | PyCursesInitialisedColor; 2196 | 2197 | switch(PyTuple_Size(args)) { 2198 | case 4: 2199 | if (!PyArg_ParseTuple(args, "hhhh;color,r,g,b", &color, &r, &g, &b)) return NULL; 2200 | break; 2201 | default: 2202 | PyErr_SetString(PyExc_TypeError, "init_color requires 4 arguments"); 2203 | return NULL; 2204 | } 2205 | 2206 | return PyCursesCheckERR(init_color(color, r, g, b), "init_color"); 2207 | } 2208 | 2209 | static PyObject * 2210 | PyCurses_Init_Pair(PyObject *self, PyObject *args) 2211 | { 2212 | short pair, f, b; 2213 | 2214 | PyCursesInitialised; 2215 | PyCursesInitialisedColor; 2216 | 2217 | if (PyTuple_Size(args) != 3) { 2218 | PyErr_SetString(PyExc_TypeError, "init_pair requires 3 arguments"); 2219 | return NULL; 2220 | } 2221 | 2222 | if (!PyArg_ParseTuple(args, "hhh;pair, f, b", &pair, &f, &b)) return NULL; 2223 | 2224 | return PyCursesCheckERR(init_pair(pair, f, b), "init_pair"); 2225 | } 2226 | 2227 | static PyObject *ModDict; 2228 | 2229 | static PyObject * 2230 | PyCurses_InitScr(PyObject *self) 2231 | { 2232 | WINDOW *win; 2233 | 2234 | if (initialised == TRUE) { 2235 | wrefresh(stdscr); 2236 | return (PyObject *)PyCursesWindow_New(stdscr); 2237 | } 2238 | 2239 | win = initscr(); 2240 | 2241 | if (win == NULL) { 2242 | PyErr_SetString(PyCursesError, catchall_NULL); 2243 | return NULL; 2244 | } 2245 | 2246 | initialised = initialised_setupterm = TRUE; 2247 | 2248 | /* This was moved from initcurses() because it core dumped on SGI, 2249 | where they're not defined until you've called initscr() */ 2250 | #if PY_MAJOR_VERSION == 3 2251 | #define SetDictInt(string,ch) \ 2252 | do { \ 2253 | PyObject *o = PyLong_FromLong((long) (ch)); \ 2254 | if (o && PyDict_SetItemString(ModDict, string, o) == 0) { \ 2255 | Py_DECREF(o); \ 2256 | } \ 2257 | } while (0) 2258 | #else 2259 | #define SetDictInt(string,ch) \ 2260 | do { \ 2261 | PyObject *o = PyInt_FromLong((long) (ch)); \ 2262 | if (o && PyDict_SetItemString(ModDict, string, o) == 0) { \ 2263 | Py_DECREF(o); \ 2264 | } \ 2265 | } while (0) 2266 | #endif 2267 | 2268 | /* Here are some graphic symbols you can use */ 2269 | SetDictInt("ACS_ULCORNER", (ACS_ULCORNER)); 2270 | SetDictInt("ACS_LLCORNER", (ACS_LLCORNER)); 2271 | SetDictInt("ACS_URCORNER", (ACS_URCORNER)); 2272 | SetDictInt("ACS_LRCORNER", (ACS_LRCORNER)); 2273 | SetDictInt("ACS_LTEE", (ACS_LTEE)); 2274 | SetDictInt("ACS_RTEE", (ACS_RTEE)); 2275 | SetDictInt("ACS_BTEE", (ACS_BTEE)); 2276 | SetDictInt("ACS_TTEE", (ACS_TTEE)); 2277 | SetDictInt("ACS_HLINE", (ACS_HLINE)); 2278 | SetDictInt("ACS_VLINE", (ACS_VLINE)); 2279 | SetDictInt("ACS_PLUS", (ACS_PLUS)); 2280 | #if !defined(__hpux) || defined(HAVE_NCURSES_H) 2281 | /* On HP/UX 11, these are of type cchar_t, which is not an 2282 | integral type. If this is a problem on more platforms, a 2283 | configure test should be added to determine whether ACS_S1 2284 | is of integral type. */ 2285 | SetDictInt("ACS_S1", (ACS_S1)); 2286 | SetDictInt("ACS_S9", (ACS_S9)); 2287 | SetDictInt("ACS_DIAMOND", (ACS_DIAMOND)); 2288 | SetDictInt("ACS_CKBOARD", (ACS_CKBOARD)); 2289 | SetDictInt("ACS_DEGREE", (ACS_DEGREE)); 2290 | SetDictInt("ACS_PLMINUS", (ACS_PLMINUS)); 2291 | SetDictInt("ACS_BULLET", (ACS_BULLET)); 2292 | SetDictInt("ACS_LARROW", (ACS_LARROW)); 2293 | SetDictInt("ACS_RARROW", (ACS_RARROW)); 2294 | SetDictInt("ACS_DARROW", (ACS_DARROW)); 2295 | SetDictInt("ACS_UARROW", (ACS_UARROW)); 2296 | SetDictInt("ACS_BOARD", (ACS_BOARD)); 2297 | SetDictInt("ACS_LANTERN", (ACS_LANTERN)); 2298 | SetDictInt("ACS_BLOCK", (ACS_BLOCK)); 2299 | #endif 2300 | SetDictInt("ACS_BSSB", (ACS_ULCORNER)); 2301 | SetDictInt("ACS_SSBB", (ACS_LLCORNER)); 2302 | SetDictInt("ACS_BBSS", (ACS_URCORNER)); 2303 | SetDictInt("ACS_SBBS", (ACS_LRCORNER)); 2304 | SetDictInt("ACS_SBSS", (ACS_RTEE)); 2305 | SetDictInt("ACS_SSSB", (ACS_LTEE)); 2306 | SetDictInt("ACS_SSBS", (ACS_BTEE)); 2307 | SetDictInt("ACS_BSSS", (ACS_TTEE)); 2308 | SetDictInt("ACS_BSBS", (ACS_HLINE)); 2309 | SetDictInt("ACS_SBSB", (ACS_VLINE)); 2310 | SetDictInt("ACS_SSSS", (ACS_PLUS)); 2311 | 2312 | /* The following are never available with strict SYSV curses */ 2313 | #ifdef ACS_S3 2314 | SetDictInt("ACS_S3", (ACS_S3)); 2315 | #endif 2316 | #ifdef ACS_S7 2317 | SetDictInt("ACS_S7", (ACS_S7)); 2318 | #endif 2319 | #ifdef ACS_LEQUAL 2320 | SetDictInt("ACS_LEQUAL", (ACS_LEQUAL)); 2321 | #endif 2322 | #ifdef ACS_GEQUAL 2323 | SetDictInt("ACS_GEQUAL", (ACS_GEQUAL)); 2324 | #endif 2325 | #ifdef ACS_PI 2326 | SetDictInt("ACS_PI", (ACS_PI)); 2327 | #endif 2328 | #ifdef ACS_NEQUAL 2329 | SetDictInt("ACS_NEQUAL", (ACS_NEQUAL)); 2330 | #endif 2331 | #ifdef ACS_STERLING 2332 | SetDictInt("ACS_STERLING", (ACS_STERLING)); 2333 | #endif 2334 | 2335 | SetDictInt("LINES", LINES); 2336 | SetDictInt("COLS", COLS); 2337 | 2338 | return (PyObject *)PyCursesWindow_New(win); 2339 | } 2340 | 2341 | static PyObject * 2342 | PyCurses_setupterm(PyObject* self, PyObject *args, PyObject* keywds) 2343 | { 2344 | int fd = -1; 2345 | int err; 2346 | char* termstr = NULL; 2347 | 2348 | static char *kwlist[] = {"term", "fd", NULL}; 2349 | 2350 | if (!PyArg_ParseTupleAndKeywords( 2351 | args, keywds, "|zi:setupterm", kwlist, &termstr, &fd)) { 2352 | return NULL; 2353 | } 2354 | 2355 | if (fd == -1) { 2356 | PyObject* sys_stdout; 2357 | 2358 | sys_stdout = PySys_GetObject("stdout"); 2359 | 2360 | if (sys_stdout == NULL 2361 | #if PY_MAJOR_VERSION == 3 2362 | || sys_stdout == Py_None 2363 | #endif 2364 | ) 2365 | { 2366 | PyErr_SetString( 2367 | PyCursesError, 2368 | "lost sys.stdout"); 2369 | return NULL; 2370 | } 2371 | 2372 | fd = PyObject_AsFileDescriptor(sys_stdout); 2373 | 2374 | if (fd == -1) { 2375 | return NULL; 2376 | } 2377 | } 2378 | 2379 | #ifndef _WIN32 2380 | if (setupterm(termstr,fd,&err) == ERR) { 2381 | char* s = "setupterm: unknown error"; 2382 | 2383 | if (err == 0) { 2384 | s = "setupterm: could not find terminal"; 2385 | } else if (err == -1) { 2386 | s = "setupterm: could not find terminfo database"; 2387 | } 2388 | 2389 | PyErr_SetString(PyCursesError,s); 2390 | return NULL; 2391 | } 2392 | #else 2393 | UNUSED(err); 2394 | #endif 2395 | 2396 | initialised_setupterm = TRUE; 2397 | 2398 | Py_INCREF(Py_None); 2399 | return Py_None; 2400 | } 2401 | 2402 | static PyObject * 2403 | PyCurses_IntrFlush(PyObject *self, PyObject *args) 2404 | { 2405 | int ch; 2406 | 2407 | PyCursesInitialised; 2408 | 2409 | switch(PyTuple_Size(args)) { 2410 | case 1: 2411 | if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&ch)) return NULL; 2412 | break; 2413 | default: 2414 | PyErr_SetString(PyExc_TypeError, "intrflush requires 1 argument"); 2415 | return NULL; 2416 | } 2417 | 2418 | return PyCursesCheckERR(intrflush(NULL,ch), "intrflush"); 2419 | } 2420 | 2421 | #ifdef HAVE_CURSES_IS_TERM_RESIZED 2422 | static PyObject * 2423 | PyCurses_Is_Term_Resized(PyObject *self, PyObject *args) 2424 | { 2425 | int lines; 2426 | int columns; 2427 | int result; 2428 | 2429 | PyCursesInitialised; 2430 | 2431 | if (!PyArg_ParseTuple(args,"ii:is_term_resized", &lines, &columns)) 2432 | return NULL; 2433 | result = is_term_resized(lines, columns); 2434 | if (result == TRUE) { 2435 | Py_INCREF(Py_True); 2436 | return Py_True; 2437 | } else { 2438 | Py_INCREF(Py_False); 2439 | return Py_False; 2440 | } 2441 | } 2442 | #endif /* HAVE_CURSES_IS_TERM_RESIZED */ 2443 | 2444 | #if !defined(__NetBSD__) 2445 | static PyObject * 2446 | PyCurses_KeyName(PyObject *self, PyObject *args) 2447 | { 2448 | const char *knp; 2449 | int ch; 2450 | 2451 | PyCursesInitialised; 2452 | 2453 | if (!PyArg_ParseTuple(args,"i",&ch)) return NULL; 2454 | 2455 | if (ch < 0) { 2456 | PyErr_SetString(PyExc_ValueError, "invalid key number"); 2457 | return NULL; 2458 | } 2459 | knp = keyname(ch); 2460 | 2461 | #if PY_MAJOR_VERSION == 3 2462 | return PyUnicode_FromString 2463 | #else 2464 | return PyString_FromString 2465 | #endif 2466 | ((knp == NULL) ? "" : (char *)knp); 2467 | } 2468 | #endif 2469 | 2470 | static PyObject * 2471 | PyCurses_KillChar(PyObject *self) 2472 | { 2473 | char ch; 2474 | 2475 | ch = killchar(); 2476 | 2477 | #if PY_MAJOR_VERSION == 3 2478 | return PyUnicode_FromStringAndSize 2479 | #else 2480 | return PyString_FromStringAndSize 2481 | #endif 2482 | (&ch, 1); 2483 | } 2484 | 2485 | static PyObject * 2486 | PyCurses_Meta(PyObject *self, PyObject *args) 2487 | { 2488 | int ch; 2489 | 2490 | PyCursesInitialised; 2491 | 2492 | switch(PyTuple_Size(args)) { 2493 | case 1: 2494 | if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&ch)) return NULL; 2495 | break; 2496 | default: 2497 | PyErr_SetString(PyExc_TypeError, "meta requires 1 argument"); 2498 | return NULL; 2499 | } 2500 | 2501 | return PyCursesCheckERR(meta(stdscr, ch), "meta"); 2502 | } 2503 | 2504 | #ifdef NCURSES_MOUSE_VERSION 2505 | static PyObject * 2506 | PyCurses_MouseInterval(PyObject *self, PyObject *args) 2507 | { 2508 | int interval; 2509 | PyCursesInitialised; 2510 | 2511 | if (!PyArg_ParseTuple(args,"i;interval",&interval)) 2512 | return NULL; 2513 | return PyCursesCheckERR(mouseinterval(interval), "mouseinterval"); 2514 | } 2515 | 2516 | static PyObject * 2517 | PyCurses_MouseMask(PyObject *self, PyObject *args) 2518 | { 2519 | int newmask; 2520 | mmask_t oldmask, availmask; 2521 | 2522 | PyCursesInitialised; 2523 | if (!PyArg_ParseTuple(args,"i;mousemask",&newmask)) 2524 | return NULL; 2525 | availmask = mousemask(newmask, &oldmask); 2526 | return Py_BuildValue("(ll)", (long)availmask, (long)oldmask); 2527 | } 2528 | #endif 2529 | 2530 | static PyObject * 2531 | PyCurses_Napms(PyObject *self, PyObject *args) 2532 | { 2533 | int ms; 2534 | 2535 | PyCursesInitialised; 2536 | if (!PyArg_ParseTuple(args, "i;ms", &ms)) return NULL; 2537 | 2538 | return Py_BuildValue("i", napms(ms)); 2539 | } 2540 | 2541 | 2542 | static PyObject * 2543 | PyCurses_NewPad(PyObject *self, PyObject *args) 2544 | { 2545 | WINDOW *win; 2546 | int nlines, ncols; 2547 | 2548 | PyCursesInitialised; 2549 | 2550 | if (!PyArg_ParseTuple(args,"ii;nlines,ncols",&nlines,&ncols)) return NULL; 2551 | 2552 | win = newpad(nlines, ncols); 2553 | 2554 | if (win == NULL) { 2555 | PyErr_SetString(PyCursesError, catchall_NULL); 2556 | return NULL; 2557 | } 2558 | 2559 | return (PyObject *)PyCursesWindow_New(win); 2560 | } 2561 | 2562 | static PyObject * 2563 | PyCurses_NewWindow(PyObject *self, PyObject *args) 2564 | { 2565 | WINDOW *win; 2566 | int nlines, ncols, begin_y=0, begin_x=0; 2567 | 2568 | PyCursesInitialised; 2569 | 2570 | switch (PyTuple_Size(args)) { 2571 | case 2: 2572 | if (!PyArg_ParseTuple(args,"ii;nlines,ncols",&nlines,&ncols)) 2573 | return NULL; 2574 | break; 2575 | case 4: 2576 | if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x", 2577 | &nlines,&ncols,&begin_y,&begin_x)) 2578 | return NULL; 2579 | break; 2580 | default: 2581 | PyErr_SetString(PyExc_TypeError, "newwin requires 2 or 4 arguments"); 2582 | return NULL; 2583 | } 2584 | 2585 | win = newwin(nlines,ncols,begin_y,begin_x); 2586 | if (win == NULL) { 2587 | PyErr_SetString(PyCursesError, catchall_NULL); 2588 | return NULL; 2589 | } 2590 | 2591 | return (PyObject *)PyCursesWindow_New(win); 2592 | } 2593 | 2594 | static PyObject * 2595 | PyCurses_Pair_Content(PyObject *self, PyObject *args) 2596 | { 2597 | short pair,f,b; 2598 | 2599 | PyCursesInitialised; 2600 | PyCursesInitialisedColor; 2601 | 2602 | switch(PyTuple_Size(args)) { 2603 | case 1: 2604 | if (!PyArg_ParseTuple(args, "h;pair", &pair)) return NULL; 2605 | break; 2606 | default: 2607 | PyErr_SetString(PyExc_TypeError, "pair_content requires 1 argument"); 2608 | return NULL; 2609 | } 2610 | 2611 | if (pair_content(pair, &f, &b)==ERR) { 2612 | PyErr_SetString(PyCursesError, 2613 | "Argument 1 was out of range. (1..COLOR_PAIRS-1)"); 2614 | return NULL; 2615 | } 2616 | 2617 | return Py_BuildValue("(ii)", f, b); 2618 | } 2619 | 2620 | static PyObject * 2621 | PyCurses_pair_number(PyObject *self, PyObject *args) 2622 | { 2623 | int n; 2624 | 2625 | PyCursesInitialised; 2626 | PyCursesInitialisedColor; 2627 | 2628 | switch(PyTuple_Size(args)) { 2629 | case 1: 2630 | if (!PyArg_ParseTuple(args, "i;pairvalue", &n)) return NULL; 2631 | break; 2632 | default: 2633 | PyErr_SetString(PyExc_TypeError, 2634 | "pair_number requires 1 argument"); 2635 | return NULL; 2636 | } 2637 | #if PY_MAJOR_VERSION == 3 2638 | return PyLong_FromLong 2639 | #else 2640 | return PyInt_FromLong 2641 | #endif 2642 | ((long) ((n & A_COLOR) >> 8)); 2643 | } 2644 | 2645 | static PyObject * 2646 | PyCurses_Putp(PyObject *self, PyObject *args) 2647 | { 2648 | char *str; 2649 | 2650 | if (!PyArg_ParseTuple(args,"s;str", &str)) return NULL; 2651 | return PyCursesCheckERR(putp(str), "putp"); 2652 | } 2653 | 2654 | static PyObject * 2655 | PyCurses_QiFlush(PyObject *self, PyObject *args) 2656 | { 2657 | int flag = 0; 2658 | 2659 | PyCursesInitialised; 2660 | 2661 | switch(PyTuple_Size(args)) { 2662 | case 0: 2663 | qiflush(); 2664 | Py_INCREF(Py_None); 2665 | return Py_None; 2666 | case 1: 2667 | if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL; 2668 | if (flag) qiflush(); 2669 | else noqiflush(); 2670 | Py_INCREF(Py_None); 2671 | return Py_None; 2672 | default: 2673 | PyErr_SetString(PyExc_TypeError, "qiflush requires 0 or 1 arguments"); 2674 | return NULL; 2675 | } 2676 | } 2677 | 2678 | /* Internal helper used for updating curses.LINES, curses.COLS, _curses.LINES 2679 | * and _curses.COLS */ 2680 | #if defined(HAVE_CURSES_RESIZETERM) || defined(HAVE_CURSES_RESIZE_TERM) 2681 | static int 2682 | update_lines_cols(void) 2683 | { 2684 | PyObject *o; 2685 | PyObject *m = PyImport_ImportModuleNoBlock("curses"); 2686 | 2687 | if (!m) 2688 | return 0; 2689 | #if PY_MAJOR_VERSION == 3 2690 | o = PyLong_FromLong 2691 | #else 2692 | o = PyInt_FromLong 2693 | #endif 2694 | (LINES); 2695 | 2696 | if (!o) { 2697 | Py_DECREF(m); 2698 | return 0; 2699 | } 2700 | if (PyObject_SetAttrString(m, "LINES", o)) { 2701 | Py_DECREF(m); 2702 | Py_DECREF(o); 2703 | return 0; 2704 | } 2705 | if (PyDict_SetItemString(ModDict, "LINES", o)) { 2706 | Py_DECREF(m); 2707 | Py_DECREF(o); 2708 | return 0; 2709 | } 2710 | Py_DECREF(o); 2711 | 2712 | #if PY_MAJOR_VERSION == 3 2713 | o = PyLong_FromLong 2714 | #else 2715 | o = PyInt_FromLong 2716 | #endif 2717 | (COLS); 2718 | 2719 | if (!o) { 2720 | Py_DECREF(m); 2721 | return 0; 2722 | } 2723 | if (PyObject_SetAttrString(m, "COLS", o)) { 2724 | Py_DECREF(m); 2725 | Py_DECREF(o); 2726 | return 0; 2727 | } 2728 | if (PyDict_SetItemString(ModDict, "COLS", o)) { 2729 | Py_DECREF(m); 2730 | Py_DECREF(o); 2731 | return 0; 2732 | } 2733 | Py_DECREF(o); 2734 | Py_DECREF(m); 2735 | return 1; 2736 | } 2737 | #endif 2738 | 2739 | #ifdef HAVE_CURSES_RESIZETERM 2740 | static PyObject * 2741 | PyCurses_ResizeTerm(PyObject *self, PyObject *args) 2742 | { 2743 | int lines; 2744 | int columns; 2745 | PyObject *result; 2746 | 2747 | PyCursesInitialised; 2748 | 2749 | if (!PyArg_ParseTuple(args,"ii:resizeterm", &lines, &columns)) 2750 | return NULL; 2751 | 2752 | result = PyCursesCheckERR(resizeterm(lines, columns), "resizeterm"); 2753 | if (!result) 2754 | return NULL; 2755 | if (!update_lines_cols()) 2756 | return NULL; 2757 | return result; 2758 | } 2759 | 2760 | #endif 2761 | 2762 | #ifdef HAVE_CURSES_RESIZE_TERM 2763 | static PyObject * 2764 | PyCurses_Resize_Term(PyObject *self, PyObject *args) 2765 | { 2766 | int lines; 2767 | int columns; 2768 | 2769 | PyObject *result; 2770 | 2771 | PyCursesInitialised; 2772 | 2773 | if (!PyArg_ParseTuple(args,"ii:resize_term", &lines, &columns)) 2774 | return NULL; 2775 | 2776 | result = PyCursesCheckERR(resize_term(lines, columns), "resize_term"); 2777 | if (!result) 2778 | return NULL; 2779 | if (!update_lines_cols()) 2780 | return NULL; 2781 | return result; 2782 | } 2783 | #endif /* HAVE_CURSES_RESIZE_TERM */ 2784 | 2785 | static PyObject * 2786 | PyCurses_setsyx(PyObject *self, PyObject *args) 2787 | { 2788 | int y,x; 2789 | 2790 | PyCursesInitialised; 2791 | 2792 | if (PyTuple_Size(args)!=2) { 2793 | PyErr_SetString(PyExc_TypeError, "setsyx requires 2 arguments"); 2794 | return NULL; 2795 | } 2796 | 2797 | if (!PyArg_ParseTuple(args, "ii;y, x", &y, &x)) return NULL; 2798 | 2799 | setsyx(y,x); 2800 | 2801 | Py_INCREF(Py_None); 2802 | return Py_None; 2803 | } 2804 | 2805 | static PyObject * 2806 | PyCurses_Start_Color(PyObject *self) 2807 | { 2808 | int code; 2809 | PyObject *c, *cp; 2810 | 2811 | PyCursesInitialised; 2812 | 2813 | code = start_color(); 2814 | if (code != ERR) { 2815 | initialisedcolors = TRUE; 2816 | #if PY_MAJOR_VERSION == 3 2817 | c = PyLong_FromLong 2818 | #else 2819 | c = PyInt_FromLong 2820 | #endif 2821 | ((long) COLORS); 2822 | 2823 | PyDict_SetItemString(ModDict, "COLORS", c); 2824 | Py_DECREF(c); 2825 | 2826 | #if PY_MAJOR_VERSION == 3 2827 | cp = PyLong_FromLong 2828 | #else 2829 | cp = PyInt_FromLong 2830 | #endif 2831 | ((long) COLOR_PAIRS); 2832 | 2833 | PyDict_SetItemString(ModDict, "COLOR_PAIRS", cp); 2834 | Py_DECREF(cp); 2835 | Py_INCREF(Py_None); 2836 | return Py_None; 2837 | } else { 2838 | PyErr_SetString(PyCursesError, "start_color() returned ERR"); 2839 | return NULL; 2840 | } 2841 | } 2842 | 2843 | static PyObject * 2844 | PyCurses_tigetflag(PyObject *self, PyObject *args) 2845 | { 2846 | char *capname; 2847 | 2848 | PyCursesSetupTermCalled; 2849 | 2850 | if (!PyArg_ParseTuple(args, "s", &capname)) 2851 | return NULL; 2852 | 2853 | #if PY_MAJOR_VERSION == 3 2854 | return PyLong_FromLong 2855 | #else 2856 | return PyInt_FromLong 2857 | #endif 2858 | ( (long) tigetflag( capname ) ); 2859 | } 2860 | 2861 | static PyObject * 2862 | PyCurses_tigetnum(PyObject *self, PyObject *args) 2863 | { 2864 | char *capname; 2865 | 2866 | PyCursesSetupTermCalled; 2867 | 2868 | if (!PyArg_ParseTuple(args, "s", &capname)) 2869 | return NULL; 2870 | 2871 | #if PY_MAJOR_VERSION == 3 2872 | return PyLong_FromLong 2873 | #else 2874 | return PyInt_FromLong 2875 | #endif 2876 | ( (long) tigetnum( capname ) ); 2877 | } 2878 | 2879 | static PyObject * 2880 | PyCurses_tigetstr(PyObject *self, PyObject *args) 2881 | { 2882 | char *capname; 2883 | 2884 | PyCursesSetupTermCalled; 2885 | 2886 | if (!PyArg_ParseTuple(args, "s", &capname)) 2887 | return NULL; 2888 | 2889 | capname = tigetstr( capname ); 2890 | if (capname == 0 || capname == (char*) -1) { 2891 | Py_INCREF(Py_None); 2892 | return Py_None; 2893 | } 2894 | 2895 | #if PY_MAJOR_VERSION == 3 2896 | return PyUnicode_FromString 2897 | #else 2898 | return PyString_FromString 2899 | #endif 2900 | ( capname ); 2901 | } 2902 | 2903 | static PyObject * 2904 | PyCurses_tparm(PyObject *self, PyObject *args) 2905 | { 2906 | char* fmt; 2907 | char* result = NULL; 2908 | int i1=0,i2=0,i3=0,i4=0,i5=0,i6=0,i7=0,i8=0,i9=0; 2909 | 2910 | PyCursesSetupTermCalled; 2911 | 2912 | if (!PyArg_ParseTuple(args, "s|iiiiiiiii:tparm", 2913 | &fmt, &i1, &i2, &i3, &i4, 2914 | &i5, &i6, &i7, &i8, &i9)) { 2915 | return NULL; 2916 | } 2917 | 2918 | result = tparm(fmt,i1,i2,i3,i4,i5,i6,i7,i8,i9); 2919 | if (!result) { 2920 | PyErr_SetString(PyCursesError, "tparm() returned NULL"); 2921 | return NULL; 2922 | } 2923 | 2924 | #if PY_MAJOR_VERSION == 3 2925 | return PyUnicode_FromString 2926 | #else 2927 | return PyString_FromString 2928 | #endif 2929 | (result); 2930 | } 2931 | 2932 | static PyObject * 2933 | PyCurses_TypeAhead(PyObject *self, PyObject *args) 2934 | { 2935 | int fd; 2936 | 2937 | PyCursesInitialised; 2938 | 2939 | if (!PyArg_ParseTuple(args,"i;fd",&fd)) return NULL; 2940 | 2941 | return PyCursesCheckERR(typeahead( fd ), "typeahead"); 2942 | } 2943 | 2944 | #if PY_MAJOR_VERSION == 3 2945 | static PyObject * 2946 | PyCurses_UnCtrl(PyObject *self, PyObject *args) 2947 | { 2948 | PyObject *temp; 2949 | chtype ch; 2950 | 2951 | PyCursesInitialised 2952 | 2953 | if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL; 2954 | 2955 | if (!PyCurses_ConvertToChtype(temp, &ch)) { 2956 | PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int"); 2957 | return NULL; 2958 | } 2959 | 2960 | return PyBytes_FromString(unctrl(ch)); 2961 | } 2962 | #else 2963 | static PyObject * 2964 | PyCurses_UnCtrl(PyObject *self, PyObject *args) 2965 | { 2966 | PyObject *temp; 2967 | chtype ch; 2968 | 2969 | PyCursesInitialised; 2970 | 2971 | if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL; 2972 | 2973 | if (PyInt_Check(temp)) 2974 | ch = (chtype) PyInt_AsLong(temp); 2975 | else if (PyString_Check(temp)) 2976 | ch = (chtype) *PyString_AsString(temp); 2977 | else { 2978 | PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int"); 2979 | return NULL; 2980 | } 2981 | 2982 | return PyString_FromString(unctrl(ch)); 2983 | } 2984 | #endif 2985 | 2986 | #if PY_MAJOR_VERSION == 3 2987 | static PyObject * 2988 | PyCurses_UngetCh(PyObject *self, PyObject *args) 2989 | { 2990 | PyObject *temp; 2991 | chtype ch; 2992 | 2993 | PyCursesInitialised 2994 | 2995 | if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL; 2996 | 2997 | if (!PyCurses_ConvertToChtype(temp, &ch)) { 2998 | PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int"); 2999 | return NULL; 3000 | } 3001 | 3002 | return PyCursesCheckERR(ungetch(ch), "ungetch"); 3003 | } 3004 | #else 3005 | static PyObject * 3006 | PyCurses_UngetCh(PyObject *self, PyObject *args) 3007 | { 3008 | PyObject *temp; 3009 | int ch; 3010 | 3011 | PyCursesInitialised; 3012 | 3013 | if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL; 3014 | 3015 | if (PyInt_Check(temp)) 3016 | ch = (int) PyInt_AsLong(temp); 3017 | else if (PyString_Check(temp)) 3018 | ch = (int) *PyString_AsString(temp); 3019 | else { 3020 | PyErr_SetString(PyExc_TypeError, "argument must be a ch or an int"); 3021 | return NULL; 3022 | } 3023 | 3024 | return PyCursesCheckERR(ungetch(ch), "ungetch"); 3025 | } 3026 | #endif 3027 | 3028 | static PyObject * 3029 | PyCurses_Use_Env(PyObject *self, PyObject *args) 3030 | { 3031 | int flag; 3032 | 3033 | switch(PyTuple_Size(args)) { 3034 | case 1: 3035 | if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&flag)) 3036 | return NULL; 3037 | break; 3038 | default: 3039 | PyErr_SetString(PyExc_TypeError, "use_env requires 1 argument"); 3040 | return NULL; 3041 | } 3042 | use_env(flag); 3043 | Py_INCREF(Py_None); 3044 | return Py_None; 3045 | } 3046 | 3047 | #ifndef STRICT_SYSV_CURSES 3048 | static PyObject * 3049 | PyCurses_Use_Default_Colors(PyObject *self) 3050 | { 3051 | int code; 3052 | 3053 | PyCursesInitialised; 3054 | PyCursesInitialisedColor; 3055 | 3056 | code = use_default_colors(); 3057 | if (code != ERR) { 3058 | Py_INCREF(Py_None); 3059 | return Py_None; 3060 | } else { 3061 | PyErr_SetString(PyCursesError, "use_default_colors() returned ERR"); 3062 | return NULL; 3063 | } 3064 | } 3065 | #endif /* STRICT_SYSV_CURSES */ 3066 | 3067 | /* List of functions defined in the module */ 3068 | 3069 | static PyMethodDef PyCurses_methods[] = { 3070 | {"baudrate", (PyCFunction)PyCurses_baudrate, METH_NOARGS}, 3071 | {"beep", (PyCFunction)PyCurses_beep, METH_NOARGS}, 3072 | {"can_change_color", (PyCFunction)PyCurses_can_change_color, METH_NOARGS}, 3073 | {"cbreak", (PyCFunction)PyCurses_cbreak, METH_VARARGS}, 3074 | {"color_content", (PyCFunction)PyCurses_Color_Content, METH_VARARGS}, 3075 | {"color_pair", (PyCFunction)PyCurses_color_pair, METH_VARARGS}, 3076 | {"curs_set", (PyCFunction)PyCurses_Curs_Set, METH_VARARGS}, 3077 | {"def_prog_mode", (PyCFunction)PyCurses_def_prog_mode, METH_NOARGS}, 3078 | {"def_shell_mode", (PyCFunction)PyCurses_def_shell_mode, METH_NOARGS}, 3079 | {"delay_output", (PyCFunction)PyCurses_Delay_Output, METH_VARARGS}, 3080 | {"doupdate", (PyCFunction)PyCurses_doupdate, METH_NOARGS}, 3081 | {"echo", (PyCFunction)PyCurses_echo, METH_VARARGS}, 3082 | {"endwin", (PyCFunction)PyCurses_endwin, METH_NOARGS}, 3083 | {"erasechar", (PyCFunction)PyCurses_EraseChar, METH_NOARGS}, 3084 | {"filter", (PyCFunction)PyCurses_filter, METH_NOARGS}, 3085 | {"flash", (PyCFunction)PyCurses_flash, METH_NOARGS}, 3086 | {"flushinp", (PyCFunction)PyCurses_flushinp, METH_NOARGS}, 3087 | #ifdef NCURSES_MOUSE_VERSION 3088 | {"getmouse", (PyCFunction)PyCurses_GetMouse, METH_NOARGS}, 3089 | {"ungetmouse", (PyCFunction)PyCurses_UngetMouse, METH_VARARGS}, 3090 | #endif 3091 | {"getsyx", (PyCFunction)PyCurses_getsyx, METH_NOARGS}, 3092 | {"getwin", (PyCFunction)PyCurses_GetWin, METH_O}, 3093 | {"has_colors", (PyCFunction)PyCurses_has_colors, METH_NOARGS}, 3094 | {"has_ic", (PyCFunction)PyCurses_has_ic, METH_NOARGS}, 3095 | {"has_il", (PyCFunction)PyCurses_has_il, METH_NOARGS}, 3096 | #ifndef STRICT_SYSV_CURSES 3097 | {"has_key", (PyCFunction)PyCurses_has_key, METH_VARARGS}, 3098 | #endif 3099 | {"halfdelay", (PyCFunction)PyCurses_HalfDelay, METH_VARARGS}, 3100 | {"init_color", (PyCFunction)PyCurses_Init_Color, METH_VARARGS}, 3101 | {"init_pair", (PyCFunction)PyCurses_Init_Pair, METH_VARARGS}, 3102 | {"initscr", (PyCFunction)PyCurses_InitScr, METH_NOARGS}, 3103 | {"intrflush", (PyCFunction)PyCurses_IntrFlush, METH_VARARGS}, 3104 | {"isendwin", (PyCFunction)PyCurses_isendwin, METH_NOARGS}, 3105 | #ifdef HAVE_CURSES_IS_TERM_RESIZED 3106 | {"is_term_resized", (PyCFunction)PyCurses_Is_Term_Resized, METH_VARARGS}, 3107 | #endif 3108 | #if !defined(__NetBSD__) 3109 | {"keyname", (PyCFunction)PyCurses_KeyName, METH_VARARGS}, 3110 | #endif 3111 | {"killchar", (PyCFunction)PyCurses_KillChar, METH_NOARGS}, 3112 | {"longname", (PyCFunction)PyCurses_longname, METH_NOARGS}, 3113 | {"meta", (PyCFunction)PyCurses_Meta, METH_VARARGS}, 3114 | #ifdef NCURSES_MOUSE_VERSION 3115 | {"mouseinterval", (PyCFunction)PyCurses_MouseInterval, METH_VARARGS}, 3116 | {"mousemask", (PyCFunction)PyCurses_MouseMask, METH_VARARGS}, 3117 | #endif 3118 | {"napms", (PyCFunction)PyCurses_Napms, METH_VARARGS}, 3119 | {"newpad", (PyCFunction)PyCurses_NewPad, METH_VARARGS}, 3120 | {"newwin", (PyCFunction)PyCurses_NewWindow, METH_VARARGS}, 3121 | {"nl", (PyCFunction)PyCurses_nl, METH_VARARGS}, 3122 | {"nocbreak", (PyCFunction)PyCurses_nocbreak, METH_NOARGS}, 3123 | {"noecho", (PyCFunction)PyCurses_noecho, METH_NOARGS}, 3124 | {"nonl", (PyCFunction)PyCurses_nonl, METH_NOARGS}, 3125 | {"noqiflush", (PyCFunction)PyCurses_noqiflush, METH_NOARGS}, 3126 | {"noraw", (PyCFunction)PyCurses_noraw, METH_NOARGS}, 3127 | {"pair_content", (PyCFunction)PyCurses_Pair_Content, METH_VARARGS}, 3128 | {"pair_number", (PyCFunction)PyCurses_pair_number, METH_VARARGS}, 3129 | {"putp", (PyCFunction)PyCurses_Putp, METH_VARARGS}, 3130 | {"qiflush", (PyCFunction)PyCurses_QiFlush, METH_VARARGS}, 3131 | {"raw", (PyCFunction)PyCurses_raw, METH_VARARGS}, 3132 | {"reset_prog_mode", (PyCFunction)PyCurses_reset_prog_mode, METH_NOARGS}, 3133 | {"reset_shell_mode", (PyCFunction)PyCurses_reset_shell_mode, METH_NOARGS}, 3134 | {"resetty", (PyCFunction)PyCurses_resetty, METH_NOARGS}, 3135 | #ifdef HAVE_CURSES_RESIZETERM 3136 | {"resizeterm", (PyCFunction)PyCurses_ResizeTerm, METH_VARARGS}, 3137 | #endif 3138 | #ifdef HAVE_CURSES_RESIZE_TERM 3139 | {"resize_term", (PyCFunction)PyCurses_Resize_Term, METH_VARARGS}, 3140 | #endif 3141 | {"savetty", (PyCFunction)PyCurses_savetty, METH_NOARGS}, 3142 | {"setsyx", (PyCFunction)PyCurses_setsyx, METH_VARARGS}, 3143 | {"setupterm", (PyCFunction)PyCurses_setupterm, 3144 | METH_VARARGS|METH_KEYWORDS}, 3145 | {"start_color", (PyCFunction)PyCurses_Start_Color, METH_NOARGS}, 3146 | {"termattrs", (PyCFunction)PyCurses_termattrs, METH_NOARGS}, 3147 | {"termname", (PyCFunction)PyCurses_termname, METH_NOARGS}, 3148 | {"tigetflag", (PyCFunction)PyCurses_tigetflag, METH_VARARGS}, 3149 | {"tigetnum", (PyCFunction)PyCurses_tigetnum, METH_VARARGS}, 3150 | {"tigetstr", (PyCFunction)PyCurses_tigetstr, METH_VARARGS}, 3151 | {"tparm", (PyCFunction)PyCurses_tparm, METH_VARARGS}, 3152 | {"typeahead", (PyCFunction)PyCurses_TypeAhead, METH_VARARGS}, 3153 | {"unctrl", (PyCFunction)PyCurses_UnCtrl, METH_VARARGS}, 3154 | {"ungetch", (PyCFunction)PyCurses_UngetCh, METH_VARARGS}, 3155 | {"use_env", (PyCFunction)PyCurses_Use_Env, METH_VARARGS}, 3156 | #ifndef STRICT_SYSV_CURSES 3157 | {"use_default_colors", (PyCFunction)PyCurses_Use_Default_Colors, METH_NOARGS}, 3158 | #endif 3159 | {NULL, NULL} /* sentinel */ 3160 | }; 3161 | 3162 | /* Initialization function for the module */ 3163 | 3164 | #if PY_MAJOR_VERSION == 3 3165 | static struct PyModuleDef _cursesmodule = { 3166 | PyModuleDef_HEAD_INIT, 3167 | "_curses", 3168 | NULL, 3169 | -1, 3170 | PyCurses_methods, 3171 | NULL, 3172 | NULL, 3173 | NULL, 3174 | NULL 3175 | }; 3176 | #endif 3177 | 3178 | PyMODINIT_FUNC 3179 | #if PY_MAJOR_VERSION == 3 3180 | PyInit__curses(void) 3181 | #else 3182 | init_curses(void) 3183 | #endif 3184 | { 3185 | PyObject *m, *d, *v, *c_api_object; 3186 | static void *PyCurses_API[PyCurses_API_pointers]; 3187 | 3188 | /* Initialize object type */ 3189 | #if PY_MAJOR_VERSION == 3 3190 | if (PyType_Ready(&PyCursesWindow_Type) < 0) 3191 | return NULL; 3192 | #else 3193 | Py_TYPE(&PyCursesWindow_Type) = &PyType_Type; 3194 | #endif 3195 | 3196 | /* Initialize the C API pointer array */ 3197 | PyCurses_API[0] = (void *)&PyCursesWindow_Type; 3198 | PyCurses_API[1] = (void *)func_PyCursesSetupTermCalled; 3199 | PyCurses_API[2] = (void *)func_PyCursesInitialised; 3200 | PyCurses_API[3] = (void *)func_PyCursesInitialisedColor; 3201 | 3202 | /* Create the module and add the functions */ 3203 | #if PY_MAJOR_VERSION == 3 3204 | m = PyModule_Create(&_cursesmodule); 3205 | #else 3206 | m = Py_InitModule("_curses", PyCurses_methods); 3207 | #endif 3208 | if (m == NULL) 3209 | #if PY_MAJOR_VERSION == 3 3210 | return NULL; 3211 | #else 3212 | return; 3213 | #endif 3214 | 3215 | /* Add some symbolic constants to the module */ 3216 | d = PyModule_GetDict(m); 3217 | if (d == NULL) 3218 | #if PY_MAJOR_VERSION == 3 3219 | return NULL; 3220 | #else 3221 | return; 3222 | #endif 3223 | ModDict = d; /* For PyCurses_InitScr to use later */ 3224 | 3225 | #ifndef PyCurses_CAPSULE_NAME 3226 | /* Expose the C API. */ 3227 | c_api_object = PyCObject_FromVoidPtr((void *)PyCurses_API, NULL); 3228 | PyDict_SetItemString(d, "_C_API", c_api_object); 3229 | Py_DECREF(c_api_object); 3230 | #else 3231 | /* If Capsules are available, use them. */ 3232 | c_api_object = PyCapsule_New(PyCurses_API, PyCurses_CAPSULE_NAME, NULL); 3233 | PyDict_SetItemString(d, "_C_API", c_api_object); 3234 | Py_DECREF(c_api_object); 3235 | #endif 3236 | 3237 | /* For exception curses.error */ 3238 | PyCursesError = PyErr_NewException("_curses.error", NULL, NULL); 3239 | PyDict_SetItemString(d, "error", PyCursesError); 3240 | 3241 | /* Make the version available */ 3242 | #if PY_MAJOR_VERSION == 3 3243 | v = PyUnicode_FromString 3244 | #else 3245 | v = PyString_FromString 3246 | #endif 3247 | (PyCursesVersion); 3248 | 3249 | PyDict_SetItemString(d, "version", v); 3250 | PyDict_SetItemString(d, "__version__", v); 3251 | Py_DECREF(v); 3252 | 3253 | SetDictInt("ERR", ERR); 3254 | SetDictInt("OK", OK); 3255 | 3256 | /* Here are some attributes you can add to chars to print */ 3257 | 3258 | SetDictInt("A_ATTRIBUTES", A_ATTRIBUTES); 3259 | SetDictInt("A_NORMAL", A_NORMAL); 3260 | SetDictInt("A_STANDOUT", A_STANDOUT); 3261 | SetDictInt("A_UNDERLINE", A_UNDERLINE); 3262 | SetDictInt("A_REVERSE", A_REVERSE); 3263 | SetDictInt("A_BLINK", A_BLINK); 3264 | SetDictInt("A_DIM", A_DIM); 3265 | SetDictInt("A_BOLD", A_BOLD); 3266 | SetDictInt("A_ALTCHARSET", A_ALTCHARSET); 3267 | #if !defined(__NetBSD__) 3268 | SetDictInt("A_INVIS", A_INVIS); 3269 | #endif 3270 | SetDictInt("A_PROTECT", A_PROTECT); 3271 | SetDictInt("A_CHARTEXT", A_CHARTEXT); 3272 | SetDictInt("A_COLOR", A_COLOR); 3273 | 3274 | /* The following are never available with strict SYSV curses */ 3275 | #ifdef A_HORIZONTAL 3276 | SetDictInt("A_HORIZONTAL", A_HORIZONTAL); 3277 | #endif 3278 | #ifdef A_LEFT 3279 | SetDictInt("A_LEFT", A_LEFT); 3280 | #endif 3281 | #ifdef A_LOW 3282 | SetDictInt("A_LOW", A_LOW); 3283 | #endif 3284 | #ifdef A_RIGHT 3285 | SetDictInt("A_RIGHT", A_RIGHT); 3286 | #endif 3287 | #ifdef A_TOP 3288 | SetDictInt("A_TOP", A_TOP); 3289 | #endif 3290 | #ifdef A_VERTICAL 3291 | SetDictInt("A_VERTICAL", A_VERTICAL); 3292 | #endif 3293 | 3294 | SetDictInt("COLOR_BLACK", COLOR_BLACK); 3295 | SetDictInt("COLOR_RED", COLOR_RED); 3296 | SetDictInt("COLOR_GREEN", COLOR_GREEN); 3297 | SetDictInt("COLOR_YELLOW", COLOR_YELLOW); 3298 | SetDictInt("COLOR_BLUE", COLOR_BLUE); 3299 | SetDictInt("COLOR_MAGENTA", COLOR_MAGENTA); 3300 | SetDictInt("COLOR_CYAN", COLOR_CYAN); 3301 | SetDictInt("COLOR_WHITE", COLOR_WHITE); 3302 | 3303 | #ifdef NCURSES_MOUSE_VERSION 3304 | /* Mouse-related constants */ 3305 | SetDictInt("BUTTON1_PRESSED", BUTTON1_PRESSED); 3306 | SetDictInt("BUTTON1_RELEASED", BUTTON1_RELEASED); 3307 | SetDictInt("BUTTON1_CLICKED", BUTTON1_CLICKED); 3308 | SetDictInt("BUTTON1_DOUBLE_CLICKED", BUTTON1_DOUBLE_CLICKED); 3309 | SetDictInt("BUTTON1_TRIPLE_CLICKED", BUTTON1_TRIPLE_CLICKED); 3310 | 3311 | SetDictInt("BUTTON2_PRESSED", BUTTON2_PRESSED); 3312 | SetDictInt("BUTTON2_RELEASED", BUTTON2_RELEASED); 3313 | SetDictInt("BUTTON2_CLICKED", BUTTON2_CLICKED); 3314 | SetDictInt("BUTTON2_DOUBLE_CLICKED", BUTTON2_DOUBLE_CLICKED); 3315 | SetDictInt("BUTTON2_TRIPLE_CLICKED", BUTTON2_TRIPLE_CLICKED); 3316 | 3317 | SetDictInt("BUTTON3_PRESSED", BUTTON3_PRESSED); 3318 | SetDictInt("BUTTON3_RELEASED", BUTTON3_RELEASED); 3319 | SetDictInt("BUTTON3_CLICKED", BUTTON3_CLICKED); 3320 | SetDictInt("BUTTON3_DOUBLE_CLICKED", BUTTON3_DOUBLE_CLICKED); 3321 | SetDictInt("BUTTON3_TRIPLE_CLICKED", BUTTON3_TRIPLE_CLICKED); 3322 | 3323 | SetDictInt("BUTTON4_PRESSED", BUTTON4_PRESSED); 3324 | SetDictInt("BUTTON4_RELEASED", BUTTON4_RELEASED); 3325 | SetDictInt("BUTTON4_CLICKED", BUTTON4_CLICKED); 3326 | SetDictInt("BUTTON4_DOUBLE_CLICKED", BUTTON4_DOUBLE_CLICKED); 3327 | SetDictInt("BUTTON4_TRIPLE_CLICKED", BUTTON4_TRIPLE_CLICKED); 3328 | 3329 | SetDictInt("BUTTON_SHIFT", BUTTON_SHIFT); 3330 | SetDictInt("BUTTON_CTRL", BUTTON_CTRL); 3331 | SetDictInt("BUTTON_ALT", BUTTON_ALT); 3332 | 3333 | SetDictInt("ALL_MOUSE_EVENTS", ALL_MOUSE_EVENTS); 3334 | SetDictInt("REPORT_MOUSE_POSITION", REPORT_MOUSE_POSITION); 3335 | #endif 3336 | /* Now set everything up for KEY_ variables */ 3337 | { 3338 | int key; 3339 | char *key_n; 3340 | char *key_n2; 3341 | #if !defined(__NetBSD__) 3342 | for (key=KEY_MIN;key < KEY_MAX; key++) { 3343 | key_n = (char *)keyname(key); 3344 | if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0) 3345 | continue; 3346 | if (strncmp(key_n,"KEY_F(",6)==0) { 3347 | char *p1, *p2; 3348 | key_n2 = malloc(strlen(key_n)+1); 3349 | if (!key_n2) { 3350 | PyErr_NoMemory(); 3351 | break; 3352 | } 3353 | p1 = key_n; 3354 | p2 = key_n2; 3355 | while (*p1) { 3356 | if (*p1 != '(' && *p1 != ')') { 3357 | *p2 = *p1; 3358 | p2++; 3359 | } 3360 | p1++; 3361 | } 3362 | *p2 = (char)0; 3363 | } else 3364 | key_n2 = key_n; 3365 | SetDictInt(key_n2,key); 3366 | if (key_n2 != key_n) 3367 | free(key_n2); 3368 | } 3369 | #endif 3370 | SetDictInt("KEY_MIN", KEY_MIN); 3371 | SetDictInt("KEY_MAX", KEY_MAX); 3372 | } 3373 | 3374 | #if PY_MAJOR_VERSION == 3 3375 | return m; 3376 | #endif 3377 | } 3378 | -------------------------------------------------------------------------------- /curses.h: -------------------------------------------------------------------------------- 1 | #ifndef PDC_DLL_BUILD 2 | # define PDC_DLL_BUILD 3 | #endif 4 | #ifndef PDC_WIDE 5 | # define PDC_WIDE 6 | #endif 7 | 8 | /* Public Domain Curses */ 9 | 10 | /* $Id: curses.h,v 1.295 2008/07/15 17:13:25 wmcbrine Exp $ */ 11 | 12 | /*----------------------------------------------------------------------* 13 | * PDCurses * 14 | *----------------------------------------------------------------------*/ 15 | 16 | #ifndef __PDCURSES__ 17 | #define __PDCURSES__ 1 18 | 19 | /*man-start************************************************************** 20 | 21 | PDCurses definitions list: (Only define those needed) 22 | 23 | XCURSES True if compiling for X11. 24 | PDC_RGB True if you want to use RGB color definitions 25 | (Red = 1, Green = 2, Blue = 4) instead of BGR. 26 | PDC_WIDE True if building wide-character support. 27 | PDC_DLL_BUILD True if building a Win32 DLL. 28 | NCURSES_MOUSE_VERSION Use the ncurses mouse API instead 29 | of PDCurses' traditional mouse API. 30 | 31 | PDCurses portable platform definitions list: 32 | 33 | PDC_BUILD Defines API build version. 34 | PDCURSES Enables access to PDCurses-only routines. 35 | XOPEN Always true. 36 | SYSVcurses True if you are compiling for SYSV portability. 37 | BSDcurses True if you are compiling for BSD portability. 38 | 39 | **man-end****************************************************************/ 40 | 41 | #define PDC_BUILD 3401 42 | #define PDCURSES 1 /* PDCurses-only routines */ 43 | #define XOPEN 1 /* X/Open Curses routines */ 44 | #define SYSVcurses 1 /* System V Curses routines */ 45 | #define BSDcurses 1 /* BSD Curses routines */ 46 | #define CHTYPE_LONG 1 /* size of chtype; long */ 47 | 48 | /*----------------------------------------------------------------------*/ 49 | 50 | #include 51 | #include 52 | #include /* Required by X/Open usage below */ 53 | 54 | #ifdef PDC_WIDE 55 | # include 56 | #endif 57 | 58 | #if defined(__cplusplus) || defined(__cplusplus__) || defined(__CPLUSPLUS) 59 | extern "C" 60 | { 61 | # define bool _bool 62 | #endif 63 | 64 | /*---------------------------------------------------------------------- 65 | * 66 | * PDCurses Manifest Constants 67 | * 68 | */ 69 | 70 | #ifndef FALSE 71 | # define FALSE 0 72 | #endif 73 | #ifndef TRUE 74 | # define TRUE 1 75 | #endif 76 | #ifndef NULL 77 | # define NULL (void *)0 78 | #endif 79 | #ifndef ERR 80 | # define ERR (-1) 81 | #endif 82 | #ifndef OK 83 | # define OK 0 84 | #endif 85 | 86 | /*---------------------------------------------------------------------- 87 | * 88 | * PDCurses Type Declarations 89 | * 90 | */ 91 | 92 | typedef unsigned char bool; /* PDCurses Boolean type */ 93 | 94 | #ifdef CHTYPE_LONG 95 | # if _LP64 96 | typedef unsigned int chtype; 97 | # else 98 | typedef unsigned long chtype; /* 16-bit attr + 16-bit char */ 99 | # endif 100 | #else 101 | typedef unsigned short chtype; /* 8-bit attr + 8-bit char */ 102 | #endif 103 | 104 | #ifdef PDC_WIDE 105 | typedef chtype cchar_t; 106 | #endif 107 | 108 | typedef chtype attr_t; 109 | 110 | /*---------------------------------------------------------------------- 111 | * 112 | * PDCurses Mouse Interface -- SYSVR4, with extensions 113 | * 114 | */ 115 | 116 | typedef struct 117 | { 118 | int x; /* absolute column, 0 based, measured in characters */ 119 | int y; /* absolute row, 0 based, measured in characters */ 120 | short button[3]; /* state of each button */ 121 | int changes; /* flags indicating what has changed with the mouse */ 122 | } MOUSE_STATUS; 123 | 124 | #define BUTTON_RELEASED 0x0000 125 | #define BUTTON_PRESSED 0x0001 126 | #define BUTTON_CLICKED 0x0002 127 | #define BUTTON_DOUBLE_CLICKED 0x0003 128 | #define BUTTON_TRIPLE_CLICKED 0x0004 129 | #define BUTTON_MOVED 0x0005 /* PDCurses */ 130 | #define WHEEL_SCROLLED 0x0006 /* PDCurses */ 131 | #define BUTTON_ACTION_MASK 0x0007 /* PDCurses */ 132 | 133 | #define PDC_BUTTON_SHIFT 0x0008 /* PDCurses */ 134 | #define PDC_BUTTON_CONTROL 0x0010 /* PDCurses */ 135 | #define PDC_BUTTON_ALT 0x0020 /* PDCurses */ 136 | #define BUTTON_MODIFIER_MASK 0x0038 /* PDCurses */ 137 | 138 | #define MOUSE_X_POS (Mouse_status.x) 139 | #define MOUSE_Y_POS (Mouse_status.y) 140 | 141 | /* 142 | * Bits associated with the .changes field: 143 | * 3 2 1 0 144 | * 210987654321098765432109876543210 145 | * 1 <- button 1 has changed 146 | * 10 <- button 2 has changed 147 | * 100 <- button 3 has changed 148 | * 1000 <- mouse has moved 149 | * 10000 <- mouse position report 150 | * 100000 <- mouse wheel up 151 | * 1000000 <- mouse wheel down 152 | */ 153 | 154 | #define PDC_MOUSE_MOVED 0x0008 155 | #define PDC_MOUSE_POSITION 0x0010 156 | #define PDC_MOUSE_WHEEL_UP 0x0020 157 | #define PDC_MOUSE_WHEEL_DOWN 0x0040 158 | 159 | #define A_BUTTON_CHANGED (Mouse_status.changes & 7) 160 | #define MOUSE_MOVED (Mouse_status.changes & PDC_MOUSE_MOVED) 161 | #define MOUSE_POS_REPORT (Mouse_status.changes & PDC_MOUSE_POSITION) 162 | #define BUTTON_CHANGED(x) (Mouse_status.changes & (1 << ((x) - 1))) 163 | #define BUTTON_STATUS(x) (Mouse_status.button[(x) - 1]) 164 | #define MOUSE_WHEEL_UP (Mouse_status.changes & PDC_MOUSE_WHEEL_UP) 165 | #define MOUSE_WHEEL_DOWN (Mouse_status.changes & PDC_MOUSE_WHEEL_DOWN) 166 | 167 | /* mouse bit-masks */ 168 | 169 | #define BUTTON1_RELEASED 0x00000001L 170 | #define BUTTON1_PRESSED 0x00000002L 171 | #define BUTTON1_CLICKED 0x00000004L 172 | #define BUTTON1_DOUBLE_CLICKED 0x00000008L 173 | #define BUTTON1_TRIPLE_CLICKED 0x00000010L 174 | #define BUTTON1_MOVED 0x00000010L /* PDCurses */ 175 | 176 | #define BUTTON2_RELEASED 0x00000020L 177 | #define BUTTON2_PRESSED 0x00000040L 178 | #define BUTTON2_CLICKED 0x00000080L 179 | #define BUTTON2_DOUBLE_CLICKED 0x00000100L 180 | #define BUTTON2_TRIPLE_CLICKED 0x00000200L 181 | #define BUTTON2_MOVED 0x00000200L /* PDCurses */ 182 | 183 | #define BUTTON3_RELEASED 0x00000400L 184 | #define BUTTON3_PRESSED 0x00000800L 185 | #define BUTTON3_CLICKED 0x00001000L 186 | #define BUTTON3_DOUBLE_CLICKED 0x00002000L 187 | #define BUTTON3_TRIPLE_CLICKED 0x00004000L 188 | #define BUTTON3_MOVED 0x00004000L /* PDCurses */ 189 | 190 | /* For the ncurses-compatible functions only, BUTTON4_PRESSED and 191 | BUTTON5_PRESSED are returned for mouse scroll wheel up and down; 192 | otherwise PDCurses doesn't support buttons 4 and 5 */ 193 | 194 | #define BUTTON4_RELEASED 0x00008000L 195 | #define BUTTON4_PRESSED 0x00010000L 196 | #define BUTTON4_CLICKED 0x00020000L 197 | #define BUTTON4_DOUBLE_CLICKED 0x00040000L 198 | #define BUTTON4_TRIPLE_CLICKED 0x00080000L 199 | 200 | #define BUTTON5_RELEASED 0x00100000L 201 | #define BUTTON5_PRESSED 0x00200000L 202 | #define BUTTON5_CLICKED 0x00400000L 203 | #define BUTTON5_DOUBLE_CLICKED 0x00800000L 204 | #define BUTTON5_TRIPLE_CLICKED 0x01000000L 205 | 206 | #define MOUSE_WHEEL_SCROLL 0x02000000L /* PDCurses */ 207 | #define BUTTON_MODIFIER_SHIFT 0x04000000L /* PDCurses */ 208 | #define BUTTON_MODIFIER_CONTROL 0x08000000L /* PDCurses */ 209 | #define BUTTON_MODIFIER_ALT 0x10000000L /* PDCurses */ 210 | 211 | #define ALL_MOUSE_EVENTS 0x1fffffffL 212 | #define REPORT_MOUSE_POSITION 0x20000000L 213 | 214 | /* ncurses mouse interface */ 215 | 216 | typedef unsigned long mmask_t; 217 | 218 | typedef struct 219 | { 220 | short id; /* unused, always 0 */ 221 | int x, y, z; /* x, y same as MOUSE_STATUS; z unused */ 222 | mmask_t bstate; /* equivalent to changes + button[], but 223 | in the same format as used for mousemask() */ 224 | } MEVENT; 225 | 226 | #ifdef NCURSES_MOUSE_VERSION 227 | # define BUTTON_SHIFT BUTTON_MODIFIER_SHIFT 228 | # define BUTTON_CONTROL BUTTON_MODIFIER_CONTROL 229 | # define BUTTON_CTRL BUTTON_MODIFIER_CONTROL 230 | # define BUTTON_ALT BUTTON_MODIFIER_ALT 231 | #else 232 | # define BUTTON_SHIFT PDC_BUTTON_SHIFT 233 | # define BUTTON_CONTROL PDC_BUTTON_CONTROL 234 | # define BUTTON_ALT PDC_BUTTON_ALT 235 | #endif 236 | 237 | /*---------------------------------------------------------------------- 238 | * 239 | * PDCurses Structure Definitions 240 | * 241 | */ 242 | 243 | typedef struct _win /* definition of a window */ 244 | { 245 | int _cury; /* current pseudo-cursor */ 246 | int _curx; 247 | int _maxy; /* max window coordinates */ 248 | int _maxx; 249 | int _begy; /* origin on screen */ 250 | int _begx; 251 | int _flags; /* window properties */ 252 | chtype _attrs; /* standard attributes and colors */ 253 | chtype _bkgd; /* background, normally blank */ 254 | bool _clear; /* causes clear at next refresh */ 255 | bool _leaveit; /* leaves cursor where it is */ 256 | bool _scroll; /* allows window scrolling */ 257 | bool _nodelay; /* input character wait flag */ 258 | bool _immed; /* immediate update flag */ 259 | bool _sync; /* synchronise window ancestors */ 260 | bool _use_keypad; /* flags keypad key mode active */ 261 | chtype **_y; /* pointer to line pointer array */ 262 | int *_firstch; /* first changed character in line */ 263 | int *_lastch; /* last changed character in line */ 264 | int _tmarg; /* top of scrolling region */ 265 | int _bmarg; /* bottom of scrolling region */ 266 | int _delayms; /* milliseconds of delay for getch() */ 267 | int _parx, _pary; /* coords relative to parent (0,0) */ 268 | struct _win *_parent; /* subwin's pointer to parent win */ 269 | } WINDOW; 270 | 271 | /* Avoid using the SCREEN struct directly -- use the corresponding 272 | functions if possible. This struct may eventually be made private. */ 273 | 274 | typedef struct 275 | { 276 | bool alive; /* if initscr() called, and not endwin() */ 277 | bool autocr; /* if cr -> lf */ 278 | bool cbreak; /* if terminal unbuffered */ 279 | bool echo; /* if terminal echo */ 280 | bool raw_inp; /* raw input mode (v. cooked input) */ 281 | bool raw_out; /* raw output mode (7 v. 8 bits) */ 282 | bool audible; /* FALSE if the bell is visual */ 283 | bool mono; /* TRUE if current screen is mono */ 284 | bool resized; /* TRUE if TERM has been resized */ 285 | bool orig_attr; /* TRUE if we have the original colors */ 286 | short orig_fore; /* original screen foreground color */ 287 | short orig_back; /* original screen foreground color */ 288 | int cursrow; /* position of physical cursor */ 289 | int curscol; /* position of physical cursor */ 290 | int visibility; /* visibility of cursor */ 291 | int orig_cursor; /* original cursor size */ 292 | int lines; /* new value for LINES */ 293 | int cols; /* new value for COLS */ 294 | unsigned long _trap_mbe; /* trap these mouse button events */ 295 | unsigned long _map_mbe_to_key; /* map mouse buttons to slk */ 296 | int mouse_wait; /* time to wait (in ms) for a 297 | button release after a press, in 298 | order to count it as a click */ 299 | int slklines; /* lines in use by slk_init() */ 300 | WINDOW *slk_winptr; /* window for slk */ 301 | int linesrippedoff; /* lines ripped off via ripoffline() */ 302 | int linesrippedoffontop; /* lines ripped off on 303 | top via ripoffline() */ 304 | int delaytenths; /* 1/10ths second to wait block 305 | getch() for */ 306 | bool _preserve; /* TRUE if screen background 307 | to be preserved */ 308 | int _restore; /* specifies if screen background 309 | to be restored, and how */ 310 | bool save_key_modifiers; /* TRUE if each key modifiers saved 311 | with each key press */ 312 | bool return_key_modifiers; /* TRUE if modifier keys are 313 | returned as "real" keys */ 314 | bool key_code; /* TRUE if last key is a special key; 315 | used internally by get_wch() */ 316 | #ifdef XCURSES 317 | int XcurscrSize; /* size of Xcurscr shared memory block */ 318 | bool sb_on; 319 | int sb_viewport_y; 320 | int sb_viewport_x; 321 | int sb_total_y; 322 | int sb_total_x; 323 | int sb_cur_y; 324 | int sb_cur_x; 325 | #endif 326 | short line_color; /* color of line attributes - default -1 */ 327 | } SCREEN; 328 | 329 | /*---------------------------------------------------------------------- 330 | * 331 | * PDCurses External Variables 332 | * 333 | */ 334 | 335 | #ifdef PDC_DLL_BUILD 336 | # ifdef CURSES_LIBRARY 337 | # define PDCEX __declspec(dllexport) extern 338 | # else 339 | # define PDCEX __declspec(dllimport) 340 | # endif 341 | #else 342 | # define PDCEX extern 343 | #endif 344 | 345 | PDCEX int LINES; /* terminal height */ 346 | PDCEX int COLS; /* terminal width */ 347 | PDCEX WINDOW *stdscr; /* the default screen window */ 348 | PDCEX WINDOW *curscr; /* the current screen image */ 349 | PDCEX SCREEN *SP; /* curses variables */ 350 | PDCEX MOUSE_STATUS Mouse_status; 351 | PDCEX int COLORS; 352 | PDCEX int COLOR_PAIRS; 353 | PDCEX int TABSIZE; 354 | PDCEX chtype acs_map[]; /* alternate character set map */ 355 | PDCEX char ttytype[]; /* terminal name/description */ 356 | 357 | /*man-start************************************************************** 358 | 359 | PDCurses Text Attributes 360 | ======================== 361 | 362 | Originally, PDCurses used a short (16 bits) for its chtype. To include 363 | color, a number of things had to be sacrificed from the strict Unix and 364 | System V support. The main problem was fitting all character attributes 365 | and color into an unsigned char (all 8 bits!). 366 | 367 | Today, PDCurses by default uses a long (32 bits) for its chtype, as in 368 | System V. The short chtype is still available, by undefining CHTYPE_LONG 369 | and rebuilding the library. 370 | 371 | The following is the structure of a win->_attrs chtype: 372 | 373 | short form: 374 | 375 | ------------------------------------------------- 376 | |15|14|13|12|11|10| 9| 8| 7| 6| 5| 4| 3| 2| 1| 0| 377 | ------------------------------------------------- 378 | color number | attrs | character eg 'a' 379 | 380 | The available non-color attributes are bold, reverse and blink. Others 381 | have no effect. The high order char is an index into an array of 382 | physical colors (defined in color.c) -- 32 foreground/background color 383 | pairs (5 bits) plus 3 bits for other attributes. 384 | 385 | long form: 386 | 387 | ---------------------------------------------------------------------------- 388 | |31|30|29|28|27|26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|..| 3| 2| 1| 0| 389 | ---------------------------------------------------------------------------- 390 | color number | modifiers | character eg 'a' 391 | 392 | The available non-color attributes are bold, underline, invisible, 393 | right-line, left-line, protect, reverse and blink. 256 color pairs (8 394 | bits), 8 bits for other attributes, and 16 bits for character data. 395 | 396 | **man-end****************************************************************/ 397 | 398 | /*** Video attribute macros ***/ 399 | 400 | #define A_NORMAL (chtype)0 401 | 402 | #ifdef CHTYPE_LONG 403 | # define A_ALTCHARSET (chtype)0x00010000 404 | # define A_RIGHTLINE (chtype)0x00020000 405 | # define A_LEFTLINE (chtype)0x00040000 406 | # define A_INVIS (chtype)0x00080000 407 | # define A_UNDERLINE (chtype)0x00100000 408 | # define A_REVERSE (chtype)0x00200000 409 | # define A_BLINK (chtype)0x00400000 410 | # define A_BOLD (chtype)0x00800000 411 | 412 | # define A_ATTRIBUTES (chtype)0xffff0000 413 | # define A_CHARTEXT (chtype)0x0000ffff 414 | # define A_COLOR (chtype)0xff000000 415 | 416 | # define A_ITALIC A_INVIS 417 | # define A_PROTECT (A_UNDERLINE | A_LEFTLINE | A_RIGHTLINE) 418 | 419 | # define PDC_ATTR_SHIFT 19 420 | # define PDC_COLOR_SHIFT 24 421 | #else 422 | # define A_BOLD (chtype)0x0100 /* X/Open */ 423 | # define A_REVERSE (chtype)0x0200 /* X/Open */ 424 | # define A_BLINK (chtype)0x0400 /* X/Open */ 425 | 426 | # define A_ATTRIBUTES (chtype)0xff00 /* X/Open */ 427 | # define A_CHARTEXT (chtype)0x00ff /* X/Open */ 428 | # define A_COLOR (chtype)0xf800 /* System V */ 429 | 430 | # define A_ALTCHARSET A_NORMAL /* X/Open */ 431 | # define A_PROTECT A_NORMAL /* X/Open */ 432 | # define A_UNDERLINE A_NORMAL /* X/Open */ 433 | 434 | # define A_LEFTLINE A_NORMAL 435 | # define A_RIGHTLINE A_NORMAL 436 | # define A_ITALIC A_NORMAL 437 | # define A_INVIS A_NORMAL 438 | 439 | # define PDC_ATTR_SHIFT 8 440 | # define PDC_COLOR_SHIFT 11 441 | #endif 442 | 443 | #define A_STANDOUT (A_REVERSE | A_BOLD) /* X/Open */ 444 | #define A_DIM A_NORMAL 445 | 446 | #define CHR_MSK A_CHARTEXT /* Obsolete */ 447 | #define ATR_MSK A_ATTRIBUTES /* Obsolete */ 448 | #define ATR_NRM A_NORMAL /* Obsolete */ 449 | 450 | /* For use with attr_t -- X/Open says, "these shall be distinct", so 451 | this is a non-conforming implementation. */ 452 | 453 | #define WA_ALTCHARSET A_ALTCHARSET 454 | #define WA_BLINK A_BLINK 455 | #define WA_BOLD A_BOLD 456 | #define WA_DIM A_DIM 457 | #define WA_INVIS A_INVIS 458 | #define WA_LEFT A_LEFTLINE 459 | #define WA_PROTECT A_PROTECT 460 | #define WA_REVERSE A_REVERSE 461 | #define WA_RIGHT A_RIGHTLINE 462 | #define WA_STANDOUT A_STANDOUT 463 | #define WA_UNDERLINE A_UNDERLINE 464 | 465 | #define WA_HORIZONTAL A_NORMAL 466 | #define WA_LOW A_NORMAL 467 | #define WA_TOP A_NORMAL 468 | #define WA_VERTICAL A_NORMAL 469 | 470 | /*** Alternate character set macros ***/ 471 | 472 | /* 'w' = 32-bit chtype; acs_map[] index | A_ALTCHARSET 473 | 'n' = 16-bit chtype; it gets the fallback set because no bit is 474 | available for A_ALTCHARSET */ 475 | 476 | #ifdef CHTYPE_LONG 477 | # define ACS_PICK(w, n) ((chtype)w | A_ALTCHARSET) 478 | #else 479 | # define ACS_PICK(w, n) ((chtype)n) 480 | #endif 481 | 482 | /* VT100-compatible symbols -- box chars */ 483 | 484 | #define ACS_ULCORNER ACS_PICK('l', '+') 485 | #define ACS_LLCORNER ACS_PICK('m', '+') 486 | #define ACS_URCORNER ACS_PICK('k', '+') 487 | #define ACS_LRCORNER ACS_PICK('j', '+') 488 | #define ACS_RTEE ACS_PICK('u', '+') 489 | #define ACS_LTEE ACS_PICK('t', '+') 490 | #define ACS_BTEE ACS_PICK('v', '+') 491 | #define ACS_TTEE ACS_PICK('w', '+') 492 | #define ACS_HLINE ACS_PICK('q', '-') 493 | #define ACS_VLINE ACS_PICK('x', '|') 494 | #define ACS_PLUS ACS_PICK('n', '+') 495 | 496 | /* VT100-compatible symbols -- other */ 497 | 498 | #define ACS_S1 ACS_PICK('o', '-') 499 | #define ACS_S9 ACS_PICK('s', '_') 500 | #define ACS_DIAMOND ACS_PICK('`', '+') 501 | #define ACS_CKBOARD ACS_PICK('a', ':') 502 | #define ACS_DEGREE ACS_PICK('f', '\'') 503 | #define ACS_PLMINUS ACS_PICK('g', '#') 504 | #define ACS_BULLET ACS_PICK('~', 'o') 505 | 506 | /* Teletype 5410v1 symbols -- these are defined in SysV curses, but 507 | are not well-supported by most terminals. Stick to VT100 characters 508 | for optimum portability. */ 509 | 510 | #define ACS_LARROW ACS_PICK(',', '<') 511 | #define ACS_RARROW ACS_PICK('+', '>') 512 | #define ACS_DARROW ACS_PICK('.', 'v') 513 | #define ACS_UARROW ACS_PICK('-', '^') 514 | #define ACS_BOARD ACS_PICK('h', '#') 515 | #define ACS_LANTERN ACS_PICK('i', '*') 516 | #define ACS_BLOCK ACS_PICK('0', '#') 517 | 518 | /* That goes double for these -- undocumented SysV symbols. Don't use 519 | them. */ 520 | 521 | #define ACS_S3 ACS_PICK('p', '-') 522 | #define ACS_S7 ACS_PICK('r', '-') 523 | #define ACS_LEQUAL ACS_PICK('y', '<') 524 | #define ACS_GEQUAL ACS_PICK('z', '>') 525 | #define ACS_PI ACS_PICK('{', 'n') 526 | #define ACS_NEQUAL ACS_PICK('|', '+') 527 | #define ACS_STERLING ACS_PICK('}', 'L') 528 | 529 | /* Box char aliases */ 530 | 531 | #define ACS_BSSB ACS_ULCORNER 532 | #define ACS_SSBB ACS_LLCORNER 533 | #define ACS_BBSS ACS_URCORNER 534 | #define ACS_SBBS ACS_LRCORNER 535 | #define ACS_SBSS ACS_RTEE 536 | #define ACS_SSSB ACS_LTEE 537 | #define ACS_SSBS ACS_BTEE 538 | #define ACS_BSSS ACS_TTEE 539 | #define ACS_BSBS ACS_HLINE 540 | #define ACS_SBSB ACS_VLINE 541 | #define ACS_SSSS ACS_PLUS 542 | 543 | /* cchar_t aliases */ 544 | 545 | #ifdef PDC_WIDE 546 | # define WACS_ULCORNER (&(acs_map['l'])) 547 | # define WACS_LLCORNER (&(acs_map['m'])) 548 | # define WACS_URCORNER (&(acs_map['k'])) 549 | # define WACS_LRCORNER (&(acs_map['j'])) 550 | # define WACS_RTEE (&(acs_map['u'])) 551 | # define WACS_LTEE (&(acs_map['t'])) 552 | # define WACS_BTEE (&(acs_map['v'])) 553 | # define WACS_TTEE (&(acs_map['w'])) 554 | # define WACS_HLINE (&(acs_map['q'])) 555 | # define WACS_VLINE (&(acs_map['x'])) 556 | # define WACS_PLUS (&(acs_map['n'])) 557 | 558 | # define WACS_S1 (&(acs_map['o'])) 559 | # define WACS_S9 (&(acs_map['s'])) 560 | # define WACS_DIAMOND (&(acs_map['`'])) 561 | # define WACS_CKBOARD (&(acs_map['a'])) 562 | # define WACS_DEGREE (&(acs_map['f'])) 563 | # define WACS_PLMINUS (&(acs_map['g'])) 564 | # define WACS_BULLET (&(acs_map['~'])) 565 | 566 | # define WACS_LARROW (&(acs_map[','])) 567 | # define WACS_RARROW (&(acs_map['+'])) 568 | # define WACS_DARROW (&(acs_map['.'])) 569 | # define WACS_UARROW (&(acs_map['-'])) 570 | # define WACS_BOARD (&(acs_map['h'])) 571 | # define WACS_LANTERN (&(acs_map['i'])) 572 | # define WACS_BLOCK (&(acs_map['0'])) 573 | 574 | # define WACS_S3 (&(acs_map['p'])) 575 | # define WACS_S7 (&(acs_map['r'])) 576 | # define WACS_LEQUAL (&(acs_map['y'])) 577 | # define WACS_GEQUAL (&(acs_map['z'])) 578 | # define WACS_PI (&(acs_map['{'])) 579 | # define WACS_NEQUAL (&(acs_map['|'])) 580 | # define WACS_STERLING (&(acs_map['}'])) 581 | 582 | # define WACS_BSSB WACS_ULCORNER 583 | # define WACS_SSBB WACS_LLCORNER 584 | # define WACS_BBSS WACS_URCORNER 585 | # define WACS_SBBS WACS_LRCORNER 586 | # define WACS_SBSS WACS_RTEE 587 | # define WACS_SSSB WACS_LTEE 588 | # define WACS_SSBS WACS_BTEE 589 | # define WACS_BSSS WACS_TTEE 590 | # define WACS_BSBS WACS_HLINE 591 | # define WACS_SBSB WACS_VLINE 592 | # define WACS_SSSS WACS_PLUS 593 | #endif 594 | 595 | /*** Color macros ***/ 596 | 597 | #define COLOR_BLACK 0 598 | 599 | #ifdef PDC_RGB /* RGB */ 600 | # define COLOR_RED 1 601 | # define COLOR_GREEN 2 602 | # define COLOR_BLUE 4 603 | #else /* BGR */ 604 | # define COLOR_BLUE 1 605 | # define COLOR_GREEN 2 606 | # define COLOR_RED 4 607 | #endif 608 | 609 | #define COLOR_CYAN (COLOR_BLUE | COLOR_GREEN) 610 | #define COLOR_MAGENTA (COLOR_RED | COLOR_BLUE) 611 | #define COLOR_YELLOW (COLOR_RED | COLOR_GREEN) 612 | 613 | #define COLOR_WHITE 7 614 | 615 | /*---------------------------------------------------------------------- 616 | * 617 | * Function and Keypad Key Definitions. 618 | * Many are just for compatibility. 619 | * 620 | */ 621 | 622 | #define KEY_CODE_YES 0x100 /* If get_wch() gives a key code */ 623 | 624 | #define KEY_BREAK 0x101 /* Not on PC KBD */ 625 | #define KEY_DOWN 0x102 /* Down arrow key */ 626 | #define KEY_UP 0x103 /* Up arrow key */ 627 | #define KEY_LEFT 0x104 /* Left arrow key */ 628 | #define KEY_RIGHT 0x105 /* Right arrow key */ 629 | #define KEY_HOME 0x106 /* home key */ 630 | #define KEY_BACKSPACE 0x107 /* not on pc */ 631 | #define KEY_F0 0x108 /* function keys; 64 reserved */ 632 | 633 | #define KEY_DL 0x148 /* delete line */ 634 | #define KEY_IL 0x149 /* insert line */ 635 | #define KEY_DC 0x14a /* delete character */ 636 | #define KEY_IC 0x14b /* insert char or enter ins mode */ 637 | #define KEY_EIC 0x14c /* exit insert char mode */ 638 | #define KEY_CLEAR 0x14d /* clear screen */ 639 | #define KEY_EOS 0x14e /* clear to end of screen */ 640 | #define KEY_EOL 0x14f /* clear to end of line */ 641 | #define KEY_SF 0x150 /* scroll 1 line forward */ 642 | #define KEY_SR 0x151 /* scroll 1 line back (reverse) */ 643 | #define KEY_NPAGE 0x152 /* next page */ 644 | #define KEY_PPAGE 0x153 /* previous page */ 645 | #define KEY_STAB 0x154 /* set tab */ 646 | #define KEY_CTAB 0x155 /* clear tab */ 647 | #define KEY_CATAB 0x156 /* clear all tabs */ 648 | #define KEY_ENTER 0x157 /* enter or send (unreliable) */ 649 | #define KEY_SRESET 0x158 /* soft/reset (partial/unreliable) */ 650 | #define KEY_RESET 0x159 /* reset/hard reset (unreliable) */ 651 | #define KEY_PRINT 0x15a /* print/copy */ 652 | #define KEY_LL 0x15b /* home down/bottom (lower left) */ 653 | #define KEY_ABORT 0x15c /* abort/terminate key (any) */ 654 | #define KEY_SHELP 0x15d /* short help */ 655 | #define KEY_LHELP 0x15e /* long help */ 656 | #define KEY_BTAB 0x15f /* Back tab key */ 657 | #define KEY_BEG 0x160 /* beg(inning) key */ 658 | #define KEY_CANCEL 0x161 /* cancel key */ 659 | #define KEY_CLOSE 0x162 /* close key */ 660 | #define KEY_COMMAND 0x163 /* cmd (command) key */ 661 | #define KEY_COPY 0x164 /* copy key */ 662 | #define KEY_CREATE 0x165 /* create key */ 663 | #define KEY_END 0x166 /* end key */ 664 | #define KEY_EXIT 0x167 /* exit key */ 665 | #define KEY_FIND 0x168 /* find key */ 666 | #define KEY_HELP 0x169 /* help key */ 667 | #define KEY_MARK 0x16a /* mark key */ 668 | #define KEY_MESSAGE 0x16b /* message key */ 669 | #define KEY_MOVE 0x16c /* move key */ 670 | #define KEY_NEXT 0x16d /* next object key */ 671 | #define KEY_OPEN 0x16e /* open key */ 672 | #define KEY_OPTIONS 0x16f /* options key */ 673 | #define KEY_PREVIOUS 0x170 /* previous object key */ 674 | #define KEY_REDO 0x171 /* redo key */ 675 | #define KEY_REFERENCE 0x172 /* ref(erence) key */ 676 | #define KEY_REFRESH 0x173 /* refresh key */ 677 | #define KEY_REPLACE 0x174 /* replace key */ 678 | #define KEY_RESTART 0x175 /* restart key */ 679 | #define KEY_RESUME 0x176 /* resume key */ 680 | #define KEY_SAVE 0x177 /* save key */ 681 | #define KEY_SBEG 0x178 /* shifted beginning key */ 682 | #define KEY_SCANCEL 0x179 /* shifted cancel key */ 683 | #define KEY_SCOMMAND 0x17a /* shifted command key */ 684 | #define KEY_SCOPY 0x17b /* shifted copy key */ 685 | #define KEY_SCREATE 0x17c /* shifted create key */ 686 | #define KEY_SDC 0x17d /* shifted delete char key */ 687 | #define KEY_SDL 0x17e /* shifted delete line key */ 688 | #define KEY_SELECT 0x17f /* select key */ 689 | #define KEY_SEND 0x180 /* shifted end key */ 690 | #define KEY_SEOL 0x181 /* shifted clear line key */ 691 | #define KEY_SEXIT 0x182 /* shifted exit key */ 692 | #define KEY_SFIND 0x183 /* shifted find key */ 693 | #define KEY_SHOME 0x184 /* shifted home key */ 694 | #define KEY_SIC 0x185 /* shifted input key */ 695 | 696 | #define KEY_SLEFT 0x187 /* shifted left arrow key */ 697 | #define KEY_SMESSAGE 0x188 /* shifted message key */ 698 | #define KEY_SMOVE 0x189 /* shifted move key */ 699 | #define KEY_SNEXT 0x18a /* shifted next key */ 700 | #define KEY_SOPTIONS 0x18b /* shifted options key */ 701 | #define KEY_SPREVIOUS 0x18c /* shifted prev key */ 702 | #define KEY_SPRINT 0x18d /* shifted print key */ 703 | #define KEY_SREDO 0x18e /* shifted redo key */ 704 | #define KEY_SREPLACE 0x18f /* shifted replace key */ 705 | #define KEY_SRIGHT 0x190 /* shifted right arrow */ 706 | #define KEY_SRSUME 0x191 /* shifted resume key */ 707 | #define KEY_SSAVE 0x192 /* shifted save key */ 708 | #define KEY_SSUSPEND 0x193 /* shifted suspend key */ 709 | #define KEY_SUNDO 0x194 /* shifted undo key */ 710 | #define KEY_SUSPEND 0x195 /* suspend key */ 711 | #define KEY_UNDO 0x196 /* undo key */ 712 | 713 | /* PDCurses-specific key definitions -- PC only */ 714 | 715 | #define ALT_0 0x197 716 | #define ALT_1 0x198 717 | #define ALT_2 0x199 718 | #define ALT_3 0x19a 719 | #define ALT_4 0x19b 720 | #define ALT_5 0x19c 721 | #define ALT_6 0x19d 722 | #define ALT_7 0x19e 723 | #define ALT_8 0x19f 724 | #define ALT_9 0x1a0 725 | #define ALT_A 0x1a1 726 | #define ALT_B 0x1a2 727 | #define ALT_C 0x1a3 728 | #define ALT_D 0x1a4 729 | #define ALT_E 0x1a5 730 | #define ALT_F 0x1a6 731 | #define ALT_G 0x1a7 732 | #define ALT_H 0x1a8 733 | #define ALT_I 0x1a9 734 | #define ALT_J 0x1aa 735 | #define ALT_K 0x1ab 736 | #define ALT_L 0x1ac 737 | #define ALT_M 0x1ad 738 | #define ALT_N 0x1ae 739 | #define ALT_O 0x1af 740 | #define ALT_P 0x1b0 741 | #define ALT_Q 0x1b1 742 | #define ALT_R 0x1b2 743 | #define ALT_S 0x1b3 744 | #define ALT_T 0x1b4 745 | #define ALT_U 0x1b5 746 | #define ALT_V 0x1b6 747 | #define ALT_W 0x1b7 748 | #define ALT_X 0x1b8 749 | #define ALT_Y 0x1b9 750 | #define ALT_Z 0x1ba 751 | 752 | #define CTL_LEFT 0x1bb /* Control-Left-Arrow */ 753 | #define CTL_RIGHT 0x1bc 754 | #define CTL_PGUP 0x1bd 755 | #define CTL_PGDN 0x1be 756 | #define CTL_HOME 0x1bf 757 | #define CTL_END 0x1c0 758 | 759 | #define KEY_A1 0x1c1 /* upper left on Virtual keypad */ 760 | #define KEY_A2 0x1c2 /* upper middle on Virt. keypad */ 761 | #define KEY_A3 0x1c3 /* upper right on Vir. keypad */ 762 | #define KEY_B1 0x1c4 /* middle left on Virt. keypad */ 763 | #define KEY_B2 0x1c5 /* center on Virt. keypad */ 764 | #define KEY_B3 0x1c6 /* middle right on Vir. keypad */ 765 | #define KEY_C1 0x1c7 /* lower left on Virt. keypad */ 766 | #define KEY_C2 0x1c8 /* lower middle on Virt. keypad */ 767 | #define KEY_C3 0x1c9 /* lower right on Vir. keypad */ 768 | 769 | #define PADSLASH 0x1ca /* slash on keypad */ 770 | #define PADENTER 0x1cb /* enter on keypad */ 771 | #define CTL_PADENTER 0x1cc /* ctl-enter on keypad */ 772 | #define ALT_PADENTER 0x1cd /* alt-enter on keypad */ 773 | #define PADSTOP 0x1ce /* stop on keypad */ 774 | #define PADSTAR 0x1cf /* star on keypad */ 775 | #define PADMINUS 0x1d0 /* minus on keypad */ 776 | #define PADPLUS 0x1d1 /* plus on keypad */ 777 | #define CTL_PADSTOP 0x1d2 /* ctl-stop on keypad */ 778 | #define CTL_PADCENTER 0x1d3 /* ctl-enter on keypad */ 779 | #define CTL_PADPLUS 0x1d4 /* ctl-plus on keypad */ 780 | #define CTL_PADMINUS 0x1d5 /* ctl-minus on keypad */ 781 | #define CTL_PADSLASH 0x1d6 /* ctl-slash on keypad */ 782 | #define CTL_PADSTAR 0x1d7 /* ctl-star on keypad */ 783 | #define ALT_PADPLUS 0x1d8 /* alt-plus on keypad */ 784 | #define ALT_PADMINUS 0x1d9 /* alt-minus on keypad */ 785 | #define ALT_PADSLASH 0x1da /* alt-slash on keypad */ 786 | #define ALT_PADSTAR 0x1db /* alt-star on keypad */ 787 | #define ALT_PADSTOP 0x1dc /* alt-stop on keypad */ 788 | #define CTL_INS 0x1dd /* ctl-insert */ 789 | #define ALT_DEL 0x1de /* alt-delete */ 790 | #define ALT_INS 0x1df /* alt-insert */ 791 | #define CTL_UP 0x1e0 /* ctl-up arrow */ 792 | #define CTL_DOWN 0x1e1 /* ctl-down arrow */ 793 | #define CTL_TAB 0x1e2 /* ctl-tab */ 794 | #define ALT_TAB 0x1e3 795 | #define ALT_MINUS 0x1e4 796 | #define ALT_EQUAL 0x1e5 797 | #define ALT_HOME 0x1e6 798 | #define ALT_PGUP 0x1e7 799 | #define ALT_PGDN 0x1e8 800 | #define ALT_END 0x1e9 801 | #define ALT_UP 0x1ea /* alt-up arrow */ 802 | #define ALT_DOWN 0x1eb /* alt-down arrow */ 803 | #define ALT_RIGHT 0x1ec /* alt-right arrow */ 804 | #define ALT_LEFT 0x1ed /* alt-left arrow */ 805 | #define ALT_ENTER 0x1ee /* alt-enter */ 806 | #define ALT_ESC 0x1ef /* alt-escape */ 807 | #define ALT_BQUOTE 0x1f0 /* alt-back quote */ 808 | #define ALT_LBRACKET 0x1f1 /* alt-left bracket */ 809 | #define ALT_RBRACKET 0x1f2 /* alt-right bracket */ 810 | #define ALT_SEMICOLON 0x1f3 /* alt-semi-colon */ 811 | #define ALT_FQUOTE 0x1f4 /* alt-forward quote */ 812 | #define ALT_COMMA 0x1f5 /* alt-comma */ 813 | #define ALT_STOP 0x1f6 /* alt-stop */ 814 | #define ALT_FSLASH 0x1f7 /* alt-forward slash */ 815 | #define ALT_BKSP 0x1f8 /* alt-backspace */ 816 | #define CTL_BKSP 0x1f9 /* ctl-backspace */ 817 | #define PAD0 0x1fa /* keypad 0 */ 818 | 819 | #define CTL_PAD0 0x1fb /* ctl-keypad 0 */ 820 | #define CTL_PAD1 0x1fc 821 | #define CTL_PAD2 0x1fd 822 | #define CTL_PAD3 0x1fe 823 | #define CTL_PAD4 0x1ff 824 | #define CTL_PAD5 0x200 825 | #define CTL_PAD6 0x201 826 | #define CTL_PAD7 0x202 827 | #define CTL_PAD8 0x203 828 | #define CTL_PAD9 0x204 829 | 830 | #define ALT_PAD0 0x205 /* alt-keypad 0 */ 831 | #define ALT_PAD1 0x206 832 | #define ALT_PAD2 0x207 833 | #define ALT_PAD3 0x208 834 | #define ALT_PAD4 0x209 835 | #define ALT_PAD5 0x20a 836 | #define ALT_PAD6 0x20b 837 | #define ALT_PAD7 0x20c 838 | #define ALT_PAD8 0x20d 839 | #define ALT_PAD9 0x20e 840 | 841 | #define CTL_DEL 0x20f /* clt-delete */ 842 | #define ALT_BSLASH 0x210 /* alt-back slash */ 843 | #define CTL_ENTER 0x211 /* ctl-enter */ 844 | 845 | #define SHF_PADENTER 0x212 /* shift-enter on keypad */ 846 | #define SHF_PADSLASH 0x213 /* shift-slash on keypad */ 847 | #define SHF_PADSTAR 0x214 /* shift-star on keypad */ 848 | #define SHF_PADPLUS 0x215 /* shift-plus on keypad */ 849 | #define SHF_PADMINUS 0x216 /* shift-minus on keypad */ 850 | #define SHF_UP 0x217 /* shift-up on keypad */ 851 | #define SHF_DOWN 0x218 /* shift-down on keypad */ 852 | #define SHF_IC 0x219 /* shift-insert on keypad */ 853 | #define SHF_DC 0x21a /* shift-delete on keypad */ 854 | 855 | #define KEY_MOUSE 0x21b /* "mouse" key */ 856 | #define KEY_SHIFT_L 0x21c /* Left-shift */ 857 | #define KEY_SHIFT_R 0x21d /* Right-shift */ 858 | #define KEY_CONTROL_L 0x21e /* Left-control */ 859 | #define KEY_CONTROL_R 0x21f /* Right-control */ 860 | #define KEY_ALT_L 0x220 /* Left-alt */ 861 | #define KEY_ALT_R 0x221 /* Right-alt */ 862 | #define KEY_RESIZE 0x222 /* Window resize */ 863 | #define KEY_SUP 0x223 /* Shifted up arrow */ 864 | #define KEY_SDOWN 0x224 /* Shifted down arrow */ 865 | 866 | #define KEY_MIN KEY_BREAK /* Minimum curses key value */ 867 | #define KEY_MAX KEY_SDOWN /* Maximum curses key */ 868 | 869 | #define KEY_F(n) (KEY_F0 + (n)) 870 | 871 | /*---------------------------------------------------------------------- 872 | * 873 | * PDCurses Function Declarations 874 | * 875 | */ 876 | 877 | /* Standard */ 878 | 879 | int addch(const chtype); 880 | int addchnstr(const chtype *, int); 881 | int addchstr(const chtype *); 882 | int addnstr(const char *, int); 883 | int addstr(const char *); 884 | int attroff(chtype); 885 | int attron(chtype); 886 | int attrset(chtype); 887 | int attr_get(attr_t *, short *, void *); 888 | int attr_off(attr_t, void *); 889 | int attr_on(attr_t, void *); 890 | int attr_set(attr_t, short, void *); 891 | int baudrate(void); 892 | int beep(void); 893 | int bkgd(chtype); 894 | void bkgdset(chtype); 895 | int border(chtype, chtype, chtype, chtype, chtype, chtype, chtype, chtype); 896 | int box(WINDOW *, chtype, chtype); 897 | bool can_change_color(void); 898 | int cbreak(void); 899 | int chgat(int, attr_t, short, const void *); 900 | int clearok(WINDOW *, bool); 901 | int clear(void); 902 | int clrtobot(void); 903 | int clrtoeol(void); 904 | int color_content(short, short *, short *, short *); 905 | int color_set(short, void *); 906 | int copywin(const WINDOW *, WINDOW *, int, int, int, int, int, int, int); 907 | int curs_set(int); 908 | int def_prog_mode(void); 909 | int def_shell_mode(void); 910 | int delay_output(int); 911 | int delch(void); 912 | int deleteln(void); 913 | void delscreen(SCREEN *); 914 | int delwin(WINDOW *); 915 | WINDOW *derwin(WINDOW *, int, int, int, int); 916 | int doupdate(void); 917 | WINDOW *dupwin(WINDOW *); 918 | int echochar(const chtype); 919 | int echo(void); 920 | int endwin(void); 921 | char erasechar(void); 922 | int erase(void); 923 | void filter(void); 924 | int flash(void); 925 | int flushinp(void); 926 | chtype getbkgd(WINDOW *); 927 | int getnstr(char *, int); 928 | int getstr(char *); 929 | WINDOW *getwin(FILE *); 930 | int halfdelay(int); 931 | bool has_colors(void); 932 | bool has_ic(void); 933 | bool has_il(void); 934 | int hline(chtype, int); 935 | void idcok(WINDOW *, bool); 936 | int idlok(WINDOW *, bool); 937 | void immedok(WINDOW *, bool); 938 | int inchnstr(chtype *, int); 939 | int inchstr(chtype *); 940 | chtype inch(void); 941 | int init_color(short, short, short, short); 942 | int init_pair(short, short, short); 943 | WINDOW *initscr(void); 944 | int innstr(char *, int); 945 | int insch(chtype); 946 | int insdelln(int); 947 | int insertln(void); 948 | int insnstr(const char *, int); 949 | int insstr(const char *); 950 | int instr(char *); 951 | int intrflush(WINDOW *, bool); 952 | bool isendwin(void); 953 | bool is_linetouched(WINDOW *, int); 954 | bool is_wintouched(WINDOW *); 955 | char *keyname(int); 956 | int keypad(WINDOW *, bool); 957 | char killchar(void); 958 | int leaveok(WINDOW *, bool); 959 | char *longname(void); 960 | int meta(WINDOW *, bool); 961 | int move(int, int); 962 | int mvaddch(int, int, const chtype); 963 | int mvaddchnstr(int, int, const chtype *, int); 964 | int mvaddchstr(int, int, const chtype *); 965 | int mvaddnstr(int, int, const char *, int); 966 | int mvaddstr(int, int, const char *); 967 | int mvchgat(int, int, int, attr_t, short, const void *); 968 | int mvcur(int, int, int, int); 969 | int mvdelch(int, int); 970 | int mvderwin(WINDOW *, int, int); 971 | int mvgetch(int, int); 972 | int mvgetnstr(int, int, char *, int); 973 | int mvgetstr(int, int, char *); 974 | int mvhline(int, int, chtype, int); 975 | chtype mvinch(int, int); 976 | int mvinchnstr(int, int, chtype *, int); 977 | int mvinchstr(int, int, chtype *); 978 | int mvinnstr(int, int, char *, int); 979 | int mvinsch(int, int, chtype); 980 | int mvinsnstr(int, int, const char *, int); 981 | int mvinsstr(int, int, const char *); 982 | int mvinstr(int, int, char *); 983 | int mvprintw(int, int, const char *, ...); 984 | int mvscanw(int, int, const char *, ...); 985 | int mvvline(int, int, chtype, int); 986 | int mvwaddchnstr(WINDOW *, int, int, const chtype *, int); 987 | int mvwaddchstr(WINDOW *, int, int, const chtype *); 988 | int mvwaddch(WINDOW *, int, int, const chtype); 989 | int mvwaddnstr(WINDOW *, int, int, const char *, int); 990 | int mvwaddstr(WINDOW *, int, int, const char *); 991 | int mvwchgat(WINDOW *, int, int, int, attr_t, short, const void *); 992 | int mvwdelch(WINDOW *, int, int); 993 | int mvwgetch(WINDOW *, int, int); 994 | int mvwgetnstr(WINDOW *, int, int, char *, int); 995 | int mvwgetstr(WINDOW *, int, int, char *); 996 | int mvwhline(WINDOW *, int, int, chtype, int); 997 | int mvwinchnstr(WINDOW *, int, int, chtype *, int); 998 | int mvwinchstr(WINDOW *, int, int, chtype *); 999 | chtype mvwinch(WINDOW *, int, int); 1000 | int mvwinnstr(WINDOW *, int, int, char *, int); 1001 | int mvwinsch(WINDOW *, int, int, chtype); 1002 | int mvwinsnstr(WINDOW *, int, int, const char *, int); 1003 | int mvwinsstr(WINDOW *, int, int, const char *); 1004 | int mvwinstr(WINDOW *, int, int, char *); 1005 | int mvwin(WINDOW *, int, int); 1006 | int mvwprintw(WINDOW *, int, int, const char *, ...); 1007 | int mvwscanw(WINDOW *, int, int, const char *, ...); 1008 | int mvwvline(WINDOW *, int, int, chtype, int); 1009 | int napms(int); 1010 | WINDOW *newpad(int, int); 1011 | SCREEN *newterm(const char *, FILE *, FILE *); 1012 | WINDOW *newwin(int, int, int, int); 1013 | int nl(void); 1014 | int nocbreak(void); 1015 | int nodelay(WINDOW *, bool); 1016 | int noecho(void); 1017 | int nonl(void); 1018 | void noqiflush(void); 1019 | int noraw(void); 1020 | int notimeout(WINDOW *, bool); 1021 | int overlay(const WINDOW *, WINDOW *); 1022 | int overwrite(const WINDOW *, WINDOW *); 1023 | int pair_content(short, short *, short *); 1024 | int pechochar(WINDOW *, chtype); 1025 | int pnoutrefresh(WINDOW *, int, int, int, int, int, int); 1026 | int prefresh(WINDOW *, int, int, int, int, int, int); 1027 | int printw(const char *, ...); 1028 | int putwin(WINDOW *, FILE *); 1029 | void qiflush(void); 1030 | int raw(void); 1031 | int redrawwin(WINDOW *); 1032 | int refresh(void); 1033 | int reset_prog_mode(void); 1034 | int reset_shell_mode(void); 1035 | int resetty(void); 1036 | int ripoffline(int, int (*)(WINDOW *, int)); 1037 | int savetty(void); 1038 | int scanw(const char *, ...); 1039 | int scr_dump(const char *); 1040 | int scr_init(const char *); 1041 | int scr_restore(const char *); 1042 | int scr_set(const char *); 1043 | int scrl(int); 1044 | int scroll(WINDOW *); 1045 | int scrollok(WINDOW *, bool); 1046 | SCREEN *set_term(SCREEN *); 1047 | int setscrreg(int, int); 1048 | int slk_attroff(const chtype); 1049 | int slk_attr_off(const attr_t, void *); 1050 | int slk_attron(const chtype); 1051 | int slk_attr_on(const attr_t, void *); 1052 | int slk_attrset(const chtype); 1053 | int slk_attr_set(const attr_t, short, void *); 1054 | int slk_clear(void); 1055 | int slk_color(short); 1056 | int slk_init(int); 1057 | char *slk_label(int); 1058 | int slk_noutrefresh(void); 1059 | int slk_refresh(void); 1060 | int slk_restore(void); 1061 | int slk_set(int, const char *, int); 1062 | int slk_touch(void); 1063 | int standend(void); 1064 | int standout(void); 1065 | int start_color(void); 1066 | WINDOW *subpad(WINDOW *, int, int, int, int); 1067 | WINDOW *subwin(WINDOW *, int, int, int, int); 1068 | int syncok(WINDOW *, bool); 1069 | chtype termattrs(void); 1070 | attr_t term_attrs(void); 1071 | char *termname(void); 1072 | void timeout(int); 1073 | int touchline(WINDOW *, int, int); 1074 | int touchwin(WINDOW *); 1075 | int typeahead(int); 1076 | int untouchwin(WINDOW *); 1077 | void use_env(bool); 1078 | int vidattr(chtype); 1079 | int vid_attr(attr_t, short, void *); 1080 | int vidputs(chtype, int (*)(int)); 1081 | int vid_puts(attr_t, short, void *, int (*)(int)); 1082 | int vline(chtype, int); 1083 | int vw_printw(WINDOW *, const char *, va_list); 1084 | int vwprintw(WINDOW *, const char *, va_list); 1085 | int vw_scanw(WINDOW *, const char *, va_list); 1086 | int vwscanw(WINDOW *, const char *, va_list); 1087 | int waddchnstr(WINDOW *, const chtype *, int); 1088 | int waddchstr(WINDOW *, const chtype *); 1089 | int waddch(WINDOW *, const chtype); 1090 | int waddnstr(WINDOW *, const char *, int); 1091 | int waddstr(WINDOW *, const char *); 1092 | int wattroff(WINDOW *, chtype); 1093 | int wattron(WINDOW *, chtype); 1094 | int wattrset(WINDOW *, chtype); 1095 | int wattr_get(WINDOW *, attr_t *, short *, void *); 1096 | int wattr_off(WINDOW *, attr_t, void *); 1097 | int wattr_on(WINDOW *, attr_t, void *); 1098 | int wattr_set(WINDOW *, attr_t, short, void *); 1099 | void wbkgdset(WINDOW *, chtype); 1100 | int wbkgd(WINDOW *, chtype); 1101 | int wborder(WINDOW *, chtype, chtype, chtype, chtype, 1102 | chtype, chtype, chtype, chtype); 1103 | int wchgat(WINDOW *, int, attr_t, short, const void *); 1104 | int wclear(WINDOW *); 1105 | int wclrtobot(WINDOW *); 1106 | int wclrtoeol(WINDOW *); 1107 | int wcolor_set(WINDOW *, short, void *); 1108 | void wcursyncup(WINDOW *); 1109 | int wdelch(WINDOW *); 1110 | int wdeleteln(WINDOW *); 1111 | int wechochar(WINDOW *, const chtype); 1112 | int werase(WINDOW *); 1113 | int wgetch(WINDOW *); 1114 | int wgetnstr(WINDOW *, char *, int); 1115 | int wgetstr(WINDOW *, char *); 1116 | int whline(WINDOW *, chtype, int); 1117 | int winchnstr(WINDOW *, chtype *, int); 1118 | int winchstr(WINDOW *, chtype *); 1119 | chtype winch(WINDOW *); 1120 | int winnstr(WINDOW *, char *, int); 1121 | int winsch(WINDOW *, chtype); 1122 | int winsdelln(WINDOW *, int); 1123 | int winsertln(WINDOW *); 1124 | int winsnstr(WINDOW *, const char *, int); 1125 | int winsstr(WINDOW *, const char *); 1126 | int winstr(WINDOW *, char *); 1127 | int wmove(WINDOW *, int, int); 1128 | int wnoutrefresh(WINDOW *); 1129 | int wprintw(WINDOW *, const char *, ...); 1130 | int wredrawln(WINDOW *, int, int); 1131 | int wrefresh(WINDOW *); 1132 | int wscanw(WINDOW *, const char *, ...); 1133 | int wscrl(WINDOW *, int); 1134 | int wsetscrreg(WINDOW *, int, int); 1135 | int wstandend(WINDOW *); 1136 | int wstandout(WINDOW *); 1137 | void wsyncdown(WINDOW *); 1138 | void wsyncup(WINDOW *); 1139 | void wtimeout(WINDOW *, int); 1140 | int wtouchln(WINDOW *, int, int, int); 1141 | int wvline(WINDOW *, chtype, int); 1142 | 1143 | /* Wide-character functions */ 1144 | 1145 | #ifdef PDC_WIDE 1146 | int addnwstr(const wchar_t *, int); 1147 | int addwstr(const wchar_t *); 1148 | int add_wch(const cchar_t *); 1149 | int add_wchnstr(const cchar_t *, int); 1150 | int add_wchstr(const cchar_t *); 1151 | int border_set(const cchar_t *, const cchar_t *, const cchar_t *, 1152 | const cchar_t *, const cchar_t *, const cchar_t *, 1153 | const cchar_t *, const cchar_t *); 1154 | int box_set(WINDOW *, const cchar_t *, const cchar_t *); 1155 | int echo_wchar(const cchar_t *); 1156 | int erasewchar(wchar_t *); 1157 | int getbkgrnd(cchar_t *); 1158 | int getcchar(const cchar_t *, wchar_t *, attr_t *, short *, void *); 1159 | int getn_wstr(wint_t *, int); 1160 | int get_wch(wint_t *); 1161 | int get_wstr(wint_t *); 1162 | int hline_set(const cchar_t *, int); 1163 | int innwstr(wchar_t *, int); 1164 | int ins_nwstr(const wchar_t *, int); 1165 | int ins_wch(const cchar_t *); 1166 | int ins_wstr(const wchar_t *); 1167 | int inwstr(wchar_t *); 1168 | int in_wch(cchar_t *); 1169 | int in_wchnstr(cchar_t *, int); 1170 | int in_wchstr(cchar_t *); 1171 | char *key_name(wchar_t); 1172 | int killwchar(wchar_t *); 1173 | int mvaddnwstr(int, int, const wchar_t *, int); 1174 | int mvaddwstr(int, int, const wchar_t *); 1175 | int mvadd_wch(int, int, const cchar_t *); 1176 | int mvadd_wchnstr(int, int, const cchar_t *, int); 1177 | int mvadd_wchstr(int, int, const cchar_t *); 1178 | int mvgetn_wstr(int, int, wint_t *, int); 1179 | int mvget_wch(int, int, wint_t *); 1180 | int mvget_wstr(int, int, wint_t *); 1181 | int mvhline_set(int, int, const cchar_t *, int); 1182 | int mvinnwstr(int, int, wchar_t *, int); 1183 | int mvins_nwstr(int, int, const wchar_t *, int); 1184 | int mvins_wch(int, int, const cchar_t *); 1185 | int mvins_wstr(int, int, const wchar_t *); 1186 | int mvinwstr(int, int, wchar_t *); 1187 | int mvin_wch(int, int, cchar_t *); 1188 | int mvin_wchnstr(int, int, cchar_t *, int); 1189 | int mvin_wchstr(int, int, cchar_t *); 1190 | int mvvline_set(int, int, const cchar_t *, int); 1191 | int mvwaddnwstr(WINDOW *, int, int, const wchar_t *, int); 1192 | int mvwaddwstr(WINDOW *, int, int, const wchar_t *); 1193 | int mvwadd_wch(WINDOW *, int, int, const cchar_t *); 1194 | int mvwadd_wchnstr(WINDOW *, int, int, const cchar_t *, int); 1195 | int mvwadd_wchstr(WINDOW *, int, int, const cchar_t *); 1196 | int mvwgetn_wstr(WINDOW *, int, int, wint_t *, int); 1197 | int mvwget_wch(WINDOW *, int, int, wint_t *); 1198 | int mvwget_wstr(WINDOW *, int, int, wint_t *); 1199 | int mvwhline_set(WINDOW *, int, int, const cchar_t *, int); 1200 | int mvwinnwstr(WINDOW *, int, int, wchar_t *, int); 1201 | int mvwins_nwstr(WINDOW *, int, int, const wchar_t *, int); 1202 | int mvwins_wch(WINDOW *, int, int, const cchar_t *); 1203 | int mvwins_wstr(WINDOW *, int, int, const wchar_t *); 1204 | int mvwin_wch(WINDOW *, int, int, cchar_t *); 1205 | int mvwin_wchnstr(WINDOW *, int, int, cchar_t *, int); 1206 | int mvwin_wchstr(WINDOW *, int, int, cchar_t *); 1207 | int mvwinwstr(WINDOW *, int, int, wchar_t *); 1208 | int mvwvline_set(WINDOW *, int, int, const cchar_t *, int); 1209 | int pecho_wchar(WINDOW *, const cchar_t*); 1210 | int setcchar(cchar_t*, const wchar_t*, const attr_t, short, const void*); 1211 | int slk_wset(int, const wchar_t *, int); 1212 | int unget_wch(const wchar_t); 1213 | int vline_set(const cchar_t *, int); 1214 | int waddnwstr(WINDOW *, const wchar_t *, int); 1215 | int waddwstr(WINDOW *, const wchar_t *); 1216 | int wadd_wch(WINDOW *, const cchar_t *); 1217 | int wadd_wchnstr(WINDOW *, const cchar_t *, int); 1218 | int wadd_wchstr(WINDOW *, const cchar_t *); 1219 | int wbkgrnd(WINDOW *, const cchar_t *); 1220 | void wbkgrndset(WINDOW *, const cchar_t *); 1221 | int wborder_set(WINDOW *, const cchar_t *, const cchar_t *, 1222 | const cchar_t *, const cchar_t *, const cchar_t *, 1223 | const cchar_t *, const cchar_t *, const cchar_t *); 1224 | int wecho_wchar(WINDOW *, const cchar_t *); 1225 | int wgetbkgrnd(WINDOW *, cchar_t *); 1226 | int wgetn_wstr(WINDOW *, wint_t *, int); 1227 | int wget_wch(WINDOW *, wint_t *); 1228 | int wget_wstr(WINDOW *, wint_t *); 1229 | int whline_set(WINDOW *, const cchar_t *, int); 1230 | int winnwstr(WINDOW *, wchar_t *, int); 1231 | int wins_nwstr(WINDOW *, const wchar_t *, int); 1232 | int wins_wch(WINDOW *, const cchar_t *); 1233 | int wins_wstr(WINDOW *, const wchar_t *); 1234 | int winwstr(WINDOW *, wchar_t *); 1235 | int win_wch(WINDOW *, cchar_t *); 1236 | int win_wchnstr(WINDOW *, cchar_t *, int); 1237 | int win_wchstr(WINDOW *, cchar_t *); 1238 | wchar_t *wunctrl(cchar_t *); 1239 | int wvline_set(WINDOW *, const cchar_t *, int); 1240 | #endif 1241 | 1242 | /* Quasi-standard */ 1243 | 1244 | chtype getattrs(WINDOW *); 1245 | int getbegx(WINDOW *); 1246 | int getbegy(WINDOW *); 1247 | int getmaxx(WINDOW *); 1248 | int getmaxy(WINDOW *); 1249 | int getparx(WINDOW *); 1250 | int getpary(WINDOW *); 1251 | int getcurx(WINDOW *); 1252 | int getcury(WINDOW *); 1253 | void traceoff(void); 1254 | void traceon(void); 1255 | char *unctrl(chtype); 1256 | 1257 | int crmode(void); 1258 | int nocrmode(void); 1259 | int draino(int); 1260 | int resetterm(void); 1261 | int fixterm(void); 1262 | int saveterm(void); 1263 | int setsyx(int, int); 1264 | 1265 | int mouse_set(unsigned long); 1266 | int mouse_on(unsigned long); 1267 | int mouse_off(unsigned long); 1268 | int request_mouse_pos(void); 1269 | int map_button(unsigned long); 1270 | void wmouse_position(WINDOW *, int *, int *); 1271 | unsigned long getmouse(void); 1272 | unsigned long getbmap(void); 1273 | 1274 | /* ncurses */ 1275 | 1276 | int assume_default_colors(int, int); 1277 | const char *curses_version(void); 1278 | bool has_key(int); 1279 | int use_default_colors(void); 1280 | int wresize(WINDOW *, int, int); 1281 | 1282 | int mouseinterval(int); 1283 | mmask_t mousemask(mmask_t, mmask_t *); 1284 | bool mouse_trafo(int *, int *, bool); 1285 | int nc_getmouse(MEVENT *); 1286 | int ungetmouse(MEVENT *); 1287 | bool wenclose(const WINDOW *, int, int); 1288 | bool wmouse_trafo(const WINDOW *, int *, int *, bool); 1289 | 1290 | /* PDCurses */ 1291 | 1292 | int addrawch(chtype); 1293 | int insrawch(chtype); 1294 | bool is_termresized(void); 1295 | int mvaddrawch(int, int, chtype); 1296 | int mvdeleteln(int, int); 1297 | int mvinsertln(int, int); 1298 | int mvinsrawch(int, int, chtype); 1299 | int mvwaddrawch(WINDOW *, int, int, chtype); 1300 | int mvwdeleteln(WINDOW *, int, int); 1301 | int mvwinsertln(WINDOW *, int, int); 1302 | int mvwinsrawch(WINDOW *, int, int, chtype); 1303 | int raw_output(bool); 1304 | int resize_term(int, int); 1305 | WINDOW *resize_window(WINDOW *, int, int); 1306 | int waddrawch(WINDOW *, chtype); 1307 | int winsrawch(WINDOW *, chtype); 1308 | char wordchar(void); 1309 | 1310 | #ifdef PDC_WIDE 1311 | wchar_t *slk_wlabel(int); 1312 | #endif 1313 | 1314 | void PDC_debug(const char *, ...); 1315 | int PDC_ungetch(int); 1316 | int PDC_set_blink(bool); 1317 | int PDC_set_line_color(short); 1318 | void PDC_set_title(const char *); 1319 | 1320 | int PDC_clearclipboard(void); 1321 | int PDC_freeclipboard(char *); 1322 | int PDC_getclipboard(char **, long *); 1323 | int PDC_setclipboard(const char *, long); 1324 | 1325 | unsigned long PDC_get_input_fd(void); 1326 | unsigned long PDC_get_key_modifiers(void); 1327 | int PDC_return_key_modifiers(bool); 1328 | int PDC_save_key_modifiers(bool); 1329 | 1330 | #ifdef XCURSES 1331 | WINDOW *Xinitscr(int, char **); 1332 | void XCursesExit(void); 1333 | int sb_init(void); 1334 | int sb_set_horz(int, int, int); 1335 | int sb_set_vert(int, int, int); 1336 | int sb_get_horz(int *, int *, int *); 1337 | int sb_get_vert(int *, int *, int *); 1338 | int sb_refresh(void); 1339 | #endif 1340 | 1341 | /*** Functions defined as macros ***/ 1342 | 1343 | /* getch() and ungetch() conflict with some DOS libraries */ 1344 | 1345 | #define getch() wgetch(stdscr) 1346 | #define ungetch(ch) PDC_ungetch(ch) 1347 | 1348 | #define COLOR_PAIR(n) (((chtype)(n) << PDC_COLOR_SHIFT) & A_COLOR) 1349 | #define PAIR_NUMBER(n) (((n) & A_COLOR) >> PDC_COLOR_SHIFT) 1350 | 1351 | /* These will _only_ work as macros */ 1352 | 1353 | #define getbegyx(w, y, x) (y = getbegy(w), x = getbegx(w)) 1354 | #define getmaxyx(w, y, x) (y = getmaxy(w), x = getmaxx(w)) 1355 | #define getparyx(w, y, x) (y = getpary(w), x = getparx(w)) 1356 | #define getyx(w, y, x) (y = getcury(w), x = getcurx(w)) 1357 | 1358 | #define getsyx(y, x) { if (curscr->_leaveit) (y)=(x)=-1; \ 1359 | else getyx(curscr,(y),(x)); } 1360 | 1361 | #ifdef NCURSES_MOUSE_VERSION 1362 | # define getmouse(x) nc_getmouse(x) 1363 | #endif 1364 | 1365 | /* return codes from PDC_getclipboard() and PDC_setclipboard() calls */ 1366 | 1367 | #define PDC_CLIP_SUCCESS 0 1368 | #define PDC_CLIP_ACCESS_ERROR 1 1369 | #define PDC_CLIP_EMPTY 2 1370 | #define PDC_CLIP_MEMORY_ERROR 3 1371 | 1372 | /* PDCurses key modifier masks */ 1373 | 1374 | #define PDC_KEY_MODIFIER_SHIFT 1 1375 | #define PDC_KEY_MODIFIER_CONTROL 2 1376 | #define PDC_KEY_MODIFIER_ALT 4 1377 | #define PDC_KEY_MODIFIER_NUMLOCK 8 1378 | 1379 | #if defined(__cplusplus) || defined(__cplusplus__) || defined(__CPLUSPLUS) 1380 | # undef bool 1381 | } 1382 | #endif 1383 | 1384 | #endif /* __PDCURSES__ */ 1385 | -------------------------------------------------------------------------------- /curspriv.h: -------------------------------------------------------------------------------- 1 | /* Public Domain Curses */ 2 | 3 | /* $Id: curspriv.h,v 1.158 2008/07/13 16:08:16 wmcbrine Exp $ */ 4 | 5 | /* Private definitions and declarations for use within PDCurses. 6 | These should generally not be referenced by applications. */ 7 | 8 | #ifndef __CURSES_INTERNALS__ 9 | #define __CURSES_INTERNALS__ 1 10 | 11 | #ifdef HAVE_CONFIG_H 12 | # include 13 | #endif 14 | 15 | #define CURSES_LIBRARY 16 | #include 17 | 18 | #if defined(__TURBOC__) || defined(__EMX__) || defined(__DJGPP__) || \ 19 | defined(__CYGWIN32__) || defined(__MINGW32__) || \ 20 | defined(__WATCOMC__) || defined(__PACIFIC__) 21 | # ifndef HAVE_VSSCANF 22 | # define HAVE_VSSCANF /* have vsscanf() */ 23 | # endif 24 | #endif 25 | 26 | #if defined(__CYGWIN32__) || defined(__MINGW32__) || \ 27 | defined(__LCC__) || defined(__WATCOMC__) 28 | # ifndef HAVE_VSNPRINTF 29 | # define HAVE_VSNPRINTF /* have vsnprintf() */ 30 | # endif 31 | #endif 32 | 33 | #if defined(_MSC_VER) && defined(_WIN32) && !defined(_CRT_SECURE_NO_DEPRECATE) 34 | # define _CRT_SECURE_NO_DEPRECATE 1 /* kill nonsense warnings */ 35 | #endif 36 | 37 | /*----------------------------------------------------------------------*/ 38 | 39 | typedef struct /* structure for ripped off lines */ 40 | { 41 | int line; 42 | int (*init)(WINDOW *, int); 43 | } RIPPEDOFFLINE; 44 | 45 | /* Window properties */ 46 | 47 | #define _SUBWIN 0x01 /* window is a subwindow */ 48 | #define _PAD 0x10 /* X/Open Pad. */ 49 | #define _SUBPAD 0x20 /* X/Open subpad. */ 50 | 51 | /* Miscellaneous */ 52 | 53 | #define _NO_CHANGE -1 /* flags line edge unchanged */ 54 | 55 | #define _ECHAR 0x08 /* Erase char (^H) */ 56 | #define _DWCHAR 0x17 /* Delete Word char (^W) */ 57 | #define _DLCHAR 0x15 /* Delete Line char (^U) */ 58 | 59 | extern WINDOW *pdc_lastscr; 60 | extern bool pdc_trace_on; /* tracing flag */ 61 | extern bool pdc_color_started; 62 | extern unsigned long pdc_key_modifiers; 63 | extern MOUSE_STATUS pdc_mouse_status; 64 | 65 | /*----------------------------------------------------------------------*/ 66 | 67 | /* Platform implementation functions */ 68 | 69 | void PDC_beep(void); 70 | bool PDC_can_change_color(void); 71 | int PDC_color_content(short, short *, short *, short *); 72 | bool PDC_check_key(void); 73 | int PDC_curs_set(int); 74 | void PDC_flushinp(void); 75 | int PDC_get_columns(void); 76 | int PDC_get_cursor_mode(void); 77 | int PDC_get_key(void); 78 | int PDC_get_rows(void); 79 | void PDC_gotoyx(int, int); 80 | int PDC_init_color(short, short, short, short); 81 | void PDC_init_pair(short, short, short); 82 | int PDC_modifiers_set(void); 83 | int PDC_mouse_set(void); 84 | void PDC_napms(int); 85 | int PDC_pair_content(short, short *, short *); 86 | void PDC_reset_prog_mode(void); 87 | void PDC_reset_shell_mode(void); 88 | int PDC_resize_screen(int, int); 89 | void PDC_restore_screen_mode(int); 90 | void PDC_save_screen_mode(int); 91 | void PDC_scr_close(void); 92 | void PDC_scr_free(void); 93 | int PDC_scr_open(int, char **); 94 | void PDC_set_keyboard_binary(bool); 95 | void PDC_transform_line(int, int, int, const chtype *); 96 | const char *PDC_sysname(void); 97 | 98 | /* Internal cross-module functions */ 99 | 100 | void PDC_init_atrtab(void); 101 | WINDOW *PDC_makelines(WINDOW *); 102 | WINDOW *PDC_makenew(int, int, int, int); 103 | int PDC_mouse_in_slk(int, int); 104 | void PDC_slk_free(void); 105 | void PDC_slk_initialize(void); 106 | void PDC_sync(WINDOW *); 107 | 108 | #ifdef PDC_WIDE 109 | int PDC_mbtowc(wchar_t *, const char *, size_t); 110 | size_t PDC_mbstowcs(wchar_t *, const char *, size_t); 111 | size_t PDC_wcstombs(char *, const wchar_t *, size_t); 112 | #endif 113 | 114 | #ifdef PDCDEBUG 115 | # define PDC_LOG(x) if (pdc_trace_on) PDC_debug x 116 | # define RCSID(x) static const char *rcsid = x; 117 | #else 118 | # define PDC_LOG(x) 119 | # define RCSID(x) 120 | #endif 121 | 122 | /* Internal macros for attributes */ 123 | 124 | #ifdef CHTYPE_LONG 125 | # define PDC_COLOR_PAIRS 256 126 | #else 127 | # define PDC_COLOR_PAIRS 32 128 | #endif 129 | 130 | #ifndef max 131 | # define max(a,b) (((a) > (b)) ? (a) : (b)) 132 | #endif 133 | #ifndef min 134 | # define min(a,b) (((a) < (b)) ? (a) : (b)) 135 | #endif 136 | 137 | #define DIVROUND(num, divisor) ((num) + ((divisor) >> 1)) / (divisor) 138 | 139 | #define PDC_CLICK_PERIOD 150 /* time to wait for a click, if 140 | not set by mouseinterval() */ 141 | 142 | #endif /* __CURSES_INTERNALS__*/ 143 | -------------------------------------------------------------------------------- /gen/distutils.cfg: -------------------------------------------------------------------------------- 1 | [build] 2 | compiler=mingw32 3 | -------------------------------------------------------------------------------- /gen/libpython23.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jmcb/python-pdcurses/a868ea7bd4cb6d13fde7eededa60f42fcb44ed51/gen/libpython23.a -------------------------------------------------------------------------------- /gen/pdcurses-win32a.def: -------------------------------------------------------------------------------- 1 | LIBRARY pdcurses.dll 2 | EXPORTS 3 | COLORS DATA 4 | COLOR_PAIRS DATA 5 | COLS DATA 6 | LINES DATA 7 | Mouse_status DATA 8 | PDC_clearclipboard 9 | PDC_debug 10 | PDC_freeclipboard 11 | PDC_get_input_fd 12 | PDC_get_key_modifiers 13 | PDC_getclipboard 14 | PDC_return_key_modifiers 15 | PDC_save_key_modifiers 16 | PDC_set_blink 17 | PDC_set_function_key 18 | PDC_set_line_color 19 | PDC_set_title 20 | PDC_setclipboard 21 | PDC_ungetch 22 | SP DATA 23 | TABSIZE DATA 24 | acs_map DATA 25 | addch 26 | addchnstr 27 | addchstr 28 | addnstr 29 | addrawch 30 | addstr 31 | assume_default_colors 32 | attr_get 33 | attr_off 34 | attr_on 35 | attr_set 36 | attroff 37 | attron 38 | attrset 39 | baudrate 40 | beep 41 | bkgd 42 | bkgdset 43 | border 44 | bottom_panel 45 | box 46 | can_change_color 47 | cbreak 48 | chgat 49 | clear 50 | clearok 51 | clrtobot 52 | clrtoeol 53 | color_content 54 | color_set 55 | copywin 56 | crmode 57 | cur_term DATA 58 | curs_set 59 | curscr DATA 60 | curses_version 61 | def_prog_mode 62 | def_shell_mode 63 | del_curterm 64 | del_panel 65 | delay_output 66 | delch 67 | deleteln 68 | delscreen 69 | delwin 70 | derwin 71 | doupdate 72 | draino 73 | dupwin 74 | echo 75 | echochar 76 | endwin 77 | erase 78 | erasechar 79 | filter 80 | fixterm 81 | flash 82 | flushinp 83 | getattrs 84 | getbegx 85 | getbegy 86 | getbkgd 87 | getbmap 88 | getcurx 89 | getcury 90 | getmaxx 91 | getmaxy 92 | getmouse 93 | getnstr 94 | getparx 95 | getpary 96 | getstr 97 | getwin 98 | halfdelay 99 | has_colors 100 | has_ic 101 | has_il 102 | has_key 103 | hide_panel 104 | hline 105 | idcok 106 | idlok 107 | immedok 108 | inch 109 | inchnstr 110 | inchstr 111 | init_color 112 | init_pair 113 | initscr 114 | innstr 115 | insch 116 | insdelln 117 | insertln 118 | insnstr 119 | insrawch 120 | insstr 121 | instr 122 | intrflush 123 | is_linetouched 124 | is_termresized 125 | is_wintouched 126 | isendwin 127 | keyname 128 | keypad 129 | killchar 130 | leaveok 131 | longname 132 | map_button 133 | meta 134 | mouse_off 135 | mouse_on 136 | mouse_set 137 | mouse_trafo 138 | mouseinterval 139 | mousemask 140 | move 141 | move_panel 142 | mvaddch 143 | mvaddchnstr 144 | mvaddchstr 145 | mvaddnstr 146 | mvaddrawch 147 | mvaddstr 148 | mvchgat 149 | mvcur 150 | mvdelch 151 | mvdeleteln 152 | mvderwin 153 | mvgetch 154 | mvgetnstr 155 | mvgetstr 156 | mvhline 157 | mvinch 158 | mvinchnstr 159 | mvinchstr 160 | mvinnstr 161 | mvinsch 162 | mvinsertln 163 | mvinsnstr 164 | mvinsrawch 165 | mvinsstr 166 | mvinstr 167 | mvprintw 168 | mvscanw 169 | mvvline 170 | mvwaddch 171 | mvwaddchnstr 172 | mvwaddchstr 173 | mvwaddnstr 174 | mvwaddrawch 175 | mvwaddstr 176 | mvwchgat 177 | mvwdelch 178 | mvwdeleteln 179 | mvwgetch 180 | mvwgetnstr 181 | mvwgetstr 182 | mvwhline 183 | mvwin 184 | mvwinch 185 | mvwinchnstr 186 | mvwinchstr 187 | mvwinnstr 188 | mvwinsch 189 | mvwinsertln 190 | mvwinsnstr 191 | mvwinsrawch 192 | mvwinsstr 193 | mvwinstr 194 | mvwprintw 195 | mvwscanw 196 | mvwvline 197 | napms 198 | nc_getmouse 199 | new_panel 200 | newpad 201 | newterm 202 | newwin 203 | nl 204 | nocbreak 205 | nocrmode 206 | nodelay 207 | noecho 208 | nonl 209 | noqiflush 210 | noraw 211 | notimeout 212 | overlay 213 | overwrite 214 | pair_content 215 | panel_above 216 | panel_below 217 | panel_hidden 218 | panel_userptr 219 | panel_window 220 | pechochar 221 | pnoutrefresh 222 | prefresh 223 | printw 224 | putp 225 | putwin 226 | qiflush 227 | raw 228 | raw_output 229 | redrawwin 230 | refresh 231 | replace_panel 232 | request_mouse_pos 233 | reset_prog_mode 234 | reset_shell_mode 235 | resetterm 236 | resetty 237 | resize_term 238 | resize_window 239 | restartterm 240 | ripoffline 241 | saveterm 242 | savetty 243 | scanw 244 | scr_dump 245 | scr_init 246 | scr_restore 247 | scr_set 248 | scrl 249 | scroll 250 | scrollok 251 | set_curterm 252 | set_panel_userptr 253 | set_term 254 | setscrreg 255 | setsyx 256 | setterm 257 | setupterm 258 | show_panel 259 | slk_attr_off 260 | slk_attr_on 261 | slk_attr_set 262 | slk_attroff 263 | slk_attron 264 | slk_attrset 265 | slk_clear 266 | slk_color 267 | slk_init 268 | slk_label 269 | slk_noutrefresh 270 | slk_refresh 271 | slk_restore 272 | slk_set 273 | slk_touch 274 | standend 275 | standout 276 | start_color 277 | stdscr DATA 278 | subpad 279 | subwin 280 | syncok 281 | term_attrs 282 | termattrs 283 | termname 284 | tgetent 285 | tgetflag 286 | tgetnum 287 | tgetstr 288 | tgoto 289 | tigetflag 290 | tigetnum 291 | tigetstr 292 | timeout 293 | top_panel 294 | touchline 295 | touchwin 296 | tparm 297 | tputs 298 | traceoff 299 | traceon 300 | ttytype DATA 301 | typeahead 302 | unctrl 303 | ungetmouse 304 | untouchwin 305 | update_panels 306 | use_default_colors 307 | use_env 308 | vid_attr 309 | vid_puts 310 | vidattr 311 | vidputs 312 | vline 313 | vw_printw 314 | vw_scanw 315 | vwprintw 316 | vwscanw 317 | waddch 318 | waddchnstr 319 | waddchstr 320 | waddnstr 321 | waddrawch 322 | waddstr 323 | wattr_get 324 | wattr_off 325 | wattr_on 326 | wattr_set 327 | wattroff 328 | wattron 329 | wattrset 330 | wbkgd 331 | wbkgdset 332 | wborder 333 | wchgat 334 | wclear 335 | wclrtobot 336 | wclrtoeol 337 | wcolor_set 338 | wcursyncup 339 | wdelch 340 | wdeleteln 341 | wechochar 342 | wenclose 343 | werase 344 | wgetch 345 | wgetnstr 346 | wgetstr 347 | whline 348 | winch 349 | winchnstr 350 | winchstr 351 | winnstr 352 | winsch 353 | winsdelln 354 | winsertln 355 | winsnstr 356 | winsrawch 357 | winsstr 358 | winstr 359 | wmouse_position 360 | wmouse_trafo 361 | wmove 362 | wnoutrefresh 363 | wordchar 364 | wprintw 365 | wredrawln 366 | wrefresh 367 | wresize 368 | wscanw 369 | wscrl 370 | wsetscrreg 371 | wstandend 372 | wstandout 373 | wsyncdown 374 | wsyncup 375 | wtimeout 376 | wtouchln 377 | wvline 378 | -------------------------------------------------------------------------------- /gen/pdcurses-win32a.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jmcb/python-pdcurses/a868ea7bd4cb6d13fde7eededa60f42fcb44ed51/gen/pdcurses-win32a.lib -------------------------------------------------------------------------------- /gen/pdcurses.def: -------------------------------------------------------------------------------- 1 | LIBRARY pdcurses.dll 2 | EXPORTS 3 | COLORS DATA 4 | COLOR_PAIRS DATA 5 | COLS DATA 6 | LINES DATA 7 | Mouse_status DATA 8 | PDC_clearclipboard 9 | PDC_debug 10 | PDC_freeclipboard 11 | PDC_get_input_fd 12 | PDC_get_key_modifiers 13 | PDC_getclipboard 14 | PDC_return_key_modifiers 15 | PDC_save_key_modifiers 16 | PDC_set_blink 17 | PDC_set_line_color 18 | PDC_set_title 19 | PDC_setclipboard 20 | PDC_ungetch 21 | SP DATA 22 | TABSIZE DATA 23 | acs_map DATA 24 | add_wch 25 | add_wchnstr 26 | add_wchstr 27 | addch 28 | addchnstr 29 | addchstr 30 | addnstr 31 | addnwstr 32 | addrawch 33 | addstr 34 | addwstr 35 | assume_default_colors 36 | attr_get 37 | attr_off 38 | attr_on 39 | attr_set 40 | attroff 41 | attron 42 | attrset 43 | baudrate 44 | beep 45 | bkgd 46 | bkgdset 47 | border 48 | border_set 49 | bottom_panel 50 | box 51 | box_set 52 | can_change_color 53 | cbreak 54 | chgat 55 | clear 56 | clearok 57 | clrtobot 58 | clrtoeol 59 | color_content 60 | color_set 61 | copywin 62 | crmode 63 | cur_term DATA 64 | curs_set 65 | curscr DATA 66 | curses_version 67 | def_prog_mode 68 | def_shell_mode 69 | del_curterm 70 | del_panel 71 | delay_output 72 | delch 73 | deleteln 74 | delscreen 75 | delwin 76 | derwin 77 | doupdate 78 | draino 79 | dupwin 80 | echo 81 | echo_wchar 82 | echochar 83 | endwin 84 | erase 85 | erasechar 86 | erasewchar 87 | filter 88 | fixterm 89 | flash 90 | flushinp 91 | get_wch 92 | get_wstr 93 | getattrs 94 | getbegx 95 | getbegy 96 | getbkgd 97 | getbkgrnd 98 | getbmap 99 | getcchar 100 | getcurx 101 | getcury 102 | getmaxx 103 | getmaxy 104 | getmouse 105 | getn_wstr 106 | getnstr 107 | getparx 108 | getpary 109 | getstr 110 | getwin 111 | halfdelay 112 | has_colors 113 | has_ic 114 | has_il 115 | has_key 116 | hide_panel 117 | hline 118 | hline_set 119 | idcok 120 | idlok 121 | immedok 122 | in_wch 123 | in_wchnstr 124 | in_wchstr 125 | inch 126 | inchnstr 127 | inchstr 128 | init_color 129 | init_pair 130 | initscr 131 | innstr 132 | innwstr 133 | ins_nwstr 134 | ins_wch 135 | ins_wstr 136 | insch 137 | insdelln 138 | insertln 139 | insnstr 140 | insrawch 141 | insstr 142 | instr 143 | intrflush 144 | inwstr 145 | is_linetouched 146 | is_termresized 147 | is_wintouched 148 | isendwin 149 | key_name 150 | keyname 151 | keypad 152 | killchar 153 | killwchar 154 | leaveok 155 | longname 156 | map_button 157 | meta 158 | mouse_off 159 | mouse_on 160 | mouse_set 161 | mouse_trafo 162 | mouseinterval 163 | mousemask 164 | move 165 | move_panel 166 | mvadd_wch 167 | mvadd_wchnstr 168 | mvadd_wchstr 169 | mvaddch 170 | mvaddchnstr 171 | mvaddchstr 172 | mvaddnstr 173 | mvaddnwstr 174 | mvaddrawch 175 | mvaddstr 176 | mvaddwstr 177 | mvchgat 178 | mvcur 179 | mvdelch 180 | mvdeleteln 181 | mvderwin 182 | mvget_wch 183 | mvget_wstr 184 | mvgetch 185 | mvgetn_wstr 186 | mvgetnstr 187 | mvgetstr 188 | mvhline 189 | mvhline_set 190 | mvin_wch 191 | mvin_wchnstr 192 | mvin_wchstr 193 | mvinch 194 | mvinchnstr 195 | mvinchstr 196 | mvinnstr 197 | mvinnwstr 198 | mvins_nwstr 199 | mvins_wch 200 | mvins_wstr 201 | mvinsch 202 | mvinsertln 203 | mvinsnstr 204 | mvinsrawch 205 | mvinsstr 206 | mvinstr 207 | mvinwstr 208 | mvprintw 209 | mvscanw 210 | mvvline 211 | mvvline_set 212 | mvwadd_wch 213 | mvwadd_wchnstr 214 | mvwadd_wchstr 215 | mvwaddch 216 | mvwaddchnstr 217 | mvwaddchstr 218 | mvwaddnstr 219 | mvwaddnwstr 220 | mvwaddrawch 221 | mvwaddstr 222 | mvwaddwstr 223 | mvwchgat 224 | mvwdelch 225 | mvwdeleteln 226 | mvwget_wch 227 | mvwget_wstr 228 | mvwgetch 229 | mvwgetn_wstr 230 | mvwgetnstr 231 | mvwgetstr 232 | mvwhline 233 | mvwhline_set 234 | mvwin 235 | mvwin_wch 236 | mvwin_wchnstr 237 | mvwin_wchstr 238 | mvwinch 239 | mvwinchnstr 240 | mvwinchstr 241 | mvwinnstr 242 | mvwinnwstr 243 | mvwins_nwstr 244 | mvwins_wch 245 | mvwins_wstr 246 | mvwinsch 247 | mvwinsertln 248 | mvwinsnstr 249 | mvwinsrawch 250 | mvwinsstr 251 | mvwinstr 252 | mvwinwstr 253 | mvwprintw 254 | mvwscanw 255 | mvwvline 256 | mvwvline_set 257 | napms 258 | nc_getmouse 259 | new_panel 260 | newpad 261 | newterm 262 | newwin 263 | nl 264 | nocbreak 265 | nocrmode 266 | nodelay 267 | noecho 268 | nonl 269 | noqiflush 270 | noraw 271 | notimeout 272 | overlay 273 | overwrite 274 | pair_content 275 | panel_above 276 | panel_below 277 | panel_hidden 278 | panel_userptr 279 | panel_window 280 | pecho_wchar 281 | pechochar 282 | pnoutrefresh 283 | prefresh 284 | printw 285 | putp 286 | putwin 287 | qiflush 288 | raw 289 | raw_output 290 | redrawwin 291 | refresh 292 | replace_panel 293 | request_mouse_pos 294 | reset_prog_mode 295 | reset_shell_mode 296 | resetterm 297 | resetty 298 | resize_term 299 | resize_window 300 | restartterm 301 | ripoffline 302 | saveterm 303 | savetty 304 | scanw 305 | scr_dump 306 | scr_init 307 | scr_restore 308 | scr_set 309 | scrl 310 | scroll 311 | scrollok 312 | set_curterm 313 | set_panel_userptr 314 | set_term 315 | setcchar 316 | setscrreg 317 | setsyx 318 | setterm 319 | setupterm 320 | show_panel 321 | slk_attr_off 322 | slk_attr_on 323 | slk_attr_set 324 | slk_attroff 325 | slk_attron 326 | slk_attrset 327 | slk_clear 328 | slk_color 329 | slk_init 330 | slk_label 331 | slk_noutrefresh 332 | slk_refresh 333 | slk_restore 334 | slk_set 335 | slk_touch 336 | slk_wset 337 | standend 338 | standout 339 | start_color 340 | stdscr DATA 341 | subpad 342 | subwin 343 | syncok 344 | term_attrs 345 | termattrs 346 | termname 347 | tgetent 348 | tgetflag 349 | tgetnum 350 | tgetstr 351 | tgoto 352 | tigetflag 353 | tigetnum 354 | tigetstr 355 | timeout 356 | top_panel 357 | touchline 358 | touchwin 359 | tparm 360 | tputs 361 | traceoff 362 | traceon 363 | ttytype DATA 364 | typeahead 365 | unctrl 366 | unget_wch 367 | ungetmouse 368 | untouchwin 369 | update_panels 370 | use_default_colors 371 | use_env 372 | vid_attr 373 | vid_puts 374 | vidattr 375 | vidputs 376 | vline 377 | vline_set 378 | vw_printw 379 | vw_scanw 380 | vwprintw 381 | vwscanw 382 | wadd_wch 383 | wadd_wchnstr 384 | wadd_wchstr 385 | waddch 386 | waddchnstr 387 | waddchstr 388 | waddnstr 389 | waddnwstr 390 | waddrawch 391 | waddstr 392 | waddwstr 393 | wattr_get 394 | wattr_off 395 | wattr_on 396 | wattr_set 397 | wattroff 398 | wattron 399 | wattrset 400 | wbkgd 401 | wbkgdset 402 | wbkgrnd 403 | wbkgrndset 404 | wborder 405 | wborder_set 406 | wchgat 407 | wclear 408 | wclrtobot 409 | wclrtoeol 410 | wcolor_set 411 | wcursyncup 412 | wdelch 413 | wdeleteln 414 | wecho_wchar 415 | wechochar 416 | wenclose 417 | werase 418 | wget_wch 419 | wget_wstr 420 | wgetbkgrnd 421 | wgetch 422 | wgetn_wstr 423 | wgetnstr 424 | wgetstr 425 | whline 426 | whline_set 427 | win_wch 428 | win_wchnstr 429 | win_wchstr 430 | winch 431 | winchnstr 432 | winchstr 433 | winnstr 434 | winnwstr 435 | wins_nwstr 436 | wins_wch 437 | wins_wstr 438 | winsch 439 | winsdelln 440 | winsertln 441 | winsnstr 442 | winsrawch 443 | winsstr 444 | winstr 445 | winwstr 446 | wmouse_position 447 | wmouse_trafo 448 | wmove 449 | wnoutrefresh 450 | wordchar 451 | wprintw 452 | wredrawln 453 | wrefresh 454 | wresize 455 | wscanw 456 | wscrl 457 | wsetscrreg 458 | wstandend 459 | wstandout 460 | wsyncdown 461 | wsyncup 462 | wtimeout 463 | wtouchln 464 | wunctrl 465 | wvline 466 | wvline_set 467 | -------------------------------------------------------------------------------- /gen/pdcurses.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jmcb/python-pdcurses/a868ea7bd4cb6d13fde7eededa60f42fcb44ed51/gen/pdcurses.lib -------------------------------------------------------------------------------- /gen/setup-win32a.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | python-pdcurses-win32a setup module. 4 | """ 5 | 6 | from distutils.core import setup, Extension 7 | import os, sys 8 | 9 | extra_link = [] 10 | extra_comp = [] 11 | extra_libs = [] 12 | 13 | def main (): 14 | setup ( 15 | name = "pdcurses-win32a", 16 | version = "0.3.4", 17 | description = "PDCurses drop-in replacement for _curses.", 18 | author = "Jon McManus, PDCurses", 19 | author_email = "jonathan@acss.net.au", 20 | url = "http://www.github.com/jmcb/python-pdcurses", 21 | long_description = """""", 22 | classifiers = [ 23 | 'Development Status :: 5 - Production/Stable', # PDCurses is a stable replacement for _curses. 24 | 'Environment :: Console', 25 | 'Environment :: Console :: Curses', 26 | 'Intended Audience :: Developers', 27 | 'License :: Public Domain', 28 | 'Operating System :: OS Independent', 29 | 'Programming Language :: C', 30 | 'Programming Language :: Python', 31 | 'Programming Language :: Python : 2.3', 32 | 'Programming Language :: Python : 2.4', 33 | 'Programming Language :: Python : 2.5', 34 | 'Programming Language :: Python : 2.6', 35 | 'Programming Language :: Python : 2.7', 36 | 'Topic :: Software Development :: Libraries :: Python Modules', 37 | ], 38 | ext_modules = [Extension ('_curses', 39 | sources = ['_curses_panel.c', '_cursesmodule.c'], 40 | define_macros = [("WINDOW_HAS_FLAGS", None)], 41 | extra_compile_args = ['-L./'] + extra_comp, 42 | extra_link_args = ['-L./'] + extra_link, 43 | libraries = ["pdcurses"] + extra_libs)], 44 | data_files = [(".", ["pdcurses.dll"])], 45 | include_dirs = ['./'], 46 | ) 47 | 48 | if __name__=="__main__": 49 | main() 50 | -------------------------------------------------------------------------------- /gen/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | python-pdcurses setup module. 4 | """ 5 | 6 | from distutils.core import setup, Extension 7 | import os, sys 8 | 9 | extra_link = [] 10 | extra_comp = [] 11 | extra_libs = [] 12 | 13 | def main (): 14 | setup ( 15 | name = "pdcurses", 16 | version = "0.3.4", 17 | description = "PDCurses drop-in replacement for _curses.", 18 | author = "Jon McManus, PDCurses", 19 | author_email = "jonathan@acss.net.au", 20 | url = "http://www.github.com/jmcb/python-pdcurses", 21 | long_description = """""", 22 | classifiers = [ 23 | 'Development Status :: 5 - Production/Stable', # PDCurses is a stable replacement for _curses. 24 | 'Environment :: Console', 25 | 'Environment :: Console :: Curses', 26 | 'Intended Audience :: Developers', 27 | 'License :: Public Domain', 28 | 'Operating System :: OS Independent', 29 | 'Programming Language :: C', 30 | 'Programming Language :: Python', 31 | 'Programming Language :: Python : 2.3', 32 | 'Programming Language :: Python : 2.4', 33 | 'Programming Language :: Python : 2.5', 34 | 'Programming Language :: Python : 2.6', 35 | 'Programming Language :: Python : 2.7', 36 | 'Topic :: Software Development :: Libraries :: Python Modules', 37 | ], 38 | ext_modules = [Extension ('_curses', 39 | sources = ['_curses_panel.c', '_cursesmodule.c'], 40 | define_macros = [("WINDOW_HAS_FLAGS", None)], 41 | extra_compile_args = ['-L./'] + extra_comp, 42 | extra_link_args = ['-L./'] + extra_link, 43 | libraries = ["pdcurses"] + extra_libs)], 44 | data_files = [(".", ["pdcurses.dll"])], 45 | include_dirs = ['./'], 46 | ) 47 | 48 | if __name__=="__main__": 49 | main() 50 | -------------------------------------------------------------------------------- /panel.h: -------------------------------------------------------------------------------- 1 | /* Public Domain Curses */ 2 | 3 | /* $Id: panel.h,v 1.19 2008/07/13 16:08:16 wmcbrine Exp $ */ 4 | 5 | /*----------------------------------------------------------------------* 6 | * Panels for PDCurses * 7 | *----------------------------------------------------------------------*/ 8 | 9 | #ifndef __PDCURSES_PANEL_H__ 10 | #define __PDCURSES_PANEL_H__ 1 11 | 12 | #include 13 | 14 | #if defined(__cplusplus) || defined(__cplusplus__) || defined(__CPLUSPLUS) 15 | extern "C" 16 | { 17 | #endif 18 | 19 | typedef struct panelobs 20 | { 21 | struct panelobs *above; 22 | struct panel *pan; 23 | } PANELOBS; 24 | 25 | typedef struct panel 26 | { 27 | WINDOW *win; 28 | int wstarty; 29 | int wendy; 30 | int wstartx; 31 | int wendx; 32 | struct panel *below; 33 | struct panel *above; 34 | const void *user; 35 | struct panelobs *obscure; 36 | } PANEL; 37 | 38 | int bottom_panel(PANEL *pan); 39 | int del_panel(PANEL *pan); 40 | int hide_panel(PANEL *pan); 41 | int move_panel(PANEL *pan, int starty, int startx); 42 | PANEL *new_panel(WINDOW *win); 43 | PANEL *panel_above(const PANEL *pan); 44 | PANEL *panel_below(const PANEL *pan); 45 | int panel_hidden(const PANEL *pan); 46 | const void *panel_userptr(const PANEL *pan); 47 | WINDOW *panel_window(const PANEL *pan); 48 | int replace_panel(PANEL *pan, WINDOW *win); 49 | int set_panel_userptr(PANEL *pan, const void *uptr); 50 | int show_panel(PANEL *pan); 51 | int top_panel(PANEL *pan); 52 | void update_panels(void); 53 | 54 | #if defined(__cplusplus) || defined(__cplusplus__) || defined(__CPLUSPLUS) 55 | } 56 | #endif 57 | 58 | #endif /* __PDCURSES_PANEL_H__ */ 59 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env 2 | """ 3 | A rather hack-y script for supporting pip. 4 | """ 5 | 6 | import os, shutil 7 | 8 | class SetupError (Exception): pass 9 | 10 | def main (): 11 | template = open("setup.py_template").read() 12 | template = template.replace("PDCURSES_FLAV", "") 13 | fn = open("setup2.py", "w") 14 | fn.write(template) 15 | fn.close() 16 | 17 | if not os.path.exists("pdcurses.dll"): 18 | raise SetupError, "Cannot find a pdcurses.dll file. Please provide one." 19 | 20 | shutil.copyfile("gen/pdcurses.def", "pdcurses.def") 21 | shutil.copyfile("gen/pdcurses.lib", "pdcurses.lib") 22 | 23 | import setup2 24 | setup2.main() 25 | 26 | os.unlink("setup2.py") 27 | 28 | 29 | if __name__=="__main__": 30 | main() 31 | -------------------------------------------------------------------------------- /setup.py_template: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | python-pdcursesPDCURSES_FLAV setup module. 4 | """ 5 | 6 | import distutils.version 7 | from distutils.core import setup, Extension 8 | import os, sys 9 | 10 | extra_link = [] 11 | extra_comp = [] 12 | extra_libs = [] 13 | 14 | def monkey_cmp (self, other): 15 | """ 16 | Monkey patch to resolve issue with 3.0 distutils. 17 | """ 18 | if isinstance(other, str): 19 | other = distutils.version.LooseVersion(other) 20 | 21 | if self.version == other.version: 22 | return 0 23 | if self.version < other.version: 24 | return -1 25 | if self.version > other.version: 26 | return 1 27 | 28 | if sys.hexversion <= 0x30001f0 and sys.hexversion >= 0x30000f0: 29 | distutils.version.LooseVersion._cmp = monkey_cmp 30 | 31 | def main (): 32 | setup ( 33 | name = "pdcursesPDCURSES_FLAV", 34 | version = "0.3.4", 35 | description = "PDCurses drop-in replacement for _curses.", 36 | author = "Jon McManus, PDCurses", 37 | author_email = "jonathan@acss.net.au", 38 | url = "http://www.github.com/jmcb/python-pdcurses", 39 | long_description = """""", 40 | classifiers = [ 41 | 'Development Status :: 5 - Production/Stable', # PDCurses is a stable replacement for _curses. 42 | 'Environment :: Console', 43 | 'Environment :: Console :: Curses', 44 | 'Intended Audience :: Developers', 45 | 'License :: Public Domain', 46 | 'Operating System :: OS Independent', 47 | 'Programming Language :: C', 48 | 'Programming Language :: Python', 49 | 'Programming Language :: Python : 2.3', 50 | 'Programming Language :: Python : 2.4', 51 | 'Programming Language :: Python : 2.5', 52 | 'Programming Language :: Python : 2.6', 53 | 'Programming Language :: Python : 2.7', 54 | 'Topic :: Software Development :: Libraries :: Python Modules', 55 | ], 56 | ext_modules = [Extension ('_curses', 57 | sources = ['_curses_panel.c', '_cursesmodule.c'], 58 | define_macros = [("WINDOW_HAS_FLAGS", None)], 59 | extra_compile_args = ['-L./'] + extra_comp, 60 | extra_link_args = ['-L./'] + extra_link, 61 | libraries = ["pdcurses"] + extra_libs)], 62 | data_files = [(".", ["pdcurses.dll"])], 63 | include_dirs = ['./'], 64 | ) 65 | 66 | if __name__=="__main__": 67 | main() 68 | -------------------------------------------------------------------------------- /term.h: -------------------------------------------------------------------------------- 1 | /* Public Domain Curses */ 2 | 3 | /* $Id: term.h,v 1.16 2008/07/13 16:08:16 wmcbrine Exp $ */ 4 | 5 | /* PDCurses doesn't operate with terminfo, but we need these functions for 6 | compatibility, to allow some things (notably, interface libraries for 7 | other languages) to be compiled. Anyone who tries to actually _use_ 8 | them will be disappointed, since they only return ERR. */ 9 | 10 | #ifndef __PDCURSES_TERM_H__ 11 | #define __PDCURSES_TERM_H__ 1 12 | 13 | #include 14 | 15 | #if defined(__cplusplus) || defined(__cplusplus__) || defined(__CPLUSPLUS) 16 | extern "C" 17 | { 18 | #endif 19 | 20 | typedef struct 21 | { 22 | const char *_termname; 23 | } TERMINAL; 24 | 25 | #ifdef PDC_DLL_BUILD 26 | # ifndef CURSES_LIBRARY 27 | __declspec(dllimport) TERMINAL *cur_term; 28 | # else 29 | __declspec(dllexport) extern TERMINAL *cur_term; 30 | # endif 31 | #else 32 | extern TERMINAL *cur_term; 33 | #endif 34 | 35 | int del_curterm(TERMINAL *); 36 | int putp(const char *); 37 | int restartterm(const char *, int, int *); 38 | TERMINAL *set_curterm(TERMINAL *); 39 | int setterm(const char *); 40 | int setupterm(const char *, int, int *); 41 | int tgetent(char *, const char *); 42 | int tgetflag(const char *); 43 | int tgetnum(const char *); 44 | char *tgetstr(const char *, char **); 45 | char *tgoto(const char *, int, int); 46 | int tigetflag(const char *); 47 | int tigetnum(const char *); 48 | char *tigetstr(const char *); 49 | char *tparm(const char *, long, long, long, long, long, 50 | long, long, long, long); 51 | int tputs(const char *, int, int (*)(int)); 52 | 53 | #if defined(__cplusplus) || defined(__cplusplus__) || defined(__CPLUSPLUS) 54 | } 55 | #endif 56 | 57 | #endif /* __PDCURSES_TERM_H__ */ 58 | --------------------------------------------------------------------------------