bpo-38312: Add curses.{get,set}_escdelay and curses.{get,set}_tabsize. (GH-16938)
This commit is contained in:
parent
b15100fe7d
commit
b32cb97bce
|
@ -511,6 +511,32 @@ The module :mod:`curses` defines the following functions:
|
|||
Save the current state of the terminal modes in a buffer, usable by
|
||||
:func:`resetty`.
|
||||
|
||||
.. function:: get_escdelay()
|
||||
|
||||
Retrieves the value set by :func:`set_escdelay`.
|
||||
|
||||
.. versionadded:: 3.9
|
||||
|
||||
.. function:: set_escdelay(ms)
|
||||
|
||||
Sets the number of milliseconds to wait after reading an escape character,
|
||||
to distinguish between an individual escape character entered on the
|
||||
keyboard from escape sequences sent by cursor and function keys.
|
||||
|
||||
.. versionadded:: 3.9
|
||||
|
||||
.. function:: get_tabsize()
|
||||
|
||||
Retrieves the value set by :func:`set_tabsize`.
|
||||
|
||||
.. versionadded:: 3.9
|
||||
|
||||
.. function:: set_tabsize(size)
|
||||
|
||||
Sets the number of columns used by the curses library when converting a tab
|
||||
character to spaces as it adds the tab to a window.
|
||||
|
||||
.. versionadded:: 3.9
|
||||
|
||||
.. function:: setsyx(y, x)
|
||||
|
||||
|
|
|
@ -130,6 +130,13 @@ that schedules a shutdown for the default executor that waits on the
|
|||
:func:`asyncio.run` has been updated to use the new :term:`coroutine`.
|
||||
(Contributed by Kyle Stanley in :issue:`34037`.)
|
||||
|
||||
curses
|
||||
------
|
||||
|
||||
Add :func:`curses.get_escdelay`, :func:`curses.set_escdelay`,
|
||||
:func:`curses.get_tabsize`, and :func:`curses.set_tabsize` functions.
|
||||
(Contributed by Anthony Sottile in :issue:`38312`.)
|
||||
|
||||
fcntl
|
||||
-----
|
||||
|
||||
|
|
|
@ -261,6 +261,10 @@ class TestCurses(unittest.TestCase):
|
|||
curses.putp(b'abc')
|
||||
curses.qiflush()
|
||||
curses.raw() ; curses.raw(1)
|
||||
curses.set_escdelay(25)
|
||||
self.assertEqual(curses.get_escdelay(), 25)
|
||||
curses.set_tabsize(4)
|
||||
self.assertEqual(curses.get_tabsize(), 4)
|
||||
if hasattr(curses, 'setsyx'):
|
||||
curses.setsyx(5,5)
|
||||
curses.tigetflag('hc')
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
Add :func:`curses.get_escdelay`, :func:`curses.set_escdelay`,
|
||||
:func:`curses.get_tabsize`, and :func:`curses.set_tabsize` functions -
|
||||
by Anthony Sottile.
|
|
@ -3255,6 +3255,86 @@ _curses_setupterm_impl(PyObject *module, const char *term, int fd)
|
|||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
_curses.get_escdelay
|
||||
|
||||
Gets the curses ESCDELAY setting.
|
||||
|
||||
Gets the number of milliseconds to wait after reading an escape character,
|
||||
to distinguish between an individual escape character entered on the
|
||||
keyboard from escape sequences sent by cursor and function keys.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_curses_get_escdelay_impl(PyObject *module)
|
||||
/*[clinic end generated code: output=222fa1a822555d60 input=be2d5b3dd974d0a4]*/
|
||||
{
|
||||
return PyLong_FromLong(ESCDELAY);
|
||||
}
|
||||
/*[clinic input]
|
||||
_curses.set_escdelay
|
||||
ms: int
|
||||
length of the delay in milliseconds.
|
||||
/
|
||||
|
||||
Sets the curses ESCDELAY setting.
|
||||
|
||||
Sets the number of milliseconds to wait after reading an escape character,
|
||||
to distinguish between an individual escape character entered on the
|
||||
keyboard from escape sequences sent by cursor and function keys.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_curses_set_escdelay_impl(PyObject *module, int ms)
|
||||
/*[clinic end generated code: output=43818efbf7980ac4 input=7796fe19f111e250]*/
|
||||
{
|
||||
if (ms <= 0) {
|
||||
PyErr_SetString(PyExc_ValueError, "ms must be > 0");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return PyCursesCheckERR(set_escdelay(ms), "set_escdelay");
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
_curses.get_tabsize
|
||||
|
||||
Gets the curses TABSIZE setting.
|
||||
|
||||
Gets the number of columns used by the curses library when converting a tab
|
||||
character to spaces as it adds the tab to a window.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_curses_get_tabsize_impl(PyObject *module)
|
||||
/*[clinic end generated code: output=7e9e51fb6126fbdf input=74af86bf6c9f5d7e]*/
|
||||
{
|
||||
return PyLong_FromLong(TABSIZE);
|
||||
}
|
||||
/*[clinic input]
|
||||
_curses.set_tabsize
|
||||
size: int
|
||||
rendered cell width of a tab character.
|
||||
/
|
||||
|
||||
Sets the curses TABSIZE setting.
|
||||
|
||||
Sets the number of columns used by the curses library when converting a tab
|
||||
character to spaces as it adds the tab to a window.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_curses_set_tabsize_impl(PyObject *module, int size)
|
||||
/*[clinic end generated code: output=c1de5a76c0daab1e input=78cba6a3021ad061]*/
|
||||
{
|
||||
if (size <= 0) {
|
||||
PyErr_SetString(PyExc_ValueError, "size must be > 0");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return PyCursesCheckERR(set_tabsize(size), "set_tabsize");
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
_curses.intrflush
|
||||
|
||||
|
@ -4415,6 +4495,10 @@ static PyMethodDef PyCurses_methods[] = {
|
|||
_CURSES_RESIZETERM_METHODDEF
|
||||
_CURSES_RESIZE_TERM_METHODDEF
|
||||
_CURSES_SAVETTY_METHODDEF
|
||||
_CURSES_GET_ESCDELAY_METHODDEF
|
||||
_CURSES_SET_ESCDELAY_METHODDEF
|
||||
_CURSES_GET_TABSIZE_METHODDEF
|
||||
_CURSES_SET_TABSIZE_METHODDEF
|
||||
_CURSES_SETSYX_METHODDEF
|
||||
_CURSES_SETUPTERM_METHODDEF
|
||||
_CURSES_START_COLOR_METHODDEF
|
||||
|
|
|
@ -3040,6 +3040,128 @@ exit:
|
|||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(_curses_get_escdelay__doc__,
|
||||
"get_escdelay($module, /)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Gets the curses ESCDELAY setting.\n"
|
||||
"\n"
|
||||
"Gets the number of milliseconds to wait after reading an escape character,\n"
|
||||
"to distinguish between an individual escape character entered on the\n"
|
||||
"keyboard from escape sequences sent by cursor and function keys.");
|
||||
|
||||
#define _CURSES_GET_ESCDELAY_METHODDEF \
|
||||
{"get_escdelay", (PyCFunction)_curses_get_escdelay, METH_NOARGS, _curses_get_escdelay__doc__},
|
||||
|
||||
static PyObject *
|
||||
_curses_get_escdelay_impl(PyObject *module);
|
||||
|
||||
static PyObject *
|
||||
_curses_get_escdelay(PyObject *module, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
return _curses_get_escdelay_impl(module);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(_curses_set_escdelay__doc__,
|
||||
"set_escdelay($module, ms, /)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Sets the curses ESCDELAY setting.\n"
|
||||
"\n"
|
||||
" ms\n"
|
||||
" length of the delay in milliseconds.\n"
|
||||
"\n"
|
||||
"Sets the number of milliseconds to wait after reading an escape character,\n"
|
||||
"to distinguish between an individual escape character entered on the\n"
|
||||
"keyboard from escape sequences sent by cursor and function keys.");
|
||||
|
||||
#define _CURSES_SET_ESCDELAY_METHODDEF \
|
||||
{"set_escdelay", (PyCFunction)_curses_set_escdelay, METH_O, _curses_set_escdelay__doc__},
|
||||
|
||||
static PyObject *
|
||||
_curses_set_escdelay_impl(PyObject *module, int ms);
|
||||
|
||||
static PyObject *
|
||||
_curses_set_escdelay(PyObject *module, PyObject *arg)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
int ms;
|
||||
|
||||
if (PyFloat_Check(arg)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"integer argument expected, got float" );
|
||||
goto exit;
|
||||
}
|
||||
ms = _PyLong_AsInt(arg);
|
||||
if (ms == -1 && PyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = _curses_set_escdelay_impl(module, ms);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(_curses_get_tabsize__doc__,
|
||||
"get_tabsize($module, /)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Gets the curses TABSIZE setting.\n"
|
||||
"\n"
|
||||
"Gets the number of columns used by the curses library when converting a tab\n"
|
||||
"character to spaces as it adds the tab to a window.");
|
||||
|
||||
#define _CURSES_GET_TABSIZE_METHODDEF \
|
||||
{"get_tabsize", (PyCFunction)_curses_get_tabsize, METH_NOARGS, _curses_get_tabsize__doc__},
|
||||
|
||||
static PyObject *
|
||||
_curses_get_tabsize_impl(PyObject *module);
|
||||
|
||||
static PyObject *
|
||||
_curses_get_tabsize(PyObject *module, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
return _curses_get_tabsize_impl(module);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(_curses_set_tabsize__doc__,
|
||||
"set_tabsize($module, size, /)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Sets the curses TABSIZE setting.\n"
|
||||
"\n"
|
||||
" size\n"
|
||||
" rendered cell width of a tab character.\n"
|
||||
"\n"
|
||||
"Sets the number of columns used by the curses library when converting a tab\n"
|
||||
"character to spaces as it adds the tab to a window.");
|
||||
|
||||
#define _CURSES_SET_TABSIZE_METHODDEF \
|
||||
{"set_tabsize", (PyCFunction)_curses_set_tabsize, METH_O, _curses_set_tabsize__doc__},
|
||||
|
||||
static PyObject *
|
||||
_curses_set_tabsize_impl(PyObject *module, int size);
|
||||
|
||||
static PyObject *
|
||||
_curses_set_tabsize(PyObject *module, PyObject *arg)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
int size;
|
||||
|
||||
if (PyFloat_Check(arg)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"integer argument expected, got float" );
|
||||
goto exit;
|
||||
}
|
||||
size = _PyLong_AsInt(arg);
|
||||
if (size == -1 && PyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = _curses_set_tabsize_impl(module, size);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(_curses_intrflush__doc__,
|
||||
"intrflush($module, flag, /)\n"
|
||||
"--\n"
|
||||
|
@ -4569,4 +4691,4 @@ _curses_use_default_colors(PyObject *module, PyObject *Py_UNUSED(ignored))
|
|||
#ifndef _CURSES_USE_DEFAULT_COLORS_METHODDEF
|
||||
#define _CURSES_USE_DEFAULT_COLORS_METHODDEF
|
||||
#endif /* !defined(_CURSES_USE_DEFAULT_COLORS_METHODDEF) */
|
||||
/*[clinic end generated code: output=e5b3502f1d38dff0 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=985c0849e841acec input=a9049054013a1b77]*/
|
||||
|
|
Loading…
Reference in New Issue